Skip to contentSkip to conversation

fs: Add inode_get_ino() and implement get_ino() for NFS

RFC PATCH In review Mickaël Salaün 15 participants 81 messages Oct 10, 2024 – Oct 21, 2024 1 message not in the archive

Subsystems (11)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/7 fs: Add inode_get_ino() and implement get_ino() for NFS

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

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(-)
fs/nfs/inode.c +4 -2
index 542c7d97b235..5dfc176b6d92 100644
@@ -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)
 {
fs/nfs/internal.h +1 -0
index 430733e3eff2..f5555a71a733 100644
@@ -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 */
fs/nfs/namespace.c +2 -0
index e7494cdd957e..d9b1e0606833 100644
@@ -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)
fs/stat.c +1 -1
index 41e598376d7e..05636919f94b 100644
@@ -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);
include/linux/fs.h +9 -0
index e3c603d01337..0eba09a21cf7 100644
@@ -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 *,
Signature · 1 line
2.46.1
#1 lore raw

RFC PATCH 2/7 audit: Fix inode numbers

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

---
 security/lsm_audit.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
security/lsm_audit.c +5 -5
index 849e832719e2..c39a22b27cce 100644
@@ -227,7 +227,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 		if (inode) {
 			audit_log_format(ab, " dev=");
 			audit_log_untrustedstring(ab, inode->i_sb->s_id);
-			audit_log_format(ab, " ino=%lu", inode->i_ino);
+			audit_log_format(ab, " ino=%llu", inode_get_ino(inode));
 		}
 		break;
 	}
@@ -240,7 +240,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 		if (inode) {
 			audit_log_format(ab, " dev=");
 			audit_log_untrustedstring(ab, inode->i_sb->s_id);
-			audit_log_format(ab, " ino=%lu", inode->i_ino);
+			audit_log_format(ab, " ino=%llu", inode_get_ino(inode));
 		}
 		break;
 	}
@@ -253,7 +253,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 		if (inode) {
 			audit_log_format(ab, " dev=");
 			audit_log_untrustedstring(ab, inode->i_sb->s_id);
-			audit_log_format(ab, " ino=%lu", inode->i_ino);
+			audit_log_format(ab, " ino=%llu", inode_get_ino(inode));
 		}
 
 		audit_log_format(ab, " ioctlcmd=0x%hx", a->u.op->cmd);
@@ -271,7 +271,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 		if (inode) {
 			audit_log_format(ab, " dev=");
 			audit_log_untrustedstring(ab, inode->i_sb->s_id);
-			audit_log_format(ab, " ino=%lu", inode->i_ino);
+			audit_log_format(ab, " ino=%llu", inode_get_ino(inode));
 		}
 		break;
 	}
@@ -290,7 +290,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 		}
 		audit_log_format(ab, " dev=");
 		audit_log_untrustedstring(ab, inode->i_sb->s_id);
-		audit_log_format(ab, " ino=%lu", inode->i_ino);
+		audit_log_format(ab, " ino=%llu", inode_get_ino(inode));
 		rcu_read_unlock();
 		break;
 	}
Signature · 1 line
2.46.1
maintainer Acked-by on v1 2/7
#2 lore raw

Re: [PATCH RFC v1 2/7] audit: Fix inode numbers

Quoted 10 lines · On Oct 10, 2024 =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= <[email protected]> wrote:

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

---
 security/lsm_audit.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

--
paul-moore.com

maintainer
#3 lore raw

Re: [PATCH RFC v1 2/7] audit: Fix inode numbers

Quoted 5 lines · Paul Moore
Quoted 4 lines · On Oct 10, 2024 =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= <[email protected]> wrote:

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Quoted 8 lines
Quoted 6 lines
---
 security/lsm_audit.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

It looks like patch 1/7 still needs some revisions, and an ACK from the NFS/VFS folks, but once that's sorted I can send the patchset up to Linus marked for stable.

Signature · 1 line
paul-moore.com
maintainer
#4 lore raw

Re: [RFC PATCH v1 2/7] audit: Fix inode numbers

In reply to Mickaël Salaün
Quoted 10 lines · Mickaël Salaün

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

---
 security/lsm_audit.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

While answering some off-list questions regarding audit, I realized we've got similar issues with audit_name->ino and audit_watch->ino. It would be nice if you could also fix that in this patchset.

Signature · 1 line
paul-moore.com
#5 lore raw

Re: [RFC PATCH v1 2/7] audit: Fix inode numbers

Quoted 12 lines · Paul Moore
Quoted 10 lines · Mickaël Salaün

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

---
 security/lsm_audit.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 3 lines

While answering some off-list questions regarding audit, I realized we've got similar issues with audit_name->ino and audit_watch->ino. It would be nice if you could also fix that in this patchset.

I can do that with the next version, but I'm wondering how it would fit with the UAPI's struct audit_rule_data which has only 32-bit fields/values. Does 64-bit inode filtering currently work?

maintainer
#6 lore raw

Re: [RFC PATCH v1 2/7] audit: Fix inode numbers

Quoted 13 lines · Mickaël Salaün
Quoted 12 lines · Paul Moore
Quoted 10 lines · Mickaël Salaün

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

---
 security/lsm_audit.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 3 lines

While answering some off-list questions regarding audit, I realized we've got similar issues with audit_name->ino and audit_watch->ino. It would be nice if you could also fix that in this patchset.

I can do that with the next version, but I'm wondering how it would fit with the UAPI's struct audit_rule_data which has only 32-bit fields/values.

Don't worry about audit_rule_data for the moment, that's obviously going to require a userspace update as well to supply 64-bit inode numbers. My guess is we'll probably want to introduce a new field type, e.g. AUDIT_INODE64 or similar, that either carries the high 32-bits and is used in conjunction with AUDIT_INODE, or we create the new AUDIT_INODE64 field as a "special" filter field which takes up two of the u32 value spots. Regardless, let's not worry about that for this patchset and focus on ensuring the underlying kernel filtering and reporting mechanisms work as expected so that when we do sort out the UAPI issues everything *should* work.

Quoted 1 line

Does 64-bit inode filtering currently work?

Likely not :/

Signature · 1 line
paul-moore.com
#7 lore raw

RFC PATCH 3/7 selinux: Fix inode numbers in error messages

In reply to Mickaël Salaün

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Cc Paul Moore <[email protected]>
Cc Stephen Smalley <[email protected]>
Cc Ondrej Mosnacek <[email protected]>
---
 security/selinux/hooks.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
