All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Serge Semin <Sergey.Semin@baikalelectronics.ru>,
	linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
	Kees Cook <keescook@chromium.org>,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH] mtd: physmap: physmap-bt1-rom: Fix unintentional stack access
Date: Fri, 12 Feb 2021 15:12:16 +0100	[thread overview]
Message-ID: <20210212151216.31a09ad1@xps13> (raw)
In-Reply-To: <20210212104022.GA242669@embeddedor>

Hi Gustavo,

"Gustavo A. R. Silva" <gustavoars@kernel.org> wrote on Fri, 12 Feb 2021
04:40:22 -0600:

> Cast &data to (char *) in order to avoid unintentionally accessing
> the stack.
> 
> Notice that data is of type u32, so any increment to &data
> will be in the order of 4-byte chunks, and this piece of code
> is actually intended to be a byte offset.

I don't have the same reading. I don't say that Coverity report is
wrong, but let's discuss this a bit further.

Given that &data is of type u32 *, you say that "&data + shift"
produces increments of 4-bytes, ie. we would access "&data + 4 *
shift"? Because I don't think this is the case (again, I may be wrong).

I'm sure this would be the case if we dereferenced data like
data[shift] though, but in this case I don't see what this cast is
fixing. Can you enlighten me?

Could the out-of-bounds warning come from the fact that shift
might be bigger than the data array spread?

> Fixes: b3e79e7682e0 ("mtd: physmap: Add Baikal-T1 physically mapped ROM support")
> Addresses-Coverity-ID: 1497765 ("Out-of-bounds access")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>  drivers/mtd/maps/physmap-bt1-rom.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/maps/physmap-bt1-rom.c b/drivers/mtd/maps/physmap-bt1-rom.c
> index a35450002284..58782cfaf71c 100644
> --- a/drivers/mtd/maps/physmap-bt1-rom.c
> +++ b/drivers/mtd/maps/physmap-bt1-rom.c
> @@ -79,7 +79,7 @@ static void __xipram bt1_rom_map_copy_from(struct map_info *map,
>  	if (shift) {
>  		chunk = min_t(ssize_t, 4 - shift, len);
>  		data = readl_relaxed(src - shift);
> -		memcpy(to, &data + shift, chunk);
> +		memcpy(to, (char *)&data + shift, chunk);
>  		src += chunk;
>  		to += chunk;
>  		len -= chunk;

Thanks,
Miquèl

WARNING: multiple messages have this Message-ID (diff)
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Vignesh Raghavendra <vigneshr@ti.com>,
	Richard Weinberger <richard@nod.at>,
	linux-kernel@vger.kernel.org,
	Serge Semin <Sergey.Semin@baikalelectronics.ru>,
	linux-mtd@lists.infradead.org, linux-hardening@vger.kernel.org,
	Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH] mtd: physmap: physmap-bt1-rom: Fix unintentional stack access
Date: Fri, 12 Feb 2021 15:12:16 +0100	[thread overview]
Message-ID: <20210212151216.31a09ad1@xps13> (raw)
In-Reply-To: <20210212104022.GA242669@embeddedor>

Hi Gustavo,

"Gustavo A. R. Silva" <gustavoars@kernel.org> wrote on Fri, 12 Feb 2021
04:40:22 -0600:

> Cast &data to (char *) in order to avoid unintentionally accessing
> the stack.
> 
> Notice that data is of type u32, so any increment to &data
> will be in the order of 4-byte chunks, and this piece of code
> is actually intended to be a byte offset.

I don't have the same reading. I don't say that Coverity report is
wrong, but let's discuss this a bit further.

Given that &data is of type u32 *, you say that "&data + shift"
produces increments of 4-bytes, ie. we would access "&data + 4 *
shift"? Because I don't think this is the case (again, I may be wrong).

I'm sure this would be the case if we dereferenced data like
data[shift] though, but in this case I don't see what this cast is
fixing. Can you enlighten me?

Could the out-of-bounds warning come from the fact that shift
might be bigger than the data array spread?

> Fixes: b3e79e7682e0 ("mtd: physmap: Add Baikal-T1 physically mapped ROM support")
> Addresses-Coverity-ID: 1497765 ("Out-of-bounds access")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>  drivers/mtd/maps/physmap-bt1-rom.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/maps/physmap-bt1-rom.c b/drivers/mtd/maps/physmap-bt1-rom.c
> index a35450002284..58782cfaf71c 100644
> --- a/drivers/mtd/maps/physmap-bt1-rom.c
> +++ b/drivers/mtd/maps/physmap-bt1-rom.c
> @@ -79,7 +79,7 @@ static void __xipram bt1_rom_map_copy_from(struct map_info *map,
>  	if (shift) {
>  		chunk = min_t(ssize_t, 4 - shift, len);
>  		data = readl_relaxed(src - shift);
> -		memcpy(to, &data + shift, chunk);
> +		memcpy(to, (char *)&data + shift, chunk);
>  		src += chunk;
>  		to += chunk;
>  		len -= chunk;

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2021-02-12 14:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12 10:40 [PATCH] mtd: physmap: physmap-bt1-rom: Fix unintentional stack access Gustavo A. R. Silva
2021-02-12 10:40 ` Gustavo A. R. Silva
2021-02-12 14:12 ` Miquel Raynal [this message]
2021-02-12 14:12   ` Miquel Raynal
2021-02-12 14:45   ` Gustavo A. R. Silva
2021-02-12 14:50     ` Miquel Raynal
2021-02-12 14:50       ` Miquel Raynal
2021-02-12 15:18       ` Gustavo A. R. Silva
2021-02-12 16:30 ` Serge Semin
2021-02-12 16:30   ` Serge Semin
2021-03-02 17:14 ` Miquel Raynal
2021-03-02 17:14   ` Miquel Raynal

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=20210212151216.31a09ad1@xps13 \
    --to=miquel.raynal@bootlin.com \
    --cc=Sergey.Semin@baikalelectronics.ru \
    --cc=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.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.