[PATCH net] phonet: fix use-after-free in can_respond()
From: Elkin Cruz
Date: Wed Nov 25 2026 - 17:16:43 EST
In can_respond(), ph is cached before pskb_may_pull(skb, 5). When
ph->pn_res == PN_PREFIX and pskb_may_pull() reallocates skb->head,
the check `if (ph->pn_res == PN_COMMGR)` dereferences the dangling ph
pointer before the code re-acquires ph = pn_hdr(skb).
Check for PN_COMMGR before calling pskb_may_pull() to avoid accessing
the potentially invalidated header pointer.
This issue was found while trying out new Clang static analysis checks for
kernel bug classes. The finding was triaged and fixed, and this commit
description was drafted with the help of AI, then verified by code
inspection and compile-tested against linux-next (not reproduced and not
runtime-tested on hardware).
Fixes: c3a90c788b74 ("Phonet: do not reply to indication reset packets")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Elkin Cruz <elkin@xxxxxxxxxx>
---
net/phonet/af_phonet.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index d89225d6bfd3..e70ade97bf17 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -294,10 +294,10 @@ static inline int can_respond(struct sk_buff *skb)
return 0;
ph = pn_hdr(skb);
- if (ph->pn_res == PN_PREFIX && !pskb_may_pull(skb, 5))
- return 0;
if (ph->pn_res == PN_COMMGR) /* indications */
return 0;
+ if (ph->pn_res == PN_PREFIX && !pskb_may_pull(skb, 5))
+ return 0;
ph = pn_hdr(skb); /* re-acquires the pointer */
pm = pn_msg(skb);
--
2.56.1.839.g22a8290db9-goog