security/selinux/hooks.c +7 -7
index fc926d3cac6e..60b31b35f475 100644
@@ -1384,8 +1384,8 @@ static int inode_doinit_use_xattr(struct inode *inode, struct dentry *dentry,
 	if (rc < 0) {
 		kfree(context);
 		if (rc != -ENODATA) {
-			pr_warn("SELinux: %s:  getxattr returned %d for dev=%s ino=%ld\n",
-				__func__, -rc, inode->i_sb->s_id, inode->i_ino);
+			pr_warn("SELinux: %s:  getxattr returned %d for dev=%s ino=%llu\n",
+				__func__, -rc, inode->i_sb->s_id, inode_get_ino(inode));
 			return rc;
 		}
 		*sid = def_sid;
@@ -1396,13 +1396,13 @@ static int inode_doinit_use_xattr(struct inode *inode, struct dentry *dentry,
 					     def_sid, GFP_NOFS);
 	if (rc) {
 		char *dev = inode->i_sb->s_id;
-		unsigned long ino = inode->i_ino;
+		u64 ino = inode_get_ino(inode);
 
 		if (rc == -EINVAL) {
-			pr_notice_ratelimited("SELinux: inode=%lu on dev=%s was found to have an invalid context=%s.  This indicates you may need to relabel the inode or the filesystem in question.\n",
+			pr_notice_ratelimited("SELinux: inode=%llu on dev=%s was found to have an invalid context=%s.  This indicates you may need to relabel the inode or the filesystem in question.\n",
 					      ino, dev, context);
 		} else {
-			pr_warn("SELinux: %s:  context_to_sid(%s) returned %d for dev=%s ino=%ld\n",
+			pr_warn("SELinux: %s:  context_to_sid(%s) returned %d for dev=%s ino=%llu\n",
 				__func__, context, -rc, dev, ino);
 		}
 	}
@@ -3324,8 +3324,8 @@ static void selinux_inode_post_setxattr(struct dentry *dentry, const char *name,
 					   &newsid);
 	if (rc) {
 		pr_err("SELinux:  unable to map context to SID"
-		       "for (%s, %lu), rc=%d\n",
-		       inode->i_sb->s_id, inode->i_ino, -rc);
+		       "for (%s, %llu), rc=%d\n",
+		       inode->i_sb->s_id, inode_get_ino(inode), -rc);
 		return;
 	}
 
Signature · 1 line
2.46.1
maintainer Acked-by on v1 3/7
#8 lore raw

Re: [PATCH RFC v1 3/7] selinux: Fix inode numbers in error messages

Quoted 11 lines · On Oct 10, 2024 =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= <[email protected]> wrote:

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Cc Paul Moore <[email protected]>
Cc Stephen Smalley <[email protected]>
Cc Ondrej Mosnacek <[email protected]>
---
 security/selinux/hooks.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

--
paul-moore.com

#9 lore raw

RFC PATCH 4/7 integrity: Fix inode numbers in audit records

In reply to Mickaël Salaün

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Cc Mimi Zohar <[email protected]>
Cc Roberto Sassu <[email protected]>
Cc Dmitry Kasatkin <[email protected]>
Cc Eric Snowberg <[email protected]>
---
 security/integrity/integrity_audit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/integrity/integrity_audit.c +1 -1
index 0ec5e4c22cb2..e344d5bcf99c 100644
@@ -62,7 +62,7 @@ void integrity_audit_message(int audit_msgno, struct inode *inode,
 	if (inode) {
 		audit_log_format(ab, " dev=");
 		audit_log_untrustedstring(ab, inode->i_sb->s_id);
-		audit_log_format(ab, " ino=%lu", inode->i_ino);
+		audit_log_format(ab, " ino=%llu", inode_get_ino(inode));
 	}
 	audit_log_format(ab, " res=%d errno=%d", !result, errno);
 	audit_log_end(ab);
Signature · 1 line
2.46.1
maintainer
#10 lore raw

Re: [PATCH RFC v1 4/7] integrity: Fix inode numbers in audit records

Quoted 4 lines · On Oct 10, 2024 =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= <[email protected]> wrote:

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Quoted 8 lines
Cc Mimi Zohar <[email protected]>
Cc Roberto Sassu <[email protected]>
Cc Dmitry Kasatkin <[email protected]>
Cc Eric Snowberg <[email protected]>
---
 security/integrity/integrity_audit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Should we also need to update the inode value used in hmac_add_misc()?

security/integrity/evm/evm_crypto.c +1 -1
index 7c06ffd633d2..68ae454e187f 100644
@@ -155,7 +155,7 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
         * signatures
         */
        if (type != EVM_XATTR_PORTABLE_DIGSIG) {
-               hmac_misc.ino = inode->i_ino;
+               hmac_misc.ino = inode_get_ino(inode->i_ino);
                hmac_misc.generation = inode->i_generation;
        }
        /* The hmac uid and gid must be encoded in the initial user

--
paul-moore.com

#11 lore raw

Re: [PATCH RFC v1 4/7] integrity: Fix inode numbers in audit records

Quoted 14 lines · Paul Moore
Quoted 4 lines · On Oct 10, 2024 =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= <[email protected]> wrote:

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Quoted 8 lines
Cc Mimi Zohar <[email protected]>
Cc Roberto Sassu <[email protected]>
Cc Dmitry Kasatkin <[email protected]>
Cc Eric Snowberg <[email protected]>
---
 security/integrity/integrity_audit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 1 line

Should we also need to update the inode value used in hmac_add_misc()?

I'm not sure what the impact will be wrt backward compatibility. Mimi, Roberto?

Quoted 17 lines
security/integrity/evm/evm_crypto.c +1 -2
index 7c06ffd633d2..68ae454e187f 100644
@@ -155,7 +155,7 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
         * signatures
         */
        if (type != EVM_XATTR_PORTABLE_DIGSIG) {
-               hmac_misc.ino = inode->i_ino;
+               hmac_misc.ino = inode_get_ino(inode->i_ino);
                hmac_misc.generation = inode->i_generation;
        }
        /* The hmac uid and gid must be encoded in the initial user
 
--

paul-moore.com

#12 lore raw

Re: [PATCH RFC v1 4/7] integrity: Fix inode numbers in audit records

Quoted 15 lines · Mickaël Salaün
Quoted 14 lines · Paul Moore
Quoted 12 lines · On Oct 10, 2024 =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= <[email protected]> wrote:

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Cc Mimi Zohar <[email protected]>
Cc Roberto Sassu <[email protected]>
Cc Dmitry Kasatkin <[email protected]>
Cc Eric Snowberg <[email protected]>
---
 security/integrity/integrity_audit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 4 lines
Quoted 1 line

Should we also need to update the inode value used in hmac_add_misc()?

I'm not sure what the impact will be wrt backward compatibility. Mimi, Roberto?

Changing the inode number the HMAC was calculated with has the potential effect of making the file inaccessible.

In order to use the new inode number, we need to define a new EVM xattr type, and update the previous xattr version with the new one. We could deprecate the old xattr version after a while (to be discussed with Mimi).

Roberto

Quoted 17 lines
Quoted 17 lines
security/integrity/evm/evm_crypto.c +1 -2
index 7c06ffd633d2..68ae454e187f 100644
@@ -155,7 +155,7 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
         * signatures
         */
        if (type != EVM_XATTR_PORTABLE_DIGSIG) {
-               hmac_misc.ino = inode->i_ino;
+               hmac_misc.ino = inode_get_ino(inode->i_ino);
                hmac_misc.generation = inode->i_generation;
        }
        /* The hmac uid and gid must be encoded in the initial user
 
--

paul-moore.com

#13 lore raw

Re: [PATCH RFC v1 4/7] integrity: Fix inode numbers in audit records

Quoted 21 lines · Roberto Sassu
Quoted 15 lines · Mickaël Salaün
Quoted 14 lines · Paul Moore
Quoted 12 lines · On Oct 10, 2024 =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= <[email protected]> wrote:

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Cc Mimi Zohar <[email protected]>
Cc Roberto Sassu <[email protected]>
Cc Dmitry Kasatkin <[email protected]>
Cc Eric Snowberg <[email protected]>
---
 security/integrity/integrity_audit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 4 lines
Quoted 1 line

Should we also need to update the inode value used in hmac_add_misc()?

I'm not sure what the impact will be wrt backward compatibility. Mimi, Roberto?

Quoted 7 lines

Changing the inode number the HMAC was calculated with has the potential effect of making the file inaccessible.

In order to use the new inode number, we need to define a new EVM xattr type, and update the previous xattr version with the new one. We could deprecate the old xattr version after a while (to be discussed with Mimi).

That was my though. I don't we should patch hmac_add_misc() because it is already in the IMA/EVM ABI and not directly reflected to user space. The issue might be that user space cannot recreate this hmac because this private inode number is not known to user space, but I don't know if there is such user space implementation of IMA/EVM.

Quoted 22 lines

Roberto

Quoted 17 lines
Quoted 17 lines
security/integrity/evm/evm_crypto.c +1 -2
index 7c06ffd633d2..68ae454e187f 100644
@@ -155,7 +155,7 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
         * signatures
         */
        if (type != EVM_XATTR_PORTABLE_DIGSIG) {
-               hmac_misc.ino = inode->i_ino;
+               hmac_misc.ino = inode_get_ino(inode->i_ino);
                hmac_misc.generation = inode->i_generation;
        }
        /* The hmac uid and gid must be encoded in the initial user
 
--

paul-moore.com

#14 lore raw

Re: [PATCH RFC v1 4/7] integrity: Fix inode numbers in audit records

Quoted 30 lines · Mickaël Salaün
Quoted 21 lines · Roberto Sassu
Quoted 15 lines · Mickaël Salaün
Quoted 14 lines · Paul Moore
Quoted 12 lines · On Oct 10, 2024 =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= <[email protected]> wrote:

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Cc Mimi Zohar <[email protected]>
Cc Roberto Sassu <[email protected]>
Cc Dmitry Kasatkin <[email protected]>
Cc Eric Snowberg <[email protected]>
---
 security/integrity/integrity_audit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 4 lines
Quoted 1 line

Should we also need to update the inode value used in hmac_add_misc()?

I'm not sure what the impact will be wrt backward compatibility. Mimi, Roberto?

Quoted 7 lines

Changing the inode number the HMAC was calculated with has the potential effect of making the file inaccessible.

In order to use the new inode number, we need to define a new EVM xattr type, and update the previous xattr version with the new one. We could deprecate the old xattr version after a while (to be discussed with Mimi).

Quoted 5 lines

That was my though. I don't we should patch hmac_add_misc() because it is already in the IMA/EVM ABI and not directly reflected to user space. The issue might be that user space cannot recreate this hmac because this private inode number is not known to user space, but I don't know if there is such user space implementation of IMA/EVM.

EVM will recalculate the HMAC of the file metadata based on the new inode number, and will conclude that metadata was corrupted (same as if someone modified a protected xattr during an offline attack).

Roberto

Quoted 22 lines
Quoted 22 lines

Roberto

Quoted 17 lines
Quoted 17 lines
security/integrity/evm/evm_crypto.c +1 -2
index 7c06ffd633d2..68ae454e187f 100644
@@ -155,7 +155,7 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
         * signatures
         */
        if (type != EVM_XATTR_PORTABLE_DIGSIG) {
-               hmac_misc.ino = inode->i_ino;
+               hmac_misc.ino = inode_get_ino(inode->i_ino);
                hmac_misc.generation = inode->i_generation;
        }
        /* The hmac uid and gid must be encoded in the initial user
 
--

paul-moore.com

#15 lore raw

RFC PATCH 5/7 ipe: Fix inode numbers in audit records

In reply to Mickaël Salaün

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

---
 security/ipe/audit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/ipe/audit.c +1 -1
index f05f0caa4850..72d3e02c2b5f 100644
@@ -150,7 +150,7 @@ void ipe_audit_match(const struct ipe_eval_ctx *const ctx,
 		if (inode) {
 			audit_log_format(ab, " dev=");
 			audit_log_untrustedstring(ab, inode->i_sb->s_id);
-			audit_log_format(ab, " ino=%lu", inode->i_ino);
+			audit_log_format(ab, " ino=%llu", inode_get_ino(inode));
 		} else {
 			audit_log_format(ab, " dev=? ino=?");
 		}
Signature · 1 line
2.46.1
Acked-by on v1 5/7
#16 lore raw

Re: [RFC PATCH v1 5/7] ipe: Fix inode numbers in audit records

Quoted 22 lines · Mickaël Salaün

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

---
  security/ipe/audit.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
security/ipe/audit.c +1 -1
index f05f0caa4850..72d3e02c2b5f 100644
@@ -150,7 +150,7 @@ void ipe_audit_match(const struct ipe_eval_ctx *const ctx,
  		if (inode) {
  			audit_log_format(ab, " dev=");
  			audit_log_untrustedstring(ab, inode->i_sb->s_id);
-			audit_log_format(ab, " ino=%lu", inode->i_ino);
+			audit_log_format(ab, " ino=%llu", inode_get_ino(inode));
  		} else {
  			audit_log_format(ab, " dev=? ino=?");
  		}
#17 lore raw

RFC PATCH 6/7 smack: Fix inode numbers in logs

In reply to Mickaël Salaün

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

---
 security/smack/smack_lsm.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
security/smack/smack_lsm.c +12 -12
index 370fd594da12..0be7e442e70f 100644
@@ -199,8 +199,8 @@ static int smk_bu_inode(struct inode *inode, int mode, int rc)
 	char acc[SMK_NUM_ACCESS_TYPE + 1];
 
 	if (isp->smk_flags & SMK_INODE_IMPURE)
-		pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n",
-			inode->i_sb->s_id, inode->i_ino, current->comm);
+		pr_info("Smack Unconfined Corruption: inode=(%s %llu) %s\n",
+			inode->i_sb->s_id, inode_get_ino(inode), current->comm);
 
 	if (rc <= 0)
 		return rc;
@@ -212,9 +212,9 @@ static int smk_bu_inode(struct inode *inode, int mode, int rc)
 
 	smk_bu_mode(mode, acc);
 
-	pr_info("Smack %s: (%s %s %s) inode=(%s %ld) %s\n", smk_bu_mess[rc],
+	pr_info("Smack %s: (%s %s %s) inode=(%s %llu) %s\n", smk_bu_mess[rc],
 		tsp->smk_task->smk_known, isp->smk_inode->smk_known, acc,
-		inode->i_sb->s_id, inode->i_ino, current->comm);
+		inode->i_sb->s_id, inode_get_ino(inode), current->comm);
 	return 0;
 }
 #else
@@ -231,8 +231,8 @@ static int smk_bu_file(struct file *file, int mode, int rc)
 	char acc[SMK_NUM_ACCESS_TYPE + 1];
 
 	if (isp->smk_flags & SMK_INODE_IMPURE)
-		pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n",
-			inode->i_sb->s_id, inode->i_ino, current->comm);
+		pr_info("Smack Unconfined Corruption: inode=(%s %llu) %s\n",
+			inode->i_sb->s_id, inode_get_ino(inode), current->comm);
 
 	if (rc <= 0)
 		return rc;
@@ -240,9 +240,9 @@ static int smk_bu_file(struct file *file, int mode, int rc)
 		rc = 0;
 
 	smk_bu_mode(mode, acc);
-	pr_info("Smack %s: (%s %s %s) file=(%s %ld %pD) %s\n", smk_bu_mess[rc],
+	pr_info("Smack %s: (%s %s %s) file=(%s %llu %pD) %s\n", smk_bu_mess[rc],
 		sskp->smk_known, smk_of_inode(inode)->smk_known, acc,
-		inode->i_sb->s_id, inode->i_ino, file,
+		inode->i_sb->s_id, inode_get_ino(inode), file,
 		current->comm);
 	return 0;
 }
@@ -261,8 +261,8 @@ static int smk_bu_credfile(const struct cred *cred, struct file *file,
 	char acc[SMK_NUM_ACCESS_TYPE + 1];
 
 	if (isp->smk_flags & SMK_INODE_IMPURE)
-		pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n",
-			inode->i_sb->s_id, inode->i_ino, current->comm);
+		pr_info("Smack Unconfined Corruption: inode=(%s %llu) %s\n",
+			inode->i_sb->s_id, inode_get_ino(inode), current->comm);
 
 	if (rc <= 0)
 		return rc;
@@ -270,9 +270,9 @@ static int smk_bu_credfile(const struct cred *cred, struct file *file,
 		rc = 0;
 
 	smk_bu_mode(mode, acc);
-	pr_info("Smack %s: (%s %s %s) file=(%s %ld %pD) %s\n", smk_bu_mess[rc],
+	pr_info("Smack %s: (%s %s %s) file=(%s %llu %pD) %s\n", smk_bu_mess[rc],
 		sskp->smk_known, smk_of_inode(inode)->smk_known, acc,
-		inode->i_sb->s_id, inode->i_ino, file,
+		inode->i_sb->s_id, inode_get_ino(inode), file,
 		current->comm);
 	return 0;
 }
Signature · 1 line
2.46.1
maintainer Acked-by on v1 6/7
#18 lore raw

Re: [RFC PATCH v1 6/7] smack: Fix inode numbers in logs

Quoted 5 lines · Mickaël Salaün

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Quoted 77 lines
---
 security/smack/smack_lsm.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
security/smack/smack_lsm.c +12 -12
index 370fd594da12..0be7e442e70f 100644
@@ -199,8 +199,8 @@ static int smk_bu_inode(struct inode *inode, int mode, int rc)
 	char acc[SMK_NUM_ACCESS_TYPE + 1];
 
 	if (isp->smk_flags & SMK_INODE_IMPURE)
-		pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n",
-			inode->i_sb->s_id, inode->i_ino, current->comm);
+		pr_info("Smack Unconfined Corruption: inode=(%s %llu) %s\n",
+			inode->i_sb->s_id, inode_get_ino(inode), current->comm);
 
 	if (rc <= 0)
 		return rc;
@@ -212,9 +212,9 @@ static int smk_bu_inode(struct inode *inode, int mode, int rc)
 
 	smk_bu_mode(mode, acc);
 
-	pr_info("Smack %s: (%s %s %s) inode=(%s %ld) %s\n", smk_bu_mess[rc],
+	pr_info("Smack %s: (%s %s %s) inode=(%s %llu) %s\n", smk_bu_mess[rc],
 		tsp->smk_task->smk_known, isp->smk_inode->smk_known, acc,
-		inode->i_sb->s_id, inode->i_ino, current->comm);
+		inode->i_sb->s_id, inode_get_ino(inode), current->comm);
 	return 0;
 }
 #else
@@ -231,8 +231,8 @@ static int smk_bu_file(struct file *file, int mode, int rc)
 	char acc[SMK_NUM_ACCESS_TYPE + 1];
 
 	if (isp->smk_flags & SMK_INODE_IMPURE)
-		pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n",
-			inode->i_sb->s_id, inode->i_ino, current->comm);
+		pr_info("Smack Unconfined Corruption: inode=(%s %llu) %s\n",
+			inode->i_sb->s_id, inode_get_ino(inode), current->comm);
 
 	if (rc <= 0)
 		return rc;
@@ -240,9 +240,9 @@ static int smk_bu_file(struct file *file, int mode, int rc)
 		rc = 0;
 
 	smk_bu_mode(mode, acc);
-	pr_info("Smack %s: (%s %s %s) file=(%s %ld %pD) %s\n", smk_bu_mess[rc],
+	pr_info("Smack %s: (%s %s %s) file=(%s %llu %pD) %s\n", smk_bu_mess[rc],
 		sskp->smk_known, smk_of_inode(inode)->smk_known, acc,
-		inode->i_sb->s_id, inode->i_ino, file,
+		inode->i_sb->s_id, inode_get_ino(inode), file,
 		current->comm);
 	return 0;
 }
@@ -261,8 +261,8 @@ static int smk_bu_credfile(const struct cred *cred, struct file *file,
 	char acc[SMK_NUM_ACCESS_TYPE + 1];
 
 	if (isp->smk_flags & SMK_INODE_IMPURE)
-		pr_info("Smack Unconfined Corruption: inode=(%s %ld) %s\n",
-			inode->i_sb->s_id, inode->i_ino, current->comm);
+		pr_info("Smack Unconfined Corruption: inode=(%s %llu) %s\n",
+			inode->i_sb->s_id, inode_get_ino(inode), current->comm);
 
 	if (rc <= 0)
 		return rc;
@@ -270,9 +270,9 @@ static int smk_bu_credfile(const struct cred *cred, struct file *file,
 		rc = 0;
 
 	smk_bu_mode(mode, acc);
-	pr_info("Smack %s: (%s %s %s) file=(%s %ld %pD) %s\n", smk_bu_mess[rc],
+	pr_info("Smack %s: (%s %s %s) file=(%s %llu %pD) %s\n", smk_bu_mess[rc],
 		sskp->smk_known, smk_of_inode(inode)->smk_known, acc,
-		inode->i_sb->s_id, inode->i_ino, file,
+		inode->i_sb->s_id, inode_get_ino(inode), file,
 		current->comm);
 	return 0;
 }
#19 lore raw

RFC PATCH 7/7 tomoyo: Fix inode numbers in logs

In reply to Mickaël Salaün

Use the new inode_get_ino() helper to log the user space's view of inode's numbers instead of the private kernel values.

Cc Kentaro Takeda <[email protected]>
Cc Tetsuo Handa <[email protected]>

---

Because of the required type changes, there might be some side effects. Please review carefully.

---
 security/tomoyo/common.h    | 4 ++--
 security/tomoyo/condition.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
security/tomoyo/common.h +2 -2
index 0e8e2e959aef..c670a8e3c351 100644
@@ -524,7 +524,7 @@ struct tomoyo_name_union {
 
 /* Structure for holding a number. */
 struct tomoyo_number_union {
-	unsigned long values[2];
+	u64 values[2];
 	struct tomoyo_group *group; /* Maybe NULL. */
 	/* One of values in "enum tomoyo_value_type". */
 	u8 value_type[2];
@@ -567,7 +567,7 @@ struct tomoyo_address_group {
 struct tomoyo_mini_stat {
 	kuid_t uid;
 	kgid_t gid;
-	ino_t ino;
+	u64 ino;
 	umode_t mode;
 	dev_t dev;
 	dev_t rdev;
security/tomoyo/condition.c +4 -4
index f8bcc083bb0d..a44ea574fd89 100644
@@ -741,7 +741,7 @@ void tomoyo_get_attributes(struct tomoyo_obj_info *obj)
 
 			stat->uid  = inode->i_uid;
 			stat->gid  = inode->i_gid;
-			stat->ino  = inode->i_ino;
+			stat->ino  = inode_get_ino(inode);
 			stat->mode = inode->i_mode;
 			stat->dev  = inode->i_sb->s_dev;
 			stat->rdev = inode->i_rdev;
@@ -766,8 +766,8 @@ bool tomoyo_condition(struct tomoyo_request_info *r,
 		      const struct tomoyo_condition *cond)
 {
 	u32 i;
-	unsigned long min_v[2] = { 0, 0 };
-	unsigned long max_v[2] = { 0, 0 };
+	u64 min_v[2] = { 0, 0 };
+	u64 max_v[2] = { 0, 0 };
 	const struct tomoyo_condition_element *condp;
 	const struct tomoyo_number_union *numbers_p;
 	const struct tomoyo_name_union *names_p;
@@ -834,7 +834,7 @@ bool tomoyo_condition(struct tomoyo_request_info *r,
 		/* Check numeric or bit-op expressions. */
 		for (j = 0; j < 2; j++) {
 			const u8 index = j ? right : left;
-			unsigned long value = 0;
+			u64 value = 0;
 
 			switch (index) {
 			case TOMOYO_TASK_UID:
Signature · 1 line
2.46.1
maintainer
#20 lore raw

PATCH 1/1 tomoyo: use u64 for handling numeric values

TOMOYO was using "unsigned long" for handling numeric values because all possible value range fits in "unsigned long". Since Mickaël Salaün is about to replace "ino_t" with "u64", possible value range no longer fits in architecture-dependent "unsigned long". Therefore, replace "unsigned long" and "ino_t" with "u64".

---
Please include this patch before your patch.

 security/tomoyo/audit.c     | 10 ++++------
 security/tomoyo/common.c    | 14 +++++++-------
 security/tomoyo/common.h    | 17 ++++++++---------
 security/tomoyo/condition.c |  8 ++++----
 security/tomoyo/file.c      |  6 +++---
 security/tomoyo/group.c     |  3 +--
 security/tomoyo/util.c      | 28 ++++++++++++++--------------
 7 files changed, 41 insertions(+), 45 deletions(-)
security/tomoyo/audit.c +4 -6
index 610c1536cf70..36c9e63651b5 100644
@@ -195,21 +195,19 @@ static char *tomoyo_print_header(struct tomoyo_request_info *r)
 		if (i & 1) {
 			pos += snprintf(buffer + pos,
 					tomoyo_buffer_len - 1 - pos,
-					" path%u.parent={ uid=%u gid=%u ino=%lu perm=0%o }",
+					" path%u.parent={ uid=%u gid=%u ino=%llu perm=0%o }",
 					(i >> 1) + 1,
 					from_kuid(&init_user_ns, stat->uid),
 					from_kgid(&init_user_ns, stat->gid),
-					(unsigned long)stat->ino,
-					stat->mode & S_IALLUGO);
+					stat->ino, stat->mode & S_IALLUGO);
 			continue;
 		}
 		pos += snprintf(buffer + pos, tomoyo_buffer_len - 1 - pos,
-				" path%u={ uid=%u gid=%u ino=%lu major=%u minor=%u perm=0%o type=%s",
+				" path%u={ uid=%u gid=%u ino=%llu major=%u minor=%u perm=0%o type=%s",
 				(i >> 1) + 1,
 				from_kuid(&init_user_ns, stat->uid),
 				from_kgid(&init_user_ns, stat->gid),
-				(unsigned long)stat->ino,
-				MAJOR(dev), MINOR(dev),
+				stat->ino, MAJOR(dev), MINOR(dev),
 				mode & S_IALLUGO, tomoyo_filetype(mode));
 		if (S_ISCHR(mode) || S_ISBLK(mode)) {
 			dev = stat->rdev;
security/tomoyo/common.c +7 -7
index 5c7b059a332a..528b96c917e5 100644
@@ -424,8 +424,8 @@ static void tomoyo_print_number_union_nospace
 		tomoyo_set_string(head, ptr->group->group_name->name);
 	} else {
 		int i;
-		unsigned long min = ptr->values[0];
-		const unsigned long max = ptr->values[1];
+		u64 min = ptr->values[0];
+		const u64 max = ptr->values[1];
 		u8 min_type = ptr->value_type[0];
 		const u8 max_type = ptr->value_type[1];
 		char buffer[128];
@@ -435,15 +435,15 @@ static void tomoyo_print_number_union_nospace
 			switch (min_type) {
 			case TOMOYO_VALUE_TYPE_HEXADECIMAL:
 				tomoyo_addprintf(buffer, sizeof(buffer),
-						 "0x%lX", min);
+						 "0x%llX", min);
 				break;
 			case TOMOYO_VALUE_TYPE_OCTAL:
 				tomoyo_addprintf(buffer, sizeof(buffer),
-						 "0%lo", min);
+						 "0%llo", min);
 				break;
 			default:
-				tomoyo_addprintf(buffer, sizeof(buffer), "%lu",
-						 min);
+				tomoyo_addprintf(buffer, sizeof(buffer),
+						 "%llu", min);
 				break;
 			}
 			if (min == max && min_type == max_type)
@@ -1287,7 +1287,7 @@ static bool tomoyo_print_condition(struct tomoyo_io_buffer *head,
 				switch (left) {
 				case TOMOYO_ARGV_ENTRY:
 					tomoyo_io_printf(head,
-							 "exec.argv[%lu]%s=\"",
+							 "exec.argv[%llu]%s=\"",
 							 argv->index, argv->is_not ? "!" : "");
 					tomoyo_set_string(head,
 							  argv->value->name);
security/tomoyo/common.h +8 -9
index 0e8e2e959aef..bdbb4f0ae751 100644
@@ -524,7 +524,7 @@ struct tomoyo_name_union {
 
 /* Structure for holding a number. */
 struct tomoyo_number_union {
-	unsigned long values[2];
+	u64 values[2];
 	struct tomoyo_group *group; /* Maybe NULL. */
 	/* One of values in "enum tomoyo_value_type". */
 	u8 value_type[2];
@@ -567,7 +567,7 @@ struct tomoyo_address_group {
 struct tomoyo_mini_stat {
 	kuid_t uid;
 	kgid_t gid;
-	ino_t ino;
+	u64 ino;
 	umode_t mode;
 	dev_t dev;
 	dev_t rdev;
@@ -605,7 +605,7 @@ struct tomoyo_obj_info {
 
 /* Structure for argv[]. */
 struct tomoyo_argv {
-	unsigned long index;
+	u64 index;
 	const struct tomoyo_path_info *value;
 	bool is_not;
 };
@@ -926,7 +926,7 @@ struct tomoyo_task {
 
 bool tomoyo_address_matches_group(const bool is_ipv6, const __be32 *address,
 				  const struct tomoyo_group *group);
-bool tomoyo_compare_number_union(const unsigned long value,
+bool tomoyo_compare_number_union(const u64 value,
 				 const struct tomoyo_number_union *ptr);
 bool tomoyo_condition(struct tomoyo_request_info *r,
 		      const struct tomoyo_condition *cond);
@@ -938,8 +938,7 @@ bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
 bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos,
 		      struct tomoyo_page_dump *dump);
 bool tomoyo_memory_ok(void *ptr);
-bool tomoyo_number_matches_group(const unsigned long min,
-				 const unsigned long max,
+bool tomoyo_number_matches_group(const u64 min, const u64 max,
 				 const struct tomoyo_group *group);
 bool tomoyo_parse_ipaddr_union(struct tomoyo_acl_param *param,
 			       struct tomoyo_ipaddr_union *ptr);
@@ -1037,7 +1036,7 @@ struct tomoyo_policy_namespace *tomoyo_assign_namespace
 (const char *domainname);
 struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
 				      const u8 profile);
-u8 tomoyo_parse_ulong(unsigned long *result, char **str);
+u8 tomoyo_parse_u64(u64 *result, char **str);
 void *tomoyo_commit_ok(void *data, const unsigned int size);
 void __init tomoyo_load_builtin_policy(void);
 void __init tomoyo_mm_init(void);
@@ -1055,8 +1054,8 @@ void tomoyo_normalize_line(unsigned char *buffer);
 void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register);
 void tomoyo_print_ip(char *buf, const unsigned int size,
 		     const struct tomoyo_ipaddr_union *ptr);
-void tomoyo_print_ulong(char *buffer, const int buffer_len,
-			const unsigned long value, const u8 type);
+void tomoyo_print_u64(char *buffer, const int buffer_len,
+		      const u64 value, const u8 type);
 void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
 void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
 void tomoyo_read_log(struct tomoyo_io_buffer *head);
security/tomoyo/condition.c +4 -4
index f8bcc083bb0d..4a27fbf4588b 100644
@@ -299,7 +299,7 @@ static bool tomoyo_parse_name_union_quoted(struct tomoyo_acl_param *param,
 static bool tomoyo_parse_argv(char *left, char *right,
 			      struct tomoyo_argv *argv)
 {
-	if (tomoyo_parse_ulong(&argv->index, &left) !=
+	if (tomoyo_parse_u64(&argv->index, &left) !=
 	    TOMOYO_VALUE_TYPE_DECIMAL || *left++ != ']' || *left)
 		return false;
 	argv->value = tomoyo_get_dqword(right);
@@ -766,8 +766,8 @@ bool tomoyo_condition(struct tomoyo_request_info *r,
 		      const struct tomoyo_condition *cond)
 {
 	u32 i;
-	unsigned long min_v[2] = { 0, 0 };
-	unsigned long max_v[2] = { 0, 0 };
+	u64 min_v[2] = { 0, 0 };
+	u64 max_v[2] = { 0, 0 };
 	const struct tomoyo_condition_element *condp;
 	const struct tomoyo_number_union *numbers_p;
 	const struct tomoyo_name_union *names_p;
@@ -834,7 +834,7 @@ bool tomoyo_condition(struct tomoyo_request_info *r,
 		/* Check numeric or bit-op expressions. */
 		for (j = 0; j < 2; j++) {
 			const u8 index = j ? right : left;
-			unsigned long value = 0;
+			u64 value = 0;
 
 			switch (index) {
 			case TOMOYO_TASK_UID:
security/tomoyo/file.c +3 -3
index 8f3b90b6e03d..4fa58abf5975 100644
@@ -109,7 +109,7 @@ void tomoyo_put_number_union(struct tomoyo_number_union *ptr)
  *
  * Returns true if @value matches @ptr, false otherwise.
  */
-bool tomoyo_compare_number_union(const unsigned long value,
+bool tomoyo_compare_number_union(const u64 value,
 				 const struct tomoyo_number_union *ptr)
 {
 	if (ptr->group)
@@ -230,8 +230,8 @@ static int tomoyo_audit_path_number_log(struct tomoyo_request_info *r)
 		radix = TOMOYO_VALUE_TYPE_DECIMAL;
 		break;
 	}
-	tomoyo_print_ulong(buffer, sizeof(buffer), r->param.path_number.number,
-			   radix);
+	tomoyo_print_u64(buffer, sizeof(buffer), r->param.path_number.number,
+			 radix);
 	return tomoyo_supervisor(r, "file %s %s %s\n", tomoyo_mac_keywords
 				 [tomoyo_pn2mac[type]],
 				 r->param.path_number.filename->name, buffer);
security/tomoyo/group.c +1 -2
index 1cecdd797597..dc650eaedba3 100644
@@ -155,8 +155,7 @@ tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
  *
  * Caller holds tomoyo_read_lock().
  */
-bool tomoyo_number_matches_group(const unsigned long min,
-				 const unsigned long max,
+bool tomoyo_number_matches_group(const u64 min, const u64 max,
 				 const struct tomoyo_group *group)
 {
 	struct tomoyo_number_group *member;
security/tomoyo/util.c +14 -14
index 6799b1122c9d..ac9535b4bdcd 100644
@@ -172,9 +172,9 @@ const struct tomoyo_path_info *tomoyo_get_domainname
 }
 
 /**
- * tomoyo_parse_ulong - Parse an "unsigned long" value.
+ * tomoyo_parse_u64 - Parse a u64 value.
  *
- * @result: Pointer to "unsigned long".
+ * @result: Pointer to u64.
  * @str:    Pointer to string to parse.
  *
  * Returns one of values in "enum tomoyo_value_type".
@@ -182,7 +182,7 @@ const struct tomoyo_path_info *tomoyo_get_domainname
  * The @src is updated to point the first character after the value
  * on success.
  */
-u8 tomoyo_parse_ulong(unsigned long *result, char **str)
+u8 tomoyo_parse_u64(u64 *result, char **str)
 {
 	const char *cp = *str;
 	char *ep;
@@ -199,7 +199,7 @@ u8 tomoyo_parse_ulong(unsigned long *result, char **str)
 			cp++;
 		}
 	}
-	*result = simple_strtoul(cp, &ep, base);
+	*result = (u64) simple_strtoull(cp, &ep, base);
 	if (cp == ep)
 		return TOMOYO_VALUE_TYPE_INVALID;
 	*str = ep;
@@ -214,24 +214,24 @@ u8 tomoyo_parse_ulong(unsigned long *result, char **str)
 }
 
 /**
- * tomoyo_print_ulong - Print an "unsigned long" value.
+ * tomoyo_print_u64 - Print a u64 value.
  *
  * @buffer:     Pointer to buffer.
  * @buffer_len: Size of @buffer.
- * @value:      An "unsigned long" value.
+ * @value:      A u64 value.
  * @type:       Type of @value.
  *
  * Returns nothing.
  */
-void tomoyo_print_ulong(char *buffer, const int buffer_len,
-			const unsigned long value, const u8 type)
+void tomoyo_print_u64(char *buffer, const int buffer_len,
+		      const u64 value, const u8 type)
 {
 	if (type == TOMOYO_VALUE_TYPE_DECIMAL)
-		snprintf(buffer, buffer_len, "%lu", value);
+		snprintf(buffer, buffer_len, "%llu", value);
 	else if (type == TOMOYO_VALUE_TYPE_OCTAL)
-		snprintf(buffer, buffer_len, "0%lo", value);
+		snprintf(buffer, buffer_len, "0%llo", value);
 	else if (type == TOMOYO_VALUE_TYPE_HEXADECIMAL)
-		snprintf(buffer, buffer_len, "0x%lX", value);
+		snprintf(buffer, buffer_len, "0x%llX", value);
 	else
 		snprintf(buffer, buffer_len, "type(%u)", type);
 }
@@ -274,7 +274,7 @@ bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
 {
 	char *data;
 	u8 type;
-	unsigned long v;
+	u64 v;
 
 	memset(ptr, 0, sizeof(*ptr));
 	if (param->data[0] == '@') {
@@ -283,7 +283,7 @@ bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
 		return ptr->group != NULL;
 	}
 	data = tomoyo_read_token(param);
-	type = tomoyo_parse_ulong(&v, &data);
+	type = tomoyo_parse_u64(&v, &data);
 	if (type == TOMOYO_VALUE_TYPE_INVALID)
 		return false;
 	ptr->values[0] = v;
@@ -295,7 +295,7 @@ bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
 	}
 	if (*data++ != '-')
 		return false;
-	type = tomoyo_parse_ulong(&v, &data);
+	type = tomoyo_parse_u64(&v, &data);
 	if (type == TOMOYO_VALUE_TYPE_INVALID || *data || ptr->values[0] > v)
 		return false;
 	ptr->values[1] = v;
Signature · 1 line
2.43.5
#21 lore raw

Re: [PATCH] tomoyo: use u64 for handling numeric values

Quoted 9 lines · Tetsuo Handa

TOMOYO was using "unsigned long" for handling numeric values because all possible value range fits in "unsigned long". Since Mickaël Salaün is about to replace "ino_t" with "u64", possible value range no longer fits in architecture-dependent "unsigned long". Therefore, replace "unsigned long" and "ino_t" with "u64".

---
Please include this patch before your patch.

Thanks, I'll merge the two patches to get a more consistent one in the next series.

Quoted 322 lines
 security/tomoyo/audit.c     | 10 ++++------
 security/tomoyo/common.c    | 14 +++++++-------
 security/tomoyo/common.h    | 17 ++++++++---------
 security/tomoyo/condition.c |  8 ++++----
 security/tomoyo/file.c      |  6 +++---
 security/tomoyo/group.c     |  3 +--
 security/tomoyo/util.c      | 28 ++++++++++++++--------------
 7 files changed, 41 insertions(+), 45 deletions(-)
security/tomoyo/audit.c +4 -6
index 610c1536cf70..36c9e63651b5 100644
@@ -195,21 +195,19 @@ static char *tomoyo_print_header(struct tomoyo_request_info *r)
 		if (i & 1) {
 			pos += snprintf(buffer + pos,
 					tomoyo_buffer_len - 1 - pos,
-					" path%u.parent={ uid=%u gid=%u ino=%lu perm=0%o }",
+					" path%u.parent={ uid=%u gid=%u ino=%llu perm=0%o }",
 					(i >> 1) + 1,
 					from_kuid(&init_user_ns, stat->uid),
 					from_kgid(&init_user_ns, stat->gid),
-					(unsigned long)stat->ino,
-					stat->mode & S_IALLUGO);
+					stat->ino, stat->mode & S_IALLUGO);
 			continue;
 		}
 		pos += snprintf(buffer + pos, tomoyo_buffer_len - 1 - pos,
-				" path%u={ uid=%u gid=%u ino=%lu major=%u minor=%u perm=0%o type=%s",
+				" path%u={ uid=%u gid=%u ino=%llu major=%u minor=%u perm=0%o type=%s",
 				(i >> 1) + 1,
 				from_kuid(&init_user_ns, stat->uid),
 				from_kgid(&init_user_ns, stat->gid),
-				(unsigned long)stat->ino,
-				MAJOR(dev), MINOR(dev),
+				stat->ino, MAJOR(dev), MINOR(dev),
 				mode & S_IALLUGO, tomoyo_filetype(mode));
 		if (S_ISCHR(mode) || S_ISBLK(mode)) {
 			dev = stat->rdev;
security/tomoyo/common.c +7 -7
index 5c7b059a332a..528b96c917e5 100644
@@ -424,8 +424,8 @@ static void tomoyo_print_number_union_nospace
 		tomoyo_set_string(head, ptr->group->group_name->name);
 	} else {
 		int i;
-		unsigned long min = ptr->values[0];
-		const unsigned long max = ptr->values[1];
+		u64 min = ptr->values[0];
+		const u64 max = ptr->values[1];
 		u8 min_type = ptr->value_type[0];
 		const u8 max_type = ptr->value_type[1];
 		char buffer[128];
@@ -435,15 +435,15 @@ static void tomoyo_print_number_union_nospace
 			switch (min_type) {
 			case TOMOYO_VALUE_TYPE_HEXADECIMAL:
 				tomoyo_addprintf(buffer, sizeof(buffer),
-						 "0x%lX", min);
+						 "0x%llX", min);
 				break;
 			case TOMOYO_VALUE_TYPE_OCTAL:
 				tomoyo_addprintf(buffer, sizeof(buffer),
-						 "0%lo", min);
+						 "0%llo", min);
 				break;
 			default:
-				tomoyo_addprintf(buffer, sizeof(buffer), "%lu",
-						 min);
+				tomoyo_addprintf(buffer, sizeof(buffer),
+						 "%llu", min);
 				break;
 			}
 			if (min == max && min_type == max_type)
@@ -1287,7 +1287,7 @@ static bool tomoyo_print_condition(struct tomoyo_io_buffer *head,
 				switch (left) {
 				case TOMOYO_ARGV_ENTRY:
 					tomoyo_io_printf(head,
-							 "exec.argv[%lu]%s=\"",
+							 "exec.argv[%llu]%s=\"",
 							 argv->index, argv->is_not ? "!" : "");
 					tomoyo_set_string(head,
 							  argv->value->name);
security/tomoyo/common.h +8 -9
index 0e8e2e959aef..bdbb4f0ae751 100644
@@ -524,7 +524,7 @@ struct tomoyo_name_union {
 
 /* Structure for holding a number. */
 struct tomoyo_number_union {
-	unsigned long values[2];
+	u64 values[2];
 	struct tomoyo_group *group; /* Maybe NULL. */
 	/* One of values in "enum tomoyo_value_type". */
 	u8 value_type[2];
@@ -567,7 +567,7 @@ struct tomoyo_address_group {
 struct tomoyo_mini_stat {
 	kuid_t uid;
 	kgid_t gid;
-	ino_t ino;
+	u64 ino;
 	umode_t mode;
 	dev_t dev;
 	dev_t rdev;
@@ -605,7 +605,7 @@ struct tomoyo_obj_info {
 
 /* Structure for argv[]. */
 struct tomoyo_argv {
-	unsigned long index;
+	u64 index;
 	const struct tomoyo_path_info *value;
 	bool is_not;
 };
@@ -926,7 +926,7 @@ struct tomoyo_task {
 
 bool tomoyo_address_matches_group(const bool is_ipv6, const __be32 *address,
 				  const struct tomoyo_group *group);
-bool tomoyo_compare_number_union(const unsigned long value,
+bool tomoyo_compare_number_union(const u64 value,
 				 const struct tomoyo_number_union *ptr);
 bool tomoyo_condition(struct tomoyo_request_info *r,
 		      const struct tomoyo_condition *cond);
@@ -938,8 +938,7 @@ bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
 bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos,
 		      struct tomoyo_page_dump *dump);
 bool tomoyo_memory_ok(void *ptr);
-bool tomoyo_number_matches_group(const unsigned long min,
-				 const unsigned long max,
+bool tomoyo_number_matches_group(const u64 min, const u64 max,
 				 const struct tomoyo_group *group);
 bool tomoyo_parse_ipaddr_union(struct tomoyo_acl_param *param,
 			       struct tomoyo_ipaddr_union *ptr);
@@ -1037,7 +1036,7 @@ struct tomoyo_policy_namespace *tomoyo_assign_namespace
 (const char *domainname);
 struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
 				      const u8 profile);
-u8 tomoyo_parse_ulong(unsigned long *result, char **str);
+u8 tomoyo_parse_u64(u64 *result, char **str);
 void *tomoyo_commit_ok(void *data, const unsigned int size);
 void __init tomoyo_load_builtin_policy(void);
 void __init tomoyo_mm_init(void);
@@ -1055,8 +1054,8 @@ void tomoyo_normalize_line(unsigned char *buffer);
 void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register);
 void tomoyo_print_ip(char *buf, const unsigned int size,
 		     const struct tomoyo_ipaddr_union *ptr);
-void tomoyo_print_ulong(char *buffer, const int buffer_len,
-			const unsigned long value, const u8 type);
+void tomoyo_print_u64(char *buffer, const int buffer_len,
+		      const u64 value, const u8 type);
 void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
 void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
 void tomoyo_read_log(struct tomoyo_io_buffer *head);
security/tomoyo/condition.c +4 -4
index f8bcc083bb0d..4a27fbf4588b 100644
@@ -299,7 +299,7 @@ static bool tomoyo_parse_name_union_quoted(struct tomoyo_acl_param *param,
 static bool tomoyo_parse_argv(char *left, char *right,
 			      struct tomoyo_argv *argv)
 {
-	if (tomoyo_parse_ulong(&argv->index, &left) !=
+	if (tomoyo_parse_u64(&argv->index, &left) !=
 	    TOMOYO_VALUE_TYPE_DECIMAL || *left++ != ']' || *left)
 		return false;
 	argv->value = tomoyo_get_dqword(right);
@@ -766,8 +766,8 @@ bool tomoyo_condition(struct tomoyo_request_info *r,
 		      const struct tomoyo_condition *cond)
 {
 	u32 i;
-	unsigned long min_v[2] = { 0, 0 };
-	unsigned long max_v[2] = { 0, 0 };
+	u64 min_v[2] = { 0, 0 };
+	u64 max_v[2] = { 0, 0 };
 	const struct tomoyo_condition_element *condp;
 	const struct tomoyo_number_union *numbers_p;
 	const struct tomoyo_name_union *names_p;
@@ -834,7 +834,7 @@ bool tomoyo_condition(struct tomoyo_request_info *r,
 		/* Check numeric or bit-op expressions. */
 		for (j = 0; j < 2; j++) {
 			const u8 index = j ? right : left;
-			unsigned long value = 0;
+			u64 value = 0;
 
 			switch (index) {
 			case TOMOYO_TASK_UID:
security/tomoyo/file.c +3 -3
index 8f3b90b6e03d..4fa58abf5975 100644
@@ -109,7 +109,7 @@ void tomoyo_put_number_union(struct tomoyo_number_union *ptr)
  *
  * Returns true if @value matches @ptr, false otherwise.
  */
-bool tomoyo_compare_number_union(const unsigned long value,
+bool tomoyo_compare_number_union(const u64 value,
 				 const struct tomoyo_number_union *ptr)
 {
 	if (ptr->group)
@@ -230,8 +230,8 @@ static int tomoyo_audit_path_number_log(struct tomoyo_request_info *r)
 		radix = TOMOYO_VALUE_TYPE_DECIMAL;
 		break;
 	}
-	tomoyo_print_ulong(buffer, sizeof(buffer), r->param.path_number.number,
-			   radix);
+	tomoyo_print_u64(buffer, sizeof(buffer), r->param.path_number.number,
+			 radix);
 	return tomoyo_supervisor(r, "file %s %s %s\n", tomoyo_mac_keywords
 				 [tomoyo_pn2mac[type]],
 				 r->param.path_number.filename->name, buffer);
security/tomoyo/group.c +1 -2
index 1cecdd797597..dc650eaedba3 100644
@@ -155,8 +155,7 @@ tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
  *
  * Caller holds tomoyo_read_lock().
  */
-bool tomoyo_number_matches_group(const unsigned long min,
-				 const unsigned long max,
+bool tomoyo_number_matches_group(const u64 min, const u64 max,
 				 const struct tomoyo_group *group)
 {
 	struct tomoyo_number_group *member;
security/tomoyo/util.c +14 -14
index 6799b1122c9d..ac9535b4bdcd 100644
@@ -172,9 +172,9 @@ const struct tomoyo_path_info *tomoyo_get_domainname
 }
 
 /**
- * tomoyo_parse_ulong - Parse an "unsigned long" value.
+ * tomoyo_parse_u64 - Parse a u64 value.
  *
- * @result: Pointer to "unsigned long".
+ * @result: Pointer to u64.
  * @str:    Pointer to string to parse.
  *
  * Returns one of values in "enum tomoyo_value_type".
@@ -182,7 +182,7 @@ const struct tomoyo_path_info *tomoyo_get_domainname
  * The @src is updated to point the first character after the value
  * on success.
  */
-u8 tomoyo_parse_ulong(unsigned long *result, char **str)
+u8 tomoyo_parse_u64(u64 *result, char **str)
 {
 	const char *cp = *str;
 	char *ep;
@@ -199,7 +199,7 @@ u8 tomoyo_parse_ulong(unsigned long *result, char **str)
 			cp++;
 		}
 	}
-	*result = simple_strtoul(cp, &ep, base);
+	*result = (u64) simple_strtoull(cp, &ep, base);
 	if (cp == ep)
 		return TOMOYO_VALUE_TYPE_INVALID;
 	*str = ep;
@@ -214,24 +214,24 @@ u8 tomoyo_parse_ulong(unsigned long *result, char **str)
 }
 
 /**
- * tomoyo_print_ulong - Print an "unsigned long" value.
+ * tomoyo_print_u64 - Print a u64 value.
  *
  * @buffer:     Pointer to buffer.
  * @buffer_len: Size of @buffer.
- * @value:      An "unsigned long" value.
+ * @value:      A u64 value.
  * @type:       Type of @value.
  *
  * Returns nothing.
  */
-void tomoyo_print_ulong(char *buffer, const int buffer_len,
-			const unsigned long value, const u8 type)
+void tomoyo_print_u64(char *buffer, const int buffer_len,
+		      const u64 value, const u8 type)
 {
 	if (type == TOMOYO_VALUE_TYPE_DECIMAL)
-		snprintf(buffer, buffer_len, "%lu", value);
+		snprintf(buffer, buffer_len, "%llu", value);
 	else if (type == TOMOYO_VALUE_TYPE_OCTAL)
-		snprintf(buffer, buffer_len, "0%lo", value);
+		snprintf(buffer, buffer_len, "0%llo", value);
 	else if (type == TOMOYO_VALUE_TYPE_HEXADECIMAL)
-		snprintf(buffer, buffer_len, "0x%lX", value);
+		snprintf(buffer, buffer_len, "0x%llX", value);
 	else
 		snprintf(buffer, buffer_len, "type(%u)", type);
 }
@@ -274,7 +274,7 @@ bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
 {
 	char *data;
 	u8 type;
-	unsigned long v;
+	u64 v;
 
 	memset(ptr, 0, sizeof(*ptr));
 	if (param->data[0] == '@') {
@@ -283,7 +283,7 @@ bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
 		return ptr->group != NULL;
 	}
 	data = tomoyo_read_token(param);
-	type = tomoyo_parse_ulong(&v, &data);
+	type = tomoyo_parse_u64(&v, &data);
 	if (type == TOMOYO_VALUE_TYPE_INVALID)
 		return false;
 	ptr->values[0] = v;
@@ -295,7 +295,7 @@ bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
 	}
 	if (*data++ != '-')
 		return false;
-	type = tomoyo_parse_ulong(&v, &data);
+	type = tomoyo_parse_u64(&v, &data);
 	if (type == TOMOYO_VALUE_TYPE_INVALID || *data || ptr->values[0] > v)
 		return false;
 	ptr->values[1] = v;
Signature · 1 line
2.43.5
#22 lore raw
In reply to Mickaël Salaün

Hi Mickaël,

Quoted 39 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

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(-)
fs/nfs/inode.c +0 -0
index 542c7d97b235..5dfc176b6d92 100644
@@ -83,18 +83,19 @@ EXPORT_SYMBOL_GPL(nfs_wait_bit_killable);
 

fs/nfs/inode.c EXPORT_SYMBOL_GPL(nfs_wait_bit_killable); · line 91

Quoted 10 lines
fs/nfs/inode.c +2 -2
 /**
  * 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)
                             ^^^^^^^^^^^^^^^^^^^

This should be "const struct inode *inode"

Quoted 23 lines
fs/nfs/inode.c +2 -0
 {
 #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)
 {
fs/nfs/internal.h +0 -0
index 430733e3eff2..f5555a71a733 100644

fs/nfs/internal.h extern void nfs_zap_acl_cache(struct inode *inode); · line 454

Quoted 4 lines
fs/nfs/internal.h +1 -0
@@ -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);

Why add this here when it's already in include/linux/nfs_fs.h? Can you update that declaration instead?

Also, there is a caller for nfs_compat_user_ino64() in fs/nfs/dir.c that needs to be updated. Can you double check that you have CONFIG_NFS_FS=m (or 'y') in your kernel .config? These are all issues my compiler caught when I applied your patch.

Thanks,
Anna

Quoted 61 lines
fs/nfs/internal.h +0 -0
 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
 /* localio.c */
fs/nfs/namespace.c +2 -0
index e7494cdd957e..d9b1e0606833 100644
@@ -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)
fs/stat.c +1 -1
index 41e598376d7e..05636919f94b 100644
@@ -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);
include/linux/fs.h +9 -0
index e3c603d01337..0eba09a21cf7 100644
@@ -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 *,
#23 lore raw
Quoted 53 lines · Anna Schumaker

Hi Mickaël,

Quoted 39 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

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(-)
fs/nfs/inode.c +0 -0
index 542c7d97b235..5dfc176b6d92 100644
@@ -83,18 +83,19 @@ EXPORT_SYMBOL_GPL(nfs_wait_bit_killable);
 

fs/nfs/inode.c EXPORT_SYMBOL_GPL(nfs_wait_bit_killable); · line 91

Quoted 10 lines
fs/nfs/inode.c +2 -2
 /**
  * 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)
                             ^^^^^^^^^^^^^^^^^^^
Quoted 1 line

This should be "const struct inode *inode"

Indeed...

Quoted 31 lines
Quoted 24 lines
fs/nfs/inode.c +2 -0
 {
 #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)
 {
fs/nfs/internal.h +0 -0
index 430733e3eff2..f5555a71a733 100644

fs/nfs/internal.h extern void nfs_zap_acl_cache(struct inode *inode); · line 454

Quoted 4 lines
fs/nfs/internal.h +1 -0
@@ -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);

Why add this here when it's already in include/linux/nfs_fs.h? Can you update that declaration instead?

Quoted 1 line

Also, there is a caller for nfs_compat_user_ino64() in fs/nfs/dir.c that needs to be updated. Can you double check that you have CONFIG_NFS_FS=m (or 'y') in your kernel .config? These are all issues my compiler caught when I applied your patch.

Oh, I enabled CONFIG_NFSD_V4 and CONFIG_NFS_COMMON but not CONFIG_NFS_FS, that explains these uncaught errors... Thanks!

About the nfs_do_filldir(), the nfs_compat_user_ino64() call is indeed not correct with this patch, but I'm wondering why not use ent->ino instead?

Quoted 18 lines

Thanks,
Anna

Quoted 14 lines
fs/nfs/internal.h +0 -0
 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
 /* localio.c */
fs/nfs/namespace.c +1 -0
index e7494cdd957e..d9b1e0606833 100644
@@ -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,
 };
 
Quoted 4 lines

fs/nfs/namespace.c nfs_namespace_setattr(struct mnt_idmap *idmap, struct dentry *dentry, · line 241

Quoted 4 lines
fs/nfs/namespace.c +1 -0
 const struct inode_operations nfs_referral_inode_operations = {
 	.getattr	= nfs_namespace_getattr,
 	.setattr	= nfs_namespace_setattr,
+	.get_ino	= nfs_compat_user_ino64,

Is it correct to use nfs_compat_user_ino64() for both of these inode operation structs? With this patch, generic_fileattr() initialize the stat struct with get_ino(), which might not what we want according to these nfs_mountpoint and nfs_referral structs.

Quoted 45 lines
Quoted 43 lines
fs/nfs/namespace.c +0 -0
 };
 
 static void nfs_expire_automounts(struct work_struct *work)
fs/stat.c +1 -1
index 41e598376d7e..05636919f94b 100644
@@ -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);
include/linux/fs.h +9 -0
index e3c603d01337..0eba09a21cf7 100644
@@ -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 *,
maintainer
#24 lore raw
In reply to Mickaël Salaün
Quoted 147 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

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(-)
fs/nfs/inode.c +0 -0
index 542c7d97b235..5dfc176b6d92 100644
@@ -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.
  */

fs/nfs/inode.c +1 -1
-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

fs/nfs/inode.c +1 -0
+	u64 fileid = NFS_FILEID(inode);


  if (enable_ino64)
  return fileid;

fs/nfs/inode.c +1 -0
@@ -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)
 {

fs/nfs/internal.h +0 -0
index 430733e3eff2..f5555a71a733 100644
@@ -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 */

fs/nfs/namespace.c +1 -0
index e7494cdd957e..d9b1e0606833 100644
@@ -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,

fs/nfs/namespace.c +1 -0
+	.get_ino	= nfs_compat_user_ino64,

 };

 static void nfs_expire_automounts(struct work_struct *work)

fs/stat.c +0 -0
index 41e598376d7e..05636919f94b 100644
@@ -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;

fs/stat.c +1 -1
-	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);

include/linux/fs.h +0 -0
index e3c603d01337..0eba09a21cf7 100644
@@ -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);

include/linux/fs.h +1 -0
+	u64 (*get_ino)(const struct inode *inode);

 } ____cacheline_aligned;

 static inline int call_mmap(struct file *file, struct vm_area_struct *vma)

include/linux/fs.h +0 -0
@@ -2172,6 +2173,14 @@ static inline int call_mmap(struct file *file,
 struct vm_area_struct *vma)
  	return file->f_op->mmap(file, vma);
  }

include/linux/fs.h +8 -0
+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;
+}
+
Quoted 6 lines

 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 *,

There should be no need to add this callback to generic_fillattr().

generic_fillattr() is a helper function for use by the filesystems themselves. It should never be called from any outside functions, as the inode number would be far from the only attribute that will be incorrect.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#25 lore raw
Quoted 157 lines · Trond Myklebust
Quoted 147 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

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(-)
fs/nfs/inode.c +0 -0
index 542c7d97b235..5dfc176b6d92 100644
@@ -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.
  */

fs/nfs/inode.c +1 -1
-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

fs/nfs/inode.c +1 -0
+	u64 fileid = NFS_FILEID(inode);


  if (enable_ino64)
  return fileid;

fs/nfs/inode.c +1 -0
@@ -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)
 {

fs/nfs/internal.h +0 -0
index 430733e3eff2..f5555a71a733 100644
@@ -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 */

fs/nfs/namespace.c +1 -0
index e7494cdd957e..d9b1e0606833 100644
@@ -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,

fs/nfs/namespace.c +1 -0
+	.get_ino	= nfs_compat_user_ino64,

 };

 static void nfs_expire_automounts(struct work_struct *work)

fs/stat.c +0 -0
index 41e598376d7e..05636919f94b 100644
@@ -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;

fs/stat.c +1 -1
-	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);

include/linux/fs.h +0 -0
index e3c603d01337..0eba09a21cf7 100644
@@ -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);

include/linux/fs.h +1 -0
+	u64 (*get_ino)(const struct inode *inode);

 } ____cacheline_aligned;

 static inline int call_mmap(struct file *file, struct vm_area_struct *vma)

include/linux/fs.h +0 -0
@@ -2172,6 +2173,14 @@ static inline int call_mmap(struct file *file,
 struct vm_area_struct *vma)
  	return file->f_op->mmap(file, vma);
  }

include/linux/fs.h +8 -0
+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;
+}
+
Quoted 6 lines

 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 *,

There should be no need to add this callback to generic_fillattr().

Quoted 4 lines

generic_fillattr() is a helper function for use by the filesystems themselves. It should never be called from any outside functions, as the inode number would be far from the only attribute that will be incorrect.

This change will not impact filesystems except the ones that implement the new get_ino() operation, and I suspect NFS is not or will not be the only one. We need to investigate on other filesystems but I wanted to get a first feedback before. Using get_ino() in generic_fillattr() should guarantee a consistent getattr() wrt inode numbers. I forgot to remove the now-useless call to nfs_compat_user_ino64() in nfs_getattr() for this to make sense:

fs/nfs/inode.c +0 -1
index 542c7d97b235..78a9e907c905 100644
@@ -981,7 +983,6 @@ int nfs_getattr(struct mnt_idmap *idmap, const struct path *path,
        stat->result_mask = nfs_get_valid_attrmask(inode) | request_mask;
 
        generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
-       stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
        stat->change_cookie = inode_peek_iversion_raw(inode);
        stat->attributes_mask |= STATX_ATTR_CHANGE_MONOTONIC;
        if (server->change_attr_type != NFS4_CHANGE_TYPE_IS_UNDEFINED)

Al, Christian, what do you think about this generic_fillattr() change?

Quoted 7 lines
Signature · 4 lines
-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
maintainer
#26 lore raw
Quoted 184 lines · Mickaël Salaün
Quoted 177 lines · Trond Myklebust
Quoted 165 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

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(-)
fs/nfs/inode.c +0 -0
index 542c7d97b235..5dfc176b6d92 100644
@@ -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.
  */

fs/nfs/inode.c +1 -1
-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

fs/nfs/inode.c +1 -0
+	u64 fileid = NFS_FILEID(inode);


  if (enable_ino64)
  return fileid;

fs/nfs/inode.c +0 -0
@@ -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)
 {

fs/nfs/internal.h +0 -0
index 430733e3eff2..f5555a71a733 100644
@@ -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 */

fs/nfs/namespace.c +0 -0
index e7494cdd957e..d9b1e0606833 100644
@@ -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,

fs/nfs/namespace.c +1 -0
+	.get_ino	= nfs_compat_user_ino64,

 };

 const struct inode_operations nfs_referral_inode_operations = {
  .getattr = nfs_namespace_getattr,
  .setattr = nfs_namespace_setattr,

fs/nfs/namespace.c +1 -0
+	.get_ino	= nfs_compat_user_ino64,

 };

 static void nfs_expire_automounts(struct work_struct *work)

fs/stat.c +0 -0
index 41e598376d7e..05636919f94b 100644
@@ -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;

fs/stat.c +1 -1
-	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);

include/linux/fs.h +0 -0
index e3c603d01337..0eba09a21cf7 100644
@@ -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);

include/linux/fs.h +1 -0
+	u64 (*get_ino)(const struct inode *inode);

 } ____cacheline_aligned;

 static inline int call_mmap(struct file *file, struct vm_area_struct
*vma)

include/linux/fs.h +0 -0
@@ -2172,6 +2173,14 @@ static inline int call_mmap(struct file
 *file,
 struct vm_area_struct *vma)
  	return file->f_op->mmap(file, vma);
  }

include/linux/fs.h +8 -0
+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,

Quoted 8 lines

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 *,

There should be no need to add this callback to generic_fillattr().

Quoted 5 lines

generic_fillattr() is a helper function for use by the filesystems themselves. It should never be called from any outside functions, as
the inode number would be far from the only attribute that will be incorrect.

Quoted 11 lines

This change will not impact filesystems except the ones that implement the new
get_ino() operation, and I suspect NFS is not or will not be the only one.  We
need to investigate on other filesystems but I wanted to get a first feedback
before.  Using get_ino() in generic_fillattr() should guarantee a consistent
getattr() wrt inode numbers.  I forgot to remove the now-useless call to
nfs_compat_user_ino64() in nfs_getattr() for this to make sense:

You're missing my point. From the point of view of NFS, all you're doing is to replace a relatively fast direct call to nfs_compat_user_ino64() with a much slower callback. There is no benefit at all to anyone in doing so.

Yes, other filesystems may also want to replace this and/or other fields in the "struct kstat" that they return, but none of them should have a problem with doing that after the actual call to generic_fillattr().

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#27 lore raw
Quoted 202 lines · Trond Myklebust
Quoted 184 lines · Mickaël Salaün
Quoted 177 lines · Trond Myklebust
Quoted 165 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

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(-)
fs/nfs/inode.c +0 -0
index 542c7d97b235..5dfc176b6d92 100644
@@ -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.
  */

fs/nfs/inode.c +1 -1
-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

fs/nfs/inode.c +1 -0
+	u64 fileid = NFS_FILEID(inode);


  if (enable_ino64)
  return fileid;

fs/nfs/inode.c +0 -0
@@ -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)
 {

fs/nfs/internal.h +0 -0
index 430733e3eff2..f5555a71a733 100644
@@ -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 */

fs/nfs/namespace.c +0 -0
index e7494cdd957e..d9b1e0606833 100644
@@ -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,

fs/nfs/namespace.c +1 -0
+	.get_ino	= nfs_compat_user_ino64,

 };

 const struct inode_operations nfs_referral_inode_operations = {
  .getattr = nfs_namespace_getattr,
  .setattr = nfs_namespace_setattr,

fs/nfs/namespace.c +1 -0
+	.get_ino	= nfs_compat_user_ino64,

 };

 static void nfs_expire_automounts(struct work_struct *work)

fs/stat.c +0 -0
index 41e598376d7e..05636919f94b 100644
@@ -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;

fs/stat.c +1 -1
-	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);

include/linux/fs.h +0 -0
index e3c603d01337..0eba09a21cf7 100644
@@ -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);

include/linux/fs.h +1 -0
+	u64 (*get_ino)(const struct inode *inode);

 } ____cacheline_aligned;

 static inline int call_mmap(struct file *file, struct vm_area_struct
*vma)

include/linux/fs.h +0 -0
@@ -2172,6 +2173,14 @@ static inline int call_mmap(struct file
 *file,
 struct vm_area_struct *vma)
  	return file->f_op->mmap(file, vma);
  }

include/linux/fs.h +8 -0
+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,

Quoted 8 lines

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 *,

There should be no need to add this callback to generic_fillattr().

Quoted 5 lines

generic_fillattr() is a helper function for use by the filesystems themselves. It should never be called from any outside functions, as
the inode number would be far from the only attribute that will be incorrect.

Quoted 11 lines

This change will not impact filesystems except the ones that implement the new
get_ino() operation, and I suspect NFS is not or will not be the only one.  We
need to investigate on other filesystems but I wanted to get a first feedback
before.  Using get_ino() in generic_fillattr() should guarantee a consistent
getattr() wrt inode numbers.  I forgot to remove the now-useless call to
nfs_compat_user_ino64() in nfs_getattr() for this to make sense:

You're missing my point. From the point of view of NFS, all you're doing is to replace a relatively fast direct call to nfs_compat_user_ino64() with a much slower callback. There is no benefit at all to anyone in doing so.

Quoted 4 lines

Yes, other filesystems may also want to replace this and/or other fields in the "struct kstat" that they return, but none of them should have a problem with doing that after the actual call to generic_fillattr().

OK, I'll remove this part then.

Quoted 8 lines
Signature · 4 lines
-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#28 lore raw
Quoted 203 lines · Mickaël Salaün
Quoted 202 lines · Trond Myklebust
Quoted 184 lines · Mickaël Salaün
Quoted 177 lines · Trond Myklebust
Quoted 165 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

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(-)
fs/nfs/inode.c +0 -0
index 542c7d97b235..5dfc176b6d92 100644
@@ -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.
  */

fs/nfs/inode.c +1 -1
-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

fs/nfs/inode.c +1 -0
+	u64 fileid = NFS_FILEID(inode);


  if (enable_ino64)
  return fileid;

fs/nfs/inode.c +0 -0
@@ -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)
 {

fs/nfs/internal.h +0 -0
index 430733e3eff2..f5555a71a733 100644
@@ -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 */

fs/nfs/namespace.c +0 -0
index e7494cdd957e..d9b1e0606833 100644
@@ -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,

fs/nfs/namespace.c +1 -0
+	.get_ino	= nfs_compat_user_ino64,

 };

 const struct inode_operations nfs_referral_inode_operations = {
  .getattr = nfs_namespace_getattr,
  .setattr = nfs_namespace_setattr,

fs/nfs/namespace.c +1 -0
+	.get_ino	= nfs_compat_user_ino64,

 };

 static void nfs_expire_automounts(struct work_struct *work)

fs/stat.c +0 -0
index 41e598376d7e..05636919f94b 100644
@@ -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;

fs/stat.c +1 -1
-	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);

include/linux/fs.h +0 -0
index e3c603d01337..0eba09a21cf7 100644
@@ -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);

include/linux/fs.h +1 -0
+	u64 (*get_ino)(const struct inode *inode);

 } ____cacheline_aligned;

 static inline int call_mmap(struct file *file, struct vm_area_struct
*vma)

include/linux/fs.h +0 -0
@@ -2172,6 +2173,14 @@ static inline int call_mmap(struct file
 *file,
 struct vm_area_struct *vma)
  	return file->f_op->mmap(file, vma);
  }

include/linux/fs.h +8 -0
+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,

Quoted 8 lines

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 *,

There should be no need to add this callback to generic_fillattr().

Quoted 5 lines

generic_fillattr() is a helper function for use by the filesystems themselves. It should never be called from any outside functions, as
the inode number would be far from the only attribute that will be incorrect.

Quoted 11 lines

This change will not impact filesystems except the ones that implement the new
get_ino() operation, and I suspect NFS is not or will not be the only one.  We
need to investigate on other filesystems but I wanted to get a first feedback
before.  Using get_ino() in generic_fillattr() should guarantee a consistent
getattr() wrt inode numbers.  I forgot to remove the now-useless call to
nfs_compat_user_ino64() in nfs_getattr() for this to make sense:

You're missing my point. From the point of view of NFS, all you're doing is to replace a relatively fast direct call to nfs_compat_user_ino64() with a much slower callback. There is no benefit at all to anyone in doing so.

Quoted 6 lines
Quoted 4 lines

Yes, other filesystems may also want to replace this and/or other fields in the "struct kstat" that they return, but none of them should have a problem with doing that after the actual call to generic_fillattr().

OK, I'll remove this part then.

My concern is about maintaining consistency. If this get_ino() operation is not visible to filesystem developers, I think there is a good chance for desynchronization between the getattr() implementation and get get_ino(). Anyway, I guess the performance argument wins.

Quoted 9 lines
Quoted 9 lines
Signature · 4 lines
-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
maintainer
#29 lore raw
In reply to Mickaël Salaün
Quoted 3 lines · Mickaël Salaün

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.

I can't catch what you are trying to do. What is wrong with that?

Quoted 2 lines

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.

Currently, ino_t is 32bits on 32-bit architectures, isn't it? Why do you need to use 64bits on 32-bit architectures?

Quoted 3 lines

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().

What does the user space's view of an inode number mean? What does the kernel space's view of an inode number mean?

maintainer
#30 lore raw
Quoted 5 lines · Tetsuo Handa
Quoted 3 lines · Mickaël Salaün

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.

Quoted 7 lines

I can't catch what you are trying to do. What is wrong with that?

Quoted 2 lines

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.

Currently, ino_t is 32bits on 32-bit architectures, isn't it? Why do you need to use 64bits on 32-bit architectures?

Changing from 32bits to 64bits for communicating with userspace programs breaks userspace programs using "ino_t" (or "unsigned long") for handling inode numbers, doesn't it? Attempt to change from %lu to %llu will not be acceptable unless the upper 32bits are guaranteed to be 0 on 32-bit architectures.

Since syslogd/auditd are not the only programs that parse kernel logs and audit logs, updating only syslogd/auditd is not sufficient. We must not break existing userspace programs, and thus we can't change the format string.

Quoted 8 lines
Quoted 4 lines

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().

What does the user space's view of an inode number mean? What does the kernel space's view of an inode number mean?

#31 lore raw
Quoted 15 lines · Tetsuo Handa
Quoted 7 lines · Tetsuo Handa
Quoted 2 lines · Mickaël Salaün

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.

Currently, ino_t is 32bits on 32-bit architectures, isn't it? Why do you need to use 64bits on 32-bit architectures?

Changing from 32bits to 64bits for communicating with userspace programs breaks userspace programs using "ino_t" (or "unsigned long") for handling inode numbers, doesn't it? Attempt to change from %lu to %llu will not be acceptable unless the upper 32bits are guaranteed to be 0 on 32-bit architectures.

Quoted 3 lines

Since syslogd/auditd are not the only programs that parse kernel logs and audit logs, updating only syslogd/auditd is not sufficient. We must not break existing userspace programs, and thus we can't change the format string.

This might only break user space that wrongfully uses 32-bit variables to store 64-bit values. According to the UAPI, inode numbers should be 64 bits.

#32 lore raw
In reply to Tetsuo Handa
Quoted 6 lines · Tetsuo Handa
Quoted 3 lines · Mickaël Salaün

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.

I can't catch what you are trying to do. What is wrong with that?

My understanding is that tomoyo_get_attributes() is used to log or expose access requests to user space, including inode numbers. Is that correct? If yes, then the inode numbers might not reflect what user space sees with stat(2).

Quoted 6 lines
Quoted 3 lines

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.

Currently, ino_t is 32bits on 32-bit architectures, isn't it? Why do you need to use 64bits on 32-bit architectures?

ino_t is indeed 32 bits on 32-bit architectures, but user space can still get a 64-bit stat->ino value.

Quoted 6 lines
Quoted 4 lines

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().

What does the user space's view of an inode number mean?

It's the value user space gets with stat(2).

Quoted 1 line

What does the kernel space's view of an inode number mean?

It's struct inode->i_ino and ino_t variables.

maintainer
#33 lore raw
Quoted 6 lines · Mickaël Salaün
Quoted 5 lines · Tetsuo Handa
Quoted 3 lines · Mickaël Salaün

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.

Quoted 6 lines
Quoted 1 line

I can't catch what you are trying to do. What is wrong with that?

My understanding is that tomoyo_get_attributes() is used to log or expose access requests to user space, including inode numbers. Is that correct? If yes, then the inode numbers might not reflect what user space sees with stat(2).

Several questions because I've never seen inode number beyond UINT_MAX...

Since "struct inode"->i_ino is "unsigned long" (which is 32bits on 32-bit architectures), despite stat(2) is ready to receive inode number as 64bits, filesystems (except NFS) did not use inode numbers beyond UINT_MAX until now so that fs/stat.c will not hit -EOVERFLOW condition, and that resulted in misuse of %lu for e.g. audit logs?

But NFS was already using inode numbers beyond UINT_MAX, and e.g. audit logs had been recording incorrect values when NFS is used?

Or, some filesystems are already using inode numbers beyond UINT_MAX but the capacity limitation on 32-bit architectures practically prevented users from creating/mounting filesystems with so many inodes enough to require inode numbers going beyond UINT_MAX?

You are trying to fix out-of-sync between stat(2) and e.g. audit logs rather than introducing new feature, aren't you?

Then, what you are trying to do is OK, but TOMOYO side needs more changes. Since TOMOYO is currently handling any numeric values (e.g. uid, gid, device major/minor number, inode number, ioctl's cmd number) as "unsigned long", most of "unsigned long" usage in TOMOYO needs to be updated to use "u64" because you are about to change inode number values to always-64bits.

#34 lore raw
Quoted 4 lines · Tetsuo Handa

Or, some filesystems are already using inode numbers beyond UINT_MAX but the capacity limitation on 32-bit architectures practically prevented users from creating/mounting filesystems with so many inodes enough to require inode numbers going beyond UINT_MAX?

Plenty of file systems use 64-bit inode numbers. XFS and btrfs for example if you care about commonly used local file systems.

#35 lore raw
In reply to Tetsuo Handa
Quoted 14 lines · Tetsuo Handa
Quoted 6 lines · Mickaël Salaün
Quoted 5 lines · Tetsuo Handa
Quoted 3 lines · Mickaël Salaün

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.

Quoted 6 lines
Quoted 1 line

I can't catch what you are trying to do. What is wrong with that?

My understanding is that tomoyo_get_attributes() is used to log or expose access requests to user space, including inode numbers. Is that correct? If yes, then the inode numbers might not reflect what user space sees with stat(2).

Quoted 7 lines

Several questions because I've never seen inode number beyond UINT_MAX...

Since "struct inode"->i_ino is "unsigned long" (which is 32bits on 32-bit architectures), despite stat(2) is ready to receive inode number as 64bits, filesystems (except NFS) did not use inode numbers beyond UINT_MAX until now so that fs/stat.c will not hit -EOVERFLOW condition, and that resulted in misuse of %lu for e.g. audit logs?

Yes, I think other filesystems (e.g. tmpfs) only enable 64-bit inodes on 64-bit architectures.

Quoted 3 lines

But NFS was already using inode numbers beyond UINT_MAX, and e.g. audit logs had been recording incorrect values when NFS is used?

Correct, all the logs with NFS inodes are wrong.

Quoted 5 lines

Or, some filesystems are already using inode numbers beyond UINT_MAX but the capacity limitation on 32-bit architectures practically prevented users from creating/mounting filesystems with so many inodes enough to require inode numbers going beyond UINT_MAX?

I think so but I didn't take a look at all other filesystems.

Quoted 5 lines

You are trying to fix out-of-sync between stat(2) and e.g. audit logs rather than introducing new feature, aren't you?

Yes

Quoted 7 lines

Then, what you are trying to do is OK, but TOMOYO side needs more changes. Since TOMOYO is currently handling any numeric values (e.g. uid, gid, device major/minor number, inode number, ioctl's cmd number) as "unsigned long", most of "unsigned long" usage in TOMOYO needs to be updated to use "u64" because you are about to change inode number values to always-64bits.

OK, could you please send a full patch in reply to this email? I'll include it in the next patch series.

#36 lore raw
In reply to Mickaël Salaün
Quoted 4 lines · Mickaël Salaün

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.

Quoted 8 lines

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.

The proper interface for that is ->getattr, and you should use that for all file systems (through the proper vfs wrappers).

And yes, it's really time to move to a 64-bit i_ino, but that's a separate discussion.

#37 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Mickaël Salaün

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.

Quoted 8 lines
Quoted 5 lines

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.

The proper interface for that is ->getattr, and you should use that for all file systems (through the proper vfs wrappers).

How to get the inode number with ->getattr and only a struct inode?

Quoted 3 lines

And yes, it's really time to move to a 64-bit i_ino, but that's a separate discussion.

#38 lore raw
Quoted 1 line · Mickaël Salaün

How to get the inode number with ->getattr and only a struct inode?

You get a struct kstat and extract it from that.

#39 lore raw
Quoted 4 lines · Christoph Hellwig
Quoted 1 line · Mickaël Salaün

How to get the inode number with ->getattr and only a struct inode?

You get a struct kstat and extract it from that.

Yes, but how do you call getattr() without a path?

#40 lore raw
Quoted 7 lines · Mickaël Salaün
Quoted 4 lines · Christoph Hellwig
Quoted 1 line · Mickaël Salaün

How to get the inode number with ->getattr and only a struct inode?

You get a struct kstat and extract it from that.

Yes, but how do you call getattr() without a path?

You don't because inode numbers are irrelevant without the path.

#41 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Mickaël Salaün
Quoted 4 lines · Christoph Hellwig
Quoted 1 line · Mickaël Salaün

How to get the inode number with ->getattr and only a struct inode?

You get a struct kstat and extract it from that.

Yes, but how do you call getattr() without a path?

You don't because inode numbers are irrelevant without the path.

They are for kernel messages and audit logs. Please take a look at the use cases with the other patches.

#42 lore raw
Quoted 6 lines · Mickaël Salaün
Quoted 3 lines
Quoted 1 line

Yes, but how do you call getattr() without a path?

You don't because inode numbers are irrelevant without the path.

They are for kernel messages and audit logs. Please take a look at the use cases with the other patches.

It still is useless. E.g. btrfs has duplicate inode numbers due to subvolumes.

If you want a better pretty but not useful value just work on making i_ino 64-bits wide, which is long overdue.

#43 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Mickaël Salaün
Quoted 3 lines
Quoted 1 line

Yes, but how do you call getattr() without a path?

You don't because inode numbers are irrelevant without the path.

They are for kernel messages and audit logs. Please take a look at the use cases with the other patches.

It still is useless. E.g. btrfs has duplicate inode numbers due to subvolumes.

At least it reflects what users see.

Quoted 3 lines

If you want a better pretty but not useful value just work on making i_ino 64-bits wide, which is long overdue.

That would require too much work for me, and this would be a pain to backport to all stable kernels.

Reviewed-by
#44 lore raw
Quoted 4 lines · Mickaël Salaün
Quoted 2 lines

It still is useless. E.g. btrfs has duplicate inode numbers due to subvolumes.

At least it reflects what users see.

Users generally don't see inode numbers.

Quoted 5 lines
Quoted 2 lines

If you want a better pretty but not useful value just work on making i_ino 64-bits wide, which is long overdue.

That would require too much work for me, and this would be a pain to backport to all stable kernels.

Well, if doing the right thing is too hard we can easily do nothing.

In case it wan't clear, this thread has been a very explicit:

#45 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 4 lines · Mickaël Salaün
Quoted 2 lines

It still is useless. E.g. btrfs has duplicate inode numbers due to subvolumes.

At least it reflects what users see.

Users generally don't see inode numbers.

Quoted 3 lines
Quoted 2 lines

If you want a better pretty but not useful value just work on making i_ino 64-bits wide, which is long overdue.

Quoted 8 lines
Quoted 2 lines

That would require too much work for me, and this would be a pain to backport to all stable kernels.

Well, if doing the right thing is too hard we can easily do nothing.

In case it wan't clear, this thread has been a very explicit:

This must be typo and you want a NAK here, right?

#46 lore raw
Quoted 15 lines · Christian Brauner
Quoted 14 lines · Christoph Hellwig
Quoted 4 lines · Mickaël Salaün
Quoted 2 lines

It still is useless. E.g. btrfs has duplicate inode numbers due to subvolumes.

At least it reflects what users see.

Users generally don't see inode numbers.

Quoted 5 lines
Quoted 2 lines

If you want a better pretty but not useful value just work on making i_ino 64-bits wide, which is long overdue.

That would require too much work for me, and this would be a pain to backport to all stable kernels.

Quoted 7 lines
Quoted 5 lines

Well, if doing the right thing is too hard we can easily do nothing.

In case it wan't clear, this thread has been a very explicit:

This must be typo and you want a NAK here, right?

Yes :)

maintainer
#47 lore raw
In reply to Mickaël Salaün
Quoted 12 lines · Mickaël Salaün
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Mickaël Salaün
Quoted 3 lines
Quoted 1 line

Yes, but how do you call getattr() without a path?

You don't because inode numbers are irrelevant without the path.

They are for kernel messages and audit logs. Please take a look at the use cases with the other patches.

It still is useless. E.g. btrfs has duplicate inode numbers due to subvolumes.

Quoted 9 lines

At least it reflects what users see.

Quoted 3 lines

If you want a better pretty but not useful value just work on making i_ino 64-bits wide, which is long overdue.

That would require too much work for me, and this would be a pain to backport to all stable kernels.

Would it though? Adding this new inode operation seems sub-optimal.

Inode numbers are static information. Once an inode number is set on an inode it basically never changes. This patchset will turn all of those direct inode->i_ino fetches into a pointer chase for the new inode operation, which will then almost always just result in a direct fetch.

A better solution here would be to make inode->i_ino a u64, and just fix up all of the places that touch it to expect that. Then, just ensure that all of the filesystems set it properly when instantiating new inodes. Even on 32-bit arch, you likely wouldn't need a seqcount loop or anything to fetch this since the chance of a torn read there is basically zero.

If there are places where we need to convert i_ino down to 32-bits, then we can just use some scheme like nfs_fattr_to_ino_t(), or just cast i_ino to a u32.

Yes, it'd be a larger patchset, but that seems like it would be a better solution.

Signature · 1 line
Jeff Layton <[email protected]>
#48 lore raw
Quoted 37 lines · Jeff Layton
Quoted 12 lines · Mickaël Salaün
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Mickaël Salaün
Quoted 3 lines
Quoted 1 line

Yes, but how do you call getattr() without a path?

You don't because inode numbers are irrelevant without the path.

They are for kernel messages and audit logs. Please take a look at the use cases with the other patches.

It still is useless. E.g. btrfs has duplicate inode numbers due to subvolumes.

Quoted 9 lines

At least it reflects what users see.

Quoted 3 lines

If you want a better pretty but not useful value just work on making i_ino 64-bits wide, which is long overdue.

That would require too much work for me, and this would be a pain to backport to all stable kernels.

Would it though? Adding this new inode operation seems sub-optimal.

Inode numbers are static information. Once an inode number is set on an inode it basically never changes. This patchset will turn all of those direct inode->i_ino fetches into a pointer chase for the new inode operation, which will then almost always just result in a direct fetch.

A better solution here would be to make inode->i_ino a u64, and just fix up all of the places that touch it to expect that. Then, just ensure that all of the filesystems set it properly when instantiating new inodes. Even on 32-bit arch, you likely wouldn't need a seqcount loop or anything to fetch this since the chance of a torn read there is basically zero.

Quoted 6 lines

If there are places where we need to convert i_ino down to 32-bits, then we can just use some scheme like nfs_fattr_to_ino_t(), or just cast i_ino to a u32.

Yes, it'd be a larger patchset, but that seems like it would be a better solution.

As someone who lives in the analytical user space of Linux audit, I take it that for large (say >200TB) file systems, the inode value reported in audit PATH records is no longer forensically defensible and it's use as a correlation item is of questionable value now?

#49 lore raw
Quoted 4 lines · Burn Alting

As someone who lives in the analytical user space of Linux audit, I take it that for large (say >200TB) file systems, the inode value reported in audit PATH records is no longer forensically defensible and it's use as a correlation item is of questionable value now?

What do you mean with forensically defensible?

A 64-bit inode number is supposed to be unique. Some file systems (most notably btrfs, but probably also various non-native file system) break and this, and get away with lots of userspace hacks papering over it. If you are on a 32-bit system and not using the LFS APIs stat will fail with -EOVERFLOW. Some file systems have options to never generate > 32bit inode numbers. None of that is directly related to file system size, although at least for XFS file system size is one relevant variable, but 200TB is in no way relevant.

#50 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 4 lines · Burn Alting

As someone who lives in the analytical user space of Linux audit, I take it that for large (say >200TB) file systems, the inode value reported in audit PATH records is no longer forensically defensible and it's use as a correlation item is of questionable value now?

What do you mean with forensically defensible?

If the auditd system only maintains a 32 bit variable for an inode value, when it emits an inode number, then how does one categorically state/defend that the inode value in the audit event is the actual one on the file system. The PATH record will offer one value (32 bits) but the returned inode value from a stat will return another (the actual 64 bit value). Basically auditd would not be recording the correct value.

Quoted 9 lines

A 64-bit inode number is supposed to be unique. Some file systems (most notably btrfs, but probably also various non-native file system) break and this, and get away with lots of userspace hacks papering over it. If you are on a 32-bit system and not using the LFS APIs stat will fail with -EOVERFLOW. Some file systems have options to never generate > 32bit inode numbers. None of that is directly related to file system size, although at least for XFS file system size is one relevant variable, but 200TB is in no way relevant.

My reference to the filesystem size was a quick and dirty estimate of when one may see more than 2^32 inodes on a single filesystem. What I failed to state (my apologies) is that this presumed an xfs filesystem with default values when creating the file system. (A quick check on an single 240TB xfs filesystem advised more than 5000000000 inodes were available).

#51 lore raw
Quoted 11 lines · Burn Alting
Quoted 4 lines
Quoted 2 lines

PATH records is no longer forensically defensible and it's use as a correlation item is of questionable value now?

What do you mean with forensically defensible?

If the auditd system only maintains a 32 bit variable for an inode value, when it emits an inode number, then how does one categorically state/defend that the inode value in the audit event is the actual one on the file system. The PATH record will offer one value (32 bits) but the returned inode value from a stat will return another (the actual 64 bit value). Basically auditd would not be recording the correct value.

Does auditd only track 32-bit inodes? If yes, it is fundamentally broken.

Quoted 5 lines

My reference to the filesystem size was a quick and dirty estimate of when one may see more than 2^32 inodes on a single filesystem. What I failed to state (my apologies) is that this presumed an xfs filesystem with default values when creating the file system. (A quick check on an single 240TB xfs filesystem advised more than 5000000000 inodes were available).

For XFS inode number encoding is sparse, with part of it encoding the allocation group it resides in. For btrfs for example the inode number is simply a 64-bit monotonically increasing counter per subvolume where freed inode numbers never get reused.

#52 lore raw
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Burn Alting
Quoted 4 lines
Quoted 2 lines

PATH records is no longer forensically defensible and it's use as a correlation item is of questionable value now?

What do you mean with forensically defensible?

If the auditd system only maintains a 32 bit variable for an inode value, when it emits an inode number, then how does one categorically state/defend that the inode value in the audit event is the actual one on the file system. The PATH record will offer one value (32 bits) but the returned inode value from a stat will return another (the actual 64 bit value). Basically auditd would not be recording the correct value.

Quoted 2 lines

Does auditd only track 32-bit inodes? If yes, it is fundamentally broken.

auditd logs 32-bit inodes on 32-bit architecture, whereas it should always log 64-bit inodes. The goal of this patch series is to fix this this issue for auditd and other kernel logs (and to backport these fixes).

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#54 lore raw
Quoted 154 lines · Burn Alting

On 13/10/24 21:17, Jeff Layton wrote:

Quoted 122 lines

On Fri, 2024-10-11 at 17:30 +0200, Mickaël Salaün wrote:

Quoted 84 lines

On Fri, Oct 11, 2024 at 07:39:33AM -0700, Christoph Hellwig wrote:

Quoted 45 lines

On Fri, Oct 11, 2024 at 03:52:42PM +0200, Mickaël Salaün wrote:

Quoted 26 lines

Quoted 13 lines

Quoted 9 lines

Yes, but how do you call getattr() without a path?

Quoted 9 lines

You don't because inode numbers are irrelevant without the path.

Quoted 10 lines

They are for kernel messages and audit logs. Please take a look at the use cases with the other patches.

Quoted 10 lines

It still is useless. E.g. btrfs has duplicate inode numbers due to subvolumes.

At least it reflects what users see.

Quoted 10 lines

If you want a better pretty but not useful value just work on making i_ino 64-bits wide, which is long overdue.

Quoted 11 lines

That would require too much work for me, and this would be a pain to backport to all stable kernels.

Would it though? Adding this new inode operation seems sub-optimal.

Inode numbers are static information. Once an inode number is set on an inode it basically never changes. This patchset will turn all of those direct inode->i_ino fetches into a pointer chase for the new inode operation, which will then almost always just result in a direct fetch.

A better solution here would be to make inode->i_ino a u64, and just fix up all of the places that touch it to expect that. Then, just ensure that all of the filesystems set it properly when instantiating new inodes. Even on 32-bit arch, you likely wouldn't need a seqcount loop or anything to fetch this since the chance of a torn read there is basically zero.

Quoted 10 lines

If there are places where we need to convert i_ino down to 32-bits, then we can just use some scheme like nfs_fattr_to_ino_t(), or just cast i_ino to a u32.

Yes, it'd be a larger patchset, but that seems like it would be a better solution.

Quoted 9 lines

As someone who lives in the analytical user space of Linux audit, I take it that for large (say >200TB) file systems, the inode reported in audit PATH records is no longer forensically defensible and it's use as a correlation item is of questionable value now?

It's been a while since I worked in audit, but if audit is only reporting 32-bit inode numbers in its records, then that could be ambiguous. It's easily possible on larger filesystems to generate more than 2^32 inodes.

Signature · 1 line
Jeff Layton <[email protected]>
#55 lore raw
In reply to Jeff Layton
Quoted 16 lines · Jeff Layton
Quoted 15 lines · Mickaël Salaün
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Mickaël Salaün
Quoted 3 lines
Quoted 1 line

Yes, but how do you call getattr() without a path?

You don't because inode numbers are irrelevant without the path.

They are for kernel messages and audit logs. Please take a look at the use cases with the other patches.

It still is useless. E.g. btrfs has duplicate inode numbers due to subvolumes.

At least it reflects what users see.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

If you want a better pretty but not useful value just work on making i_ino 64-bits wide, which is long overdue.

That would require too much work for me, and this would be a pain to backport to all stable kernels.

Would it though? Adding this new inode operation seems sub-optimal.

I agree.

Quoted 4 lines

Inode numbers are static information. Once an inode number is set on an inode it basically never changes. This patchset will turn all of those direct inode->i_ino fetches into a pointer chase for the new inode operation, which will then almost always just result in a direct fetch.

Yup.

Quoted 2 lines

A better solution here would be to make inode->i_ino a u64, and just fix up all of the places that touch it to expect that. Then, just

I would like us to try and see to make this happen. I really dislike that struct inode is full of non-explicity types.

#56 lore raw
Quoted 20 lines · Christian Brauner
Quoted 19 lines · Jeff Layton
Quoted 18 lines · Mickaël Salaün
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Mickaël Salaün
Quoted 3 lines
Quoted 1 line

Yes, but how do you call getattr() without a path?

You don't because inode numbers are irrelevant without the path.

They are for kernel messages and audit logs. Please take a look at the use cases with the other patches.

It still is useless. E.g. btrfs has duplicate inode numbers due to subvolumes.

At least it reflects what users see.

Quoted 3 lines

If you want a better pretty but not useful value just work on making i_ino 64-bits wide, which is long overdue.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

That would require too much work for me, and this would be a pain to backport to all stable kernels.

Would it though? Adding this new inode operation seems sub-optimal.

I agree.

Of course it would be better to fix the root of the issue. Who is up for the challenge?

Quoted 6 lines
Quoted 5 lines

Inode numbers are static information. Once an inode number is set on an inode it basically never changes. This patchset will turn all of those direct inode->i_ino fetches into a pointer chase for the new inode operation, which will then almost always just result in a direct fetch.

Quoted 7 lines

Yup.

Quoted 2 lines

A better solution here would be to make inode->i_ino a u64, and just fix up all of the places that touch it to expect that. Then, just

I would like us to try and see to make this happen. I really dislike that struct inode is full of non-explicity types.

Also, it would be OK to backport it, right?

maintainer
#57 lore raw
In reply to Christian Brauner
Quoted 4 lines · Christian Brauner
Quoted 3 lines · Jeff Layton
Quoted 2 lines · Mickaël Salaün
Quoted 1 line · Christoph Hellwig

On Fri, Oct 11, 2024 at 03:52:42PM +0200, Mickaël Salaün wrote:

...

Quoted 5 lines
Quoted 2 lines

A better solution here would be to make inode->i_ino a u64, and just fix up all of the places that touch it to expect that. Then, just

I would like us to try and see to make this happen. I really dislike that struct inode is full of non-explicity types.

Presumably this would include moving all of the filesystems to use inode->i_ino instead of their own private file ID number, e.g. the NFS issue pointed out in the original patch? If not, I think most of us in the LSM/audit space still have a need for a filesystem agnostic way to determine the inode number from an inode struct.

Signature · 1 line
paul-moore.com
#58 lore raw
In reply to Mickaël Salaün
kernel test robot noticed the following build errors:

Hi Mickaël,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on trondmy-nfs/linux-next pcmoore-selinux/next linus/master v6.12-rc3 next-20241011] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Micka-l-Sala-n/audit-Fix-inode-numbers/20241010-232916
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20241010152649.849254-1-mic%40digikod.net
patch subject: [RFC PATCH v1 1/7] fs: Add inode_get_ino() and implement get_ino() for NFS
config: x86_64-rhel-8.3 (https://download.01.org/0day-ci/archive/20241014/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241014/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

In file included from fs/nfs/client.c:47:

>> fs/nfs/internal.h:454:47: error: expected '{' before '*' token
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                               ^
>> fs/nfs/internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from fs/nfs/client.c:25:
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
   fs/nfs/client.c: In function 'nfs_free_client':
>> fs/nfs/client.c:244:9: error: implicit declaration of function 'nfs_local_disable'; did you mean 'nfs_local_probe'? [-Werror=implicit-function-declaration]
     244 |         nfs_local_disable(clp);
         |         ^~~~~~~~~~~~~~~~~
         |         nfs_local_probe
   cc1: some warnings being treated as errors
--
   In file included from fs/nfs/dir.c:46:
>> fs/nfs/internal.h:454:47: error: expected '{' before '*' token
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                               ^
>> fs/nfs/internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from fs/nfs/dir.c:32:
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
   fs/nfs/dir.c: In function 'nfs_do_filldir':
>> fs/nfs/dir.c:1107:46: warning: passing argument 1 of 'nfs_compat_user_ino64' makes pointer from integer without a cast [-Wint-conversion]
    1107 |                     nfs_compat_user_ino64(ent->ino), ent->d_type)) {
         |                                           ~~~^~~~~
         |                                              |
         |                                              u64 {aka long long unsigned int}
   fs/nfs/internal.h:454:48: note: expected 'const int *' but argument is of type 'u64' {aka 'long long unsigned int'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                  ~~~~~~~~~~~~~~^~~~~
--
   In file included from fs/nfs/file.c:37:
>> fs/nfs/internal.h:454:47: error: expected '{' before '*' token
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                               ^
>> fs/nfs/internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from fs/nfs/file.c:26:
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
--
   In file included from fs/nfs/inode.c:49:
>> fs/nfs/internal.h:454:47: error: expected '{' before '*' token
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                               ^
>> fs/nfs/internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from fs/nfs/inode.c:30:
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
>> fs/nfs/inode.c:91:40: error: expected '{' before '*' token
      91 | u64 nfs_compat_user_ino64(const struct *inode)
         |                                        ^
>> fs/nfs/inode.c:91:5: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
      91 | u64 nfs_compat_user_ino64(const struct *inode)
         |     ^~~~~~~~~~~~~~~~~~~~~
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
   fs/nfs/inode.c: In function 'nfs_compat_user_ino64':
>> fs/nfs/inode.c:98:33: error: passing argument 1 of 'NFS_FILEID' from incompatible pointer type [-Werror=incompatible-pointer-types]
      98 |         u64 fileid = NFS_FILEID(inode);
         |                                 ^~~~~
         |                                 |
         |                                 const int *
   include/linux/nfs_fs.h:369:52: note: expected 'const struct inode *' but argument is of type 'const int *'
     369 | static inline __u64 NFS_FILEID(const struct inode *inode)
         |                                ~~~~~~~~~~~~~~~~~~~~^~~~~
>> fs/nfs/inode.c:102:9: error: 'ino' undeclared (first use in this function); did you mean 'int'?
     102 |         ino = fileid;
         |         ^~~
         |         int
   fs/nfs/inode.c:102:9: note: each undeclared identifier is reported only once for each function it appears in
   In file included from include/linux/linkage.h:7,
                    from arch/x86/include/asm/cache.h:5,
                    from include/linux/cache.h:6,
                    from include/linux/time.h:5,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:13,
                    from fs/nfs/inode.c:17:
   fs/nfs/inode.c: At top level:
   fs/nfs/inode.c:107:19: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     107 | EXPORT_SYMBOL_GPL(nfs_compat_user_ino64);
         |                   ^~~~~~~~~~~~~~~~~~~~~
   include/linux/export.h:56:28: note: in definition of macro '__EXPORT_SYMBOL'
      56 |         extern typeof(sym) sym;                                 \
         |                            ^~~
   include/linux/export.h:69:41: note: in expansion of macro '_EXPORT_SYMBOL'
      69 | #define EXPORT_SYMBOL_GPL(sym)          _EXPORT_SYMBOL(sym, "GPL")
         |                                         ^~~~~~~~~~~~~~
   fs/nfs/inode.c:107:1: note: in expansion of macro 'EXPORT_SYMBOL_GPL'
     107 | EXPORT_SYMBOL_GPL(nfs_compat_user_ino64);
         | ^~~~~~~~~~~~~~~~~
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
   fs/nfs/inode.c: In function 'nfs_getattr':
>> fs/nfs/inode.c:986:43: warning: passing argument 1 of 'nfs_compat_user_ino64' makes pointer from integer without a cast [-Wint-conversion]
     986 |         stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
         |                                           ^~~~~~~~~~~~~~~~~
         |                                           |
         |                                           __u64 {aka long long unsigned int}
   fs/nfs/inode.c:107:19: note: expected 'const int *' but argument is of type '__u64' {aka 'long long unsigned int'}
     107 | EXPORT_SYMBOL_GPL(nfs_compat_user_ino64);
         |                   ^~~~~~~~~~~~~~~~~~~~~
   include/linux/export.h:56:28: note: in definition of macro '__EXPORT_SYMBOL'
      56 |         extern typeof(sym) sym;                                 \
         |                            ^~~
   include/linux/export.h:69:41: note: in expansion of macro '_EXPORT_SYMBOL'
      69 | #define EXPORT_SYMBOL_GPL(sym)          _EXPORT_SYMBOL(sym, "GPL")
         |                                         ^~~~~~~~~~~~~~
   fs/nfs/inode.c:107:1: note: in expansion of macro 'EXPORT_SYMBOL_GPL'
     107 | EXPORT_SYMBOL_GPL(nfs_compat_user_ino64);
         | ^~~~~~~~~~~~~~~~~
   fs/nfs/inode.c: In function 'nfs_compat_user_ino64':
>> fs/nfs/inode.c:106:1: warning: control reaches end of non-void function [-Wreturn-type]
     106 | }
         | ^
   cc1: some warnings being treated as errors
--
   In file included from fs/nfs/namespace.c:21:
>> fs/nfs/internal.h:454:47: error: expected '{' before '*' token
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                               ^
>> fs/nfs/internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from fs/nfs/namespace.c:16:
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
>> fs/nfs/namespace.c:235:27: error: initialization of 'u64 (*)(const struct inode *)' {aka 'long long unsigned int (*)(const struct inode *)'} from incompatible pointer type 'u64 (*)(const int *)' {aka 'long long unsigned int (*)(const int *)'} [-Werror=incompatible-pointer-types]

235 | .get_ino = nfs_compat_user_ino64,
| ^~~~~~~~~~~~~~~~~~~~~
fs/nfs/namespace.c:235:27: note: (near initialization for 'nfs_mountpoint_inode_operations.get_ino')
fs/nfs/namespace.c:241:27: error: initialization of 'u64 (*)(const struct inode *)' {aka 'long long unsigned int (*)(const struct inode *)'} from incompatible pointer type 'u64 (*)(const int *)' {aka 'long long unsigned int (*)(const int *)'} [-Werror=incompatible-pointer-types]
241 | .get_ino = nfs_compat_user_ino64,
| ^~~~~~~~~~~~~~~~~~~~~
fs/nfs/namespace.c:241:27: note: (near initialization for 'nfs_referral_inode_operations.get_ino')
cc1: some warnings being treated as errors
--
In file included from fs/nfs/nfs4proc.c:61:

>> fs/nfs/internal.h:454:47: error: expected '{' before '*' token
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                               ^
>> fs/nfs/internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from fs/nfs/nfs4proc.c:48:
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
   fs/nfs/nfs4proc.c: In function 'nfs4_proc_create_session':
   fs/nfs/nfs4proc.c:9462:19: warning: variable 'ptr' set but not used [-Wunused-but-set-variable]
    9462 |         unsigned *ptr;
         |                   ^~~
--
   In file included from fs/nfs/filelayout/filelayout.c:40:
>> fs/nfs/filelayout/../internal.h:454:47: error: expected '{' before '*' token
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                               ^
>> fs/nfs/filelayout/../internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from fs/nfs/filelayout/filelayout.c:32:
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
--
   In file included from fs/nfs/blocklayout/blocklayout.c:43:
>> fs/nfs/blocklayout/../internal.h:454:47: error: expected '{' before '*' token
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                               ^
>> fs/nfs/blocklayout/../internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from fs/nfs/blocklayout/../pnfs.h:34,
                    from fs/nfs/blocklayout/blocklayout.c:41:
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
--
   In file included from fs/nfs/flexfilelayout/flexfilelayout.c:22:
>> fs/nfs/flexfilelayout/../internal.h:454:47: error: expected '{' before '*' token
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                               ^
>> fs/nfs/flexfilelayout/../internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from fs/nfs/flexfilelayout/flexfilelayout.c:10:
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
   fs/nfs/flexfilelayout/flexfilelayout.c: In function 'ff_layout_io_track_ds_error':
   fs/nfs/flexfilelayout/flexfilelayout.c:1238:13: warning: variable 'err' set but not used [-Wunused-but-set-variable]
    1238 |         int err;
         |             ^~~
--
   In file included from fs/nfs/flexfilelayout/flexfilelayoutdev.c:15:
>> fs/nfs/flexfilelayout/../internal.h:454:47: error: expected '{' before '*' token
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                               ^
>> fs/nfs/flexfilelayout/../internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'; have 'u64(const int *)' {aka 'long long unsigned int(const int *)'}
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from fs/nfs/flexfilelayout/flexfilelayoutdev.c:10:
   include/linux/nfs_fs.h:448:12: note: previous declaration of 'nfs_compat_user_ino64' with type 'u64(u64)' {aka 'long long unsigned int(long long unsigned int)'}
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^~~~~~~~~~~~~~~~~~~~~
   fs/nfs/flexfilelayout/flexfilelayoutdev.c: In function 'nfs4_ff_alloc_deviceid_node':
   fs/nfs/flexfilelayout/flexfilelayoutdev.c:55:16: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
      55 |         int i, ret = -ENOMEM;
         |                ^~~

vim +454 fs/nfs/internal.h

440
441 /* inode.c */
442 extern struct workqueue_struct *nfsiod_workqueue;
443 extern struct workqueue_struct *nfslocaliod_workqueue;
444 extern struct inode *nfs_alloc_inode(struct super_block *sb);
445 extern void nfs_free_inode(struct inode *);
446 extern int nfs_write_inode(struct inode *, struct writeback_control *);
447 extern int nfs_drop_inode(struct inode *);
448 extern void nfs_clear_inode(struct inode *);
449 extern void nfs_evict_inode(struct inode *);
450 extern void nfs_zap_acl_cache(struct inode *inode);
451 extern void nfs_set_cache_invalid(struct inode *inode, unsigned long flags);
452 extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
453 extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);

 > 454	extern u64 nfs_compat_user_ino64(const struct *inode);

455

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#59 lore raw
In reply to Mickaël Salaün
kernel test robot noticed the following build errors:

Hi Mickaël,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on trondmy-nfs/linux-next pcmoore-selinux/next linus/master v6.12-rc3 next-20241011] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Micka-l-Sala-n/audit-Fix-inode-numbers/20241010-232916
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20241010152649.849254-1-mic%40digikod.net
patch subject: [RFC PATCH v1 1/7] fs: Add inode_get_ino() and implement get_ino() for NFS
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20241014/[email protected]/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241014/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

In file included from fs/nfs/client.c:47:

>> fs/nfs/internal.h:454:40: error: declaration of anonymous struct must be a definition
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                        ^
>> fs/nfs/internal.h:454:53: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                  ~~~~~              ^
         |                                  int
>> fs/nfs/internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^
   include/linux/nfs_fs.h:448:12: note: previous declaration is here
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^
   3 errors generated.
--
   In file included from fs/nfs/inode.c:49:
>> fs/nfs/internal.h:454:40: error: declaration of anonymous struct must be a definition
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                        ^
>> fs/nfs/internal.h:454:53: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                  ~~~~~              ^
         |                                  int
>> fs/nfs/internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^
   include/linux/nfs_fs.h:448:12: note: previous declaration is here
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^
>> fs/nfs/inode.c:91:33: error: declaration of anonymous struct must be a definition
      91 | u64 nfs_compat_user_ino64(const struct *inode)
         |                                 ^
>> fs/nfs/inode.c:91:46: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
      91 | u64 nfs_compat_user_ino64(const struct *inode)
         |                           ~~~~~              ^
         |                           int
>> fs/nfs/inode.c:91:5: error: conflicting types for 'nfs_compat_user_ino64'
      91 | u64 nfs_compat_user_ino64(const struct *inode)
         |     ^
   include/linux/nfs_fs.h:448:12: note: previous declaration is here
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^
>> fs/nfs/inode.c:91:46: warning: omitting the parameter name in a function definition is a C23 extension [-Wc23-extensions]
      91 | u64 nfs_compat_user_ino64(const struct *inode)
         |                                              ^
>> fs/nfs/inode.c:98:26: error: use of undeclared identifier 'inode'
      98 |         u64 fileid = NFS_FILEID(inode);
         |                                 ^
   1 warning and 7 errors generated.
--
   In file included from fs/nfs/namespace.c:21:
>> fs/nfs/internal.h:454:40: error: declaration of anonymous struct must be a definition
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                        ^
>> fs/nfs/internal.h:454:53: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                  ~~~~~              ^
         |                                  int
>> fs/nfs/internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^
   include/linux/nfs_fs.h:448:12: note: previous declaration is here
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^
>> fs/nfs/namespace.c:235:13: error: incompatible function pointer types initializing 'u64 (*)(const struct inode *)' (aka 'unsigned long long (*)(const struct inode *)') with an expression of type 'u64 (u64)' (aka 'unsigned long long (unsigned long long)') [-Wincompatible-function-pointer-types]

235 | .get_ino = nfs_compat_user_ino64,
| ^~~~~~~~~~~~~~~~~~~~~
fs/nfs/namespace.c:241:13: error: incompatible function pointer types initializing 'u64 (*)(const struct inode *)' (aka 'unsigned long long (*)(const struct inode *)') with an expression of type 'u64 (u64)' (aka 'unsigned long long (unsigned long long)') [-Wincompatible-function-pointer-types]
241 | .get_ino = nfs_compat_user_ino64,
| ^~~~~~~~~~~~~~~~~~~~~
5 errors generated.
--
In file included from fs/nfs/nfs4proc.c:61:

>> fs/nfs/internal.h:454:40: error: declaration of anonymous struct must be a definition
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                        ^
>> fs/nfs/internal.h:454:53: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                  ~~~~~              ^
         |                                  int
>> fs/nfs/internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^
   include/linux/nfs_fs.h:448:12: note: previous declaration is here
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^
   fs/nfs/nfs4proc.c:9462:12: warning: variable 'ptr' set but not used [-Wunused-but-set-variable]
    9462 |         unsigned *ptr;
         |                   ^
   1 warning and 3 errors generated.
--
   In file included from fs/nfs/filelayout/filelayout.c:40:
>> fs/nfs/filelayout/../internal.h:454:40: error: declaration of anonymous struct must be a definition
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                        ^
>> fs/nfs/filelayout/../internal.h:454:53: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                  ~~~~~              ^
         |                                  int
>> fs/nfs/filelayout/../internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^
   include/linux/nfs_fs.h:448:12: note: previous declaration is here
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^
   3 errors generated.
--
   In file included from fs/nfs/flexfilelayout/flexfilelayout.c:22:
>> fs/nfs/flexfilelayout/../internal.h:454:40: error: declaration of anonymous struct must be a definition
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                        ^
>> fs/nfs/flexfilelayout/../internal.h:454:53: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                  ~~~~~              ^
         |                                  int
>> fs/nfs/flexfilelayout/../internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^
   include/linux/nfs_fs.h:448:12: note: previous declaration is here
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^
   fs/nfs/flexfilelayout/flexfilelayout.c:1238:6: warning: variable 'err' set but not used [-Wunused-but-set-variable]
    1238 |         int err;
         |             ^
   1 warning and 3 errors generated.
--
   In file included from fs/nfs/flexfilelayout/flexfilelayoutdev.c:15:
>> fs/nfs/flexfilelayout/../internal.h:454:40: error: declaration of anonymous struct must be a definition
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                        ^
>> fs/nfs/flexfilelayout/../internal.h:454:53: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                  ~~~~~              ^
         |                                  int
>> fs/nfs/flexfilelayout/../internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^
   include/linux/nfs_fs.h:448:12: note: previous declaration is here
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^
   fs/nfs/flexfilelayout/flexfilelayoutdev.c:55:9: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
      55 |         int i, ret = -ENOMEM;
         |                ^
   1 warning and 3 errors generated.
--
   In file included from fs/nfs/blocklayout/blocklayout.c:43:
>> fs/nfs/blocklayout/../internal.h:454:40: error: declaration of anonymous struct must be a definition
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                        ^
>> fs/nfs/blocklayout/../internal.h:454:53: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |                                  ~~~~~              ^
         |                                  int
>> fs/nfs/blocklayout/../internal.h:454:12: error: conflicting types for 'nfs_compat_user_ino64'
     454 | extern u64 nfs_compat_user_ino64(const struct *inode);
         |            ^
   include/linux/nfs_fs.h:448:12: note: previous declaration is here
     448 | extern u64 nfs_compat_user_ino64(u64 fileid);
         |            ^
   fs/nfs/blocklayout/blocklayout.c:384:9: warning: variable 'count' set but not used [-Wunused-but-set-variable]
     384 |         size_t count = header->args.count;
         |                ^

1 warning and 3 errors generated.

vim +454 fs/nfs/internal.h

440
441 /* inode.c */
442 extern struct workqueue_struct *nfsiod_workqueue;
443 extern struct workqueue_struct *nfslocaliod_workqueue;
444 extern struct inode *nfs_alloc_inode(struct super_block *sb);
445 extern void nfs_free_inode(struct inode *);
446 extern int nfs_write_inode(struct inode *, struct writeback_control *);
447 extern int nfs_drop_inode(struct inode *);
448 extern void nfs_clear_inode(struct inode *);
449 extern void nfs_evict_inode(struct inode *);
450 extern void nfs_zap_acl_cache(struct inode *inode);
451 extern void nfs_set_cache_invalid(struct inode *inode, unsigned long flags);
452 extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
453 extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);

 > 454	extern u64 nfs_compat_user_ino64(const struct *inode);

455

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#60 lore raw
In reply to Mickaël Salaün
Quoted 10 lines · Mickaël Salaün

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().

I mean, you have to admit that this is a pretty blatant hack and that's not worthy of a separate inode method, let alone the potential performance implication that multiple people already brought up.

#61 lore raw
Quoted 8 lines · Christian Brauner
Quoted 7 lines · Mickaël Salaün

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.

Quoted 7 lines
Quoted 3 lines

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().

I mean, you have to admit that this is a pretty blatant hack and that's not worthy of a separate inode method, let alone the potential performance implication that multiple people already brought up.

My initial approach was to use u64 for struct inode's i_ino, but I realized it had too much implications on potentially all filesystems and other parts of the kernel. I'm sure they are much more legitimate folks to handle this transition. I'd be curious to know how such i_ino type change could be backported though.

#62 lore raw
In reply to Mickaël Salaün
Quoted 19 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>
Quoted 6 lines

---

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.

What are the other filesystems that are presumably affected by this that would need an inode accessor?

If this is just about NFS then just add a helper function that audit and whatever can call if they need to know the real inode number without forcing a new get_inode() method onto struct inode_operations.

I'm against adding a new inode_operations method unless we really have to because it means that we grow a nasty interface that filesystem can start using and we absolutely don't want them to.

And I don't buy that is suddenly rush hour for this. Seemingly no one noticed this in the past idk how many years.

Quoted 115 lines
---
 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(-)
fs/nfs/inode.c +4 -2
index 542c7d97b235..5dfc176b6d92 100644
@@ -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)
 {
fs/nfs/internal.h +1 -0
index 430733e3eff2..f5555a71a733 100644
@@ -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 */
fs/nfs/namespace.c +2 -0
index e7494cdd957e..d9b1e0606833 100644
@@ -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)
fs/stat.c +1 -1
index 41e598376d7e..05636919f94b 100644
@@ -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);
include/linux/fs.h +9 -0
index e3c603d01337..0eba09a21cf7 100644
@@ -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 *,
Signature · 1 line
2.46.1
maintainer
#63 lore raw
Quoted 23 lines · Christian Brauner
Quoted 21 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

Quoted 7 lines
Quoted 4 lines

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.

What are the other filesystems that are presumably affected by this that would need an inode accessor?

I don't want to speak for Mickaël, but my reading of the patchset was that he was suspecting that other filesystems had the same issue (privately maintained inode numbers) and was posting this as a RFC partly for clarity on this from the VFS developers such as yourself.

Quoted 3 lines

If this is just about NFS then just add a helper function that audit and whatever can call if they need to know the real inode number without forcing a new get_inode() method onto struct inode_operations.

If this really is just limited to NFS, or perhaps NFS and a small number of filesystems, then a a helper function is a reasonable solution. I think Mickaël was worried that private inode numbers would be more common, in which case a get_ino() method makes a bit more sense.

Quoted 1 line

And I don't buy that is suddenly rush hour for this.

I don't think Mickaël ever characterized this as a "rush hour" issue and I know I didn't. It definitely caught us by surprise to learn that inode->i_no wasn't always maintained, and we want to find a solution, but I'm not hearing anyone screaming for a solution "yesterday".

Quoted 1 line

Seemingly no one noticed this in the past idk how many years.

Yet the issue has been noticed and we would like to find a solution, one that is acceptable both to the VFS and LSM folks.

Can we start with compiling a list of filesystems that maintain their inode numbers outside of inode->i_no? NFS is obviously first on that list, are there others that the VFS devs can add?

Signature · 1 line
paul-moore.com
#64 lore raw
Quoted 66 lines · Paul Moore
Quoted 31 lines · Christian Brauner
Quoted 29 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

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

Quoted 7 lines
Quoted 3 lines

I guess there are other filesystems exposing inode numbers different
than inode->i_ino, and they should be patched too.

What are the other filesystems that are presumably affected by this that
would need an inode accessor?

I don't want to speak for Mickaël, but my reading of the patchset was that he was suspecting that other filesystems had the same issue (privately maintained inode numbers) and was posting this as a RFC partly for clarity on this from the VFS developers such as yourself.

Quoted 5 lines

If this is just about NFS then just add a helper function that audit and
whatever can call if they need to know the real inode number without
forcing a new get_inode() method onto struct inode_operations.

If this really is just limited to NFS, or perhaps NFS and a small number of filesystems, then a a helper function is a reasonable solution.  I think Mickaël was worried that private inode numbers would be more common, in which case a get_ino() method makes a bit more sense.

Quoted 1 line

And I don't buy that is suddenly rush hour for this.

I don't think Mickaël ever characterized this as a "rush hour" issue and I know I didn't.  It definitely caught us by surprise to learn that inode->i_no wasn't always maintained, and we want to find a solution, but I'm not hearing anyone screaming for a solution "yesterday".

Quoted 9 lines
Quoted 1 line

Seemingly no one noticed this in the past idk how many years.

Yet the issue has been noticed and we would like to find a solution, one that is acceptable both to the VFS and LSM folks.

Can we start with compiling a list of filesystems that maintain their inode numbers outside of inode->i_no?  NFS is obviously first on that list, are there others that the VFS devs can add?

Pretty much any filesystem that uses 64-bit inode numbers has the same
problem: if the application calls stat(), 32-bit glibc will happily convert that into a call to fstatat64() and then cry foul if the kernel dares return an inode number that doesn't fit in 32 bits.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
maintainer
#65 lore raw
Quoted 77 lines · Trond Myklebust
Quoted 66 lines · Paul Moore
Quoted 31 lines · Christian Brauner
Quoted 29 lines · Mickaël Salaün

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 <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jan Kara <[email protected]>

---

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

Quoted 7 lines
Quoted 3 lines

I guess there are other filesystems exposing inode numbers different
than inode->i_ino, and they should be patched too.

What are the other filesystems that are presumably affected by this that
would need an inode accessor?

I don't want to speak for Mickaël, but my reading of the patchset was that he was suspecting that other filesystems had the same issue (privately maintained inode numbers) and was posting this as a RFC partly for clarity on this from the VFS developers such as yourself.

Quoted 5 lines

If this is just about NFS then just add a helper function that audit and
whatever can call if they need to know the real inode number without
forcing a new get_inode() method onto struct inode_operations.

If this really is just limited to NFS, or perhaps NFS and a small number of filesystems, then a a helper function is a reasonable solution. I think Mickaël was worried that private inode numbers would be more common, in which case a get_ino() method makes a bit more sense.

Quoted 1 line

And I don't buy that is suddenly rush hour for this.

I don't think Mickaël ever characterized this as a "rush hour" issue and I know I didn't. It definitely caught us by surprise to learn that inode->i_no wasn't always maintained, and we want to find a solution, but I'm not hearing anyone screaming for a solution "yesterday".

Quoted 9 lines
Quoted 1 line

Seemingly no one noticed this in the past idk how many years.

Yet the issue has been noticed and we would like to find a solution, one that is acceptable both to the VFS and LSM folks.

Can we start with compiling a list of filesystems that maintain their inode numbers outside of inode->i_no? NFS is obviously first on that list, are there others that the VFS devs can add?

Quoted 4 lines

Pretty much any filesystem that uses 64-bit inode numbers has the same
problem: if the application calls stat(), 32-bit glibc will happily convert that into a call to fstatat64() and then cry foul if the kernel dares return an inode number that doesn't fit in 32 bits.

Okay, good to know, but I was hoping that there we could come up with an explicit list of filesystems that maintain their own private inode numbers outside of inode-i_ino.

Signature · 1 line
paul-moore.com
#66 lore raw
Quoted 3 lines · Paul Moore

Okay, good to know, but I was hoping that there we could come up with an explicit list of filesystems that maintain their own private inode numbers outside of inode-i_ino.

Anything using iget5_locked is a good start. Add to that file systems implementing their own inode cache (at least xfs and bcachefs).

maintainer
#67 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Paul Moore

Okay, good to know, but I was hoping that there we could come up with an explicit list of filesystems that maintain their own private inode numbers outside of inode-i_ino.

Anything using iget5_locked is a good start. Add to that file systems implementing their own inode cache (at least xfs and bcachefs).

Also good to know, thanks. However, at this point the lack of a clear answer is making me wonder a bit more about inode numbers in the view of VFS developers; do you folks care about inode numbers? I'm not asking to start an argument, it's a genuine question so I can get a better understanding about the durability and sustainability of inode->i_no. If all of you (the VFS folks) aren't concerned about inode numbers, I suspect we are going to have similar issues in the future and we (the LSM folks) likely need to move away from reporting inode numbers as they aren't reliably maintained by the VFS layer.

Signature · 1 line
paul-moore.com
#68 lore raw
Quoted 3 lines · Paul Moore

Also good to know, thanks. However, at this point the lack of a clear answer is making me wonder a bit more about inode numbers in the view of VFS developers; do you folks care about inode numbers?

The VFS itself does not care much about inode numbers. The Posix API does, although btrfs ignores that and seems to get away with that (mostly because applications put in btrfs-specific hacks). Various other non-native file systems that don't support real inodes numbers also get away with that, but usually the applications used on those file systems are very limited.

reviewer
#69 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Paul Moore

Also good to know, thanks. However, at this point the lack of a clear answer is making me wonder a bit more about inode numbers in the view of VFS developers; do you folks care about inode numbers?

The VFS itself does not care much about inode numbers. The Posix API does, although btrfs ignores that and seems to get away with that (mostly because applications put in btrfs-specific hacks).

Well, btrfs plays tricks with *device* numbers, right? Exactly so that st_ino + st_dev actually stay unique for each file. Whether it matters for audit I don't dare to say :). Bcachefs does not care and returns non-unique inode numbers.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#70 lore raw
Quoted 6 lines · Jan Kara
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Paul Moore

Also good to know, thanks. However, at this point the lack of a clear answer is making me wonder a bit more about inode numbers in the view of VFS developers; do you folks care about inode numbers?

Quoted 8 lines
Quoted 3 lines

The VFS itself does not care much about inode numbers. The Posix API does, although btrfs ignores that and seems to get away with that (mostly because applications put in btrfs-specific hacks).

Well, btrfs plays tricks with *device* numbers, right? Exactly so that st_ino + st_dev actually stay unique for each file. Whether it matters for audit I don't dare to say :). Bcachefs does not care and returns non-unique inode numbers.

But st_ino + st_dev is the only thing Posix and thus historically Linux has guaranteed to applications. So if st_dev is unique, but you need an unknown scope in which it is unique it might as well not be for that purpose. And I think for any kind of audit report that is true as well.

#71 lore raw
In reply to Jan Kara
Quoted 6 lines · Jan Kara
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Paul Moore

Also good to know, thanks. However, at this point the lack of a clear answer is making me wonder a bit more about inode numbers in the view of VFS developers; do you folks care about inode numbers?

Quoted 6 lines
Quoted 3 lines

The VFS itself does not care much about inode numbers. The Posix API does, although btrfs ignores that and seems to get away with that (mostly because applications put in btrfs-specific hacks).

Well, btrfs plays tricks with *device* numbers, right? Exactly so that st_ino + st_dev actually stay unique for each file. Whether it matters for

Yes.

Quoted 2 lines

audit I don't dare to say :). Bcachefs does not care and returns non-unique inode numbers.

Userspace can now easily disambiguate them via STATX_SUBVOL.

maintainer
#72 lore raw
In reply to Paul Moore
Quoted 9 lines · Paul Moore
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Paul Moore

Okay, good to know, but I was hoping that there we could come up with an explicit list of filesystems that maintain their own private inode numbers outside of inode-i_ino.

Anything using iget5_locked is a good start. Add to that file systems implementing their own inode cache (at least xfs and bcachefs).

Quoted 10 lines

Also good to know, thanks. However, at this point the lack of a clear answer is making me wonder a bit more about inode numbers in the view of VFS developers; do you folks care about inode numbers? I'm not asking to start an argument, it's a genuine question so I can get a better understanding about the durability and sustainability of inode->i_no. If all of you (the VFS folks) aren't concerned about inode numbers, I suspect we are going to have similar issues in the future and we (the LSM folks) likely need to move away from reporting inode numbers as they aren't reliably maintained by the VFS layer.

Like Christoph said, the kernel doesn't care much about inode numbers.

People care about them though, and sometimes we have things in the kernel that report them in some fashion (tracepoints, procfiles, audit events, etc.). Having those match what the userland stat() st_ino field tells you is ideal, and for the most part that's the way it works.

The main exception is when people use 32-bit interfaces (somewhat rare these days), or they have a 32-bit kernel with a filesystem that has a 64-bit inode number space (NFS being one of those). The NFS client has basically hacked around this for years by tracking its own fileid field in its inode. That's really a waste though. That could be converted over to use i_ino instead if it were always wide enough.

It'd be better to stop with these sort of hacks and just fix this the right way once and for all, by making i_ino 64 bits everywhere.

A lot of the changes can probably be automated via coccinelle. I'd probably start by turning all of the direct i_ino accesses into static inline wrapper function calls. The hard part will be parceling out that work into digestable chunks. If you can avoid "flag day" changes, then that's ideal. You'd want a patch per subsystem so you can collect ACKs.

The hardest part will probably be the format string changes. I'm not sure you can easily use coccinelle for that, so that may need to be done by hand or scripted with python or something.

Signature · 1 line
Jeff Layton <[email protected]>
#73 lore raw
Quoted 49 lines · Jeff Layton
Quoted 13 lines · Paul Moore
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Paul Moore

Okay, good to know, but I was hoping that there we could come up with
an explicit list of filesystems that maintain their own private inode
numbers outside of inode-i_ino.

Anything using iget5_locked is a good start.  Add to that file systems
implementing their own inode cache (at least xfs and bcachefs).

Quoted 13 lines

Also good to know, thanks.  However, at this point the lack of a clear
answer is making me wonder a bit more about inode numbers in the view
of VFS developers; do you folks care about inode numbers?  I'm not asking to start an argument, it's a genuine question so I can get a better understanding about the durability and sustainability of inode->i_no.  If all of you (the VFS folks) aren't concerned about inode numbers, I suspect we are going to have similar issues in the future and we (the LSM folks) likely need to move away from reporting
inode numbers as they aren't reliably maintained by the VFS layer.

Like Christoph said, the kernel doesn't care much about inode numbers.

People care about them though, and sometimes we have things in the kernel that report them in some fashion (tracepoints, procfiles, audit
events, etc.). Having those match what the userland stat() st_ino field
tells you is ideal, and for the most part that's the way it works.

The main exception is when people use 32-bit interfaces (somewhat rare
these days), or they have a 32-bit kernel with a filesystem that has a
64-bit inode number space (NFS being one of those). The NFS client has
basically hacked around this for years by tracking its own fileid field
in its inode. That's really a waste though. That could be converted over to use i_ino instead if it were always wide enough.

Quoted 2 lines

It'd be better to stop with these sort of hacks and just fix this the right way once and for all, by making i_ino 64 bits everywhere.

Nope.

That won't fix glibc, which is the main problem NFS has to work around.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
maintainer
#74 lore raw
Quoted 50 lines · Trond Myklebust
Quoted 49 lines · Jeff Layton
Quoted 13 lines · Paul Moore
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Paul Moore

Okay, good to know, but I was hoping that there we could come up with
an explicit list of filesystems that maintain their own private inode
numbers outside of inode-i_ino.

Anything using iget5_locked is a good start.  Add to that file systems
implementing their own inode cache (at least xfs and bcachefs).

Quoted 13 lines

Also good to know, thanks.  However, at this point the lack of a clear
answer is making me wonder a bit more about inode numbers in the view
of VFS developers; do you folks care about inode numbers?  I'm not asking to start an argument, it's a genuine question so I can get a better understanding about the durability and sustainability of inode->i_no.  If all of you (the VFS folks) aren't concerned about inode numbers, I suspect we are going to have similar issues in the future and we (the LSM folks) likely need to move away from reporting
inode numbers as they aren't reliably maintained by the VFS layer.

Like Christoph said, the kernel doesn't care much about inode numbers.

People care about them though, and sometimes we have things in the kernel that report them in some fashion (tracepoints, procfiles, audit
events, etc.). Having those match what the userland stat() st_ino field
tells you is ideal, and for the most part that's the way it works.

The main exception is when people use 32-bit interfaces (somewhat rare
these days), or they have a 32-bit kernel with a filesystem that has a
64-bit inode number space (NFS being one of those). The NFS client has
basically hacked around this for years by tracking its own fileid field
in its inode. That's really a waste though. That could be converted over to use i_ino instead if it were always wide enough.

Quoted 7 lines
Quoted 2 lines

It'd be better to stop with these sort of hacks and just fix this the right way once and for all, by making i_ino 64 bits everywhere.

Nope.

That won't fix glibc, which is the main problem NFS has to work around.

True, but that's really a separate problem.

It also doesn't inform how we track inode numbers inside the kernel. Inode numbers have been 64 bits for years on "real" filesystems. If we were designing this today, i_ino would be a u64, and we'd only hash that down to 32 bits when necessary.

Signature · 1 line
Jeff Layton <[email protected]>
#75 lore raw
Quoted 71 lines · Jeff Layton
Quoted 70 lines · Trond Myklebust
Quoted 68 lines · Jeff Layton
Quoted 28 lines · Paul Moore
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Paul Moore

Okay, good to know, but I was hoping that there we could come
up with
an explicit list of filesystems that maintain their own private
inode
numbers outside of inode-i_ino.

Quoted 5 lines

Anything using iget5_locked is a good start.  Add to that file
systems
implementing their own inode cache (at least xfs and bcachefs).

Also good to know, thanks.  However, at this point the lack of a
clear
answer is making me wonder a bit more about inode numbers in the
view
of VFS developers; do you folks care about inode numbers?  I'm not
asking to start an argument, it's a genuine question so I can get a
better understanding about the durability and sustainability of

Quoted 9 lines

inode->i_no.  If all of you (the VFS folks) aren't concerned about
inode numbers, I suspect we are going to have similar issues in the
future and we (the LSM folks) likely need to move away from reporting
inode numbers as they aren't reliably maintained by the VFS layer.

Like Christoph said, the kernel doesn't care much about inode numbers.

People care about them though, and sometimes we have things in the
kernel that report them in some fashion (tracepoints, procfiles, audit
events, etc.). Having those match what the userland stat() st_ino field
tells you is ideal, and for the most part that's the way it works.

The main exception is when people use 32-bit interfaces (somewhat rare
these days), or they have a 32-bit kernel with a filesystem that has
a
64-bit inode number space (NFS being one of those). The NFS client
has
basically hacked around this for years by tracking its own fileid field
in its inode. That's really a waste though. That could be converted
over to use i_ino instead if it were always wide enough.

It'd be better to stop with these sort of hacks and just fix this the
right way once and for all, by making i_ino 64 bits everywhere.

Quoted 7 lines
Quoted 5 lines

Nope.

That won't fix glibc, which is the main problem NFS has to work around.

True, but that's really a separate problem.

Currently, the problem where the kernel needs to use one inode number in iget5() and a different one when replying to stat() is limited to the set of 64-bit kernels that can operate in 32-bit userland compability mode. So mainly on x86_64 kernels that are set up to run in i386 userland compatibility mode.

If you now decree that all kernels will use 64-bit inode numbers internally, then you've suddenly expanded the problem to encompass all the remaining 32-bit kernels. In order to avoid stat() returning EOVERFLOW to the applications, they too will have to start generating separate 32-bit inode numbers.

Quoted 6 lines

It also doesn't inform how we track inode numbers inside the kernel. Inode numbers have been 64 bits for years on "real" filesystems. If we
were designing this today, i_ino would be a u64, and we'd only hash that down to 32 bits when necessary.

"I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones."

History is a bitch...

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#76 lore raw
In reply to Trond Myklebust
Quoted 6 lines · Trond Myklebust
Quoted 2 lines

It'd be better to stop with these sort of hacks and just fix this the right way once and for all, by making i_ino 64 bits everywhere.

Nope.

That won't fix glibc, which is the main problem NFS has to work around.

There's no Problem in glibc here, it's mostly the Linux syscall layer being stupid for the 32-bit non-LFS interface.

That being said with my XFS hat on we've not really had issue with 32-bit non-LFS code for a long time. Not saying it doesn't exist, but it's probably limited to retro computing by now. The way we support it is with the inode32 option that never allocates larger inode numbers. I think something similar should work for NFS where an option is required for the ino mangling.

maintainer
#77 lore raw
In reply to Jeff Layton
Quoted 28 lines · Jeff Layton
Quoted 9 lines · Paul Moore
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Paul Moore

Okay, good to know, but I was hoping that there we could come up with an explicit list of filesystems that maintain their own private inode numbers outside of inode-i_ino.

Anything using iget5_locked is a good start. Add to that file systems implementing their own inode cache (at least xfs and bcachefs).

Quoted 10 lines

Also good to know, thanks. However, at this point the lack of a clear answer is making me wonder a bit more about inode numbers in the view of VFS developers; do you folks care about inode numbers? I'm not asking to start an argument, it's a genuine question so I can get a better understanding about the durability and sustainability of inode->i_no. If all of you (the VFS folks) aren't concerned about inode numbers, I suspect we are going to have similar issues in the future and we (the LSM folks) likely need to move away from reporting inode numbers as they aren't reliably maintained by the VFS layer.

Like Christoph said, the kernel doesn't care much about inode numbers.

People care about them though, and sometimes we have things in the kernel that report them in some fashion (tracepoints, procfiles, audit events, etc.). Having those match what the userland stat() st_ino field tells you is ideal, and for the most part that's the way it works.

Quoted 5 lines

The main exception is when people use 32-bit interfaces (somewhat rare these days), or they have a 32-bit kernel with a filesystem that has a 64-bit inode number space (NFS being one of those). The NFS client has basically hacked around this for years by tracking its own fileid field in its inode.

When I asked if the VFS dev cared about inode numbers this is more of what I was wondering about. Regardless of if the kernel itself uses inode numbers for anything, it does appear that users do care about inode numbers to some extent, and I wanted to know if the VFS devs viewed the inode numbers as a first order UAPI interface/thing, or if it was of lesser importance and not something the kernel was going to provide much of a guarantee around. Once again, I'm not asking this to start a war, I'm just trying to get some perspective from the VFS dev side of things.

Quoted 10 lines

A lot of the changes can probably be automated via coccinelle. I'd probably start by turning all of the direct i_ino accesses into static inline wrapper function calls. The hard part will be parceling out that work into digestable chunks. If you can avoid "flag day" changes, then that's ideal. You'd want a patch per subsystem so you can collect ACKs.

The hardest part will probably be the format string changes. I'm not sure you can easily use coccinelle for that, so that may need to be done by hand or scripted with python or something.

Out of curiosity, is this on anyone's roadmap? I've already got enough work in security land to keep myself occupied until I'm hit by that mythical bus, so I can't volunteer in good conscience, but I (and many others in security land) would be grateful for a single, consistent way to fetch inode numbers :)

