diff mbox series

[2/5] 9p: virtio: fix unlikely null pointer deref in handle_rerror

Message ID 20230427-scan-build-v1-2-efa05d65e2da@codewreck.org (mailing list archive)
State Superseded
Headers show
Series Fix scan-build warnings | expand

Commit Message

Dominique Martinet April 27, 2023, 11:23 a.m. UTC
handle_rerror can dereference the pages pointer, but it is not
necessarily set for small payloads.
In practice these should be filtered out by the size check, but
might as well double-check explicitly.

This fixes the following scan-build warnings:
net/9p/trans_virtio.c:401:24: warning: Dereference of null pointer [core.NullDereference]
                memcpy_from_page(to, *pages++, offs, n);
                                     ^~~~~~~~
net/9p/trans_virtio.c:406:23: warning: Dereference of null pointer (loaded from variable 'pages') [core.NullDereference]
        memcpy_from_page(to, *pages, offs, size);
                             ^~~~~~

Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
---
 net/9p/trans_virtio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Horman May 2, 2023, 3:28 p.m. UTC | #1
On Thu, Apr 27, 2023 at 08:23:35PM +0900, Dominique Martinet wrote:
> handle_rerror can dereference the pages pointer, but it is not
> necessarily set for small payloads.
> In practice these should be filtered out by the size check, but
> might as well double-check explicitly.
> 
> This fixes the following scan-build warnings:
> net/9p/trans_virtio.c:401:24: warning: Dereference of null pointer [core.NullDereference]
>                 memcpy_from_page(to, *pages++, offs, n);
>                                      ^~~~~~~~
> net/9p/trans_virtio.c:406:23: warning: Dereference of null pointer (loaded from variable 'pages') [core.NullDereference]
>         memcpy_from_page(to, *pages, offs, size);
>                              ^~~~~~
> 
> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>

Reviewed-by: Simon Horman <simon.horman@corigine.com>
diff mbox series

Patch

diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 3c27ffb781e3..2c9495ccda6b 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -384,7 +384,7 @@  static void handle_rerror(struct p9_req_t *req, int in_hdr_len,
 	void *to = req->rc.sdata + in_hdr_len;
 
 	// Fits entirely into the static data?  Nothing to do.
-	if (req->rc.size < in_hdr_len)
+	if (req->rc.size < in_hdr_len || !pages)
 		return;
 
 	// Really long error message?  Tough, truncate the reply.  Might get