From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Daniel Xu <dxu@dxuuu.xyz>
Cc: bpf <bpf@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Song Liu <songliubraving@fb.com>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf v5 0/2] Fix bpf_probe_read_user_str() overcopying
Date: Wed, 11 Nov 2020 15:22:21 -0800 [thread overview]
Message-ID: <CAEf4BzZx=7N6dbKk8Eb_k-FA-PmmPFBJ=V-PLhbDu38wuXkOkw@mail.gmail.com> (raw)
In-Reply-To: <cover.1605134506.git.dxu@dxuuu.xyz>
On Wed, Nov 11, 2020 at 2:46 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
>
> 6ae08ae3dea2 ("bpf: Add probe_read_{user, kernel} and probe_read_{user,
> kernel}_str helpers") introduced a subtle bug where
> bpf_probe_read_user_str() would potentially copy a few extra bytes after
> the NUL terminator.
>
> This issue is particularly nefarious when strings are used as map keys,
> as seemingly identical strings can occupy multiple entries in a map.
>
> This patchset fixes the issue and introduces a selftest to prevent
> future regressions.
>
> v4 -> v5:
> * don't read potentially uninitialized memory
I think the bigger problem was that it could overwrite unintended
memory. E.g., in BPF program, if you had something like:
char my_buf[8 + 3];
char my_precious_data[5] = {1, 2, 3, 4, 5};
With previous version you'd overwrite my_precious data. BTW, do you
test such scenario in the selftests you added? If not, we should have
something like this as well and validate 1, 2, 3, 4, 5 stay intact.
>
> v3 -> v4:
> * directly pass userspace pointer to prog
> * test more strings of different length
>
> v2 -> v3:
> * set pid filter before attaching prog in selftest
> * use long instead of int as bpf_probe_read_user_str() retval
> * style changes
>
> v1 -> v2:
> * add Fixes: tag
> * add selftest
>
> Daniel Xu (2):
> lib/strncpy_from_user.c: Don't overcopy bytes after NUL terminator
> selftest/bpf: Test bpf_probe_read_user_str() strips trailing bytes
> after NUL
>
> lib/strncpy_from_user.c | 9 ++-
> .../bpf/prog_tests/probe_read_user_str.c | 71 +++++++++++++++++++
> .../bpf/progs/test_probe_read_user_str.c | 25 +++++++
> 3 files changed, 100 insertions(+), 5 deletions(-)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/probe_read_user_str.c
> create mode 100644 tools/testing/selftests/bpf/progs/test_probe_read_user_str.c
>
> --
> 2.29.2
>
next prev parent reply other threads:[~2020-11-12 1:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-11 22:45 [PATCH bpf v5 0/2] Fix bpf_probe_read_user_str() overcopying Daniel Xu
2020-11-11 22:45 ` [PATCH bpf v5 1/2] lib/strncpy_from_user.c: Don't overcopy bytes after NUL terminator Daniel Xu
2020-11-11 23:20 ` Andrii Nakryiko
2020-11-13 17:03 ` Alexei Starovoitov
2020-11-13 18:08 ` Linus Torvalds
2020-11-13 19:17 ` Alexei Starovoitov
2020-11-13 19:29 ` Linus Torvalds
2020-11-13 19:46 ` Linus Torvalds
2020-11-13 20:10 ` Linus Torvalds
2020-11-13 20:57 ` Alexei Starovoitov
2020-11-13 21:14 ` Linus Torvalds
2020-11-11 22:45 ` [PATCH bpf v5 2/2] selftest/bpf: Test bpf_probe_read_user_str() strips trailing bytes after NUL Daniel Xu
2020-11-11 23:22 ` Andrii Nakryiko [this message]
2020-11-12 19:10 ` [PATCH bpf v5 0/2] Fix bpf_probe_read_user_str() overcopying Daniel Xu
2020-11-12 19:24 ` Andrii Nakryiko
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='CAEf4BzZx=7N6dbKk8Eb_k-FA-PmmPFBJ=V-PLhbDu38wuXkOkw@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dxu@dxuuu.xyz \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=songliubraving@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;
as well as URLs for NNTP newsgroup(s).