Skip to content

Commit 2a2403c

Browse files
lxindavem330
authored andcommitted
tipc: increment the tmp aead refcnt before attaching it
Li Shuang found a NULL pointer dereference crash in her testing: [] BUG: unable to handle kernel NULL pointer dereference at 0000000000000020 [] RIP: 0010:tipc_crypto_rcv_complete+0xc8/0x7e0 [tipc] [] Call Trace: [] <IRQ> [] tipc_crypto_rcv+0x2d9/0x8f0 [tipc] [] tipc_rcv+0x2fc/0x1120 [tipc] [] tipc_udp_recv+0xc6/0x1e0 [tipc] [] udpv6_queue_rcv_one_skb+0x16a/0x460 [] udp6_unicast_rcv_skb.isra.35+0x41/0xa0 [] ip6_protocol_deliver_rcu+0x23b/0x4c0 [] ip6_input+0x3d/0xb0 [] ipv6_rcv+0x395/0x510 [] __netif_receive_skb_core+0x5fc/0xc40 This is caused by NULL returned by tipc_aead_get(), and then crashed when dereferencing it later in tipc_crypto_rcv_complete(). This might happen when tipc_crypto_rcv_complete() is called by two threads at the same time: the tmp attached by tipc_crypto_key_attach() in one thread may be released by the one attached by that in the other thread. This patch is to fix it by incrementing the tmp's refcnt before attaching it instead of calling tipc_aead_get() after attaching it. Fixes: fc1b6d6 ("tipc: introduce TIPC encryption & authentication") Reported-by: Li Shuang <[email protected]> Signed-off-by: Xin Long <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0f6925b commit 2a2403c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/tipc/crypto.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,12 +1941,13 @@ static void tipc_crypto_rcv_complete(struct net *net, struct tipc_aead *aead,
19411941
goto rcv;
19421942
if (tipc_aead_clone(&tmp, aead) < 0)
19431943
goto rcv;
1944+
WARN_ON(!refcount_inc_not_zero(&tmp->refcnt));
19441945
if (tipc_crypto_key_attach(rx, tmp, ehdr->tx_key, false) < 0) {
19451946
tipc_aead_free(&tmp->rcu);
19461947
goto rcv;
19471948
}
19481949
tipc_aead_put(aead);
1949-
aead = tipc_aead_get(tmp);
1950+
aead = tmp;
19501951
}
19511952

19521953
if (unlikely(err)) {

0 commit comments

Comments
 (0)