* [PATCH] NFC: nci: Bounds check struct nfc_target arrays
@ 2022-12-02 21:44 Kees Cook
2022-12-05 8:17 ` Krzysztof Kozlowski
2022-12-06 5:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2022-12-02 21:44 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Kees Cook, syzbot+210e196cef4711b65139, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev,
John W. Linville, Ilan Elias, linux-kernel, linux-hardening
While running under CONFIG_FORTIFY_SOURCE=y, syzkaller reported:
memcpy: detected field-spanning write (size 129) of single field "target->sensf_res" at net/nfc/nci/ntf.c:260 (size 18)
This appears to be a legitimate lack of bounds checking in
nci_add_new_protocol(). Add the missing checks.
Reported-by: syzbot+210e196cef4711b65139@syzkaller.appspotmail.com
Link: https://lore.kernel.org/lkml/0000000000001c590f05ee7b3ff4@google.com
Fixes: 019c4fbaa790 ("NFC: Add NCI multiple targets support")
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.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: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
net/nfc/nci/ntf.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c
index 282c51051dcc..994a0a1efb58 100644
--- a/net/nfc/nci/ntf.c
+++ b/net/nfc/nci/ntf.c
@@ -240,6 +240,8 @@ static int nci_add_new_protocol(struct nci_dev *ndev,
target->sens_res = nfca_poll->sens_res;
target->sel_res = nfca_poll->sel_res;
target->nfcid1_len = nfca_poll->nfcid1_len;
+ if (target->nfcid1_len > ARRAY_SIZE(target->nfcid1))
+ return -EPROTO;
if (target->nfcid1_len > 0) {
memcpy(target->nfcid1, nfca_poll->nfcid1,
target->nfcid1_len);
@@ -248,6 +250,8 @@ static int nci_add_new_protocol(struct nci_dev *ndev,
nfcb_poll = (struct rf_tech_specific_params_nfcb_poll *)params;
target->sensb_res_len = nfcb_poll->sensb_res_len;
+ if (target->sensb_res_len > ARRAY_SIZE(target->sensb_res))
+ return -EPROTO;
if (target->sensb_res_len > 0) {
memcpy(target->sensb_res, nfcb_poll->sensb_res,
target->sensb_res_len);
@@ -256,6 +260,8 @@ static int nci_add_new_protocol(struct nci_dev *ndev,
nfcf_poll = (struct rf_tech_specific_params_nfcf_poll *)params;
target->sensf_res_len = nfcf_poll->sensf_res_len;
+ if (target->sensf_res_len > ARRAY_SIZE(target->sensf_res))
+ return -EPROTO;
if (target->sensf_res_len > 0) {
memcpy(target->sensf_res, nfcf_poll->sensf_res,
target->sensf_res_len);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] NFC: nci: Bounds check struct nfc_target arrays
2022-12-02 21:44 [PATCH] NFC: nci: Bounds check struct nfc_target arrays Kees Cook
@ 2022-12-05 8:17 ` Krzysztof Kozlowski
2022-12-06 5:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2022-12-05 8:17 UTC (permalink / raw)
To: Kees Cook
Cc: syzbot+210e196cef4711b65139, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, John W. Linville,
Ilan Elias, linux-kernel, linux-hardening
On 02/12/2022 22:44, Kees Cook wrote:
> While running under CONFIG_FORTIFY_SOURCE=y, syzkaller reported:
>
> memcpy: detected field-spanning write (size 129) of single field "target->sensf_res" at net/nfc/nci/ntf.c:260 (size 18)
>
> This appears to be a legitimate lack of bounds checking in
> nci_add_new_protocol(). Add the missing checks.
>
> Reported-by: syzbot+210e196cef4711b65139@syzkaller.appspotmail.com
> Link: https://lore.kernel.org/lkml/0000000000001c590f05ee7b3ff4@google.com
> Fixes: 019c4fbaa790 ("NFC: Add NCI multiple targets support")
> Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.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: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] NFC: nci: Bounds check struct nfc_target arrays
2022-12-02 21:44 [PATCH] NFC: nci: Bounds check struct nfc_target arrays Kees Cook
2022-12-05 8:17 ` Krzysztof Kozlowski
@ 2022-12-06 5:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-12-06 5:00 UTC (permalink / raw)
To: Kees Cook
Cc: krzysztof.kozlowski, syzbot+210e196cef4711b65139, davem,
edumazet, kuba, pabeni, netdev, linville, ilane, linux-kernel,
linux-hardening
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 2 Dec 2022 13:44:14 -0800 you wrote:
> While running under CONFIG_FORTIFY_SOURCE=y, syzkaller reported:
>
> memcpy: detected field-spanning write (size 129) of single field "target->sensf_res" at net/nfc/nci/ntf.c:260 (size 18)
>
> This appears to be a legitimate lack of bounds checking in
> nci_add_new_protocol(). Add the missing checks.
>
> [...]
Here is the summary with links:
- NFC: nci: Bounds check struct nfc_target arrays
https://git.kernel.org/netdev/net/c/e329e71013c9
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] 3+ messages in thread
end of thread, other threads:[~2022-12-06 5:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-02 21:44 [PATCH] NFC: nci: Bounds check struct nfc_target arrays Kees Cook
2022-12-05 8:17 ` Krzysztof Kozlowski
2022-12-06 5:00 ` 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.