From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Uday Shankar <ushankar@purestorage.com>,
Caleb Sander Mateos <csander@purestorage.com>,
Ming Lei <ming.lei@redhat.com>
Subject: [PATCH V3 01/17] ublk: validate ublk server pid
Date: Sun, 13 Jul 2025 22:33:56 +0800 [thread overview]
Message-ID: <20250713143415.2857561-2-ming.lei@redhat.com> (raw)
In-Reply-To: <20250713143415.2857561-1-ming.lei@redhat.com>
ublk server pid(the `tgid` of the process opening the ublk device) is stored
in `ublk_device->ublksrv_tgid`. This `tgid` is then checked against the
`ublksrv_pid` in `ublk_ctrl_start_dev` and `ublk_ctrl_end_recovery`.
This ensures that correct ublk server pid is stored in device info.
Fixes: 71f28f3136af ("ublk_drv: add io_uring based userspace block driver")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
drivers/block/ublk_drv.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index a1a700c7e67a..2b894de29823 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -237,6 +237,7 @@ struct ublk_device {
unsigned int nr_privileged_daemon;
struct mutex cancel_mutex;
bool canceling;
+ pid_t ublksrv_tgid;
};
/* header of ublk_params */
@@ -1528,6 +1529,7 @@ static int ublk_ch_open(struct inode *inode, struct file *filp)
if (test_and_set_bit(UB_STATE_OPEN, &ub->state))
return -EBUSY;
filp->private_data = ub;
+ ub->ublksrv_tgid = current->tgid;
return 0;
}
@@ -1542,6 +1544,7 @@ static void ublk_reset_ch_dev(struct ublk_device *ub)
ub->mm = NULL;
ub->nr_queues_ready = 0;
ub->nr_privileged_daemon = 0;
+ ub->ublksrv_tgid = -1;
}
static struct gendisk *ublk_get_disk(struct ublk_device *ub)
@@ -2820,6 +2823,9 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
if (wait_for_completion_interruptible(&ub->completion) != 0)
return -EINTR;
+ if (ub->ublksrv_tgid != ublksrv_pid)
+ return -EINVAL;
+
mutex_lock(&ub->mutex);
if (ub->dev_info.state == UBLK_S_DEV_LIVE ||
test_bit(UB_STATE_USED, &ub->state)) {
@@ -3321,6 +3327,9 @@ static int ublk_ctrl_end_recovery(struct ublk_device *ub,
pr_devel("%s: All FETCH_REQs received, dev id %d\n", __func__,
header->dev_id);
+ if (ub->ublksrv_tgid != ublksrv_pid)
+ return -EINVAL;
+
mutex_lock(&ub->mutex);
if (ublk_nosrv_should_stop_dev(ub))
goto out_unlock;
--
2.47.0
next prev parent reply other threads:[~2025-07-13 14:34 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-13 14:33 [PATCH V3 00/17] ublk: cleanup for supporting batch IO command Ming Lei
2025-07-13 14:33 ` Ming Lei [this message]
2025-07-15 14:50 ` [PATCH V3 01/17] ublk: validate ublk server pid Caleb Sander Mateos
2025-07-15 15:42 ` Ming Lei
2025-07-15 15:48 ` Caleb Sander Mateos
2025-07-15 22:39 ` Ming Lei
2025-07-13 14:33 ` [PATCH V3 02/17] ublk: look up ublk task via its pid in timeout handler Ming Lei
2025-07-13 14:33 ` [PATCH V3 03/17] ublk: move fake timeout logic into __ublk_complete_rq() Ming Lei
2025-07-13 14:33 ` [PATCH V3 04/17] ublk: let ublk_fill_io_cmd() cover more things Ming Lei
2025-07-15 15:22 ` Caleb Sander Mateos
2025-07-13 14:34 ` [PATCH V3 05/17] ublk: avoid to pass `struct ublksrv_io_cmd *` to ublk_commit_and_fetch() Ming Lei
2025-07-13 14:34 ` [PATCH V3 06/17] ublk: move auto buffer register handling into one dedicated helper Ming Lei
2025-07-13 14:34 ` [PATCH V3 07/17] ublk: store auto buffer register data into `struct ublk_io` Ming Lei
2025-07-13 14:34 ` [PATCH V3 08/17] ublk: add helper ublk_check_fetch_buf() Ming Lei
2025-07-13 14:34 ` [PATCH V3 09/17] ublk: remove ublk_commit_and_fetch() Ming Lei
2025-07-15 15:38 ` Caleb Sander Mateos
2025-07-13 14:34 ` [PATCH V3 10/17] ublk: pass 'const struct ublk_io *' to ublk_[un]map_io() Ming Lei
2025-07-13 14:34 ` [PATCH V3 11/17] selftests: ublk: remove `tag` parameter of ->tgt_io_done() Ming Lei
2025-07-13 14:34 ` [PATCH V3 12/17] selftests: ublk: pass 'ublk_thread *' to ->queue_io() and ->tgt_io_done() Ming Lei
2025-07-13 14:34 ` [PATCH V3 13/17] selftests: ublk: pass 'ublk_thread *' to more common helpers Ming Lei
2025-07-13 14:34 ` [PATCH V3 14/17] selftests: ublk: remove ublk queue self-defined flags Ming Lei
2025-07-13 14:34 ` [PATCH V3 15/17] selftests: ublk: improve flags naming Ming Lei
2025-07-13 14:34 ` [PATCH V3 16/17] selftests: ublk: add helper ublk_handle_uring_cmd() for handle ublk command Ming Lei
2025-07-13 14:34 ` [PATCH V3 17/17] selftests: ublk: add utils.h Ming Lei
2025-07-15 14:07 ` [PATCH V3 00/17] ublk: cleanup for supporting batch IO command Jens Axboe
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=20250713143415.2857561-2-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.com \
--cc=linux-block@vger.kernel.org \
--cc=ushankar@purestorage.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).