Signature · 1 line
paul-moore.com
reviewer
#78 lore raw
Quoted 35 lines · Paul Moore
Quoted 28 lines · Jeff Layton
Quoted 9 lines · Paul Moore
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Paul Moore

Okay, good to know, but I was hoping that there we could come up with an explicit list of filesystems that maintain their own private inode numbers outside of inode-i_ino.

Anything using iget5_locked is a good start. Add to that file systems implementing their own inode cache (at least xfs and bcachefs).

Quoted 10 lines

Also good to know, thanks. However, at this point the lack of a clear answer is making me wonder a bit more about inode numbers in the view of VFS developers; do you folks care about inode numbers? I'm not asking to start an argument, it's a genuine question so I can get a better understanding about the durability and sustainability of inode->i_no. If all of you (the VFS folks) aren't concerned about inode numbers, I suspect we are going to have similar issues in the future and we (the LSM folks) likely need to move away from reporting inode numbers as they aren't reliably maintained by the VFS layer.

Like Christoph said, the kernel doesn't care much about inode numbers.

People care about them though, and sometimes we have things in the kernel that report them in some fashion (tracepoints, procfiles, audit events, etc.). Having those match what the userland stat() st_ino field tells you is ideal, and for the most part that's the way it works.

Quoted 5 lines

