nfc: llcp: fix UAF on socket in nfc_llcp_tx_work()
Subsystems (3)
PATCH 1/1 nfc: llcp: fix UAF on socket in nfc_llcp_tx_work()
Shuangpeng Bai reported a slab-use-after-free in nfc_llcp_tx_work():
BUG: KASAN: slab-use-after-free in _raw_spin_lock_irqsave Write of size 4 at addr ffff88811da9cb94 by task kworker/0:0/9 Call Trace: _raw_spin_lock_irqsave (kernel/locking/spinlock.c:166) skb_queue_tail (net/core/skbuff.c:4114) nfc_llcp_tx_work (net/nfc/llcp_core.c:848)
When transmitting an I-frame, nfc_llcp_tx_work() creates a copy via skb_copy() to keep in tx_pending_queue. If the socket is closed concurrently, freeing the original skb during nfc_data_exchange() drops sk_wmem_alloc to 0 and destroys the socket before copy_skb is queued to llcp_sock->tx_pending_queue.
Call skb_set_owner_w(copy_skb, sk) to keep the socket alive while copy_skb is queued.
---
Cc: David Heidelberg <[email protected]>
Cc: [email protected]
--- net/nfc/llcp_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/nfc/llcp_core.c +4 -1
@@ -786,8 +786,11 @@ static void nfc_llcp_tx_work(struct work_struct *work)print_hex_dump_debug ("LLCP Tx: " ,DUMP_PREFIX_OFFSET ,16 ,1 , skb->data, skb->len, true); -if (ptype ==LLCP_PDU_I ) +if (ptype ==LLCP_PDU_I ) { copy_skb =skb_copy (skb,GFP_ATOMIC ); +if (copy_skb) +skb_set_owner_w (copy_skb, sk); + }__net_timestamp (skb);
Signature · 1 line
2.55.0.766.g2966f0265a-goog
Thanks for your patch!
Quoted 50 lines · Eric Dumazet
Shuangpeng Bai reported a slab-use-after-free in
nfc_llcp_tx_work():BUG: KASAN: slab-use-after-free in _raw_spin_lock_irqsave Write of size 4 at addr ffff88811da9cb94 by task kworker/0:0/9 Call Trace: _raw_spin_lock_irqsave (kernel/locking/spinlock.c:166) skb_queue_tail (net/core/skbuff.c:4114) nfc_llcp_tx_work (net/nfc/llcp_core.c:848)When transmitting an I-frame,
nfc_llcp_tx_work()creates a copy viaskb_copy()to keep intx_pending_queue. If the socket is closed concurrently, freeing the original skb duringnfc_data_exchange()dropssk_wmem_allocto 0 and destroys the socket beforecopy_skbis queued tollcp_sock->tx_pending_queue.Call
skb_set_owner_w(copy_skb, sk)to keep the socket alive whilecopy_skbis queued.Fixes be02b6b62400 ("NFC: Queue a copy of the transmitted LLCP skb")Reported-by Shuangpeng Bai <[email protected]>Signed-off-by Eric Dumazet <[email protected]>---
Cc: David Heidelberg <[email protected]>
Cc: [email protected]
---net/nfc/llcp_core.c| 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)net/nfc/llcp_core.c +4
-1@@ -786,8 +786,11 @@ static void nfc_llcp_tx_work(struct work_struct *work)print_hex_dump_debug ("LLCP Tx: " ,DUMP_PREFIX_OFFSET ,16 ,1 , skb->data, skb->len, true); -if (ptype ==LLCP_PDU_I ) +if (ptype ==LLCP_PDU_I ) { copy_skb =skb_copy (skb,GFP_ATOMIC ); +if (copy_skb) +skb_set_owner_w (copy_skb, sk); + }__net_timestamp (skb);Signature · 1 line
2.55.0.766.g2966f0265a-goog