netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/ieee802154: fix uninit value bug in dgram_sendmsg
@ 2022-08-22  7:19 Haimin Zhang
  2022-08-23  8:40 ` Stefan Schmidt
  0 siblings, 1 reply; 6+ messages in thread
From: Haimin Zhang @ 2022-08-22  7:19 UTC (permalink / raw)
  To: alex.aring, stefan, davem, edumazet, kuba, pabeni, linux-wpan,
	netdev, linux-kernel
  Cc: Haimin Zhang

There is uninit value bug in dgram_sendmsg function in
net/ieee802154/socket.c when the length of valid data pointed by the
msg->msg_name isn't verified.

This length is specified by msg->msg_namelen. Function
ieee802154_addr_from_sa is called by dgram_sendmsg, which use
msg->msg_name as struct sockaddr_ieee802154* and read it, that will
eventually lead to uninit value read. So we should check the length of
msg->msg_name is not less than sizeof(struct sockaddr_ieee802154)
before entering the ieee802154_addr_from_sa.

Signed-off-by: Haimin Zhang <tcs_kernel@tencent.com>
---
 net/ieee802154/socket.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/ieee802154/socket.c b/net/ieee802154/socket.c
index 718fb77bb..efbe08590 100644
--- a/net/ieee802154/socket.c
+++ b/net/ieee802154/socket.c
@@ -655,6 +655,10 @@ static int dgram_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
 	if (msg->msg_name) {
 		DECLARE_SOCKADDR(struct sockaddr_ieee802154*,
 				 daddr, msg->msg_name);
+		if (msg->msg_namelen < sizeof(*daddr)) {
+			err = -EINVAL;
+			goto out_skb;
+		}
 
 		ieee802154_addr_from_sa(&dst_addr, &daddr->addr);
 	} else {
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-08-30  7:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-22  7:19 [PATCH] net/ieee802154: fix uninit value bug in dgram_sendmsg Haimin Zhang
2022-08-23  8:40 ` Stefan Schmidt
2022-08-23 12:22   ` Alexander Aring
     [not found]     ` <CAB2z9exhnzte0rpT9t6=VpFCm9x+zZdmr01UHFxqvYy8y9ifag@mail.gmail.com>
2022-08-24 12:38       ` Alexander Aring
2022-08-29  9:08     ` Stefan Schmidt
2022-08-30  7:04       ` zhang haiming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).