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

Packit Bot 36190f
/* Check incompatibility with legacy JIT engine.
Packit Bot 36190f
   Copyright (C) 2020 Free Software Foundation, Inc.
Packit Bot 36190f
   This file is part of the GNU C Library.
Packit Bot 36190f
Packit Bot 36190f
   The GNU C Library is free software; you can redistribute it and/or
Packit Bot 36190f
   modify it under the terms of the GNU Lesser General Public
Packit Bot 36190f
   License as published by the Free Software Foundation; either
Packit Bot 36190f
   version 2.1 of the License, or (at your option) any later version.
Packit Bot 36190f
Packit Bot 36190f
   The GNU C Library is distributed in the hope that it will be useful,
Packit Bot 36190f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 36190f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot 36190f
   Lesser General Public License for more details.
Packit Bot 36190f
Packit Bot 36190f
   You should have received a copy of the GNU Lesser General Public
Packit Bot 36190f
   License along with the GNU C Library; if not, see
Packit Bot 36190f
   <https://www.gnu.org/licenses/>.  */
Packit Bot 36190f
Packit Bot 36190f
#include <stdio.h>
Packit Bot 36190f
#include <stdlib.h>
Packit Bot 36190f
#include <x86intrin.h>
Packit Bot 36190f
#include <sys/mman.h>
Packit Bot 36190f
#include <support/test-driver.h>
Packit Bot 36190f
#include <support/xsignal.h>
Packit Bot 36190f
#include <support/xunistd.h>
Packit Bot 36190f
Packit Bot 36190f
/* Check that mmapped legacy code trigges segfault with -fcf-protection.  */
Packit Bot 36190f
Packit Bot 36190f
static int
Packit Bot 36190f
do_test (void)
Packit Bot 36190f
{
Packit Bot 36190f
  /* NB: This test should trigger SIGSEGV on CET platforms.  If SHSTK
Packit Bot 36190f
     is disabled, assuming IBT is also disabled.  */
Packit Bot 36190f
  if (_get_ssp () == 0)
Packit Bot 36190f
    return EXIT_UNSUPPORTED;
Packit Bot 36190f
Packit Bot 36190f
  void (*funcp) (void);
Packit Bot 36190f
  funcp = xmmap (NULL, 0x1000, PROT_EXEC | PROT_READ | PROT_WRITE,
Packit Bot 36190f
		 MAP_ANONYMOUS | MAP_PRIVATE, -1);
Packit Bot 36190f
  printf ("mmap = %p\n", funcp);
Packit Bot 36190f
  /* Write RET instruction.  */
Packit Bot 36190f
  *(char *) funcp = 0xc3;
Packit Bot 36190f
  funcp ();
Packit Bot 36190f
  return EXIT_FAILURE;
Packit Bot 36190f
}
Packit Bot 36190f
Packit Bot 36190f
#define EXPECTED_SIGNAL (_get_ssp () == 0 ? 0 : SIGSEGV)
Packit Bot 36190f
#include <support/test-driver.c>