From nobody Fri Dec 26 11:40:46 2025 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 4E48041230 for ; Mon, 8 Jan 2024 12:10:18 +0000 (UTC) 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="O3ONM7m+" Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.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 AE6103F2A6 for ; Mon, 8 Jan 2024 12:10:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1704715816; bh=9JOCkZnahtYcjH5f/6OzDGT6n3cRWHJ6WXIUPPzUvyw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O3ONM7m+eFjSrc/qCOGyOSDoP9mzxvpW4mg13LZQzt8raSR+yZG6qNs2lC2pPNcMk dadoWRzbK4UGfN4gTf9E/0DaukJwudqo02FI8BWvdETQ7OGtHkavTqX4rxGD6rLRwL vPRhArHbHXFnX0RwZwebAV0XbY+T2Pg8efOatTJOygVazKdVjOQjSjI4irgxSb1IAW bROfPJFdaQp6nYlT7AMvpxq7eHAhyXgM7XR1xaoCW7aL0qlkAiaE/6NMCKkbRwRigj E9HA/A/dwFNroT5HcsaAYlRfbUQDJIBDKFceJ92Yc0DCCaxvRywXEPX0ijlebi3pio Ad1Mp63ezzmcg== Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-557a318580dso536676a12.3 for ; Mon, 08 Jan 2024 04:10:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704715816; x=1705320616; 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=9JOCkZnahtYcjH5f/6OzDGT6n3cRWHJ6WXIUPPzUvyw=; b=npC7rYn/zFlLe6mShrE7DBV0iVpqKDRs0bpSqyDkoHu+v05x8RLo/QLx4+8useZGYO JG3fyR2lFyxMLZSS1TaHHTnEGJ1YbMtcwfiwVgZqkEqyUAfRHs+o5RnWXfSAdjHPt12i 2Uc2u+YpoKzZhAhYcEH10+FSoJowzBsxcU8jMXIPQtVt37R38K9LbCv0P3JSZHUK8l64 ggrCHe6lI5mT8OCT5BMdmsgLUWIBjq+jh/iDQFXmGrCnRB/REIpYcR7cHWdOZHDXTrfL N7JerO90tr6Cyb9OdNnLnVhLd2twqsNaoDUyjMX87hra+KpO5CW8qLks/Mx1Q7MIy2HK jOjQ== X-Gm-Message-State: AOJu0YxtdU08/HJCPrkopjpdALb4wtJu2ir3W0imvN6gSVRtYfkygC+1 tCok8u10PktTnaRMMQIAeP7/PwVBH6g7pkw+BtYx6e0EKkwAzyAt3DDZKpFt1qPkpL+zfFDzw3C bmw9Y7ite0hELOsGn9t9+lhws/a5GuFIFzlMGw0gCd0eOZiYL X-Received: by 2002:a50:9e24:0:b0:557:2213:bc4e with SMTP id z33-20020a509e24000000b005572213bc4emr1414494ede.57.1704715816369; Mon, 08 Jan 2024 04:10:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHw8peZwjRNS6HnIeq6gf9kiSM/PadeOHzJBqN/8B3lBmvGk2+H+2sR5ks64RD0Cx44QtvI+w== X-Received: by 2002:a50:9e24:0:b0:557:2213:bc4e with SMTP id z33-20020a509e24000000b005572213bc4emr1414490ede.57.1704715816191; Mon, 08 Jan 2024 04:10:16 -0800 (PST) Received: from localhost.localdomain ([91.64.72.41]) by smtp.gmail.com with ESMTPSA id fi21-20020a056402551500b005578b816f20sm1767959edb.29.2024.01.08.04.10.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 04:10:14 -0800 (PST) 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 v1 6/9] fs/fuse: support idmapped ->setattr op Date: Mon, 8 Jan 2024 13:08:21 +0100 Message-Id: <20240108120824.122178-7-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240108120824.122178-1-aleksandr.mikhalitsyn@canonical.com> References: <20240108120824.122178-1-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 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 f7c2c54f7122..5fbb7100ad1c 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1739,17 +1739,27 @@ static bool update_mtime(unsigned ivalid, bool trus= t_local_mtime) return true; } =20 -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 =3D iattr->ia_valid; =20 if (ivalid & ATTR_MODE) arg->valid |=3D FATTR_MODE, arg->mode =3D iattr->ia_mode; - if (ivalid & ATTR_UID) - arg->valid |=3D FATTR_UID, arg->uid =3D from_kuid(fc->user_ns, iattr-= >ia_uid); - if (ivalid & ATTR_GID) - arg->valid |=3D FATTR_GID, arg->gid =3D from_kgid(fc->user_ns, iattr-= >ia_gid); + + if (ivalid & ATTR_UID) { + kuid_t fsuid =3D from_vfsuid(idmap, fc->user_ns, iattr->ia_vfsuid); + arg->valid |=3D FATTR_UID; + arg->uid =3D from_kuid(fc->user_ns, fsuid); + } + + if (ivalid & ATTR_GID) { + kgid_t fsgid =3D from_vfsgid(idmap, fc->user_ns, iattr->ia_vfsgid); + arg->valid |=3D FATTR_GID; + arg->gid =3D from_kgid(fc->user_ns, fsgid); + } + if (ivalid & ATTR_SIZE) arg->valid |=3D FATTR_SIZE, arg->size =3D iattr->ia_size; if (ivalid & ATTR_ATIME) { @@ -1869,8 +1879,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 =3D d_inode(dentry); struct fuse_mount *fm =3D get_fuse_mount(inode); @@ -1890,7 +1900,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iat= tr *attr, if (!fc->default_permissions) attr->ia_valid |=3D ATTR_FORCE; =20 - err =3D setattr_prepare(&nop_mnt_idmap, dentry, attr); + err =3D setattr_prepare(idmap, dentry, attr); if (err) return err; =20 @@ -1949,7 +1959,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iat= tr *attr, =20 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 =3D file->private_data; inarg.valid |=3D FATTR_FH; @@ -2084,7 +2094,7 @@ static int fuse_setattr(struct mnt_idmap *idmap, stru= ct dentry *entry, if (!attr->ia_valid) return 0; =20 - ret =3D fuse_do_setattr(entry, attr, file); + ret =3D 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 a660f1f21540..e0fe5497a548 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2870,7 +2870,7 @@ static void fuse_do_truncate(struct file *file) attr.ia_file =3D file; attr.ia_valid |=3D ATTR_FILE; =20 - fuse_do_setattr(file_dentry(file), &attr, file); + fuse_do_setattr(&nop_mnt_idmap, file_dentry(file), &attr, file); } =20 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 15ec95dea276..94b25ea5344a 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1288,8 +1288,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); =20 -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); =20 void fuse_set_initialized(struct fuse_conn *fc); =20 --=20 2.34.1