mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-08-21 16:31:14 +02:00

The addition of general support for unprivileged tests in test_loader.c breaks building test_verifier on non-glibc (e.g. musl) systems, due to the inclusion of glibc extension '<error.h>' in 'unpriv_helpers.c'. However, the header is actually not needed, so remove it to restore building. Similarly for sk_lookup.c and flow_dissector.c, error.h is not necessary and causes problems, so drop them. Fixes:1d56ade032
("selftests/bpf: Unprivileged tests for test_loader.c") Fixes:0ab5539f85
("selftests/bpf: Tests for BPF_SK_LOOKUP attach point") Fixes:0905beec9f
("selftests/bpf: run flow dissector tests in skb-less mode") Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/5664367edf5fea4f3f4b4aec3b182bcfc6edff9c.1721713597.git.tony.ambardar@gmail.com
57 lines
1.0 KiB
C
57 lines
1.0 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
|
|
#include "unpriv_helpers.h"
|
|
|
|
static bool get_mitigations_off(void)
|
|
{
|
|
char cmdline[4096], *c;
|
|
int fd, ret = false;
|
|
|
|
fd = open("/proc/cmdline", O_RDONLY);
|
|
if (fd < 0) {
|
|
perror("open /proc/cmdline");
|
|
return false;
|
|
}
|
|
|
|
if (read(fd, cmdline, sizeof(cmdline) - 1) < 0) {
|
|
perror("read /proc/cmdline");
|
|
goto out;
|
|
}
|
|
|
|
cmdline[sizeof(cmdline) - 1] = '\0';
|
|
for (c = strtok(cmdline, " \n"); c; c = strtok(NULL, " \n")) {
|
|
if (strncmp(c, "mitigations=off", strlen(c)))
|
|
continue;
|
|
ret = true;
|
|
break;
|
|
}
|
|
out:
|
|
close(fd);
|
|
return ret;
|
|
}
|
|
|
|
bool get_unpriv_disabled(void)
|
|
{
|
|
bool disabled;
|
|
char buf[2];
|
|
FILE *fd;
|
|
|
|
fd = fopen("/proc/sys/" UNPRIV_SYSCTL, "r");
|
|
if (fd) {
|
|
disabled = (fgets(buf, 2, fd) == buf && atoi(buf));
|
|
fclose(fd);
|
|
} else {
|
|
perror("fopen /proc/sys/" UNPRIV_SYSCTL);
|
|
disabled = true;
|
|
}
|
|
|
|
return disabled ? true : get_mitigations_off();
|
|
}
|