1 From f3eceaed9edd7c0e0d9fb057613131f92973626f Mon Sep 17 00:00:00 2001
2 From: Kees Cook <keescook@chromium.org>
3 Date: Fri, 27 Jan 2023 14:38:54 -0800
4 Subject: [PATCH] net: ethernet: mtk_eth_soc: Avoid truncating allocation
6 There doesn't appear to be a reason to truncate the allocation used for
7 flow_info, so do a full allocation and remove the unused empty struct.
8 GCC does not like having a reference to an object that has been
9 partially allocated, as bounds checking may become impossible when
10 such an object is passed to other code. Seen with GCC 13:
12 ../drivers/net/ethernet/mediatek/mtk_ppe.c: In function 'mtk_foe_entry_commit_subflow':
13 ../drivers/net/ethernet/mediatek/mtk_ppe.c:623:18: warning: array subscript 'struct mtk_flow_entry[0]' is partly outside array bounds of 'unsigned char[48]' [-Warray-bounds=]
14 623 | flow_info->l2_data.base_flow = entry;
17 Cc: Felix Fietkau <nbd@nbd.name>
18 Cc: John Crispin <john@phrozen.org>
19 Cc: Sean Wang <sean.wang@mediatek.com>
20 Cc: Mark Lee <Mark-MC.Lee@mediatek.com>
21 Cc: Lorenzo Bianconi <lorenzo@kernel.org>
22 Cc: "David S. Miller" <davem@davemloft.net>
23 Cc: Eric Dumazet <edumazet@google.com>
24 Cc: Jakub Kicinski <kuba@kernel.org>
25 Cc: Paolo Abeni <pabeni@redhat.com>
26 Cc: Matthias Brugger <matthias.bgg@gmail.com>
27 Cc: netdev@vger.kernel.org
28 Cc: linux-arm-kernel@lists.infradead.org
29 Cc: linux-mediatek@lists.infradead.org
30 Signed-off-by: Kees Cook <keescook@chromium.org>
31 Reviewed-by: Simon Horman <simon.horman@corigine.com>
32 Link: https://lore.kernel.org/r/20230127223853.never.014-kees@kernel.org
33 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
35 drivers/net/ethernet/mediatek/mtk_ppe.c | 3 +--
36 drivers/net/ethernet/mediatek/mtk_ppe.h | 1 -
37 2 files changed, 1 insertion(+), 3 deletions(-)
39 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
40 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
41 @@ -601,8 +601,7 @@ mtk_foe_entry_commit_subflow(struct mtk_
42 u32 ib1_mask = mtk_get_ib1_pkt_type_mask(ppe->eth) | MTK_FOE_IB1_UDP;
45 - flow_info = kzalloc(offsetof(struct mtk_flow_entry, l2_data.end),
47 + flow_info = kzalloc(sizeof(*flow_info), GFP_ATOMIC);
51 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
52 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
53 @@ -277,7 +277,6 @@ struct mtk_flow_entry {
55 struct mtk_flow_entry *base_flow;
56 struct hlist_node list;
60 struct rhash_head node;