From: Leon Hwang <leon.hwang@linux.dev>
To: sashiko@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v4 6/8] bpftool: Generate skeleton for global percpu data
Date: Fri, 17 Apr 2026 10:01:36 +0800 [thread overview]
Message-ID: <bd23783b-9afc-48c9-8bd5-31f4920187e1@linux.dev> (raw)
In-Reply-To: <20260414212650.4F89BC19425@smtp.kernel.org>
On 15/4/26 05:26, sashiko-bot@kernel.org wrote:
> Sashiko AI review found 1 potential issue(s):
> - [High] Missing read-only memory protection for `.percpu` initial value buffer in generated light skeletons.
> --
>
> commit e61b5ee6e5a7cee758b644de0f6b4aaea40f020c
> Author: Leon Hwang <leon.hwang@linux.dev>
>
> bpftool: Generate skeleton for global percpu data
>
> Enhance bpftool to generate skeletons that properly handle global percpu
> variables. The skeleton includes a nested structure for percpu data, which
> is marked as read-only after loading so users must update the map directly.
>
>> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
>> --- a/tools/bpf/bpftool/gen.c
>> +++ b/tools/bpf/bpftool/gen.c
>
> [ ... ]
>
>> @@ -847,7 +851,7 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
>> bpf_object__for_each_map(map, obj) {
>> const char *mmap_flags;
>>
>> - if (!is_mmapable_map(map, ident, sizeof(ident)))
>> + if (!is_mmapable_map(map, ident, sizeof(ident)) || bpf_map_is_percpu_data(map))
>> continue;
>>
>> if (bpf_map__map_flags(map) & BPF_F_RDONLY_PROG)
>
> The commit message notes that after loading the skeleton, maps.percpu->mmaped
> has been marked as read-only.
>
> By skipping the .percpu map entirely here during light skeleton generation
> in gen_trace(), does this leave the user-space buffer for .percpu writable?
>
> If a user modifies skel->percpu after the light skeleton is loaded, will it
> silently succeed without actually updating the kernel per-cpu map? Does the
> generated light skeleton need an explicit mprotect(..., PROT_READ) for the
> .percpu initial value buffer to enforce the read-only constraint?
>
The mprotect(..., PROT_READ) was added in patch #4.
I think it'd better to move the change to this patch. Then, readers
won't miss the mprotect().
Thanks,
Leon
parent reply other threads:[~2026-04-17 2:01 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20260414212650.4F89BC19425@smtp.kernel.org>]
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=bd23783b-9afc-48c9-8bd5-31f4920187e1@linux.dev \
--to=leon.hwang@linux.dev \
--cc=bpf@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
/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