From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D3A47EEF2; Wed, 21 Feb 2024 14:01:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708524089; cv=none; b=K9O7RBm0AgnS8iQNQeVTpMw+4sXkUq7M6uiawu//cZqeaWqSJ3fbfuewL+yopgB5krT5NtG8PIICSodF1Bk17DOeuBTKB/t+96UFqrWgV7vX07kLRAcKvIsCbO2wXzfjnEBtGkuRMXtb5e2oGYyVQzA4lccUfmtZj2iylgZ7DSM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708524089; c=relaxed/simple; bh=13W7gM6fncSyktI/Q/UUTJnJ9pgJq3JD50QIGB+gZtg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tZFtJ7Tqz7AGKBXvP3MlACIrO0vc9WL3kkl36F2gFk7BcuLwbGlmbw3Y2XVpVRVRhIS3/ywVEx3hFNlT3IWF907u2cL4NPmShSK1T+ITxWsUHgcW7q47AKr5tyJ2dSci5qpDS+dj665Qsx7uPuXoqwUwTr7Fkf5O/4LA5TMAWPM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=OXDvrQWS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="OXDvrQWS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C594C433C7; Wed, 21 Feb 2024 14:01:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708524089; bh=13W7gM6fncSyktI/Q/UUTJnJ9pgJq3JD50QIGB+gZtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OXDvrQWSmBTm/3xCtPfmPUet98e0ii5Wqk+hgRXdqKBdRVSjPTJ76P8tf+EioeFw4 Ke8C5AitI+n1BY/rylS8oAKrmh0P4X3ZwfBLOvKioX6xhMkT3K0qyHSP3ZfAfhedtp vLb0c7m5QoqnPbg3/o+u8X2mQwGXNUlQYA95CIDs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Oleg Nesterov , David Howells , Marc Dionne , linux-afs@lists.infradead.org, Sasha Levin Subject: [PATCH 5.10 125/379] afs: fix the usage of read_seqbegin_or_lock() in afs_lookup_volume_rcu() Date: Wed, 21 Feb 2024 14:05:04 +0100 Message-ID: <20240221125958.625999367@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125954.917878865@linuxfoundation.org> References: <20240221125954.917878865@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Oleg Nesterov [ Upstream commit 4121b4337146b64560d1e46ebec77196d9287802 ] David Howells says: (2) afs_lookup_volume_rcu(). There can be a lot of volumes known by a system. A thousand would require a 10-step walk and this is drivable by remote operation, so I think this should probably take a lock on the second pass too. Make the "seq" counter odd on the 2nd pass, otherwise read_seqbegin_or_lock() never takes the lock. Signed-off-by: Oleg Nesterov Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org Link: https://lore.kernel.org/r/20231130115606.GA21571@redhat.com/ Signed-off-by: Sasha Levin --- fs/afs/callback.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/afs/callback.c b/fs/afs/callback.c index 7d9b23d981bf..229308c7f744 100644 --- a/fs/afs/callback.c +++ b/fs/afs/callback.c @@ -70,13 +70,14 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell, { struct afs_volume *volume = NULL; struct rb_node *p; - int seq = 0; + int seq = 1; do { /* Unfortunately, rbtree walking doesn't give reliable results * 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(&cell->volume_lock, &seq); p = rcu_dereference_raw(cell->volumes.rb_node); -- 2.43.0