The main exception is when people use 32-bit interfaces (somewhat rare these days), or they have a 32-bit kernel with a filesystem that has a 64-bit inode number space (NFS being one of those). The NFS client has basically hacked around this for years by tracking its own fileid field in its inode.

Quoted 9 lines

When I asked if the VFS dev cared about inode numbers this is more of what I was wondering about. Regardless of if the kernel itself uses inode numbers for anything, it does appear that users do care about inode numbers to some extent, and I wanted to know if the VFS devs viewed the inode numbers as a first order UAPI interface/thing, or if it was of lesser importance and not something the kernel was going to provide much of a guarantee around. Once again, I'm not asking this to start a war, I'm just trying to get some perspective from the VFS dev side of things.

Well, we do care to not break our users. So our opinion about "first order UAPI" doesn't matter that much. If userspace is using it, we have to avoid breaking it. And there definitely is userspace depending on st_ino + st_dev being unique identifier of a file / directory so we want to maintain that as much as possible (at least as long as there's userspace depending on it which I don't see changing in the near future).

That being said historically people have learned NFS has its quirks, similarly as btrfs needing occasionally a special treatment and adapted to it, bcachefs is new enough that userspace didn't notice yet, that's going to be interesting.

There's another aspect that even 64-bits start to be expensive to pack things into for some filesystems (either due to external protocol constraints such as for AFS or due to the combination of features such as subvolumes, snapshotting, etc.). Going to 128-bits for everybody seems like a waste so at last LSF summit we've discussed about starting to push file handles (output of name_to_handle_at(2)) as a replacement of st_ino for file/dir identifier in a filesystem. For the kernel this would be convenient because each filesystem can pack there what it needs. But userspace guys were not thrilled by this (mainly due to the complexities of dynamically sized identifier and passing it around). So this transition isn't currently getting much traction and we'll see how things evolve.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#79 lore raw
Quoted 58 lines · Jan Kara
Quoted 35 lines · Paul Moore
Quoted 28 lines · Jeff Layton
Quoted 9 lines · Paul Moore
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Paul Moore

