Article View: linux.kernel.netdev
Article #6793Re: [PATCH net] inet: reject unhashed sockets during established lookups
From: netdev-bot+sashiko
Date: Fri, 23 Oct 2026 11:39
Date: Fri, 23 Oct 2026 11:39
143 lines
13121 bytes
13121 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (1) · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The new reader-side check does not order later loads of socket
fields.
Pre-existing issues:
- [Medium] When a tuple matches but refcount_inc_not_zero_acquire()
fails, __inet_lookup_established()…
--
inet: reject unhashed sockets during established lookups
This patch changes __inet_lookup_established() and
__inet6_lookup_established() to take the reference with
refcount_inc_not_zero_acquire(). After taking it, the lookup now restarts
if the nulls node is unhashed. It also switches the initial nonzero
refcount stores in the SYN cookie, TFO, request migration and TIME_WAIT
paths to refcount_set_release(), and frees published requests with
reqsk_put().
[ ... ]
> diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
> index ba0faa9ae2bb3..7ffa9171d6de1 100644
> --- a/net/ipv4/inet_hashtables.c
> +++ b/net/ipv4/inet_hashtables.c
> @@ -550,10 +550,11 @@ struct sock *__inet_lookup_established(const struct net *net,
> if (sk->sk_hash != hash)
> continue;
> if (likely(inet_match(net, sk, acookie, ports, dif, sdif))) {
> - if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
> + if (unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt)))
> goto out;
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. When
the tuple matches but the refcount increment fails, the lookup still
does goto out and returns NULL instead of restarting.
Documentation/RCU/rculist_nulls.rst restarts the lookup in this case.
Can this miss a live socket that is in the same chain? Here is one window.
In reqsk_timer_handler(), inet_reqsk_clone() does:
memcpy(nreq_sk, req_sk,
offsetof(struct sock, sk_dontcopy_begin));
This copies skc_hash and the tuple from oreq, but not skc_refcnt. Until
reqsk_timer_handler() reaches this line:
refcount_set_release(&nreq->rsk_refcnt, 2 + 1);
nreq carries oreq's hash and tuple with a refcount of 0 left over from its
previous life. During that time oreq is still hashed in the same chain.
A reader whose stale pointer lands on nreq passes the hash and tuple
checks and fails the increment. It then returns NULL without reaching
oreq.
tcp_v4_rcv() then falls back to the listener. For an ACK,
tcp_rcv_state_process() in TCP_LISTEN returns 1, so a RST is sent for a
valid handshake. A similar window exists for a replaced req whose
refcount has already dropped to 0.
A restart has a cost of its own. reqsk_queue_hash_req() hashes a req
before it sets the refcount, so a restarting reader would have to spin
past that window. The window is kept short with preempt_disable_nested().
The same goto out exists in __inet6_lookup_established().
> - if (unlikely(!inet_match(net, sk, acookie,
> - ports, dif, sdif))) {
> + if (unlikely(hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) ||
> + !inet_match(net, sk, acookie, ports, dif,
> + sdif))) {
[Severity: Medium]
On weakly ordered CPUs such as arm64 and POWER, does this check order the
caller's later loads of socket fields?
hlist_nulls_unhashed_lockless() is only:
return !READ_ONCE(h->pprev);
Branching on it creates a control dependency. That orders later stores,
but not later loads.
For full child sockets, the acquire in refcount_inc_not_zero_acquire()
does not seem to pair with a release either. sk_clone() publishes the
refcount with a plain store:
smp_wmb();
refcount_set(&newsk->sk_refcnt, 2);
After that store, inet_csk_clone_lock() writes the child's tuple, clears
icsk_accept_queue, and changes sk_state from the TCP_LISTEN value copied
from the parent to TCP_SYN_RECV. tcp_v4_syn_recv_sock() hashes the child
last.
A stale reader could then see a non-NULL pprev and the new tuple, but
still load the parent's TCP_LISTEN when tcp_v4_rcv() reads sk_state:
if (sk->sk_state == TCP_LISTEN) {
ret = tcp_v4_do_rcv(sk, skb);
goto put_and_return;
}
That path skips bh_lock_sock_nested(). The packet is processed on the
child without its lock while the creating CPU still holds that lock and
is finishing setup. The result is either a RST from listener handling or
unlocked SYN_RECV processing that races with the creator.
The commit message says:
This rejects the SYN cookie
request socket and blocks the child socket path observed in the x86
test.
Does this hold only under x86 TSO? Is an smp_rmb() (or an acquire load of
pprev) needed after the hashed check, with matching ordering on the
writer side?
The same check in __inet6_lookup_established() has the same ordering
question.
> sock_gen_put(sk);
> goto begin;
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/ath58Egc-oI6p3Jl%40v4bel
Technical Details
Message-ID:
<179275558269.3134.17308052093423946226@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351042-linux-kernel-netdev=dewy.ruReferences:
<ath58Egc-oI6p3Jl@v4bel>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351042-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] inet: reject unhashed sockets during established lookups Date: Fri, 23 Oct 2026 11:39:42 +0000 Organization: Usenet Network Message-ID: <179275558269.3134.17308052093423946226@kernel.org> References: <ath58Egc-oI6p3Jl@v4bel> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="487652"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:t9nPIz7GOb5dFYiYi+EpA4E7KXQ= sha256:jynwT+YVWObf/s7wEHlJYTpaImo/pY7WA/LSqw7rTtQ= sha1:uqCiRoLwnaDayz6M4B7upBNSNXY= sha256:CC+GuAu0OoKjKTkIs/tjA1ZmPPpKbXBafpGU7AjlCBg= 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 918D110DA2B; Fri, 23 Oct 2026 14:43:21 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.738 X-Spam-Status: No, score=-3.738 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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=kernel.org 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 k34l0aidFx_j; Fri, 23 Oct 2026 14:43:17 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-351042-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id CFF4310D5A5; Fri, 23 Oct 2026 14:43:08 +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 7D0C33C145; Fri, 23 Oct 2026 11:39:45 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1792755585; b=0u37zzTO7stgbTrMIb/cMT8FCLPr04pVDQGiF+tPzimmdZ+APGA8S2UE687oqxg6juI0 8HNT1GeQsr90wgQcpA6AQeCUvbSggTgUwqZIPcy7m70GpSbn8nW2d5cThVWJcM5skGteF pE295x+73E154NkJm9Fc3IQ+6pQ+/fuYKM+Ha9z+NdUZK4FEZaRDGMuqvtoScujfRdV5I 3t4sf44uaXt+O7Li3CVho/H2hdvagUdC/PCF6ypgwywEia6PiOkcjC6SiEeqNDTgr6Eu6 dOwa7BA3dYXu3vWDziP9LR+WTdQBukEMNkXcIY0WjjgQSazW8ByxDfcSCqqfqRiqv3Q== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792755585; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=Q6S79bbMaNSuqrqpLiqNPimBxEwlH1ndoIlreZhWFgs=; b=YP7vOgbS9r/L3+v65IMGnH2LpjpLPaXdtcO+shmVKlQ9Nf/Q82md9qBm1/t4udV0wDRU oPV/TETsACHB88liHPy9VqyHf7Lb1ACF1L4MxhVrIHARfwOvZlJpDkVGz1miGmqa6P1Ef sho1K6V9M+RmJNH4H7mQULC/X19lo/9t7f1pIxOuv917DQr1xGxfXDJ7ZT0lvsYtaloUU gyJA/Eip9xSF2iRFCUe9Xu6R/mgCagl+V4qyG/wu3BT2jwt7A9jZrrRmnrUdZyCmMxJh4 RnECwwAoabNjOSr9Isqyu2DrS22BRDtHHldY3TjdV35b0GdYK63p9s6hTwe+H8SsOAg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dXbu00Fg; arc=pass header.oldest-pass=0 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 54B0F606A323; Fri, 23 Oct 2026 11:39:45 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dXbu00Fg X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792755584; b=LfWb2z8wC/I+1nURZrecr4SPSC6MZ2XnlzKPvuOMcIBzs+d2U4m0ykg+hF2hwl3WiQyA lMiWVdEta29diYtEnWu+E/NL0bvAwfnIh4BRViGPIHYSYjjDK1tBQPUytn9YQsDi+0sH0 3jj5bqF2mhnJoQ+S+e5QxLVq/il7sOX3VkwUxew47gxNzO8TTlsBcAKCbzPaYoQ6GAc2q ehPdga8FR3W+y+n9C0cs5WN0W4opugyRuxS1n4w0dvN9wibCaeW09RV8lE6r6RrlilEnl ArLhuni6B/6lHBAvXWlM6NeGn6RaTKjMMsmrV6rRrp1INyFIBrsDPZ4ggSnwmJhbiOA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792755584; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=Q6S79bbMaNSuqrqpLiqNPimBxEwlH1ndoIlreZhWFgs=; b=EMoD9DBb/BZfokuuCP6gRaTG0ad4keFy9USaeiAHJQe4sFfvSKoAeYCRwGjwZHGsSPqC ZDOM+KGYtqOyWNUedU2lQ/Uj4s8HO6qXtD4y7u8h9M8QENN1R9Xy3H6VhUtkdpXRhSDVd P3fCeyOVDJlFJaQMzKLqQ3ASKU5faxA6NQJa94xuE4ykWp3zLOd7uRU9n4e+Q84slB9LJ DWnJhtkPE7qvIb9evy2dcK7CD0vclFCuzLId6bHQiQonBL2Uv1+RP1HWyBukWFDGVv/Py foULRxsKv1H6OD+Xxq+Q21z3Lcyqyi2AvR7pHyz/DzN4UHQc+6MIBFmRUEFoCGOnRhg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dXbu00Fg; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F9FC606A31A for <netdev@vger.kernel.org>; Fri, 23 Oct 2026 11:39:44 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DEFF1F01825; Fri, 23 Oct 2026 11:39:43 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1792755583; bh=Q6S79bbMaNSuqrqpLiqNPimBxEwlH1ndoIlreZhWFgs=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=dXbu00FgxNz/J6C1nxky8UQOXaBC40ne0Z/z/88qchfSIY000BuEmYr5UqMV9/eMH 5nKX5ieIviSs5jqALqBjXMc5XifeBvJGWgbTWx3gNv4IPM/kT+OFn5hR8ukHO2k/TX NJ0uat0w/hXw/ZF+rvv39bCEQfmAnV5Nm0S1O8gpejnyhZZq9dT6qBMUy7YItD3trg 053zDTwbn32HPCbqUIBy8OWPYZcnb0EMxtJzpSI9A5W6Igb/EtB+06ou7ZDOYr0J5a h3DhK3DSF6voUToL7zVvVucGgpMYMvvUIKSOVXD4IEOLZHW9UAXlogaNrHEj7ADXz9 Grrtx4sDGrFyg== X-Cc: edumazet@kernel.org, ncardwell@google.com, kuniyu@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, martin.lau@linux.dev, john.fastabend@gmail.com, weiwan@google.com, sd@queasysnail.net, jiayuan.chen@linux.dev, netdev@vger.kernel.org X-In-Reply-To: <ath58Egc-oI6p3Jl@v4bel> X-sashiko-severity: Medium 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