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 6428F19E827; Tue, 16 Jul 2024 15:47:13 +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=1721144833; cv=none; b=OPl0CLmPvd6/+vHIfC3/XCTGnVjtWrcm1tmPJ4Xl/qsfKUQ5rz6m7qoAfaarG4pYSilnS3GiYkzhDklJE/GOp/4+8wLBXGYeIZxgzaM922bjqDLt7oVTSNp7A/CeHG9lT/sXCQFS8eCkIp0Juw+ol2THqRNsqbUj1ThckCAcqJs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721144833; c=relaxed/simple; bh=0W0Km0qZJ8IpcvLKG/SBH4vB9pFm+yjTwyd3TKzXP58=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DAH1c/W2h5MlN2FKWmGPlpF69sd5v/iv0Xw8Ej1Tvk4AdbjAGhP0HnAhpHxh2/tQcMZjGdOUbXmadI9YlSpT1LUHPeWB1vzcORH1ldQJ4gKp5kGfioD7XJkizIl1xN29zSPBFUwMsoUxj/EyYCflCCubhZa1AXszak2JNiqJdoY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZIPsFZn6; 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="ZIPsFZn6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0943C116B1; Tue, 16 Jul 2024 15:47:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1721144833; bh=0W0Km0qZJ8IpcvLKG/SBH4vB9pFm+yjTwyd3TKzXP58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZIPsFZn6TlptuaD7++kmIL+vMAg8bSIigmb5M4ixzybkqijojKT+BzhM28uQgwdgi gKrsGy7GHA+6//yHlVHX5WHPDTCzvQtoi9NQrNUGfgwh/mutlTD97Za0ILJgPioy6/ Mr3Qe5S1j3agP3VpTLdY64d3IVBfvSDEg1leWNhw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jingbo Xu , Baokun Li , Jeff Layton , Jia Zhu , Gao Xiang , Christian Brauner , Sasha Levin Subject: [PATCH 6.9 011/143] cachefiles: add missing lock protection when polling Date: Tue, 16 Jul 2024 17:30:07 +0200 Message-ID: <20240716152756.423196014@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240716152755.980289992@linuxfoundation.org> References: <20240716152755.980289992@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 6.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jingbo Xu [ Upstream commit cf5bb09e742a9cf6349127e868329a8f69b7a014 ] Add missing lock protection in poll routine when iterating xarray, otherwise: Even with RCU read lock held, only the slot of the radix tree is ensured to be pinned there, while the data structure (e.g. struct cachefiles_req) stored in the slot has no such guarantee. The poll routine will iterate the radix tree and dereference cachefiles_req accordingly. Thus RCU read lock is not adequate in this case and spinlock is needed here. Fixes: b817e22b2e91 ("cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode") Signed-off-by: Jingbo Xu Signed-off-by: Baokun Li Link: https://lore.kernel.org/r/20240628062930.2467993-10-libaokun@huaweicloud.com Acked-by: Jeff Layton Reviewed-by: Jia Zhu Reviewed-by: Gao Xiang Signed-off-by: Christian Brauner Signed-off-by: Sasha Levin --- fs/cachefiles/daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index 06cdf1a8a16f6..89b11336a8369 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -366,14 +366,14 @@ static __poll_t cachefiles_daemon_poll(struct file *file, if (cachefiles_in_ondemand_mode(cache)) { if (!xa_empty(&cache->reqs)) { - rcu_read_lock(); + xas_lock(&xas); xas_for_each_marked(&xas, req, ULONG_MAX, CACHEFILES_REQ_NEW) { if (!cachefiles_ondemand_is_reopening_read(req)) { mask |= EPOLLIN; break; } } - rcu_read_unlock(); + xas_unlock(&xas); } } else { if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags)) -- 2.43.0