Okay, good to know, but I was hoping that there we could come up with an explicit list of filesystems that maintain their own private inode numbers outside of inode-i_ino.

Anything using iget5_locked is a good start. Add to that file systems implementing their own inode cache (at least xfs and bcachefs).

Quoted 10 lines

Also good to know, thanks. However, at this point the lack of a clear answer is making me wonder a bit more about inode numbers in the view of VFS developers; do you folks care about inode numbers? I'm not asking to start an argument, it's a genuine question so I can get a better understanding about the durability and sustainability of inode->i_no. If all of you (the VFS folks) aren't concerned about inode numbers, I suspect we are going to have similar issues in the future and we (the LSM folks) likely need to move away from reporting inode numbers as they aren't reliably maintained by the VFS layer.

Like Christoph said, the kernel doesn't care much about inode numbers.

People care about them though, and sometimes we have things in the kernel that report them in some fashion (tracepoints, procfiles, audit events, etc.). Having those match what the userland stat() st_ino field tells you is ideal, and for the most part that's the way it works.

Quoted 5 lines

The main exception is when people use 32-bit interfaces (somewhat rare these days), or they have a 32-bit kernel with a filesystem that has a 64-bit inode number space (NFS being one of those). The NFS client has basically hacked around this for years by tracking its own fileid field in its inode.

