From: Tao Cui <cui.tao@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: cui.tao@linux.dev, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] blktrace: require CAP_SYS_ADMIN for the BLKTRACE ioctls
Date: Mon, 9 Nov 2026 10:22:59 +0800 [thread overview]
Message-ID: <91c8d6b5-9496-4c0f-b81d-ac31fbe2748d@linux.dev> (raw)
In-Reply-To: <sashiko-outbox-201597@kernel.org>
Hi,
在 2026/11/6 22:39, sashiko-bot@kernel.org 写道:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] blktrace: missing CAP_SYS_ADMIN check in sg_ioctl_common()
> --
>
> commit 8392196724a6f06dfb860d63cf54fba3357cc04e
> Author: Tao Cui <cuitao@kylinos.cn>
>
> blktrace: require CAP_SYS_ADMIN for the BLKTRACE ioctls
>
> This commit adds a CAP_SYS_ADMIN capability check to blk_trace_ioctl() to
> restrict block tracing ioctls to privileged users.
>
>> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
>> index 8cd2520b4c99e..c1bf8ca350fee 100644
>> --- a/kernel/trace/blktrace.c
>> +++ b/kernel/trace/blktrace.c
>> @@ -927,6 +927,9 @@ int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg)
>> int ret, start = 0;
>> char b[BDEVNAME_SIZE];
>>
>> + if (!capable(CAP_SYS_ADMIN))
>> + return -EPERM;
>> +
>> switch (cmd) {
>> case BLKTRACESETUP2:
>> snprintf(b, sizeof(b), "%pg", bdev);
>
> [Severity: Medium]
> Does checking CAP_SYS_ADMIN only in blk_trace_ioctl() leave the sg
> passthrough path in sg_ioctl_common() ungated?
>
> drivers/scsi/sg.c:sg_ioctl_common() {
> ...
> case BLKTRACESETUP:
> return blk_trace_setup(sdp->device->request_queue, sdp->name,
> MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
> NULL, p);
> case BLKTRACESTART:
> return blk_trace_startstop(sdp->device->request_queue, 1);
> case BLKTRACESTOP:
> return blk_trace_startstop(sdp->device->request_queue, 0);
> case BLKTRACETEARDOWN:
> return blk_trace_remove(sdp->device->request_queue);
> ...
> }
>
> Because sg_ioctl_common() calls blk_trace_setup(), blk_trace_startstop()
> and blk_trace_remove() directly rather than going through
> blk_trace_ioctl(), an unprivileged process with access to an /dev/sg* node
> can still allocate persistent relay buffers and control tracing state on
> the underlying request_queue.
Thanks for catching this.
The sg path is covered by patch 1/7 of the memcg accounting series:
https://lore.kernel.org/all/20261106131829.3228926-2-cui.tao@linux.dev/
Originally these changes were part of a single series. Since the
blktrace capability check isn't itself a memcg accounting fix, I split
it out into a separate series, but the corresponding sg_ioctl_common()
change remained with the memcg patches.
You're right that the standalone blktrace patch is incomplete by
itself. I'll fold the sg-side check into the blktrace patch in the
next revision so it is self-contained.
Thanks>
prev parent reply other threads:[~2026-11-09 2:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 14:28 [PATCH] blktrace: require CAP_SYS_ADMIN for the BLKTRACE ioctls Tao Cui
2026-11-06 14:39 ` sashiko-bot
2026-11-09 2:22 ` Tao Cui [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=91c8d6b5-9496-4c0f-b81d-ac31fbe2748d@linux.dev \
--to=cui.tao@linux.dev \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox