erofs-utils: sbi->devs should be cleared after freed
PATCH 1/1 erofs-utils: sbi->devs should be cleared after freed
Otherwise, it could cause double-free if sbi reuses when fuzzing [1].
[1] https://github.com/erofs/erofsnightly/actions/runs/5921003885/job/16053013007
Signed-off-by Gao Xiang <[email protected]>
--- lib/super.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
lib/super.c +6 -2
@@ -123,14 +123,18 @@ int erofs_read_superblock(struct erofs_sb_info *sbi)return ret; ret =erofs_xattr_prefixes_init (sbi); -if (ret) +if (ret) {free (sbi->devs); + sbi->devs =NULL ; + }return ret; }void erofs_put_super (struct erofs_sb_info *sbi) { -if (sbi->devs) +if (sbi->devs) {free (sbi->devs); + sbi->devs =NULL ; + }erofs_xattr_prefixes_cleanup (sbi); }
Signature · 1 line
2.24.4
PATCH v2 1/1 erofs-utils: sbi->devs should be cleared after freed
Otherwise, it could cause double-free if sbi reuses when fuzzing [1].
[1] https://github.com/erofs/erofsnightly/actions/runs/5921003885/job/16053013007
Signed-off-by Gao Xiang <[email protected]>
---
changes since v1:
- add a missing sbi->devs = NULL in erofs_init_devices().
lib/super.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
lib/super.c +7 -2
@@ -53,6 +53,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi, ret =dev_read (sbi,0 , &dis, pos,sizeof (dis));if (ret <0 ) {free (sbi->devs); + sbi->devs =NULL ;return ret; }
@@ -123,14 +124,18 @@ int erofs_read_superblock(struct erofs_sb_info *sbi)return ret; ret =erofs_xattr_prefixes_init (sbi); -if (ret) +if (ret && sbi->devs) {free (sbi->devs); + sbi->devs =NULL ; + }return ret; }void erofs_put_super (struct erofs_sb_info *sbi) { -if (sbi->devs) +if (sbi->devs) {free (sbi->devs); + sbi->devs =NULL ; + }erofs_xattr_prefixes_cleanup (sbi); }
Signature · 1 line
2.24.4
Quoted 5 lines · Gao Xiang
Otherwise, it could cause double-free if sbi reuses when fuzzing [1].
[1] https://github.com/erofs/erofsnightly/actions/runs/5921003885/job/16053013007
Signed-off-by Gao Xiang <[email protected]>
LGTM.
Reviewed-by Jingbo Xu <[email protected]>
Quoted 40 lines
---
changes since v1:
- add a missingsbi->devs= NULL inerofs_init_devices().lib/super.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)lib/super.c +7
-2@@ -53,6 +53,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi, ret =dev_read (sbi,0 , &dis, pos,sizeof (dis));if (ret <0 ) {free (sbi->devs); + sbi->devs =NULL ;return ret; }@@ -123,14 +124,18 @@ int erofs_read_superblock(struct erofs_sb_info *sbi)return ret; ret =erofs_xattr_prefixes_init (sbi); -if (ret) +if (ret && sbi->devs) {free (sbi->devs); + sbi->devs =NULL ; + }return ret; }void erofs_put_super (struct erofs_sb_info *sbi) { -if (sbi->devs) +if (sbi->devs) {free (sbi->devs); + sbi->devs =NULL ; + }erofs_xattr_prefixes_cleanup (sbi); }
Signature · 2 lines
Thanks, Jingbo