bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@huaweicloud.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
	haoluo@google.com, jolsa@kernel.org, mykolal@fb.com,
	shuah@kernel.org, oss@lmb.io
Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, fengc@google.com,
	davem@davemloft.net
Subject: [RFC][PATCH 0/3] bpf: Enforce map fd modes in verifier
Date: Mon, 26 Sep 2022 17:44:27 +0200	[thread overview]
Message-ID: <20220926154430.1552800-1-roberto.sassu@huaweicloud.com> (raw)

From: Roberto Sassu <roberto.sassu@huawei.com>

===
All credits of this patch set go to Lorenz Bauer <oss@lmb.io>, as he
identified this issue and proposed a number of solutions.
===

Lorenz presented at the Linux Plumbers EU 2022 a talk with title 'Closing
the BPF map permission loophole', where he reported that read-only fds can
be used for map update operations, if they were provided to eBPF programs.

This work initially started as PoC to reproduce the reported bug, and
became the test for validating an idea on how to fix the bug.

Patch 1 adds a dependency necessary for the tests.

The actual fix, in patch 2, is relatively simple. It is based on an already
existing enforcement mechanism in the eBPF verifier for map flags. As
Lorenz mentioned, a problem would be backporting this fix to stable kernels
which don't have that enforcement mechanism. However, backporting just the
enforcement mechanism itself (without introducing the new map flags and
allowing user space to use them) could meet the stable kernel criteria.

Alternatively, a completely different fix can be developed for older stable
kernels, like what Lorenz suggested, to refuse fds which are not
read/write.

Finally, patch 3 introduces the tests.

Roberto Sassu (3):
  libbpf: Define bpf_get_fd_opts and introduce
    bpf_map_get_fd_by_id_opts()
  bpf: Enforce granted permissions in a map fd at verifier level
  selftests/bpf: Test enforcement of map fd permissions at verifier
    level

 include/linux/bpf.h                           |  13 +
 include/linux/bpf_verifier.h                  |   1 +
 kernel/bpf/verifier.c                         |  26 +-
 tools/lib/bpf/bpf.c                           |  12 +-
 tools/lib/bpf/bpf.h                           |  10 +
 tools/lib/bpf/libbpf.map                      |   3 +-
 .../selftests/bpf/prog_tests/map_fd_perm.c    | 227 ++++++++++++++++++
 7 files changed, 288 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/map_fd_perm.c

-- 
2.25.1


             reply	other threads:[~2022-09-26 16:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 15:44 Roberto Sassu [this message]
2022-09-26 15:44 ` [RFC][PATCH 1/3] libbpf: Define bpf_get_fd_opts and introduce bpf_map_get_fd_by_id_opts() Roberto Sassu
2022-09-30 20:50   ` Andrii Nakryiko
2022-09-26 15:44 ` [RFC][PATCH 2/3] bpf: Enforce granted permissions in a map fd at verifier level Roberto Sassu
2022-09-26 15:44 ` [RFC][PATCH 3/3] selftests/bpf: Test enforcement of map fd permissions " Roberto Sassu

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=20220926154430.1552800-1-roberto.sassu@huaweicloud.com \
    --to=roberto.sassu@huaweicloud.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=fengc@google.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=oss@lmb.io \
    --cc=sdf@google.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).