Skip to contentSkip to conversation

virtiofsd: Fix potential NULL pointer dereference in virtio_send_msg()

PATCH In review Alex Chen 2 participants 3 messages Dec 10, 2020 – Dec 11, 2020

lore
Share & tools
lore

Alex Chen

author
#0 lore raw

PATCH 1/1 virtiofsd: Fix potential NULL pointer dereference in virtio_send_msg()

The 'ch' will be NULL in the following stack:
send_notify_iov()->fuse_send_msg()->virtio_send_msg(), so we should check 'ch' is valid before dereferencing it

---
 tools/virtiofsd/fuse_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
tools/virtiofsd/fuse_virtio.c +2 -0
index 623812c432..31b2187a15 100644
@@ -205,6 +205,8 @@ static void copy_iov(struct iovec *src_iov, int src_count,
 int virtio_send_msg(struct fuse_session *se, struct fuse_chan *ch,
                     struct iovec *iov, int count)
 {
+    assert(ch);
+
     FVRequest *req = container_of(ch, FVRequest, ch);
     struct fv_QueueInfo *qi = ch->qi;
     VuDev *dev = &se->virtio_dev->dev;
Signature · 1 line
2.19.1
#1 lore raw
Quoted 6 lines · * Alex Chen ([email protected]) wrote:

The 'ch' will be NULL in the following stack:
send_notify_iov()->fuse_send_msg()->virtio_send_msg(), so we should check 'ch' is valid before dereferencing it

Please check, but I don't think we can currently hit this because we never call send_notify_iov - it's currently called by fuse_lowlevel_notify_inval_entry, inval_inode, and fuse_lowlevel_notify_poll -
but I don't think those are called anywhere.

In that case, probably the best fix is to remove those until we put notify back in.

Dave

Quoted 20 lines
---
 tools/virtiofsd/fuse_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
tools/virtiofsd/fuse_virtio.c +2 -0
index 623812c432..31b2187a15 100644
@@ -205,6 +205,8 @@ static void copy_iov(struct iovec *src_iov, int src_count,
 int virtio_send_msg(struct fuse_session *se, struct fuse_chan *ch,
                     struct iovec *iov, int count)
 {
+    assert(ch);
+
     FVRequest *req = container_of(ch, FVRequest, ch);
     struct fv_QueueInfo *qi = ch->qi;
     VuDev *dev = &se->virtio_dev->dev;
Signature · 1 line
2.19.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
author
#2 lore raw

Hi Dave,

Quoted 5 lines · Dr. David Alan Gilbert
Quoted 4 lines · * Alex Chen ([email protected]) wrote:

The 'ch' will be NULL in the following stack:
send_notify_iov()->fuse_send_msg()->virtio_send_msg(), so we should check 'ch' is valid before dereferencing it

Quoted 9 lines
Quoted 2 lines

Please check, but I don't think we can currently hit this because we never call send_notify_iov - it's currently called by fuse_lowlevel_notify_inval_entry, inval_inode, and fuse_lowlevel_notify_poll -
but I don't think those are called anywhere.

Thanks for your review.
The send_notify_iov() is really not being called.

Quoted 3 lines

In that case, probably the best fix is to remove those until we put notify back in.

OK, I will remove those temporarily useless code and send patch v2 to fix this problem.

Thanks,
Alex

Quoted 22 lines

Dave

Quoted 20 lines
---
 tools/virtiofsd/fuse_virtio.c | 2 ++
 1 file changed, 2 insertions(+)
tools/virtiofsd/fuse_virtio.c +2 -0
index 623812c432..31b2187a15 100644
@@ -205,6 +205,8 @@ static void copy_iov(struct iovec *src_iov, int src_count,
 int virtio_send_msg(struct fuse_session *se, struct fuse_chan *ch,
                     struct iovec *iov, int count)
 {
+    assert(ch);
+
     FVRequest *req = container_of(ch, FVRequest, ch);
     struct fv_QueueInfo *qi = ch->qi;
     VuDev *dev = &se->virtio_dev->dev;
Signature · 1 line
2.19.1