From: Seth Forshee <sforshee@kernel.org>
To: Tao Cui <cui.tao@linux.dev>
Cc: clm@fb.com, dsterba@suse.com, wqu@suse.com, josef@toxicpanda.com,
brauner@kernel.org, linux-btrfs@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Tao Cui <cuitao@kylinos.cn>
Subject: Re: [PATCH v2] btrfs: allow idmapped DEFRAG ioctls
Date: Sat, 15 Aug 2026 13:36:42 -0500 [thread overview]
Message-ID: <aoCxuk2DJVPsOXoB@ubuntu-x1> (raw)
In-Reply-To: <20260815132259.3935817-1-cui.tao@linux.dev>
On Sat, Aug 15, 2026 at 09:22:59PM +0800, Tao Cui wrote:
> From: Tao Cui <cuitao@kylinos.cn>
>
> btrfs_ioctl_defrag() checks MAY_WRITE against nop_mnt_idmap, so on an
> idmapped mount the owner comparison uses the caller's fsuid against the
> raw on-disk uid and the ioctl fails with -EPERM even for the file's
> owner. Pass the mount idmap down so defrag works on idmapped mounts.
>
> The check, added in 616d374efa23 ("btrfs: allow defrag on a file opened
> read-only that has rw permissions"), is not a privilege gate. It only
> tests whether the file could have been opened for writing, and a user
> who owns the file on the idmapped mount can already open it O_RDWR,
> write() to it or fallocate() it. Defragmenting a regular file only
> rearranges the caller's own extents; there is nothing it can rewrite
> that the caller could not rewrite anyway. Whole-subvolume defrag on a
> directory keeps its capable(CAP_SYS_ADMIN) requirement, and the
> !capable() guard around this check is left as is.
>
> FIDEDUPERANGE already works this way for unprivileged callers:
> may_dedupe_file() in fs/remap_range.c compares the inode owner through
> file_mnt_idmap(file) and falls back to inode_permission() with the same
> idmap, and dedupe can rewrite one file's extents from another file's
> contents, which is a stronger operation than defrag.
>
> On regular mounts file_mnt_idmap() is nop_mnt_idmap and nothing
> changes.
>
> Signed-off-by: Tao Cui <cuitao@kylinos.cn>
Thanks for the updated commit message!
Reviewed-by: Seth Forshee <sforshee@kernel.org>
next prev parent reply other threads:[~2026-08-15 18:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 13:22 Tao Cui
2026-08-15 18:36 ` Seth Forshee [this message]
2026-08-15 22:14 ` Qu Wenruo
2026-08-25 12:47 ` Christian Brauner
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=aoCxuk2DJVPsOXoB@ubuntu-x1 \
--to=sforshee@kernel.org \
--cc=brauner@kernel.org \
--cc=clm@fb.com \
--cc=cui.tao@linux.dev \
--cc=cuitao@kylinos.cn \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wqu@suse.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
all inboxes | Powered by JetHome®