diff mbox series

[wpan] net: ieee802154: handle iftypes as u32

Message ID 20211112030916.685793-1-aahringo@redhat.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [wpan] net: ieee802154: handle iftypes as u32 | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 300 this patch: 107
netdev/cc_maintainers fail 2 blamed authors not CCed: marcel@holtmann.org alex.aring@gmail.com; 4 maintainers not CCed: marcel@holtmann.org kuba@kernel.org alex.aring@gmail.com davem@davemloft.net
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 3
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 lines checked
netdev/kdoc success Errors and warnings before: 6 this patch: 6
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Alexander Aring Nov. 12, 2021, 3:09 a.m. UTC
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")
Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
 include/net/nl802154.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Stefan Schmidt Nov. 16, 2021, 6:31 p.m. UTC | #1
Hello.

On 12.11.21 04:09, Alexander Aring wrote:
> 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")
> Signed-off-by: Alexander Aring <aahringo@redhat.com>
> ---
>   include/net/nl802154.h | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/include/net/nl802154.h b/include/net/nl802154.h
> index ddcee128f5d9..145acb8f2509 100644
> --- a/include/net/nl802154.h
> +++ b/include/net/nl802154.h
> @@ -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,
>   


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

regards
Stefan Schmidt
diff mbox series

Patch

diff --git a/include/net/nl802154.h b/include/net/nl802154.h
index ddcee128f5d9..145acb8f2509 100644
--- a/include/net/nl802154.h
+++ b/include/net/nl802154.h
@@ -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,