Skip to content

Commit 4e1795d

Browse files
Stefan Schmidtholtmann
authored andcommitted
nl802154: stricter input checking for boolean inputs
So far we handled boolean input by forcing them with !! and assigning them into a bool. This allowed userspace to send values > 1 which were used as 1. We should be stricter here and return -EINVAL for all but 0 or 1. Signed-off-by: Stefan Schmidt <[email protected]> Acked-by: Alexander Aring <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent df94536 commit 4e1795d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

net/ieee802154/nl802154.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,15 +1034,19 @@ static int nl802154_set_lbt_mode(struct sk_buff *skb, struct genl_info *info)
10341034
struct cfg802154_registered_device *rdev = info->user_ptr[0];
10351035
struct net_device *dev = info->user_ptr[1];
10361036
struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1037-
bool mode;
1037+
int mode;
10381038

10391039
if (netif_running(dev))
10401040
return -EBUSY;
10411041

10421042
if (!info->attrs[NL802154_ATTR_LBT_MODE])
10431043
return -EINVAL;
10441044

1045-
mode = !!nla_get_u8(info->attrs[NL802154_ATTR_LBT_MODE]);
1045+
mode = nla_get_u8(info->attrs[NL802154_ATTR_LBT_MODE]);
1046+
1047+
if (mode != 0 && mode != 1)
1048+
return -EINVAL;
1049+
10461050
if (!wpan_phy_supported_bool(mode, rdev->wpan_phy.supported.lbt))
10471051
return -EINVAL;
10481052

@@ -1055,15 +1059,19 @@ nl802154_set_ackreq_default(struct sk_buff *skb, struct genl_info *info)
10551059
struct cfg802154_registered_device *rdev = info->user_ptr[0];
10561060
struct net_device *dev = info->user_ptr[1];
10571061
struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1058-
bool ackreq;
1062+
int ackreq;
10591063

10601064
if (netif_running(dev))
10611065
return -EBUSY;
10621066

10631067
if (!info->attrs[NL802154_ATTR_ACKREQ_DEFAULT])
10641068
return -EINVAL;
10651069

1066-
ackreq = !!nla_get_u8(info->attrs[NL802154_ATTR_ACKREQ_DEFAULT]);
1070+
ackreq = nla_get_u8(info->attrs[NL802154_ATTR_ACKREQ_DEFAULT]);
1071+
1072+
if (ackreq != 0 && ackreq != 1)
1073+
return -EINVAL;
1074+
10671075
return rdev_set_ackreq_default(rdev, wpan_dev, ackreq);
10681076
}
10691077

0 commit comments

Comments
 (0)