From: Alexander H Duyck <alexander.duyck@gmail.com>
To: Aleksandr Burakov <a.burakov@rosalinux.ru>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Christophe Ricard <christophe.ricard@gmail.com>,
Samuel Ortiz <sameo@linux.intel.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
lvc-project@linuxtesting.org
Subject: Re: [PATCH] nfc: st-nci: array index overflow in st_nci_se_get_bwi()
Date: Wed, 14 Dec 2022 10:35:59 -0800 [thread overview]
Message-ID: <5841f9021baf856c26fb27ac1d75fc1e29d3e044.camel@gmail.com> (raw)
In-Reply-To: <20221213141228.101786-1-a.burakov@rosalinux.ru>
On Tue, 2022-12-13 at 09:12 -0500, Aleksandr Burakov wrote:
> Index of info->se_info.atr can be overflow due to unchecked increment
> in the loop "for". The patch checks the value of current array index
> and doesn't permit increment in case of the index is equal to
> ST_NCI_ESE_MAX_LENGTH - 1.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: ed06aeefdac3 ("nfc: st-nci: Rename st21nfcb to st-nci")
> Signed-off-by: Aleksandr Burakov <a.burakov@rosalinux.ru>
> ---
> drivers/nfc/st-nci/se.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
> index ec87dd21e054..ff8ac1784880 100644
> --- a/drivers/nfc/st-nci/se.c
> +++ b/drivers/nfc/st-nci/se.c
> @@ -119,10 +119,11 @@ static u8 st_nci_se_get_bwi(struct nci_dev *ndev)
> /* Bits 8 to 5 of the first TB for T=1 encode BWI from zero to nine */
> for (i = 1; i < ST_NCI_ESE_MAX_LENGTH; i++) {
> td = ST_NCI_ATR_GET_Y_FROM_TD(info->se_info.atr[i]);
> - if (ST_NCI_ATR_TA_PRESENT(td))
> + if (ST_NCI_ATR_TA_PRESENT(td) && i < ST_NCI_ESE_MAX_LENGTH - 1)
> i++;
> if (ST_NCI_ATR_TB_PRESENT(td)) {
> - i++;
> + if (i < ST_NCI_ESE_MAX_LENGTH - 1)
> + i++;
> return info->se_info.atr[i] >> 4;
> }
> }
Rather than adding 2 checks you could do this all with one check.
Basically you would just need to replace:
if (ST_NCI_ATR_TB_PRESENT(td)) {
i++;
with:
if (ST_NCI_ATR_TB_PRESENT(td) && ++i < ST_NCI_ESE_MAX_LENGTH)
Basically it is fine to increment "i" as long as it isn't being used as
an index so just restricting the last access so that we don't
dereference using it as an index should be enough.
next prev parent reply other threads:[~2022-12-14 18:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-13 14:12 [PATCH] nfc: st-nci: array index overflow in st_nci_se_get_bwi() Aleksandr Burakov
2022-12-14 18:35 ` Alexander H Duyck [this message]
2022-12-19 9:06 ` Krzysztof Kozlowski
2022-12-19 15:41 ` Alexander Duyck
2022-12-19 15:46 ` 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=5841f9021baf856c26fb27ac1d75fc1e29d3e044.camel@gmail.com \
--to=alexander.duyck@gmail.com \
--cc=a.burakov@rosalinux.ru \
--cc=christophe.ricard@gmail.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=netdev@vger.kernel.org \
--cc=sameo@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox