Forwarded: [PATCH] ntfs3: add debug warnings for run_lock initialization

syzbot posted 1 patch 2 months ago
fs/ntfs3/file.c  |   1 +
fs/ntfs3/inode.c | 115 +++++++++++++++++++++++++++++++++++------------
2 files changed, 87 insertions(+), 29 deletions(-)
Forwarded: [PATCH] ntfs3: add debug warnings for run_lock initialization
Posted by syzbot 2 months ago
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] ntfs3: add debug warnings for run_lock initialization
Author: kartikey406@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master


Add debug messages to track when run_lock is initialized for regular
files to help diagnose lockdep warnings.

Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
 fs/ntfs3/file.c  |   1 +
 fs/ntfs3/inode.c | 115 +++++++++++++++++++++++++++++++++++------------
 2 files changed, 87 insertions(+), 29 deletions(-)

diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
index 4c90ec2fa2ea..0eb218a2b999 100644
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -773,6 +773,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
 int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 		 struct iattr *attr)
 {
+	printk(KERN_WARNING "ntfs_setattr: testing by deepanshu \n");
 	struct inode *inode = d_inode(dentry);
 	struct ntfs_inode *ni = ntfs_i(inode);
 	u32 ia_valid = attr->ia_valid;
diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index 3959f23c487a..d5fe133f8845 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0
+// Created regular file inode// SPDX-License-Identifier: GPL-2.0
 /*
  *
  * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
@@ -50,10 +50,17 @@ static struct inode *ntfs_read_mft(struct inode *inode,
 	/* Setup 'uid' and 'gid' */
 	inode->i_uid = sbi->options->fs_uid;
 	inode->i_gid = sbi->options->fs_gid;
-
+	
+	if (ino == 25) {
+		printk(KERN_ERR "DEEPANSHU: ntfs_read_mft ENTERED for inode 25\n");
+	}
+	
 	err = mi_init(&ni->mi, sbi, ino);
-	if (err)
+	if (err) {
+		if (ino == 25)
+			printk(KERN_ERR "DEEPANSHU: inode 25 - mi_init FAILED, err=%d\n", err);
 		goto out;
+	}
 
 	if (!sbi->mft.ni && ino == MFT_REC_MFT && !sb->s_root) {
 		t64 = sbi->mft.lbo >> sbi->cluster_bits;
@@ -407,8 +414,14 @@ static struct inode *ntfs_read_mft(struct inode *inode,
 
 end_enum:
 
-	if (!std5)
+	if (ino == 25)
+		printk(KERN_ERR "DEEPANSHU: inode 25 reached end_enum, mode=0%o\n", mode);
+
+	if (!std5) {
+		if (ino == 25)
+			printk(KERN_ERR "DEEPANSHU: inode 25 - NO std5, going to out\n");
 		goto out;
+	}
 
 	if (is_bad_inode(inode))
 		goto out;
@@ -436,6 +449,8 @@ static struct inode *ntfs_read_mft(struct inode *inode,
 	set_nlink(inode, links);
 
 	if (S_ISDIR(mode)) {
+		if (ino == 25)
+			printk(KERN_ERR "DEEPANSHU: inode 25 is DIR\n");
 		ni->std_fa |= FILE_ATTRIBUTE_DIRECTORY;
 
 		/*
@@ -449,11 +464,15 @@ static struct inode *ntfs_read_mft(struct inode *inode,
 				       &ntfs_dir_operations;
 		ni->i_valid = 0;
 	} else if (S_ISLNK(mode)) {
+		if (ino == 25)
+			printk(KERN_ERR "DEEPANSHU: inode 25 is SYMLINK\n");
 		ni->std_fa &= ~FILE_ATTRIBUTE_DIRECTORY;
 		inode->i_op = &ntfs_link_inode_operations;
 		inode->i_fop = NULL;
 		inode_nohighmem(inode);
 	} else if (S_ISREG(mode)) {
+		if (ino == 25)
+			printk(KERN_ERR "DEEPANSHU: inode 25 is REGULAR FILE, about to init lock\n");
 		ni->std_fa &= ~FILE_ATTRIBUTE_DIRECTORY;
 		inode->i_op = &ntfs_file_inode_operations;
 		inode->i_fop = unlikely(is_legacy_ntfs(sb)) ?
@@ -461,18 +480,27 @@ static struct inode *ntfs_read_mft(struct inode *inode,
 				       &ntfs_file_operations;
 		inode->i_mapping->a_ops = is_compressed(ni) ? &ntfs_aops_cmpr :
 							      &ntfs_aops;
-		if (ino != MFT_REC_MFT)
+		if (ino != MFT_REC_MFT) {
+			if (ino == 25)
+				printk(KERN_ERR "DEEPANSHU: inode 25 - INITIALIZING run_lock NOW\n");
 			init_rwsem(&ni->file.run_lock);
+		}
 	} else if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode) ||
 		   S_ISSOCK(mode)) {
+		if (ino == 25)
+			printk(KERN_ERR "DEEPANSHU: inode 25 is SPECIAL\n");
 		inode->i_op = &ntfs_special_inode_operations;
 		init_special_inode(inode, mode, inode->i_rdev);
 	} else if (fname && fname->home.low == cpu_to_le32(MFT_REC_EXTEND) &&
 		   fname->home.seq == cpu_to_le16(MFT_REC_EXTEND)) {
+		if (ino == 25)
+			printk(KERN_ERR "DEEPANSHU: inode 25 is EXTEND record\n");
 		/* Records in $Extend are not a files or general directories. */
 		inode->i_op = &ntfs_file_inode_operations;
 		mode = S_IFREG;
 	} else {
+		if (ino == 25)
+			printk(KERN_ERR "DEEPANSHU: inode 25 - INVALID mode, going to out\n");
 		err = -EINVAL;
 		goto out;
 	}
@@ -494,11 +522,16 @@ static struct inode *ntfs_read_mft(struct inode *inode,
 	if (ino == MFT_REC_MFT && !sb->s_root)
 		sbi->mft.ni = NULL;
 
+	if (ino == 25)
+		printk(KERN_ERR "DEEPANSHU: inode 25 - SUCCESS, about to unlock_new_inode\n");
+
 	unlock_new_inode(inode);
 
 	return inode;
 
 out:
+	if (ino == 25)
+		printk(KERN_ERR "DEEPANSHU: inode 25 - ERROR PATH, err=%d\n", err);
 	if (ino == MFT_REC_MFT && !sb->s_root)
 		sbi->mft.ni = NULL;
 
@@ -527,33 +560,52 @@ static int ntfs_set_inode(struct inode *inode, void *data)
 }
 
 struct inode *ntfs_iget5(struct super_block *sb, const struct MFT_REF *ref,
-			 const struct cpu_str *name)
+                         const struct cpu_str *name)
 {
-	struct inode *inode;
-
-	inode = iget5_locked(sb, ino_get(ref), ntfs_test_inode, ntfs_set_inode,
-			     (void *)ref);
-	if (unlikely(!inode))
-		return ERR_PTR(-ENOMEM);
-
-	/* If this is a freshly allocated inode, need to read it now. */
-	if (inode->i_state & I_NEW)
-		inode = ntfs_read_mft(inode, name, ref);
-	else if (ref->seq != ntfs_i(inode)->mi.mrec->seq) {
-		/*
-		 * Sequence number is not expected.
-		 * Looks like inode was reused but caller uses the old reference
-		 */
-		iput(inode);
-		inode = ERR_PTR(-ESTALE);
-	}
-
-	if (IS_ERR(inode))
-		ntfs_set_state(sb->s_fs_info, NTFS_DIRTY_ERROR);
-
-	return inode;
+    struct inode *inode;
+    unsigned long ino = ino_get(ref);
+    
+    if (ino == 25) {
+        printk(KERN_ERR "DEEPANSHU: ntfs_iget5 START for inode 25\n");
+        //dump_stack();
+    }
+    
+    inode = iget5_locked(sb, ino, ntfs_test_inode, ntfs_set_inode,
+                         (void *)ref);
+    
+    if (unlikely(!inode))
+        return ERR_PTR(-ENOMEM);
+    
+    if (inode->i_ino == 25) {
+        printk(KERN_ERR "DEEPANSHU: After iget5_locked for inode 25, I_NEW=%d, i_state=0x%x\n", 
+               !!(inode->i_state & I_NEW), inode->i_state);
+        //dump_stack();
+    }
+    
+    /* If this is a freshly allocated inode, need to read it now. */
+    if (inode->i_state & I_NEW) {
+        if (inode->i_ino == 25)
+            printk(KERN_ERR "DEEPANSHU: Calling ntfs_read_mft for inode 25\n");
+        inode = ntfs_read_mft(inode, name, ref);
+        if (inode->i_ino == 25 && IS_ERR(inode))
+            printk(KERN_ERR "DEEPANSHU: ntfs_read_mft FAILED for inode 25\n");
+    } else if (ref->seq != ntfs_i(inode)->mi.mrec->seq) {
+        if (inode->i_ino == 25)
+            printk(KERN_ERR "DEEPANSHU: inode 25 seq mismatch\n");
+        iput(inode);
+        inode = ERR_PTR(-ESTALE);
+    } else if (inode->i_ino == 25) {
+        printk(KERN_ERR "DEEPANSHU: inode 25 found in CACHE, skipping ntfs_read_mft!\n");
+        //dump_stack();
+    }
+
+    if (IS_ERR(inode))
+        ntfs_set_state(sb->s_fs_info, NTFS_DIRTY_ERROR);
+
+    return inode;
 }
 
+
 enum get_block_ctx {
 	GET_BLOCK_GENERAL = 0,
 	GET_BLOCK_WRITE_BEGIN = 1,
@@ -1180,6 +1232,8 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
 		      umode_t mode, dev_t dev, const char *symname, u32 size,
 		      struct ntfs_fnd *fnd)
 {
+	printk(KERN_WARNING "GET THE MESSAGE deepanshu \n");
+	//ntfs_warn(sb, "DEBUG: In inodde function");
 	int err;
 	struct super_block *sb = dir->i_sb;
 	struct ntfs_sb_info *sbi = sb->s_fs_info;
@@ -1597,6 +1651,7 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
 		inode->i_size = size;
 		inode_nohighmem(inode);
 	} else if (S_ISREG(mode)) {
+		ntfs_warn(dir->i_sb, "DEBUG: Setting up regular file inode %lu", inode->i_ino);
 		inode->i_op = &ntfs_file_inode_operations;
 		inode->i_fop = unlikely(is_legacy_ntfs(sb)) ?
 				       &ntfs_legacy_file_operations :
@@ -1604,6 +1659,8 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
 		inode->i_mapping->a_ops = is_compressed(ni) ? &ntfs_aops_cmpr :
 							      &ntfs_aops;
 		init_rwsem(&ni->file.run_lock);
+		ntfs_warn(sb, "DEBUG: Created regular file inode %lu, run_lock initialized", 
+              inode->i_ino);
 	} else {
 		inode->i_op = &ntfs_special_inode_operations;
 		init_special_inode(inode, mode, dev);
-- 
2.43.0
Re: Forwarded: [PATCH] ntfs3: add debug warnings for run_lock initialization
Posted by Dan Carpenter 2 months ago
Hi syzbot,

kernel test robot noticed the following build warnings:

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/syzbot/Forwarded-PATCH-ntfs3-add-debug-warnings-for-run_lock-initialization/20251014-195051
base:   v6.18-rc1
patch link:    https://lore.kernel.org/r/68ee38b5.050a0220.ac43.00fd.GAE%40google.com
patch subject: Forwarded: [PATCH] ntfs3: add debug warnings for run_lock initialization
config: i386-randconfig-141-20251015 (https://download.01.org/0day-ci/archive/20251017/202510170051.yMGKcZjz-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)

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 <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202510170051.yMGKcZjz-lkp@intel.com/

smatch warnings:
fs/ntfs3/inode.c:590 ntfs_iget5() warn: variable dereferenced before IS_ERR check 'inode' (see line 590)

vim +/inode +590 fs/ntfs3/inode.c

82cae269cfa9530 Konstantin Komarov 2021-08-13  562  struct inode *ntfs_iget5(struct super_block *sb, const struct MFT_REF *ref,
82cae269cfa9530 Konstantin Komarov 2021-08-13  563                           const struct cpu_str *name)
82cae269cfa9530 Konstantin Komarov 2021-08-13  564  {
82cae269cfa9530 Konstantin Komarov 2021-08-13  565      struct inode *inode;
9ca11d2cd5f563e syzbot             2025-10-14  566      unsigned long ino = ino_get(ref);
82cae269cfa9530 Konstantin Komarov 2021-08-13  567      
9ca11d2cd5f563e syzbot             2025-10-14  568      if (ino == 25) {
9ca11d2cd5f563e syzbot             2025-10-14  569          printk(KERN_ERR "DEEPANSHU: ntfs_iget5 START for inode 25\n");
9ca11d2cd5f563e syzbot             2025-10-14  570          //dump_stack();
9ca11d2cd5f563e syzbot             2025-10-14  571      }
9ca11d2cd5f563e syzbot             2025-10-14  572      
9ca11d2cd5f563e syzbot             2025-10-14  573      inode = iget5_locked(sb, ino, ntfs_test_inode, ntfs_set_inode,
82cae269cfa9530 Konstantin Komarov 2021-08-13  574                           (void *)ref);
9ca11d2cd5f563e syzbot             2025-10-14  575      
82cae269cfa9530 Konstantin Komarov 2021-08-13  576      if (unlikely(!inode))
82cae269cfa9530 Konstantin Komarov 2021-08-13  577          return ERR_PTR(-ENOMEM);
82cae269cfa9530 Konstantin Komarov 2021-08-13  578      
9ca11d2cd5f563e syzbot             2025-10-14  579      if (inode->i_ino == 25) {
9ca11d2cd5f563e syzbot             2025-10-14  580          printk(KERN_ERR "DEEPANSHU: After iget5_locked for inode 25, I_NEW=%d, i_state=0x%x\n", 
9ca11d2cd5f563e syzbot             2025-10-14  581                 !!(inode->i_state & I_NEW), inode->i_state);
9ca11d2cd5f563e syzbot             2025-10-14  582          //dump_stack();
9ca11d2cd5f563e syzbot             2025-10-14  583      }
9ca11d2cd5f563e syzbot             2025-10-14  584      
82cae269cfa9530 Konstantin Komarov 2021-08-13  585      /* If this is a freshly allocated inode, need to read it now. */
9ca11d2cd5f563e syzbot             2025-10-14  586      if (inode->i_state & I_NEW) {
9ca11d2cd5f563e syzbot             2025-10-14  587          if (inode->i_ino == 25)
9ca11d2cd5f563e syzbot             2025-10-14  588              printk(KERN_ERR "DEEPANSHU: Calling ntfs_read_mft for inode 25\n");
82cae269cfa9530 Konstantin Komarov 2021-08-13  589          inode = ntfs_read_mft(inode, name, ref);
9ca11d2cd5f563e syzbot             2025-10-14 @590          if (inode->i_ino == 25 && IS_ERR(inode))
                                                                ^^^^^^^^^^^^                 ^^^^^
"inode" dereferenced before an IS_ERR() check...

9ca11d2cd5f563e syzbot             2025-10-14  591              printk(KERN_ERR "DEEPANSHU: ntfs_read_mft FAILED for inode 25\n");
9ca11d2cd5f563e syzbot             2025-10-14  592      } else if (ref->seq != ntfs_i(inode)->mi.mrec->seq) {
9ca11d2cd5f563e syzbot             2025-10-14  593          if (inode->i_ino == 25)
9ca11d2cd5f563e syzbot             2025-10-14  594              printk(KERN_ERR "DEEPANSHU: inode 25 seq mismatch\n");
1fd21919de6de24 Konstantin Komarov 2024-08-22  595          iput(inode);
1fd21919de6de24 Konstantin Komarov 2024-08-22  596          inode = ERR_PTR(-ESTALE);
9ca11d2cd5f563e syzbot             2025-10-14  597      } else if (inode->i_ino == 25) {
9ca11d2cd5f563e syzbot             2025-10-14  598          printk(KERN_ERR "DEEPANSHU: inode 25 found in CACHE, skipping ntfs_read_mft!\n");
9ca11d2cd5f563e syzbot             2025-10-14  599          //dump_stack();
82cae269cfa9530 Konstantin Komarov 2021-08-13  600      }
82cae269cfa9530 Konstantin Komarov 2021-08-13  601  
1fd21919de6de24 Konstantin Komarov 2024-08-22  602      if (IS_ERR(inode))
0e8235d28f3a0e9 Konstantin Komarov 2022-10-10  603          ntfs_set_state(sb->s_fs_info, NTFS_DIRTY_ERROR);
0e8235d28f3a0e9 Konstantin Komarov 2022-10-10  604  
82cae269cfa9530 Konstantin Komarov 2021-08-13  605      return inode;
82cae269cfa9530 Konstantin Komarov 2021-08-13  606  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki