lkml.org 
[lkml]   [2022]   [Sep]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [syzbot] WARNING in u32_change
Do you want to submit that patch then?
FWIW, I could not recreate what syzbot saw even after setting
CONFIG_FORTIFY_SOURCE=y

cheers,
jamal

On Sun, Sep 25, 2022 at 10:39 PM Kees Cook <keescook@chromium.org> wrote:
>
> On Sun, Sep 25, 2022 at 10:34:37AM -0700, Eric Dumazet wrote:
> > Sure, please look at:
> >
> > commit 54d9469bc515dc5fcbc20eecbe19cea868b70d68
> > Author: Kees Cook <keescook@chromium.org>
> > Date: Thu Jun 24 15:39:26 2021 -0700
> >
> > fortify: Add run-time WARN for cross-field memcpy()
> > [...]
> > Here, we might switch to unsafe_memcpy() instead of memcpy()
>
> I would tend to agree. Something like:
>
> diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
> index 4d27300c287c..21e0e6206ecc 100644
> --- a/net/sched/cls_u32.c
> +++ b/net/sched/cls_u32.c
> @@ -1040,7 +1040,9 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
> }
> #endif
>
> - memcpy(&n->sel, s, sel_size);
> + unsafe_memcpy(&n->sel, s, sel_size,
> + /* A composite flex-array structure destination,
> + * which was correctly sized and allocated above. */);
> RCU_INIT_POINTER(n->ht_up, ht);
> n->handle = handle;
> n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0;
>
> This alloc/partial-copy pattern is relatively common in the kernel, so
> I've been considering adding a helper for it. It'd be like kmemdup(),
> but more like kmemdup_offset(), which only the object from a certainly
> point is copied.
>
> --
> Kees Cook

\
 
 \ /
  Last update: 2022-09-27 13:26    [W:0.084 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site