From: Miquel Raynal <miquel.raynal@bootlin.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
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:50:31 +0100 [thread overview]
Message-ID: <20210212155031.08ad8742@xps13> (raw)
In-Reply-To: <d4f2385d-bd4f-1af8-60c9-48657d046d5f@embeddedor.com>
Hi Gustavo,
"Gustavo A. R. Silva" <gustavo@embeddedor.com> wrote on Fri, 12 Feb
2021 08:45:33 -0600:
> On 2/12/21 08:12, Miquel Raynal wrote:
> > 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).
>
> Yep; this is pointer arithmetic. If you have an object ptr of type u32 *:
>
> u32 *ptr;
>
> and let's say it points to address 100. If you increment it by one:
>
> ptr++
>
> ptr will now point to address 104, not to 101.
>
> Now, if instead, you first cast ptr to 'char *' and increment it by 1,
> then it will point to address 101.
Yep, I got confused with the proper addition compared to dereferencing.
Patch looks legitimate.
Thanks,
Miquèl
next prev parent reply other threads:[~2021-02-12 14:51 UTC|newest]
Thread overview: 5+ 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 14:12 ` Miquel Raynal
[not found] ` <d4f2385d-bd4f-1af8-60c9-48657d046d5f@embeddedor.com>
2021-02-12 14:50 ` Miquel Raynal [this message]
2021-02-12 16:30 ` Serge Semin
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=20210212155031.08ad8742@xps13 \
--to=miquel.raynal@bootlin.com \
--cc=Sergey.Semin@baikalelectronics.ru \
--cc=gustavo@embeddedor.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox