net/ncsi: Silence runtime memcpy() false positive warning
Subsystems (3)
PATCH 1/1 net/ncsi: Silence runtime memcpy() false positive warning
The memcpy() in ncsi_cmd_handler_oem deserializes nca->data into a flexible array structure that overlapping with non-flex-array members (mfr_id) intentionally. Since the mem_to_flex() API is not finished, temporarily silence this warning, since it is a false positive, using unsafe_memcpy().
--- net/ncsi/ncsi-cmd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ncsi/ncsi-cmd.c +2 -1
@@ -228,7 +228,8 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb, len +=max (payload, padding_bytes); cmd =skb_put_zero (skb, len); -memcpy (&cmd->mfr_id, nca->data, nca->payload); +unsafe_memcpy (&cmd->mfr_id, nca->data, nca->payload, + /* skb allocated with enough to load the payload */);ncsi_cmd_build_header (&cmd->cmd.common, nca);return 0 ;
Signature · 1 line
2.34.1
Paolo Abeni
maintainerHello,
Quoted 6 lines · Kees Cook
The
memcpy()inncsi_cmd_handler_oemdeserializesnca->datainto a flexible array structure that overlapping with non-flex-array members (mfr_id) intentionally. Since themem_to_flex()API is not finished, temporarily silence this warning, since it is a false positive, usingunsafe_memcpy().
Quoted 9 lines
Reported-by Joel Stanley <[email protected]>Link https://lore.kernel.org/netdev/CACPK8Xdfi=OJKP0x0D1w87fQeFZ4A2DP2qzGCRcuVbpU-9=4sQ@mail.gmail.com/ open hereCc Samuel Mendoza-Jonas <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Signed-off-by Kees Cook <[email protected]>
Is this for the -net or the -net-next tree? It applies to both...
It you are targetting the -net tree, I think it would be nicer adding a suitable Fixes tag.
Thanks!
Paolo
Quoted 19 lines · Paolo Abeni
Hello,
Quoted 6 lines · Kees Cook
The
memcpy()inncsi_cmd_handler_oemdeserializesnca->datainto a flexible array structure that overlapping with non-flex-array members (mfr_id) intentionally. Since themem_to_flex()API is not finished, temporarily silence this warning, since it is a false positive, usingunsafe_memcpy().Quoted 9 lines
Reported-by Joel Stanley <[email protected]>Link https://lore.kernel.org/netdev/CACPK8Xdfi=OJKP0x0D1w87fQeFZ4A2DP2qzGCRcuVbpU-9=4sQ@mail.gmail.com/ open hereCc Samuel Mendoza-Jonas <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Signed-off-by Kees Cook <[email protected]>
Quoted 4 lines
Is this for the -net or the -net-next tree? It applies to both...
It you are targetting the -net tree, I think it would be nicer adding a suitable Fixes tag.
-net-next (v6.2) is fine -- this is where the warning manifests.
-Kees
Signature · 1 line
Kees Cook
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 16 lines · On Fri, 2 Dec 2022 13:24:22 -0800 you wrote:
The
memcpy()inncsi_cmd_handler_oemdeserializesnca->datainto a flexible array structure that overlapping with non-flex-array members (mfr_id) intentionally. Since themem_to_flex()API is not finished, temporarily silence this warning, since it is a false positive, usingunsafe_memcpy().Reported-by Joel Stanley <[email protected]>Link https://lore.kernel.org/netdev/CACPK8Xdfi=OJKP0x0D1w87fQeFZ4A2DP2qzGCRcuVbpU-9=4sQ@mail.gmail.com/ open hereCc Samuel Mendoza-Jonas <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Signed-off-by Kees Cook <[email protected]>
Quoted 1 line
[...]
Here is the summary with links:
- net/ncsi: Silence runtime memcpy() false positive warning
https://git.kernel.org/netdev/net-next/c/b93884eea26f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 6 lines · Kees Cook
The
memcpy()inncsi_cmd_handler_oemdeserializesnca->datainto a flexible array structure that overlapping with non-flex-array members (mfr_id) intentionally. Since themem_to_flex()API is not finished, temporarily silence this warning, since it is a false positive, usingunsafe_memcpy().
Thanks for sending the fix Kees. I got a bit busy towards the end of the year.
I spent some time looking at how the netlink api was used, and tried to convince myself that a user couldn't send an OEM command that triggered the overflow. It all got a bit tangled up so I didn't come to a conclusion.
Cheers,
Joel
Quoted 31 lines
Reported-by Joel Stanley <[email protected]>Link https://lore.kernel.org/netdev/CACPK8Xdfi=OJKP0x0D1w87fQeFZ4A2DP2qzGCRcuVbpU-9=4sQ@mail.gmail.com/ open hereCc Samuel Mendoza-Jonas <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Signed-off-by Kees Cook <[email protected]>--- net/ncsi/ncsi-cmd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/ncsi/ncsi-cmd.c +2
-2@@ -228,7 +228,8 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb, len +=max (payload, padding_bytes); cmd =skb_put_zero (skb, len); -memcpy (&cmd->mfr_id, nca->data, nca->payload); +unsafe_memcpy (&cmd->mfr_id, nca->data, nca->payload, + /* skb allocated with enough to load the payload */);ncsi_cmd_build_header (&cmd->cmd.common, nca);return 0 ; --2.34.1