linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: linux-kernel@vger.kernel.org
Cc: x86@kernel.org, samitolvanen@google.com, alxmtvv@gmail.com,
	linux-kbuild@vger.kernel.org, yamada.masahiro@socionext.com,
	akpm@linux-foundation.org, Andi Kleen <ak@linux.intel.com>,
	hugues.fruchet@st.com, mchehab@s-opensource.com
Subject: [PATCH 10/21] Fix read buffer overflow in delta-ipc
Date: Mon, 27 Nov 2017 13:34:12 -0800	[thread overview]
Message-ID: <20171127213423.27218-11-andi@firstfloor.org> (raw)
In-Reply-To: <20171127213423.27218-1-andi@firstfloor.org>

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>
---
 arch/x86/platform/intel-mid/device_libs/platform_bt.c | 2 +-
 certs/blacklist_nohashes.c                            | 2 +-
 drivers/media/platform/sti/delta/delta-ipc.c          | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/platform/intel-mid/device_libs/platform_bt.c b/arch/x86/platform/intel-mid/device_libs/platform_bt.c
index dc036e511f48..2b5d86ce24c2 100644
--- a/arch/x86/platform/intel-mid/device_libs/platform_bt.c
+++ b/arch/x86/platform/intel-mid/device_libs/platform_bt.c
@@ -60,7 +60,7 @@ static int __init tng_bt_sfi_setup(struct bt_sfi_data *ddata)
 	return 0;
 }
 
-static const struct bt_sfi_data tng_bt_sfi_data __initdata = {
+static const struct bt_sfi_data tng_bt_sfi_data __initconst = {
 	.setup	= tng_bt_sfi_setup,
 };
 
diff --git a/certs/blacklist_nohashes.c b/certs/blacklist_nohashes.c
index 73fd99098ad7..753b703ef0ef 100644
--- a/certs/blacklist_nohashes.c
+++ b/certs/blacklist_nohashes.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include "blacklist.h"
 
-const char __initdata *const blacklist_hashes[] = {
+const char __initconst *const blacklist_hashes[] = {
 	NULL
 };
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);
-- 
2.13.6


  parent reply	other threads:[~2017-11-27 21:34 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-27 21:34 Link time optimization for LTO/x86 Andi Kleen
2017-11-27 21:34 ` [PATCH 01/21] x86/xen: Mark pv stub assembler symbol visible Andi Kleen
2017-11-27 21:34 ` [PATCH 02/21] afs: Fix const confusion in AFS Andi Kleen
2017-11-27 21:34 ` [PATCH 03/21] x86/timer: Don't inline __const_udelay Andi Kleen
2017-11-27 21:34 ` [PATCH 04/21] locking/spinlocks: Mark spinlocks noinline when inline spinlocks are disabled Andi Kleen
2017-11-27 21:34 ` [PATCH 05/21] x86/kvm: Make steal_time visible Andi Kleen
2017-11-27 21:34 ` [PATCH 06/21] x86/syscalls: Make x86 syscalls use real prototypes Andi Kleen
2017-11-27 21:34 ` [PATCH 07/21] x86: Make exception handler functions visible Andi Kleen
2017-11-27 21:34 ` [PATCH 08/21] x86/idt: Make const __initconst Andi Kleen
2017-11-27 21:34 ` [PATCH 09/21] lto: Use C version for SYSCALL_ALIAS Andi Kleen
2017-11-27 21:34 ` Andi Kleen [this message]
2017-11-27 21:34 ` [PATCH 11/21] trace: Use -mcount-record for dynamic ftrace Andi Kleen
2017-12-01  0:22   ` Steven Rostedt
2018-05-01 18:42     ` Steven Rostedt
2017-11-27 21:34 ` [PATCH 12/21] ftrace: Mark function tracer test functions noinline/noclone Andi Kleen
2017-11-27 21:34 ` [PATCH 13/21] ftrace: Disable LTO for ftrace self tests Andi Kleen
2017-11-27 21:34 ` [PATCH 14/21] lto, fs: Avoid static variable in linux/fs.h Andi Kleen
2017-11-27 21:34 ` [PATCH 15/21] lto, x86, mm: Disable vmalloc BUILD_BUG_ON for LTO Andi Kleen
2017-11-27 21:34 ` [PATCH 16/21] lto: Add __noreorder and mark initcalls __noreorder Andi Kleen
2017-11-27 21:34 ` [PATCH 17/21] lto, workaround: Disable LTO for BPF Andi Kleen
2017-11-27 21:34 ` [PATCH 18/21] lto, crypto: Disable LTO for camelia glue Andi Kleen
2017-11-27 21:34 ` [PATCH 19/21] lto, x86: Disable LTO for realmode / vDSO / head64 Andi Kleen
2017-11-27 21:34 ` [PATCH 20/21] Kbuild, lto: Add Link Time Optimization support Andi Kleen
2018-01-27  0:15   ` Arnd Bergmann
2018-01-27  0:55     ` Andi Kleen
2018-01-27 14:26       ` Arnd Bergmann
2018-01-28 18:33         ` Andi Kleen
2017-11-27 21:34 ` [PATCH 21/21] x86: Enable Link Time Optimization Andi Kleen
2017-11-28 16:04 ` [PATCH 02/21] afs: Fix const confusion in AFS David Howells
2017-11-28 16:50   ` Andi Kleen
2017-11-29 23:09 ` Link time optimization for LTO/x86 Sami Tolvanen

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=20171127213423.27218-11-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=alxmtvv@gmail.com \
    --cc=hugues.fruchet@st.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@s-opensource.com \
    --cc=samitolvanen@google.com \
    --cc=x86@kernel.org \
    --cc=yamada.masahiro@socionext.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;
as well as URLs for NNTP newsgroup(s).