From patchwork Thu Aug 15 09:24:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764618 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA3DF1EB48D for ; Thu, 15 Aug 2024 09:24:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713890; cv=none; b=Fm5UQvr6mLAMnDzxx5uGUExWCX5y9jHkV/1GteRFHnry0fMUUHFHpr1MxHfP9356ZdfoLrdyNvVRubfEf+IcVSBGK93oOXiahdDlYi1tDVP6Q068MSPOz6C2QAUrQBc2C9Nein+hlr1IsV46rLKTvyThridqXnk5fCxbEnyYX1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713890; c=relaxed/simple; bh=7QlYD6l9p5eF21jVsZq19AIhqtZNByHgXnAh7C0YaT4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u8lGpPDH+nP+ev4MKEVfh+a4vivtkwlrAj5BVyI1uzLqtgJ3mpgRibM97jRQ8J072g3SSb+wHLyDH7RmP8c7CGKbwOXp6Y+Q4t1oGu2xb9DlBp2F3/hKlj7GnTORuogKpYzvH0VKxpgOSFGrItbZJRE32Cp0voOChd5nTe1Hifk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=DPvwIH7N; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="DPvwIH7N" Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id D525B3F196 for ; Thu, 15 Aug 2024 09:24:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713886; bh=rAXMreNRBTPp2+RJ3in8rXzVuCGcw271HJnlzrndXY4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DPvwIH7Nxo/G6vxKU5f5NnxsZN0g9klwabS8P7LbEAyKSU4haqFP5eAZcchCoPOCJ ZjVLOx4pKTFGZJPxFjPcp4Jrli6TuB8Y3zAioCUnavLJT/cQBD9gr6vzXZxJbkVJ+x XpzwvuM+J6Nopn3OrzUH13n5u924pk10+lt8UxC+MEAeVoTBT0Oigm9e2noyI7xu8i SOdYoGf0MjoPi8W5fIklaQlF1SX9nDMiQeMBXyArBDmHdZaqTM/IGmpJ95IY4KONAC GteU4q09hGNwjPlfh9NLDU6tmL8cS6J+5Xv5UHIB3emhqGr34LG5BIZ+u6FaPVtcEE odXb3WegFyuQw== Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a7bcaa94892so74656966b.0 for ; Thu, 15 Aug 2024 02:24:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713886; x=1724318686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rAXMreNRBTPp2+RJ3in8rXzVuCGcw271HJnlzrndXY4=; b=REdAYCXbj8cvE/agXUib2OLt1CzmYHhYYpEbesoKLZHR0CLMcZHTApuoLce58+/rmG h5WjP7vNvHT9nJa1mabbUDX1MWoXv+zpsNq6mEMSSaPB2HX6nP88euurhqmPG+j8NiWe rGGIeJu2kQ+pToLSgxLseJcfahA9jJMcgLPgwGepSMdQC+2b9C0XgTDmHzmx+mVMh6k+ 9rwrVBgPWR8S3TbXAvN/Y7PGMtAnFfblxjb48t40DiSijn73ERNSH1/QmSrfcIPOHa/+ Hs5ihKxm0dhIwag0vugVLnFJFxHb6J8pSnfs+1nygG6SjPus0/k57dvs5RQtxqKtxr4i vJRQ== X-Forwarded-Encrypted: i=1; AJvYcCV7vx6XXmeJ48sFU+050tgYnDYFawdJmdIxAyd9k0Rt8nyPtzplLpuX8bSimgmjv2YNInr0nntwdUNRbF7IYt7aI28dX7wusAXWsfBgeQ== X-Gm-Message-State: AOJu0Yy+0k1GKqY14DHOryyHPkItsnVL6NLcAQjf7zlVtAdwPFp1IBlF bqT9A+PH/DmmJH/Ec00j4W/x22YT3ACUKfcVE2Ya/wfn0niu6biSODkL12MN3LHJ+kfTfdEKVwh F+4sODBpE2W+4Oydsf8ycWAFLlIKsu1BqwijSX3qaUHVAXqkczW1Mm0Szo+PYNk+m/ZGViVppvy ak0DI= X-Received: by 2002:a17:906:d25c:b0:a7a:8cb9:7491 with SMTP id a640c23a62f3a-a8367087421mr391867966b.54.1723713886448; Thu, 15 Aug 2024 02:24:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFs7cI7cvU+ksFskAocCsC23yqHF28RZ3Vu3jlzk3u1ykj3LBphtlYXWKHo08N1JU0SKHg0ow== X-Received: by 2002:a17:906:d25c:b0:a7a:8cb9:7491 with SMTP id a640c23a62f3a-a8367087421mr391866066b.54.1723713885797; Thu, 15 Aug 2024 02:24:45 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:24:44 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , Alexander Viro , Jan Kara , linux-kernel@vger.kernel.org Subject: [PATCH v3 01/11] fs/namespace: introduce SB_I_NOIDMAP flag Date: Thu, 15 Aug 2024 11:24:18 +0200 Message-Id: <20240815092429.103356-2-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Right now we determine if filesystem support vfs idmappings or not basing on the FS_ALLOW_IDMAP flag presence. This "static" way works perfecly well for local filesystems like ext4, xfs, btrfs, etc. But for network-like filesystems like fuse, cephfs this approach is not ideal, because sometimes proper support of vfs idmaps requires some extensions for the on-wire protocol, which implies that changes have to be made not only in the Linux kernel code but also in the 3rd party components like libfuse, cephfs MDS server and so on. We have seen that issue during our work on cephfs idmapped mounts [1] with Christian, but right now I'm working on the idmapped mounts support for fuse/virtiofs and I think that it is a right time for this extension. [1] 5ccd8530dd7 ("ceph: handle idmapped mounts in create_request_message()") Cc: Christian Brauner Cc: Seth Forshee Cc: Miklos Szeredi Cc: Amir Goldstein Cc: Bernd Schubert Cc: Suggested-by: Christian Brauner Signed-off-by: Alexander Mikhalitsyn --- v3: - this commit added --- fs/namespace.c | 4 ++++ include/linux/fs.h | 1 + 2 files changed, 5 insertions(+) diff --git a/fs/namespace.c b/fs/namespace.c index 328087a4df8a..d1702285c915 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -4436,6 +4436,10 @@ static int can_idmap_mount(const struct mount_kattr *kattr, struct mount *mnt) if (!(m->mnt_sb->s_type->fs_flags & FS_ALLOW_IDMAP)) return -EINVAL; + /* The filesystem has turned off idmapped mounts. */ + if (m->mnt_sb->s_iflags & SB_I_NOIDMAP) + return -EINVAL; + /* We're not controlling the superblock. */ if (!ns_capable(fs_userns, CAP_SYS_ADMIN)) return -EPERM; diff --git a/include/linux/fs.h b/include/linux/fs.h index fd34b5755c0b..6ff547ef21f2 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1189,6 +1189,7 @@ extern int send_sigurg(struct fown_struct *fown); #define SB_I_TS_EXPIRY_WARNED 0x00000400 /* warned about timestamp range expiry */ #define SB_I_RETIRED 0x00000800 /* superblock shouldn't be reused */ #define SB_I_NOUMASK 0x00001000 /* VFS does not apply umask */ +#define SB_I_NOIDMAP 0x00002000 /* No idmapped mounts on this superblock */ /* Possible states of 'frozen' field */ enum { From patchwork Thu Aug 15 09:24:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764619 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AE921EB4B0 for ; Thu, 15 Aug 2024 09:24:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713894; cv=none; b=BHedGs3tfD7eZsnXVenwLBwK2R85G2b8C3uTbnVmv5ibT+zFJ8CBILUoI24GW0EciYCsATiLLYQ8SE6zkI0R79jr8a7LJlJNTzIjcabxL/9DJeC2H91R0JJ/kuv2rrl+d4oBYu4U8+PIZmGOFkp5qzEzHMcsN4IVqMFYPgI7+bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713894; c=relaxed/simple; bh=3sKR5heXsN3+PDmKkyp9ATdAOr7cyhuezAbCen+o5+Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aAZw74gfkDGsRVPLEqydjUNR5ZXrs3lW5HAiK0QZeQjqt1WenGUSSTAn3uIpQBpYWsq+5JReGnEC204YVYaq2aOmXljHcvJMVHG4UbG+6V8aw72hSJgOsfnGjX1G4qX91d4dtBONFstUyp7MvNfEfIcjkKyrjmP9m5XpVAuAI9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=q73mGquI; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="q73mGquI" Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id CB33C400B0 for ; Thu, 15 Aug 2024 09:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713890; bh=m96HZWLn8OKWP/L3it/bQmtO6VIcFcKI507cIhh46m0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q73mGquI69OZGNL5MIQiAYWxMsQkln182oyfjfzT3Hy/p+RF76g4EgYMBeHbCvxn4 5WabbO05loSFMXCJ2Our2XCTdv0bNrqncrs/b+TJU996uGdWVjfqgD0rKgjAjXbmCA TNDSyDS2g58U9xEbXHJUY4kP7vzLb6QJL9DjYvnXANfpA6cG/lgHWLAOv475RvFA5r kGXMN2gQnkH91qdeiq+uMnQxS75ej0pfikABIpdctCqvjkjGuMHCpptsw4fznV5nJL eFFII03xHx4X5TLiakNW+xnuZbg0pmpD+j50l/VD2g7QYoaCMbwxj18XQmKuO1ZPoG pHqt0mAPZAjXA== Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a7a8281dba5so77439366b.3 for ; Thu, 15 Aug 2024 02:24:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713890; x=1724318690; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m96HZWLn8OKWP/L3it/bQmtO6VIcFcKI507cIhh46m0=; b=iwp03rSiOfogxENetS5EDoEdzrAd2xvzMm9KncKzDeYOmnCl1UuCE+maRrncCB0P3r GhRQoBReAJp4un3OLzYIHs9WN4liXf/1AVz0qbnzocrDkACbWmHbHhNxO+quKSRP2DMS NTF+rNks23JrtgMPi9txqjdHWf1kyO+P0Q748Q3DrqC88IssjLZmARg/mI1QXjHVRRFm 7EVCQRAaFwSjbXXBHEW2awFFUkr/ZywSzn6rNoJvW1T7uhLkHVLgBe6JSF3HkM1nD9WP 7bc5h1vdFhpXVL3S3NjFojmi9MMGpEExQateuMAM52RmOydpBaYqMwQ90jnv/oTsWDqW h0ew== X-Forwarded-Encrypted: i=1; AJvYcCV9bMFoGp7OSH2Kzf8N1ykNt9MuavrUCelNQbDwbhdacuDQWLAUmPpJDLa+lNkIVtm8EDQeVhUIqiVibbB+@vger.kernel.org X-Gm-Message-State: AOJu0Yx4qh8b/1ST8eC+S8koLDilF5yQa0WmPwJPTabDs3jbSLzaaO/+ LThkLa6u2rTiqcJkUrf6e4K0vyYJCFMUoBI4/5TzvHnYRHeQ8IasoFl0noWLS32/ETQ52tEkW17 QsDw3JspGcEs1d9lCIy89kAr5YDHteSRXI1iLSBkwElPHMZZ10dgWwkve1w1MvXBuv0vZuJ9Y4F F+gmg= X-Received: by 2002:a17:907:e686:b0:a7a:bc34:a4c0 with SMTP id a640c23a62f3a-a8367017958mr340288266b.45.1723713889868; Thu, 15 Aug 2024 02:24:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2JvonBW7VByiYt9qrK3OXi7/p00XdZN0Z3eAkYXMajB1mk3hDfAZbiimTYiDiMwXegHifNg== X-Received: by 2002:a17:907:e686:b0:a7a:bc34:a4c0 with SMTP id a640c23a62f3a-a8367017958mr340286066b.45.1723713889437; Thu, 15 Aug 2024 02:24:49 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:24:48 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Miklos Szeredi , Seth Forshee , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v3 02/11] fs/fuse: add FUSE_OWNER_UID_GID_EXT extension Date: Thu, 15 Aug 2024 11:24:19 +0200 Message-Id: <20240815092429.103356-3-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To properly support vfs idmappings we need to provide a fuse daemon with the correct owner uid/gid for inode creation requests like mkdir, mknod, atomic_open, symlink. Right now, fuse daemons use req->in.h.uid/req->in.h.gid to set inode owner. These fields contain fsuid/fsgid of the syscall's caller. And that's perfectly fine, because inode owner have to be set to these values. But, for idmapped mounts it's not the case and caller fsuid/fsgid != inode owner, because idmapped mounts do nothing with the caller fsuid/fsgid, but affect inode owner uid/gid. It means that we can't apply vfsid mapping to caller fsuid/fsgid, but instead we have to introduce a new fields to store inode owner uid/gid which will be appropriately transformed. Christian and I have done the same to support idmapped mounts in the cephfs recently [1]. [1] 5ccd8530 ("ceph: handle idmapped mounts in create_request_message()") Cc: Miklos Szeredi Cc: Christian Brauner Cc: Seth Forshee Cc: Amir Goldstein Cc: Bernd Schubert Cc: Signed-off-by: Alexander Mikhalitsyn --- fs/fuse/dir.c | 34 +++++++++++++++++++++++++++++++--- fs/fuse/fuse_i.h | 3 +++ fs/fuse/inode.c | 4 +++- include/uapi/linux/fuse.h | 19 +++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 2b0d4781f394..30d27d4f3b5a 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -572,7 +572,33 @@ static int get_create_supp_group(struct inode *dir, struct fuse_in_arg *ext) return 0; } -static int get_create_ext(struct fuse_args *args, +static int get_owner_uid_gid(struct mnt_idmap *idmap, struct fuse_conn *fc, struct fuse_in_arg *ext) +{ + struct fuse_ext_header *xh; + struct fuse_owner_uid_gid *owner_creds; + u32 owner_creds_len = fuse_ext_size(sizeof(*owner_creds)); + kuid_t owner_fsuid; + kgid_t owner_fsgid; + + xh = extend_arg(ext, owner_creds_len); + if (!xh) + return -ENOMEM; + + xh->size = owner_creds_len; + xh->type = FUSE_EXT_OWNER_UID_GID; + + owner_creds = (struct fuse_owner_uid_gid *) &xh[1]; + + owner_fsuid = mapped_fsuid(idmap, fc->user_ns); + owner_fsgid = mapped_fsgid(idmap, fc->user_ns); + owner_creds->uid = from_kuid(fc->user_ns, owner_fsuid); + owner_creds->gid = from_kgid(fc->user_ns, owner_fsgid); + + return 0; +} + +static int get_create_ext(struct mnt_idmap *idmap, + struct fuse_args *args, struct inode *dir, struct dentry *dentry, umode_t mode) { @@ -584,6 +610,8 @@ static int get_create_ext(struct fuse_args *args, err = get_security_context(dentry, mode, &ext); if (!err && fc->create_supp_group) err = get_create_supp_group(dir, &ext); + if (!err && fc->owner_uid_gid_ext) + err = get_owner_uid_gid(idmap, fc, &ext); if (!err && ext.size) { WARN_ON(args->in_numargs >= ARRAY_SIZE(args->in_args)); @@ -668,7 +696,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, args.out_args[1].size = sizeof(*outopenp); args.out_args[1].value = outopenp; - err = get_create_ext(&args, dir, entry, mode); + err = get_create_ext(&nop_mnt_idmap, &args, dir, entry, mode); if (err) goto out_put_forget_req; @@ -798,7 +826,7 @@ static int create_new_entry(struct fuse_mount *fm, struct fuse_args *args, args->out_args[0].value = &outarg; if (args->opcode != FUSE_LINK) { - err = get_create_ext(args, dir, entry, mode); + err = get_create_ext(&nop_mnt_idmap, args, dir, entry, mode); if (err) goto out_put_forget_req; } diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index f23919610313..d06934e70cc5 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -845,6 +845,9 @@ struct fuse_conn { /* Add supplementary group info when creating a new inode */ unsigned int create_supp_group:1; + /* Add owner_{u,g}id info when creating a new inode */ + unsigned int owner_uid_gid_ext:1; + /* Does the filesystem support per inode DAX? */ unsigned int inode_dax:1; diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index d8ab4e93916f..6c205731c844 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -1343,6 +1343,8 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, } if (flags & FUSE_NO_EXPORT_SUPPORT) fm->sb->s_export_op = &fuse_export_fid_operations; + if (flags & FUSE_OWNER_UID_GID_EXT) + fc->owner_uid_gid_ext = 1; } else { ra_pages = fc->max_read / PAGE_SIZE; fc->no_lock = 1; @@ -1390,7 +1392,7 @@ void fuse_send_init(struct fuse_mount *fm) FUSE_HANDLE_KILLPRIV_V2 | FUSE_SETXATTR_EXT | FUSE_INIT_EXT | FUSE_SECURITY_CTX | FUSE_CREATE_SUPP_GROUP | FUSE_HAS_EXPIRE_ONLY | FUSE_DIRECT_IO_ALLOW_MMAP | - FUSE_NO_EXPORT_SUPPORT | FUSE_HAS_RESEND; + FUSE_NO_EXPORT_SUPPORT | FUSE_HAS_RESEND | FUSE_OWNER_UID_GID_EXT; #ifdef CONFIG_FUSE_DAX if (fm->fc->dax) flags |= FUSE_MAP_ALIGNMENT; diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index d08b99d60f6f..d9ecc17fd13b 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -217,6 +217,10 @@ * - add backing_id to fuse_open_out, add FOPEN_PASSTHROUGH open flag * - add FUSE_NO_EXPORT_SUPPORT init flag * - add FUSE_NOTIFY_RESEND, add FUSE_HAS_RESEND init flag + * + * 7.41 + * - add FUSE_EXT_OWNER_UID_GID + * - add FUSE_OWNER_UID_GID_EXT */ #ifndef _LINUX_FUSE_H @@ -421,6 +425,8 @@ struct fuse_file_lock { * FUSE_NO_EXPORT_SUPPORT: explicitly disable export support * FUSE_HAS_RESEND: kernel supports resending pending requests, and the high bit * of the request ID indicates resend requests + * FUSE_OWNER_UID_GID_EXT: add inode owner UID/GID info to create, mkdir, + * symlink and mknod */ #define FUSE_ASYNC_READ (1 << 0) #define FUSE_POSIX_LOCKS (1 << 1) @@ -466,6 +472,7 @@ struct fuse_file_lock { /* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */ #define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP +#define FUSE_OWNER_UID_GID_EXT (1ULL << 40) /** * CUSE INIT request/reply flags @@ -575,11 +582,13 @@ struct fuse_file_lock { * extension type * FUSE_MAX_NR_SECCTX: maximum value of &fuse_secctx_header.nr_secctx * FUSE_EXT_GROUPS: &fuse_supp_groups extension + * FUSE_EXT_OWNER_UID_GID: &fuse_owner_uid_gid extension */ enum fuse_ext_type { /* Types 0..31 are reserved for fuse_secctx_header */ FUSE_MAX_NR_SECCTX = 31, FUSE_EXT_GROUPS = 32, + FUSE_EXT_OWNER_UID_GID = 33, }; enum fuse_opcode { @@ -1186,4 +1195,14 @@ struct fuse_supp_groups { uint32_t groups[]; }; +/** + * struct fuse_owner_uid_gid - Inode owner UID/GID extension + * @uid: inode owner UID + * @gid: inode owner GID + */ +struct fuse_owner_uid_gid { + uint32_t uid; + uint32_t gid; +}; + #endif /* _LINUX_FUSE_H */ From patchwork Thu Aug 15 09:24:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764620 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 556801EB4B0 for ; Thu, 15 Aug 2024 09:24:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713896; cv=none; b=hfhzEkOyY99Xscsb1DGu6JRmYxOe8K5elLGxRNSaNHeJkFUUZIZFcKBxQ0sbPsJYNXkFZ93emDL36ijpp6dHDB308X0zigPzCw7sKVh2+QaE4RJL4yL/cxRY8CGd28oaTVDGs1j6YA4ncKi7VkOrg2AClh1Ywe5I0u24zM0vC7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713896; c=relaxed/simple; bh=4eTUDWhrEbeO6LacpkSTpWZsQS6mjvQhzRI0A/zxHU4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JwVH2PNweYkYOVxmw4b2ughgFHw8Fb8zLc+VHDj4CLbnZUtYy9xPQout7CwYOKsKjPNSJQocy1PRoSafDKv9vM8qikQZ1aW7mNYyYl1B2fW1M/Q2iQa5ZJAOTy/P7Cko3XpeACIfFlqLytr10OZ2sg5zrtdDUy3HQ5O29C7y4MA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=Z7vkY4PW; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="Z7vkY4PW" Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 94FA73F1FC for ; Thu, 15 Aug 2024 09:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713893; bh=cuULsUu9z+BvalrO9+cGgsIucfP8fxo4BNYi78/zGSU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z7vkY4PWsL+FbY/LwaeQP8UReIhxt+pJEJJWHSi8C05CP0tueuJHk2gxuL9yW3+QR 4XSMyvnpi2Ju2vaQvqSl4KObuIEgc8+XQiqV3sYWbNg28oqwjUSupyP3CG2LS1GqWB 9KG4TBy3QHf1KwndLlrfi+3cyF6UElTL+ixjN4+ZZaApTG5ujPR2X6m11g48HWSbVw CQ9jSrAI7iM4dk4rIS2WJLk84vOSam1T8Lr3JrFnwwa7AtbqiacEJ6bCn1ecJQS5i+ uA3m4r/CEddcLeY6tWswu5ZhMobWaHrwmWzUBvGMybZ+cPgOJZXFGHEwhCbuUNp3BE 6QsfrXUemHiVw== Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a7d63fbf4afso85182666b.2 for ; Thu, 15 Aug 2024 02:24:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713893; x=1724318693; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cuULsUu9z+BvalrO9+cGgsIucfP8fxo4BNYi78/zGSU=; b=APoRAWZRZ0mwVK28eEp7uO8ooeLWQVDD/iPhB7iVdw0X3vL8wNS/vM9EoYHmOtTb/e DPlrUfi2B3wqVgZjZUbEw3cR+cil6h2qPIZXmaDTaWZ7QDKxNcWRvu/v2mp5wRJpioYC vsONeteiEWrCiX1J064KqzktfiooCsDjSTY1NZtzMr4cFPyR9enxjX6WlJHsUCYnHqgn AsOFP6Bm9DEYHBZnruemDC7gHtdP3X72uQqbOOkFSnC8z/gqK0dR3LLAbKDFNqq7t68E UfR21+Op2TGZqIJLNuig50Pfc5WU0G7Ks+uNhM9UqwtpGTM7PnQl2+fXpZYkCnWYsiLE jiHg== X-Forwarded-Encrypted: i=1; AJvYcCVOASBl8+3sezvpiLCiaonuwN00xo9R2AvXYQMw+7H+rkw6mnrp6EM7bzcTstmAN+JpsAr/yPOyjENcHUmkyVi/zROQ5yPwSMl729uWlg== X-Gm-Message-State: AOJu0YxxICgaaI9slQ2HqvbJJ16NTkLtbIu5xRdUIxck4V5/riXHX3g2 TbaAHxLNYgjmRLR+Rf0qlMSKOl7OtaQkhSPyvihbHKU7abtebaRmBTv1n+r+pwX8U8XnXYj7BYe Pf1QI2yjgOUORrAP+AEk+SvOKf7wM+O8iDq85Jg31UH+UNqSa0KWYEOweTfcGSZSHAMawmna5KM fzVIE= X-Received: by 2002:a17:907:e65f:b0:a7a:952b:95ae with SMTP id a640c23a62f3a-a8367058dbfmr391411666b.47.1723713892784; Thu, 15 Aug 2024 02:24:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHVQTlmRiIxSatjFzhhXDyxgdPLqtIwQZ41XRrUNboCAzF4zXXfl9MJmxs2xMNWOOI3Fsi2g== X-Received: by 2002:a17:907:e65f:b0:a7a:952b:95ae with SMTP id a640c23a62f3a-a8367058dbfmr391410066b.47.1723713892276; Thu, 15 Aug 2024 02:24:52 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.24.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:24:51 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v3 03/11] fs/fuse: support idmap for mkdir/mknod/symlink/create Date: Thu, 15 Aug 2024 11:24:20 +0200 Message-Id: <20240815092429.103356-4-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have all the infrastructure in place, we just need to pass an idmapping here. Cc: Christian Brauner Cc: Seth Forshee Cc: Miklos Szeredi Cc: Amir Goldstein Cc: Bernd Schubert Cc: Signed-off-by: Alexander Mikhalitsyn --- fs/fuse/dir.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 30d27d4f3b5a..1e45c6157af4 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -637,9 +637,9 @@ static void free_ext_value(struct fuse_args *args) * If the filesystem doesn't support this, then fall back to separate * 'mknod' + 'open' requests. */ -static int fuse_create_open(struct inode *dir, struct dentry *entry, - struct file *file, unsigned int flags, - umode_t mode, u32 opcode) +static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, + struct dentry *entry, struct file *file, + unsigned int flags, umode_t mode, u32 opcode) { int err; struct inode *inode; @@ -696,7 +696,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, args.out_args[1].size = sizeof(*outopenp); args.out_args[1].value = outopenp; - err = get_create_ext(&nop_mnt_idmap, &args, dir, entry, mode); + err = get_create_ext(idmap, &args, dir, entry, mode); if (err) goto out_put_forget_req; @@ -757,6 +757,7 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry, umode_t mode) { int err; + struct mnt_idmap *idmap = file_mnt_idmap(file); struct fuse_conn *fc = get_fuse_conn(dir); struct dentry *res = NULL; @@ -781,7 +782,7 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry, if (fc->no_create) goto mknod; - err = fuse_create_open(dir, entry, file, flags, mode, FUSE_CREATE); + err = fuse_create_open(idmap, dir, entry, file, flags, mode, FUSE_CREATE); if (err == -ENOSYS) { fc->no_create = 1; goto mknod; @@ -792,7 +793,7 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry, return err; mknod: - err = fuse_mknod(&nop_mnt_idmap, dir, entry, mode, 0); + err = fuse_mknod(idmap, dir, entry, mode, 0); if (err) goto out_dput; no_open: @@ -802,9 +803,9 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry, /* * Code shared between mknod, mkdir, symlink and link */ -static int create_new_entry(struct fuse_mount *fm, struct fuse_args *args, - struct inode *dir, struct dentry *entry, - umode_t mode) +static int create_new_entry(struct mnt_idmap *idmap, struct fuse_mount *fm, + struct fuse_args *args, struct inode *dir, + struct dentry *entry, umode_t mode) { struct fuse_entry_out outarg; struct inode *inode; @@ -826,7 +827,7 @@ static int create_new_entry(struct fuse_mount *fm, struct fuse_args *args, args->out_args[0].value = &outarg; if (args->opcode != FUSE_LINK) { - err = get_create_ext(&nop_mnt_idmap, args, dir, entry, mode); + err = get_create_ext(idmap, args, dir, entry, mode); if (err) goto out_put_forget_req; } @@ -892,13 +893,13 @@ static int fuse_mknod(struct mnt_idmap *idmap, struct inode *dir, args.in_args[0].value = &inarg; args.in_args[1].size = entry->d_name.len + 1; args.in_args[1].value = entry->d_name.name; - return create_new_entry(fm, &args, dir, entry, mode); + return create_new_entry(idmap, fm, &args, dir, entry, mode); } static int fuse_create(struct mnt_idmap *idmap, struct inode *dir, struct dentry *entry, umode_t mode, bool excl) { - return fuse_mknod(&nop_mnt_idmap, dir, entry, mode, 0); + return fuse_mknod(idmap, dir, entry, mode, 0); } static int fuse_tmpfile(struct mnt_idmap *idmap, struct inode *dir, @@ -910,7 +911,7 @@ static int fuse_tmpfile(struct mnt_idmap *idmap, struct inode *dir, if (fc->no_tmpfile) return -EOPNOTSUPP; - err = fuse_create_open(dir, file->f_path.dentry, file, file->f_flags, mode, FUSE_TMPFILE); + err = fuse_create_open(idmap, dir, file->f_path.dentry, file, file->f_flags, mode, FUSE_TMPFILE); if (err == -ENOSYS) { fc->no_tmpfile = 1; err = -EOPNOTSUPP; @@ -937,7 +938,7 @@ static int fuse_mkdir(struct mnt_idmap *idmap, struct inode *dir, args.in_args[0].value = &inarg; args.in_args[1].size = entry->d_name.len + 1; args.in_args[1].value = entry->d_name.name; - return create_new_entry(fm, &args, dir, entry, S_IFDIR); + return create_new_entry(idmap, fm, &args, dir, entry, S_IFDIR); } static int fuse_symlink(struct mnt_idmap *idmap, struct inode *dir, @@ -953,7 +954,7 @@ static int fuse_symlink(struct mnt_idmap *idmap, struct inode *dir, args.in_args[0].value = entry->d_name.name; args.in_args[1].size = len; args.in_args[1].value = link; - return create_new_entry(fm, &args, dir, entry, S_IFLNK); + return create_new_entry(idmap, fm, &args, dir, entry, S_IFLNK); } void fuse_flush_time_update(struct inode *inode) @@ -1147,7 +1148,7 @@ static int fuse_link(struct dentry *entry, struct inode *newdir, args.in_args[0].value = &inarg; args.in_args[1].size = newent->d_name.len + 1; args.in_args[1].value = newent->d_name.name; - err = create_new_entry(fm, &args, newdir, newent, inode->i_mode); + err = create_new_entry(&nop_mnt_idmap, fm, &args, newdir, newent, inode->i_mode); if (!err) fuse_update_ctime_in_cache(inode); else if (err == -EINTR) From patchwork Thu Aug 15 09:24:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764621 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54A9B200127 for ; Thu, 15 Aug 2024 09:24:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713899; cv=none; b=r2sP1WyG8AmXvwb16jJGw/6KITkgOnInOQpllOk9NUHQvlTaRd5Bh7JpGEwf/0xxDJobPrZuSF14UEXTG5kpK9JJleksSReAMHzLu6kVDnfEDgITvCFp8yzwAIW+490lTI651m4ssesSAfPUNDnulSKWBqoiBGK/fCdYwQG6pTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713899; c=relaxed/simple; bh=No6OwevU+qxY4W/s/DWsEFKfEe7pGU5C8qXdUs/4/SQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j0trqqjyJRD72xYr/Iyu4cisUQJZBVmSfmhxbIsx3ocXu75OVLbXigW/yETEcuxFVCzge4MmFf85rs5fgtD6Cn/8IrgOi0QN04cLF1XyNLiDPT50xrQVM5nocOQ/cXgVqgzo0Beu2iGgDc/GuT9MxQtLcmSXh7Y0ZclK04tgOpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=swk7a10k; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="swk7a10k" Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id D49973F366 for ; Thu, 15 Aug 2024 09:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713895; bh=xaypcV2UJPM2r0pQHUTFWnnOJyltujHG9QByRfl37as=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=swk7a10kWqI6Y0/Y/1X74iZrOGzIWwaRRv1NZqKaGFw4Ml6Yv2lcczolgFbTbZdsp CtPhff21vzAln3D7aGA8vGfVxehJmLD3vueIiVXfh3KpjCQZjJUfzN/656yx+Thm0t bMvzJX9zZ+chqWANFQz8+y4jGU9t+VLcCedHFBrAE2uD/SvyPY2vZF7ovi2BLtCorM 2MjOxtaly4hLrlCeq8sc0DaVUwfVjxFqDb2YxfcnIB7YjtXKzLyuVjUAMv4Fi1zDaq mCguC8QlzHemM1ROlZpU175/CR2Lh8tjZf/l7hQSsxSRscbB+0SmX93h18g/KXpAFj 2H0l4C13JoLRA== Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a7a9761bf6dso73565066b.3 for ; Thu, 15 Aug 2024 02:24:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713895; x=1724318695; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xaypcV2UJPM2r0pQHUTFWnnOJyltujHG9QByRfl37as=; b=ReTuA0rQXZepGA5Dalktfw8vDp9C8I/FwEHLkJEVkjfvBT4XJxr+0Yag7Mb0OyXgu6 b5MBjiQPLTZndgihsfJE0nUHvp8inAGxdOpaS9FvLBa/VtTAHHPFtufp7+TF9L9vwgKQ vL227R6zrCJ6f2+lwra/2HYGDZ/ljoWYLHFIENlwxq9E5vBUtAFlY2s4tFwmW4KVJm0L qQNyHQSCsHO7/LKxtth4eOKd9ouB+wtlyDcNsBwfN0ns1SCA78JW3weB95MKA5BlgTlm Ivoo8D2mQkttNz5QOJ4gTz+H0e1iVhiPWsPmxvLrcq13Z5X5aJ9uMLLhfE+CsV4wZxVb rLdg== X-Forwarded-Encrypted: i=1; AJvYcCVEwPR3UFAhsIHfiJYfOUBXF6Me8RNwn2CcemivFm0g9kq/h2waoOGDPoCRI+JkndVrVo5B35rl4oskW34Ngk7Q0cakvH5zxU6qTX2sUQ== X-Gm-Message-State: AOJu0YzUTxAd6I5SkLghPYZNQm6jzSz4FSNADSJVYOWgxcn2T5MjYpWZ 4rU8AKVdVXg2Bg+Y+saX1mEX2XMC9xAqronXl3Bx178+gsh7cBQN2T2B6s8PrYys9f391L33DPz NIGalDuV3MdEMuIBWGsTYyNObayDu0H5uqVEn2idk514kTWZvOy2hIVP6gzIuTeteWM5q57VuK9 j1gGw= X-Received: by 2002:a17:906:d7d9:b0:a80:f79a:10c9 with SMTP id a640c23a62f3a-a8366c387e8mr373890266b.12.1723713895288; Thu, 15 Aug 2024 02:24:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUDE6UeM03+0fYWSQvu+kTAfAhwxSnFGl4olPqV1KLax6wyKK7710ZFz/zECKrL7s7mRsrjg== X-Received: by 2002:a17:906:d7d9:b0:a80:f79a:10c9 with SMTP id a640c23a62f3a-a8366c387e8mr373889366b.12.1723713894907; Thu, 15 Aug 2024 02:24:54 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:24:54 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v3 04/11] fs/fuse: support idmapped getattr inode op Date: Thu, 15 Aug 2024 11:24:21 +0200 Message-Id: <20240815092429.103356-5-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have to: - pass an idmapping to the generic_fillattr() to properly handle UIG/GID mapping for the userspace. - pass -/- to fuse_fillattr() (analog of generic_fillattr() in fuse). Difference between these two is that generic_fillattr() takes all the stat() data from the inode directly, while fuse_fillattr() codepath takes a fresh data just from the userspace reply on the FUSE_GETATTR request. In some cases we can just pass &nop_mnt_idmap, because idmapping won't be used in these codepaths. For example, when 3rd argument of fuse_do_getattr() is NULL then idmap argument is not used. Cc: Christian Brauner Cc: Seth Forshee Cc: Miklos Szeredi Cc: Amir Goldstein Cc: Bernd Schubert Cc: Signed-off-by: Alexander Mikhalitsyn --- v2: - pass idmap in more cases to make code easier to understand --- fs/fuse/dir.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 1e45c6157af4..a5bf8c18a0ae 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1157,18 +1157,22 @@ static int fuse_link(struct dentry *entry, struct inode *newdir, return err; } -static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr, - struct kstat *stat) +static void fuse_fillattr(struct mnt_idmap *idmap, struct inode *inode, + struct fuse_attr *attr, struct kstat *stat) { unsigned int blkbits; struct fuse_conn *fc = get_fuse_conn(inode); + vfsuid_t vfsuid = make_vfsuid(idmap, fc->user_ns, + make_kuid(fc->user_ns, attr->uid)); + vfsgid_t vfsgid = make_vfsgid(idmap, fc->user_ns, + make_kgid(fc->user_ns, attr->gid)); stat->dev = inode->i_sb->s_dev; stat->ino = attr->ino; stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777); stat->nlink = attr->nlink; - stat->uid = make_kuid(fc->user_ns, attr->uid); - stat->gid = make_kgid(fc->user_ns, attr->gid); + stat->uid = vfsuid_into_kuid(vfsuid); + stat->gid = vfsgid_into_kgid(vfsgid); stat->rdev = inode->i_rdev; stat->atime.tv_sec = attr->atime; stat->atime.tv_nsec = attr->atimensec; @@ -1207,8 +1211,8 @@ static void fuse_statx_to_attr(struct fuse_statx *sx, struct fuse_attr *attr) attr->blksize = sx->blksize; } -static int fuse_do_statx(struct inode *inode, struct file *file, - struct kstat *stat) +static int fuse_do_statx(struct mnt_idmap *idmap, struct inode *inode, + struct file *file, struct kstat *stat) { int err; struct fuse_attr attr; @@ -1261,15 +1265,15 @@ static int fuse_do_statx(struct inode *inode, struct file *file, stat->result_mask = sx->mask & (STATX_BASIC_STATS | STATX_BTIME); stat->btime.tv_sec = sx->btime.tv_sec; stat->btime.tv_nsec = min_t(u32, sx->btime.tv_nsec, NSEC_PER_SEC - 1); - fuse_fillattr(inode, &attr, stat); + fuse_fillattr(idmap, inode, &attr, stat); stat->result_mask |= STATX_TYPE; } return 0; } -static int fuse_do_getattr(struct inode *inode, struct kstat *stat, - struct file *file) +static int fuse_do_getattr(struct mnt_idmap *idmap, struct inode *inode, + struct kstat *stat, struct file *file) { int err; struct fuse_getattr_in inarg; @@ -1308,15 +1312,15 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat, ATTR_TIMEOUT(&outarg), attr_version); if (stat) - fuse_fillattr(inode, &outarg.attr, stat); + fuse_fillattr(idmap, inode, &outarg.attr, stat); } } return err; } -static int fuse_update_get_attr(struct inode *inode, struct file *file, - struct kstat *stat, u32 request_mask, - unsigned int flags) +static int fuse_update_get_attr(struct mnt_idmap *idmap, struct inode *inode, + struct file *file, struct kstat *stat, + u32 request_mask, unsigned int flags) { struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_conn *fc = get_fuse_conn(inode); @@ -1347,17 +1351,17 @@ static int fuse_update_get_attr(struct inode *inode, struct file *file, forget_all_cached_acls(inode); /* Try statx if BTIME is requested */ if (!fc->no_statx && (request_mask & ~STATX_BASIC_STATS)) { - err = fuse_do_statx(inode, file, stat); + err = fuse_do_statx(idmap, inode, file, stat); if (err == -ENOSYS) { fc->no_statx = 1; err = 0; goto retry; } } else { - err = fuse_do_getattr(inode, stat, file); + err = fuse_do_getattr(idmap, inode, stat, file); } } else if (stat) { - generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat); + generic_fillattr(idmap, request_mask, inode, stat); stat->mode = fi->orig_i_mode; stat->ino = fi->orig_ino; if (test_bit(FUSE_I_BTIME, &fi->state)) { @@ -1371,7 +1375,7 @@ static int fuse_update_get_attr(struct inode *inode, struct file *file, int fuse_update_attributes(struct inode *inode, struct file *file, u32 mask) { - return fuse_update_get_attr(inode, file, NULL, mask, 0); + return fuse_update_get_attr(&nop_mnt_idmap, inode, file, NULL, mask, 0); } int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid, @@ -1515,7 +1519,7 @@ static int fuse_perm_getattr(struct inode *inode, int mask) return -ECHILD; forget_all_cached_acls(inode); - return fuse_do_getattr(inode, NULL, NULL); + return fuse_do_getattr(&nop_mnt_idmap, inode, NULL, NULL); } /* @@ -2094,7 +2098,7 @@ static int fuse_setattr(struct mnt_idmap *idmap, struct dentry *entry, * ia_mode calculation may have used stale i_mode. * Refresh and recalculate. */ - ret = fuse_do_getattr(inode, NULL, file); + ret = fuse_do_getattr(idmap, inode, NULL, file); if (ret) return ret; @@ -2151,7 +2155,7 @@ static int fuse_getattr(struct mnt_idmap *idmap, return -EACCES; } - return fuse_update_get_attr(inode, NULL, stat, request_mask, flags); + return fuse_update_get_attr(idmap, inode, NULL, stat, request_mask, flags); } static const struct inode_operations fuse_dir_inode_operations = { From patchwork Thu Aug 15 09:24:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764622 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D80FE201266 for ; Thu, 15 Aug 2024 09:24:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713901; cv=none; b=LswvVM8AKLEgw0clJDfa5kmvNVhVCQk3+X0bpz94N/6qT5Zvc/uiQ8Wm4PCXpl2iG2QTGQ+oCbn8y8IepkkeiEKlaD9mcta3wqW/R2oqGtv+urW4DQZuVCzAz74MKMtMFsIF6PSJi2e/wGLANvvOg/dstN4oIho33fPc9jtKILg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713901; c=relaxed/simple; bh=ONyUrWrgUBZRJvO+nhcwWS/g3zi/w0z15wLOTv3nesw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YDNTFKX/gyAYnS0X5D3pVKQvJVp8m7ZilfPKMudMWHZlX02msZ8PeUxoJKhloNj63oYj+JOuJNiEiRjEzlAPGhTlUeweyQvF1djGvoB0fJfRUPcNbDo3fLEoKsTKonGZzt66Y1gfOGLD8SKJVy/LJRdaIOtwPlkCwHqj+icbeWw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=WQbp65R9; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="WQbp65R9" Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 7D1DC3F48A for ; Thu, 15 Aug 2024 09:24:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713898; bh=+wGAYIUsqVxDBSfRQAij7GIIUQJC7PY8L940f+LK16E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WQbp65R96KUqMq2tQQHAbqCR5RPCIB/wA8HBBObPm/zqYgr/CKsvdBqUCfVTWd0aG Zy1SMf/Xcl50OFvzBcAnmboTuEWWFsJY8DdNz5+OXF6SbHTXndPsVoh+YxUrscscS7 xLZEwojxqawnYpaHCQzpcnmOQmBc8R/Ex6bOVQAekGxBY4RWSkkxhYBxBNjz0H4VvX bDTm1lTZLF/1tQ/2rZzKaoWrSMLHDZa8XCYocp0NlcjcMGoKZFU6kBGPAu1sE9kCR7 g+RB2AAGtpA+kA9FJa7IGVQaeDfd0zFQIYBrbCWYuyuD1j2kpqFZTD4MJq0xMj8dcx Lq3VHpnp0bFig== Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a7d2d414949so69024966b.0 for ; Thu, 15 Aug 2024 02:24:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713898; x=1724318698; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+wGAYIUsqVxDBSfRQAij7GIIUQJC7PY8L940f+LK16E=; b=Mf7xtlyGRqEui+Y8qRp23+CgvtHX7J56jGQw43/oSesCuX8+scbz4/0loboaJTZBVm xvM6WZaxGmbeAAdkgGljKehJiGLuU6S2mq3fYVxzHLUot6nYbaIQs7s1Q31E3hBhmeiZ T6yvvp7zHPIz++ERTCU8uq9NB/PYnwXkg85ANSR3Yy7Kn6m+7+1sQseAwlAEPS/4VD/f QsDPtTvloQmohEkASru4llae26ADiTkBak/d3bQiC0pEW6Y4e3yi377W29uJYXbSmj7h kFs80haQmZD2KUzOn2J/CAr+AluUc1VTqC5nxvOjJI9KAplthHgRa7Zo1XHx7HxkVt11 ZvKg== X-Forwarded-Encrypted: i=1; AJvYcCX+0R+e8FURtnsh3fTTnG3tUjnXBPmP2j1tOAX8gxMxcasknYQBOhf5g0YWsLQFpbbea9whpfRaGmY2T5Ya1FE6/PvLcmowXxoTZmmomQ== X-Gm-Message-State: AOJu0YyzFrUHrcnRi8qMj3K3yXWowSXiYLo1L8caeXpBIxxfQeBt/lTB BhOwkU3Xn1/lBlDc1ma8+Kx9hQ37PaDscXo8o6G/pG038OpGulkgIxnM6SVikUAgDkFWa0fzm1U riTK+alejyUNTNJ67BUUIqcDPP5sXUpQLb5M7GHEHxnBoWVrT7ieACT9ppWILtEnQqrISAvjNGt sFhJSviYV9t+0= X-Received: by 2002:a17:907:c7d3:b0:a7a:bd5a:1eb2 with SMTP id a640c23a62f3a-a8366ff3a98mr420619666b.54.1723713897816; Thu, 15 Aug 2024 02:24:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGuKDZsZwogroqc1dsjEpW71XEGxJgIgeq15px+a9+tIq8OenSZ6u8PMrp1qdRVRLS8F9toSw== X-Received: by 2002:a17:907:c7d3:b0:a7a:bd5a:1eb2 with SMTP id a640c23a62f3a-a8366ff3a98mr420618066b.54.1723713897408; Thu, 15 Aug 2024 02:24:57 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:24:57 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v3 05/11] fs/fuse: support idmapped ->permission inode op Date: Thu, 15 Aug 2024 11:24:22 +0200 Message-Id: <20240815092429.103356-6-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We only cover the case when "default_permissions" flag is used. A reason for that is that otherwise all the permission checks are done in the userspace and we have to deal with VFS idmapping in the userspace (which is bad), alternatively we have to provide the userspace with idmapped req->in.h.uid/req->in.h.gid which is also not align with VFS idmaps philosophy. Cc: Christian Brauner Cc: Seth Forshee Cc: Miklos Szeredi Cc: Amir Goldstein Cc: Bernd Schubert Cc: Signed-off-by: Alexander Mikhalitsyn --- fs/fuse/dir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index a5bf8c18a0ae..cd3b91b60cae 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1567,7 +1567,7 @@ static int fuse_permission(struct mnt_idmap *idmap, } if (fc->default_permissions) { - err = generic_permission(&nop_mnt_idmap, inode, mask); + err = generic_permission(idmap, inode, mask); /* If permission is denied, try to refresh file attributes. This is also needed, because the root @@ -1575,7 +1575,7 @@ static int fuse_permission(struct mnt_idmap *idmap, if (err == -EACCES && !refreshed) { err = fuse_perm_getattr(inode, mask); if (!err) - err = generic_permission(&nop_mnt_idmap, + err = generic_permission(idmap, inode, mask); } From patchwork Thu Aug 15 09:24:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764623 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6344B205E20 for ; Thu, 15 Aug 2024 09:25:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713903; cv=none; b=HcQc9hl+ZraOaVtfoCm3CEiqqiRiXduXClwq0VXDS/dDuecipBI7nceUPpNv0rLpM3WhreCFixq1avndY7vlNO77cd57emW00mWDVbcTkOV/mxT9/G+7KawOpj9s9FIafT0xe5Q6nPwhMpzyWdnUXEpm2nlZtVDAqaqor264Ub8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713903; c=relaxed/simple; bh=WQyGP3ArX26n53a7N84tK4GY62m6jwfx6zeJykj/kFg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FQWzMaZEUq8UkSfk5mIjZ3H+eWlCll9sN28nLKfRDq+jBLKXMQ2rruKA8yh9bD5lD7hD1aSvtt46IY+ZuNR6Kfp/XCideLZI/PwokPL25pJX3/tnxWFcycbptqpG7pRuY7HPX205LysIVpTIAAPV/wSzpt/Fdy9VM3J9XwSmA6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=QwwuyKaE; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="QwwuyKaE" Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id B1F933F1BD for ; Thu, 15 Aug 2024 09:25:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713900; bh=Cr6mS4vM8svS+Y0pvJjPEy2yIGPChWIqWWxar373974=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QwwuyKaEO8Km5slwrbdEzcfbvUHOhYYpw0r44U1UgUTQZC6xwdwWsXWPt9H4eWlgg gMZoA89iFym/FbpNoIOweCFgT7ukqzwvvf95uMTGCVZkjYt6RzJGAB4JCD/flJZdmn ql8BL6809vzHclsflKwv9ISRNo7Ju6mQ+nfwpJKfpe1fIfRH+MuWQHV5M5baSgP3tO ia7+MJiRQNvZUzJBV9m0ol7DO5IEggrZ0e+olS7wud/KOv2YUrCfPGQ0XIeRB80n03 zL1IAbcHC5TwFgiYJVp8nUS5l1UJGO9JR/u+bhWF1sBusIePPPSDRaC3hRsfcydZGQ M43s2lRu/VUHg== Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a80ebde3f94so65035366b.2 for ; Thu, 15 Aug 2024 02:25:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713900; x=1724318700; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cr6mS4vM8svS+Y0pvJjPEy2yIGPChWIqWWxar373974=; b=eKW1NauBsWqAHLKKdYuZZxE3ahiReO1ZfcamEZ9lYNI/GHKMzvFDS4XvHi5VCvB92K iVeWuVNk2YZVBsrqGexngi89cTYa4qvMgjTD0beDihQDjimHCmjpbCD/L0jYt8/TphYl oms8QJuLo239vdQgugZMK0nxyPL/0rH6/Mzu85aoC/tk+0rZYw72aTrbr6WxwiVrFNn1 O/l4k+ACSPIzpsC9j2wuFe2Q3d+EbEZ9QCkv9A/XHubfImSqrF6hcJslCYgUk1/q6p0H maeBSXKmYCTyjsu/Q4p3f9TPPiHISFa+jQ2F0Qxanz6xObZ1VftYt662OEu84jo9OwJA qChQ== X-Forwarded-Encrypted: i=1; AJvYcCURwnSc4Rz4Vw9WIdDvuANba9UQLjg4S7UTv92xo36FkLLn51YglC50uVxWJI6E4U72NNy4DtdMas83vsJB0tR8WI2yj7HCMQ0cNojG6w== X-Gm-Message-State: AOJu0YzRn5YsFBFpDNLd+8cNfMOyqNVWxFMiNMkGODkN4FjJvhEQdlID XijqG5emnhNPxNZK87kvLeLCV/IVaedZqiVW+BSUTVcA1N0TJnnETw5nDNX8Ez5ZJmZuHXT+gUY znutjP31im8krPFKVsNpCEk1P1KnjHyzdKvP3mrQLxEMG4xAVm9gJ8IVOVRuQJ2oTE/OY03YCZc HEne4= X-Received: by 2002:a17:907:3f89:b0:a7a:a33e:47b7 with SMTP id a640c23a62f3a-a83670722aemr419369866b.69.1723713900169; Thu, 15 Aug 2024 02:25:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEghyVaXn5Dbtn6avz2ju4iyCpDYekR/UIUNfpUCzBfAEqAmdPwUCKFJ/4+cn52QZhbpY2Qjw== X-Received: by 2002:a17:907:3f89:b0:a7a:a33e:47b7 with SMTP id a640c23a62f3a-a83670722aemr419367866b.69.1723713899831; Thu, 15 Aug 2024 02:24:59 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:24:59 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v3 06/11] fs/fuse: support idmapped ->setattr op Date: Thu, 15 Aug 2024 11:24:23 +0200 Message-Id: <20240815092429.103356-7-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Cc: Christian Brauner Cc: Seth Forshee Cc: Miklos Szeredi Cc: Amir Goldstein Cc: Bernd Schubert Cc: Signed-off-by: Alexander Mikhalitsyn --- v2: - pass idmap in more cases to make code easier to understand --- fs/fuse/dir.c | 32 +++++++++++++++++++++----------- fs/fuse/file.c | 2 +- fs/fuse/fuse_i.h | 4 ++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index cd3b91b60cae..c50f951596dd 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1771,17 +1771,27 @@ static bool update_mtime(unsigned ivalid, bool trust_local_mtime) return true; } -static void iattr_to_fattr(struct fuse_conn *fc, struct iattr *iattr, - struct fuse_setattr_in *arg, bool trust_local_cmtime) +static void iattr_to_fattr(struct mnt_idmap *idmap, struct fuse_conn *fc, + struct iattr *iattr, struct fuse_setattr_in *arg, + bool trust_local_cmtime) { unsigned ivalid = iattr->ia_valid; if (ivalid & ATTR_MODE) arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode; - if (ivalid & ATTR_UID) - arg->valid |= FATTR_UID, arg->uid = from_kuid(fc->user_ns, iattr->ia_uid); - if (ivalid & ATTR_GID) - arg->valid |= FATTR_GID, arg->gid = from_kgid(fc->user_ns, iattr->ia_gid); + + if (ivalid & ATTR_UID) { + kuid_t fsuid = from_vfsuid(idmap, fc->user_ns, iattr->ia_vfsuid); + arg->valid |= FATTR_UID; + arg->uid = from_kuid(fc->user_ns, fsuid); + } + + if (ivalid & ATTR_GID) { + kgid_t fsgid = from_vfsgid(idmap, fc->user_ns, iattr->ia_vfsgid); + arg->valid |= FATTR_GID; + arg->gid = from_kgid(fc->user_ns, fsgid); + } + if (ivalid & ATTR_SIZE) arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size; if (ivalid & ATTR_ATIME) { @@ -1901,8 +1911,8 @@ int fuse_flush_times(struct inode *inode, struct fuse_file *ff) * vmtruncate() doesn't allow for this case, so do the rlimit checking * and the actual truncation by hand. */ -int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, - struct file *file) +int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry, + struct iattr *attr, struct file *file) { struct inode *inode = d_inode(dentry); struct fuse_mount *fm = get_fuse_mount(inode); @@ -1922,7 +1932,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, if (!fc->default_permissions) attr->ia_valid |= ATTR_FORCE; - err = setattr_prepare(&nop_mnt_idmap, dentry, attr); + err = setattr_prepare(idmap, dentry, attr); if (err) return err; @@ -1981,7 +1991,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, memset(&inarg, 0, sizeof(inarg)); memset(&outarg, 0, sizeof(outarg)); - iattr_to_fattr(fc, attr, &inarg, trust_local_cmtime); + iattr_to_fattr(idmap, fc, attr, &inarg, trust_local_cmtime); if (file) { struct fuse_file *ff = file->private_data; inarg.valid |= FATTR_FH; @@ -2116,7 +2126,7 @@ static int fuse_setattr(struct mnt_idmap *idmap, struct dentry *entry, if (!attr->ia_valid) return 0; - ret = fuse_do_setattr(entry, attr, file); + ret = fuse_do_setattr(idmap, entry, attr, file); if (!ret) { /* * If filesystem supports acls it may have updated acl xattrs in diff --git a/fs/fuse/file.c b/fs/fuse/file.c index f39456c65ed7..562bdf8d5976 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2966,7 +2966,7 @@ static void fuse_do_truncate(struct file *file) attr.ia_file = file; attr.ia_valid |= ATTR_FILE; - fuse_do_setattr(file_dentry(file), &attr, file); + fuse_do_setattr(file_mnt_idmap(file), file_dentry(file), &attr, file); } static inline loff_t fuse_round_up(struct fuse_conn *fc, loff_t off) diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index d06934e70cc5..883151a44d72 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1333,8 +1333,8 @@ bool fuse_write_update_attr(struct inode *inode, loff_t pos, ssize_t written); int fuse_flush_times(struct inode *inode, struct fuse_file *ff); int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); -int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, - struct file *file); +int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry, + struct iattr *attr, struct file *file); void fuse_set_initialized(struct fuse_conn *fc); From patchwork Thu Aug 15 09:24:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764624 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC3E8201266 for ; Thu, 15 Aug 2024 09:25:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713909; cv=none; b=YqpaT0JwZiYZotynb0/2FfixYP0WJST2YOMfHLahSbqE1TtXHI9/PYcrhBtxA12acGqLq+Y5TBb2of8bnYvzoGIZy6TlL1iIDN4FzZaYfXW9S4GZlH8c//CAeCovfsm7sMLWUA+RQaI9MZ2nlJWpYZ0jDWYu5UGVK3NGJNCnEUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713909; c=relaxed/simple; bh=4adc61tKzjK2fTdo7B9pTquQAHQKVd/XEnUnW9CoK7g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rMPDENPrrGvUQ2E3iZ+hk2cZKVWE5qUL5o8dj71CT4YzwVC896lf1cI9YMbeCwBl5ZCkpuvguLwuu3qMMgokF2SkQV0wZJdY8+vrZW0W1ZzisfjNxjF4lPzy/wuE7K5cdbM9AaTmGpyFut4O6GNjqudpVXSl5jSWgMRKJIS9Ftk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=DKXqD5e9; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="DKXqD5e9" Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 6D9003F31C for ; Thu, 15 Aug 2024 09:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713906; bh=ftHOv+os2MH3Qk9OKnsGMHrGZxHBoFg3umKFJ4e1joU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DKXqD5e9tHFJS/l+r2i86IlJfKbS9PFq/X6Jj4pjfhuwvKJL/HpOPsFJKMmLIk77f Hd7dFi8dAMV1fgJyK49q0ZSdoL57991ge89/T4q/bkffN2pvstqg8Z8QcHQhjDH81L gSnTxMzgDTxmUfkvFWdf5VxmlU2ort6Y5yULD2s6T8NWgxydsGaOwPzI8Zr0QI0l/L vv8uYid8OUpaImQI4vWMwYuG54B/JBbFKBK1Ej4lraly5CXynOD2HuOuyeWZnSFt7H UN3OBgoILwsGfkeQEMVozK0mDfkAhQhDCQs+dM3PxJdj2q/WOwYnTjzNs8pfL+UoaK YcwFd1Y3AZcqQ== Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-532fbabc468so773704e87.0 for ; Thu, 15 Aug 2024 02:25:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713903; x=1724318703; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ftHOv+os2MH3Qk9OKnsGMHrGZxHBoFg3umKFJ4e1joU=; b=Sr7O6pQA4MBAUtSSz5L25iiP2HVfUUnfav4pQLcSJuKUprzdlu4xqpHlQ6Gq537VSB yjY9GO3YOx5LQp+JFycDAhYHvbO8kzzf0ffTV+cYNimny7n+hpIxQIuasCTKLHPKmHAx Q60EUAzqfOlhdNS7plfh8j4P793qw4EVgolT2luKTtWXarcQ+ji89B7R72k367kbESAJ zz6Ghn9kNkYS+y6rzYwVgihLR35hGDaV5r8Tj9By1ALwe0lorNc7KA00QmC+LVJzCub7 KqNrEguWV+LvA62MoHcA57NCmdg3FxzHenu2VC7vanY+rCcozn/oRdtNjwdw58kbR5oM 4D/Q== X-Forwarded-Encrypted: i=1; AJvYcCXrvLuO12w67JPeI6xfnStkIECxyC/O+6iRyIJd1748CJdOggP9pug4DYaq2kviZFAtilMCk+r/vWZcRRzTfUXq6ZFICJM67kwiqUx9Dg== X-Gm-Message-State: AOJu0YyFkfAsNWityC4na4+u8CpN948Xvrad7U+09vKx0WzhFmtx0M1l sf9eAmvwqPrbctUIflD4mzw5Pgp76a3ETB8g1bEgSYRgPp9SSoDgc2Ue8U6EXR8NhFvjiTOwQig nF930O7Og9+qQLIdrNAcnRPEbV19U4TBXamQeNYPztHok5pdCaY3btEXPBTxr81ebyc9Zvp5DSs 5YnpE= X-Received: by 2002:a05:6512:282a:b0:52d:582e:410f with SMTP id 2adb3069b0e04-532edbbcdddmr3352411e87.46.1723713902558; Thu, 15 Aug 2024 02:25:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTZkKDHUW/a1SQ8jPfQJ+Q+tEU5ep/4T2uXV0NfHa+967OhzX5TBfB5pRRpmHTOYVJYolsYw== X-Received: by 2002:a05:6512:282a:b0:52d:582e:410f with SMTP id 2adb3069b0e04-532edbbcdddmr3352395e87.46.1723713902114; Thu, 15 Aug 2024 02:25:02 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:25:01 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v3 07/11] fs/fuse: drop idmap argument from __fuse_get_acl Date: Thu, 15 Aug 2024 11:24:24 +0200 Message-Id: <20240815092429.103356-8-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We don't need to have idmap in the __fuse_get_acl as we don't have any use for it. In the current POSIX ACL implementation, idmapped mounts are taken into account on the userspace/kernel border (see vfs_set_acl_idmapped_mnt() and vfs_posix_acl_to_xattr()). Cc: Christian Brauner Cc: Seth Forshee Cc: Miklos Szeredi Cc: Amir Goldstein Cc: Bernd Schubert Cc: Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Christian Brauner --- fs/fuse/acl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/fuse/acl.c b/fs/fuse/acl.c index 04cfd8fee992..897d813c5e92 100644 --- a/fs/fuse/acl.c +++ b/fs/fuse/acl.c @@ -12,7 +12,6 @@ #include static struct posix_acl *__fuse_get_acl(struct fuse_conn *fc, - struct mnt_idmap *idmap, struct inode *inode, int type, bool rcu) { int size; @@ -74,7 +73,7 @@ struct posix_acl *fuse_get_acl(struct mnt_idmap *idmap, if (fuse_no_acl(fc, inode)) return ERR_PTR(-EOPNOTSUPP); - return __fuse_get_acl(fc, idmap, inode, type, false); + return __fuse_get_acl(fc, inode, type, false); } struct posix_acl *fuse_get_inode_acl(struct inode *inode, int type, bool rcu) @@ -90,8 +89,7 @@ struct posix_acl *fuse_get_inode_acl(struct inode *inode, int type, bool rcu) */ if (!fc->posix_acl) return NULL; - - return __fuse_get_acl(fc, &nop_mnt_idmap, inode, type, rcu); + return __fuse_get_acl(fc, inode, type, rcu); } int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, From patchwork Thu Aug 15 09:24:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764626 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DD1320FA8C for ; Thu, 15 Aug 2024 09:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713910; cv=none; b=bk8ibpyLtYxUq5SmktLgb/LMZ2xDMW9Fd7TrOvfNxzlCWaNsI/1ngr+tg1E2QqkA3m6WWuRZ1NR37YQmGXM48UirP0efmcqJ5pu8fE+MbQihvxrNTH2bBkxkEPFiM7rSoIBBKVMdUU8Xml7LE08vhc9sen66RYWpUezvawp3WXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713910; c=relaxed/simple; bh=ItY86ikXLB5CiOOsAivB6bVSog31+kYXgujXhFdDat8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XUzUOv6GA8g+f6MHIf7iW/gEv6cx/SDQ/xHL2yZ+wsWUhPxhviNBGQ3HtOAKboPQtub46RONY7MArvN1Pcc7ZosCXMRpEpFats7ueg0uGN4WoRhNtOt2i6gJFpWnmTfh+Rz9U9LQnKADFExfgjo73ZxB0S7rAPgjGkKwisl9oBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=uKYtqnOY; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="uKYtqnOY" Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 2D6E9402E8 for ; Thu, 15 Aug 2024 09:25:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713907; bh=AKgOJzf1FD6sazbw1kqXlY4ydMZMTG/q+wfid3Wy6NY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uKYtqnOYPR3K/sTeXrDQWfFo9+G2Xh7O3ihjiNiBQNCXFsYhqgsapU9Q9cb8RpdxS iaaK1f2kbetz2xlEE4wOwmiP274yX8D7fz/yU4OEMvncYzjany2bLYpNiNRLcjGwKL T7yAB0lQdH18WhNEJs7XnKozIKx6260UiMlMFEE54A/wjsEPqJmrKUoHbGfsssPI4T LTpOww3/Q/khPbtnmb3G39QdXjw0ke5m+qdk7f5K32fkMNTq12tHNxtluDusNqqqoD Tij+J00E1S1+FGe9TniBwXHxnMoLU4bTnKVnuE9ODK+IbAD+rRhZ27isXH7zTHdKI9 xmIvSORsPrs7A== Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-52efe4c2261so927426e87.1 for ; Thu, 15 Aug 2024 02:25:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713905; x=1724318705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AKgOJzf1FD6sazbw1kqXlY4ydMZMTG/q+wfid3Wy6NY=; b=QarFFmWeAkakK9xmTkMFUGSl4KnmppFuwxCdigHVYjl6t3Fp0Zq1RSUnGhdyk0Y2vx oEiK96cYCsMfZ6trO0Y3pnPrC+wGb0K+F7UIoOEsxDoqP/gZi18M4Z/zQjsxb8zrzSXM odzeZB1uLREfUDPfpf8v6+XbKkbnIui6LxOhX47yDQuMgVYRju977MpArpI/r/LnMOdz My/hYv/ETCuk8RkaaxQ28c6SL9xFtF3JLRFR6A7jo57v/ieNgNec10nDbKLbHcvRAv7s v0YQKZBjeOauI+CwQIWOPM0C40sACnnZUkYnnPWKFiKojjw1wKsxFvcZbscrrYCGwWzj Rfhw== X-Forwarded-Encrypted: i=1; AJvYcCWoSsNME5WTo4u7QLRlkekheUPaNpczMQ192ZgzpaMyEpEgWWCqEtGEgu18ASA4vBzvE/yF7GSppdh/R5XqZ1A1iRurrUcYuHvz5QSJGw== X-Gm-Message-State: AOJu0Yxu/dv2q9efvZYvSORpJ+ePaPJCkczEbgw+UD89zJRk43hstKKG Y8U5AWlrklKTHhfaEYpyPrw5wYm0J+R8W/eyjGxXaRhnGLTGlskU/Ka133hD64CV0nDi4K23aqi Kq2OFUuhciZi3Vr7izg/hMmwfFe0ishib7nqU+B4dOQFZp86o2eiI8Q1rw+JZxUYV+Q5KA4mAAX e80kU= X-Received: by 2002:ac2:5695:0:b0:532:fb9e:a175 with SMTP id 2adb3069b0e04-532fb9ea617mr3817510e87.6.1723713904889; Thu, 15 Aug 2024 02:25:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGx/vdKNpZNgVQz01CbRwoXGyKCak1Dnuqwz633QdtWw+oIMOWdvHhKLICOjgJpC7mpuObEw== X-Received: by 2002:ac2:5695:0:b0:532:fb9e:a175 with SMTP id 2adb3069b0e04-532fb9ea617mr3817480e87.6.1723713904456; Thu, 15 Aug 2024 02:25:04 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.25.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:25:03 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v3 08/11] fs/fuse: support idmapped ->set_acl Date: Thu, 15 Aug 2024 11:24:25 +0200 Message-Id: <20240815092429.103356-9-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 It's just a matter of adjusting a permission check condition for S_ISGID flag. All the rest is already handled in the generic VFS code. Notice that this permission check is the analog of what we have in posix_acl_update_mode() generic helper, but fuse doesn't use this helper as on the kernel side we don't care about ensuring that POSIX ACL and CHMOD permissions are in sync as it is a responsibility of a userspace daemon to handle that. For the same reason we don't have a calls to posix_acl_chmod(), while most of other filesystem do. Cc: Christian Brauner Cc: Seth Forshee Cc: Miklos Szeredi Cc: Amir Goldstein Cc: Bernd Schubert Cc: Signed-off-by: Alexander Mikhalitsyn --- fs/fuse/acl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/fuse/acl.c b/fs/fuse/acl.c index 897d813c5e92..8f484b105f13 100644 --- a/fs/fuse/acl.c +++ b/fs/fuse/acl.c @@ -144,8 +144,8 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, * be stripped. */ if (fc->posix_acl && - !in_group_or_capable(&nop_mnt_idmap, inode, - i_gid_into_vfsgid(&nop_mnt_idmap, inode))) + !in_group_or_capable(idmap, inode, + i_gid_into_vfsgid(idmap, inode))) extra_flags |= FUSE_SETXATTR_ACL_KILL_SGID; ret = fuse_setxattr(inode, name, value, size, 0, extra_flags); From patchwork Thu Aug 15 09:24:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764625 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1322820FAA1 for ; Thu, 15 Aug 2024 09:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713910; cv=none; b=Qhtf3c3G4bXT3NXgTa6TwYR1c6kYopxV5DM25PRFRUSS0tXolbRo8R2aa14rDL9jT+d5yEzuhOfBFhajAtmHAkXOhuRn5ZWUe5OvL7stmBb/mlHSLY1o44cdl32SVksrUas55KNG2xUFjYxWDHVwHNa8Dx8/3KxaC3/9jwfOw/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713910; c=relaxed/simple; bh=9LyCmNQL+Wo2sLWHPY86vHgjnCGu8A+hXloJ3pDxAko=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Qx/wnaUoNRo1dMO9Bv4+0crMzE6sZgD3hcYhA8hl9XhLjetHpdY0Qgxzu546deOxtLibBr62hYMgnuw3jwHwBVtUKXDdSgFow9ND+egXNqm9FkzpaQJqoJKODodxsDuZyaFDO1gOAPB6oJTNivYW79xKmxO0OGtyp+Vljc8vDHU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=R86FgbAk; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="R86FgbAk" Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C75913F670 for ; Thu, 15 Aug 2024 09:25:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713907; bh=ex29ohbhGi3Fy6+0Qs/1K/FDT7vHiirCCSI2eAx8vvk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R86FgbAkGw8v8oIzoq6yVS/N45XM7MC35LVyhhnJYLgPT+P1mtfCZ1juOGIJk24I2 wHln28uqSibfD9o/Ck2KAMUOJV7uhJbbxEtGMrrEgxl7tc7INt7yQF7RCt8/rP5mZ3 wxRWWqOuTR7Pt1zKkxsI3+MdiGIqknitdln2Fmry27A21GCnxIEk/8KfAWM5YctxjR jvayuk5uUbXAcqQ/rDnqrScP+29Udp3xUHVxOKM3JVF1fKRqoK9ZxeUzml+HIdrpA6 LBJB40UcnPOOf7ELFeSmNuCpnCTIWAEiE0MB7aeKE5gY4VkA7nk8nSacTWLHeIbhXl 1s+PvInnZg1Yg== Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a79c35c28f1so71968566b.3 for ; Thu, 15 Aug 2024 02:25:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713907; x=1724318707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ex29ohbhGi3Fy6+0Qs/1K/FDT7vHiirCCSI2eAx8vvk=; b=IxVN0btAWmbDAt/QcV9PbtnipZ1RUjBu44bY1F9n4CzKrrio7VjC+dAhA6df1G2g/O Lqvti4VFhULEpK2Kr5OrpDiAmQbjjL0ykQBOr5lPBhEekwnwUSxPYIYkHCCLG5c6QabT +KD+n6ontpSQEjQ8F8VlUqfy9QBk424c2FxUt0ygRu7dKlXrokypwBCLKQBmDtVfv5K1 M8Vz+irOrxelIuCesAB2LBsHHlG8SZvFBnll7Azuumld0+T/wlQIzOd81rD/4AG+5eCh 2jelZjfeThvpdvsSr02z/rU5DX+/BZt3BgWZDExeY3XDHxi2PEbQ1YYpXBDvXQUGqsaU NdDg== X-Forwarded-Encrypted: i=1; AJvYcCX2/fUy/rry/7K2xywfAM2ZQcZFQZ2Y6hMHTquuns3nxkJ57rhSwcZ55sMSrtpBq0hfHdqIzwFJLBY0gJQ7GuRMa/C38wKkmtLIJDVtPg== X-Gm-Message-State: AOJu0YzHKQsu4z8uqkmrRNekhKQ05kwSNiN7c9od3Cr7IvjNTNKdBcgq zDeMAz1FDQSW5XFrbe8w0Z6RrbVhbEpyIttvca8FpyXK4Sh6Kx7ZCZZTeOnXu9f2vJoU5M6tL9B PVD2iLGFZn2GBHumzawGo6EDiJlefxh2jx1BIus7Bru58i2G1pCbOU9NTuioC3o5cU6qzMgfFOY RS64c= X-Received: by 2002:a17:907:e622:b0:a7d:cf4f:180b with SMTP id a640c23a62f3a-a8366d5be39mr383852566b.32.1723713906894; Thu, 15 Aug 2024 02:25:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZ5OnmkMFXHCENGvuouya0YLtsXvkFjYOL6tsjC3SgQjQW5b/e4j/Mtgu8clZbCAuhvbK4pg== X-Received: by 2002:a17:907:e622:b0:a7d:cf4f:180b with SMTP id a640c23a62f3a-a8366d5be39mr383851166b.32.1723713906574; Thu, 15 Aug 2024 02:25:06 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:25:06 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v3 09/11] fs/fuse: properly handle idmapped ->rename op Date: Thu, 15 Aug 2024 11:24:26 +0200 Message-Id: <20240815092429.103356-10-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Support of RENAME_WHITEOUT with idmapped mounts requires an API extension for FUSE_RENAME2. Let's just forbid this combination for now. It's not critical at all as it's only needed for overlayfs on top of fuse/virtiofs. Choice of EINVAL is not random, we just simulate a standard behavior when RENAME_WHITEOUT flag is not supported. Cc: Christian Brauner Cc: Seth Forshee Cc: Miklos Szeredi Cc: Amir Goldstein Cc: Bernd Schubert Cc: Signed-off-by: Alexander Mikhalitsyn --- v2: - this commit added --- fs/fuse/dir.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index c50f951596dd..0cd01f25251f 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1111,6 +1111,9 @@ static int fuse_rename2(struct mnt_idmap *idmap, struct inode *olddir, if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) return -EINVAL; + if ((flags & RENAME_WHITEOUT) && (idmap != &nop_mnt_idmap)) + return -EINVAL; + if (flags) { if (fc->no_rename2 || fc->minor < 23) return -EINVAL; From patchwork Thu Aug 15 09:24:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764627 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1920B2139B0 for ; Thu, 15 Aug 2024 09:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713914; cv=none; b=FMM+QlVVfvuoSHuJJ+f6I6tb4WdABhhcuP9HcOLUrKHhuF+YlJa8lnNYdZlrEI4EtIGVCWhlDJ88ZQYFpCZ4fkTNvuTkSjqvYs07AqDSP/hV9Og4ryU6H3X4ENqK1rhQ+lTQLFW4Flh/B/nBhoJl8edX9ZWmUSiwNEwHSH7dIgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713914; c=relaxed/simple; bh=Uvo6a5h0Mq4wDc4UKZj3kSS6IHIbPsNpdHtWtHYTJrE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mAgajzgataRQoLQ6l65RTNsAddRUbh3chFb7K3Vnp5mJstj+vixTz0y5kAxHkRdqB0Cho0uUyEZfKRHMQ9g2TzopyUvQvv+K9I72EF4IHshBqPTlxLO+OFErlZZaJyykwTQkgEQGbh8oPbj3XfP/J/3dGda43ZYLZFO0GDe7VAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=X7pteKxh; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="X7pteKxh" Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 9484B3F322 for ; Thu, 15 Aug 2024 09:25:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713911; bh=63Iup0ra8rDQZw3AHJfX27OH/U8X3fJMxHpyqnCbE2I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X7pteKxhTQdg6dDKuM17Z4/hWR5DvkQhqHozDJFSmU9/1oUypHAs26OiJNOJm5DC0 TOWIwK54ndx+agaNEg0AiHWha6fj2NSWEW7SwuUXA2q6ByUfGHazkBpugUqYmDuxnY jDyfzKph3kDXJZi4nDQFGWNeWOSCV/DofyxCiR7E7VmGOkuK9uViyz1qhwGzkxsj4t nazEqdWOWTsB+GE5JiJ+AW70DhORI+kzlc1RaKGYtnqzdn+TmVepReAQPa0oI4QnAi J7E/jIl4TNIyuZ0jKuDTyxZ/s6sNaNbzf8gg906Rxj6fb4Tm6y1nxgyYiHtetUx3mX Zi0fukupu1LQg== Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a79c35c28f1so71969866b.3 for ; Thu, 15 Aug 2024 02:25:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713909; x=1724318709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=63Iup0ra8rDQZw3AHJfX27OH/U8X3fJMxHpyqnCbE2I=; b=vNr0MfS+FUl9uU0IQ/mOHaFEbNLmfo4oijM7ZVddVFj/MZWJx2uNb5uEPd0zEH6F3d 0QtP1Spxk0YxNoDEPYv+eRTzoQu/W40g4UD2/glDHAsVSegcvmru3bAPw+bl+CG88Zwk BrpA5gBv8+UbsmiKvyMnI0JxU7QhmuTlSKb6CIdcHO2A6Hp/Gv3yz/oT7c/5YAOXz5gl WCNPRX6VHc626VbUKDLDQgUjn+OXdYjNEMhv2o/yeC8Dop/XKIF+7pcHsjeZ+yStdaRp 6ChCJSYvIZ/ivCXK5bGfZcr8xobDjLHAK1BLGj5Lgnn1b1YK85t5OjRFhBrO1yIbL7cg Cyqg== X-Forwarded-Encrypted: i=1; AJvYcCUdAQ4mDTqEauOHCe0ZNUeyO/1lDVDLHsdnYSbk1apf4eRBDLAYQZ5LphVThxcO3yLrfx79gtEgDbHE38VM2rcfgF6adCfxWVGCIwjOLQ== X-Gm-Message-State: AOJu0YzGbCO1Iwqr67Vp4x8ElizjS67iUcGjn+0d/cwoWhZ2XMYW0vSB cMiCt+nly+OGefU0MBMybsbkI5xf21296a+tVcSqtnnvzzxTTCfJ5oKiBs14NpSG8Q6emOZM1MS Mp+rwiwbBNpbJGHktbghjBioeGAEqE7aeVVJWogFdDNltgrEG8GtBzyeAH12hpAak3n73B9BhIf c8484= X-Received: by 2002:a17:907:ea5:b0:a80:bf0f:2256 with SMTP id a640c23a62f3a-a8366c1e7a1mr381458966b.8.1723713909245; Thu, 15 Aug 2024 02:25:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETTIDQ9OzhDD4lLGreLHiYuvXvyqwtTitrGMl+Ajjnib3jCTcBF7RJUjWTevOZFresikXBrg== X-Received: by 2002:a17:907:ea5:b0:a80:bf0f:2256 with SMTP id a640c23a62f3a-a8366c1e7a1mr381457466b.8.1723713908704; Thu, 15 Aug 2024 02:25:08 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:25:08 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v3 10/11] fs/fuse: allow idmapped mounts Date: Thu, 15 Aug 2024 11:24:27 +0200 Message-Id: <20240815092429.103356-11-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now we have everything in place and we can allow idmapped mounts by setting the FS_ALLOW_IDMAP flag. Notice that real availability of idmapped mounts will depend on the fuse daemon. Fuse daemon have to set FUSE_ALLOW_IDMAP flag in the FUSE_INIT reply. To discuss: - we enable idmapped mounts support only if "default_permissions" mode is enabled, because otherwise we would need to deal with UID/GID mappings in the userspace side OR provide the userspace with idmapped req->in.h.uid/req->in.h.gid values which is not something that we probably want to. Idmapped mounts phylosophy is not about faking caller uid/gid. Some extra links and examples: - libfuse support https://github.com/mihalicyn/libfuse/commits/idmap_support - fuse-overlayfs support: https://github.com/mihalicyn/fuse-overlayfs/commits/idmap_support - cephfs-fuse conversion example https://github.com/mihalicyn/ceph/commits/fuse_idmap - glusterfs conversion example https://github.com/mihalicyn/glusterfs/commits/fuse_idmap Cc: Christian Brauner Cc: Seth Forshee Cc: Miklos Szeredi Cc: Amir Goldstein Cc: Bernd Schubert Cc: Signed-off-by: Alexander Mikhalitsyn --- v2: - simplified and get rid of ->allow_idmap global VFS callback v3: - now use a new SB_I_NOIDMAP flag --- fs/fuse/inode.c | 14 +++++++++++--- include/uapi/linux/fuse.h | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 6c205731c844..b840189ac8be 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -1345,6 +1345,12 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, fm->sb->s_export_op = &fuse_export_fid_operations; if (flags & FUSE_OWNER_UID_GID_EXT) fc->owner_uid_gid_ext = 1; + if (flags & FUSE_ALLOW_IDMAP) { + if (fc->owner_uid_gid_ext && fc->default_permissions) + fm->sb->s_iflags &= ~SB_I_NOIDMAP; + else + ok = false; + } } else { ra_pages = fc->max_read / PAGE_SIZE; fc->no_lock = 1; @@ -1392,7 +1398,8 @@ void fuse_send_init(struct fuse_mount *fm) FUSE_HANDLE_KILLPRIV_V2 | FUSE_SETXATTR_EXT | FUSE_INIT_EXT | FUSE_SECURITY_CTX | FUSE_CREATE_SUPP_GROUP | FUSE_HAS_EXPIRE_ONLY | FUSE_DIRECT_IO_ALLOW_MMAP | - FUSE_NO_EXPORT_SUPPORT | FUSE_HAS_RESEND | FUSE_OWNER_UID_GID_EXT; + FUSE_NO_EXPORT_SUPPORT | FUSE_HAS_RESEND | FUSE_OWNER_UID_GID_EXT | + FUSE_ALLOW_IDMAP; #ifdef CONFIG_FUSE_DAX if (fm->fc->dax) flags |= FUSE_MAP_ALIGNMENT; @@ -1569,6 +1576,7 @@ static void fuse_sb_defaults(struct super_block *sb) sb->s_time_gran = 1; sb->s_export_op = &fuse_export_operations; sb->s_iflags |= SB_I_IMA_UNVERIFIABLE_SIGNATURE; + sb->s_iflags |= SB_I_NOIDMAP; if (sb->s_user_ns != &init_user_ns) sb->s_iflags |= SB_I_UNTRUSTED_MOUNTER; sb->s_flags &= ~(SB_NOSEC | SB_I_VERSION); @@ -1981,7 +1989,7 @@ static void fuse_kill_sb_anon(struct super_block *sb) static struct file_system_type fuse_fs_type = { .owner = THIS_MODULE, .name = "fuse", - .fs_flags = FS_HAS_SUBTYPE | FS_USERNS_MOUNT, + .fs_flags = FS_HAS_SUBTYPE | FS_USERNS_MOUNT | FS_ALLOW_IDMAP, .init_fs_context = fuse_init_fs_context, .parameters = fuse_fs_parameters, .kill_sb = fuse_kill_sb_anon, @@ -2002,7 +2010,7 @@ static struct file_system_type fuseblk_fs_type = { .init_fs_context = fuse_init_fs_context, .parameters = fuse_fs_parameters, .kill_sb = fuse_kill_sb_blk, - .fs_flags = FS_REQUIRES_DEV | FS_HAS_SUBTYPE, + .fs_flags = FS_REQUIRES_DEV | FS_HAS_SUBTYPE | FS_ALLOW_IDMAP, }; MODULE_ALIAS_FS("fuseblk"); diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index d9ecc17fd13b..b23e8247ce43 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -221,6 +221,7 @@ * 7.41 * - add FUSE_EXT_OWNER_UID_GID * - add FUSE_OWNER_UID_GID_EXT + * - add FUSE_ALLOW_IDMAP */ #ifndef _LINUX_FUSE_H @@ -256,7 +257,7 @@ #define FUSE_KERNEL_VERSION 7 /** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 40 +#define FUSE_KERNEL_MINOR_VERSION 41 /** The node ID of the root inode */ #define FUSE_ROOT_ID 1 @@ -427,6 +428,7 @@ struct fuse_file_lock { * of the request ID indicates resend requests * FUSE_OWNER_UID_GID_EXT: add inode owner UID/GID info to create, mkdir, * symlink and mknod + * FUSE_ALLOW_IDMAP: allow creation of idmapped mounts */ #define FUSE_ASYNC_READ (1 << 0) #define FUSE_POSIX_LOCKS (1 << 1) @@ -473,6 +475,7 @@ struct fuse_file_lock { /* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */ #define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP #define FUSE_OWNER_UID_GID_EXT (1ULL << 40) +#define FUSE_ALLOW_IDMAP (1ULL << 41) /** * CUSE INIT request/reply flags From patchwork Thu Aug 15 09:24:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13764628 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACD7B21C160 for ; Thu, 15 Aug 2024 09:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713916; cv=none; b=boWCboX1c+vYoxFmiinqbH2BpGVuCM2d20dmPYIvl86MWCmd2X3xvUPNZxdX30jMuxfkvQ1i+UGwX7RQ2408iQi7tloSg12Dz+npzNz3JQ6weJaKKCwJ7gclH23vYZjX+d69gO9exqaxUhBgY1gjo1wYORLMdif/aJf5H0A1EI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713916; c=relaxed/simple; bh=ymy9AdLU4FnRhhiUnMjD0ZbEgyL+Q2k8uHDQ8UA+HNE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lnCGPp8S7cf9D+QVOtHm8IiBa/nQ7gzoQJyayKaB6GP/wM/iuJ7xHBI3IaQIphW7bLbuZgQnb8QbNgwdwTEPXXhhrm2tEtauPMgukCs9cTf16TkAT+yOA3iAwovfJ73WiEbQnVDebq/PWO/M4qq5+7e+xw+43cV+fEx+TnAMim4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=ORm2gGoD; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="ORm2gGoD" Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id D3EB13F670 for ; Thu, 15 Aug 2024 09:25:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1723713912; bh=mjFOlrsdA+rODkwJYHT/kVKlqhDJvVibiu+JqNMSC1g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ORm2gGoDL4V40CyxZRLO/AO48sGW16oz+oWNDdjw8iC/FvkJZsYU3eLZRNUOPUcoX mNB5dXFMwjDWEb6Wkp7Nkb4cn+CkkExSjoZ5iOkNN/oApNI9B1EhxiKX5EjVGdrUCm j4ON28VAam68el/G82rUir6fYK6RX6IgVTVz24W0LF5tg7Ntgkt6WLkWR42uu+2xyF 5rgbpd6YQwdk3x4ZZKQsf1XgOTxvyfv0l+20wMNx+8nS7IHg4KpqhQrpXFtd7d/ZQW HhG/KGYLy42ia5VluUyPnWnbo1492Wo48Nw6+UsQ2ddNYxID26CMXauBcZpeenRwvZ Z/OZIvz+/0G3w== Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-530c299a480so647257e87.0 for ; Thu, 15 Aug 2024 02:25:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723713912; x=1724318712; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mjFOlrsdA+rODkwJYHT/kVKlqhDJvVibiu+JqNMSC1g=; b=wqC8rTyuYXAS3pQ3iL/+gD7vMsrangVHRHL1WC5JpJVAD/ZPyi7HHl7xDg30zkDTlz FHQPjZjFnssYrNwWLNEFglf7xGz9hBNcQA7Uu1zH2dkPE1CUwlFBrNO9QWjraJ8QHjt4 RUXh/YTaVDl9/aNHnsXvFpJNHdpwxrj55AK/tL5bNlPbhZYf8emZKxBW/DpZmXdQ2stA HQG03bPQaNRcIximAK+AWCko3y8sZsR9frKtNXaSfkUou3wCBxHv0mVp/qwezUDMwelo xSMmza62adarO9V62P+85gwGuOt0l6uhnpVeq3N2IPOYX1UglgldrKEbU+D8wfxN755y 75eQ== X-Forwarded-Encrypted: i=1; AJvYcCXQByAVLgYPEaXYLofoMarn3MpnF3+VVZ8Lq8Nj/2SNKv4gYXaNVikWJvbLZjpBfA575XfqAN0EmLUUxtyDsafKGVDJHKC5h08rbTt2mQ== X-Gm-Message-State: AOJu0YwpSeuURIJlymGXybDrBERAmmf2bQazAtat6K2OSAqS0B801xws wA2CGW3A4XAODqq6VtMtJ4pYbnM7wXyiXx8UEy76GQcY9maK22nIaV7MH9JmFVYYix4iUZZuxqQ FEgGYgWROk2d60TwEDd0KqwcRX86svf+2frECZbQWcxinWBreX/MdHfoVRsPBIW9E9knWaJTd1i S4ius= X-Received: by 2002:a05:6512:3c8a:b0:52f:2adf:d445 with SMTP id 2adb3069b0e04-532edbade41mr3498318e87.41.1723713911619; Thu, 15 Aug 2024 02:25:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXVHcom9bqqi9GSeZiOw88lrHGMwV+yLO4NjQtn8iMbKuCv4yuzR2v2cJk7x7ywlGr+9KTSQ== X-Received: by 2002:a05:6512:3c8a:b0:52f:2adf:d445 with SMTP id 2adb3069b0e04-532edbade41mr3498304e87.41.1723713911159; Thu, 15 Aug 2024 02:25:11 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8383934585sm72142866b.107.2024.08.15.02.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 02:25:10 -0700 (PDT) From: Alexander Mikhalitsyn To: mszeredi@redhat.com Cc: brauner@kernel.org, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Vivek Goyal , German Maglione , Amir Goldstein , Bernd Schubert , Alexander Mikhalitsyn , Stefan Hajnoczi , =?utf-8?q?Eugenio_P=C3=A9rez?= , linux-kernel@vger.kernel.org, virtualization@lists.linux.dev Subject: [PATCH v3 11/11] fs/fuse/virtio_fs: allow idmapped mounts Date: Thu, 15 Aug 2024 11:24:28 +0200 Message-Id: <20240815092429.103356-12-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> References: <20240815092429.103356-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Allow idmapped mounts for virtiofs. It's absolutely safe as for virtiofs we have the same feature negotiation mechanism as for classical fuse filesystems. This does not affect any existing setups anyhow. virtiofsd support: https://gitlab.com/virtio-fs/virtiofsd/-/merge_requests/245 Cc: Christian Brauner Cc: Seth Forshee Cc: Miklos Szeredi Cc: Vivek Goyal Cc: German Maglione Cc: Amir Goldstein Cc: Bernd Schubert Cc: Signed-off-by: Alexander Mikhalitsyn --- v3: - this commit added --- fs/fuse/virtio_fs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index dd5260141615..7e5bbaef6f76 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -1628,6 +1628,7 @@ static struct file_system_type virtio_fs_type = { .name = "virtiofs", .init_fs_context = virtio_fs_init_fs_context, .kill_sb = virtio_kill_sb, + .fs_flags = FS_ALLOW_IDMAP, }; static int virtio_fs_uevent(const struct kobject *kobj, struct kobj_uevent_env *env)