LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Hugues FRUCHET <hugues.fruchet@st.com>
To: Andi Kleen <andi@firstfloor.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	Andi Kleen <ak@linux.intel.com>,
	"mchehab@s-opensource.com" <mchehab@s-opensource.com>
Subject: Re: [PATCH] Fix read buffer overflow in delta-ipc
Date: Wed, 3 Jan 2018 09:40:04 +0000
Message-ID: <74958ca0-e78e-0505-f738-1ddda50d8ead@st.com> (raw)
In-Reply-To: <20171222001212.1850-1-andi@firstfloor.org>

Hi Andi,
Thanks for the patch but I would suggest to use strlcpy instead, this 
will guard msg.name overwriting and add the NULL termination in case
of truncation:
-	memcpy(msg.name, name, sizeof(msg.name));
-	msg.name[sizeof(msg.name) - 1] = 0;
+	strlcpy(msg.name, name, sizeof(msg.name));

Best regards,
Hugues.

On 12/22/2017 01:12 AM, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
> 
> The single caller passes a string to delta_ipc_open, which copies with a
> fixed size larger than the string. So it copies some random data after
> the original string the ro segment.
> 
> If the string was at the end of a page it may fault.
> 
> Just copy the string with a normal strcpy after clearing the field.
> 
> Found by a LTO build (which errors out)
> because the compiler inlines the functions and can resolve
> the string sizes and triggers the compile time checks in memcpy.
> 
> In function ‘memcpy’,
>      inlined from ‘delta_ipc_open.constprop’ at linux/drivers/media/platform/sti/delta/delta-ipc.c:178:0,
>      inlined from ‘delta_mjpeg_ipc_open’ at linux/drivers/media/platform/sti/delta/delta-mjpeg-dec.c:227:0,
>      inlined from ‘delta_mjpeg_decode’ at linux/drivers/media/platform/sti/delta/delta-mjpeg-dec.c:403:0:
> /home/andi/lsrc/linux/include/linux/string.h:337:0: error: call to ‘__read_overflow2’ declared with attribute error: detected read beyond size of object passed as 2nd parameter
>      __read_overflow2();
> 
> Cc: hugues.fruchet@st.com
> Cc: mchehab@s-opensource.com
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
>   drivers/media/platform/sti/delta/delta-ipc.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/sti/delta/delta-ipc.c b/drivers/media/platform/sti/delta/delta-ipc.c
> index 41e4a4c259b3..b6c256e3ceb6 100644
> --- a/drivers/media/platform/sti/delta/delta-ipc.c
> +++ b/drivers/media/platform/sti/delta/delta-ipc.c
> @@ -175,8 +175,8 @@ int delta_ipc_open(struct delta_ctx *pctx, const char *name,
>   	msg.ipc_buf_size = ipc_buf_size;
>   	msg.ipc_buf_paddr = ctx->ipc_buf->paddr;
>   
> -	memcpy(msg.name, name, sizeof(msg.name));
> -	msg.name[sizeof(msg.name) - 1] = 0;
> +	memset(msg.name, 0, sizeof(msg.name));
> +	strcpy(msg.name, name);
>   
>   	msg.param_size = param->size;
>   	memcpy(ctx->ipc_buf->vaddr, param->data, msg.param_size);
> 

  reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-22  0:12 Andi Kleen
2018-01-03  9:40 ` Hugues FRUCHET [this message]
2018-01-04  0:19   ` Andi Kleen
2018-01-04  9:53     ` Hugues FRUCHET

Reply instructions:

You may reply publically 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=74958ca0-e78e-0505-f738-1ddda50d8ead@st.com \
    --to=hugues.fruchet@st.com \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@s-opensource.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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox