Skip to contentSkip to conversation

net/af_iucv: fix NULL deref in afiucv_hs_callback_syn()

PATCH New Hidayath Khan 1 participant 1 message Jul 6

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/af_iucv: fix NULL deref in afiucv_hs_callback_syn()

afiucv_hs_callback_syn() allocates the child socket with GFP_ATOMIC, which can fail and return NULL. The connection-refused branch is entered when the listen state check fails, the accept backlog is full, or nsk is NULL - and unconditionally calls iucv_sock_kill(nsk). When entered due to allocation failure, iucv_sock_kill() dereferences the NULL pointer at the sock_flag(sk, SOCK_ZAPPED) check, causing a NULL pointer dereference in softirq context.

Only kill the child socket if it was actually allocated.

Fixes 3881ac441f64 ("af_iucv: add HiperSockets transport")
---
 net/iucv/af_iucv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/iucv/af_iucv.c +2 -1
index 890d9df5ae36..a471fbe178e8 100644
@@ -1875,7 +1875,8 @@ static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb)
 		afiucv_swap_src_dest(skb);
 		trans_hdr->flags = AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_FIN;
 		err = dev_queue_xmit(skb);
-		iucv_sock_kill(nsk);
+		if (nsk)
+			iucv_sock_kill(nsk);
 		bh_unlock_sock(sk);
 		goto out;
 	}
Signature · 1 line
2.52.0