netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Paul Chaignon <paul.chaignon@orange.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Cc: Xiao Han <xiao.han@orange.com>, Martin Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>
Subject: Re: [PATCH bpf v3 0/2] bpf: mark registers in all frames after pkt/null checks
Date: Thu, 25 Apr 2019 15:27:00 +0000	[thread overview]
Message-ID: <233bca7b-6412-bb07-8185-71a6f86ec003@fb.com> (raw)
In-Reply-To: <cover.1556127905.git.paul.chaignon@orange.com>



On 4/24/19 12:49 PM, Paul Chaignon wrote:
> In case of a null check on a pointer inside a subprog, we should mark all
> registers with this pointer as either safe or unknown, in both the current
> and previous frames.  Currently, only spilled registers and registers in
> the current frame are marked.  Packet bound checks in subprogs have the
> same issue.  The first patch fixes it to mark registers in previous frames
> as well.
> 
> A good reproducer for null checks looks as follow:
> 
> 1: ptr = bpf_map_lookup_elem(map, &key);
> 2: ret = subprog(ptr) {
> 3:   return ptr != NULL;
> 4: }
> 5: if (ret)
> 6:   value = *ptr;
> 
> With the above, the verifier will complain on line 6 because it sees ptr
> as map_value_or_null despite the null check in subprog 1.  The second
> patch implements the above as a new test case.
> 
> Note that this patch fixes another resulting bug when using
> bpf_sk_release():
> 
> 1: sk = bpf_sk_lookup_tcp(...);
> 2: subprog(sk) {
> 3:   if (sk)
> 4:     bpf_sk_release(sk);
> 5: }
> 6: if (!sk)
> 7:   return 0;
> 8: return 1;
> 
> In the above, mark_ptr_or_null_regs will warn on line 6 because it will
> try to free the reference state, even though it was already freed on
> line 3.
> 
> Changelogs:
>    Changes in v3:
>      - Fix same issue in find_good_pkt_pointers().
>      - Add test case for find_good_pkt_pointers() issue.
>      - Change title to account for the above change. Old title was
>        "bpf: mark registers as safe or unknown in all frames".
>      - Refactor find_good_pkt_pointers and mark_ptr_or_null_regs.
>      - I did not keep Yonghong's ack because of the above changes.
>    Changes in v2:
>      - Fix example codes in commit message.
> 
> Paul Chaignon (2):
>    bpf: mark registers in all frames after pkt/null checks
>    selftests/bpf: test cases for pkt/null checks in subprogs
> 
>   kernel/bpf/verifier.c                         | 76 +++++++++++--------
>   tools/testing/selftests/bpf/verifier/calls.c  | 25 ++++++
>   .../bpf/verifier/direct_packet_access.c       | 22 ++++++
>   3 files changed, 93 insertions(+), 30 deletions(-)

Ack for the whole series.
Acked-by: Yonghong Song <yhs@fb.com>

  parent reply	other threads:[~2019-04-25 15:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 19:49 [PATCH bpf v3 0/2] bpf: mark registers in all frames after pkt/null checks Paul Chaignon
2019-04-24 19:50 ` [PATCH bpf v3 1/2] " Paul Chaignon
2019-04-24 19:51 ` [PATCH bpf v3 2/2] selftests/bpf: test cases for pkt/null checks in subprogs Paul Chaignon
2019-04-25 15:27 ` Yonghong Song [this message]
2019-04-25 20:46 ` [PATCH bpf v3 0/2] bpf: mark registers in all frames after pkt/null checks Alexei Starovoitov
2019-04-25 21:04   ` Daniel Borkmann

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=233bca7b-6412-bb07-8185-71a6f86ec003@fb.com \
    --to=yhs@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=paul.chaignon@orange.com \
    --cc=songliubraving@fb.com \
    --cc=xiao.han@orange.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).