Skip to contentSkip to conversation

net: ieee802154: handle iftypes as u32

PATCH In review Alexander Aring 2 participants 2 messages Nov 12, 2021 – Nov 16, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ieee802154: handle iftypes as u32

This patch fixes an issue that an u32 netlink value is handled as a signed enum value which doesn't fit into the range of u32 netlink type. If it's handled as -1 value some BIT() evaluation ends in a shift-out-of-bounds issue. To solve the issue we set the to u32 max which is s32 "-1" value to keep backwards compatibility and let the followed enum values start counting at 0. This brings the compiler to never handle the enum as signed and a check if the value is above NL802154_IFTYPE_MAX should filter -1 out.

Fixes f3ea5e44231a ("ieee802154: add new interface command")
---
 include/net/nl802154.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
include/net/nl802154.h +4 -3
index ddcee128f5d9..145acb8f2509 100644
@@ -19,6 +19,8 @@
  *
  */
 
+#include <linux/types.h>
+
 #define NL802154_GENL_NAME "nl802154"
 
 enum nl802154_commands {
@@ -150,10 +152,9 @@ enum nl802154_attrs {
 };
 
 enum nl802154_iftype {
-	/* for backwards compatibility TODO */
-	NL802154_IFTYPE_UNSPEC = -1,
+	NL802154_IFTYPE_UNSPEC = (~(__u32)0),
 
-	NL802154_IFTYPE_NODE,
+	NL802154_IFTYPE_NODE = 0,
 	NL802154_IFTYPE_MONITOR,
 	NL802154_IFTYPE_COORD,
 
Signature · 1 line
2.27.0
maintainer
#1 lore raw

Hello.

Quoted 31 lines · Alexander Aring

This patch fixes an issue that an u32 netlink value is handled as a signed enum value which doesn't fit into the range of u32 netlink type. If it's handled as -1 value some BIT() evaluation ends in a shift-out-of-bounds issue. To solve the issue we set the to u32 max which is s32 "-1" value to keep backwards compatibility and let the followed enum values start counting at 0. This brings the compiler to never handle the enum as signed and a check if the value is above NL802154_IFTYPE_MAX should filter -1 out.

Fixes f3ea5e44231a ("ieee802154: add new interface command")
---
  include/net/nl802154.h | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
include/net/nl802154.h +2 -0
index ddcee128f5d9..145acb8f2509 100644
@@ -19,6 +19,8 @@
   *
   */
 
+#include <linux/types.h>
+
  #define NL802154_GENL_NAME "nl802154"
 
  enum nl802154_commands {
@@ -150,10 +152,9 @@ enum nl802154_attrs {
  };
 

include/net/nl802154.h enum nl802154_attrs { · line 160

Quoted 10 lines
include/net/nl802154.h +2 -3
  enum nl802154_iftype {
-	/* for backwards compatibility TODO */
-	NL802154_IFTYPE_UNSPEC = -1,
+	NL802154_IFTYPE_UNSPEC = (~(__u32)0),
 
-	NL802154_IFTYPE_NODE,
+	NL802154_IFTYPE_NODE = 0,
  	NL802154_IFTYPE_MONITOR,
  	NL802154_IFTYPE_COORD,
 

This patch has been applied to the wpan tree and will be part of the next pull request to net. Thanks!

regards
Stefan Schmidt