Skip to contentSkip to conversation

security: smack: Fix possible null-pointer dereferences in smack_socket_sock_rcv_skb()

PATCH New Jia-Ju Bai 1 participant 1 message Jul 23, 2019

Subsystems (2)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 security: smack: Fix possible null-pointer dereferences in smack_socket_sock_rcv_skb()

In smack_socket_sock_rcv_skb(), there is an if statement on line 3920 to check whether skb is NULL:

    if (skb && skb->secmark != 0)

This check indicates skb can be NULL in some cases.

But on lines 3931 and 3932, skb is used:

    ad.a.u.net->netif = skb->skb_iif;
    ipv6_skb_to_auditdata(skb, &ad.a, NULL);

Thus, possible null-pointer dereferences may occur when skb is NULL.

To fix these possible bugs, an if statement is added to check skb.

These bugs are found by a static analysis tool STCheck written by us.

---
 security/smack/smack_lsm.c | 2 ++
 1 file changed, 2 insertions(+)
security/smack/smack_lsm.c +2 -0
index 4c5e5a438f8b..5c9fc8ba6e57 100644
@@ -3925,6 +3925,8 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
 			skp = smack_ipv6host_label(&sadd);
 		if (skp == NULL)
 			skp = smack_net_ambient;
+		if (skb == NULL)
+			break;
 #ifdef CONFIG_AUDIT
 		smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
 		ad.a.u.net->family = family;
Signature · 1 line
2.17.0