From nobody Fri Dec 26 11:39:43 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 618C51917CD for ; Tue, 3 Sep 2024 15:17: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=1725376631; cv=none; b=Z9kWPuoO8s0i8ZIne1UQxNjgrxVtsObepxXcJO5Yy0b8x4OIy+xx1wqiz/hKYeR0kVjri8A2aNr7FkfjAbEG1CjWtXPDhbBZscmPqxrHiKqNuobTg+a8kIa94HZGVhAE7CGmaTfQVrLCXQWcZUD7nfmGk9Ng0OgTnLbnCOuIhfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725376631; c=relaxed/simple; bh=d1QU9K0mCSLy9i49hu3VgHqnFt0IkZctbCF8EsYa5UY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rKpd8v2fI+38TagP17mKZHEp/bdhDZCRzxN43CdKqSErTMP6BrRFIJI4cCjcPsMNdN55ZfTr+1KrsQHTmRfxvaVjESQXvwoiAe13etm5azvWBgkY5ALywcBcJO7UJEvIF3bt+wK/yHnYCdrAGrKYZFtFZ5GOV6ma41AdQ967srw= 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=FfxESeom; 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="FfxESeom" 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-1.canonical.com (Postfix) with ESMTPS id D00B03F339 for ; Tue, 3 Sep 2024 15:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1725376627; bh=RUXBxrexsYj2ubgYvgii/4vTEm7ycdd5RVigA12ybdw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FfxESeom9fJH97jCSP78l8CZEteJRmVEyMNTzlOopcmfou/wXpkkfjRnHlqmPBhID NPHnFweLphaIK7NF9kLizwlCHtrsyIe8p9UjTeCFIOycbOTf3N9WlTKE9nEVTPJhZi 45sKComEUJ8bX2k4oozswxzRRG5GOutEyk1YFETdGCT/UmfIpA1oKI4bzVDXbXftEq 0u4ESyKtZlxaWyF3J/OcbbNHQg/vTvn0QimtJtogUABcTkH/24xqpAm/LHquiLPuao 8GeQF0gZuMX7a0ayc17m7LL+JgmZKCPyYt+ZJyQNqwmy8VyMpcpANw0+ivoXCMUbUb s593nrV+/Gs+g== Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-5334656d5c3so5588675e87.1 for ; Tue, 03 Sep 2024 08:17:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725376625; x=1725981425; 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=RUXBxrexsYj2ubgYvgii/4vTEm7ycdd5RVigA12ybdw=; b=oxOgndkg8hmqiM+SHIk/W0JD8lfYYEMxaJJVSPJjPkqI+A+HJxNZY8QPXzpkJ4npbK WG/qzbS+bToGFP0w7CXlTq4vjxASweMD0IHupkkD2VXUAbqG5g1BtpoOxfZYL91j9R74 x+jtxeLwdMCEvXrGKgy1EuWYE4XBa3SRSc+Jcf383+yUhkcg2pe2Dy5ybL3a0DhmEkIc PGGKehTZ5rgnDF9DXUB2dR+n/hhRJsi1ToUUJMRp1/poi5JgCPE0/tklmJM8dLauvIJC w/tUYiNJJkBimDyXjWlyY6PR/XCe8uWVyuShPBFbV09X4g+FFlHu0F+nZZKQizHzxArL 9sZw== X-Forwarded-Encrypted: i=1; AJvYcCUPh5NUIHZ5G+X0Og+p1x0gEr3sH/OlZaL8YtUJUUSpVQVG6E1+54tQi5+vmb9btsbM5LmQu692jSNUPMU=@vger.kernel.org X-Gm-Message-State: AOJu0YwwwOaLOFpY3ifRolsWiV+eKhW+LbQTDtmd/JUu0VFyVadV9YDF ysbWncEzpsJWZ/E9XpvqUTOOjSHFTcCoE9x0wl0p6iKHfiCuyDZHdT5K4hHccWhOXzmQ7yh53rb b23v6yvvbgMfKjenP25IMmCLV/KZzTr/hAz7nnMz74xf1nyFmgKFoS655d1iqBfxrg0EONK5B2f DYBg== X-Received: by 2002:a05:6512:2387:b0:530:c1fc:1c32 with SMTP id 2adb3069b0e04-53546b8e196mr10335871e87.45.1725376625247; Tue, 03 Sep 2024 08:17:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbdVNQw9JIGlffkc2qNWniuxTLPhkWGbYYHUXdBD/ban51LA6iUri9d3hyagPN6wYzcdu37w== X-Received: by 2002:a05:6512:2387:b0:530:c1fc:1c32 with SMTP id 2adb3069b0e04-53546b8e196mr10335839e87.45.1725376624758; Tue, 03 Sep 2024 08:17:04 -0700 (PDT) Received: from amikhalitsyn.. ([188.192.113.77]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a19afb108sm156377166b.223.2024.09.03.08.17.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 08:17:04 -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 v4 08/15] fs/fuse: support idmapped ->setattr op Date: Tue, 3 Sep 2024 17:16:19 +0200 Message-Id: <20240903151626.264609-9-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903151626.264609-1-aleksandr.mikhalitsyn@canonical.com> References: <20240903151626.264609-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 Reviewed-by: Christian Brauner --- 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 870932543aa0..08bf9cc51a65 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1748,17 +1748,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) { @@ -1878,8 +1888,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); @@ -1899,7 +1909,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 @@ -1958,7 +1968,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; @@ -2093,7 +2103,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 7d14d533dad1..06ff4742ab08 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 =3D file; attr.ia_valid |=3D ATTR_FILE; =20 - fuse_do_setattr(file_dentry(file), &attr, file); + fuse_do_setattr(file_mnt_idmap(file), 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 656575e3e4cf..de0ab2f14995 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1331,8 +1331,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