All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: ethernet: mtk_eth_soc: Avoid truncating allocation
@ 2023-01-27 22:38 ` Kees Cook
  0 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2023-01-27 22:38 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Kees Cook, John Crispin, Sean Wang, Mark Lee, Lorenzo Bianconi,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Matthias Brugger, netdev, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-hardening

There doesn't appear to be a reason to truncate the allocation used for
flow_info, so do a full allocation and remove the unused empty struct.
GCC does not like having a reference to an object that has been
partially allocated, as bounds checking may become impossible when
such an object is passed to other code. Seen with GCC 13:

../drivers/net/ethernet/mediatek/mtk_ppe.c: In function 'mtk_foe_entry_commit_subflow':
../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=]
  623 |         flow_info->l2_data.base_flow = entry;
      |                  ^~

Cc: Felix Fietkau <nbd@nbd.name>
Cc: John Crispin <john@phrozen.org>
Cc: Sean Wang <sean.wang@mediatek.com>
Cc: Mark Lee <Mark-MC.Lee@mediatek.com>
Cc: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: netdev@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-mediatek@lists.infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/ethernet/mediatek/mtk_ppe.c | 3 +--
 drivers/net/ethernet/mediatek/mtk_ppe.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
index 451a87b1bc20..6883eb34cd8b 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
@@ -615,8 +615,7 @@ mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
 	u32 ib1_mask = mtk_get_ib1_pkt_type_mask(ppe->eth) | MTK_FOE_IB1_UDP;
 	int type;
 
-	flow_info = kzalloc(offsetof(struct mtk_flow_entry, l2_data.end),
-			    GFP_ATOMIC);
+	flow_info = kzalloc(sizeof(*flow_info), GFP_ATOMIC);
 	if (!flow_info)
 		return;
 
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
index 16b02e1d4649..5e8bc48252b1 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
@@ -279,7 +279,6 @@ struct mtk_flow_entry {
 		struct {
 			struct mtk_flow_entry *base_flow;
 			struct hlist_node list;
-			struct {} end;
 		} l2_data;
 	};
 	struct rhash_head node;
-- 
2.34.1


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

* [PATCH] net: ethernet: mtk_eth_soc: Avoid truncating allocation
@ 2023-01-27 22:38 ` Kees Cook
  0 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2023-01-27 22:38 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: Kees Cook, John Crispin, Sean Wang, Mark Lee, Lorenzo Bianconi,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Matthias Brugger, netdev, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-hardening

There doesn't appear to be a reason to truncate the allocation used for
flow_info, so do a full allocation and remove the unused empty struct.
GCC does not like having a reference to an object that has been
partially allocated, as bounds checking may become impossible when
such an object is passed to other code. Seen with GCC 13:

../drivers/net/ethernet/mediatek/mtk_ppe.c: In function 'mtk_foe_entry_commit_subflow':
../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=]
  623 |         flow_info->l2_data.base_flow = entry;
      |                  ^~

Cc: Felix Fietkau <nbd@nbd.name>
Cc: John Crispin <john@phrozen.org>
Cc: Sean Wang <sean.wang@mediatek.com>
Cc: Mark Lee <Mark-MC.Lee@mediatek.com>
Cc: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: netdev@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-mediatek@lists.infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/ethernet/mediatek/mtk_ppe.c | 3 +--
 drivers/net/ethernet/mediatek/mtk_ppe.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
index 451a87b1bc20..6883eb34cd8b 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
@@ -615,8 +615,7 @@ mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
 	u32 ib1_mask = mtk_get_ib1_pkt_type_mask(ppe->eth) | MTK_FOE_IB1_UDP;
 	int type;
 
-	flow_info = kzalloc(offsetof(struct mtk_flow_entry, l2_data.end),
-			    GFP_ATOMIC);
+	flow_info = kzalloc(sizeof(*flow_info), GFP_ATOMIC);
 	if (!flow_info)
 		return;
 
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
index 16b02e1d4649..5e8bc48252b1 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
@@ -279,7 +279,6 @@ struct mtk_flow_entry {
 		struct {
 			struct mtk_flow_entry *base_flow;
 			struct hlist_node list;
-			struct {} end;
 		} l2_data;
 	};
 	struct rhash_head node;
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] net: ethernet: mtk_eth_soc: Avoid truncating allocation
  2023-01-27 22:38 ` Kees Cook
@ 2023-01-28 13:40   ` Simon Horman
  -1 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2023-01-28 13:40 UTC (permalink / raw)
  To: Kees Cook
  Cc: Felix Fietkau, John Crispin, Sean Wang, Mark Lee,
	Lorenzo Bianconi, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Matthias Brugger, netdev, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-hardening

