51 lines
1.7 KiB
Diff
51 lines
1.7 KiB
Diff
From 9da0dcb62149ab0a6c5711813d77a844ec6f393b Mon Sep 17 00:00:00 2001
|
|
From: Jon Doron <jond@wiz.io>
|
|
Date: Sun, 25 Sep 2022 10:04:31 +0300
|
|
Subject: [PATCH] libbpf: Fix the case of running as non-root with capabilities
|
|
|
|
When running rootless with special capabilities like:
|
|
FOWNER / DAC_OVERRIDE / DAC_READ_SEARCH
|
|
|
|
The "access" API will not make the proper check if there is really
|
|
access to a file or not.
|
|
|
|
>From the access man page:
|
|
"
|
|
The check is done using the calling process's real UID and GID, rather
|
|
than the effective IDs as is done when actually attempting an operation
|
|
(e.g., open(2)) on the file. Similarly, for the root user, the check
|
|
uses the set of permitted capabilities rather than the set of effective
|
|
capabilities; ***and for non-root users, the check uses an empty set of
|
|
capabilities.***
|
|
"
|
|
|
|
What that means is that for non-root user the access API will not do the
|
|
proper validation if the process really has permission to a file or not.
|
|
|
|
To resolve this this patch replaces all the access API calls with
|
|
faccessat with AT_EACCESS flag.
|
|
|
|
Signed-off-by: Jon Doron <jond@wiz.io>
|
|
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
|
|
Link: https://lore.kernel.org/bpf/20220925070431.1313680-1-arilou@gmail.com
|
|
---
|
|
src/btf.c | 2 +-
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
diff --git a/src/btf.c b/src/btf.c
|
|
index 8066f5f..28c061d 100644
|
|
--- a/src/btf.c
|
|
+++ b/src/btf.c
|
|
@@ -4618,7 +4618,7 @@ struct btf *libbpf_find_kernel_btf(void)
|
|
for (i = 0; i < ARRAY_SIZE(locations); i++) {
|
|
snprintf(path, PATH_MAX, locations[i].path_fmt, buf.release);
|
|
|
|
- if (access(path, R_OK))
|
|
+ if (faccessat(AT_FDCWD, path, R_OK, AT_EACCESS))
|
|
continue;
|
|
|
|
if (locations[i].raw_btf)
|
|
--
|
|
2.33.0
|
|
|