From nobody Tue Feb 10 08:26:58 2026 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 5258B200126 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=1723713898; cv=none; b=qWreh2rwFpWxyvoz+jY4nUMivfVirc+e5KlMj5SdWEV30VqXtKc7765Un+0knW39cj+j1xMgjkZhdR0J3pccuMS6eYYNYuqfN6TRlucNIm1WxWOa2fny6OXEkg0jbFOF5AVqoTv76gBY7Q8ytZaNmPkrjMyxCZkgmLyT5dWZt28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723713898; 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=lYV61ZKt4c4vFwnHlfFo3/YWUkrbr8yKTs23SKvijrqqDHhMIkstLi82uVtkAXHm3nBrkwUSlIQeg/OEmRmX+KgWPHpiUpCrxs1Q75uCmz9YDG13yLRKFLo+WEtLUi84ih4P5V0r8oNAHTskq5VmE2dxvXk7+oXmgvc51mVYpL8= 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-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 C3BD33F31C 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-f70.google.com with SMTP id a640c23a62f3a-a77f0eca75bso84194366b.1 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=KmOOmuFP0ubso/umv1+R7jhpD5RtXoq4YBkazoDGJGcwU6ObIiNZw05WzeSTU5SHAQ ECC0u/tMjrNY9AZzTrJZ60NKgkljX96unToRX0CxkxXzf4r+ILIH8ShzPdESgQ2+7pz7 Em7Bihlw1iTv29qftZI+Dz0X381afBHq3OsZhcjtE1x7xJDmVBK2EBHW3iz+rnujpJln fXr6fu2HpfKV4lnnzDiGav2gq8hlgAUB8ob7BwRu6dYfTBHMqYFrua6PSryuK1ahJhWW RCVDtBqdiEIaE8AvahdQW0aSCinRo7/R77aG+LzvTrIIM8O8WFjV9Dmo6NhBQWwOEPYR 0Hxg== X-Forwarded-Encrypted: i=1; AJvYcCXZrBDrJnipQgyos+Jiggtm9sbZamJzdC6wYCpRLovR9XtgGWNvH7ubZTbgB5fchGgKtywm1Kzkm3VNeH/rhJu6F4qmDnig6FE7BUva X-Gm-Message-State: AOJu0YwwdI7sDJx2aAsnogeeoMFfRggqTHL4U+mXkQeEp9N5zmpj8yBP Od9MgHjFv442uNkz3m+i0nRqG36aHl6woShVZKsHJGM7TjPmYzzehr9jiN6AXGpmPunUBionh4v 94T+Qx7jAT1nNNSqVpOKnWZs30sSizvSVhwCD40OXL/FrgXNqZ7MjKDvZn08s6SUUPEF6HQdA7w Ilqg== X-Received: by 2002:a17:906:d7d9:b0:a80:f79a:10c9 with SMTP id a640c23a62f3a-a8366c387e8mr373890066b.12.1723713895286; 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-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" 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 reques= t. 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_getat= tr() 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 i= node *newdir, return err; } =20 -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 =3D get_fuse_conn(inode); + vfsuid_t vfsuid =3D make_vfsuid(idmap, fc->user_ns, + make_kuid(fc->user_ns, attr->uid)); + vfsgid_t vfsgid =3D make_vfsgid(idmap, fc->user_ns, + make_kgid(fc->user_ns, attr->gid)); =20 stat->dev =3D inode->i_sb->s_dev; stat->ino =3D attr->ino; stat->mode =3D (inode->i_mode & S_IFMT) | (attr->mode & 07777); stat->nlink =3D attr->nlink; - stat->uid =3D make_kuid(fc->user_ns, attr->uid); - stat->gid =3D make_kgid(fc->user_ns, attr->gid); + stat->uid =3D vfsuid_into_kuid(vfsuid); + stat->gid =3D vfsgid_into_kgid(vfsgid); stat->rdev =3D inode->i_rdev; stat->atime.tv_sec =3D attr->atime; stat->atime.tv_nsec =3D attr->atimensec; @@ -1207,8 +1211,8 @@ static void fuse_statx_to_attr(struct fuse_statx *sx,= struct fuse_attr *attr) attr->blksize =3D sx->blksize; } =20 -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, struc= t file *file, stat->result_mask =3D sx->mask & (STATX_BASIC_STATS | STATX_BTIME); stat->btime.tv_sec =3D sx->btime.tv_sec; stat->btime.tv_nsec =3D 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 |=3D STATX_TYPE; } =20 return 0; } =20 -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, str= uct kstat *stat, ATTR_TIMEOUT(&outarg), attr_version); if (stat) - fuse_fillattr(inode, &outarg.attr, stat); + fuse_fillattr(idmap, inode, &outarg.attr, stat); } } return err; } =20 -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 *ino= de, + struct file *file, struct kstat *stat, + u32 request_mask, unsigned int flags) { struct fuse_inode *fi =3D get_fuse_inode(inode); struct fuse_conn *fc =3D 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 =3D fuse_do_statx(inode, file, stat); + err =3D fuse_do_statx(idmap, inode, file, stat); if (err =3D=3D -ENOSYS) { fc->no_statx =3D 1; err =3D 0; goto retry; } } else { - err =3D fuse_do_getattr(inode, stat, file); + err =3D 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 =3D fi->orig_i_mode; stat->ino =3D 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, =20 int fuse_update_attributes(struct inode *inode, struct file *file, u32 mas= k) { - return fuse_update_get_attr(inode, file, NULL, mask, 0); + return fuse_update_get_attr(&nop_mnt_idmap, inode, file, NULL, mask, 0); } =20 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; =20 forget_all_cached_acls(inode); - return fuse_do_getattr(inode, NULL, NULL); + return fuse_do_getattr(&nop_mnt_idmap, inode, NULL, NULL); } =20 /* @@ -2094,7 +2098,7 @@ static int fuse_setattr(struct mnt_idmap *idmap, stru= ct dentry *entry, * ia_mode calculation may have used stale i_mode. * Refresh and recalculate. */ - ret =3D fuse_do_getattr(inode, NULL, file); + ret =3D fuse_do_getattr(idmap, inode, NULL, file); if (ret) return ret; =20 @@ -2151,7 +2155,7 @@ static int fuse_getattr(struct mnt_idmap *idmap, return -EACCES; } =20 - return fuse_update_get_attr(inode, NULL, stat, request_mask, flags); + return fuse_update_get_attr(idmap, inode, NULL, stat, request_mask, flags= ); } =20 static const struct inode_operations fuse_dir_inode_operations =3D { --=20 2.34.1