🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Amery Hung Thu, 15 Oct 2026 17:01
Re: [PATCH net 1/1] bpf: reject raw iteration over managed sk_storage values
#3664
Author: Amery Hung
Date: Thu, 15 Oct 2026 17:01
62 lines
11468 bytes
On Wed, Oct 14, 2026 at 5:24 AM Zhiling Zou <zhilinz@nebusec.ai> wrote:
>
> The sk_storage iterator exposes values as raw PTR_TO_BUF memory. Attach
> validation checks only the maximum access against value_size, so BPF
> programs can read or overwrite BTF-managed fields such as __kptr without
> the verifier's ownership checks.
>
> Reject value accesses when the storage map has a BTF record containing
> managed fields. Iterators that do not access values, and maps without
> managed fields, retain their existing behavior.

AI is right. It also appears that iter/bpf_map_elem may expose special
fields as writable PTR_TO_BUF. Could you cover that path as well?

>
> Fixes: 9db44fdd8105 ("bpf: Support kptrs in local storage maps")
> Cc: stable@vger.kernel.org
> Reported-by: Vega <vega@nebusec.ai>
> Assisted-by: LLM
> Signed-off-by: Zhiling Zou <zhilinz@nebusec.ai>
> ---
>  net/core/bpf_sk_storage.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
> index 1d295a8769fa..b54fd90d4bde 100644
> --- a/net/core/bpf_sk_storage.c
> +++ b/net/core/bpf_sk_storage.c
> @@ -863,6 +863,12 @@ static int bpf_iter_attach_map(struct bpf_prog *prog,
>         if (map->map_type != BPF_MAP_TYPE_SK_STORAGE)
>                 goto put_map;
>
> +       /* The iterator exposes values as raw buffers, bypassing field checks. */
> +       if (map->record && prog->aux->max_rdwr_access) {
> +               err = -EACCES;
> +               goto put_map;
> +       }
> +

Could we preserve access to non-special fields of the value? Since
max_rdwr_access is an exclusive upper bound and record->fields[] is
sorted by offset, attachment could be rejected only when:

prog->aux->max_rdwr_access > map->record->fields[0].offset

This remains conservative, while allowing users to place special
fields at the end of the value structure and iterate over the
preceding fields.

Please also add a selftest covering allowed non-special access,
rejected special-field access.

>         if (prog->aux->max_rdwr_access > map->value_size) {
>                 err = -EACCES;
>                 goto put_map;
> --
> 2.55.0
>
Re: [PATCH net 1/1] bpf: reject raw iteration over managed sk_storage values
#4139
Author: Amery Hung
Date: Fri, 16 Oct 2026 20:49
94 lines
12742 bytes
On Thu, Oct 15, 2026 at 10:24 PM zhilin zou <zhilinz@nebusec.ai> wrote:
>
> On Fri, Oct 16, 2026 at 1:01 AM Amery Hung <ameryhung@gmail.com> wrote:
> >
> > On Wed, Oct 14, 2026 at 5:24 AM Zhiling Zou <zhilinz@nebusec.ai> wrote:
> > >
> > > The sk_storage iterator exposes values as raw PTR_TO_BUF memory. Attach
> > > validation checks only the maximum access against value_size, so BPF
> > > programs can read or overwrite BTF-managed fields such as __kptr without
> > > the verifier's ownership checks.
> > >
> > > Reject value accesses when the storage map has a BTF record containing
> > > managed fields. Iterators that do not access values, and maps without
> > > managed fields, retain their existing behavior.
> >
> > AI is right. It also appears that iter/bpf_map_elem may expose special
> > fields as writable PTR_TO_BUF. Could you cover that path as well?
> >
>
> Thanks, Amery. Agreed. I’ll extend the fix to cover iter/bpf_map_elem as well
> and ensure bpf_link_update() validates the replacement program against the
> attached map.
>
> > >
> > > Fixes: 9db44fdd8105 ("bpf: Support kptrs in local storage maps")
> > > Cc: stable@vger.kernel.org
> > > Reported-by: Vega <vega@nebusec.ai>
> > > Assisted-by: LLM
> > > Signed-off-by: Zhiling Zou <zhilinz@nebusec.ai>
> > > ---
> > >  net/core/bpf_sk_storage.c | 6 ++++++
> > >  1 file changed, 6 insertions(+)
> > >
> > > diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
> > > index 1d295a8769fa..b54fd90d4bde 100644
> > > --- a/net/core/bpf_sk_storage.c
> > > +++ b/net/core/bpf_sk_storage.c
> > > @@ -863,6 +863,12 @@ static int bpf_iter_attach_map(struct bpf_prog *prog,
> > >         if (map->map_type != BPF_MAP_TYPE_SK_STORAGE)
> > >                 goto put_map;
> > >
> > > +       /* The iterator exposes values as raw buffers, bypassing field checks. */
> > > +       if (map->record && prog->aux->max_rdwr_access) {
> > > +               err = -EACCES;
> > > +               goto put_map;
> > > +       }
> > > +
> >
> > Could we preserve access to non-special fields of the value? Since
> > max_rdwr_access is an exclusive upper bound and record->fields[] is
> > sorted by offset, attachment could be rejected only when:
> >
> > prog->aux->max_rdwr_access > map->record->fields[0].offset
> >
> > This remains conservative, while allowing users to place special
> > fields at the end of the value structure and iterate over the
> > preceding fields.
> >
> > Please also add a selftest covering allowed non-special access,
> > rejected special-field access.
> >
>
> Agreed. Since max_rdwr_access is an exclusive upper bound and the
> managed fields are ordered by offset, I’ll reject access when it extends
> past the first managed field’s offset. This preserves access to ordinary
> fields before it. I’ll add selftests for both allowed prefix access
> and rejected
> managed-field access.

One more thing I noticed. When you respin, please change the subject
prefix to "bpf" as the patchset should go through bpf tree and the CI
first.

>
> > >         if (prog->aux->max_rdwr_access > map->value_size) {
> > >                 err = -EACCES;
> > >                 goto put_map;
> > > --
> > > 2.55.0
> > >
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads