wifi: cfg80211: fix CQM for non-range use
Subsystems (3)
Michael Walle
build botHi Johannes,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on wireless-next/main]
[also build test WARNING on wireless/main linus/master next-20231108] [cannot apply to v6.6]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Johannes-Berg/wifi-cfg80211-fix-CQM-for-non-range-use/20231107-071337 base: https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main patch link: https://lore.kernel.org/r/20231106231715.3a506ac2dadb.Ie774b85b9d4ff934a1236e77096cb9c6c9fe6561%40changeid patch subject: [RFC PATCH] wifi: cfg80211: fix CQM for non-range use config: x86_64-buildonly-randconfig-006-20231108 (https://download.01.org/0day-ci/archive/20231109/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231109/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
net/wireless/nl80211.c: In function 'nl80211_set_cqm_rssi.isra':
>> net/wireless/nl80211.c:12892:17: warning: 'memcpy' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
12892 | memcpy(cqm_config->rssi_thresholds, thresholds,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12893 | flex_array_size(cqm_config, rssi_thresholds,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12894 | n_thresholds));
| ~~~~~~~~~~~~~~vim +/memcpy +12892 net/wireless/nl80211.c
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12840
d6dc1a38635897 Juuso Oikarinen 2010-03-23 12841 static int nl80211_set_cqm_rssi(struct genl_info *info,
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12842 const s32 *thresholds, int n_thresholds,
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12843 u32 hysteresis)
d6dc1a38635897 Juuso Oikarinen 2010-03-23 12844 {
4c476991062a0a Johannes Berg 2010-10-04 12845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
37c20b2effe987 Johannes Berg 2023-08-16 12846 struct cfg80211_cqm_config *cqm_config = NULL, *old;
4c476991062a0a Johannes Berg 2010-10-04 12847 struct net_device *dev = info->user_ptr[1];
1da5fcc86d7104 Johannes Berg 2013-08-06 12848 struct wireless_dev *wdev = dev->ieee80211_ptr;
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12849 s32 prev = S32_MIN;
7d6904bf26b96e Johannes Berg 2023-10-05 12850 int i, err;
d6dc1a38635897 Juuso Oikarinen 2010-03-23 12851
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12852 /* Check all values negative and sorted */
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12853 for (i = 0; i < n_thresholds; i++) {
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12854 if (thresholds[i] > 0 || thresholds[i] <= prev)
d6dc1a38635897 Juuso Oikarinen 2010-03-23 12855 return -EINVAL;
d6dc1a38635897 Juuso Oikarinen 2010-03-23 12856
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12857 prev = thresholds[i];
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12858 }
d6dc1a38635897 Juuso Oikarinen 2010-03-23 12859
074ac8df9f93f2 Johannes Berg 2010-09-16 12860 if (wdev->iftype != NL80211_IFTYPE_STATION &&
4c476991062a0a Johannes Berg 2010-10-04 12861 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
4c476991062a0a Johannes Berg 2010-10-04 12862 return -EOPNOTSUPP;
d6dc1a38635897 Juuso Oikarinen 2010-03-23 12863
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12864 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12865 n_thresholds = 0;
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12866
7d6904bf26b96e Johannes Berg 2023-10-05 12867 old = wiphy_dereference(wdev->wiphy, wdev->cqm_config);
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12868
54e1e1c490f4db Johannes Berg 2023-11-06 12869 /* if already disabled just succeed */
54e1e1c490f4db Johannes Berg 2023-11-06 12870 if (!n_thresholds && !old)
54e1e1c490f4db Johannes Berg 2023-11-06 12871 return 0;
54e1e1c490f4db Johannes Berg 2023-11-06 12872
54e1e1c490f4db Johannes Berg 2023-11-06 12873 if (n_thresholds > 1) {
54e1e1c490f4db Johannes Berg 2023-11-06 12874 if (!wiphy_ext_feature_isset(&rdev->wiphy,
54e1e1c490f4db Johannes Berg 2023-11-06 12875 NL80211_EXT_FEATURE_CQM_RSSI_LIST) ||
54e1e1c490f4db Johannes Berg 2023-11-06 12876 !rdev->ops->set_cqm_rssi_range_config)
54e1e1c490f4db Johannes Berg 2023-11-06 12877 return -EOPNOTSUPP;
54e1e1c490f4db Johannes Berg 2023-11-06 12878 } else {
54e1e1c490f4db Johannes Berg 2023-11-06 12879 if (!rdev->ops->set_cqm_rssi_config)
54e1e1c490f4db Johannes Berg 2023-11-06 12880 return -EOPNOTSUPP;
54e1e1c490f4db Johannes Berg 2023-11-06 12881 }
54e1e1c490f4db Johannes Berg 2023-11-06 12882
37c20b2effe987 Johannes Berg 2023-08-16 12883 if (n_thresholds) {
40f231e75a1d98 Len Baker 2021-09-19 12884 cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds,
40f231e75a1d98 Len Baker 2021-09-19 12885 n_thresholds),
40f231e75a1d98 Len Baker 2021-09-19 12886 GFP_KERNEL);
076fc8775dafe9 Johannes Berg 2023-08-29 12887 if (!cqm_config)
076fc8775dafe9 Johannes Berg 2023-08-29 12888 return -ENOMEM;
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12889
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12890 cqm_config->rssi_hyst = hysteresis;
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12891 cqm_config->n_rssi_thresholds = n_thresholds;
4a4b8169501b18 Andrew Zaborowski 2017-02-10 @12892 memcpy(cqm_config->rssi_thresholds, thresholds,
40f231e75a1d98 Len Baker 2021-09-19 12893 flex_array_size(cqm_config, rssi_thresholds,
40f231e75a1d98 Len Baker 2021-09-19 12894 n_thresholds));
54e1e1c490f4db Johannes Berg 2023-11-06 12895 cqm_config->use_range_api = n_thresholds > 1 ||
54e1e1c490f4db Johannes Berg 2023-11-06 12896 !rdev->ops->set_cqm_rssi_config;
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12897
37c20b2effe987 Johannes Berg 2023-08-16 12898 rcu_assign_pointer(wdev->cqm_config, cqm_config);
54e1e1c490f4db Johannes Berg 2023-11-06 12899
54e1e1c490f4db Johannes Berg 2023-11-06 12900 if (cqm_config->use_range_api)
54e1e1c490f4db Johannes Berg 2023-11-06 12901 err = cfg80211_cqm_rssi_update(rdev, dev, cqm_config);
54e1e1c490f4db Johannes Berg 2023-11-06 12902 else
54e1e1c490f4db Johannes Berg 2023-11-06 12903 err = rdev_set_cqm_rssi_config(rdev, dev,
54e1e1c490f4db Johannes Berg 2023-11-06 12904 thresholds[0],
54e1e1c490f4db Johannes Berg 2023-11-06 12905 hysteresis);
37c20b2effe987 Johannes Berg 2023-08-16 12906 } else {
37c20b2effe987 Johannes Berg 2023-08-16 12907 RCU_INIT_POINTER(wdev->cqm_config, NULL);
54e1e1c490f4db Johannes Berg 2023-11-06 12908 /* if enabled as range also disable via range */
54e1e1c490f4db Johannes Berg 2023-11-06 12909 if (old->use_range_api)
54e1e1c490f4db Johannes Berg 2023-11-06 12910 err = rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
54e1e1c490f4db Johannes Berg 2023-11-06 12911 else
54e1e1c490f4db Johannes Berg 2023-11-06 12912 err = rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12913 }
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12914
37c20b2effe987 Johannes Berg 2023-08-16 12915 if (err) {
37c20b2effe987 Johannes Berg 2023-08-16 12916 rcu_assign_pointer(wdev->cqm_config, old);
37c20b2effe987 Johannes Berg 2023-08-16 12917 kfree_rcu(cqm_config, rcu_head);
37c20b2effe987 Johannes Berg 2023-08-16 12918 } else {
37c20b2effe987 Johannes Berg 2023-08-16 12919 kfree_rcu(old, rcu_head);
37c20b2effe987 Johannes Berg 2023-08-16 12920 }
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12921
4a4b8169501b18 Andrew Zaborowski 2017-02-10 12922 return err;
d6dc1a38635897 Juuso Oikarinen 2010-03-23 12923 }
d6dc1a38635897 Juuso Oikarinen 2010-03-23 12924 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Johannes Berg
maintainerQuoted 9 lines · Michael Walle
Hi,
Quoted 4 lines
net/wireless/nl80211.c: In function 'nl80211_set_cqm_rssi.isra':net/wireless/nl80211.c:12892:17: warning: 'memcpy' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]FWIW, I'm getting the same error with the current next (next-20231128).
I actually forgot about that, but does anyone actually know what this is trying to tell me?
The code seems to be
if (n_thresholds) {
cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds,
n_thresholds),
GFP_KERNEL);
if (!cqm_config)
return -ENOMEM;
cqm_config->rssi_hyst = hysteresis;
cqm_config->n_rssi_thresholds = n_thresholds;
memcpy(cqm_config->rssi_thresholds, thresholds,
flex_array_size(cqm_config, rssi_thresholds,
n_thresholds));Or does it just want to say n_thresholds shouldn't be a signed variable?
johannes
Quoted 30 lines · Johannes Berg
Quoted 9 lines · Michael Walle
Hi,
Quoted 4 lines
net/wireless/nl80211.c: In function 'nl80211_set_cqm_rssi.isra':net/wireless/nl80211.c:12892:17: warning: 'memcpy' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]FWIW, I'm getting the same error with the current next (next-20231128).
I actually forgot about that, but does anyone actually know what this is trying to tell me?
The code seems to be
if (n_thresholds) { cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds, n_thresholds), GFP_KERNEL); if (!cqm_config) return -ENOMEM; cqm_config->rssi_hyst = hysteresis; cqm_config->n_rssi_thresholds = n_thresholds; memcpy(cqm_config->rssi_thresholds, thresholds, flex_array_size(cqm_config, rssi_thresholds, n_thresholds));
Quoted 1 line
Or does it just want to say
n_thresholdsshouldn't be a signed variable?
+Kees for flex array education :)
Quoted 31 lines · Jeff Johnson
Quoted 30 lines · Johannes Berg
Quoted 9 lines · Michael Walle
Hi,
Quoted 4 lines
net/wireless/nl80211.c: In function 'nl80211_set_cqm_rssi.isra':net/wireless/nl80211.c:12892:17: warning: 'memcpy' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]FWIW, I'm getting the same error with the current next (next-20231128).
I actually forgot about that, but does anyone actually know what this is trying to tell me?
The code seems to be
if (n_thresholds) { cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds, n_thresholds), GFP_KERNEL); if (!cqm_config) return -ENOMEM; cqm_config->rssi_hyst = hysteresis; cqm_config->n_rssi_thresholds = n_thresholds; memcpy(cqm_config->rssi_thresholds, thresholds, flex_array_size(cqm_config, rssi_thresholds, n_thresholds));
Quoted 3 lines
Quoted 1 line
Or does it just want to say
n_thresholdsshouldn't be a signed variable?+Kees for flex array education :)
Yeah, I would expect this to mean that there is a code path that GCC found where the value could overflow. It does this when a variable "value range" gets bounded (e.g. an int isn't the full -INT_MAX to INT_MAX range).And flex_array_size() was designed to saturate at SIZE_MIX rather than wrapping around to an unexpected small value, so these are playing together it seems.
However, I would have expected the kzalloc() to blow up _first_.
Regardless, I suspect the addition of "if (n_thresholds > 1)" is what is tripping GCC.
int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
...
return nl80211_set_cqm_rssi(info, thresholds, len / 4,
hysteresis);Now it "knows" there is a path where n_threasholds could be [2, INT_MAX].
Does this warning go away if "len" is made unsigned?
Does adding an upper bounds sanity check help as a work-around, like:
net/wireless/nl80211.c +3 -0
@@ -12855,6 +12855,9 @@ static int nl80211_set_cqm_rssi(struct genl_info *info,s32 prev =S32_MIN ;int i, err; +if (n_thresholds >INT_MAX /sizeof (*thresholds)) +return -EINVAL ; +/* Check all values negative and sorted */ for (i =0 ; i < n_thresholds; i++) {if (thresholds[i] >0 || thresholds[i] <= prev)
Signature · 1 line
Kees Cook
Johannes Berg
maintainerQuoted 8 lines · Kees Cook
Yeah, I would expect this to mean that there is a code path that GCC found where the value could overflow. It does this when a variable "value range" gets bounded (e.g. an int isn't the full -INT_MAX to
INT_MAXrange).Andflex_array_size()was designed to saturate atSIZE_MIXrather than wrapping around to an unexpected small value, so these are playing together it seems.However, I would have expected the
kzalloc()to blow up _first_.
Hmm.
Quoted 10 lines
Regardless, I suspect the addition of "if (
n_thresholds> 1)" is what is tripping GCC.int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); ... return nl80211_set_cqm_rssi(info, thresholds, len / 4, hysteresis);Now it "knows" there is a path where
n_threasholdscould be [2,INT_MAX].
Yeah, it's not _really_ bounded, apart from the message length? But then struct_size() should saturate and fail? But I guess it cannot know that, and limits the object size to 1<<63 - 1 whereas the copy is 1<<64 - 1...
Quoted 1 line
Does this warning go away if "len" is made unsigned?
Thing is, neither Kalle nor I can even reproduce the warning locally, so it's a bit hard to check ... not even with their config and gcc 12.2.0 (nix, rather than debian though.)
Quoted 1 line
Does adding an upper bounds sanity check help as a work-around, like:
So ... no idea!
I guess I can push something to a branch and see if the robot picks it up ...
johannes
Quoted 27 lines · Johannes Berg
Quoted 8 lines · Kees Cook
Yeah, I would expect this to mean that there is a code path that GCC found where the value could overflow. It does this when a variable "value range" gets bounded (e.g. an int isn't the full -INT_MAX to
INT_MAXrange).Andflex_array_size()was designed to saturate atSIZE_MIXrather than wrapping around to an unexpected small value, so these are playing together it seems.However, I would have expected the
kzalloc()to blow up _first_.Hmm.
Quoted 10 lines
Regardless, I suspect the addition of "if (
n_thresholds> 1)" is what is tripping GCC.int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); ... return nl80211_set_cqm_rssi(info, thresholds, len / 4, hysteresis);Now it "knows" there is a path where
n_threasholdscould be [2,INT_MAX].Yeah, it's not _really_ bounded, apart from the message length? But then
struct_size()should saturate and fail? But I guess it cannot know that, and limits the object size to 1<<63 - 1 whereas the copy is 1<<64 - 1...
Quoted 5 lines
Quoted 1 line
Does this warning go away if "len" is made unsigned?
Thing is, neither Kalle nor I can even reproduce the warning locally, so it's a bit hard to check ... not even with their config and gcc 12.2.0 (nix, rather than debian though.)
Ah! Hmm. Let me see if I can coax out the warning locally...
Signature · 1 line
Kees Cook
Johannes Berg
maintainerQuoted 9 lines · Kees Cook
Quoted 6 lines
Quoted 2 lines
Does this warning go away if "len" is made unsigned?
Thing is, neither Kalle nor I can even reproduce the warning locally, so it's a bit hard to check ... not even with their config and gcc 12.2.0 (nix, rather than debian though.)
Ah! Hmm. Let me see if I can coax out the warning locally...
Actually, I see it now with wireless-next + that patch ... I had put it into wireless, not wireless-next :)
johannes
Quoted 27 lines · Johannes Berg
Quoted 8 lines · Kees Cook
Yeah, I would expect this to mean that there is a code path that GCC found where the value could overflow. It does this when a variable "value range" gets bounded (e.g. an int isn't the full -INT_MAX to
INT_MAXrange).Andflex_array_size()was designed to saturate atSIZE_MIXrather than wrapping around to an unexpected small value, so these are playing together it seems.However, I would have expected the
kzalloc()to blow up _first_.Hmm.
Quoted 10 lines
Regardless, I suspect the addition of "if (
n_thresholds> 1)" is what is tripping GCC.int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); ... return nl80211_set_cqm_rssi(info, thresholds, len / 4, hysteresis);Now it "knows" there is a path where
n_threasholdscould be [2,INT_MAX].Yeah, it's not _really_ bounded, apart from the message length? But then
struct_size()should saturate and fail? But I guess it cannot know that, and limits the object size to 1<<63 - 1 whereas the copy is 1<<64 - 1...
Quoted 5 lines
Quoted 1 line
Does this warning go away if "len" is made unsigned?
Thing is, neither Kalle nor I can even reproduce the warning locally, so it's a bit hard to check ... not even with their config and gcc 12.2.0 (nix, rather than debian though.)
I was able to see it with Ubuntu's GCC 12.3.0 and their config. This fixed it for me:
net/wireless/nl80211.c +2 -2
@@ -12845,7 +12845,7 @@ static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, }static int nl80211_set_cqm_rssi (struct genl_info *info, -const s32 *thresholds,int n_thresholds, +const s32 *thresholds,u32 n_thresholds,u32 hysteresis) {struct cfg80211_registered_device *rdev = info->user_ptr[0 ];
@@ -12948,7 +12948,7 @@ static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) attrs[NL80211_ATTR_CQM_RSSI_HYST]) {const s32 *thresholds =nla_data (attrs[NL80211_ATTR_CQM_RSSI_THOLD ]); -int len =nla_len (attrs[NL80211_ATTR_CQM_RSSI_THOLD ]); +u32 len =nla_len (attrs[NL80211_ATTR_CQM_RSSI_THOLD ]);u32 hysteresis =nla_get_u32 (attrs[NL80211_ATTR_CQM_RSSI_HYST ]);if (len %4 )
If that's sensible, I can send a proper patch?
(Oh, it looks like nla_len is actually u16 ... should I use that instead of u32?)
Signature · 1 line
Kees Cook
Johannes Berg
maintainerQuoted 3 lines · Kees Cook
I was able to see it with Ubuntu's GCC 12.3.0 and their config. This fixed it for me:
OK. I guess kernel tree also mattered somehow, and I got confused because I'd applied the patch on wireless, where the robot did it on wireless-next. Not sure how that's different, but OK.
Quoted 24 lines
net/wireless/nl80211.c +2
-2@@ -12845,7 +12845,7 @@ static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, }static int nl80211_set_cqm_rssi (struct genl_info *info, -const s32 *thresholds,int n_thresholds, +const s32 *thresholds,u32 n_thresholds,u32 hysteresis) {struct cfg80211_registered_device *rdev = info->user_ptr[0 ];@@ -12948,7 +12948,7 @@ static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) attrs[NL80211_ATTR_CQM_RSSI_HYST]) {const s32 *thresholds =nla_data (attrs[NL80211_ATTR_CQM_RSSI_THOLD ]); -int len =nla_len (attrs[NL80211_ATTR_CQM_RSSI_THOLD ]); +u32 len =nla_len (attrs[NL80211_ATTR_CQM_RSSI_THOLD ]);u32 hysteresis =nla_get_u32 (attrs[NL80211_ATTR_CQM_RSSI_HYST ]);if (len %4 )
Quoted 1 line
If that's sensible, I can send a proper patch?
Sure, that seems reasonable.
Quoted 2 lines
(Oh, it looks like
nla_lenis actually u16 ... should I use that instead of u32?)
Yeah it's a 16-bit field in the message format. Doesn't really matter?
johannes
Quoted 20 lines · Johannes Berg
Quoted 8 lines · Kees Cook
Yeah, I would expect this to mean that there is a code path that GCC found where the value could overflow. It does this when a variable "value range" gets bounded (e.g. an int isn't the full -INT_MAX to
INT_MAXrange).Andflex_array_size()was designed to saturate atSIZE_MIXrather than wrapping around to an unexpected small value, so these are playing together it seems.However, I would have expected the
kzalloc()to blow up _first_.Hmm.
Quoted 8 lines
Regardless, I suspect the addition of "if (
n_thresholds> 1)" is what is tripping GCC.int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); ... return nl80211_set_cqm_rssi(info, thresholds, len / 4, hysteresis);
Quoted 8 lines
Quoted 2 lines
Now it "knows" there is a path where
n_threasholdscould be [2,INT_MAX].Yeah, it's not _really_ bounded, apart from the message length? But then
struct_size()should saturate and fail? But I guess it cannot know that, and limits the object size to 1<<63 - 1 whereas the copy is 1<<64 - 1...Quoted 1 line
Does this warning go away if "len" is made unsigned?
Actually, this alone fixes it too:
include/net/netlink.h +2 -2
@@ -1214,9 +1214,9 @@ static inline void *nla_data(const struct nlattr *nla)* nla_len - length of payload * @nla: netlink attribute */ -static inline int nla_len (const struct nlattr *nla) +static inline u16 nla_len (const struct nlattr *nla) { -return nla->nla_len -NLA_HDRLEN ; +return nla->nla_len >NLA_HDRLEN ? nla->nla_len -NLA_HDRLEN :0 ; }/**
Signature · 1 line
Kees Cook
Johannes Berg
maintainerQuoted 37 lines · Kees Cook
Quoted 20 lines · Johannes Berg
Quoted 8 lines · Kees Cook
Yeah, I would expect this to mean that there is a code path that GCC found where the value could overflow. It does this when a variable "value range" gets bounded (e.g. an int isn't the full -INT_MAX to
INT_MAXrange).Andflex_array_size()was designed to saturate atSIZE_MIXrather than wrapping around to an unexpected small value, so these are playing together it seems.However, I would have expected the
kzalloc()to blow up _first_.Hmm.
Quoted 8 lines
Regardless, I suspect the addition of "if (
n_thresholds> 1)" is what is tripping GCC.int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); ... return nl80211_set_cqm_rssi(info, thresholds, len / 4, hysteresis);Quoted 8 lines
Quoted 2 lines
Now it "knows" there is a path where
n_threasholdscould be [2,INT_MAX].Yeah, it's not _really_ bounded, apart from the message length? But then
struct_size()should saturate and fail? But I guess it cannot know that, and limits the object size to 1<<63 - 1 whereas the copy is 1<<64 - 1...Quoted 1 line
Does this warning go away if "len" is made unsigned?
Actually, this alone fixes it too:
include/net/netlink.h +0
-0
include/net/netlink.h static inline void *nla_data(const struct nlattr *nla) · line 1221
Quoted 10 lines
include/net/netlink.h +2
-2@@ -1214,9 +1214,9 @@ static inline void *nla_data(const struct nlattr *nla)* nla_len - length of payload * @nla: netlink attribute */ -static inline int nla_len (const struct nlattr *nla) +static inline u16 nla_len (const struct nlattr *nla) { -return nla->nla_len -NLA_HDRLEN ; +return nla->nla_len >NLA_HDRLEN ? nla->nla_len -NLA_HDRLEN :0 ; }
Heh. If you can sell that to Jakub I don't mind, but that might be a harder sell than the int/u32 in our code...
johannes