From nobody Tue Dec 30 08:09:12 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81601C197A0 for ; Fri, 17 Nov 2023 16:49:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232906AbjKQQuA (ORCPT ); Fri, 17 Nov 2023 11:50:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbjKQQt7 (ORCPT ); Fri, 17 Nov 2023 11:49:59 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C5D583 for ; Fri, 17 Nov 2023 08:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700239795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=2xHmGuoMtPQwOYwidrVH9fzqJ2yR9Z3MUz8VIv42SVo=; b=frwBsBWnm2L/BWNduqEpW9YD/2DRrP1iVbTwMnavAlI5VhcrWnygLtPc+/ACa3rnZzjGSU kq65FJYAd60a85JHWN0DoaPnTaNnuSfs77A4LQcm/QyutOrYk9snCyXqJDYPI2siJ+XWOl DeMutp0XBNIoHSbihM0XCveV2T4B4ME= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-eX82f_qrP5Kokjcude60UQ-1; Fri, 17 Nov 2023 11:49:52 -0500 X-MC-Unique: eX82f_qrP5Kokjcude60UQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B205185A781; Fri, 17 Nov 2023 16:49:52 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.123]) by smtp.corp.redhat.com (Postfix) with SMTP id 0EE7B2166B27; Fri, 17 Nov 2023 16:49:50 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 17 Nov 2023 17:48:48 +0100 (CET) Date: Fri, 17 Nov 2023 17:48:46 +0100 From: Oleg Nesterov To: David Howells Cc: Al Viro , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rxrpc_find_service_conn_rcu: fix the usage of read_seqbegin_or_lock() Message-ID: <20231117164846.GA10410@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" rxrpc_find_service_conn_rcu() should make the "seq" counter odd on the second pass, otherwise read_seqbegin_or_lock() never takes the lock. Signed-off-by: Oleg Nesterov --- net/rxrpc/conn_service.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/rxrpc/conn_service.c b/net/rxrpc/conn_service.c index 89ac05a711a4..39c908a3ca6e 100644 --- a/net/rxrpc/conn_service.c +++ b/net/rxrpc/conn_service.c @@ -25,7 +25,7 @@ struct rxrpc_connection *rxrpc_find_service_conn_rcu(stru= ct rxrpc_peer *peer, struct rxrpc_conn_proto k; struct rxrpc_skb_priv *sp =3D rxrpc_skb(skb); struct rb_node *p; - unsigned int seq =3D 0; + unsigned int seq =3D 1; =20 k.epoch =3D sp->hdr.epoch; k.cid =3D sp->hdr.cid & RXRPC_CIDMASK; @@ -35,6 +35,7 @@ struct rxrpc_connection *rxrpc_find_service_conn_rcu(stru= ct rxrpc_peer *peer, * under just the RCU read lock, so we have to check for * changes. */ + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&peer->service_conn_lock, &seq); =20 p =3D rcu_dereference_raw(peer->service_conns.rb_node); --=20 2.25.1.362.g51ebf55