qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 1/1] configure: use appropriate code fragment for -fstack-protector checks
@ 2015-11-12 14:04 Rodrigo Rebello
  2015-11-12 16:10 ` Markus Armbruster
  2015-11-29 10:44 ` Michael Tokarev
  0 siblings, 2 replies; 3+ messages in thread
From: Rodrigo Rebello @ 2015-11-12 14:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Rodrigo Rebello, armbru

The check for stack-protector support consisted in compiling and linking
the test program below (output by function write_c_skeleton()) with the
compiler flag -fstack-protector-strong first and then with
-fstack-protector-all if the first one failed to work:

  int main(void) { return 0; }

This caused false positives when using certain toolchains in which the
compiler accepted -fstack-protector-strong but no support was provided
by the C library, since for this stack-protector variant the compiler
emits canary code only for functions that meet specific conditions
(local arrays, memory references to local variables, etc.) and the code
fragment under test included none of them (hence no stack protection
code generated, no link failure).

This fix changes the test program used for -fstack-protector checks to
include a function that meets conditions which cause the compiler to
generate canary code in all variants.

Signed-off-by: Rodrigo Rebello <rprebello@gmail.com>
---
Changes v1 -> v2:
  - Use a simpler test code that works.
---
 configure | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/configure b/configure
index 46fd8bd..d93c744 100755
--- a/configure
+++ b/configure
@@ -1486,6 +1486,16 @@ for flag in $gcc_flags; do
 done
 
 if test "$stack_protector" != "no"; then
+  cat > $TMPC << EOF
+int main(int argc, char *argv[])
+{
+    char arr[64], *p = arr, *c = argv[0];
+    while (*c) {
+        *p++ = *c++;
+    }
+    return 0;
+}
+EOF
   gcc_flags="-fstack-protector-strong -fstack-protector-all"
   sp_on=0
   for flag in $gcc_flags; do
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/1] configure: use appropriate code fragment for -fstack-protector checks
  2015-11-12 14:04 [Qemu-devel] [PATCH v2 1/1] configure: use appropriate code fragment for -fstack-protector checks Rodrigo Rebello
@ 2015-11-12 16:10 ` Markus Armbruster
  2015-11-29 10:44 ` Michael Tokarev
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2015-11-12 16:10 UTC (permalink / raw)
  To: Rodrigo Rebello; +Cc: qemu-trivial, qemu-devel

Rodrigo Rebello <rprebello@gmail.com> writes:

> The check for stack-protector support consisted in compiling and linking
> the test program below (output by function write_c_skeleton()) with the
> compiler flag -fstack-protector-strong first and then with
> -fstack-protector-all if the first one failed to work:
>
>   int main(void) { return 0; }
>
> This caused false positives when using certain toolchains in which the
> compiler accepted -fstack-protector-strong but no support was provided
> by the C library, since for this stack-protector variant the compiler
> emits canary code only for functions that meet specific conditions
> (local arrays, memory references to local variables, etc.) and the code
> fragment under test included none of them (hence no stack protection
> code generated, no link failure).
>
> This fix changes the test program used for -fstack-protector checks to
> include a function that meets conditions which cause the compiler to
> generate canary code in all variants.
>
> Signed-off-by: Rodrigo Rebello <rprebello@gmail.com>

Reviewed-by: Markus Armbruster <armbru@redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/1] configure: use appropriate code fragment for -fstack-protector checks
  2015-11-12 14:04 [Qemu-devel] [PATCH v2 1/1] configure: use appropriate code fragment for -fstack-protector checks Rodrigo Rebello
  2015-11-12 16:10 ` Markus Armbruster
@ 2015-11-29 10:44 ` Michael Tokarev
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Tokarev @ 2015-11-29 10:44 UTC (permalink / raw)
  To: Rodrigo Rebello, qemu-devel; +Cc: qemu-trivial, armbru

12.11.2015 17:04, Rodrigo Rebello wrote:
> The check for stack-protector support consisted in compiling and linking
> the test program below (output by function write_c_skeleton()) with the
> compiler flag -fstack-protector-strong first and then with
> -fstack-protector-all if the first one failed to work:
...

Applied to -trivial, thank you!

/mjt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-29 10:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-12 14:04 [Qemu-devel] [PATCH v2 1/1] configure: use appropriate code fragment for -fstack-protector checks Rodrigo Rebello
2015-11-12 16:10 ` Markus Armbruster
2015-11-29 10:44 ` Michael Tokarev

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).