mirror of https://gitee.com/Nocallback/glibc.git
Browse Source
This is a workaround for [BZ #20839] which doesn't remove the NODELETE object when _dl_open_check throws an exception. Move it after relocation in dl_open_worker to avoid leaving the NODELETE object mapped without relocation. [BZ #24259] * elf/dl-open.c (dl_open_worker): Call _dl_open_check after relocation. * sysdeps/x86/Makefile (tests): Add tst-cet-legacy-5a, tst-cet-legacy-5b, tst-cet-legacy-6a and tst-cet-legacy-6b. (modules-names): Add tst-cet-legacy-mod-5a, tst-cet-legacy-mod-5b, tst-cet-legacy-mod-5c, tst-cet-legacy-mod-6a, tst-cet-legacy-mod-6b and tst-cet-legacy-mod-6c. (CFLAGS-tst-cet-legacy-5a.c): New. (CFLAGS-tst-cet-legacy-5b.c): Likewise. (CFLAGS-tst-cet-legacy-mod-5a.c): Likewise. (CFLAGS-tst-cet-legacy-mod-5b.c): Likewise. (CFLAGS-tst-cet-legacy-mod-5c.c): Likewise. (CFLAGS-tst-cet-legacy-6a.c): Likewise. (CFLAGS-tst-cet-legacy-6b.c): Likewise. (CFLAGS-tst-cet-legacy-mod-6a.c): Likewise. (CFLAGS-tst-cet-legacy-mod-6b.c): Likewise. (CFLAGS-tst-cet-legacy-mod-6c.c): Likewise. ($(objpfx)tst-cet-legacy-5a): Likewise. ($(objpfx)tst-cet-legacy-5a.out): Likewise. ($(objpfx)tst-cet-legacy-mod-5a.so): Likewise. ($(objpfx)tst-cet-legacy-mod-5b.so): Likewise. ($(objpfx)tst-cet-legacy-5b): Likewise. ($(objpfx)tst-cet-legacy-5b.out): Likewise. (tst-cet-legacy-5b-ENV): Likewise. ($(objpfx)tst-cet-legacy-6a): Likewise. ($(objpfx)tst-cet-legacy-6a.out): Likewise. ($(objpfx)tst-cet-legacy-mod-6a.so): Likewise. ($(objpfx)tst-cet-legacy-mod-6b.so): Likewise. ($(objpfx)tst-cet-legacy-6b): Likewise. ($(objpfx)tst-cet-legacy-6b.out): Likewise. (tst-cet-legacy-6b-ENV): Likewise. * sysdeps/x86/tst-cet-legacy-5.c: New file. * sysdeps/x86/tst-cet-legacy-5a.c: Likewise. * sysdeps/x86/tst-cet-legacy-5b.c: Likewise. * sysdeps/x86/tst-cet-legacy-6.c: Likewise. * sysdeps/x86/tst-cet-legacy-6a.c: Likewise. * sysdeps/x86/tst-cet-legacy-6b.c: Likewise. * sysdeps/x86/tst-cet-legacy-mod-5.c: Likewise. * sysdeps/x86/tst-cet-legacy-mod-5a.c: Likewise. * sysdeps/x86/tst-cet-legacy-mod-5b.c: Likewise. * sysdeps/x86/tst-cet-legacy-mod-5c.c: Likewise. * sysdeps/x86/tst-cet-legacy-mod-6.c: Likewise. * sysdeps/x86/tst-cet-legacy-mod-6a.c: Likewise. * sysdeps/x86/tst-cet-legacy-mod-6b.c: Likewise. * sysdeps/x86/tst-cet-legacy-mod-6c.c: Likewise.nsz/mathvec
18 changed files with 387 additions and 5 deletions
@ -0,0 +1,76 @@ |
|||
/* Check compatibility of CET-enabled executable with dlopened legacy
|
|||
shared object. |
|||
Copyright (C) 2019 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> |
|||
#include <stdbool.h> |
|||
#include <string.h> |
|||
|
|||
static void |
|||
do_test_1 (const char *modname, bool fail) |
|||
{ |
|||
int (*fp) (void); |
|||
void *h; |
|||
|
|||
h = dlopen (modname, RTLD_LAZY); |
|||
if (h == NULL) |
|||
{ |
|||
if (fail) |
|||
{ |
|||
const char *err = dlerror (); |
|||
if (strstr (err, "shadow stack isn't enabled") == NULL) |
|||
{ |
|||
printf ("incorrect dlopen '%s' error: %s\n", modname, |
|||
dlerror ()); |
|||
exit (1); |
|||
} |
|||
|
|||
return; |
|||
} |
|||
|
|||
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); |
|||
} |
|||
|
|||
static int |
|||
do_test (void) |
|||
{ |
|||
do_test_1 ("tst-cet-legacy-mod-5a.so", true); |
|||
do_test_1 ("tst-cet-legacy-mod-5b.so", false); |
|||
return 0; |
|||
} |
|||
|
|||
#include <support/test-driver.c> |
|||
@ -0,0 +1 @@ |
|||
#include "tst-cet-legacy-5.c" |
|||
@ -0,0 +1 @@ |
|||
#include "tst-cet-legacy-5.c" |
|||
@ -0,0 +1,76 @@ |
|||
/* Check compatibility of CET-enabled executable with dlopened legacy
|
|||
shared object. |
|||
Copyright (C) 2019 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> |
|||
#include <stdbool.h> |
|||
#include <string.h> |
|||
|
|||
static void |
|||
do_test_1 (const char *modname, bool fail) |
|||
{ |
|||
int (*fp) (void); |
|||
void *h; |
|||
|
|||
h = dlopen (modname, RTLD_LAZY); |
|||
if (h == NULL) |
|||
{ |
|||
if (fail) |
|||
{ |
|||
const char *err = dlerror (); |
|||
if (strstr (err, "shadow stack isn't enabled") == NULL) |
|||
{ |
|||
printf ("incorrect dlopen '%s' error: %s\n", modname, |
|||
dlerror ()); |
|||
exit (1); |
|||
} |
|||
|
|||
return; |
|||
} |
|||
|
|||
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); |
|||
} |
|||
|
|||
static int |
|||
do_test (void) |
|||
{ |
|||
do_test_1 ("tst-cet-legacy-mod-6a.so", true); |
|||
do_test_1 ("tst-cet-legacy-mod-6b.so", false); |
|||
return 0; |
|||
} |
|||
|
|||
#include <support/test-driver.c> |
|||
@ -0,0 +1 @@ |
|||
#include "tst-cet-legacy-6.c" |
|||
@ -0,0 +1 @@ |
|||
#include "tst-cet-legacy-6.c" |
|||
@ -0,0 +1,31 @@ |
|||
/* Check compatibility of CET-enabled executable with dlopened legacy
|
|||
shared object. |
|||
Copyright (C) 2019 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 <error.h> |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
|
|||
extern void foo (void); |
|||
|
|||
int |
|||
test (void) |
|||
{ |
|||
foo (); |
|||
return 0; |
|||
} |
|||
@ -0,0 +1 @@ |
|||
#include "tst-cet-legacy-mod-5.c" |
|||
@ -0,0 +1 @@ |
|||
#include "tst-cet-legacy-mod-5.c" |
|||
@ -0,0 +1,36 @@ |
|||
/* Check compatibility of CET-enabled executable with dlopened legacy
|
|||
shared object. |
|||
Copyright (C) 2019 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 <stdlib.h> |
|||
|
|||
static int called = 0; |
|||
|
|||
static void |
|||
__attribute__ ((constructor)) |
|||
init (void) |
|||
{ |
|||
called = 1; |
|||
} |
|||
|
|||
void |
|||
foo (void) |
|||
{ |
|||
if (!called) |
|||
abort (); |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/* Check compatibility of CET-enabled executable with dlopened legacy
|
|||
shared object. |
|||
Copyright (C) 2019 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 <error.h> |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
|
|||
extern void foo (void); |
|||
|
|||
int |
|||
test (void) |
|||
{ |
|||
foo (); |
|||
return 0; |
|||
} |
|||
@ -0,0 +1 @@ |
|||
#include "tst-cet-legacy-mod-6.c" |
|||
@ -0,0 +1 @@ |
|||
#include "tst-cet-legacy-mod-6.c" |
|||
@ -0,0 +1,36 @@ |
|||
/* Check compatibility of CET-enabled executable with dlopened legacy
|
|||
shared object. |
|||
Copyright (C) 2019 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 <stdlib.h> |
|||
|
|||
static int called = 0; |
|||
|
|||
static void |
|||
__attribute__ ((constructor)) |
|||
init (void) |
|||
{ |
|||
called = 1; |
|||
} |
|||
|
|||
void |
|||
foo (void) |
|||
{ |
|||
if (!called) |
|||
abort (); |
|||
} |
|||
@ -0,0 +1 @@ |
|||
#include "tst-cet-legacy-mod-6c.c" |
|||
Loading…
Reference in new issue