On Fri, Jan 27, 2023 at 02:38:54PM -0800, Kees Cook wrote:
> There doesn't appear to be a reason to truncate the allocation used for
> flow_info, so do a full allocation and remove the unused empty struct.
> GCC does not like having a reference to an object that has been
> partially allocated, as bounds checking may become impossible when
> such an object is passed to other code. Seen with GCC 13:
> 
> ../drivers/net/ethernet/mediatek/mtk_ppe.c: In function 'mtk_foe_entry_commit_subflow':
> ../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=]
>   623 |         flow_info->l2_data.base_flow = entry;
>       |                  ^~
> 

...

> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  drivers/net/ethernet/mediatek/mtk_ppe.c | 3 +--
>  drivers/net/ethernet/mediatek/mtk_ppe.h | 1 -
>  2 files changed, 1 insertion(+), 3 deletions(-)

Reviewed-by: Simon Horman <simon.horman@corigine.com>


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

* Re: [PATCH] net: ethernet: mtk_eth_soc: Avoid truncating allocation
@ 2023-01-28 13:40   ` Simon Horman
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2023-01-28 13:40 UTC (permalink / raw)
  To: Kees Cook
  Cc: Felix Fietkau, John Crispin, Sean Wang, Mark Lee,
	Lorenzo Bianconi, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Matthias Brugger, netdev, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-hardening

On Fri, Jan 27, 2023 at 02:38:54PM -0800, Kees Cook wrote:
> There doesn't appear to be a reason to truncate the allocation used for
> flow_info, so do a full allocation and remove the unused empty struct.
> GCC does not like having a reference to an object that has been
> partially allocated, as bounds checking may become impossible when
> such an object is passed to other code. Seen with GCC 13:
> 
> ../drivers/net/ethernet/mediatek/mtk_ppe.c: In function 'mtk_foe_entry_commit_subflow':
> ../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=]
>   623 |         flow_info->l2_data.base_flow = entry;
>       |                  ^~
> 

...

> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  drivers/net/ethernet/mediatek/mtk_ppe.c | 3 +--
>  drivers/net/ethernet/mediatek/mtk_ppe.h | 1 -
>  2 files changed, 1 insertion(+), 3 deletions(-)

Reviewed-by: Simon Horman <simon.horman@corigine.com>


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] net: ethernet: mtk_eth_soc: Avoid truncating allocation
  2023-01-27 22:38 ` Kees Cook
@ 2023-01-31 10:10   ` patchwork-bot+netdevbpf
  -1 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-01-31 10:10 UTC (permalink / raw)
  To: Kees Cook
  Cc: nbd, john, sean.wang, Mark-MC.Lee, lorenzo, davem, edumazet,
	kuba, pabeni, matthias.bgg, netdev, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-hardening

Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Fri, 27 Jan 2023 14:38:54 -0800 you wrote:
> There doesn't appear to be a reason to truncate the allocation used for
> flow_info, so do a full allocation and remove the unused empty struct.
> GCC does not like having a reference to an object that has been
> partially allocated, as bounds checking may become impossible when
> such an object is passed to other code. Seen with GCC 13:
> 
> ../drivers/net/ethernet/mediatek/mtk_ppe.c: In function 'mtk_foe_entry_commit_subflow':
> ../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=]
>   623 |         flow_info->l2_data.base_flow = entry;
>       |                  ^~
> 
> [...]

Here is the summary with links:
  - net: ethernet: mtk_eth_soc: Avoid truncating allocation
    https://git.kernel.org/netdev/net/c/f3eceaed9edd

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH] net: ethernet: mtk_eth_soc: Avoid truncating allocation
@ 2023-01-31 10:10   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-01-31 10:10 UTC (permalink / raw)
  To: Kees Cook
  Cc: nbd, john, sean.wang, Mark-MC.Lee, lorenzo, davem, edumazet,
	kuba, pabeni, matthias.bgg, netdev, linux-arm-kernel,
	linux-mediatek, linux-kernel, linux-hardening

Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Fri, 27 Jan 2023 14:38:54 -0800 you wrote:
> There doesn't appear to be a reason to truncate the allocation used for
> flow_info, so do a full allocation and remove the unused empty struct.
> GCC does not like having a reference to an object that has been
> partially allocated, as bounds checking may become impossible when
> such an object is passed to other code. Seen with GCC 13:
> 
> ../drivers/net/ethernet/mediatek/mtk_ppe.c: In function 'mtk_foe_entry_commit_subflow':
> ../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=]
>   623 |         flow_info->l2_data.base_flow = entry;
>       |                  ^~
> 
> [...]

Here is the summary with links:
  - net: ethernet: mtk_eth_soc: Avoid truncating allocation
    https://git.kernel.org/netdev/net/c/f3eceaed9edd

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-01-31 10:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27 22:38 [PATCH] net: ethernet: mtk_eth_soc: Avoid truncating allocation Kees Cook
2023-01-27 22:38 ` Kees Cook
2023-01-28 13:40 ` Simon Horman
2023-01-28 13:40   ` Simon Horman
2023-01-31 10:10 ` patchwork-bot+netdevbpf
2023-01-31 10:10   ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.