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>,
	selinux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] [v3] selinux: avoid uninitialized variable warning
Date: Mon, 25 Mar 2019 10:40:49 -0400	[thread overview]
Message-ID: <CAHC9VhTyVXMxqDvSQs5skCjAOwkjjQxENyv8UQUSMftkDBiTZg@mail.gmail.com> (raw)
In-Reply-To: <20190325142317.3666259-1-arnd@arndb.de>

On Mon, Mar 25, 2019 at 10:23 AM Arnd Bergmann <arnd@arndb.de> wrote:
>
> clang correctly points out a code path that would lead
> to an uninitialized variable use:
>
> security/selinux/netlabel.c:310:6: error: variable 'addr' is used uninitialized whenever 'if' condition is false
>       [-Werror,-Wsometimes-uninitialized]
>         if (ip_hdr(skb)->version == 4) {
>             ^~~~~~~~~~~~~~~~~~~~~~~~~
> security/selinux/netlabel.c:322:40: note: uninitialized use occurs here
>         rc = netlbl_conn_setattr(ep->base.sk, addr, &secattr);
>                                               ^~~~
> security/selinux/netlabel.c:310:2: note: remove the 'if' if its condition is always true
>         if (ip_hdr(skb)->version == 4) {
>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> security/selinux/netlabel.c:291:23: note: initialize the variable 'addr' to silence this warning
>         struct sockaddr *addr;
>                              ^
>                               = NULL
>
> This is probably harmless since we should not see ipv6 packets
> of CONFIG_IPV6 is disabled, but it's better to rearrange the code
> so this cannot happen.
>
> Link: https://lore.kernel.org/patchwork/patch/1053663/
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> v3: add missing ip_hdr(skb)->version == 6 check
> v2: revise after discussing with Paul Moore
> ---
>  security/selinux/netlabel.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)

Better, thank you; merged into selinux/next.  FYI, I had to fix a
couple of style errors that checkpatch.pl was complaining about ("void
*" not "void*").

> diff --git a/security/selinux/netlabel.c b/security/selinux/netlabel.c
> index 186e727b737b..f10813e54d07 100644
> --- a/security/selinux/netlabel.c
> +++ b/security/selinux/netlabel.c
> @@ -288,11 +288,8 @@ 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;
> -#endif
>
>         if (ep->base.sk->sk_family != PF_INET &&
>                                 ep->base.sk->sk_family != PF_INET6)
> @@ -310,16 +307,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;
> -#if IS_ENABLED(CONFIG_IPV6)
> -       } else {
> +               rc = netlbl_conn_setattr(ep->base.sk, (void*)&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;
> -               addr = (struct sockaddr *)&addr6;
> -#endif
> +               rc = netlbl_conn_setattr(ep->base.sk, (void*)&addr6, &secattr);
> +       } else {
> +               rc = -EAFNOSUPPORT;
>         }
>
> -       rc = netlbl_conn_setattr(ep->base.sk, addr, &secattr);
>         if (rc == 0)
>                 sksec->nlbl_state = NLBL_LABELED;
>
> --
> 2.20.0

-- 
paul moore
www.paul-moore.com

      reply	other threads:[~2019-03-25 14:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-25 14:23 [PATCH] [v3] selinux: avoid uninitialized variable warning Arnd Bergmann
2019-03-25 14:40 ` 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=CAHC9VhTyVXMxqDvSQs5skCjAOwkjjQxENyv8UQUSMftkDBiTZg@mail.gmail.com \
    --to=paul@paul-moore.com \
    --cc=arnd@arndb.de \
    --cc=eparis@parisplace.org \
    --cc=linux-kernel@vger.kernel.org \
    --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).