net/af_iucv: fix NULL deref in afiucv_hs_callback_syn()
Subsystems (4)
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. If the allocation fails, nsk is NULL.
The connection-refused path is entered when the listen state check fails, the accept backlog is full, or nsk is NULL. The code unconditionally calls iucv_sock_kill(nsk) in that path.
iucv_sock_kill() does not accept a NULL socket pointer and immediately dereferences sk via sock_flag(sk, SOCK_ZAPPED). When nsk is NULL, calling iucv_sock_kill(nsk) results in a NULL pointer dereference.
Only call iucv_sock_kill() when a child socket was successfully allocated.
--- net/iucv/af_iucv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/iucv/af_iucv.c +2 -1
@@ -1872,7 +1872,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; }
base-commit: 262b2eac463d880a664cf92af1107b4f9d84ad37
Signature · 1 line
2.52.0
From: Hidayath Khan <[email protected]>
Sent: Thursday, July 9, 2026 9:18 PM
Quoted 27 lines
afiucv_hs_callback_syn()allocates the child socket withGFP_ATOMIC. If the allocation fails, nsk is NULL.The connection-refused path is entered when the listen state check fails, the accept backlog is full, or nsk is NULL. The code unconditionally calls
iucv_sock_kill(nsk)in that path.
iucv_sock_kill()does not accept a NULL socket pointer and immediately dereferences sk viasock_flag(sk, SOCK_ZAPPED). When nsk is NULL, callingiucv_sock_kill(nsk)results in a NULL pointer dereference.Only call
iucv_sock_kill()when a child socket was successfully allocated.Fixes 3881ac441f64 ("af_iucv: add HiperSockets transport")Reviewed-by Alexandra Winter <[email protected]>Signed-off-by Hidayath Khan <[email protected]>---
net/iucv/af_iucv.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/iucv/af_iucv.c +0
-0
net/iucv/af_iucv.c static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb) · line 1875
Quoted 5 lines
net/iucv/af_iucv.c +1
-1@@ -1872,7 +1872,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)
Hi Hidayath
why not to move this check into iucv_sock_kill()? would prevent from potential similar issues in the future
Quoted 8 lines
net/iucv/af_iucv.c +1
-0+iucv_sock_kill (nsk);bh_unlock_sock (sk); goto out; }base-commit:
262b2eac463d880a664cf92af1107b4f9d84ad37Signature · 1 line
2.52.0
Quoted 37 lines · Jedrzej
From: Hidayath Khan <[email protected]>
Sent: Thursday, July 9, 2026 9:18 PMQuoted 27 lines
afiucv_hs_callback_syn()allocates the child socket withGFP_ATOMIC. If the allocation fails, nsk is NULL.The connection-refused path is entered when the listen state check fails, the accept backlog is full, or nsk is NULL. The code unconditionally calls
iucv_sock_kill(nsk)in that path.
iucv_sock_kill()does not accept a NULL socket pointer and immediately dereferences sk viasock_flag(sk, SOCK_ZAPPED). When nsk is NULL, callingiucv_sock_kill(nsk)results in a NULL pointer dereference.Only call
iucv_sock_kill()when a child socket was successfully allocated.Fixes 3881ac441f64 ("af_iucv: add HiperSockets transport")Reviewed-by Alexandra Winter <[email protected]>Signed-off-by Hidayath Khan <[email protected]>---
net/iucv/af_iucv.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/iucv/af_iucv.c +0
-0net/iucv/af_iucv.c static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb) · line 1875
Quoted 5 lines
net/iucv/af_iucv.c +1
-1@@ -1872,7 +1872,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)Hi Hidayath
Quoted 2 lines
why not to move this check into
iucv_sock_kill()? would prevent from potential similar issues in the future
Hi Jedrzej,
Every other call to iucv_sock_kill() passes a non-NULL socket by construction.
If iucv_sock_kill() silently accepted NULL, a future caller wrongly passing NULL would go unnoticed instead of being caught.
Quoted 11 lines
Quoted 9 lines
net/iucv/af_iucv.c +1
-0+iucv_sock_kill (nsk);bh_unlock_sock (sk); goto out; }base-commit:
262b2eac463d880a664cf92af1107b4f9d84ad37Signature · 1 line
2.52.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] Newly allocated sockets and their pinned net_devices are permanently leaked on error paths because iucv_sock_kill() ignores sockets without the SOCK_ZAPPED flag.
- [High] Missing socket reference count (sock_hold) when searching the global socket list leads to a Use-After-Free vulnerability.
- [High] In-place modification of potentially shared/cloned SKBs corrupts data for concurrent consumers, and missing headroom checks cause panics.
- [High] Unlocked traversal of the accept_q leads to list corruption and data races.
--
--- Patch [1]: [PATCH net] net/af_iucv: fix NULL deref in afiucv_hs_callback_syn() --- commit df9d50569da59293e9b6bc6ce2e2ee48847f1ed8
Author: Hidayath Khan <[email protected]>
net/af_iucv: fix NULL deref in afiucv_hs_callback_syn()
afiucv_hs_callback_syn() allocates the child socket with GFP_ATOMIC. If the allocation fails, nsk is NULL. The connection-refused path unconditionally calls iucv_sock_kill(nsk), resulting in a NULL pointer dereference, which this patch fixes by checking if nsk is valid.
net/iucv/af_iucv.c static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb)
Quoted 5 lines
net/iucv/af_iucv.c +0
-0@@ -1872,7 +1872,8 @@ static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb)
[Severity: High]
This is a pre-existing issue, but is there a missing reference count when looking up sockets?
In afiucv_hs_rcv(), the socket is found and the list lock is dropped without acquiring a reference:
net/iucv/af_iucv.c:afiucv_hs_rcv() {
...
read_unlock(&iucv_sk_list.lock);
if (!iucv)
sk = NULL;
...
err = afiucv_hs_callback_syn(sk, skb);
}Could another CPU concurrently close and destroy the socket, causing a use-after-free when afiucv_hs_callback_syn() calls bh_lock_sock(sk)?
net/iucv/af_iucv.c static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb) · line 1872
Quoted 1 line
net/iucv/af_iucv.c +0
-0afiucv_swap_src_dest (skb);
[Severity: High]
This isn't a bug introduced by this patch, but does afiucv_swap_src_dest() safely modify the SKB?
The SKB payload is modified in-place, but there is no check to ensure exclusive ownership:
net/iucv/af_iucv.c:afiucv_hs_rcv() {
...
trans_hdr = iucv_trans_hdr(skb);
EBCASC(trans_hdr->destAppName, sizeof(trans_hdr->destAppName));
...
}Could this corrupt packet data for concurrent consumers if the SKB is shared or cloned?
Additionally, afiucv_swap_src_dest() unconditionally pushes into the SKB headroom:
net/iucv/af_iucv.c:afiucv_swap_src_dest() {
...
skb_push(skb, ETH_HLEN);
memset(skb->data, 0, ETH_HLEN);
}If an untrusted packet is received with 0 headroom, will this cause an skb_under_panic?
net/iucv/af_iucv.c static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb) · line 1876
Quoted 5 lines
net/iucv/af_iucv.c +2
-1trans_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);
[Severity: High]
This is a pre-existing issue, but does iucv_sock_kill() actually clean up the socket here?
When iucv_sock_alloc() creates the socket, the SOCK_ZAPPED flag is cleared. However, iucv_sock_kill() immediately returns if SOCK_ZAPPED is not set:
net/iucv/af_iucv.c:iucv_sock_kill() {
if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket)
return;
...
}Does this mean newly allocated sockets and their pinned net_devices are permanently leaked on this error path?
net/iucv/af_iucv.c static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb) · line 1879
Quoted 3 lines
net/iucv/af_iucv.c +0
-0bh_unlock_sock (sk); goto out; }
[Severity: High]
This is a pre-existing issue, but is the accept queue safely protected against concurrent modifications?
In iucv_accept_dequeue(), the queue is traversed without holding accept_q_lock:
net/iucv/af_iucv.c:iucv_accept_dequeue() {
...
list_for_each_entry_safe(isk, n, &iucv_sk(parent)->accept_q, accept_q) {
...
}Meanwhile, iucv_accept_enqueue() modifies the same list from softirq context using the lock:
net/iucv/af_iucv.c:iucv_accept_enqueue() {
...
spin_lock_irqsave(&par->accept_q_lock, flags);
list_add_tail(&iucv_sk(sk)->accept_q, &par->accept_q);
spin_unlock_irqrestore(&par->accept_q_lock, flags);
}Since lock_sock(parent) does not block softirqs from acquiring bh_lock_sock, can iucv_accept_enqueue() run concurrently and corrupt the list pointers?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Thanks for the Sashiko AI review: On the findings it raised.
Finding 1: iucv_sock_kill() returns early unless SOCK_ZAPPED is set, and the flag is never set on a freshly allocated child socket, so the child socket and its pinned net_device leak on the error paths. I had already spotted this leak (in afiucv_hs_callback_syn() and iucv_callback_connreq()) and Alexandra Winter and I are looking into it.
Both NULL deref and child sock leak come from the same root cause, the child socket is allocated before the listen-state and accept-queue checks. I will address them together in v2 by allocating the child socket only after the listen-state and accept-queue checks, so the refused path has nothing to release (no NULL to guard and no child socket to free).
And on the transmit-failure path release the already-constructed child socket directly (dev_put, unlink, put the last reference) instead of relying on iucv_sock_kill().
Finding 2: missing sock_hold on the afiucv_hs_rcv() lookup. Agreed. Bryam Vargas has already submitted a patch for this.
The other findings look valid too. I will follow up on them separately.
Thanks,
Hidayath Khan
Quoted 38 lines · Hidayath Khan
afiucv_hs_callback_syn()allocates the child socket withGFP_ATOMIC. If the allocation fails, nsk is NULL.The connection-refused path is entered when the listen state check fails, the accept backlog is full, or nsk is NULL. The code unconditionally calls
iucv_sock_kill(nsk)in that path.
iucv_sock_kill()does not accept a NULL socket pointer and immediately dereferences sk viasock_flag(sk, SOCK_ZAPPED). When nsk is NULL, callingiucv_sock_kill(nsk)results in a NULL pointer dereference.Only call
iucv_sock_kill()when a child socket was successfully allocated.Fixes 3881ac441f64 ("af_iucv: add HiperSockets transport")Reviewed-by Alexandra Winter <[email protected]>Signed-off-by Hidayath Khan <[email protected]>--- net/iucv/af_iucv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/iucv/af_iucv.c +2
-1@@ -1872,7 +1872,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; }base-commit:
262b2eac463d880a664cf92af1107b4f9d84ad37
Alexandra Winter
maintainerQuoted 37 lines · Hidayath Khan
afiucv_hs_callback_syn()allocates the child socket withGFP_ATOMIC. If the allocation fails, nsk is NULL.The connection-refused path is entered when the listen state check fails, the accept backlog is full, or nsk is NULL. The code unconditionally calls
iucv_sock_kill(nsk)in that path.
iucv_sock_kill()does not accept a NULL socket pointer and immediately dereferences sk viasock_flag(sk, SOCK_ZAPPED). When nsk is NULL, callingiucv_sock_kill(nsk)results in a NULL pointer dereference.Only call
iucv_sock_kill()when a child socket was successfully allocated.Fixes 3881ac441f64 ("af_iucv: add HiperSockets transport")Reviewed-by Alexandra Winter <[email protected]>Signed-off-by Hidayath Khan <[email protected]>--- net/iucv/af_iucv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/iucv/af_iucv.c +2
-1@@ -1872,7 +1872,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; }
Quoted 1 line
base-commit:
262b2eac463d880a664cf92af1107b4f9d84ad37
Gentle ping to netdev maintainers:
Did this one get lost in the overflow?
It is all green in patchwork. Is there something you need us to do? Should we re-send it?
I don't see this as urgent or especially dangerous.
Kind regards
Alexandra
Paolo Abeni
maintainerQuoted 38 lines · Alexandra Winter
Quoted 37 lines · Hidayath Khan
afiucv_hs_callback_syn()allocates the child socket withGFP_ATOMIC. If the allocation fails, nsk is NULL.The connection-refused path is entered when the listen state check fails, the accept backlog is full, or nsk is NULL. The code unconditionally calls
iucv_sock_kill(nsk)in that path.
iucv_sock_kill()does not accept a NULL socket pointer and immediately dereferences sk viasock_flag(sk, SOCK_ZAPPED). When nsk is NULL, callingiucv_sock_kill(nsk)results in a NULL pointer dereference.Only call
iucv_sock_kill()when a child socket was successfully allocated.Fixes 3881ac441f64 ("af_iucv: add HiperSockets transport")Reviewed-by Alexandra Winter <[email protected]>Signed-off-by Hidayath Khan <[email protected]>--- net/iucv/af_iucv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/iucv/af_iucv.c +2
-1@@ -1872,7 +1872,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; }
Quoted 8 lines
Quoted 1 line
base-commit:
262b2eac463d880a664cf92af1107b4f9d84ad37Gentle ping to netdev maintainers:
Did this one get lost in the overflow?
It is all green in patchwork. Is there something you need us to do? Should we re-send it?
I don't see this as urgent or especially dangerous.
It's still alive in PW. Our backlog is unusually huge due to an unfortunate sequence of season holidays and conferences, but hopefully it should get back to normality someday in the future :)
/P
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Thu, 9 Jul 2026 21:17:32 +0200 you wrote:
afiucv_hs_callback_syn()allocates the child socket withGFP_ATOMIC. If the allocation fails, nsk is NULL.The connection-refused path is entered when the listen state check fails, the accept backlog is full, or nsk is NULL. The code unconditionally calls
iucv_sock_kill(nsk)in that path.[...]
Here is the summary with links:
- [net] net/af_iucv: fix NULL deref in afiucv_hs_callback_syn()
https://git.kernel.org/netdev/net/c/47a5116e56a6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html