linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: qed: Fix memcpy() overflow of qed_dcbx_params()
@ 2021-06-17 17:09 Kees Cook
  2021-06-17 19:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2021-06-17 17:09 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Kees Cook, Ariel Elior, David S. Miller, Jakub Kicinski,
	linux-kernel, GR-everest-linux-l2, netdev, linux-hardening

The source (&dcbx_info->operational.params) and dest
(&p_hwfn->p_dcbx_info->set.config.params) are both struct qed_dcbx_params
(560 bytes), not struct qed_dcbx_admin_params (564 bytes), which is used
as the memcpy() size.

However it seems that struct qed_dcbx_operational_params
(dcbx_info->operational)'s layout matches struct qed_dcbx_admin_params
(p_hwfn->p_dcbx_info->set.config)'s 4 byte difference (3 padding, 1 byte
for "valid").

On the assumption that the size is wrong (rather than the source structure
type), adjust the memcpy() size argument to be 4 bytes smaller and add
a BUILD_BUG_ON() to validate any changes to the structure sizes.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/ethernet/qlogic/qed/qed_dcbx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
index 17d5b649eb36..e81dd34a3cac 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
@@ -1266,9 +1266,11 @@ int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
 		p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
 
 	p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
+	BUILD_BUG_ON(sizeof(dcbx_info->operational.params) !=
+		     sizeof(p_hwfn->p_dcbx_info->set.config.params));
 	memcpy(&p_hwfn->p_dcbx_info->set.config.params,
 	       &dcbx_info->operational.params,
-	       sizeof(struct qed_dcbx_admin_params));
+	       sizeof(p_hwfn->p_dcbx_info->set.config.params));
 	p_hwfn->p_dcbx_info->set.config.valid = true;
 
 	memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
-- 
2.25.1


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

* Re: [PATCH] net: qed: Fix memcpy() overflow of qed_dcbx_params()
  2021-06-17 17:09 [PATCH] net: qed: Fix memcpy() overflow of qed_dcbx_params() Kees Cook
@ 2021-06-17 19:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-06-17 19:20 UTC (permalink / raw)
  To: Kees Cook
  Cc: alobakin, aelior, davem, kuba, linux-kernel, GR-everest-linux-l2,
	netdev, linux-hardening

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Thu, 17 Jun 2021 10:09:53 -0700 you wrote:
> The source (&dcbx_info->operational.params) and dest
> (&p_hwfn->p_dcbx_info->set.config.params) are both struct qed_dcbx_params
> (560 bytes), not struct qed_dcbx_admin_params (564 bytes), which is used
> as the memcpy() size.
> 
> However it seems that struct qed_dcbx_operational_params
> (dcbx_info->operational)'s layout matches struct qed_dcbx_admin_params
> (p_hwfn->p_dcbx_info->set.config)'s 4 byte difference (3 padding, 1 byte
> for "valid").
> 
> [...]

Here is the summary with links:
  - net: qed: Fix memcpy() overflow of qed_dcbx_params()
    https://git.kernel.org/netdev/net/c/1c200f832e14

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] 2+ messages in thread

end of thread, other threads:[~2021-06-17 19:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 17:09 [PATCH] net: qed: Fix memcpy() overflow of qed_dcbx_params() Kees Cook
2021-06-17 19:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).