Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1577526 > unrolled thread

[PATCH] Smack: fix a dereference before null check on sock->sk

Started byColin King <colin.king@canonical.com>
First post2017-02-09 13:30 +0100
Last post2017-02-09 18:00 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] Smack: fix a dereference before null check on sock->sk Colin King <colin.king@canonical.com> - 2017-02-09 13:30 +0100
    Re: [PATCH] Smack: fix a dereference before null check on sock->sk walter harms <wharms@bfs.de> - 2017-02-09 14:20 +0100
      Re: [PATCH] Smack: fix a dereference before null check on sock->sk Casey Schaufler <casey@schaufler-ca.com> - 2017-02-09 18:00 +0100

#1577526 — [PATCH] Smack: fix a dereference before null check on sock->sk

FromColin King <colin.king@canonical.com>
Date2017-02-09 13:30 +0100
Subject[PATCH] Smack: fix a dereference before null check on sock->sk
Message-ID<t8W1k-66e-13@gated-at.bofh.it>
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);
-- 
2.10.2

[toc] | [next] | [standalone]


#1577556

Fromwalter harms <wharms@bfs.de>
Date2017-02-09 14:20 +0100
Message-ID<t8WNH-6CT-7@gated-at.bofh.it>
In reply to#1577526

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

[toc] | [prev] | [next] | [standalone]


#1577784

FromCasey Schaufler <casey@schaufler-ca.com>
Date2017-02-09 18:00 +0100
Message-ID<t90eC-98-25@gated-at.bofh.it>
In reply to#1577556
On 2/9/2017 5:09 AM, walter harms wrote:
>
> 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 ...

I can't say that I'm proud of that chunk of code.
A real clean-up is on my todo list, and I would happily
entertain patches.

>
> re,
>  wh
>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web