linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: ieee802154: fix shift-out-of-bound in nl802154_new_interface
@ 2021-11-11 14:58 Dongliang Mu
  2021-11-12  3:12 ` Alexander Aring
  0 siblings, 1 reply; 3+ messages in thread
From: Dongliang Mu @ 2021-11-11 14:58 UTC (permalink / raw)
  To: Alexander Aring, Stefan Schmidt, David S. Miller, Jakub Kicinski,
	Marcel Holtmann
  Cc: Dongliang Mu, linux-wpan, netdev, linux-kernel

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) [1].

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

Fixes: 65318680c97c ("ieee802154: add iftypes capability")
Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
---
 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..0613867d43ce 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] net: ieee802154: fix shift-out-of-bound in nl802154_new_interface
  2021-11-11 14:58 [PATCH v2] net: ieee802154: fix shift-out-of-bound in nl802154_new_interface Dongliang Mu
@ 2021-11-12  3:12 ` Alexander Aring
  2021-11-12  7:22   ` Dongliang Mu
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Aring @ 2021-11-12  3:12 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: Stefan Schmidt, David S. Miller, Jakub Kicinski, Marcel Holtmann,
	linux-wpan - ML, open list:NETWORKING [GENERAL],
	kernel list

Hi,

On Thu, 11 Nov 2021 at 09:59, Dongliang Mu <mudongliangabcd@gmail.com> wrote:
>
> 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) [1].
>
> Fix this by adding a condition to check if the variable type is
> larger than NL802154_IFTYPE_UNSPEC(-1).
>

Thanks.

I just sent another patch to fix this issue. The real problem here is
that the enum type doesn't fit into the u32 netlink range as I
mentioned some months ago. [0] Sorry for the delayed fix.

- Alex

[0] https://lore.kernel.org/linux-wpan/CAB_54W62WZCcPintGnu-kqzCmgAH7EsJxP9oaeD2NVZ03e_2Wg@mail.gmail.com/T/#t

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] net: ieee802154: fix shift-out-of-bound in nl802154_new_interface
  2021-11-12  3:12 ` Alexander Aring
@ 2021-11-12  7:22   ` Dongliang Mu
  0 siblings, 0 replies; 3+ messages in thread
From: Dongliang Mu @ 2021-11-12  7:22 UTC (permalink / raw)
  To: Alexander Aring
  Cc: Stefan Schmidt, David S. Miller, Jakub Kicinski, Marcel Holtmann,
	linux-wpan - ML, open list:NETWORKING [GENERAL],
	kernel list

On Fri, Nov 12, 2021 at 11:12 AM Alexander Aring <alex.aring@gmail.com> wrote:
>
> Hi,
>
> On Thu, 11 Nov 2021 at 09:59, Dongliang Mu <mudongliangabcd@gmail.com> wrote:
> >
> > 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) [1].
> >
> > Fix this by adding a condition to check if the variable type is
> > larger than NL802154_IFTYPE_UNSPEC(-1).
> >
>
> Thanks.
>
> I just sent another patch to fix this issue. The real problem here is
> that the enum type doesn't fit into the u32 netlink range as I
> mentioned some months ago. [0] Sorry for the delayed fix.

It's fine. This fix hits the core of the underlying bug.

>
> - Alex
>
> [0] https://lore.kernel.org/linux-wpan/CAB_54W62WZCcPintGnu-kqzCmgAH7EsJxP9oaeD2NVZ03e_2Wg@mail.gmail.com/T/#t

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-12  7:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-11 14:58 [PATCH v2] net: ieee802154: fix shift-out-of-bound in nl802154_new_interface Dongliang Mu
2021-11-12  3:12 ` Alexander Aring
2021-11-12  7:22   ` Dongliang Mu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).