Skip to contentSkip to conversation

erofs: fix double free of 'copied'

PATCH In review Gao Xiang 2 participants 2 messages Aug 25, 2021 EROFS file system

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs: fix double free of 'copied'

Dan reported a new smatch warning [1]
"fs/erofs/inode.c:210 erofs_read_inode() error: double free of 'copied'"

Due to new chunk-based format handling logic, the error path can be called after kfree(copied).

Set "copied = NULL" after kfree(copied) to fix this.

[1] https://lore.kernel.org/r/[email protected]

Fixes c5aa903a59db ("erofs: support reading chunk-based uncompressed files")
---
 fs/erofs/inode.c | 1 +
 1 file changed, 1 insertion(+)
fs/erofs/inode.c +1 -0
index 4408929bd6f5..31ac3a73b390 100644
@@ -127,6 +127,7 @@ static struct page *erofs_read_inode(struct inode *inode,
 			/* fill chunked inode summary info */
 			vi->chunkformat = le16_to_cpu(die->i_u.c.format);
 		kfree(copied);
+		copied = NULL;
 		break;
 	case EROFS_INODE_LAYOUT_COMPACT:
 		vi->inode_isize = sizeof(struct erofs_inode_compact);
Signature · 1 line
2.24.4
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Gao Xiang

Dan reported a new smatch warning [1]
"fs/erofs/inode.c:210 erofs_read_inode() error: double free of 'copied'"

Due to new chunk-based format handling logic, the error path can be called after kfree(copied).

Quoted 7 lines

Set "copied = NULL" after kfree(copied) to fix this.

[1] https://lore.kernel.org/r/[email protected]

Fixes c5aa903a59db ("erofs: support reading chunk-based uncompressed files")

Thanks,