Skip to contentSkip to conversation

virtiofsd: fix some accessing NULL pointer problem

PATCH Superseded Haotian Li 3 participants 6 messages Nov 10, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Haotian Li

author
#0 lore raw

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(-)
author
#1 lore raw

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
index 27c1377f22..bdc608c221 100644
@@ -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) {
author
#2 lore raw

PATCH v2 2/2 virtiofsd: check whether lo_map_reserve returns NULL in main func

In reply to Haotian Li

In 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
index ec1008bceb..0c279ff9fb 100644
@@ -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);
Reviewed-by on the v2 series
#3 lore raw
In reply to Haotian Li
Quoted 9 lines · Haotian Li

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(-)

Please consider printing an error message in Patch 2 so that users can easily tell why the program refused to start.

#4 lore raw
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_advance func
virtiofsd/passthrough_ll.c: check whether lo_map_reserve returns 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.

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

author
#5 lore raw
In reply to Stefan Hajnoczi

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_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(-)

Please consider printing an error message in Patch 2 so that users can easily tell why the program refused to start.