Skip to contentSkip to conversation

net: initialize msg.msg_flags in recvfrom

PATCH Applied Alexander Potapenko 2 participants 2 messages Mar 8, 2017 – Mar 10, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: initialize msg.msg_flags in recvfrom

KMSAN reports a use of uninitialized memory in put_cmsg() because msg.msg_flags in recvfrom haven't been initialized properly. The flag values don't affect the result on this path, but it's still a good idea to initialize them explicitly.

---
Changes since v1:
- removed KMSAN report and reproducer from the description

---
 net/socket.c | 1 +
 1 file changed, 1 insertion(+)
net/socket.c +1 -0
index 2c1e8677ff2d..e0757e648c0c 100644
@@ -1731,6 +1731,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
 	/* We assume all kernel code knows the size of sockaddr_storage */
 	msg.msg_namelen = 0;
 	msg.msg_iocb = NULL;
+	msg.msg_flags = 0;
 	if (sock->file->f_flags & O_NONBLOCK)
 		flags |= MSG_DONTWAIT;
 	err = sock_recvmsg(sock, &msg, flags);
Signature · 1 line
2.12.0.246.ga2ecc84866-goog
maintainer Applied
#1 lore raw

From: Alexander Potapenko <[email protected]>
Date: Wed, 8 Mar 2017 18:08:16 +0100

Quoted 9 lines

KMSAN reports a use of uninitialized memory in put_cmsg() because msg.msg_flags in recvfrom haven't been initialized properly. The flag values don't affect the result on this path, but it's still a good idea to initialize them explicitly.

---
Changes since v1:
- removed KMSAN report and reproducer from the description

Applied, thank you.