Blame support/support_ptrace.c

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