]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/virtio: check mmap return value in vringh_test
authorlonglong yan <yanlonglong@kylinos.cn>
Fri, 5 Jun 2026 02:14:45 +0000 (10:14 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 10 Jun 2026 06:16:59 +0000 (02:16 -0400)
In parallel_test(), the return values of mmap() for both host_map and
guest_map are not checked against MAP_FAILED. If mmap() fails, the
subsequent code will dereference the invalid pointer, leading to a
segmentation fault.

Add MAP_FAILED checks after both mmap() calls, using err() to report
the error and exit, consistent with the existing error handling style
in this file (e.g., the open() call on line 149).

Fixes: 1515c5ce26ae ("tools/virtio: add vring_test.")
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20260605021446.1611-1-yanlonglong@kylinos.cn>

tools/virtio/vringh_test.c

index b9591223437a64d2fb3e527124ddb6b6bad524fb..5ea6d29bc992d299ba724c5b82644aa50e1a0c85 100644 (file)
@@ -159,7 +159,12 @@ static int parallel_test(u64 features,
 
        /* Parent and child use separate addresses, to check our mapping logic! */
        host_map = mmap(NULL, mapsize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+       if (host_map == MAP_FAILED)
+               err(1, "mmap host_map");
+
        guest_map = mmap(NULL, mapsize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+       if (guest_map == MAP_FAILED)
+               err(1, "mmap guest_map");
 
        pipe_ret = pipe(to_guest);
        assert(!pipe_ret);