All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anup Sharma <anupnewsmail@gmail.com>
To: krzysztof.kozlowski@linaro.org, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	linma@zju.edu.cn, dvyukov@google.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] net: nfc: nci: fix for UBSAN: shift-out-of-bounds in nci_activate_target
Date: Wed, 19 Apr 2023 06:46:20 +0530	[thread overview]
Message-ID: <ZD9A5Krm+ZoFEFWZ@yoga> (raw)

syzbot found  UBSAN: shift-out-of-bounds in nci_activate_target [1],
when nci_target->supported_protocols is bigger than UNIT_MAX,
where supported_protocols is unsigned 32-bit interger type.

32 is the maximum allowed for supported_protocols. Added a check
for it. 

[1] UBSAN: shift-out-of-bounds in net/nfc/nci/core.c:912:45
shift exponent 4294967071 is too large for 32-bit type 'int'
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x136/0x150 lib/dump_stack.c:106
 ubsan_epilogue lib/ubsan.c:217 [inline]
 __ubsan_handle_shift_out_of_bounds+0x221/0x5a0 lib/ubsan.c:387
 nci_activate_target.cold+0x1a/0x1f net/nfc/nci/core.c:912
 nfc_activate_target+0x1f8/0x4c0 net/nfc/core.c:420
 nfc_genl_activate_target+0x1f3/0x290 net/nfc/netlink.c:900
 genl_family_rcv_msg_doit.isra.0+0x1e6/0x2d0 net/netlink/genetlink.c:968
 genl_family_rcv_msg net/netlink/genetlink.c:1048 [inline]

Reported-by: syzbot+0839b78e119aae1fec78@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?id=19cf2724120ef8c51c8d2566df0cc34617188433

Signed-off-by: anupsharma <anupnewsmail@gmail.com>
---
 net/nfc/nci/core.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index fff755dde30d..e9d968bd1cd9 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -908,6 +908,11 @@ static int nci_activate_target(struct nfc_dev *nfc_dev,
 		pr_err("unable to find the selected target\n");
 		return -EINVAL;
 	}
+	
+	if (nci_target->supported_protocols >= 32) {
+		pr_err("Too many supported protocol by the device\n");
+		return -EINVAL;
+	}
 
 	if (!(nci_target->supported_protocols & (1 << protocol))) {
 		pr_err("target does not support the requested protocol 0x%x\n",
-- 
2.34.1


             reply	other threads:[~2023-04-19  1:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-19  1:16 Anup Sharma [this message]
2023-04-19  8:26 ` [PATCH] net: nfc: nci: fix for UBSAN: shift-out-of-bounds in nci_activate_target Krzysztof Kozlowski
2023-04-19  8:28   ` Krzysztof Kozlowski
     [not found]     ` <ZEA/N5SAFHd2UjS8@yoga>
2023-04-19 19:42       ` Krzysztof Kozlowski
2023-04-19  8:27 ` Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZD9A5Krm+ZoFEFWZ@yoga \
    --to=anupnewsmail@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dvyukov@google.com \
    --cc=edumazet@google.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linma@zju.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.