All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Zizhi Wo <wozizhi@huawei.com>, Baokun Li <libaokun1@huawei.com>,
	Jeff Layton <jlayton@kernel.org>,
	Jia Zhu <zhujia.zj@bytedance.com>,
	Christian Brauner <brauner@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	dhowells@redhat.com, netfs@lists.linux.dev
Subject: [PATCH AUTOSEL 6.9 06/21] cachefiles: Set object to close if ondemand_id < 0 in copen
Date: Sun, 23 Jun 2024 09:43:39 -0400	[thread overview]
Message-ID: <20240623134405.809025-6-sashal@kernel.org> (raw)
In-Reply-To: <20240623134405.809025-1-sashal@kernel.org>

From: Zizhi Wo <wozizhi@huawei.com>

[ Upstream commit 4f8703fb3482f92edcfd31661857b16fec89c2c0 ]

If copen is maliciously called in the user mode, it may delete the request
corresponding to the random id. And the request may have not been read yet.

Note that when the object is set to reopen, the open request will be done
with the still reopen state in above case. As a result, the request
corresponding to this object is always skipped in select_req function, so
the read request is never completed and blocks other process.

Fix this issue by simply set object to close if its id < 0 in copen.

Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Link: https://lore.kernel.org/r/20240522114308.2402121-11-libaokun@huaweicloud.com
Acked-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Jia Zhu <zhujia.zj@bytedance.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/cachefiles/ondemand.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c
index 6f815e7c50867..922cab1a314b2 100644
--- a/fs/cachefiles/ondemand.c
+++ b/fs/cachefiles/ondemand.c
@@ -182,6 +182,7 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
 	xas_store(&xas, NULL);
 	xa_unlock(&cache->reqs);
 
+	info = req->object->ondemand;
 	/* fail OPEN request if copen format is invalid */
 	ret = kstrtol(psize, 0, &size);
 	if (ret) {
@@ -201,7 +202,6 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
 		goto out;
 	}
 
-	info = req->object->ondemand;
 	spin_lock(&info->lock);
 	/*
 	 * The anonymous fd was closed before copen ? Fail the request.
@@ -241,6 +241,11 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
 	wake_up_all(&cache->daemon_pollwq);
 
 out:
+	spin_lock(&info->lock);
+	/* Need to set object close to avoid reopen status continuing */
+	if (info->ondemand_id == CACHEFILES_ONDEMAND_ID_CLOSED)
+		cachefiles_ondemand_set_object_close(req->object);
+	spin_unlock(&info->lock);
 	complete(&req->done);
 	return ret;
 }
-- 
2.43.0


  parent reply	other threads:[~2024-06-23 13:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-23 13:43 [PATCH AUTOSEL 6.9 01/21] NFSv4: Fix memory leak in nfs4_set_security_label Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 02/21] nfs: propagate readlink errors in nfs_symlink_filler Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 03/21] nfs: Avoid flushing many pages with NFS_FILE_SYNC Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 04/21] nfs: don't invalidate dentries on transient errors Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 05/21] cachefiles: add consistency check for copen/cread Sasha Levin
2024-06-23 13:43 ` Sasha Levin [this message]
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 07/21] cachefiles: make on-demand read killable Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 08/21] fs/file: fix the check in find_next_fd() Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 09/21] vfio: Create vfio_fs_type with inode per device Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 10/21] vfio/pci: Use unmap_mapping_range() Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 11/21] mei: demote client disconnect warning on suspend to debug Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 12/21] parport: amiga: Mark driver struct with __refdata to prevent section mismatch Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 13/21] iomap: Fix iomap_adjust_read_range for plen calculation Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 14/21] drm/exynos: dp: drop driver owner initialization Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 15/21] drm: panel-orientation-quirks: Add quirk for Aya Neo KUN Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 16/21] drm: renesas: shmobile: Call drm_atomic_helper_shutdown() at shutdown time Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 17/21] drm/mediatek: " Sasha Levin
2024-06-23 13:43   ` Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 18/21] nvme: avoid double free special payload Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 19/21] nvmet: always initialize cqe.result Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 20/21] vfio/pci: Insert full vma on mmap'd MMIO fault Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 21/21] loop: Disable fallocate() zero and discard if not supported Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240623134405.809025-6-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=brauner@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=jlayton@kernel.org \
    --cc=libaokun1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netfs@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=wozizhi@huawei.com \
    --cc=zhujia.zj@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.