Article View: linux.kernel.netdev
Article #25210[PATCH net v3 2/2] net/x25: re-check x25->neighbour after re-acquiring the socket lock
From: Martin Schiller
Date: Tue, 01 Dec 2026 12:01
Date: Tue, 01 Dec 2026 12:01
94 lines
13913 bytes
13913 bytes
x25_sendmsg(), x25_output() and x25_recvmsg() release the socket lock
while they wait for memory or data, and use x25->neighbour once they
own the socket again. The call may have been cleared in the meantime:
x25_disconnect() drops the neighbour reference and sets x25->neighbour
to NULL, for example when a CLEAR REQUEST from the peer or a link
failure is processed in softirq context while the socket is not owned.
sock_alloc_send_skb() only notices this if the disconnect happened
before its error checks. A disconnect during the allocation, or before
lock_sock() returns, leads to a NULL pointer dereference when
x25_sendmsg() builds the packet header or in the fragmentation loop of
x25_output(). In x25_recvmsg(), x25_disconnect() leaves x25->condition
alone, so if the receiver was busy, x25_check_rbuf() sends an RR
through x25_write_internal(), which dereferences x25->neighbour too.
Re-check x25->neighbour after lock_sock(): fail with -ENOTCONN in
x25_sendmsg() and x25_output(), and skip x25_check_rbuf() in
x25_recvmsg(), which still returns the data it has dequeued. Fragments
already queued by x25_output() have been purged by x25_disconnect() at
that point.
The x25_sendmsg() and x25_output() cases were also pointed out by the
netdev AI review of an earlier version of the x25_kill_by_neigh() fix.
Krystian Kaniewski found the x25_recvmsg() case by code inspection and
reproduced all three in QEMU without modifying the kernel: a second
thread owns the socket, stalled in a userfaultfd copy, while sendmsg()
or recvmsg() waits with the lock dropped, and a CLEAR REQUEST from the
peer goes to the backlog. Without this patch, KASAN reports a NULL
pointer dereference in x25_sendmsg(), in x25_output() or, called from
x25_check_rbuf(), in x25_write_internal(). With it, send() fails with
ENOTCONN and recv() returns the data.
Fixes: 4becb7ee5b3d ("net/x25: Fix x25_neigh refcnt leak when x25 disconnect")
Reported-by: Krystian Kaniewski <krystianmkaniewski@gmail.com>
Closes: https://lore.kernel.org/all/02419845-bab8-4e36-9a98-6830761da1b9@gmail.com/
Link: https://lore.kernel.org/all/179121364205.434549.10310203820251738113@kernel.org/
Tested-by: Krystian Kaniewski <krystianmkaniewski@gmail.com>
Tested-by: Shuai Liu <847807867@qq.com>
Reviewed-by: Shuai Liu <847807867@qq.com>
Signed-off-by: Martin Schiller <ms@dev.tdt.de>
---
net/x25/af_x25.c | 10 +++++++++-
net/x25/x25_out.c | 6 ++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index 43c606a6bfa5a3cf69c905f230edf2c37a85e25d..1f9d5f7faffe26289f5723ade5d4d568a522fae6 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -1248,6 +1248,12 @@ static int x25_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
lock_sock(sk);
if (!skb)
goto out;
+
+ /* The call may have been cleared while the socket was unlocked */
+ rc = -ENOTCONN;
+ if (!x25->neighbour)
+ goto out_kfree_skb;
+
X25_SKB_CB(skb)->flags = msg->msg_flags;
skb_reserve(skb, X25_MAX_L2_LEN + X25_EXT_MIN_LEN);
@@ -1433,7 +1439,9 @@ static int x25_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
msg->msg_namelen = sizeof(*sx25);
}
- x25_check_rbuf_owned(sk);
+ /* The call may have been cleared while the socket was unlocked */
+ if (x25->neighbour)
+ x25_check_rbuf_owned(sk);
rc = copied;
out_free_dgram:
skb_free_datagram(sk, skb);
diff --git a/net/x25/x25_out.c b/net/x25/x25_out.c
index f710d015fcc2ffd6a6922a0c29876bb248125666..89858a3fdf428b3eae5f9c8ba54fee82f73fd0d9 100644
--- a/net/x25/x25_out.c
+++ b/net/x25/x25_out.c
@@ -78,6 +78,12 @@ int x25_output(struct sock *sk, struct sk_buff *skb)
return err;
}
+ /* The call may have been cleared while unlocked */
+ if (!x25->neighbour) {
+ kfree_skb(skbn);
+ return -ENOTCONN;
+ }
+
skb_reserve(skbn, frontlen);
len = max_len > skb->len ? skb->len : max_len;
--
2.47.3
Technical Details
Message-ID:
<20261201-x25-kill-by-neigh-v3-2-7f05bdff15b1@dev.tdt.de>Path:
mbox-mo1.pugleaf.net!news-ams.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374997-linux-kernel-netdev=dewy.ruReferences:
<20261201-x25-kill-by-neigh-v3-0-7f05bdff15b1@dev.tdt.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-ams.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374997-linux-kernel-netdev=dewy.ru From: ms@dev.tdt.de (Martin Schiller) Newsgroups: linux.kernel.netdev Subject: [PATCH net v3 2/2] net/x25: re-check x25->neighbour after re-acquiring the socket lock Date: Tue, 1 Dec 2026 13:01:24 +0100 (CET) Organization: Usenet Network Message-ID: <20261201-x25-kill-by-neigh-v3-2-7f05bdff15b1@dev.tdt.de> References: <20261201-x25-kill-by-neigh-v3-0-7f05bdff15b1@dev.tdt.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1703596"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:3R9r6KUEQm/1PlP+KZ4j3oe3wQE= sha256:vPRS7nal/XSwnWyvRp85urFssOzEBm6fv3wA63mG2aY= sha1:7JINnNfDYN6hopSchsxb8TDP4Ow= sha256:BS3lV8TwJEEFeWCVol7OdUPnWUaVAgQsEeQiTw5OBlw= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 1ADEF11735E; Tue, 1 Dec 2026 15:02:18 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=dev.tdt.de X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Dfo7mXCvq2WF; Tue, 1 Dec 2026 15:02:14 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374997-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=dev.tdt.de X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 00A0911734A; Tue, 1 Dec 2026 15:02:05 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 74E8331E01; Tue, 1 Dec 2026 12:02:02 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796126521; b=LhXtMuCZw0uLeTy98S1xgdSCO/qlYK6cWvNUIsf28PKqxMxRi2rzcb1eXp1Y0zsvj2Ml yZXg1TXzJx2PLrOxGKs5p3b6z8KpGCVtpfwXt9phyeYwrQVsZBtdvQLacknPpO/YdjOLW VVn+whBDx58lPnuz2soCt54cLGrvpoaLpUfirZjeaXjVdAiD02BU86vg1o+VPElIsY1BK aXGpOlPQk/rY1lg7PsmF2YBEFSCcQBvGkMGg7vx26TPzejb5QHoEj/olmvj2WQGA306x2 +eK2g9P/4xFW9mVPQtMti95/D/bMtYxNJYllp2YkidXhLlZTApR2B+1rtdI1DLeOgZw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796126521; h=X-Original-To:Received:DMARC-Filter:Received:Received:DKIM-Signature: Received:Received:Received:From:Date:Subject:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-ID:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-purgate-type:X-purgate-ID: X-purgate; bh=6BN5dXEKGcmdDgjy7EgY+H2t1HnfALecEbBYfS6ymFc=; b=yae1RC6v6x8FXAhGJBKIhbZr2J2VCdcfgC1nA1O41rGlcw8gZbRYmsENXzOwpotiw4MW atu5so8KELfbgl/GnltVWHkJC6kbmHEzZOVWfdYLyGmFq3YsBcslrvUjlI3XPUcyc9WV3 zY0wT3pJ4l3SDYksPdytp8XbZa1/5Zn93bOQL+v7on4pooYk5vw4hIz4OEYQNexIuwNn9 DcEzYwvy0E7ct0JCIQx9ImIjLVC1gfgsoh3l1JBOVqIEpcZUiN6KwJ1ZKwWFOO21E+yH3 +i2JCQPNj6sDvr51Uji5xsdQt2hzwrm/OxyT5V5M7rD/+w0igyNF5WhqCgKX/dzpFkA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=dev.tdt.de header.i=@dev.tdt.de header.a=rsa-sha256 header.s=z1-selector1 header.b=kaTX6nCz; dmarc=pass header.from=dev.tdt.de; spf=pass smtp.mailfrom=dev.tdt.de; arc=fail smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF7DB606A329; Tue, 1 Dec 2026 12:02:01 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dev.tdt.de header.i=@dev.tdt.de header.a=rsa-sha256 header.s=z1-selector1 header.b=kaTX6nCz X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=194.37.255.70 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796126520; b=x8EW9Mk45r4idrVKW+a0PXv7X0Xaqss8ghRBt25dT6F9IsiFNfjFrt7udBYs91gfWlne cV8TtXF1mW3ztxEpgTEriuhIelCmrxX4o9QPHf9HRR1oW72PdyLi9SeMB6wq6D3H4eUYE qe/iBj+BP2helqg7vex2QF7jkn34wrF4ljxW44aVX6+37IGpGvKb8duPFdzZ2CsI94y+k Yl7NnAXNyX9sKIfcsSxYGysZxgeRDhUDb/JwvAZcpEtx4nrDjrkJdh51khQUH7u5Sleu8 P2Y47Rm43P9a0W1J+hDJdixBYgiVPnkinID301TJeiZ1cYiAdMomfOMvJlsi1PDL/ag== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796126520; h=DMARC-Filter:Received:Received:DKIM-Signature:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key:X-Spam-Status: X-Spam-Checker-Version:X-purgate-type:X-purgate-ID:X-purgate; bh=6BN5dXEKGcmdDgjy7EgY+H2t1HnfALecEbBYfS6ymFc=; b=SDbjgcoTeeuRvpwldDuVvvuHNiR7lj+1o0m2prxGK25d59Bgl6DvXks2NF/XhtB4J5N4 YL2oT4YAKaYTfl9mA1dM9fdeH2HkUsA7TcPz9lZQndFI99TAMAQbrUeqQH4XzUS/hbpH3 JdiSSxCSfqNzopajBSd+0J7PDIlSQ+WRXCEEeC8EDt+3xVmgxmplAVXy3/M8fxE5pFplz 2wDd2FVJK11ILAIJ/bJelOCLGPiNIZBrPP/3N1pg2n55mrLvYC/Vlw8VfX15WuxLst+py CHIFZA1HJbrG9Zg8JyqseEpPhykxDptErSJvCQ3k5SKY94oqSOdGq6FOljQb+m0wY8A== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=dev.tdt.de; spf=pass smtp.mailfrom=dev.tdt.de; dkim=pass header.d=dev.tdt.de header.i=@dev.tdt.de header.a=rsa-sha256 header.s=z1-selector1 header.b=kaTX6nCz; arc=none smtp.remote-ip=194.37.255.70 X-Received: from mxout70.expurgate.net (mxout70.expurgate.net [194.37.255.70]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E3BC606A320; Tue, 1 Dec 2026 12:02:00 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3E3BC606A320 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=dev.tdt.de X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dev.tdt.de X-Received: from [194.37.255.9] (helo=mxout.expurgate.net) by relay.expurgate.net with smtp (Exim 4.92) (envelope-from <prvs=6809d4f748=ms@dev.tdt.de>) id 1xYMYD-009McE-Gu; Tue, 01 Dec 2026 13:01:37 +0100 X-Received: from [195.243.126.94] (helo=securemail.tdt.de) by relay.expurgate.net with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <ms@dev.tdt.de>) id 1xYMYC-003zEG-OF; Tue, 01 Dec 2026 13:01:36 +0100 X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dev.tdt.de; s=z1-selector1; t=1796126496; bh=6BN5dXEKGcmdDgjy7EgY+H2t1HnfALecEbBYfS6ymFc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kaTX6nCz0r2ZzsxxARiZ8B/TqKOHk1T1vM/qzDJIrSi1iFRaBS7GVXLzv5RXMYEBB VogxNpT9SMjHPG7maSjXgy0LnMQhxLOnROT80WIJaEC9bdsHZrDZvLy9no+sALKjGN mNkuK0o2tgd3WiDKdQet65RqGPokMkxabP3/Z9dmMhpiXxB7Iva8W9gY+jeNudhoBY fm3mbVG9iGkXH9GYj/bLS6LMSLjZyaX/FB9ZAkG/0mF2hJMCPT1Z/cDexzeuIlTak7 mJR1lYEtw5HGWEt3O2xac5AUiPLvWWQ+uSOQ6oUrLktYaga9L1pxMn+NfjrsCaJNX0 lVUWj4mfVGeow== X-Received: from securemail.tdt.de (localhost [127.0.0.1]) by securemail.tdt.de (Postfix) with ESMTP id 05289240046; Tue, 1 Dec 2026 13:01:36 +0100 (CET) X-Received: from mail.dev.tdt.de (unknown [10.2.4.42]) by securemail.tdt.de (Postfix) with ESMTP id EBDDB240036; Tue, 1 Dec 2026 13:01:35 +0100 (CET) X-Received: from [127.0.1.1] (unknown [10.2.3.19]) by mail.dev.tdt.de (Postfix) with ESMTPSA id 9E2462B315; Tue, 1 Dec 2026 13:01:35 +0100 (CET) X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261201-x25-kill-by-neigh-v3-0-7f05bdff15b1@dev.tdt.de> X-Cc: linux-x25@vger.kernel.org, netdev@vger.kernel.org, Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>, Shuai Liu <847807867@qq.com>, Krystian Kaniewski <krystianmkaniewski@gmail.com>, syzbot+300375dfd44665f063a6@syzkaller.appspotmail.com, syzbot+9faa82ae2e94c5c7d2ef@syzkaller.appspotmail.com, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Martin Schiller <ms@dev.tdt.de> X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796126493; l=4008; i=ms@dev.tdt.de; s=20260220; h=from:subject:message-id; bh=7EDoegCMK5qFsXUiAjxxx+1N7l7VaoFQBYATq30Xrgw=; b=VDW5o3LCWNS6KJRH+9au7vETsg5OaNszSc9qAsCNtptqhqo0eQLVuMw1EWllNfDy79AlMeZNA MVEYaahK77mCJWreCVYzSMLnsZSSDpqQKO4bXSiHqEiNtShN3pwNG81 X-Developer-Key: i=ms@dev.tdt.de; a=ed25519; pk=MAojd7D5IafMnqCYSFC7hY/u/jppX58CLIEhsEsSOYE= X-purgate-type: clean X-purgate-ID: 151534::1796126497-C0E8B872-B627B028/0/0 X-purgate: clean