Skip to contentSkip to conversation

inode01: Use uint64_t to prevent inode truncation on 32-bit

PATCH Superseded Wake Liu via ltp 2 participants 6 messages Aug 7 – Aug 10

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 inode01: Use uint64_t to prevent inode truncation on 32-bit

On 32-bit architectures, ino_t is typically 32-bit, whereas the kernel and struct stat may support 64-bit inode numbers (e.g. st_ino is unsigned long long).

The conversion of inode01 to the new API introduced tracking of inodes in an array of struct inode_info, which used ino_t. This causes 64-bit inode numbers to be truncated to 32-bit when running as a 32-bit binary on a filesystem that uses 64-bit inodes.

This truncation can lead to false duplicate inode reports and test failures.

Fix this by using uint64_t for tracking inode numbers throughout the test.

---
 testcases/kernel/fs/inode/inode01.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/fs/inode/inode01.c +3 -3
index 2816ad61a..d41ff2c62 100644
@@ -36,7 +36,7 @@ static struct tcase {
 };
 
 struct inode_info {
-	ino_t ino;
+	uint64_t ino;
 	char path[PATH_MAX];
 };
 
@@ -74,7 +74,7 @@ static void record_inode(struct inode_info *inodes, unsigned int idx,
 	snprintf(inodes[idx].path, sizeof(inodes[idx].path), "%s", path);
 }
 
-static ino_t verify_file(const struct tcase *tc, const char *path)
+static uint64_t verify_file(const struct tcase *tc, const char *path)
 {
 	char buf[PATH_MAX];
 	char extra;
@@ -128,7 +128,7 @@ static void verify_tree(const struct tcase *tc, const char *parent,
 	for (i = 0; i < tc->fanout; i++, create_file = !create_file) {
 		char path[PATH_MAX];
 		unsigned int my_id;
-		ino_t ino;
+		uint64_t ino;
 
 		snprintf(path, sizeof(path), "%s/%08u", parent, ++*id);
 
Signature · 5 lines
2.55.0.654.g21b8a5bc05-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Wake,

Quoted 10 lines · Wake Liu

inode01: Use uint64_t to prevent inode truncation on 32-bit

struct inode_info {

(quoted diff) +1 -1
-	ino_t ino;
+	uint64_t ino;
	char path[PATH_MAX];
};

static void record_inode(struct inode_info *inodes, unsigned int idx,
const char *path, ino_t ino)

Could the record_inode() parameter also be changed to uint64_t? Every inode collected by verify_tree() passes through this parameter, so on the 32-bit ABI described in the commit message the value is still truncated before it is assigned to the new uint64_t field.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH v2 1/1 inode01: Use uint64_t to prevent inode truncation on 32-bit

In reply to Wake Liu via ltp

On 32-bit architectures, ino_t is typically 32-bit, whereas the kernel and struct stat may support 64-bit inode numbers (e.g. st_ino is unsigned long long).

The conversion of inode01 to the new API introduced tracking of inodes in an array of struct inode_info, which used ino_t. This causes 64-bit inode numbers to be truncated to 32-bit when running as a 32-bit binary on a filesystem that uses 64-bit inodes.

This truncation can lead to false duplicate inode reports and test failures.

Fix this by using uint64_t for tracking inode numbers throughout the test.

---
v1 -> v2:
- Also change record_inode() parameter type to uint64_t to prevent truncation before assignment.

 testcases/kernel/fs/inode/inode01.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
testcases/kernel/fs/inode/inode01.c +4 -4
index 2816ad61a..50b5311a4 100644
@@ -36,7 +36,7 @@ static struct tcase {
 };
 
 struct inode_info {
-	ino_t ino;
+	uint64_t ino;
 	char path[PATH_MAX];
 };
 
@@ -68,13 +68,13 @@ static void create_tree(const struct tcase *tc, const char *parent,
 }
 
 static void record_inode(struct inode_info *inodes, unsigned int idx,
-			 const char *path, ino_t ino)
+			 const char *path, uint64_t ino)
 {
 	inodes[idx].ino = ino;
 	snprintf(inodes[idx].path, sizeof(inodes[idx].path), "%s", path);
 }
 
-static ino_t verify_file(const struct tcase *tc, const char *path)
+static uint64_t verify_file(const struct tcase *tc, const char *path)
 {
 	char buf[PATH_MAX];
 	char extra;
@@ -128,7 +128,7 @@ static void verify_tree(const struct tcase *tc, const char *parent,
 	for (i = 0; i < tc->fanout; i++, create_file = !create_file) {
 		char path[PATH_MAX];
 		unsigned int my_id;
-		ino_t ino;
+		uint64_t ino;
 
 		snprintf(path, sizeof(path), "%s/%08u", parent, ++*id);
 
Signature · 5 lines
2.55.0.654.g21b8a5bc05-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Wake,

Quoted 1 line · Wake Liu

inode01: Use uint64_t to prevent inode truncation on 32-bit

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp