From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-34.mta0.migadu.com [91.218.175.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B667A3446C7 for ; Thu, 13 Aug 2026 03:41:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786592521; cv=none; b=K0u5P8oGPjw5eZxDUcDERvoXSOp9xUlglPrgWJ3427DqRUr0AWdify/FxONbHPJn4lR30HbpmFF9DFj3QgxhXcRD9bKvTa8ezQ1mRSFhXkCYsph4lw0eLbHuK2aKTHK3ftguR52oNiGVqBfYrp+uo2/Poso4pSpPB+k1oyihf3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786592521; c=relaxed/simple; bh=rkICQp9vai9NhJqSMqAdid4nZbPtr66Y+KDEbBSYtZg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JrxqF5lmYXAN2tSmmsmv4CncelJ2qREJH9J4HIrS8fDc/IodkD2B1znKzYWBZTiVnREdkiPofh0m503dhRqoPsPXzZAMzdyV6Qb9ByPgHs+r64mHgejFKOeriZqzgu39WJZcNaodRFnt7XLQi+ppjNrS9fkVZwSzRis9NhFA5xc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=DHjqdKEV; arc=none smtp.client-ip=91.218.175.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="DHjqdKEV" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=rkICQp9vai9NhJqSMqAdid4nZbPtr66Y+KDEbBSYtZg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786592516; v=1; x=1787197316; b=DHjqdKEVIWLXNLenYKgaK5V4em6jWRfUh4Kejj5UjBOEwXFLK9chPMKBXBDyUkulHC+Th24o odZSje321jBuqFSq42CteSi3OnkcxDSlcsG5tVT08TmHDhbmX+HKeM1BU4DTUOYHq9NoEpwiL+8 524rZiOQX7n4r0uR01aSpSLE= X-Envelope-To: linux-kernel@vger.kernel.org Received: from ctao-book.. (111.162.215.50) by smtp.migadu.com with ESMTPS id 013549756ecb3f54; Thu, 13 Aug 2026 03:41:56 +0000 X-Migadu-Flow: FLOW_OUT From: Tao Cui To: clm@fb.com, dsterba@suse.com Cc: josef@toxicpanda.com, brauner@kernel.org, sforshee@kernel.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, cui.tao@linux.dev, Tao Cui Subject: [PATCH] btrfs: use mount idmap for defrag permission check Date: Thu, 13 Aug 2026 11:41:46 +0800 Message-ID: <20260813034146.1207640-1-cui.tao@linux.dev> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Tao Cui btrfs_ioctl_defrag() checks MAY_WRITE with nop_mnt_idmap, which skips the mount idmap. On an idmapped mount the owner comparison then uses the caller's fsuid against the raw on-disk uid, dropping the mapping. Every other permission/owner check in btrfs ioctl uses file_mnt_idmap(file) (e.g. :1152, :1310, :1946); this one missed it. Switch to file_mnt_idmap(file). It equals nop_mnt_idmap on a normal mount, and the check stays behind !capable(CAP_SYS_ADMIN), so only unprivileged callers on idmapped btrfs change. The RO-fd note in the comment above is about the file descriptor, not this inode check, and is unaffected. Signed-off-by: Tao Cui --- fs/btrfs/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 72bc9d4f7708..607329dedd50 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2458,7 +2458,7 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) * running and allows defrag on files open in read-only mode. */ if (!capable(CAP_SYS_ADMIN) && - inode_permission(&nop_mnt_idmap, inode, MAY_WRITE)) { + inode_permission(file_mnt_idmap(file), inode, MAY_WRITE)) { ret = -EPERM; goto out; } -- 2.43.0