Skip to content

Commit 67fb36b

Browse files
longlong yangregkh
authored andcommitted
tools/virtio: check mmap return value in vringh_test
[ Upstream commit ec6177d ] 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: 1515c5c ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6445b94 commit 67fb36b

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

tools/virtio/vringh_test.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ static int parallel_test(u64 features,
159159

160160
/* Parent and child use separate addresses, to check our mapping logic! */
161161
host_map = mmap(NULL, mapsize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
162+
if (host_map == MAP_FAILED)
163+
err(1, "mmap host_map");
164+
162165
guest_map = mmap(NULL, mapsize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
166+
if (guest_map == MAP_FAILED)
167+
err(1, "mmap guest_map");
163168

164169
pipe(to_guest);
165170
pipe(to_host);

0 commit comments

Comments
 (0)