From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: sdf@google.com
Cc: Xu Kuohai <xukuohai@huaweicloud.com>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH bpf] bpf: Fix offset calculation error in __copy_map_value and zero_map_value
Date: Sat, 12 Nov 2022 02:15:47 +0530 [thread overview]
Message-ID: <20221111204547.lyeim477afgfgkhh@apollo> (raw)
In-Reply-To: <Y26f4H7buQXKqQFd@google.com>
On Sat, Nov 12, 2022 at 12:47:52AM IST, sdf@google.com wrote:
> On 11/11, Xu Kuohai wrote:
> > From: Xu Kuohai <xukuohai@huawei.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@huawei.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.
next prev parent reply other threads:[~2022-11-11 20:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-11 12:56 [PATCH bpf] bpf: Fix offset calculation error in __copy_map_value and zero_map_value Xu Kuohai
2022-11-11 19:17 ` sdf
2022-11-11 20:45 ` Kumar Kartikeya Dwivedi [this message]
2022-11-12 10:25 ` Xu Kuohai
2022-11-11 19:35 ` Kumar Kartikeya Dwivedi
2022-11-11 20:50 ` patchwork-bot+netdevbpf
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=20221111204547.lyeim477afgfgkhh@apollo \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=xukuohai@huaweicloud.com \
--cc=yhs@fb.com \
/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