Tools: hv: correct payload size in netlink_send
PATCH 1/1 Tools: hv: correct payload size in netlink_send
netlink_send is supposed to send just the cn_msg+hv_kvp_msg via netlink. Currently it sets an incorrect iovec size, as reported by valgrind.
In the case of registering with the kernel the allocated buffer is large enough to hold nlmsghdr+cn_msg+hv_kvp_msg, no overrun happens. In the case of responding to the kernel the cn_msg is located in the middle of recv_buffer, after the nlmsghdr. Currently the code in netlink_send adds also the size of nlmsghdr to the payload. But nlmsghdr is a separate iovec. This leads to an (harmless) out-of-bounds access when the kernel processes the iovec. Correct the iovec size of the cn_msg to be just cn_msg + its payload.
--- tools/hv/hv_kvp_daemon.c | 2 +- tools/hv/hv_vss_daemon.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/hv/hv_kvp_daemon.c +1 -1
@@ -1399,7 +1399,7 @@ netlink_send(int fd, struct cn_msg *msg)char buffer[64 ];struct iovec iov[2 ]; - size =NLMSG_SPACE (sizeof (struct cn_msg ) + msg->len); + size =sizeof (struct cn_msg ) + msg->len; nlh = (struct nlmsghdr *)buffer; nlh->nlmsg_seq =0 ;
tools/hv/hv_vss_daemon.c +1 -1
@@ -111,7 +111,7 @@ static int netlink_send(int fd, struct cn_msg *msg)char buffer[64 ];struct iovec iov[2 ]; - size =NLMSG_SPACE (sizeof (struct cn_msg ) + msg->len); + size =sizeof (struct cn_msg ) + msg->len; nlh = (struct nlmsghdr *)buffer; nlh->nlmsg_seq =0 ;
Quoted 12 lines
-----Original Message-----
From: Olaf Hering [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 9:07 AM
To: KY Srinivasan; [email protected]
Cc: [email protected]; Olaf Hering
Subject: [PATCH] Tools: hv: correct payload size innetlink_send
netlink_sendis supposed to send just the cn_msg+hv_kvp_msg via netlink. Currently it sets an incorrect iovec size, as reported by valgrind.
Quoted 8 lines
In the case of registering with the kernel the allocated buffer is large enough to hold nlmsghdr+cn_msg+hv_kvp_msg, no overrun happens. In the case of responding to the kernel the
cn_msgis located in the middle ofrecv_buffer, after the nlmsghdr. Currently the code innetlink_sendadds also the size of nlmsghdr to the payload. But nlmsghdr is a separate iovec. This leads to an (harmless) out-of-bounds access when the kernel processes the iovec. Correct the iovec size of thecn_msgto be justcn_msg+ its payload.
Thanks Olaf.
Quoted 2 lines
Signed-off-by Olaf Hering <[email protected]>
Quoted 31 lines
--- tools/hv/hv_kvp_daemon.c | 2 +- tools/hv/hv_vss_daemon.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)tools/hv/hv_kvp_daemon.c +1
-1@@ -1399,7 +1399,7 @@ netlink_send(int fd, struct cn_msg *msg)char buffer[64 ];struct iovec iov[2 ]; - size =NLMSG_SPACE (sizeof (struct cn_msg ) + msg->len); + size =sizeof (struct cn_msg ) + msg->len; nlh = (struct nlmsghdr *)buffer; nlh->nlmsg_seq =0 ;tools/hv/hv_vss_daemon.c +1
-1@@ -111,7 +111,7 @@ static int netlink_send(int fd, struct cn_msg *msg)char buffer[64 ];struct iovec iov[2 ]; - size =NLMSG_SPACE (sizeof (struct cn_msg ) + msg->len); + size =sizeof (struct cn_msg ) + msg->len; nlh = (struct nlmsghdr *)buffer; nlh->nlmsg_seq =0 ;