From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id E64AC8002A for ; Wed, 25 Nov 2026 06:23:00 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AP6LkGg016523; Wed, 25 Nov 2026 09:21:46 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP6LkGg016523 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="ckPg9m8C" Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AP6Lb3s016473 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 25 Nov 2026 09:21:37 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP6Lb3s016473 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-c5051881421so395794466b.2 for ; Tue, 24 Nov 2026 22:21:37 -0800 (PST) X-Gm-Message-State: APuU4Z/DohOfaJfo0CGytrEJTcxyIM95O1yZ6tYrG2UamhwG6bnUR7qL or5i7QuuW3crzbU3s/gfftbNZ7MJ1m0xecTmCN2wpqnfd8Bs92gQqrUCDRFSf17zSOP6TwDKkdo iVkKgGqucSYfHKTMYXa/p5Yyyd92W5LJNytcP9boJ6ajcDK5Bm7u3Gg== X-Gm-Gg: AZFdTZfCwx+znk+00hnwuoiiUZIRbofKLaraueCACiHmKxchqpbjhT7D8Nk6BohKoP3 twH+OMu8uz7d2ANhruLQm8Ic0UEuj91R2wuCwWySTvuEsEUcS1EbIFubLGHdo0tu/tCwcpst6PT 4ttp9pHiAV+u1qpo9LrTMr98kIGv6lb4LARIL4UvWz33a3IYz8XCkbyzIBkb+ZqgAopEoXCL8oB S0yYtcdtdGko1wiIhOAfeaxVLf5cwK2FebX1DDEiBcYINraibCQvfp0TOhsKLALKdc+KHZREN+6 t5wU2su5Fvs3MuChiVmzIv5A4qoOJzHY/uPV/hlF8S0Vu99SUOUOqjoKIQrxjSp+Ycv0CnqPbIL ywtHUvKrqjQzJ+F9b+8/9u53S X-Received: by 2002:a17:906:1408:b0:c51:fcf:a966 with SMTP id a640c23a62f3a-c513aaade52mr1001380866b.35.1795587697365; Tue, 24 Nov 2026 22:21:37 -0800 (PST) X-Received: by 2002:a17:906:1408:b0:c51:fcf:a966 with SMTP id a640c23a62f3a-c513aaade52mr1001379966b.35.1795587696830; Tue, 24 Nov 2026 22:21:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795587696; cv=none; d=google.com; s=arc-20260327; b=criwf0eUGbkcTU1XPpJeFVJQFEb5ntCiRRtwe2NqKYw19ixuIxfVSx8bG7Du+7XREt LgRQrsC0+qdULdMPxtpgFuyuve+tP/VjhMQfq9M42oHwAc/aqFx5HhOdz9JJj4tR2B+0 9kM0EGKQHdkGwcbZLghvui3q82LMpq22zj1uCCAO6dKobZin1BOA+67CApuj0UV8fSMm QU1Dqn8fd2obth1IkbdkeR5fmDRfG8nqzQ+KsREqQX6FaJk3gHIfr2KTutYevLLzXpVx C2FZ+x26Q75jJ7SK4Ev85ZXt5bFo3wSFB63ee6m/Rwmyf3N7jzy+F1iscvvspbizSwU+ JYQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=jEiHe4ONZadpI+jVWIGZBndS4uw2VCiP4Kud/Xb2D1U=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=LwNwZkzKFbB4fZ7b6iJQZ6WWYmQl6fMFNgP7kcxKmkTZWyDAgrP1EcV1SyU+s8wv4i Kvtup4gYLgfvdem9qZK3FElmqe8z83TlNIa8klXUOsmpMAkB9dl74KOIWKOBqhY+RqcR FR+w4Wx0E8uiqZKz1woonXZgFnwQX/KSVDmaz1SsP7EyDLLt+1wb/01Zy/Ksm8AqgZEJ UBH+I7ae0Od6wQ9xsFArE6JZ5M+jQTrJAfWvPisHnzq1+eaAm9TJzjfEhe3+ToJAu2hM rEnx91oasYUuEqmyXQdHlThcZw0CF3sb6awgTPmXSLE+ypkibmLuoNPaiLSfsd4e1ba2 GCSQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=ckPg9m8C; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id a640c23a62f3a-c513b0aac55si1099828666b.331.2026.11.24.22.21.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 22:21:36 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=ckPg9m8C; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=jEiHe4ONZadpI+jVWIGZBndS4uw2VCiP4Kud/Xb2D1U=; b=ckPg9m8C9BHa kraYBGaBWSK4rsEncyULR7S0B8YYv3l+iaaLQfAfjz0ivkQ3A7Tkf2fau0uC0flKpwRgMSg4RTCDe 4njPIFiBdHNyjh5+2y/QDLV4yQBISNE6osEl6VmQJrCi3ow4SpchPEUV7X8SLW1s4/X+aDEXxT1nC 7vJmoy63iz9pe8fXsWNwkPmQ67nqPOZ+n6pdaeNYNTNBacnOL52Xto2VMzprV/cN5nz64wRaa4taP oiGXFVlC08cvS8XCVS3WVm7jd7jvFEL5sMRS60QghYho+qIjzF4NL700WI7RZ/tpjXQwczgSLCR8C wBCzyGXnwqo1GIIfsv0YJQ==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xW6Nh-006mb7-1X; Wed, 25 Nov 2026 07:21:36 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Wed, 25 Nov 2026 08:14:12 +0200 Message-ID: <20261125062128.1996509-3-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125062128.1996509-1-eva.kurchatova@virtuozzo.com> References: <20261125062128.1996509-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 2/8] ms/net: restore refcount ordering for lockless socket access X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Hyunwoo Kim [ Upstream commit 5b5d8f351dd96f56a58bb516a80e2d4d742fe4e2 ] Before commit fb041bb7c0a9 ("locking/refcount: Consolidate implementations of refcount_t"), default builds implemented refcount_inc_not_zero() using atomic_add_unless(), which provided full memory ordering on success. The commit removed that ordering on weakly ordered architectures, allowing accesses after a successful reference acquisition to be reordered before it. Use refcount_inc_not_zero_acquire() in the IPv4 and IPv6 established lookups and in inet_twsk_purge(), where the socket is validated again after taking a reference. bpf_sk_assign() can receive a socket pointer obtained through BTF without a reference. Use acquire ordering when it takes its own reference for a refcounted socket. Use refcount_set_release() when setting refcounts in the SYN cookie, TCP Fast Open, request migration, and TIME_WAIT paths. Keep the existing TIME_WAIT smp_wmb(), which separately orders the refcount store before ehash publication. Fixes: fb041bb7c0a9 ("locking/refcount: Consolidate implementations of refcount_t") Fixes: 27e5203bd9c5 ("bpf: Change bpf_sk_assign to accept ARG_PTR_TO_BTF_ID_SOCK_COMMON") Cc: stable@vger.kernel.org Signed-off-by: Hyunwoo Kim Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261029214219.1035176-3-imv4bel@gmail.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin (cherry picked from commit 6f4fc93f76cd8ebd3c89a064573715503048d1ad) https://virtuozzo.atlassian.net/browse/VSTOR-156045 Feature: fix ms/net Signed-off-by: Eva Kurchatova Reviewed-by: Sashiko --- net/core/filter.c | 2 +- net/ipv4/inet_connection_sock.c | 6 +++--- net/ipv4/inet_hashtables.c | 2 +- net/ipv4/inet_timewait_sock.c | 4 ++-- net/ipv4/syncookies.c | 2 +- net/ipv4/tcp_fastopen.c | 2 +- net/ipv6/inet6_hashtables.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index b976eaabedd2..3b0ca58da7b5 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -7564,7 +7564,7 @@ BPF_CALL_3(bpf_sk_assign, struct sk_buff *, skb, struct sock *, sk, u64, flags) if (sk_unhashed(sk)) return -EOPNOTSUPP; if (sk_is_refcounted(sk) && - unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) + unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt))) return -ENOENT; skb_orphan(skb); diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 37da27cf66be..05ccc95cd7bd 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1070,8 +1070,8 @@ static void reqsk_timer_handler(struct timer_list *t) * hold another count to prevent use-after-free and * call reqsk_put() just before return. */ - refcount_set(&nreq->rsk_refcnt, 2 + 1); timer_setup(&nreq->rsk_timer, reqsk_timer_handler, TIMER_PINNED); + refcount_set_release(&nreq->rsk_refcnt, 2 + 1); reqsk_queue_migrated(&inet_csk(nsk)->icsk_accept_queue, req); req = nreq; @@ -1415,7 +1415,7 @@ struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child, goto child_put; } - refcount_set(&nreq->rsk_refcnt, 1); + refcount_set_release(&nreq->rsk_refcnt, 1); if (inet_csk_reqsk_queue_add(sk, nreq, child)) { __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMIGRATEREQSUCCESS); reqsk_migrate_reset(req); @@ -1469,7 +1469,7 @@ void inet_csk_listen_stop(struct sock *sk) if (nsk) { nreq = inet_reqsk_clone(req, nsk); if (nreq) { - refcount_set(&nreq->rsk_refcnt, 1); + refcount_set_release(&nreq->rsk_refcnt, 1); rcu_read_lock(); if (inet_csk_reqsk_queue_add(nsk, nreq, child)) { diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index b0f0c7c45917..866c758af08f 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -510,7 +510,7 @@ 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; if (unlikely(hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) || !inet_match(net, sk, acookie, ports, dif, diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index cf84a3c7de14..943693040a8c 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c @@ -139,7 +139,7 @@ void inet_twsk_hashdance_schedule(struct inet_timewait_sock *tw, * Also note that after this point, we lost our implicit reference * so we are not allowed to use tw anymore. */ - refcount_set(&tw->tw_refcnt, 3); + refcount_set_release(&tw->tw_refcnt, 3); /* Ensure tw_refcnt has been set before tw is published. * smp_wmb() provides the necessary memory barrier to enforce this @@ -324,7 +324,7 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo) if (refcount_read(&sock_net(sk)->ns.count)) continue; - if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) + if (unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt))) continue; if (refcount_read(&sock_net(sk)->ns.count)) { diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 153559eb679f..bba484725a1e 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -204,7 +204,7 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb, child = icsk->icsk_af_ops->syn_recv_sock(sk, skb, req, dst, NULL, &own_req, NULL); if (child) { - refcount_set(&req->rsk_refcnt, 1); + refcount_set_release(&req->rsk_refcnt, 1); sock_rps_save_rxhash(child, skb); if (rsk_drop_req(req)) { diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index 9c1173f1bddd..9764f72aeaf0 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -278,7 +278,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk, tcp_reset_xmit_timer(child, ICSK_TIME_RETRANS, req->timeout, false); - refcount_set(&req->rsk_refcnt, 2); + refcount_set_release(&req->rsk_refcnt, 2); sk_mark_napi_id_set(child, skb); diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c index 70633fed6e6a..dee00ba290f6 100644 --- a/net/ipv6/inet6_hashtables.c +++ b/net/ipv6/inet6_hashtables.c @@ -71,7 +71,7 @@ struct sock *__inet6_lookup_established(const struct net *net, continue; if (!inet6_match(net, sk, saddr, daddr, ports, dif, sdif)) continue; - if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) + if (unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt))) goto out; if (unlikely(hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) || -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel