Skip to content

Commit

Permalink
net: ieee802154: handle iftypes as u32
Browse files Browse the repository at this point in the history
[ Upstream commit 451dc48c806a7ce9fbec5e7a24ccf4b2c936e834 ]

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: f3ea5e4 ("ieee802154: add new interface command")
Signed-off-by: Alexander Aring <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Stefan Schmidt <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Alexander Aring authored and gregkh committed Dec 1, 2021
1 parent caa6246 commit d67bad9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/net/nl802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
*/

#include <linux/types.h>

#define NL802154_GENL_NAME "nl802154"

enum nl802154_commands {
Expand Down Expand Up @@ -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,

Expand Down

0 comments on commit d67bad9

Please sign in to comment.