net/ieee802154: fix uninit value bug in dgram_sendmsg
Subsystems (3)
PATCH v2 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.
We should check the msg_namelen is not less than struct sockaddr_ieee802154 when addr_type is SHORT before calling ieee802154_addr_from_sa. So we define IEEE802154_MIN_NAMELEN. And in function ieee802154_addr_from_sa, when addr_type is LONG, we check msg_namelen is not less than sizeof(struct sockaddr_ieee802154). Meanwhile we check in the beginning of function dgram_sendmsg.
Also fixed in raw_bind, dgram_bind, dgram_connect.
Signed-off-by Haimin Zhang <[email protected]>
--- include/net/ieee802154_netdev.h | 9 ++++-- net/ieee802154/socket.c | 51 ++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 22 deletions(-)
include/net/ieee802154_netdev.h +7 -2
@@ -165,8 +165,8 @@ static inline void ieee802154_devaddr_to_raw(void *raw, __le64 addr)memcpy (raw, &temp,IEEE802154_ADDR_LEN ); } -static inline void ieee802154_addr_from_sa (struct ieee802154_addr *a, -const struct ieee802154_addr_sa *sa) +static inline int ieee802154_addr_from_sa (struct ieee802154_addr *a, +const struct ieee802154_addr_sa *sa,int len) { a->mode = sa->addr_type; a->pan_id =cpu_to_le16 (sa->pan_id);
@@ -176,9 +176,14 @@ static inline void ieee802154_addr_from_sa(struct ieee802154_addr *a, a->short_addr =cpu_to_le16 (sa->short_addr);break ;case IEEE802154_ADDR_LONG : +if (len >sizeof (struct sockaddr_ieee802154 )) +return -EINVAL ; a->extended_addr =ieee802154_devaddr_from_raw (sa->hwaddr);break ; +default : +return -EINVAL ; } +return 0 ; } static inline void ieee802154_addr_to_sa(struct ieee802154_addr_sa *sa,
net/ieee802154/socket.c +31 -20
110 lines not on this page · raw message
Signature · 1 line
2.27.0