virtiofsd: fix some accessing NULL pointer problem
v2 cover virtiofsd: fix some accessing NULL pointer problem
Haotian Li (2):
tools/virtiofsd/buffer.c: check whether buf is NULL in
fuse_bufvec_advance func
virtiofsd/passthrough_ll.c: check whether lo_map_reserve returns NULL
in main func
tools/virtiofsd/buffer.c | 4 ++++ tools/virtiofsd/passthrough_ll.c | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
PATCH v2 1/2 tools/virtiofsd/buffer.c: check whether buf is NULL in fuse_bufvec_advance func
In fuse_bufvec_advance func, calling fuse_bufvec_current func may return NULL, so we should check whether buf is NULL before using it.
--- tools/virtiofsd/buffer.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/virtiofsd/buffer.c +4 -0
@@ -246,6 +246,10 @@ static int fuse_bufvec_advance(struct fuse_bufvec *bufv, size_t len) {const struct fuse_buf *buf =fuse_bufvec_current (bufv); +if (!buf) { +return 0 ; + } + bufv->off += len;assert (bufv->off <= buf->size);if (bufv->off == buf->size) {
PATCH v2 2/2 virtiofsd: check whether lo_map_reserve returns NULL in main func
In reply to Haotian LiIn main func, func lo_map_reserve is called without NULL check. If reallocing new_elems fails in func lo_map_grow, the func lo_map_reserve may return NULL. We should check whether lo_map_reserve returns NULL before using it.
--- tools/virtiofsd/passthrough_ll.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
tools/virtiofsd/passthrough_ll.c +9 -1
@@ -3433,6 +3433,7 @@ int main(int argc, char *argv[]) .proc_self_fd = -1, };struct lo_map_elem *root_elem; +struct lo_map_elem *reserve_elem;int ret =-1 ;/* Don't mask creation mode, kernel already did that */
@@ -3452,8 +3453,15 @@ int main(int argc, char *argv[])* [1] Root inode */ lo_map_init (&lo.ino_map); -lo_map_reserve (&lo.ino_map,0 )->in_use = false; + reserve_elem =lo_map_reserve (&lo.ino_map,0 ); +if (!reserve_elem) { + goto err_out1; + } + reserve_elem->in_use = false; root_elem =lo_map_reserve (&lo.ino_map, lo.root.fuse_ino); +if (!root_elem) { + goto err_out1; + } root_elem->inode = &lo.root;lo_map_init (&lo.dirp_map);
Quoted 9 lines · Haotian Li
Haotian Li (2):
tools/virtiofsd/buffer.c: check whether buf is NULL in
fuse_bufvec_advancefunc
virtiofsd/passthrough_ll.c: check whetherlo_map_reservereturns NULL
in main functools/virtiofsd/buffer.c | 4 ++++ tools/virtiofsd/passthrough_ll.c | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
Please consider printing an error message in Patch 2 so that users can easily tell why the program refused to start.
Quoted 7 lines · Stefan Hajnoczi
Quoted 6 lines · Haotian Li
Haotian Li (2):
tools/virtiofsd/buffer.c: check whether buf is NULL in
fuse_bufvec_advancefunc
virtiofsd/passthrough_ll.c: check whetherlo_map_reservereturns NULL
in main func
Quoted 9 lines
Quoted 3 lines
tools/virtiofsd/buffer.c | 4 ++++ tools/virtiofsd/passthrough_ll.c | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)Please consider printing an error message in Patch 2 so that users can easily tell why the program refused to start.
Reviewed-by Stefan Hajnoczi <[email protected]>
Thanks for your review.
We will add error message in Patch2, and then send the v3-patch series.
Regards
Zhiqiang Liu.
Quoted 6 lines
_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs
Thanks for your suggestion. New patches will be resent.
Quoted 16 lines · Haotian Li
Quoted 9 lines
Haotian Li (2):
tools/virtiofsd/buffer.c: check whether buf is NULL in
fuse_bufvec_advancefunc
virtiofsd/passthrough_ll.c: check whetherlo_map_reservereturns NULL
in main functools/virtiofsd/buffer.c | 4 ++++ tools/virtiofsd/passthrough_ll.c | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)Please consider printing an error message in Patch 2 so that users can easily tell why the program refused to start.
Reviewed-by Stefan Hajnoczi <[email protected]>