lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 12 Nov 2022 02:15:47 +0530
From:   Kumar Kartikeya Dwivedi <memxor@...il.com>
To:     sdf@...gle.com
Cc:     Xu Kuohai <xukuohai@...weicloud.com>, bpf@...r.kernel.org,
        linux-kernel@...r.kernel.org, Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Martin KaFai Lau <martin.lau@...ux.dev>,
        Song Liu <song@...nel.org>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>, Hao Luo <haoluo@...gle.com>,
        Jiri Olsa <jolsa@...nel.org>
Subject: Re: [PATCH bpf] bpf: Fix offset calculation error in
 __copy_map_value and zero_map_value

On Sat, Nov 12, 2022 at 12:47:52AM IST, sdf@...gle.com wrote:
> On 11/11, Xu Kuohai wrote:
> > From: Xu Kuohai <xukuohai@...wei.com>
>
> > Function __copy_map_value and zero_map_value miscalculated copy offset,
> > resulting in possible copy of unwanted data to user or kernel.
>
> > Fix it.
>
> > Fixes: cc48755808c6 ("bpf: Add zero_map_value to zero map value with
> > special fields")
> > Fixes: 4d7d7f69f4b1 ("bpf: Adapt copy_map_value for multiple offset case")
> > Signed-off-by: Xu Kuohai <xukuohai@...wei.com>
> > ---
> >   include/linux/bpf.h | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
>
> > diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> > index 74c6f449d81e..c1bd1bd10506 100644
> > --- a/include/linux/bpf.h
> > +++ b/include/linux/bpf.h
> > @@ -315,7 +315,7 @@ static inline void __copy_map_value(struct bpf_map
> > *map, void *dst, void *src, b
> >   		u32 next_off = map->off_arr->field_off[i];
>
> >   		memcpy(dst + curr_off, src + curr_off, next_off - curr_off);
> > -		curr_off += map->off_arr->field_sz[i];
> > +		curr_off = next_off + map->off_arr->field_sz[i];
> >   	}
> >   	memcpy(dst + curr_off, src + curr_off, map->value_size - curr_off);
> >   }
> > @@ -344,7 +344,7 @@ static inline void zero_map_value(struct bpf_map
> > *map, void *dst)
> >   		u32 next_off = map->off_arr->field_off[i];
>
> >   		memset(dst + curr_off, 0, next_off - curr_off);
> > -		curr_off += map->off_arr->field_sz[i];
> > +		curr_off = next_off + map->off_arr->field_sz[i];
> >   	}
> >   	memset(dst + curr_off, 0, map->value_size - curr_off);
> >   }
>
> Hmm, does it mean that it currently works only for the cases where
> these special fields are first/last?
>
> Also, what about bpf-next? The same problem seem to exist there?
>

Replied with the patch in the other email.

> Might be a good idea to have some selftest to exercise this?
>

I agree, there was another bug in the same code before this, so I think we
should add tests for this (I should have done that with the commit being
fixed...).

Xu, if you have cycles, can you work on testing a few edge cases and make sure
we don't regress in the future? Otherwise I will take a look next week.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