Blame sysdeps/x86/tst-cet-legacy-6.c

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