linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v1 1/7] fs: Add inode_get_ino() and implement get_ino() for NFS
@ 2024-10-10 15:26 Mickaël Salaün
  2024-10-10 15:26 ` [RFC PATCH v1 2/7] audit: Fix inode numbers Mickaël Salaün
                   ` (11 more replies)
  0 siblings, 12 replies; 79+ messages in thread
From: Mickaël Salaün @ 2024-10-10 15:26 UTC (permalink / raw)
  To: Christian Brauner, Paul Moore
  Cc: Mickaël Salaün, linux-fsdevel, linux-nfs,
	linux-security-module, audit, Trond Myklebust, Anna Schumaker,
	Alexander Viro, Jan Kara

When a filesystem manages its own inode numbers, like NFS's fileid shown
to user space with getattr(), other part of the kernel may still expose
the private inode->ino through kernel logs and audit.

Another issue is on 32-bit architectures, on which ino_t is 32 bits,
whereas the user space's view of an inode number can still be 64 bits.

Add a new inode_get_ino() helper calling the new struct
inode_operations' get_ino() when set, to get the user space's view of an
inode number.  inode_get_ino() is called by generic_fillattr().

Implement get_ino() for NFS.

Cc: Trond Myklebust <trondmy@kernel.org>
Cc: Anna Schumaker <anna@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
---

I'm not sure about nfs_namespace_getattr(), please review carefully.

I guess there are other filesystems exposing inode numbers different
than inode->i_ino, and they should be patched too.
---
 fs/nfs/inode.c     | 6 ++++--
 fs/nfs/internal.h  | 1 +
 fs/nfs/namespace.c | 2 ++
 fs/stat.c          | 2 +-
 include/linux/fs.h | 9 +++++++++
 5 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 542c7d97b235..5dfc176b6d92 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -83,18 +83,19 @@ EXPORT_SYMBOL_GPL(nfs_wait_bit_killable);
 
 /**
  * nfs_compat_user_ino64 - returns the user-visible inode number
- * @fileid: 64-bit fileid
+ * @inode: inode pointer
  *
  * This function returns a 32-bit inode number if the boot parameter
  * nfs.enable_ino64 is zero.
  */
-u64 nfs_compat_user_ino64(u64 fileid)
+u64 nfs_compat_user_ino64(const struct *inode)
 {
 #ifdef CONFIG_COMPAT
 	compat_ulong_t ino;
 #else	
 	unsigned long ino;
 #endif
+	u64 fileid = NFS_FILEID(inode);
 
 	if (enable_ino64)
 		return fileid;
@@ -103,6 +104,7 @@ u64 nfs_compat_user_ino64(u64 fileid)
 		ino ^= fileid >> (sizeof(fileid)-sizeof(ino)) * 8;
 	return ino;
 }
+EXPORT_SYMBOL_GPL(nfs_compat_user_ino64);
 
 int nfs_drop_inode(struct inode *inode)
 {
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 430733e3eff2..f5555a71a733 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -451,6 +451,7 @@ extern void nfs_zap_acl_cache(struct inode *inode);
 extern void nfs_set_cache_invalid(struct inode *inode, unsigned long flags);
 extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
 extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
+extern u64 nfs_compat_user_ino64(const struct *inode);
 
 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
 /* localio.c */
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index e7494cdd957e..d9b1e0606833 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -232,11 +232,13 @@ nfs_namespace_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 const struct inode_operations nfs_mountpoint_inode_operations = {
 	.getattr	= nfs_getattr,
 	.setattr	= nfs_setattr,
+	.get_ino	= nfs_compat_user_ino64,
 };
 
 const struct inode_operations nfs_referral_inode_operations = {
 	.getattr	= nfs_namespace_getattr,
 	.setattr	= nfs_namespace_setattr,
+	.get_ino	= nfs_compat_user_ino64,
 };
 
 static void nfs_expire_automounts(struct work_struct *work)
diff --git a/fs/stat.c b/fs/stat.c
index 41e598376d7e..05636919f94b 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -50,7 +50,7 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask,
 	vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
 
 	stat->dev = inode->i_sb->s_dev;
-	stat->ino = inode->i_ino;
+	stat->ino = inode_get_ino(inode);
 	stat->mode = inode->i_mode;
 	stat->nlink = inode->i_nlink;
 	stat->uid = vfsuid_into_kuid(vfsuid);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e3c603d01337..0eba09a21cf7 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2165,6 +2165,7 @@ struct inode_operations {
 			    struct dentry *dentry, struct fileattr *fa);
 	int (*fileattr_get)(struct dentry *dentry, struct fileattr *fa);
 	struct offset_ctx *(*get_offset_ctx)(struct inode *inode);
+	u64 (*get_ino)(const struct inode *inode);
 } ____cacheline_aligned;
 
 static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
@@ -2172,6 +2173,14 @@ static inline int call_mmap(struct file *file, struct vm_area_struct *vma)
 	return file->f_op->mmap(file, vma);
 }
 
+static inline u64 inode_get_ino(struct inode *inode)
+{
+	if (unlikely(inode->i_op->get_ino))
+		return inode->i_op->get_ino(inode);
+
+	return inode->i_ino;
+}
+
 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
 extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *,
-- 
2.46.1


^ permalink raw reply related	[flat|nested] 79+ messages in thread

