fs: fuse: dax: set fc->dax to NULL in fuse_dax_conn_free()
Subsystems (2)
PATCH 1/1 fs: fuse: dax: set fc->dax to NULL in fuse_dax_conn_free()
fuse_dax_conn_free() will be called when fuse_fill_super_common() fails after fuse_dax_conn_alloc(). Then deactivate_locked_super() in virtio_fs_get_tree() will call virtio_kill_sb() to release the discarded superblock. This will call fuse_dax_conn_free() again in fuse_conn_put(), resulting in a possible double free.
--- fs/fuse/dax.c | 1 + 1 file changed, 1 insertion(+)
fs/fuse/dax.c +1 -0
@@ -1222,6 +1222,7 @@ void fuse_dax_conn_free(struct fuse_conn *fc)if (fc->dax) {fuse_free_dax_mem_ranges (&fc->dax->free_ranges);kfree (fc->dax); + fc->dax =NULL ; } }
Signature · 1 line
2.34.1
Quoted 8 lines · Hangyu Hua
fuse_dax_conn_free()will be called whenfuse_fill_super_common()fails afterfuse_dax_conn_alloc(). Thendeactivate_locked_super()invirtio_fs_get_tree()will callvirtio_kill_sb()to release the discarded superblock. This will callfuse_dax_conn_free()again infuse_conn_put(), resulting in a possible double free.Fixes 1dd539577c42 ("virtiofs: add a mount option to enable dax")Signed-off-by Hangyu Hua <[email protected]>
Quoted 16 lines
--- fs/fuse/dax.c | 1 + 1 file changed, 1 insertion(+)fs/fuse/dax.c +1
-0@@ -1222,6 +1222,7 @@ void fuse_dax_conn_free(struct fuse_conn *fc)if (fc->dax) {fuse_free_dax_mem_ranges (&fc->dax->free_ranges);kfree (fc->dax); + fc->dax =NULL ; } }
Signature · 2 lines
Thanks, Jingbo
Miklos Szeredi
maintainerQuoted 18 lines · Hangyu Hua
fuse_dax_conn_free()will be called whenfuse_fill_super_common()fails afterfuse_dax_conn_alloc(). Thendeactivate_locked_super()invirtio_fs_get_tree()will callvirtio_kill_sb()to release the discarded superblock. This will callfuse_dax_conn_free()again infuse_conn_put(), resulting in a possible double free.Fixes 1dd539577c42 ("virtiofs: add a mount option to enable dax")Signed-off-by Hangyu Hua <[email protected]>--- fs/fuse/dax.c | 1 + 1 file changed, 1 insertion(+)fs/fuse/dax.c +0
-0
fs/fuse/dax.c void fuse_dax_conn_free(struct fuse_conn *fc) · line 1225
Quoted 4 lines
fs/fuse/dax.c +1
-0@@ -1222,6 +1222,7 @@ void fuse_dax_conn_free(struct fuse_conn *fc)if (fc->dax) {fuse_free_dax_mem_ranges (&fc->dax->free_ranges);kfree (fc->dax); + fc->dax =NULL ;
Is there a reason not to simply remove the fuse_dax_conn_free() call from the cleanup path in fuse_fill_super_common()?
Thanks,
Miklos
Quoted 6 lines
fs/fuse/dax.c +0
-1} } --2.34.1
Quoted 14 lines · Miklos Szeredi
Quoted 13 lines · Hangyu Hua
fuse_dax_conn_free()will be called whenfuse_fill_super_common()fails afterfuse_dax_conn_alloc(). Thendeactivate_locked_super()invirtio_fs_get_tree()will callvirtio_kill_sb()to release the discarded superblock. This will callfuse_dax_conn_free()again infuse_conn_put(), resulting in a possible double free.Fixes 1dd539577c42 ("virtiofs: add a mount option to enable dax")Signed-off-by Hangyu Hua <[email protected]>--- fs/fuse/dax.c | 1 + 1 file changed, 1 insertion(+)
Quoted 12 lines
fs/fuse/dax.c void fuse_dax_conn_free(struct fuse_conn *fc) · line 1225
Quoted 9 lines
fs/fuse/dax.c +1
-0@@ -1222,6 +1222,7 @@ void fuse_dax_conn_free(struct fuse_conn *fc)if (fc->dax) {fuse_free_dax_mem_ranges (&fc->dax->free_ranges);kfree (fc->dax); + fc->dax =NULL ;Is there a reason not to simply remove the
fuse_dax_conn_free()call from the cleanup path infuse_fill_super_common()?
I think setting fc->dax to NULL keeps the memory allocation and release functions together in fuse_fill_super_common more readable. What do you think?
Thanks,
Hangyu
Quoted 11 lines
Thanks,
MiklosQuoted 6 lines
fs/fuse/dax.c +0
-1} } --2.34.1
Vivek Goyal
Acked-byQuoted 28 lines · Hangyu Hua
Quoted 14 lines · Miklos Szeredi
Quoted 13 lines · Hangyu Hua
fuse_dax_conn_free()will be called whenfuse_fill_super_common()fails afterfuse_dax_conn_alloc(). Thendeactivate_locked_super()invirtio_fs_get_tree()will callvirtio_kill_sb()to release the discarded superblock. This will callfuse_dax_conn_free()again infuse_conn_put(), resulting in a possible double free.Fixes 1dd539577c42 ("virtiofs: add a mount option to enable dax")Signed-off-by Hangyu Hua <[email protected]>--- fs/fuse/dax.c | 1 + 1 file changed, 1 insertion(+)Quoted 12 lines
fs/fuse/dax.c void fuse_dax_conn_free(struct fuse_conn *fc) · line 1225
Quoted 9 lines
fs/fuse/dax.c +1
-0@@ -1222,6 +1222,7 @@ void fuse_dax_conn_free(struct fuse_conn *fc)if (fc->dax) {fuse_free_dax_mem_ranges (&fc->dax->free_ranges);kfree (fc->dax); + fc->dax =NULL ;Is there a reason not to simply remove the
fuse_dax_conn_free()call from the cleanup path infuse_fill_super_common()?
Quoted 3 lines
I think setting
fc->daxto NULL keeps the memory allocation and release functions together infuse_fill_super_commonmore readable. What do you think?
I agree with this. fuse_fill_super_common() calls fuse_dax_conn_alloc() which in-turn initializes fc->dax. If fuse_fill_super_common() fails later after calling fuse_dax_conn_alloc(), then cleanup of fc->dax and other associated stuff in same function makes sense.
As a code reader I would like to know how fc->dax is being freed in case of error and its right there in the error path (err_free_dax:).
I think I set the fc->dax upon initialization. Upon failure I freed the data structures but did not set fc->dax back to NULL.
To me, this patch looks reasonable.
Thanks
Vivek
Quoted 16 lines
Thanks,
HangyuQuoted 11 lines
Thanks,
MiklosQuoted 6 lines
fs/fuse/dax.c +0
-1} } --2.34.1
Quoted 15 lines · Vivek Goyal
Quoted 3 lines · Hangyu Hua
I think setting
fc->daxto NULL keeps the memory allocation and release functions together infuse_fill_super_commonmore readable. What do you think?I agree with this.
fuse_fill_super_common()callsfuse_dax_conn_alloc()which in-turn initializesfc->dax. Iffuse_fill_super_common()fails later after callingfuse_dax_conn_alloc(), then cleanup offc->daxand other associated stuff in same function makes sense.As a code reader I would like to know how
fc->daxis being freed in case of error and its right there in the error path (err_free_dax:).
Quoted 6 lines
I think I set the
fc->daxupon initialization. Upon failure I freed the data structures but did not setfc->daxback to NULL.To me, this patch looks reasonable.
Acked-by Vivek Goyal <[email protected]>
Applied, thanks.
The patch is clearly correct, so I have not major issue with it. It
just bothers me a little that we have two cleanup instances when we only need one, but I bow to the opinion of the majority.
Thanks,
Miklos