Skip to content

Commit b4fcd63

Browse files
ignatkkuba-moo
authored andcommitted
net: ieee802154: do not leave a dangling sk pointer in ieee802154_create()
sock_init_data() attaches the allocated sk object to the provided sock object. If ieee802154_create() fails later, the allocated sk object is freed, but the dangling pointer remains in the provided sock object, which may allow use-after-free. Clear the sk pointer in the sock object on error. Signed-off-by: Ignat Korchagin <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 811a7ca commit b4fcd63

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

net/ieee802154/socket.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,19 +1043,21 @@ static int ieee802154_create(struct net *net, struct socket *sock,
10431043

10441044
if (sk->sk_prot->hash) {
10451045
rc = sk->sk_prot->hash(sk);
1046-
if (rc) {
1047-
sk_common_release(sk);
1048-
goto out;
1049-
}
1046+
if (rc)
1047+
goto out_sk_release;
10501048
}
10511049

10521050
if (sk->sk_prot->init) {
10531051
rc = sk->sk_prot->init(sk);
10541052
if (rc)
1055-
sk_common_release(sk);
1053+
goto out_sk_release;
10561054
}
10571055
out:
10581056
return rc;
1057+
out_sk_release:
1058+
sk_common_release(sk);
1059+
sock->sk = NULL;
1060+
goto out;
10591061
}
10601062

10611063
static const struct net_proto_family ieee802154_family_ops = {

0 commit comments

Comments
 (0)