lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 22 Mar 2019 21:35:30 +0100
From:   Arnd Bergmann <arnd@...db.de>
To:     Paul Moore <paul@...l-moore.com>
Cc:     Stephen Smalley <sds@...ho.nsa.gov>,
        Eric Paris <eparis@...isplace.org>,
        clang-built-linux@...glegroups.com,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Nathan Chancellor <natechancellor@...il.com>,
        selinux@...r.kernel.org,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] selinux: avoid uninitialized variable warning

On Fri, Mar 22, 2019 at 9:15 PM Paul Moore <paul@...l-moore.com> wrote:
> On Fri, Mar 22, 2019 at 10:14 AM Arnd Bergmann <arnd@...db.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;
        }

  Arnd

Powered by blists - more mailing lists