[PATCH] net: ieee802154: fix shift-out-of-bound in nl802154_new_interface

Subsystems: ieee 802.15.4 subsystem, networking [general], the rest

STALE1731d

2 messages, 2 authors, 2021-11-11 · open the first message on its own page

[PATCH] net: ieee802154: fix shift-out-of-bound in nl802154_new_interface

From: Dongliang Mu <hidden>
Date: 2021-11-11 12:51:57

In nl802154_new_interface, if type retrieved from info->attr is
NL802154_IFTYPE_UNSPEC(-1), i.e., less than NL802154_IFTYPE_MAX,
it will trigger a shift-out-of-bound bug in BIT(type).

Fix this by adding a condition to check if the variable type is
larger than NL802154_IFTYPE_UNSPEC(-1).

Signed-off-by: Dongliang Mu <redacted>
---
 net/ieee802154/nl802154.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 277124f206e0..cecf5ce0aa20 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -915,7 +915,7 @@ static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
 
 	if (info->attrs[NL802154_ATTR_IFTYPE]) {
 		type = nla_get_u32(info->attrs[NL802154_ATTR_IFTYPE]);
-		if (type > NL802154_IFTYPE_MAX ||
+		if (type <= NL802154_IFTYPE_UNSPEC || type > NL802154_IFTYPE_MAX ||
 		    !(rdev->wpan_phy.supported.iftypes & BIT(type)))
 			return -EINVAL;
 	}
-- 
2.25.1

Re: [PATCH] net: ieee802154: fix shift-out-of-bound in nl802154_new_interface

From: Denis Kirjanov <hidden>
Date: 2021-11-11 13:19:28


11/11/21 3:51 PM, Dongliang Mu пишет:
In nl802154_new_interface, if type retrieved from info->attr is
NL802154_IFTYPE_UNSPEC(-1), i.e., less than NL802154_IFTYPE_MAX,
it will trigger a shift-out-of-bound bug in BIT(type).

Fix this by adding a condition to check if the variable type is
larger than NL802154_IFTYPE_UNSPEC(-1).
Please add Fixes tag
quoted hunk
Signed-off-by: Dongliang Mu <redacted>
---
  net/ieee802154/nl802154.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 277124f206e0..cecf5ce0aa20 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -915,7 +915,7 @@ static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
  
  	if (info->attrs[NL802154_ATTR_IFTYPE]) {
  		type = nla_get_u32(info->attrs[NL802154_ATTR_IFTYPE]);
-		if (type > NL802154_IFTYPE_MAX ||
+		if (type <= NL802154_IFTYPE_UNSPEC || type > NL802154_IFTYPE_MAX ||
  		    !(rdev->wpan_phy.supported.iftypes & BIT(type)))
  			return -EINVAL;
  	}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help