]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86/CET: Add tests with legacy non-CET shared objects
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 25 Jul 2018 11:46:53 +0000 (04:46 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 25 Jul 2018 11:47:05 +0000 (04:47 -0700)
Check binary compatibility of CET-enabled executables:

1. When CET-enabled executable is used with legacy non-CET shared object
at run-time, ld.so should disable SHSTK and put legacy non-CET shared
objects in legacy bitmap.
2. When IBT-enabled executable dlopens legacy non-CET shared object,
ld.so should put legacy shared object in legacy bitmap.
3. Use GLIBC_TUNABLES=glibc.tune.x86_shstk=[on|off|permissive] to
control how SHSTK is enabled.

* sysdeps/x86/Makefile (tests): Add tst-cet-legacy-1,
tst-cet-legacy-2, tst-cet-legacy-2a, tst-cet-legacy-3,
tst-cet-legacy-4, tst-cet-legacy-4a, tst-cet-legacy-4b
and tst-cet-legacy-4c.
(modules-names): Add tst-cet-legacy-mod-1, tst-cet-legacy-mod-2
and tst-cet-legacy-mod-4.
(CFLAGS-tst-cet-legacy-2.c): New.
(CFLAGS-tst-cet-legacy-mod-1.c): Likewise.
(CFLAGS-tst-cet-legacy-mod-2.c): Likewise.
(CFLAGS-tst-cet-legacy-3.c): Likewise.
(CFLAGS-tst-cet-legacy-4.c): Likewise.
(CFLAGS-tst-cet-legacy-mod-4.c): Likewise.
($(objpfx)tst-cet-legacy-1): Likewise.
($(objpfx)tst-cet-legacy-2): Likewise.
($(objpfx)tst-cet-legacy-2.out): Likewise.
($(objpfx)tst-cet-legacy-2a): Likewise.
($(objpfx)tst-cet-legacy-2a.out): Likewise.
($(objpfx)tst-cet-legacy-4): Likewise.
($(objpfx)tst-cet-legacy-4.out): Likewise.
($(objpfx)tst-cet-legacy-4a): Likewise.
($(objpfx)tst-cet-legacy-4a.out): Likewise.
(tst-cet-legacy-4a-ENV): Likewise.
($(objpfx)tst-cet-legacy-4b): Likewise.
($(objpfx)tst-cet-legacy-4b.out): Likewise.
(tst-cet-legacy-4b-ENV): Likewise.
($(objpfx)tst-cet-legacy-4c): Likewise.
($(objpfx)tst-cet-legacy-4c.out): Likewise.
(tst-cet-legacy-4c-ENV): Likewise.
* sysdeps/x86/tst-cet-legacy-1.c: New file.
* sysdeps/x86/tst-cet-legacy-2.c: Likewise.
* sysdeps/x86/tst-cet-legacy-2a.c: Likewise.
* sysdeps/x86/tst-cet-legacy-3.c: Likewise.
* sysdeps/x86/tst-cet-legacy-4.c: Likewise.
* sysdeps/x86/tst-cet-legacy-4a.c: Likewise.
* sysdeps/x86/tst-cet-legacy-4b.c: Likewise.
* sysdeps/x86/tst-cet-legacy-4c.c: Likewise.
* sysdeps/x86/tst-cet-legacy-mod-1.c: Likewise.
* sysdeps/x86/tst-cet-legacy-mod-2.c: Likewise.
* sysdeps/x86/tst-cet-legacy-mod-4.c: Likewise.

13 files changed:
ChangeLog
sysdeps/x86/Makefile
sysdeps/x86/tst-cet-legacy-1.c [new file with mode: 0644]
sysdeps/x86/tst-cet-legacy-2.c [new file with mode: 0644]
sysdeps/x86/tst-cet-legacy-2a.c [new file with mode: 0644]
sysdeps/x86/tst-cet-legacy-3.c [new file with mode: 0644]
sysdeps/x86/tst-cet-legacy-4.c [new file with mode: 0644]
sysdeps/x86/tst-cet-legacy-4a.c [new file with mode: 0644]
sysdeps/x86/tst-cet-legacy-4b.c [new file with mode: 0644]
sysdeps/x86/tst-cet-legacy-4c.c [new file with mode: 0644]
sysdeps/x86/tst-cet-legacy-mod-1.c [new file with mode: 0644]
sysdeps/x86/tst-cet-legacy-mod-2.c [new file with mode: 0644]
sysdeps/x86/tst-cet-legacy-mod-4.c [new file with mode: 0644]

index fb4a45bacc2c4c1a84226df3cf07fa66ab13d8ac..d387465f2985b20ad37373a905718129e100a35f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,45 @@
+2018-07-25  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * sysdeps/x86/Makefile (tests): Add tst-cet-legacy-1,
+       tst-cet-legacy-2, tst-cet-legacy-2a, tst-cet-legacy-3,
+       tst-cet-legacy-4, tst-cet-legacy-4a, tst-cet-legacy-4b
+       and tst-cet-legacy-4c.
+       (modules-names): Add tst-cet-legacy-mod-1, tst-cet-legacy-mod-2
+       and tst-cet-legacy-mod-4.
+       (CFLAGS-tst-cet-legacy-2.c): New.
+       (CFLAGS-tst-cet-legacy-mod-1.c): Likewise.
+       (CFLAGS-tst-cet-legacy-mod-2.c): Likewise.
+       (CFLAGS-tst-cet-legacy-3.c): Likewise.
+       (CFLAGS-tst-cet-legacy-4.c): Likewise.
+       (CFLAGS-tst-cet-legacy-mod-4.c): Likewise.
+       ($(objpfx)tst-cet-legacy-1): Likewise.
+       ($(objpfx)tst-cet-legacy-2): Likewise.
+       ($(objpfx)tst-cet-legacy-2.out): Likewise.
+       ($(objpfx)tst-cet-legacy-2a): Likewise.
+       ($(objpfx)tst-cet-legacy-2a.out): Likewise.
+       ($(objpfx)tst-cet-legacy-4): Likewise.
+       ($(objpfx)tst-cet-legacy-4.out): Likewise.
+       ($(objpfx)tst-cet-legacy-4a): Likewise.
+       ($(objpfx)tst-cet-legacy-4a.out): Likewise.
+       (tst-cet-legacy-4a-ENV): Likewise.
+       ($(objpfx)tst-cet-legacy-4b): Likewise.
+       ($(objpfx)tst-cet-legacy-4b.out): Likewise.
+       (tst-cet-legacy-4b-ENV): Likewise.
+       ($(objpfx)tst-cet-legacy-4c): Likewise.
+       ($(objpfx)tst-cet-legacy-4c.out): Likewise.
+       (tst-cet-legacy-4c-ENV): Likewise.
+       * sysdeps/x86/tst-cet-legacy-1.c: New file.
+       * sysdeps/x86/tst-cet-legacy-2.c: Likewise.
+       * sysdeps/x86/tst-cet-legacy-2a.c: Likewise.
+       * sysdeps/x86/tst-cet-legacy-3.c: Likewise.
+       * sysdeps/x86/tst-cet-legacy-4.c: Likewise.
+       * sysdeps/x86/tst-cet-legacy-4a.c: Likewise.
+       * sysdeps/x86/tst-cet-legacy-4b.c: Likewise.
+       * sysdeps/x86/tst-cet-legacy-4c.c: Likewise.
+       * sysdeps/x86/tst-cet-legacy-mod-1.c: Likewise.
+       * sysdeps/x86/tst-cet-legacy-mod-2.c: Likewise.
+       * sysdeps/x86/tst-cet-legacy-mod-4.c: Likewise.
+
 2018-07-25  H.J. Lu  <hongjiu.lu@intel.com>
 
        * sysdeps/i386/nptl/tcb-offsets.sym (SSP_BASE_OFFSET): New.
index e9b2d0b35dad0bb9280ac30cf8089ca38a029046..672bb19489fdb1c78e2b9598da767d6a36c02f5e 100644 (file)
@@ -17,6 +17,44 @@ endif
 ifeq ($(enable-cet),yes)
 ifeq ($(subdir),elf)
 sysdep-dl-routines += dl-cet
+
+tests += tst-cet-legacy-1 tst-cet-legacy-2 tst-cet-legacy-2a \
+        tst-cet-legacy-3 tst-cet-legacy-4
+ifneq (no,$(have-tunables))
+tests += tst-cet-legacy-4a tst-cet-legacy-4b tst-cet-legacy-4c
+endif
+modules-names += tst-cet-legacy-mod-1 tst-cet-legacy-mod-2 \
+                tst-cet-legacy-mod-4
+
+CFLAGS-tst-cet-legacy-2.c += -fcf-protection=branch
+CFLAGS-tst-cet-legacy-2a.c += -fcf-protection
+CFLAGS-tst-cet-legacy-mod-1.c += -fcf-protection=none
+CFLAGS-tst-cet-legacy-mod-2.c += -fcf-protection=none
+CFLAGS-tst-cet-legacy-3.c += -fcf-protection=none
+CFLAGS-tst-cet-legacy-4.c += -fcf-protection=branch
+CFLAGS-tst-cet-legacy-4a.c += -fcf-protection
+CFLAGS-tst-cet-legacy-4b.c += -fcf-protection
+CFLAGS-tst-cet-legacy-mod-4.c += -fcf-protection=none
+
+$(objpfx)tst-cet-legacy-1: $(objpfx)tst-cet-legacy-mod-1.so \
+                      $(objpfx)tst-cet-legacy-mod-2.so
+$(objpfx)tst-cet-legacy-2: $(objpfx)tst-cet-legacy-mod-2.so $(libdl)
+$(objpfx)tst-cet-legacy-2.out: $(objpfx)tst-cet-legacy-mod-1.so
+$(objpfx)tst-cet-legacy-2a: $(objpfx)tst-cet-legacy-mod-2.so $(libdl)
+$(objpfx)tst-cet-legacy-2a.out: $(objpfx)tst-cet-legacy-mod-1.so
+$(objpfx)tst-cet-legacy-4: $(libdl)
+$(objpfx)tst-cet-legacy-4.out: $(objpfx)tst-cet-legacy-mod-4.so
+ifneq (no,$(have-tunables))
+$(objpfx)tst-cet-legacy-4a: $(libdl)
+$(objpfx)tst-cet-legacy-4a.out: $(objpfx)tst-cet-legacy-mod-4.so
+tst-cet-legacy-4a-ENV = GLIBC_TUNABLES=glibc.tune.x86_shstk=permissive
+$(objpfx)tst-cet-legacy-4b: $(libdl)
+$(objpfx)tst-cet-legacy-4b.out: $(objpfx)tst-cet-legacy-mod-4.so
+tst-cet-legacy-4b-ENV = GLIBC_TUNABLES=glibc.tune.x86_shstk=on
+$(objpfx)tst-cet-legacy-4c: $(libdl)
+$(objpfx)tst-cet-legacy-4c.out: $(objpfx)tst-cet-legacy-mod-4.so
+tst-cet-legacy-4c-ENV = GLIBC_TUNABLES=glibc.tune.x86_shstk=off
+endif
 endif
 
 # Add -fcf-protection to CFLAGS when CET is enabled.
diff --git a/sysdeps/x86/tst-cet-legacy-1.c b/sysdeps/x86/tst-cet-legacy-1.c
new file mode 100644 (file)
index 0000000..861c09a
--- /dev/null
@@ -0,0 +1,44 @@
+/* Check compatibility of CET-enabled executable linked with legacy
+   shared object.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+extern int in_dso_1 (void);
+extern int in_dso_2 (void);
+
+static int
+do_test (void)
+{
+  if (in_dso_1 () != 0x1234678)
+    {
+      puts ("in_dso_1 () != 0x1234678");
+      exit (1);
+    }
+
+  if (in_dso_2 () != 0xbadbeef)
+    {
+      puts ("in_dso_2 () != 0xbadbeef");
+      exit (1);
+    }
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/x86/tst-cet-legacy-2.c b/sysdeps/x86/tst-cet-legacy-2.c
new file mode 100644 (file)
index 0000000..e039a16
--- /dev/null
@@ -0,0 +1,64 @@
+/* Check compatibility of CET-enabled executable with dlopened legacy
+   shared object.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+extern int in_dso_2 (void);
+
+static int
+do_test (void)
+{
+  static const char modname[] = "tst-cet-legacy-mod-1.so";
+  int (*fp) (void);
+  void *h;
+
+  h = dlopen (modname, RTLD_LAZY);
+  if (h == NULL)
+    {
+      printf ("cannot open '%s': %s\n", modname, dlerror ());
+      exit (1);
+    }
+
+  fp = dlsym (h, "in_dso_1");
+  if (fp == NULL)
+    {
+      printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
+      exit (1);
+    }
+
+  if (fp () != 0x1234678)
+    {
+      puts ("in_dso_1 () != 0x1234678");
+      exit (1);
+    }
+
+  if (in_dso_2 () != 0xbadbeef)
+    {
+      puts ("in_dso_2 () != 0xbadbeef");
+      exit (1);
+    }
+
+  dlclose (h);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/x86/tst-cet-legacy-2a.c b/sysdeps/x86/tst-cet-legacy-2a.c
new file mode 100644 (file)
index 0000000..d5aead4
--- /dev/null
@@ -0,0 +1 @@
+#include "tst-cet-legacy-2.c"
diff --git a/sysdeps/x86/tst-cet-legacy-3.c b/sysdeps/x86/tst-cet-legacy-3.c
new file mode 100644 (file)
index 0000000..bab9faa
--- /dev/null
@@ -0,0 +1,37 @@
+/* Check compatibility of CET-enabled executable with dlopened legacy
+   shared object.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+
+int
+test (void)
+{
+  printf ("PASS\n");
+  return 0;
+}
+
+#ifndef TEST_MODULE
+static int
+do_test (void)
+{
+  return test ();
+}
+
+#include <support/test-driver.c>
+#endif
diff --git a/sysdeps/x86/tst-cet-legacy-4.c b/sysdeps/x86/tst-cet-legacy-4.c
new file mode 100644 (file)
index 0000000..3ead63d
--- /dev/null
@@ -0,0 +1,56 @@
+/* Check compatibility of CET-enabled executable with dlopened legacy
+   shared object.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static int
+do_test (void)
+{
+  static const char modname[] = "tst-cet-legacy-mod-4.so";
+  int (*fp) (void);
+  void *h;
+
+  h = dlopen (modname, RTLD_LAZY);
+  if (h == NULL)
+    {
+      printf ("cannot open '%s': %s\n", modname, dlerror ());
+      exit (1);
+    }
+
+  fp = dlsym (h, "test");
+  if (fp == NULL)
+    {
+      printf ("cannot get symbol 'test': %s\n", dlerror ());
+      exit (1);
+    }
+
+  if (fp () != 0)
+    {
+      puts ("test () != 0");
+      exit (1);
+    }
+
+  dlclose (h);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/x86/tst-cet-legacy-4a.c b/sysdeps/x86/tst-cet-legacy-4a.c
new file mode 100644 (file)
index 0000000..b9bb18c
--- /dev/null
@@ -0,0 +1 @@
+#include "tst-cet-legacy-4.c"
diff --git a/sysdeps/x86/tst-cet-legacy-4b.c b/sysdeps/x86/tst-cet-legacy-4b.c
new file mode 100644 (file)
index 0000000..b9bb18c
--- /dev/null
@@ -0,0 +1 @@
+#include "tst-cet-legacy-4.c"
diff --git a/sysdeps/x86/tst-cet-legacy-4c.c b/sysdeps/x86/tst-cet-legacy-4c.c
new file mode 100644 (file)
index 0000000..b9bb18c
--- /dev/null
@@ -0,0 +1 @@
+#include "tst-cet-legacy-4.c"
diff --git a/sysdeps/x86/tst-cet-legacy-mod-1.c b/sysdeps/x86/tst-cet-legacy-mod-1.c
new file mode 100644 (file)
index 0000000..09762bc
--- /dev/null
@@ -0,0 +1,24 @@
+/* Check compatibility of CET-enabled executable with legacy shared
+   object.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+int
+in_dso_1 (void)
+{
+  return 0x1234678;
+}
diff --git a/sysdeps/x86/tst-cet-legacy-mod-2.c b/sysdeps/x86/tst-cet-legacy-mod-2.c
new file mode 100644 (file)
index 0000000..1c8de44
--- /dev/null
@@ -0,0 +1,24 @@
+/* Check compatibility of CET-enabled executable with legacy shared
+   object.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+int
+in_dso_2 (void)
+{
+  return 0xbadbeef;
+}
diff --git a/sysdeps/x86/tst-cet-legacy-mod-4.c b/sysdeps/x86/tst-cet-legacy-mod-4.c
new file mode 100644 (file)
index 0000000..a93c2fe
--- /dev/null
@@ -0,0 +1,2 @@
+#define TEST_MODULE
+#include "tst-cet-legacy-3.c"