* [PATCH wpan] net: ieee802154: handle iftypes as u32
@ 2021-11-12 3:09 Alexander Aring
2021-11-16 18:31 ` Stefan Schmidt
0 siblings, 1 reply; 2+ messages in thread
From: Alexander Aring @ 2021-11-12 3:09 UTC (permalink / raw)
To: mudongliangabcd; +Cc: stefan, linux-wpan, netdev, aahringo
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,
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH wpan] net: ieee802154: handle iftypes as u32
2021-11-12 3:09 [PATCH wpan] net: ieee802154: handle iftypes as u32 Alexander Aring
@ 2021-11-16 18:31 ` Stefan Schmidt
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Schmidt @ 2021-11-16 18:31 UTC (permalink / raw)
To: Alexander Aring, mudongliangabcd; +Cc: linux-wpan, netdev
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-16 18:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-12 3:09 [PATCH wpan] net: ieee802154: handle iftypes as u32 Alexander Aring
2021-11-16 18:31 ` Stefan Schmidt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox