Skip to contentSkip to conversation

linux-user: prevent NULL dereference in do_sendrecvmsg_locked()

PATCH Superseded [email protected] 2 participants 3 messages Aug 14, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: prevent NULL dereference in do_sendrecvmsg_locked()

From: Denis Rastyogin <[email protected]>

fd_trans_target_to_host_data() in do_sendrecvmsg_locked() may be called when msg.msg_iov is NULL, for example when sending with MSG_MORE and no actual iovec data is present. Dereferencing msg.msg_iov in this case would lead to a NULL pointer access.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
index 59b2080b98..c7e6c53f08 100644
@@ -3300,7 +3300,7 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp,
     msg.msg_iov = vec;
 
     if (send) {
-        if (fd_trans_target_to_host_data(fd)) {
+        if (fd_trans_target_to_host_data(fd) && msg.msg_iov->iov_len) {
             void *host_msg;
 
             host_msg = g_malloc(msg.msg_iov->iov_len);
Signature · 1 line
2.42.2
#1 lore raw
Quoted 20 lines · On Thu, 14 Aug 2025, 13:53 , <[email protected]> wrote:

From: Denis Rastyogin <[email protected]>

fd_trans_target_to_host_data() in do_sendrecvmsg_locked() may be called when msg.msg_iov is NULL, for example when sending with MSG_MORE and no actual iovec data is present. Dereferencing msg.msg_iov in this case would lead to a NULL pointer access.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index 59b2080b98..c7e6c53f08 100644

linux-user/syscall.c static abi_long do_sendrecvmsg_locked(int fd, struct · line 3305

Quoted 7 lines
linux-user/syscall.c +1 -1
@@ -3300,7 +3300,7 @@ static abi_long do_sendrecvmsg_locked(int fd, struct
 target_msghdr *msgp,
     msg.msg_iov = vec;
 
     if (send) {
-        if (fd_trans_target_to_host_data(fd)) {
+        if (fd_trans_target_to_host_data(fd) && msg.msg_iov->iov_len) {
 

Surely you meant && msg.msg_iov instead of dereferencing the iov_len field? According to the commit message.

             void *host_msg;
Quoted 7 lines
linux-user/syscall.c +0 -1
             host_msg = g_malloc(msg.msg_iov->iov_len);
--

2.42.2

#2 lore raw

PATCH 1/1 linux-user: prevent NULL dereference in do_sendrecvmsg_locked()

Yes, indeed — my mistake. I’ve sent v2 with the fix. Thanks.