All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 selinux] selinux: remove unneeded ipv6 hook wrappers
@ 2021-10-11 14:24 Florian Westphal
  2021-10-11 17:09 ` Paul Moore
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Westphal @ 2021-10-11 14:24 UTC (permalink / raw)
  To: selinux
  Cc: paul, stephen.smalley.work, eparis, linux-kernel, Florian Westphal

Netfilter places the protocol number the hook function is getting called
from in state->pf, so we can use that instead of an extra wrapper.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 v2: add back '#endif /* CONFIG_NETFILTER */' erronously axed in v1.
 Applies to 'next' branch of
 https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git/

 security/selinux/hooks.c | 52 ++++++++++------------------------------
 1 file changed, 12 insertions(+), 40 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index e7ebd45ca345..831b857d5dd7 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -5746,22 +5746,13 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb,
 	return NF_ACCEPT;
 }
 
-static unsigned int selinux_ipv4_forward(void *priv,
+static unsigned int selinux_hook_forward(void *priv,
 					 struct sk_buff *skb,
 					 const struct nf_hook_state *state)
 {
-	return selinux_ip_forward(skb, state->in, PF_INET);
+	return selinux_ip_forward(skb, state->in, state->pf);
 }
 
-#if IS_ENABLED(CONFIG_IPV6)
-static unsigned int selinux_ipv6_forward(void *priv,
-					 struct sk_buff *skb,
-					 const struct nf_hook_state *state)
-{
-	return selinux_ip_forward(skb, state->in, PF_INET6);
-}
-#endif	/* IPV6 */
-
 static unsigned int selinux_ip_output(struct sk_buff *skb,
 				      u16 family)
 {
@@ -5804,21 +5795,12 @@ static unsigned int selinux_ip_output(struct sk_buff *skb,
 	return NF_ACCEPT;
 }
 
-static unsigned int selinux_ipv4_output(void *priv,
-					struct sk_buff *skb,
-					const struct nf_hook_state *state)
-{
-	return selinux_ip_output(skb, PF_INET);
-}
-
-#if IS_ENABLED(CONFIG_IPV6)
-static unsigned int selinux_ipv6_output(void *priv,
+static unsigned int selinux_hook_output(void *priv,
 					struct sk_buff *skb,
 					const struct nf_hook_state *state)
 {
-	return selinux_ip_output(skb, PF_INET6);
+	return selinux_ip_output(skb, state->pf);
 }
-#endif	/* IPV6 */
 
 static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
 						int ifindex,
@@ -5994,22 +5976,12 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb,
 	return NF_ACCEPT;
 }
 
-static unsigned int selinux_ipv4_postroute(void *priv,
+static unsigned int selinux_hook_postroute(void *priv,
 					   struct sk_buff *skb,
 					   const struct nf_hook_state *state)
 {
-	return selinux_ip_postroute(skb, state->out, PF_INET);
+	return selinux_ip_postroute(skb, state->out, state->pf);
 }
-
-#if IS_ENABLED(CONFIG_IPV6)
-static unsigned int selinux_ipv6_postroute(void *priv,
-					   struct sk_buff *skb,
-					   const struct nf_hook_state *state)
-{
-	return selinux_ip_postroute(skb, state->out, PF_INET6);
-}
-#endif	/* IPV6 */
-
 #endif	/* CONFIG_NETFILTER */
 
 static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)
@@ -7470,38 +7442,38 @@ DEFINE_LSM(selinux) = {
 
 static const struct nf_hook_ops selinux_nf_ops[] = {
 	{
-		.hook =		selinux_ipv4_postroute,
+		.hook =		selinux_hook_postroute,
 		.pf =		NFPROTO_IPV4,
 		.hooknum =	NF_INET_POST_ROUTING,
 		.priority =	NF_IP_PRI_SELINUX_LAST,
 	},
 	{
-		.hook =		selinux_ipv4_forward,
+		.hook =		selinux_hook_forward,
 		.pf =		NFPROTO_IPV4,
 		.hooknum =	NF_INET_FORWARD,
 		.priority =	NF_IP_PRI_SELINUX_FIRST,
 	},
 	{
-		.hook =		selinux_ipv4_output,
+		.hook =		selinux_hook_output,
 		.pf =		NFPROTO_IPV4,
 		.hooknum =	NF_INET_LOCAL_OUT,
 		.priority =	NF_IP_PRI_SELINUX_FIRST,
 	},
 #if IS_ENABLED(CONFIG_IPV6)
 	{
-		.hook =		selinux_ipv6_postroute,
+		.hook =		selinux_hook_postroute,
 		.pf =		NFPROTO_IPV6,
 		.hooknum =	NF_INET_POST_ROUTING,
 		.priority =	NF_IP6_PRI_SELINUX_LAST,
 	},
 	{
-		.hook =		selinux_ipv6_forward,
+		.hook =		selinux_hook_forward,
 		.pf =		NFPROTO_IPV6,
 		.hooknum =	NF_INET_FORWARD,
 		.priority =	NF_IP6_PRI_SELINUX_FIRST,
 	},
 	{
-		.hook =		selinux_ipv6_output,
+		.hook =		selinux_hook_output,
 		.pf =		NFPROTO_IPV6,
 		.hooknum =	NF_INET_LOCAL_OUT,
 		.priority =	NF_IP6_PRI_SELINUX_FIRST,
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 selinux] selinux: remove unneeded ipv6 hook wrappers
  2021-10-11 14:24 [PATCH v2 selinux] selinux: remove unneeded ipv6 hook wrappers Florian Westphal
@ 2021-10-11 17:09 ` Paul Moore
  2021-10-11 18:20   ` Ondrej Mosnacek
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Moore @ 2021-10-11 17:09 UTC (permalink / raw)
  To: Florian Westphal; +Cc: selinux, Stephen Smalley, Eric Paris, linux-kernel

On Mon, Oct 11, 2021 at 10:25 AM Florian Westphal <fw@strlen.de> wrote:
>
> Netfilter places the protocol number the hook function is getting called
> from in state->pf, so we can use that instead of an extra wrapper.
>
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  v2: add back '#endif /* CONFIG_NETFILTER */' erronously axed in v1.
>  Applies to 'next' branch of
>  https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git/
>
>  security/selinux/hooks.c | 52 ++++++++++------------------------------
>  1 file changed, 12 insertions(+), 40 deletions(-)

...

> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index e7ebd45ca345..831b857d5dd7 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -7470,38 +7442,38 @@ DEFINE_LSM(selinux) = {
>
>  static const struct nf_hook_ops selinux_nf_ops[] = {
>         {
> -               .hook =         selinux_ipv4_postroute,
> +               .hook =         selinux_hook_postroute,
>                 .pf =           NFPROTO_IPV4,
>                 .hooknum =      NF_INET_POST_ROUTING,
>                 .priority =     NF_IP_PRI_SELINUX_LAST,
>         },

Thanks for the patch Florian, although the name "selinux_hook_*" seems
a bit ambiguous to me, after all we have a little more than 200
"hooks" in the SELinux LSM implementation.  Would you be okay with
calling the netfilter hook functions "selinux_nf_*" or something
similar?  If you don't have time I can do the rename during the merge
assuming we can all agree on a name.

-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 selinux] selinux: remove unneeded ipv6 hook wrappers
  2021-10-11 17:09 ` Paul Moore
@ 2021-10-11 18:20   ` Ondrej Mosnacek
  2021-10-11 19:41     ` Paul Moore
  0 siblings, 1 reply; 5+ messages in thread
From: Ondrej Mosnacek @ 2021-10-11 18:20 UTC (permalink / raw)
  To: Paul Moore
  Cc: Florian Westphal, SElinux list, Stephen Smalley, Eric Paris,
	Linux kernel mailing list

On Mon, Oct 11, 2021 at 7:10 PM Paul Moore <paul@paul-moore.com> wrote:
> On Mon, Oct 11, 2021 at 10:25 AM Florian Westphal <fw@strlen.de> wrote:
> >
> > Netfilter places the protocol number the hook function is getting called
> > from in state->pf, so we can use that instead of an extra wrapper.
> >
> > Signed-off-by: Florian Westphal <fw@strlen.de>
> > ---
> >  v2: add back '#endif /* CONFIG_NETFILTER */' erronously axed in v1.
> >  Applies to 'next' branch of
> >  https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git/
> >
> >  security/selinux/hooks.c | 52 ++++++++++------------------------------
> >  1 file changed, 12 insertions(+), 40 deletions(-)
>
> ...
>
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index e7ebd45ca345..831b857d5dd7 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -7470,38 +7442,38 @@ DEFINE_LSM(selinux) = {
> >
> >  static const struct nf_hook_ops selinux_nf_ops[] = {
> >         {
> > -               .hook =         selinux_ipv4_postroute,
> > +               .hook =         selinux_hook_postroute,
> >                 .pf =           NFPROTO_IPV4,
> >                 .hooknum =      NF_INET_POST_ROUTING,
> >                 .priority =     NF_IP_PRI_SELINUX_LAST,
> >         },
>
> Thanks for the patch Florian, although the name "selinux_hook_*" seems
> a bit ambiguous to me, after all we have a little more than 200
> "hooks" in the SELinux LSM implementation.  Would you be okay with
> calling the netfilter hook functions "selinux_nf_*" or something
> similar?  If you don't have time I can do the rename during the merge
> assuming we can all agree on a name.

Since selinux_ip_forward() and selinux_ip_postroute() are used only in
the hook functions, how about changing their signature and using them
as hooks directly? That would solve the naming and also remove a few
extra lines of boilerplate.

-- 
Ondrej Mosnacek
Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 selinux] selinux: remove unneeded ipv6 hook wrappers
  2021-10-11 18:20   ` Ondrej Mosnacek
@ 2021-10-11 19:41     ` Paul Moore
  2021-10-11 20:06       ` Florian Westphal
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Moore @ 2021-10-11 19:41 UTC (permalink / raw)
  To: Ondrej Mosnacek
  Cc: Florian Westphal, SElinux list, Stephen Smalley, Eric Paris,
	Linux kernel mailing list

On Mon, Oct 11, 2021 at 2:21 PM Ondrej Mosnacek <omosnace@redhat.com> wrote:
>
> On Mon, Oct 11, 2021 at 7:10 PM Paul Moore <paul@paul-moore.com> wrote:
> > On Mon, Oct 11, 2021 at 10:25 AM Florian Westphal <fw@strlen.de> wrote:
> > >
> > > Netfilter places the protocol number the hook function is getting called
> > > from in state->pf, so we can use that instead of an extra wrapper.
> > >
> > > Signed-off-by: Florian Westphal <fw@strlen.de>
> > > ---
> > >  v2: add back '#endif /* CONFIG_NETFILTER */' erronously axed in v1.
> > >  Applies to 'next' branch of
> > >  https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git/
> > >
> > >  security/selinux/hooks.c | 52 ++++++++++------------------------------
> > >  1 file changed, 12 insertions(+), 40 deletions(-)
> >
> > ...
> >
> > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > > index e7ebd45ca345..831b857d5dd7 100644
> > > --- a/security/selinux/hooks.c
> > > +++ b/security/selinux/hooks.c
> > > @@ -7470,38 +7442,38 @@ DEFINE_LSM(selinux) = {
> > >
> > >  static const struct nf_hook_ops selinux_nf_ops[] = {
> > >         {
> > > -               .hook =         selinux_ipv4_postroute,
> > > +               .hook =         selinux_hook_postroute,
> > >                 .pf =           NFPROTO_IPV4,
> > >                 .hooknum =      NF_INET_POST_ROUTING,
> > >                 .priority =     NF_IP_PRI_SELINUX_LAST,
> > >         },
> >
> > Thanks for the patch Florian, although the name "selinux_hook_*" seems
> > a bit ambiguous to me, after all we have a little more than 200
> > "hooks" in the SELinux LSM implementation.  Would you be okay with
> > calling the netfilter hook functions "selinux_nf_*" or something
> > similar?  If you don't have time I can do the rename during the merge
> > assuming we can all agree on a name.
>
> Since selinux_ip_forward() and selinux_ip_postroute() are used only in
> the hook functions, how about changing their signature and using them
> as hooks directly? That would solve the naming and also remove a few
> extra lines of boilerplate.

No argument against that from me, although you should be able to do
the same for selinux_ip_output() as well unless I missed a caller.

-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 selinux] selinux: remove unneeded ipv6 hook wrappers
  2021-10-11 19:41     ` Paul Moore
@ 2021-10-11 20:06       ` Florian Westphal
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Westphal @ 2021-10-11 20:06 UTC (permalink / raw)
  To: Paul Moore
  Cc: Ondrej Mosnacek, Florian Westphal, SElinux list, Stephen Smalley,
	Eric Paris, Linux kernel mailing list

Paul Moore <paul@paul-moore.com> wrote:
> On Mon, Oct 11, 2021 at 2:21 PM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> > On Mon, Oct 11, 2021 at 7:10 PM Paul Moore <paul@paul-moore.com> wrote:
> > > On Mon, Oct 11, 2021 at 10:25 AM Florian Westphal <fw@strlen.de> wrote:
> > > > Netfilter places the protocol number the hook function is getting called
> > > > from in state->pf, so we can use that instead of an extra wrapper.
> > > >
> > > > Signed-off-by: Florian Westphal <fw@strlen.de>
> > > > ---
> > > >  v2: add back '#endif /* CONFIG_NETFILTER */' erronously axed in v1.
> > > >  Applies to 'next' branch of
> > > >  https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git/
> > > >
> > > >  security/selinux/hooks.c | 52 ++++++++++------------------------------
> > > >  1 file changed, 12 insertions(+), 40 deletions(-)
> > >
> > > ...
> > >
> > > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > > > index e7ebd45ca345..831b857d5dd7 100644
> > > > --- a/security/selinux/hooks.c
> > > > +++ b/security/selinux/hooks.c
> > > > @@ -7470,38 +7442,38 @@ DEFINE_LSM(selinux) = {
> > > >
> > > >  static const struct nf_hook_ops selinux_nf_ops[] = {
> > > >         {
> > > > -               .hook =         selinux_ipv4_postroute,
> > > > +               .hook =         selinux_hook_postroute,
> > > >                 .pf =           NFPROTO_IPV4,
> > > >                 .hooknum =      NF_INET_POST_ROUTING,
> > > >                 .priority =     NF_IP_PRI_SELINUX_LAST,
> > > >         },
> > >
> > > Thanks for the patch Florian, although the name "selinux_hook_*" seems
> > > a bit ambiguous to me, after all we have a little more than 200
> > > "hooks" in the SELinux LSM implementation.  Would you be okay with
> > > calling the netfilter hook functions "selinux_nf_*" or something
> > > similar?

Absolutely.

> > > If you don't have time I can do the rename during the merge
> > > assuming we can all agree on a name.

I'll submit a v3.

> > Since selinux_ip_forward() and selinux_ip_postroute() are used only in
> > the hook functions, how about changing their signature and using them
> > as hooks directly? That would solve the naming and also remove a few
> > extra lines of boilerplate.
> 
> No argument against that from me, although you should be able to do
> the same for selinux_ip_output() as well unless I missed a caller.

I'll have a look, thanks for the pointers.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-11 20:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-11 14:24 [PATCH v2 selinux] selinux: remove unneeded ipv6 hook wrappers Florian Westphal
2021-10-11 17:09 ` Paul Moore
2021-10-11 18:20   ` Ondrej Mosnacek
2021-10-11 19:41     ` Paul Moore
2021-10-11 20:06       ` Florian Westphal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.