public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: walter harms <wharms@bfs.de>
To: Colin King <colin.king@canonical.com>
Cc: Casey Schaufler <casey@schaufler-ca.com>,
	James Morris <james.l.morris@oracle.com>,
	"Serge E . Hallyn" <serge@hallyn.com>,
	linux-security-module@vger.kernel.org,
	kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Smack: fix a dereference before null check on sock->sk
Date: Thu, 09 Feb 2017 14:09:11 +0100	[thread overview]
Message-ID: <589C69F7.8030603@bfs.de> (raw)
In-Reply-To: <20170209120301.28152-1-colin.king@canonical.com>



Am 09.02.2017 13:03, schrieb Colin King:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The initialisation of pointer ssp is from a dereference on sock->sk
> before sock-sk is null checked, hence there is a potential for a
> null pointer deference.  Fix this by moving the assignment of ssp
> to just before it is used in the call to smk_ipv6_check.
> 
> Detected with CoverityScan, CID#1324196 ("Dereference before null check")
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  security/smack/smack_lsm.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index fc8fb31..bb17387 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -2899,7 +2899,7 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
>  #endif
>  #ifdef SMACK_IPV6_SECMARK_LABELING
>  	struct smack_known *rsp;
> -	struct socket_smack *ssp = sock->sk->sk_security;
> +	struct socket_smack *ssp;
>  #endif
>  
>  	if (sock->sk == NULL)
> @@ -2916,9 +2916,11 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
>  			return -EINVAL;
>  #ifdef SMACK_IPV6_SECMARK_LABELING
>  		rsp = smack_ipv6host_label(sip);
> -		if (rsp != NULL)
> +		if (rsp != NULL) {
> +			ssp = sock->sk->sk_security;
>  			rc = smk_ipv6_check(ssp->smk_out, rsp, sip,
>  						SMK_CONNECTING);
> +		}
>  #endif
>  #ifdef SMACK_IPV6_PORT_LABELING
>  		rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING);


In the hope of reducing the ifdef forrest:
 you could move the struct smack_known *rsp; and struct socket_smack *ssp; into the block like:

{
	struct smack_known *rsp=smack_ipv6host_label(sip);
	
	if (rsp != NULL) {
		struct socket_smack *ssp= sock->sk->sk_security;
		rc = smk_ipv6_check(ssp->smk_out, rsp, sip,
  						SMK_CONNECTING);
		}
}


just my 2 cents ...

re,
 wh

  reply	other threads:[~2017-02-09 13:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-09 12:03 [PATCH] Smack: fix a dereference before null check on sock->sk Colin King
2017-02-09 13:09 ` walter harms [this message]
2017-02-09 16:49   ` Casey Schaufler

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=589C69F7.8030603@bfs.de \
    --to=wharms@bfs.de \
    --cc=casey@schaufler-ca.com \
    --cc=colin.king@canonical.com \
    --cc=james.l.morris@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=serge@hallyn.com \
    /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