All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: u-boot@lists.denx.de
Subject: [PATCH] stackprot: Make our test a bit more complex
Date: Mon, 24 May 2021 14:59:13 -0400	[thread overview]
Message-ID: <20210524185913.10422-1-trini@konsulko.com> (raw)

With better compiler optimizations available, a compiler may see we do
nothing with our buffer after calling memset and omit the call, thus
causing us to not smash the stack.  Add a comment to explain why we now
also have a printf call, so that the test will pass as the memset will
not be omitted.

Reported-by: Marek Behún <marek.behun@nic.cz>
Signed-off-by: Tom Rini <trini@konsulko.com>
---
 cmd/stackprot_test.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/cmd/stackprot_test.c b/cmd/stackprot_test.c
index 36f5bac8d230..1e26193e88b0 100644
--- a/cmd/stackprot_test.c
+++ b/cmd/stackprot_test.c
@@ -9,9 +9,16 @@
 static int do_test_stackprot_fail(struct cmd_tbl *cmdtp, int flag, int argc,
 				  char *const argv[])
 {
+	/*
+	 * In order to avoid having the compiler optimize away the stack smashing
+	 * we need to do a little something here.
+	 */
 	char a[128];
 
 	memset(a, 0xa5, 512);
+
+	printf("We have smashed our stack as this should not exceed 128: sizeof(a) = %ld\n", strlen(a));
+
 	return 0;
 }
 
-- 
2.17.1


             reply	other threads:[~2021-05-24 18:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24 18:59 Tom Rini [this message]
2021-05-25  0:58 ` [PATCH] stackprot: Make our test a bit more complex Tom Rini

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=20210524185913.10422-1-trini@konsulko.com \
    --to=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.