end of thread, other threads:[~2024-10-21 14:04 UTC | newest]

Thread overview: 79+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-10 15:26 [RFC PATCH v1 1/7] fs: Add inode_get_ino() and implement get_ino() for NFS Mickaël Salaün
2024-10-10 15:26 ` [RFC PATCH v1 2/7] audit: Fix inode numbers Mickaël Salaün
2024-10-11  1:20   ` [PATCH RFC " Paul Moore
2024-10-11  1:38     ` Paul Moore
2024-10-11 21:34   ` [RFC PATCH " Paul Moore
2024-10-14 13:30     ` Mickaël Salaün
2024-10-14 23:36       ` Paul Moore
2024-10-10 15:26 ` [RFC PATCH v1 3/7] selinux: Fix inode numbers in error messages Mickaël Salaün
2024-10-11  1:20   ` [PATCH RFC " Paul Moore
2024-10-10 15:26 ` [RFC PATCH v1 4/7] integrity: Fix inode numbers in audit records Mickaël Salaün
2024-10-11  1:20   ` [PATCH RFC " Paul Moore
2024-10-11 10:15     ` Mickaël Salaün
2024-10-11 11:34       ` Roberto Sassu
2024-10-11 12:38         ` Mickaël Salaün
2024-10-11 12:45           ` Roberto Sassu
2024-10-10 15:26 ` [RFC PATCH v1 5/7] ipe: " Mickaël Salaün
2024-10-10 17:44   ` Fan Wu
2024-10-10 15:26 ` [RFC PATCH v1 6/7] smack: Fix inode numbers in logs Mickaël Salaün
2024-10-10 17:18   ` Casey Schaufler
2024-10-10 15:26 ` [RFC PATCH v1 7/7] tomoyo: " Mickaël Salaün
2024-10-12  7:35   ` [PATCH] tomoyo: use u64 for handling numeric values Tetsuo Handa
2024-10-14 13:59     ` Mickaël Salaün
2024-10-10 18:07 ` [RFC PATCH v1 1/7] fs: Add inode_get_ino() and implement get_ino() for NFS Anna Schumaker
2024-10-11 10:14   ` Mickaël Salaün
2024-10-10 19:28 ` Trond Myklebust
2024-10-11 10:15   ` Mickaël Salaün
2024-10-11 12:22     ` Trond Myklebust
2024-10-11 12:38       ` Mickaël Salaün
2024-10-11 12:43         ` Mickaël Salaün
2024-10-11 10:12 ` Tetsuo Handa
2024-10-11 10:54   ` Tetsuo Handa
2024-10-11 11:10     ` Mickaël Salaün
2024-10-11 11:04   ` Mickaël Salaün
2024-10-11 14:27     ` Tetsuo Handa
2024-10-11 15:13       ` Christoph Hellwig
2024-10-11 15:26       ` Mickaël Salaün
2024-10-11 12:30 ` Christoph Hellwig
2024-10-11 12:47   ` Mickaël Salaün
2024-10-11 12:54     ` Christoph Hellwig
2024-10-11 13:20       ` Mickaël Salaün
2024-10-11 13:23         ` Christoph Hellwig
2024-10-11 13:52           ` Mickaël Salaün
2024-10-11 14:39             ` Christoph Hellwig
2024-10-11 15:30               ` Mickaël Salaün
2024-10-11 15:34                 ` Christoph Hellwig
2024-10-14 14:35                   ` Christian Brauner
2024-10-14 14:36                     ` Christoph Hellwig
2024-10-13 10:17                 ` Jeff Layton
2024-10-14  8:40                   ` Burn Alting
2024-10-14  9:02                     ` Christoph Hellwig
2024-10-14 12:12                       ` Burn Alting
2024-10-14 12:17                         ` Christoph Hellwig
2024-10-14 13:13                           ` Mickaël Salaün
     [not found]                   ` <9c3bc3b7-2e79-4423-b8eb-f9f6249ee5bf@iinet.net.au>
2024-10-14 10:22                     ` Jeff Layton
2024-10-14 14:45                   ` Christian Brauner
2024-10-14 15:27                     ` Mickaël Salaün
2024-10-16  0:15                     ` Paul Moore
2024-10-14 14:47 ` Christian Brauner
2024-10-14 17:51   ` Mickaël Salaün
2024-10-16 14:23 ` Christian Brauner
2024-10-16 23:05   ` Paul Moore
2024-10-17 14:30     ` Trond Myklebust
2024-10-17 14:54       ` Paul Moore
2024-10-17 14:58         ` Christoph Hellwig
2024-10-17 15:15           ` Paul Moore
2024-10-17 15:25             ` Christoph Hellwig
2024-10-17 16:43               ` Jan Kara
2024-10-18  5:15                 ` Christoph Hellwig
2024-10-21 13:17                 ` Christian Brauner
2024-10-17 17:05             ` Jeff Layton
2024-10-17 17:09               ` Trond Myklebust
2024-10-17 17:59                 ` Jeff Layton
2024-10-17 21:06                   ` Trond Myklebust
2024-10-18  5:18                 ` hch
2024-10-17 20:21               ` Paul Moore
2024-10-18 12:25                 ` Jan Kara
2024-10-21 13:13                   ` Christian Brauner
2024-10-21 14:04               ` Christian Brauner
2024-10-17 14:56   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).