From: sashiko-bot@kernel.org
To: "Taehee Yoo" <ap420073@gmail.com>
Cc: bpf@vger.kernel.org, dri-devel@lists.freedesktop.org,
media-ci@linuxtv.org
Subject: Re: [RFC PATCH net-next 05/13] bpf: offload: allow PERCPU_ARRAY maps for offloaded programs
Date: Tue, 21 Jul 2026 07:17:56 +0000 [thread overview]
Message-ID: <20260721071756.AEEDA1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260719175857.4071636-6-ap420073@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Permitting BPF_MAP_TYPE_PERCPU_ARRAY on the offload path introduces a kernel heap buffer overflow (OOB write) and an uninitialized memory leak during map lookups, because the offload driver API lacks the `flags` parameter required to determine the `value` buffer size.
- [Medium] User-triggerable WARN_ON in netdevsim driver when attempting to allocate an offloaded PERCPU_ARRAY map.
Pre-existing issues:
- [High] NULL pointer dereference in `prepare_seq_file` for offloaded maps due to incomplete `bpf_map_offload_ops`.
--
--- Patch [5]: [RFC PATCH net-next 05/13] bpf: offload: allow PERCPU_ARRAY maps for offloaded programs ---
commit 48af783b3fca05c679c6224bf05a40782d3679ed
Author: Taehee Yoo <ap420073@gmail.com>
bpf: offload: allow PERCPU_ARRAY maps for offloaded programs
The knod BPF offload keeps hot per-CPU statistics in a PERCPU_ARRAY
map that is mirrored into accelerator memory and aggregated back on the
host. Permit this map type on the offload path.
> diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
> index 0d6f5569588c3..36e747a12cbe7 100644
> --- a/kernel/bpf/offload.c
> +++ b/kernel/bpf/offload.c
> @@ -510,7 +510,8 @@ struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr)
> if (!capable(CAP_SYS_ADMIN))
> return ERR_PTR(-EPERM);
> if (attr->map_type != BPF_MAP_TYPE_ARRAY &&
> - attr->map_type != BPF_MAP_TYPE_HASH)
> + attr->map_type != BPF_MAP_TYPE_HASH &&
> + attr->map_type != BPF_MAP_TYPE_PERCPU_ARRAY)
[Severity: Medium]
Does this change trigger a WARN_ON in the netdevsim driver?
Looking at nsim_bpf_map_alloc() in drivers/net/netdevsim/bpf.c, there is an
explicit check that will panic if panic_on_warn is set:
drivers/net/netdevsim/bpf.c:nsim_bpf_map_alloc() {
if (WARN_ON(offmap->map.map_type != BPF_MAP_TYPE_ARRAY &&
offmap->map.map_type != BPF_MAP_TYPE_HASH))
return -EINVAL;
}
Since BPF_MAP_TYPE_PERCPU_ARRAY is now allowed, could this assertion be hit
when creating an offloaded PERCPU_ARRAY map on a netdevsim device?
[Severity: High]
Can this lead to a buffer overflow or uninitialized memory disclosure during
map lookups?
When user-space calls bpf(BPF_MAP_LOOKUP_ELEM) on a PERCPU_ARRAY,
map_lookup_elem() dynamically allocates the value buffer size based on
whether BPF_F_CPU is passed:
kernel/bpf/syscall.c:map_lookup_elem() {
...
value_size = bpf_map_value_size(map, attr->flags);
err = -ENOMEM;
value = kvmalloc(value_size, GFP_USER | __GFP_NOWARN);
...
}
However, bpf_map_offload_lookup_elem() drops the flags argument entirely
when calling the driver's hook:
kernel/bpf/offload.c:bpf_map_offload_lookup_elem() {
int bpf_map_offload_lookup_elem(struct bpf_map *map, void *key,
void *value)
{
struct bpf_offloaded_map *offmap = map_to_offmap(map);
...
}
If a user specifies BPF_F_CPU, the allocated buffer is small. If the driver
returns full per-CPU data, could it overwrite the buffer? Alternatively, if
no flag is passed but the driver only returns one element, could the rest
of the uninitialized buffer be copied to user-space?
[Severity: High]
This isn't a bug introduced by this patch, but does allowing PERCPU_ARRAY
(as well as existing ARRAY and HASH maps) expose a NULL pointer dereference
in the BPF iterator code?
When calling open() on a BPF iterator file descriptor for an offloaded map,
prepare_seq_file() executes:
kernel/bpf/bpf_iter.c:prepare_seq_file() {
const struct bpf_iter_seq_info *seq_info = __get_seq_info(link);
...
total_priv_dsize = offsetof(struct bpf_iter_priv_data, target_private) +
seq_info->seq_priv_size;
...
}
Because bpf_map_offload_ops does not implement .iter_seq_info,
__get_seq_info() returns NULL:
kernel/bpf/bpf_iter.c:__get_seq_info() {
if (link->aux.map) {
seq_info = link->aux.map->ops->iter_seq_info;
if (seq_info)
return seq_info;
}
return link->tinfo->reg_info->seq_info;
}
Will this result in a direct NULL pointer dereference when accessing
seq_info->seq_priv_size since both sources of seq_info are NULL for
offloaded maps?
> return ERR_PTR(-EINVAL);
>
> offmap = bpf_map_area_alloc(sizeof(*offmap), NUMA_NO_NODE);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260719175857.4071636-1-ap420073@gmail.com?part=5
next prev parent reply other threads:[~2026-07-21 7:18 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-19 17:58 [RFC PATCH net-next 00/13] net: knod: in-kernel network offload device Taehee Yoo
2026-07-19 17:58 ` [RFC PATCH net-next 01/13] net: knod: add uapi and core headers Taehee Yoo
2026-07-21 7:17 ` sashiko-bot
2026-07-19 17:58 ` [RFC PATCH net-next 02/13] net: devmem: extend memory provider for knod Taehee Yoo
2026-07-20 19:43 ` Mina Almasry
2026-07-21 16:15 ` Taehee Yoo
2026-07-21 7:17 ` sashiko-bot
2026-07-19 17:58 ` [RFC PATCH net-next 03/13] net: core: add XDP_MODE_HW offload hook " Taehee Yoo
2026-07-21 7:17 ` sashiko-bot
2026-07-19 17:58 ` [RFC PATCH net-next 04/13] net: knod: add offload device core and control plane Taehee Yoo
2026-07-21 7:17 ` sashiko-bot
2026-07-19 17:58 ` [RFC PATCH net-next 05/13] bpf: offload: allow PERCPU_ARRAY maps for offloaded programs Taehee Yoo
2026-07-21 7:17 ` sashiko-bot [this message]
2026-07-19 17:58 ` [RFC PATCH net-next 06/13] drm/amdkfd: prepare kfd core for the knod provider Taehee Yoo
2026-07-21 7:17 ` sashiko-bot
2026-07-19 17:58 ` [RFC PATCH net-next 07/13] drm/amdkfd: add knod provider core Taehee Yoo
2026-07-21 7:17 ` sashiko-bot
2026-07-19 17:58 ` [RFC PATCH net-next 08/13] drm/amdkfd: add GPU instruction emitter and disassembler Taehee Yoo
2026-07-20 20:05 ` Natalie Vock
2026-07-20 20:53 ` Andrew Lunn
2026-07-21 16:36 ` Hoyeon Lee
2026-07-19 17:58 ` [RFC PATCH net-next 09/13] drm/amdkfd: add BPF-to-GPU JIT offload Taehee Yoo
2026-07-19 17:58 ` [RFC PATCH net-next 10/13] net/mlx5e: add knod XDP offload support Taehee Yoo
2026-07-21 7:17 ` sashiko-bot
2026-07-19 17:58 ` [RFC PATCH net-next 11/13] bnxt_en: " Taehee Yoo
2026-07-21 7:18 ` sashiko-bot
2026-07-19 17:58 ` [RFC PATCH net-next 12/13] selftests: drivers/net: add knod tests Taehee Yoo
2026-07-21 7:18 ` sashiko-bot
2026-07-19 17:58 ` [RFC PATCH net-next 13/13] drm/amdkfd: add IPsec full-packet offload Taehee Yoo
2026-07-21 7:18 ` sashiko-bot
2026-07-20 19:18 ` [RFC PATCH net-next 00/13] net: knod: in-kernel network offload device Mina Almasry
2026-07-21 15:17 ` Taehee Yoo
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=20260721071756.AEEDA1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ap420073@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=media-ci@linuxtv.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.