Skip to content

Commit 58acd10

Browse files
lxindavem330
authored andcommitted
sctp: update active_key for asoc when old key is being replaced
syzbot reported a call trace: BUG: KASAN: use-after-free in sctp_auth_shkey_hold+0x22/0xa0 net/sctp/auth.c:112 Call Trace: sctp_auth_shkey_hold+0x22/0xa0 net/sctp/auth.c:112 sctp_set_owner_w net/sctp/socket.c:131 [inline] sctp_sendmsg_to_asoc+0x152e/0x2180 net/sctp/socket.c:1865 sctp_sendmsg+0x103b/0x1d30 net/sctp/socket.c:2027 inet_sendmsg+0x99/0xe0 net/ipv4/af_inet.c:821 sock_sendmsg_nosec net/socket.c:703 [inline] sock_sendmsg+0xcf/0x120 net/socket.c:723 This is an use-after-free issue caused by not updating asoc->shkey after it was replaced in the key list asoc->endpoint_shared_keys, and the old key was freed. This patch is to fix by also updating active_key for asoc when old key is being replaced with a new one. Note that this issue doesn't exist in sctp_auth_del_key_id(), as it's not allowed to delete the active_key from the asoc. Fixes: 1b1e0bc ("sctp: add refcnt support for sh_key") Reported-by: [email protected] Signed-off-by: Xin Long <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e9a72f8 commit 58acd10

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

net/sctp/auth.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,8 @@ int sctp_auth_set_key(struct sctp_endpoint *ep,
860860
if (replace) {
861861
list_del_init(&shkey->key_list);
862862
sctp_auth_shkey_release(shkey);
863+
if (asoc && asoc->active_key_id == auth_key->sca_keynumber)
864+
sctp_auth_asoc_init_active_key(asoc, GFP_KERNEL);
863865
}
864866
list_add(&cur_key->key_list, sh_keys);
865867

0 commit comments

Comments
 (0)