* [PATCH AUTOSEL 5.15 10/15] alx: fix OOB-read compiler warning
2023-09-08 18:19 [PATCH AUTOSEL 5.15 01/15] devlink: remove reload failed checks in params get/set callbacks Sasha Levin
@ 2023-09-08 18:19 ` Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 11/15] wifi: mac80211: check S1G action frame size Sasha Levin
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2023-09-08 18:19 UTC (permalink / raw)
To: linux-kernel, stable
Cc: GONG, Ruiqi, GONG, Simon Horman, Paolo Abeni, Sasha Levin,
chris.snook, davem, edumazet, kuba, netdev
From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
[ Upstream commit 3a198c95c95da10ad844cbeade2fe40bdf14c411 ]
The following message shows up when compiling with W=1:
In function ‘fortify_memcpy_chk’,
inlined from ‘alx_get_ethtool_stats’ at drivers/net/ethernet/atheros/alx/ethtool.c:297:2:
./include/linux/fortify-string.h:592:4: error: call to ‘__read_overflow2_field’
declared with attribute warning: detected read beyond size of field (2nd parameter);
maybe use struct_group()? [-Werror=attribute-warning]
592 | __read_overflow2_field(q_size_field, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In order to get alx stats altogether, alx_get_ethtool_stats() reads
beyond hw->stats.rx_ok. Fix this warning by directly copying hw->stats,
and refactor the unnecessarily complicated BUILD_BUG_ON btw.
Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20230821013218.1614265-1-gongruiqi@huaweicloud.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/net/ethernet/atheros/alx/ethtool.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/atheros/alx/ethtool.c b/drivers/net/ethernet/atheros/alx/ethtool.c
index b716adacd8159..7f6b69a523676 100644
--- a/drivers/net/ethernet/atheros/alx/ethtool.c
+++ b/drivers/net/ethernet/atheros/alx/ethtool.c
@@ -292,9 +292,8 @@ static void alx_get_ethtool_stats(struct net_device *netdev,
spin_lock(&alx->stats_lock);
alx_update_hw_stats(hw);
- BUILD_BUG_ON(sizeof(hw->stats) - offsetof(struct alx_hw_stats, rx_ok) <
- ALX_NUM_STATS * sizeof(u64));
- memcpy(data, &hw->stats.rx_ok, ALX_NUM_STATS * sizeof(u64));
+ BUILD_BUG_ON(sizeof(hw->stats) != ALX_NUM_STATS * sizeof(u64));
+ memcpy(data, &hw->stats, sizeof(hw->stats));
spin_unlock(&alx->stats_lock);
}
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH AUTOSEL 5.15 11/15] wifi: mac80211: check S1G action frame size
2023-09-08 18:19 [PATCH AUTOSEL 5.15 01/15] devlink: remove reload failed checks in params get/set callbacks Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 10/15] alx: fix OOB-read compiler warning Sasha Levin
@ 2023-09-08 18:19 ` Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 12/15] netfilter: ebtables: fix fortify warnings in size_entry_mwt() Sasha Levin
2023-09-08 21:44 ` [PATCH AUTOSEL 5.15 01/15] devlink: remove reload failed checks in params get/set callbacks Jacob Keller
3 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2023-09-08 18:19 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Johannes Berg, syzbot+be9c824e6f269d608288, Sasha Levin, johannes,
davem, edumazet, kuba, pabeni, linux-wireless, netdev
From: Johannes Berg <johannes.berg@intel.com>
[ Upstream commit 19e4a47ee74718a22e963e8a647c8c3bfe8bb05c ]
Before checking the action code, check that it even
exists in the frame.
Reported-by: syzbot+be9c824e6f269d608288@syzkaller.appspotmail.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
net/mac80211/rx.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 175ead6b19cb4..26943c93f14c4 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -3557,6 +3557,10 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
break;
goto queue;
case WLAN_CATEGORY_S1G:
+ if (len < offsetofend(typeof(*mgmt),
+ u.action.u.s1g.action_code))
+ break;
+
switch (mgmt->u.action.u.s1g.action_code) {
case WLAN_S1G_TWT_SETUP:
case WLAN_S1G_TWT_TEARDOWN:
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH AUTOSEL 5.15 12/15] netfilter: ebtables: fix fortify warnings in size_entry_mwt()
2023-09-08 18:19 [PATCH AUTOSEL 5.15 01/15] devlink: remove reload failed checks in params get/set callbacks Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 10/15] alx: fix OOB-read compiler warning Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 11/15] wifi: mac80211: check S1G action frame size Sasha Levin
@ 2023-09-08 18:19 ` Sasha Levin
2023-09-08 21:44 ` [PATCH AUTOSEL 5.15 01/15] devlink: remove reload failed checks in params get/set callbacks Jacob Keller
3 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2023-09-08 18:19 UTC (permalink / raw)
To: linux-kernel, stable
Cc: GONG, Ruiqi, GONG, Gustavo A . R . Silva, Kees Cook,
Florian Westphal, Sasha Levin, pablo, kadlec, roopa, razor, davem,
edumazet, kuba, pabeni, netfilter-devel, coreteam, bridge, netdev
From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
[ Upstream commit a7ed3465daa240bdf01a5420f64336fee879c09d ]
When compiling with gcc 13 and CONFIG_FORTIFY_SOURCE=y, the following
warning appears:
In function ‘fortify_memcpy_chk’,
inlined from ‘size_entry_mwt’ at net/bridge/netfilter/ebtables.c:2118:2:
./include/linux/fortify-string.h:592:25: error: call to ‘__read_overflow2_field’
declared with attribute warning: detected read beyond size of field (2nd parameter);
maybe use struct_group()? [-Werror=attribute-warning]
592 | __read_overflow2_field(q_size_field, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The compiler is complaining:
memcpy(&offsets[1], &entry->watchers_offset,
sizeof(offsets) - sizeof(offsets[0]));
where memcpy reads beyong &entry->watchers_offset to copy
{watchers,target,next}_offset altogether into offsets[]. Silence the
warning by wrapping these three up via struct_group().
Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/uapi/linux/netfilter_bridge/ebtables.h | 14 ++++++++------
net/bridge/netfilter/ebtables.c | 3 +--
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/include/uapi/linux/netfilter_bridge/ebtables.h b/include/uapi/linux/netfilter_bridge/ebtables.h
index a494cf43a7552..b0caad82b6937 100644
--- a/include/uapi/linux/netfilter_bridge/ebtables.h
+++ b/include/uapi/linux/netfilter_bridge/ebtables.h
@@ -182,12 +182,14 @@ struct ebt_entry {
unsigned char sourcemsk[ETH_ALEN];
unsigned char destmac[ETH_ALEN];
unsigned char destmsk[ETH_ALEN];
- /* sizeof ebt_entry + matches */
- unsigned int watchers_offset;
- /* sizeof ebt_entry + matches + watchers */
- unsigned int target_offset;
- /* sizeof ebt_entry + matches + watchers + target */
- unsigned int next_offset;
+ __struct_group(/* no tag */, offsets, /* no attrs */,
+ /* sizeof ebt_entry + matches */
+ unsigned int watchers_offset;
+ /* sizeof ebt_entry + matches + watchers */
+ unsigned int target_offset;
+ /* sizeof ebt_entry + matches + watchers + target */
+ unsigned int next_offset;
+ );
unsigned char elems[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
};
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index a09b2fc11c80e..c0389199c0dcb 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -2114,8 +2114,7 @@ static int size_entry_mwt(const struct ebt_entry *entry, const unsigned char *ba
return ret;
offsets[0] = sizeof(struct ebt_entry); /* matches come first */
- memcpy(&offsets[1], &entry->watchers_offset,
- sizeof(offsets) - sizeof(offsets[0]));
+ memcpy(&offsets[1], &entry->offsets, sizeof(entry->offsets));
if (state->buf_kern_start) {
buf_start = state->buf_kern_start + state->buf_kern_offset;
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH AUTOSEL 5.15 01/15] devlink: remove reload failed checks in params get/set callbacks
2023-09-08 18:19 [PATCH AUTOSEL 5.15 01/15] devlink: remove reload failed checks in params get/set callbacks Sasha Levin
` (2 preceding siblings ...)
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 12/15] netfilter: ebtables: fix fortify warnings in size_entry_mwt() Sasha Levin
@ 2023-09-08 21:44 ` Jacob Keller
3 siblings, 0 replies; 5+ messages in thread
From: Jacob Keller @ 2023-09-08 21:44 UTC (permalink / raw)
To: Sasha Levin, linux-kernel, stable
Cc: Jiri Pirko, Ido Schimmel, Jakub Kicinski, David S . Miller,
edumazet, pabeni, jiri, michal.wilczynski, shayd, netdev
On 9/8/2023 11:19 AM, Sasha Levin wrote:
> From: Jiri Pirko <jiri@nvidia.com>
>
> [ Upstream commit 633d76ad01ad0321a1ace3e5cc4fed06753d7ac4 ]
>
> The checks in question were introduced by:
> commit 6b4db2e528f6 ("devlink: Fix use-after-free after a failed reload").
> That fixed an issue of reload with mlxsw driver.
>
> Back then, that was a valid fix, because there was a limitation
> in place that prevented drivers from registering/unregistering params
> when devlink instance was registered.
>
> It was possible to do the fix differently by changing drivers to
> register/unregister params in appropriate places making sure the ops
> operate only on memory which is allocated and initialized. But that,
> as a dependency, would require to remove the limitation mentioned above.
>
> Eventually, this limitation was lifted by:
> commit 1d18bb1a4ddd ("devlink: allow registering parameters after the instance")
>
> Also, the alternative fix (which also fixed another issue) was done by:
> commit 74cbc3c03c82 ("mlxsw: spectrum_acl_tcam: Move devlink param to TCAM code").
>
> Therefore, the checks are no longer relevant. Each driver should make
> sure to have the params registered only when the memory the ops
> are working with is allocated and initialized.
>
> So remove the checks.
>
> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
> Reviewed-by: Ido Schimmel <idosch@nvidia.com>
> Reviewed-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
I believe my comments on the v5.4 backport apply here as well.
Thanks,
Jake
^ permalink raw reply [flat|nested] 5+ messages in thread