All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tao Cui" <cui.tao@linux.dev>
Cc: linux-scsi@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] scsi: sg: Require CAP_SYS_ADMIN for BLKTRACE passthrough ioctls
Date: Wed, 11 Nov 2026 14:59:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-209207@kernel.org> (raw)
In-Reply-To: <20261111145034.248717-3-cui.tao@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: sg: duplicate BLKTRACE ioctl command check in
  sg_ioctl_common()
--

commit 245abdd71d86c36b043cbaf6080f0c6a16895527
Author: Tao Cui <cuitao@kylinos.cn>

scsi: sg: Require CAP_SYS_ADMIN for BLKTRACE passthrough ioctls

This commit requires CAP_SYS_ADMIN in sg_ioctl_common() before handling
the four blktrace passthrough ioctl commands.

> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 5408f002e6c01..36a1fb7343607 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -910,6 +910,13 @@ static int put_compat_request_table(struct compat_sg_req_info __user *o,
>  }
>  #endif
>  
> +/* keep in sync with the commands blk_trace_ioctl() gates */
> +static bool sg_is_blktrace_cmd(unsigned int cmd)
> +{
> +	return cmd == BLKTRACESETUP || cmd == BLKTRACESTART ||
> +	       cmd == BLKTRACESTOP || cmd == BLKTRACETEARDOWN;
> +}
> +
>  static long
>  sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,
>  		unsigned int cmd_in, void __user *p)
> @@ -921,6 +928,9 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,
>  
>  	SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp,
>  				   "sg_ioctl: cmd=0x%x\n", (int) cmd_in));
> +	if (IS_ENABLED(CONFIG_BLK_DEV_IO_TRACE) &&
> +	    sg_is_blktrace_cmd(cmd_in) && !capable(CAP_SYS_ADMIN))
> +		return -EPERM;

[Severity: Low]
This isn't a bug, but sg_ioctl_common() already matches BLKTRACESETUP,
BLKTRACESTART, BLKTRACESTOP, and BLKTRACETEARDOWN in switch (cmd_in)
immediately below.  Checking sg_is_blktrace_cmd() before the switch
duplicates the four command constants and runs up to four extra comparisons
on every ioctl call, including the SG_IO path.  Could the capability check
be done inside the existing blktrace switch cases instead?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261111145034.248717-1-cui.tao@linux.dev?part=2

      reply	other threads:[~2026-11-11 14:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 14:50 [PATCH v2 0/2] blktrace: gate the blktrace interface behind CAP_SYS_ADMIN Tao Cui
2026-11-11 14:50 ` [PATCH v2 1/2] blktrace: require CAP_SYS_ADMIN for the blktrace interface Tao Cui
2026-11-11 14:50 ` [PATCH v2 2/2] scsi: sg: Require CAP_SYS_ADMIN for BLKTRACE passthrough ioctls Tao Cui
2026-11-11 14:59   ` sashiko-bot [this message]

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=sashiko-outbox-209207@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cui.tao@linux.dev \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.