1 // SPDX-License-Identifier: GPL-2.0-only
10 #include "unpriv_helpers.h"
12 static bool get_mitigations_off(void)
14 char cmdline[4096], *c;
17 fd = open("/proc/cmdline", O_RDONLY);
19 perror("open /proc/cmdline");
23 if (read(fd, cmdline, sizeof(cmdline) - 1) < 0) {
24 perror("read /proc/cmdline");
28 cmdline[sizeof(cmdline) - 1] = '\0';
29 for (c = strtok(cmdline, " \n"); c; c = strtok(NULL, " \n")) {
30 if (strncmp(c, "mitigations=off", strlen(c)))
40 bool get_unpriv_disabled(void)
46 fd = fopen("/proc/sys/" UNPRIV_SYSCTL, "r");
48 disabled = (fgets(buf, 2, fd) == buf && atoi(buf));
51 perror("fopen /proc/sys/" UNPRIV_SYSCTL);
55 return disabled ? true : get_mitigations_off();