From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>,
Alexander Popov <alex.popov@linux.com>,
Sasha Levin <sashal@kernel.org>,
linux-hardening@vger.kernel.org
Subject: [PATCH AUTOSEL 5.16 04/35] gcc-plugins/stackleak: Exactly match strings instead of prefixes
Date: Mon, 28 Mar 2022 07:19:40 -0400 [thread overview]
Message-ID: <20220328112011.1555169-4-sashal@kernel.org> (raw)
In-Reply-To: <20220328112011.1555169-1-sashal@kernel.org>
From: Kees Cook <keescook@chromium.org>
[ Upstream commit 27e9faf415dbf94af19b9c827842435edbc1fbbc ]
Since STRING_CST may not be NUL terminated, strncmp() was used for check
for equality. However, this may lead to mismatches for longer section
names where the start matches the tested-for string. Test for exact
equality by checking for the presences of NUL termination.
Cc: Alexander Popov <alex.popov@linux.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
scripts/gcc-plugins/stackleak_plugin.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c
index e9db7dcb3e5f..b04aa8e91a41 100644
--- a/scripts/gcc-plugins/stackleak_plugin.c
+++ b/scripts/gcc-plugins/stackleak_plugin.c
@@ -429,6 +429,23 @@ static unsigned int stackleak_cleanup_execute(void)
return 0;
}
+/*
+ * STRING_CST may or may not be NUL terminated:
+ * https://gcc.gnu.org/onlinedocs/gccint/Constant-expressions.html
+ */
+static inline bool string_equal(tree node, const char *string, int length)
+{
+ if (TREE_STRING_LENGTH(node) < length)
+ return false;
+ if (TREE_STRING_LENGTH(node) > length + 1)
+ return false;
+ if (TREE_STRING_LENGTH(node) == length + 1 &&
+ TREE_STRING_POINTER(node)[length] != '\0')
+ return false;
+ return !memcmp(TREE_STRING_POINTER(node), string, length);
+}
+#define STRING_EQUAL(node, str) string_equal(node, str, strlen(str))
+
static bool stackleak_gate(void)
{
tree section;
@@ -438,13 +455,13 @@ static bool stackleak_gate(void)
if (section && TREE_VALUE(section)) {
section = TREE_VALUE(TREE_VALUE(section));
- if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
+ if (STRING_EQUAL(section, ".init.text"))
return false;
- if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
+ if (STRING_EQUAL(section, ".devinit.text"))
return false;
- if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
+ if (STRING_EQUAL(section, ".cpuinit.text"))
return false;
- if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
+ if (STRING_EQUAL(section, ".meminit.text"))
return false;
}
--
2.34.1
next prev parent reply other threads:[~2022-03-28 11:23 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-28 11:19 [PATCH AUTOSEL 5.16 01/35] LSM: general protection fault in legacy_parse_param Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 02/35] regulator: rpi-panel: Handle I2C errors/timing to the Atmel Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 03/35] crypto: hisilicon/qm - cleanup warning in qm_vf_read_qos Sasha Levin
2022-03-28 11:19 ` Sasha Levin [this message]
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 05/35] rcu: Kill rnp->ofl_seq and use only rcu_state.ofl_lock for exclusion Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 06/35] pinctrl: npcm: Fix broken references to chip->parent_device Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 07/35] rcu: Mark writes to the rcu_segcblist structure's ->flags field Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 08/35] block: throttle split bio in case of iops limit Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 09/35] memstick/mspro_block: fix handling of read-only devices Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 10/35] block/bfq_wf2q: correct weight to ioprio Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 11/35] crypto: xts - Add softdep on ecb Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 12/35] crypto: hisilicon/sec - not need to enable sm4 extra mode at HW V3 Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 13/35] block, bfq: don't move oom_bfqq Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 14/35] selinux: use correct type for context length Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 15/35] powercap/dtpm_cpu: Reset per_cpu variable in the release function Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 16/35] arm64: module: remove (NOLOAD) from linker script Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 17/35] selinux: allow FIOCLEX and FIONCLEX with policy capability Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 18/35] loop: use sysfs_emit() in the sysfs xxx show() Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 19/35] Fix incorrect type in assignment of ipv6 port for audit Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 20/35] irqchip/qcom-pdc: Fix broken locking Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 21/35] irqchip/nvic: Release nvic_base upon failure Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 22/35] fs/binfmt_elf: Fix AT_PHDR for unusual ELF files Sasha Levin
2022-03-28 11:19 ` [PATCH AUTOSEL 5.16 23/35] signal, x86: Delay calling signals in atomic on RT enabled kernels Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 24/35] bfq: fix use-after-free in bfq_dispatch_request Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 25/35] ACPICA: Avoid walking the ACPI Namespace if it is not there Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 26/35] lib/raid6/test/Makefile: Use $(pound) instead of \# for Make 4.3 Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 27/35] Revert "Revert "block, bfq: honor already-setup queue merges"" Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 28/35] ACPI/APEI: Limit printable size of BERT table data Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 29/35] PM: core: keep irq flags in device_pm_check_callbacks() Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 30/35] parisc: Fix non-access data TLB cache flush faults Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 31/35] parisc: Fix handling off probe non-access faults Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 32/35] nvme-tcp: lockdep: annotate in-kernel sockets Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 33/35] spi: tegra20: Use of_device_get_match_data() Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 34/35] Revert "ACPI: Pass the same capabilities to the _OSC regardless of the query flag" Sasha Levin
2022-03-28 11:20 ` [PATCH AUTOSEL 5.16 35/35] spi: fsi: Implement a timeout for polling status Sasha Levin
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=20220328112011.1555169-4-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=alex.popov@linux.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@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