All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Seamus Connor <sconnor@purestorage.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org,
	Caleb Sander Mateos <csander@purestorage.com>
Subject: Re: [PATCH v3] ublk: fix ublksrv pid handling for pid namespaces
Date: Thu, 15 Jan 2026 09:48:17 +0800	[thread overview]
Message-ID: <aWhHYQAP6e86EAJr@fedora> (raw)
In-Reply-To: <20260114204705.2249961-1-sconnor@purestorage.com>

On Wed, Jan 14, 2026 at 12:47:04PM -0800, Seamus Connor wrote:
> When ublksrv runs inside a pid namespace, START/END_RECOVERY compared
> the stored init-ns tgid against the userspace pid (getpid vnr), so the
> check failed and control ops could not proceed. Compare against the
> caller’s init-ns tgid and store that value, then translate it back to
> the caller’s pid namespace when reporting GET_DEV_INFO so ublk list
> shows a sensible pid.
> 
> Testing: start/recover in a pid namespace; `ublk list` shows
> reasonable pid values in init, child, and sibling namespaces.
> 
> Fixes: d37a224fc119 ("ublk: validate ublk server pid")
> Signed-off-by: Seamus Connor <sconnor@purestorage.com>
> Reviewed-by: Caleb Sander Mateos <csander@purestorage.com>
> ---
> Changes since v1:
>  - Updated start_dev and end_recovery to respect the user-supplied pid
> 
> Changes since v2:
>  - Moved pid translation into a helper function
> 
>  drivers/block/ublk_drv.c | 35 ++++++++++++++++++++++++++++++++++-
>  1 file changed, 34 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 67d4a867aec4..01747d256ff5 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -2852,6 +2852,15 @@ static struct ublk_device *ublk_get_device_from_id(int idx)
>  	return ub;
>  }
>  
> +static pid_t ublk_translate_user_pid(pid_t ublksrv_pid)
> +{
> +	rcu_read_lock();
> +	ublksrv_pid = pid_nr(find_vpid(ublksrv_pid));
> +	rcu_read_unlock();
> +
> +	return ublksrv_pid;
> +}
> +
>  static int ublk_ctrl_start_dev(struct ublk_device *ub,
>  		const struct ublksrv_ctrl_cmd *header)
>  {
> @@ -2920,6 +2929,8 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
>  	if (wait_for_completion_interruptible(&ub->completion) != 0)
>  		return -EINTR;
>  
> +	ublksrv_pid = ublk_translate_user_pid(ublksrv_pid);
> +
>  	if (ub->ublksrv_tgid != ublksrv_pid)
>  		return -EINVAL;

The above two lines can be moved to the helper which can be renamed as ublk_validate_user_pid(),
otherwise this patch looks good:

Reviewed-by: Ming Lei <ming.lei@redhat.com>


Thanks, 
Ming


  reply	other threads:[~2026-01-15  1:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-11  0:00 [PATCH] ublk: fix ublksrv pid handling for pid namespaces Seamus Connor
2026-01-12  5:40 ` Ming Lei
2026-01-12 18:09   ` Seamus Connor
2026-01-12 22:56 ` [PATCH v2] " Seamus Connor
2026-01-13  2:01   ` Ming Lei
2026-01-13  2:46     ` Seamus Connor
2026-01-13  3:47       ` Ming Lei
2026-01-13 23:03         ` Seamus Connor
2026-01-14  3:55           ` Ming Lei
2026-01-14 20:47   ` [PATCH v3] " Seamus Connor
2026-01-15  1:48     ` Ming Lei [this message]
2026-01-15  2:59 ` [PATCH v4] " Seamus Connor
2026-01-20 23:48   ` Seamus Connor
2026-01-21 14:45   ` Jens Axboe
2026-01-21 14:48   ` 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=aWhHYQAP6e86EAJr@fedora \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=linux-block@vger.kernel.org \
    --cc=sconnor@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 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.