From: Jon Doron <arilou@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org
Cc: Jon Doron <jond@wiz.io>
Subject: [PATCH bpf v1] Fix the case of running rootless with capabilities
Date: Tue, 20 Sep 2022 08:20:45 +0300 [thread overview]
Message-ID: <20220920052045.3248976-1-arilou@gmail.com> (raw)
From: Jon Doron <jond@wiz.io>
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.
Signed-off-by: Jon Doron <jond@wiz.io>
---
tools/lib/bpf/libbpf.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 50d41815f431..df804fd65493 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -875,8 +875,9 @@ __u32 get_kernel_version(void)
const char *ubuntu_kver_file = "/proc/version_signature";
__u32 major, minor, patch;
struct utsname info;
+ struct stat sb;
- if (access(ubuntu_kver_file, R_OK) == 0) {
+ if (stat(ubuntu_kver_file, &sb) == 0) {
FILE *f;
f = fopen(ubuntu_kver_file, "r");
@@ -9877,9 +9878,10 @@ static int append_to_file(const char *file, const char *fmt, ...)
static bool use_debugfs(void)
{
static int has_debugfs = -1;
+ struct stat sb;
if (has_debugfs < 0)
- has_debugfs = access(DEBUGFS, F_OK) == 0;
+ has_debugfs = stat(DEBUGFS, &sb) == 0;
return has_debugfs == 1;
}
--
2.37.3
next reply other threads:[~2022-09-20 5:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-20 5:20 Jon Doron [this message]
2022-09-21 0:15 ` [PATCH bpf v1] Fix the case of running rootless with capabilities Andrii Nakryiko
2022-09-21 0:17 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220920052045.3248976-1-arilou@gmail.com \
--to=arilou@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jond@wiz.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox