Skip to contentSkip to conversation

fsck.f2fs: fix potential NULL dereference

PATCH Superseded Maxim Korotkov 2 participants 2 messages May 31, 2023 – Jun 2, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsck.f2fs: fix potential NULL dereference

The input pointer "parent" was used unsafely
before checking against NULL

Found by RASU JSC with Svace static analyzer

Fixes 603f8f9d3(sload.f2fs: support loading files into partition directly)
---
 fsck/dir.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
fsck/dir.c +9 -5
index 4a3eb6e..925fe14 100644
@@ -225,19 +225,23 @@ int f2fs_add_link(struct f2fs_sb_info *sbi, struct f2fs_node *parent,
 	int level = 0, current_depth, bit_pos;
 	int nbucket, nblock, bidx, block;
 	int slots = GET_DENTRY_SLOTS(name_len);
-	f2fs_hash_t dentry_hash = f2fs_dentry_hash(get_encoding(sbi),
-						IS_CASEFOLDED(&parent->i),
-						name, name_len);
+	f2fs_hash_t dentry_hash;
 	struct f2fs_dentry_block *dentry_blk;
 	struct f2fs_dentry_ptr d;
 	struct dnode_of_data dn;
-	nid_t pino = le32_to_cpu(parent->footer.ino);
-	unsigned int dir_level = parent->i.i_dir_level;
+	nid_t pino;
+	unsigned int dir_level;
 	int ret;
 
 	if (parent == NULL)
 		return -EINVAL;
 
+	dentry_hash = f2fs_dentry_hash(get_encoding(sbi),
+						IS_CASEFOLDED(&parent->i),
+						name, name_len);	
+	pino = le32_to_cpu(parent->footer.ino);
+	dir_level = parent->i.i_dir_level;
+
 	if (!pino) {
 		ERR_MSG("Wrong parent ino:%d \n", pino);
 		return -EINVAL;
Signature · 8 lines
2.34.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw
Quoted 27 lines · Maxim Korotkov

The input pointer "parent" was used unsafely
before checking against NULL

Found by RASU JSC with Svace static analyzer

Fixes 603f8f9d3(sload.f2fs: support loading files into partition directly)
---
  fsck/dir.c | 14 +++++++++-----
  1 file changed, 9 insertions(+), 5 deletions(-)
fsck/dir.c +1 -5
index 4a3eb6e..925fe14 100644
@@ -225,19 +225,23 @@ int f2fs_add_link(struct f2fs_sb_info *sbi, struct f2fs_node *parent,
  	int level = 0, current_depth, bit_pos;
  	int nbucket, nblock, bidx, block;
  	int slots = GET_DENTRY_SLOTS(name_len);
-	f2fs_hash_t dentry_hash = f2fs_dentry_hash(get_encoding(sbi),
-						IS_CASEFOLDED(&parent->i),
-						name, name_len);
+	f2fs_hash_t dentry_hash;
  	struct f2fs_dentry_block *dentry_blk;
  	struct f2fs_dentry_ptr d;
  	struct dnode_of_data dn;
-	nid_t pino = le32_to_cpu(parent->footer.ino);
-	unsigned int dir_level = parent->i.i_dir_level;

fsck/dir.c int f2fs_add_link(struct f2fs_sb_info *sbi, struct f2fs_node *parent, · line 241

Quoted 10 lines
fsck/dir.c +5 -0
+	nid_t pino;
+	unsigned int dir_level;
  	int ret;
 
  	if (parent == NULL)
  		return -EINVAL;
 
+	dentry_hash = f2fs_dentry_hash(get_encoding(sbi),
+						IS_CASEFOLDED(&parent->i),
+						name, name_len);	

Unneeded indent after ';', otherwise it looks good to me.

Thanks,

fsck/dir.c int f2fs_add_link(struct f2fs_sb_info *sbi, struct f2fs_node *parent, · line 247

Quoted 6 lines
fsck/dir.c +3 -0
+	pino = le32_to_cpu(parent->footer.ino);
+	dir_level = parent->i.i_dir_level;
+
  	if (!pino) {
  		ERR_MSG("Wrong parent ino:%d \n", pino);
  		return -EINVAL;

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel