selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Moore <paul@paul-moore.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Stephen Smalley <sds@tycho.nsa.gov>,
	Eric Paris <eparis@parisplace.org>,
	clang-built-linux@googlegroups.com,
	Nick Desaulniers <ndesaulniers@google.com>,
	Nathan Chancellor <natechancellor@gmail.com>,
	selinux@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] selinux: avoid uninitialized variable warning
Date: Fri, 22 Mar 2019 17:00:13 -0400	[thread overview]
Message-ID: <CAHC9VhQ2DbH1=xQWfPxjhqC-86pYuo5sXXNJnOtSOsfZrrMeaQ@mail.gmail.com> (raw)
In-Reply-To: <CAK8P3a0EF-T7fySTCDBAFftWTKXPTBcCzj7afcVTP=_pemQdug@mail.gmail.com>

On Fri, Mar 22, 2019 at 4:35 PM Arnd Bergmann <arnd@arndb.de> wrote:
> On Fri, Mar 22, 2019 at 9:15 PM Paul Moore <paul@paul-moore.com> wrote:
> > On Fri, Mar 22, 2019 at 10:14 AM Arnd Bergmann <arnd@arndb.de> wrote:
>
> > Hi Arnd,
> >
> > Thanks for pointing this out and providing a fix.  I think you're
> > right in that the should be pretty harmless, but I also agree that we
> > should fix it; some thoughts on the patch below ...
> >
> > > diff --git a/security/selinux/netlabel.c b/security/selinux/netlabel.c
> > > index 186e727b737b..d0e549d4f486 100644
> > > --- a/security/selinux/netlabel.c
> > > +++ b/security/selinux/netlabel.c
> > > @@ -288,7 +288,6 @@ int selinux_netlbl_sctp_assoc_request(struct sctp_endpoint *ep,
> > >         int rc;
> > >         struct netlbl_lsm_secattr secattr;
> > >         struct sk_security_struct *sksec = ep->base.sk->sk_security;
> > > -       struct sockaddr *addr;
> > >         struct sockaddr_in addr4;
> > >  #if IS_ENABLED(CONFIG_IPV6)
> > >         struct sockaddr_in6 addr6;
> > > @@ -310,16 +309,15 @@ int selinux_netlbl_sctp_assoc_request(struct sctp_endpoint *ep,
> > >         if (ip_hdr(skb)->version == 4) {
> > >                 addr4.sin_family = AF_INET;
> > >                 addr4.sin_addr.s_addr = ip_hdr(skb)->saddr;
> > > -               addr = (struct sockaddr *)&addr4;
> > > +               rc = netlbl_conn_setattr(ep->base.sk, (void*)&addr4, &secattr);
> > >  #if IS_ENABLED(CONFIG_IPV6)
> > >         } else {
> > >                 addr6.sin6_family = AF_INET6;
> > >                 addr6.sin6_addr = ipv6_hdr(skb)->saddr;
> > > -               addr = (struct sockaddr *)&addr6;
> > > +               rc = netlbl_conn_setattr(ep->base.sk, (void*)&addr6, &secattr);
> > >  #endif
> >
> > While we are hardening the code a bit, I'm thinking we should probably
> > refactor this if-else a bit, some pseudo code for example:
> >
> >     if (ip_hdr == 4) {
> >       rc = netlbl_conn_setattr();
> >   #if CONFIG_IPV6
> >     } else if (ip_hdr == 6) {
> >       rc = netlbl_conn_setattr();
> >   #endif
> >     } else {
> >       rc = -EAFNOSUPPORT;
> >     }
> >
> > Thoughts?
> >
>
> Seems fine. We could go a step further and use IS_ENABLED()
> as C code here to get rid of the two #ifdef checks as well, like
>
>         if (ip_hdr(skb)->version == 4 ) {
>                 addr4.sin_family = AF_INET;
>                 addr4.sin_addr.s_addr = ip_hdr(skb)->saddr;
>                 rc = netlbl_conn_setattr(ep->base.sk, &addr4, &secattr);
>         } else if (IS_ENABLED(CONFIG_IPV6) && ip_hdr(skb)->version == 6) {
>                 addr6.sin6_family = AF_INET6;
>                 addr6.sin6_addr = ipv6_hdr(skb)->saddr;
>                 rc = netlbl_conn_setattr(ep->base.sk, &addr6, &secattr);
>         } else {
>                rc = -EAFNOSUPPORT;
>         }

Looks good to me.  Can you send a revised patch?

-- 
paul moore
www.paul-moore.com

      reply	other threads:[~2019-03-22 21:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22 14:14 [PATCH] selinux: avoid uninitialized variable warning Arnd Bergmann
2019-03-22 15:17 ` Nathan Chancellor
2019-03-22 20:15 ` Paul Moore
2019-03-22 20:35   ` Arnd Bergmann
2019-03-22 21:00     ` Paul Moore [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHC9VhQ2DbH1=xQWfPxjhqC-86pYuo5sXXNJnOtSOsfZrrMeaQ@mail.gmail.com' \
    --to=paul@paul-moore.com \
    --cc=arnd@arndb.de \
    --cc=clang-built-linux@googlegroups.com \
    --cc=eparis@parisplace.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=natechancellor@gmail.com \
    --cc=ndesaulniers@google.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).