|
Packit Service |
654f5f |
/* Check compatibility of CET-enabled executable with dlopened legacy
|
|
Packit Service |
654f5f |
shared object.
|
|
Packit Service |
654f5f |
Copyright (C) 2019 Free Software Foundation, Inc.
|
|
Packit Service |
654f5f |
This file is part of the GNU C Library.
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
654f5f |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
654f5f |
License as published by the Free Software Foundation; either
|
|
Packit Service |
654f5f |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
654f5f |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
654f5f |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
654f5f |
Lesser General Public License for more details.
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
654f5f |
License along with the GNU C Library; if not, see
|
|
Packit Service |
654f5f |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
#include <dlfcn.h>
|
|
Packit Service |
654f5f |
#include <stdio.h>
|
|
Packit Service |
654f5f |
#include <stdlib.h>
|
|
Packit Service |
654f5f |
#include <stdbool.h>
|
|
Packit Service |
654f5f |
#include <string.h>
|
|
Packit Service |
cbca74 |
#include <x86intrin.h>
|
|
Packit Service |
cbca74 |
#include <support/check.h>
|
|
Packit Service |
cbca74 |
|
|
Packit Service |
cbca74 |
#if defined CET_IS_PERMISSIVE || defined CET_DISABLED_BY_ENV
|
|
Packit Service |
cbca74 |
# define CET_MAYBE_DISABLED 1
|
|
Packit Service |
cbca74 |
#else
|
|
Packit Service |
cbca74 |
# define CET_MAYBE_DISABLED 0
|
|
Packit Service |
cbca74 |
#endif
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
static void
|
|
Packit Service |
654f5f |
do_test_1 (const char *modname, bool fail)
|
|
Packit Service |
654f5f |
{
|
|
Packit Service |
654f5f |
int (*fp) (void);
|
|
Packit Service |
654f5f |
void *h;
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
h = dlopen (modname, RTLD_LAZY);
|
|
Packit Service |
654f5f |
if (h == NULL)
|
|
Packit Service |
654f5f |
{
|
|
Packit Service |
cbca74 |
const char *err = dlerror ();
|
|
Packit Service |
654f5f |
if (fail)
|
|
Packit Service |
654f5f |
{
|
|
Packit Service |
032cfe |
if (strstr (err, "rebuild shared object with SHSTK support enabled")
|
|
Packit Service |
032cfe |
== NULL)
|
|
Packit Service |
cbca74 |
FAIL_EXIT1 ("incorrect dlopen '%s' error: %s\n", modname, err);
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
return;
|
|
Packit Service |
654f5f |
}
|
|
Packit Service |
654f5f |
|
|
Packit Service |
cbca74 |
FAIL_EXIT1 ("cannot open '%s': %s\n", modname, err);
|
|
Packit Service |
654f5f |
}
|
|
Packit Service |
654f5f |
|
|
Packit Service |
cbca74 |
/* NB: dlopen should never fail on non-CET platforms. If SHSTK is
|
|
Packit Service |
cbca74 |
disabled, assuming IBT is also disabled. */
|
|
Packit Service |
cbca74 |
bool cet_enabled = _get_ssp () != 0 && !CET_MAYBE_DISABLED;
|
|
Packit Service |
cbca74 |
if (fail && cet_enabled)
|
|
Packit Service |
cbca74 |
FAIL_EXIT1 ("dlopen should have failed\n");
|
|
Packit Service |
cbca74 |
|
|
Packit Service |
654f5f |
fp = dlsym (h, "test");
|
|
Packit Service |
654f5f |
if (fp == NULL)
|
|
Packit Service |
654f5f |
{
|
|
Packit Service |
654f5f |
printf ("cannot get symbol 'test': %s\n", dlerror ());
|
|
Packit Service |
654f5f |
exit (1);
|
|
Packit Service |
654f5f |
}
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
if (fp () != 0)
|
|
Packit Service |
654f5f |
{
|
|
Packit Service |
654f5f |
puts ("test () != 0");
|
|
Packit Service |
654f5f |
exit (1);
|
|
Packit Service |
654f5f |
}
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
dlclose (h);
|
|
Packit Service |
654f5f |
}
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
static int
|
|
Packit Service |
654f5f |
do_test (void)
|
|
Packit Service |
654f5f |
{
|
|
Packit Service |
654f5f |
do_test_1 ("tst-cet-legacy-mod-5a.so", true);
|
|
Packit Service |
654f5f |
do_test_1 ("tst-cet-legacy-mod-5b.so", false);
|
|
Packit Service |
654f5f |
return 0;
|
|
Packit Service |
654f5f |
}
|
|
Packit Service |
654f5f |
|
|
Packit Service |
654f5f |
#include <support/test-driver.c>
|