net/ieee802154: fix uninit value bug in dgram_sendmsg
Subsystems (3)
PATCH 1/1 net/ieee802154: fix uninit value bug in dgram_sendmsg
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.
--- net/ieee802154/socket.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ieee802154/socket.c +4 -0
@@ -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 {
Signature · 1 line
2.27.0
Stefan Schmidt
maintainerHello.
Quoted 4 lines · Haimin Zhang
There is uninit value bug in
dgram_sendmsgfunction innet/ieee802154/socket.cwhen the length of valid data pointed by themsg->msg_nameisn't verified.
Quoted 8 lines
This length is specified by
msg->msg_namelen. Functionieee802154_addr_from_sais called bydgram_sendmsg, which usemsg->msg_nameas struct sockaddr_ieee802154* and read it, that will eventually lead to uninit value read. So we should check the length ofmsg->msg_nameis not less thansizeof(struct sockaddr_ieee802154)before entering theieee802154_addr_from_sa.Signed-off-by Haimin Zhang <[email protected]>
This patch has been applied to the wpan tree and will be part of the next pull request to net. Thanks!
Btw, I got a warning from the checkpatch script that your author and SOB email addresses do not match. Might be a good idea to fix this.
If you are having trouble to send patches through the company mail server there is always the option to use the gmail address for sending the mail and an internal From: header in the patch to fix up the author.
regards
Stefan Schmidt
Hi,
Quoted 15 lines · Stefan Schmidt
Hello.
Quoted 11 lines · Haimin Zhang
There is uninit value bug in
dgram_sendmsgfunction innet/ieee802154/socket.cwhen the length of valid data pointed by themsg->msg_nameisn't verified.This length is specified by
msg->msg_namelen. Functionieee802154_addr_from_sais called bydgram_sendmsg, which usemsg->msg_nameas struct sockaddr_ieee802154* and read it, that will eventually lead to uninit value read. So we should check the length ofmsg->msg_nameis not less thansizeof(struct sockaddr_ieee802154)before entering theieee802154_addr_from_sa.
Quoted 5 lines
Quoted 1 line
Signed-off-by Haimin Zhang <[email protected]>This patch has been applied to the wpan tree and will be part of the next pull request to net. Thanks!
For me this patch is buggy or at least it is questionable how to deal with the size of ieee802154_addr_sa here.
There should be a helper to calculate the size which depends on the addr_type field. It is not required to send the last 6 bytes if addr_type is IEEE802154_ADDR_SHORT.
Nitpick is that we should check in the beginning of that function.
- Alex
A message that is not in the archive (sent off-list or not yet received): CAB2z9exhnzte0rpT9t6=VpFCm9x+zZdmr01UHFxqvYy8y9ifag@mail.gmail.com
Hi,
cc mailing lists again.
Quoted 3 lines · zhang haiming
If
msg_namelenis too small like 1, theaddr_typefield will be unexpected. Meanwhile, checkmsg_namelen<sizeof(*daddr)is
Then check if space for addr_type is available, if not -EINVAL. If addr_type available, evaluate it, if it's unknown -EINVAL, the minimum length differs here if it's known.
Quoted 2 lines
necessary and enough as
dgram_bindanddgram_connectdid.
you probably found similar issues.
It is a nitpick and I see that the current behaviour is not correct here.
- Alex
Stefan Schmidt
maintainerHello Alex.
Quoted 19 lines · Alexander Aring
Hi,
Quoted 15 lines · Stefan Schmidt
Hello.
Quoted 11 lines · Haimin Zhang
There is uninit value bug in
dgram_sendmsgfunction innet/ieee802154/socket.cwhen the length of valid data pointed by themsg->msg_nameisn't verified.This length is specified by
msg->msg_namelen. Functionieee802154_addr_from_sais called bydgram_sendmsg, which usemsg->msg_nameas struct sockaddr_ieee802154* and read it, that will eventually lead to uninit value read. So we should check the length ofmsg->msg_nameis not less thansizeof(struct sockaddr_ieee802154)before entering theieee802154_addr_from_sa.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Haimin Zhang <[email protected]>This patch has been applied to the wpan tree and will be part of the next pull request to net. Thanks!
For me this patch is buggy or at least it is questionable how to deal with the size of
ieee802154_addr_sahere.
You are right. I completely missed this. Thanks for spotting!
Quoted 4 lines
There should be a helper to calculate the size which depends on the
addr_typefield. It is not required to send the last 6 bytes ifaddr_typeisIEEE802154_ADDR_SHORT.
Nitpick is that we should check in the beginning of that function.
Haimin, in ieee802154 we could have two different sizes for ieee802154_addr_sa depending on the addr_type. We have short and extended addresses.
Could you please rework this patch to take this into account as Alex suggested?
I reverted your original patch from my tree.
regards
Stefan Schmidt
Thanks to all.
I have sent patch v2 to fix this.
Quoted 51 lines · Stefan Schmidt
Hello Alex.
Quoted 19 lines · Alexander Aring
Hi,
Quoted 15 lines · Stefan Schmidt
Hello.
Quoted 11 lines · Haimin Zhang
There is uninit value bug in
dgram_sendmsgfunction innet/ieee802154/socket.cwhen the length of valid data pointed by themsg->msg_nameisn't verified.This length is specified by
msg->msg_namelen. Functionieee802154_addr_from_sais called bydgram_sendmsg, which usemsg->msg_nameas struct sockaddr_ieee802154* and read it, that will eventually lead to uninit value read. So we should check the length ofmsg->msg_nameis not less thansizeof(struct sockaddr_ieee802154)before entering theieee802154_addr_from_sa.Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Haimin Zhang <[email protected]>This patch has been applied to the wpan tree and will be part of the next pull request to net. Thanks!
For me this patch is buggy or at least it is questionable how to deal with the size of
ieee802154_addr_sahere.You are right. I completely missed this. Thanks for spotting!
Quoted 4 lines
There should be a helper to calculate the size which depends on the
addr_typefield. It is not required to send the last 6 bytes ifaddr_typeisIEEE802154_ADDR_SHORT.
Nitpick is that we should check in the beginning of that function.Haimin, in ieee802154 we could have two different sizes for
ieee802154_addr_sadepending on theaddr_type. We have short and extended addresses.Could you please rework this patch to take this into account as Alex suggested?
I reverted your original patch from my tree.
regards
Stefan Schmidt