Skip to contentSkip to conversation

fs/squashfs: Fix memory leak in sqfs_size_nest()

PATCH In review Andrea della Porta 3 participants 3 messages Mar 3, 2025 – Mar 6, 2025 SquashFS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/squashfs: Fix memory leak in sqfs_size_nest()

In case MAX_SYMLINK_NEST is reached while determining the size on a symlink node, the function returns immediately. This would not free the resources after the free_strings: label causing a memory leak.

Set the ret value and just break out of the switch to fix this.

---
 fs/squashfs/sqfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/squashfs/sqfs.c +2 -1
index b9314019b1..ac5b1cda3e 100644
@@ -1700,7 +1700,8 @@ static int sqfs_size_nest(const char *filename, loff_t *size)
 	case SQFS_LSYMLINK_TYPE:
 		if (++symlinknest == MAX_SYMLINK_NEST) {
 			*size = 0;
-			return -ELOOP;
+			ret = -ELOOP;
+			break;
 		}
 
 		symlink = (struct squashfs_symlink_inode *)ipos;
Signature · 1 line
2.44.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Andrea,

Quoted 8 lines · Andrea della Porta

In case MAX_SYMLINK_NEST is reached while determining the size on a symlink node, the function returns immediately. This would not free the resources after the free_strings: label causing a memory leak.

Set the ret value and just break out of the switch to fix this.

Thanks,
Miquèl

#2 lore raw
In reply to Andrea della Porta
Quoted 8 lines · Andrea della Porta

In case MAX_SYMLINK_NEST is reached while determining the size on a symlink node, the function returns immediately. This would not free the resources after the free_strings: label causing a memory leak.

Set the ret value and just break out of the switch to fix this.

[...]

Applied to u-boot/master, thanks!

[1/1] fs/squashfs: Fix memory leak in sqfs_size_nest()

      commit: e22b2d778106256b44e8ed32e6ad7a5d8fff3ebd
Signature · 1 line
Tom