Quoted 9 lines

When I asked if the VFS dev cared about inode numbers this is more of what I was wondering about. Regardless of if the kernel itself uses inode numbers for anything, it does appear that users do care about inode numbers to some extent, and I wanted to know if the VFS devs viewed the inode numbers as a first order UAPI interface/thing, or if it was of lesser importance and not something the kernel was going to provide much of a guarantee around. Once again, I'm not asking this to start a war, I'm just trying to get some perspective from the VFS dev side of things.

Well, we do care to not break our users. So our opinion about "first order UAPI" doesn't matter that much. If userspace is using it, we have to avoid breaking it. And there definitely is userspace depending on st_ino + st_dev being unique identifier of a file / directory so we want to maintain that as much as possible (at least as long as there's userspace depending on it which I don't see changing in the near future).

That being said historically people have learned NFS has its quirks, similarly as btrfs needing occasionally a special treatment and adapted to it, bcachefs is new enough that userspace didn't notice yet, that's going to be interesting.

Quoted 11 lines

There's another aspect that even 64-bits start to be expensive to pack things into for some filesystems (either due to external protocol constraints such as for AFS or due to the combination of features such as subvolumes, snapshotting, etc.). Going to 128-bits for everybody seems like a waste so at last LSF summit we've discussed about starting to push file handles (output of name_to_handle_at(2)) as a replacement of st_ino for file/dir identifier in a filesystem. For the kernel this would be convenient because each filesystem can pack there what it needs. But userspace guys were not thrilled by this (mainly due to the complexities of dynamically sized identifier and passing it around). So this transition isn't currently getting much traction and we'll see how things evolve.

It's also not an answer for every filesystem. For example, you don't want to use file handles for pidfds when you are guaranteed that the inode numbers will be unique. So file handles will not be used for that where a simple statx() and comparing inode numbers can do.

#80 lore raw
In reply to Jeff Layton
Quoted 45 lines · Jeff Layton
Quoted 9 lines · Paul Moore
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Paul Moore

Okay, good to know, but I was hoping that there we could come up with an explicit list of filesystems that maintain their own private inode numbers outside of inode-i_ino.

Anything using iget5_locked is a good start. Add to that file systems implementing their own inode cache (at least xfs and bcachefs).

Quoted 10 lines

Also good to know, thanks. However, at this point the lack of a clear answer is making me wonder a bit more about inode numbers in the view of VFS developers; do you folks care about inode numbers? I'm not asking to start an argument, it's a genuine question so I can get a better understanding about the durability and sustainability of inode->i_no. If all of you (the VFS folks) aren't concerned about inode numbers, I suspect we are going to have similar issues in the future and we (the LSM folks) likely need to move away from reporting inode numbers as they aren't reliably maintained by the VFS layer.

Like Christoph said, the kernel doesn't care much about inode numbers.

People care about them though, and sometimes we have things in the kernel that report them in some fashion (tracepoints, procfiles, audit events, etc.). Having those match what the userland stat() st_ino field tells you is ideal, and for the most part that's the way it works.

The main exception is when people use 32-bit interfaces (somewhat rare these days), or they have a 32-bit kernel with a filesystem that has a 64-bit inode number space (NFS being one of those). The NFS client has basically hacked around this for years by tracking its own fileid field in its inode. That's really a waste though. That could be converted over to use i_ino instead if it were always wide enough.

It'd be better to stop with these sort of hacks and just fix this the right way once and for all, by making i_ino 64 bits everywhere.

A lot of the changes can probably be automated via coccinelle. I'd probably start by turning all of the direct i_ino accesses into static inline wrapper function calls. The hard part will be parceling out that work into digestable chunks. If you can avoid "flag day" changes, then that's ideal. You'd want a patch per subsystem so you can collect ACKs.

Quoted 3 lines

The hardest part will probably be the format string changes. I'm not sure you can easily use coccinelle for that, so that may need to be done by hand or scripted with python or something.

The problem where we're dealing with 64 bit inode numbers even on 32 bit systems is one problem and porting struct inode to use a 64 bit type for i_ino is a good thing that I agree we should explore.

I'm still not sure how that would stolve the audit problem though. The inode numbers that audit reports, even if always 64 bit, are not unique with e.g., btrfs and bcachefs. Audit would need to report additional information for both filesystems like the subvolume number which would make this consistent.

We should port to 64 bit and yes that'll take some time. Then audit may want to grow support to report additional information such as the subvolume number. And that can be done in various ways without having to burden struct inode_operations with any of this. Or, document the 20 year reality that audit inode numbers aren't unique on some filesystems.

#81 lore raw
In reply to Christian Brauner
Quoted 2 lines · Christian Brauner

And I don't buy that is suddenly rush hour for this. Seemingly no one noticed this in the past idk how many years.

Asuming this showed up with the initial import of kernel/audit.c that would be more than 20 years.