Blame support/support_ptrace.c

Packit Bot 56bdcd
/* Support functions handling ptrace_scope.
Packit Bot 56bdcd
   Copyright (C) 2019 Free Software Foundation, Inc.
Packit Bot 56bdcd
   This file is part of the GNU C Library.
Packit Bot 56bdcd
Packit Bot 56bdcd
   The GNU C Library is free software; you can redistribute it and/or
Packit Bot 56bdcd
   modify it under the terms of the GNU Lesser General Public
Packit Bot 56bdcd
   License as published by the Free Software Foundation; either
Packit Bot 56bdcd
   version 2.1 of the License, or (at your option) any later version.
Packit Bot 56bdcd
Packit Bot 56bdcd
   The GNU C Library is distributed in the hope that it will be useful,
Packit Bot 56bdcd
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 56bdcd
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot 56bdcd
   Lesser General Public License for more details.
Packit Bot 56bdcd
Packit Bot 56bdcd
   You should have received a copy of the GNU Lesser General Public
Packit Bot 56bdcd
   License along with the GNU C Library; if not, see
Packit Bot 56bdcd
   <https://www.gnu.org/licenses/>.  */
Packit Bot 56bdcd
Packit Bot 56bdcd
#include <support/check.h>
Packit Bot 56bdcd
#include <support/xstdio.h>
Packit Bot 56bdcd
#include <support/xptrace.h>
Packit Bot 56bdcd
Packit Bot 56bdcd
int
Packit Bot 56bdcd
support_ptrace_scope (void)
Packit Bot 56bdcd
{
Packit Bot 56bdcd
  int ptrace_scope = -1;
Packit Bot 56bdcd
Packit Bot 56bdcd
#ifdef __linux__
Packit Bot 56bdcd
  /* YAMA may be not enabled.  Otherwise it contains a value from 0 to 3:
Packit Bot 56bdcd
     - 0 classic ptrace permissions
Packit Bot 56bdcd
     - 1 restricted ptrace
Packit Bot 56bdcd
     - 2 admin-only attach
Packit Bot 56bdcd
     - 3 no attach  */
Packit Bot 56bdcd
  FILE *f = fopen ("/proc/sys/kernel/yama/ptrace_scope", "r");
Packit Bot 56bdcd
  if (f != NULL)
Packit Bot 56bdcd
    {
Packit Bot 56bdcd
      TEST_COMPARE (fscanf (f, "%d", &ptrace_scope), 1);
Packit Bot 56bdcd
      xfclose (f);
Packit Bot 56bdcd
    }
Packit Bot 56bdcd
#endif
Packit Bot 56bdcd
Packit Bot 56bdcd
  return ptrace_scope;
Packit Bot 56bdcd
}