BPF List
 help / color / mirror / Atom feed
From: Leon Hwang <leon.hwang@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v5 5/9] bpftool: Generate skeleton for global percpu data
Date: Thu, 11 Jun 2026 13:09:10 +0800	[thread overview]
Message-ID: <76112c8e-e9c2-463d-80a3-171fae5a98c3@linux.dev> (raw)
In-Reply-To: <20260608151109.D0A701F00893@smtp.kernel.org>

On 8/6/26 23:11, sashiko-bot@kernel.org wrote:
[...]
>> @@ -263,13 +268,12 @@ static bool is_mmapable_map(const struct bpf_map *map, char *buf, size_t sz)
>>  		return true;
>>  	}
>>  
>> -	if (!bpf_map__is_internal(map) || !(bpf_map__map_flags(map) & BPF_F_MMAPABLE))
>> -		return false;
>> -
>> -	if (!get_map_ident(map, buf, sz))
>> -		return false;
>> +	if (bpf_map__is_internal(map) &&
>> +	    ((bpf_map__map_flags(map) & BPF_F_MMAPABLE) || bpf_map_is_percpu_data(map)) &&
>> +	    get_map_ident(map, buf, sz))
>> +		return true;
>>  
>> -	return true;
>> +	return false;
>>  }
> 
> [Severity: High]
> Does forcibly treating the percpu maps as mmapable here break subskeletons?
> 
> Since subskeletons operate on an already-loaded BPF object to read or write
> live state, this change might cause do_subskeleton() to export pointers to
> disconnected user-space memory.
> 
> If they point to the disconnected PROT_READ initialization buffer instead of
> live state, would reads always return stale initial data and fail to reflect
> live kernel modifications?
> 

Do subskeletons operate on an already-loaded BPF object to read or write
live state?

If true, will skip percpu data variables for subskeleton.

> [ ... ]
> 
>> @@ -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)
> 
> [Severity: High]
> Does skipping map finalization for percpu maps in light skeletons leave the
> user-space initialization buffer mapped as PROT_READ | PROT_WRITE?
> 
> In standard skeletons managed by libbpf, the buffer is protected with
> PROT_READ to explicitly crash on invalid writes.
> 
> If we skip finalization here in gen_trace(), it seems writes to lskel->percpu
> after load() might silently succeed without actually updating the kernel map.
> 

The buffer should be protected with PROT_READ in light skeletons. Will
do it.

Thanks,
Leon


  reply	other threads:[~2026-06-11  5:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08 14:51 [PATCH bpf-next v5 0/9] bpf: Introduce global percpu data Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 1/9] bpf: Drop duplicate blank lines in verifier Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 2/9] bpf: Introduce global percpu data Leon Hwang
2026-06-08 15:13   ` sashiko-bot
2026-06-11  5:04     ` Leon Hwang
2026-06-08 15:56   ` bot+bpf-ci
2026-06-11  5:05     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 3/9] libbpf: Probe percpu data feature Leon Hwang
2026-06-08 15:05   ` sashiko-bot
2026-06-11  5:08     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 4/9] libbpf: Add support for global percpu data Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 5/9] bpftool: Generate skeleton " Leon Hwang
2026-06-08 15:11   ` sashiko-bot
2026-06-11  5:09     ` Leon Hwang [this message]
2026-06-08 15:29   ` bot+bpf-ci
2026-06-11  5:09     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 6/9] selftests/bpf: Add tests to verify " Leon Hwang
2026-06-08 15:20   ` sashiko-bot
2026-06-11  5:10     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 7/9] selftests/bpf: Add tests to verify verifier log for " Leon Hwang
2026-06-08 15:22   ` sashiko-bot
2026-06-11  5:11     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 8/9] selftests/bpf: Add test to verify xlated insns " Leon Hwang
2026-06-08 15:21   ` sashiko-bot
2026-06-11  5:12     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 9/9] selftests/bpf: Add test to verify bpf_iter " Leon Hwang

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=76112c8e-e9c2-463d-80a3-171fae5a98c3@linux.dev \
    --to=leon.hwang@linux.dev \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@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