Skip to contentSkip to conversation

ubifs: Call ubifs_iput when ubifs_iget is used

PATCH Superseded Michael Trimarchi 2 participants 3 messages Aug 7, 2024 – Aug 10, 2024 UBI file system (UBIFS)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ubifs: Call ubifs_iput when ubifs_iget is used

The inode should be freed after a reference is get to avoid memory leak

---
RFC=>V1:
- Heiko gives more points to address on the patch and review it
- Alexander Dahl test on top of his own series reported in the commit message
- add leak on super.c file too from Heiko

---
 fs/ubifs/super.c | 1 +
 fs/ubifs/ubifs.c | 9 ++++++---
 2 files changed, 7 insertions(+), 3 deletions(-)
fs/ubifs/super.c +1 -0
index d8d78a2d3d..7721e168fb 100644
@@ -2321,6 +2321,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
 		goto out_umount;
 	}
 #else
+	ubifs_iput(inode);
 	sb->s_root = NULL;
 #endif
 
fs/ubifs/ubifs.c +6 -3
index 048730db7f..6acd6c3776 100644
@@ -319,9 +319,7 @@ static int filldir(struct ubifs_info *c, const char *name, int namlen,
 	}
 	ctime_r((time_t *)&inode->i_mtime, filetime);
 	printf("%9lld  %24.24s  ", inode->i_size, filetime);
-#ifndef __UBOOT__
 	ubifs_iput(inode);
-#endif
 
 	printf("%s\n", name);
 
@@ -557,6 +555,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
 
 			/* We have some sort of symlink recursion, bail out */
 			if (symlink_count++ > 8) {
+				ubifs_iput(inode);
 				printf("Symlink recursion, aborting\n");
 				return 0;
 			}
@@ -568,6 +567,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
 				 * the leading slash */
 				next = name = link_name + 1;
 				root_inum = 1;
+				ubifs_iput(inode);
 				continue;
 			}
 			/* Relative to cur dir */
@@ -575,6 +575,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
 					link_name, next == NULL ? "" : next);
 			memcpy(symlinkpath, buf, sizeof(buf));
 			next = name = symlinkpath;
+			ubifs_iput(inode);
 			continue;
 		}
 
@@ -583,8 +584,10 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
 		 */
 
 		/* Found the node!  */
-		if (!next || *next == '\0')
+		if (!next || *next == '\0') {
+			ubifs_iput(inode);
 			return inum;
+		}
 
 		root_inum = inum;
 		name = next;
Signature · 1 line
2.43.0
#1 lore raw

Hello Michael,

Quoted 24 lines · Michael Trimarchi

The inode should be freed after a reference is get to avoid memory leak

---
RFC=>V1:
- Heiko gives more points to address on the patch and review it
- Alexander Dahl test on top of his own series reported in the commit message
- add leak on super.c file too from Heiko

---
  fs/ubifs/super.c | 1 +
  fs/ubifs/ubifs.c | 9 ++++++---
  2 files changed, 7 insertions(+), 3 deletions(-)
fs/ubifs/super.c +0 -0
index d8d78a2d3d..7721e168fb 100644

fs/ubifs/super.c static int ubifs_fill_super(struct super_block *sb, void *data, int silent) · line 2326

Quoted 6 lines
fs/ubifs/super.c +1 -0
@@ -2321,6 +2321,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
  		goto out_umount;
  	}
  #else
+	ubifs_iput(inode);
  	sb->s_root = NULL;
  #endif

This breaks build:

https://dev.azure.com/hs0298/hs/_build/results?buildId=120&view=logs&j=4f2a9147-48ab-50e3-8e13-2f207368f205&t=617c682e-fe32-5637-a697-bfafa314b3b3&l=271

obviously it must be

ubifs_iput(root);

Sorry... can you send a v2 please?

bye,
Heiko

Quoted 52 lines
fs/ubifs/ubifs.c +6 -3
index 048730db7f..6acd6c3776 100644
@@ -319,9 +319,7 @@ static int filldir(struct ubifs_info *c, const char *name, int namlen,
  	}
  	ctime_r((time_t *)&inode->i_mtime, filetime);
  	printf("%9lld  %24.24s  ", inode->i_size, filetime);
-#ifndef __UBOOT__
  	ubifs_iput(inode);
-#endif
 
  	printf("%s\n", name);
 
@@ -557,6 +555,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
 
  			/* We have some sort of symlink recursion, bail out */
  			if (symlink_count++ > 8) {
+				ubifs_iput(inode);
  				printf("Symlink recursion, aborting\n");
  				return 0;
  			}
@@ -568,6 +567,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
  				 * the leading slash */
  				next = name = link_name + 1;
  				root_inum = 1;
+				ubifs_iput(inode);
  				continue;
  			}
  			/* Relative to cur dir */
@@ -575,6 +575,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
  					link_name, next == NULL ? "" : next);
  			memcpy(symlinkpath, buf, sizeof(buf));
  			next = name = symlinkpath;
+			ubifs_iput(inode);
  			continue;
  		}
 
@@ -583,8 +584,10 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
  		 */
 
  		/* Found the node!  */
-		if (!next || *next == '\0')
+		if (!next || *next == '\0') {
+			ubifs_iput(inode);
  			return inum;
+		}
 
  		root_inum = inum;
  		name = next;
Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#2 lore raw

Hi Heiko

Quoted 23 lines · Heiko Schocher

Hello Michael,

Quoted 19 lines · Michael Trimarchi

The inode should be freed after a reference is get to avoid memory leak

---
RFC=>V1:
- Heiko gives more points to address on the patch and review it
- Alexander Dahl test on top of his own series reported in the commit message
- add leak on super.c file too from Heiko

---
  fs/ubifs/super.c | 1 +
  fs/ubifs/ubifs.c | 9 ++++++---
  2 files changed, 7 insertions(+), 3 deletions(-)
Quoted 14 lines

fs/ubifs/super.c static int ubifs_fill_super(struct super_block *sb, void *data, int silent) · line 2326

Quoted 11 lines
fs/ubifs/super.c +1 -0
index d8d78a2d3d..7721e168fb 100644
@@ -2321,6 +2321,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
              goto out_umount;
      }
  #else
+     ubifs_iput(inode);
      sb->s_root = NULL;
  #endif

This breaks build:

I was silly not to pay attention on it

Michael

Quoted 68 lines

https://dev.azure.com/hs0298/hs/_build/results?buildId=120&view=logs&j=4f2a9147-48ab-50e3-8e13-2f207368f205&t=617c682e-fe32-5637-a697-bfafa314b3b3&l=271

obviously it must be

ubifs_iput(root);

Sorry... can you send a v2 please?

bye,
Heiko

Quoted 42 lines
fs/ubifs/ubifs.c +3 -2
index 048730db7f..6acd6c3776 100644
@@ -319,9 +319,7 @@ static int filldir(struct ubifs_info *c, const char *name, int namlen,
      }
      ctime_r((time_t *)&inode->i_mtime, filetime);
      printf("%9lld  %24.24s  ", inode->i_size, filetime);
-#ifndef __UBOOT__
      ubifs_iput(inode);
-#endif
 
      printf("%s\n", name);
 
@@ -557,6 +555,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
 
                      /* We have some sort of symlink recursion, bail out */
                      if (symlink_count++ > 8) {
+                             ubifs_iput(inode);
                              printf("Symlink recursion, aborting\n");
                              return 0;
                      }
@@ -568,6 +567,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
                               * the leading slash */
                              next = name = link_name + 1;
                              root_inum = 1;
+                             ubifs_iput(inode);
                              continue;
                      }
                      /* Relative to cur dir */
@@ -575,6 +575,7 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
                                      link_name, next == NULL ? "" : next);
                      memcpy(symlinkpath, buf, sizeof(buf));
                      next = name = symlinkpath;
+                     ubifs_iput(inode);
                      continue;
              }
 
@@ -583,8 +584,10 @@ static unsigned long ubifs_findfile(struct super_block *sb, char *filename)
               */

fs/ubifs/ubifs.c static unsigned long ubifs_findfile(struct super_block *sb, char *filename) · line 593

Quoted 10 lines
fs/ubifs/ubifs.c +3 -1
 
              /* Found the node!  */
-             if (!next || *next == '\0')
+             if (!next || *next == '\0') {
+                     ubifs_iput(inode);
                      return inum;
+             }
 
              root_inum = inum;
              name = next;

--
DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: [email protected]

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com