linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Serge Semin <fancer.lancer@gmail.com>
To: Kees Cook <keescook@chromium.org>
Cc: Serge Semin <Sergey.Semin@baikalelectronics.ru>,
	linux-kernel@vger.kernel.org, Mark Brown <broonie@kernel.org>,
	Ramil Zaripov <Ramil.Zaripov@baikalelectronics.ru>,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	linux-spi@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] spi: dw: Avoid stack content exposure
Date: Fri, 12 Feb 2021 00:49:39 +0300	[thread overview]
Message-ID: <20210211214939.bwzojhjhazyxbi7i@mobilestation> (raw)
In-Reply-To: <20210211203714.1929862-1-keescook@chromium.org>

On Thu, Feb 11, 2021 at 12:37:14PM -0800, Kees Cook wrote:
> Since "data" is u32, &data is a "u32 *" type, which means pointer math
> will move in u32-sized steps. This was meant to be a byte offset, so
> cast &data to "char *" to aim the copy into the correct location.
> 
> Seen with -Warray-bounds (and found by Coverity):
> 
> In file included from ./include/linux/string.h:269,
>                  from ./arch/powerpc/include/asm/paca.h:15,
>                  from ./arch/powerpc/include/asm/current.h:13,
>                  from ./include/linux/mutex.h:14,
>                  from ./include/linux/notifier.h:14,
>                  from ./include/linux/clk.h:14,
>                  from drivers/spi/spi-dw-bt1.c:12:
> In function 'memcpy',
>     inlined from 'dw_spi_bt1_dirmap_copy_from_map' at drivers/spi/spi-dw-bt1.c:87:3:
> ./include/linux/fortify-string.h:20:29: warning: '__builtin_memcpy' offset 4 is out of the bounds [0, 4] of object 'data' with type 'u32' {aka 'unsigned int'} [-Warray-bounds]
>    20 | #define __underlying_memcpy __builtin_memcpy
>       |                             ^
> ./include/linux/fortify-string.h:191:9: note: in expansion of macro '__underlying_memcpy'
>   191 |  return __underlying_memcpy(p, q, size);
>       |         ^~~~~~~~~~~~~~~~~~~
> drivers/spi/spi-dw-bt1.c: In function 'dw_spi_bt1_dirmap_copy_from_map':
> drivers/spi/spi-dw-bt1.c:77:6: note: 'data' declared here
>    77 |  u32 data;
>       |      ^~~~

Can't believe I missed that. Thanks!
Acked-by: Serge Semin <fancer.lancer@gmail.com>

> 
> Addresses-Coverity: CID 1497771 Out-of-bounds access
> Fixes: abf00907538e ("spi: dw: Add Baikal-T1 SPI Controller glue driver")
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  drivers/spi/spi-dw-bt1.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/spi-dw-bt1.c b/drivers/spi/spi-dw-bt1.c
> index 4aa8596fb1f2..5be6b7b80c21 100644
> --- a/drivers/spi/spi-dw-bt1.c
> +++ b/drivers/spi/spi-dw-bt1.c
> @@ -84,7 +84,7 @@ static void dw_spi_bt1_dirmap_copy_from_map(void *to, void __iomem *from, size_t
>  	if (shift) {
>  		chunk = min_t(size_t, 4 - shift, len);
>  		data = readl_relaxed(from - shift);
> -		memcpy(to, &data + shift, chunk);
> +		memcpy(to, (char *)&data + shift, chunk);
>  		from += chunk;
>  		to += chunk;
>  		len -= chunk;
> -- 
> 2.25.1
> 

  reply	other threads:[~2021-02-11 21:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11 20:37 [PATCH] spi: dw: Avoid stack content exposure Kees Cook
2021-02-11 21:49 ` Serge Semin [this message]
2021-02-12 14:01 ` Mark Brown

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=20210211214939.bwzojhjhazyxbi7i@mobilestation \
    --to=fancer.lancer@gmail.com \
    --cc=Ramil.Zaripov@baikalelectronics.ru \
    --cc=Sergey.Semin@baikalelectronics.ru \
    --cc=broonie@kernel.org \
    --cc=gustavo@embeddedor.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).