public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] bpf: Retry access to a map in read-only mode
@ 2022-05-30  8:45 Roberto Sassu
  2022-05-30  8:45 ` [PATCH 1/2] libbpf: Retry map access with read-only permission Roberto Sassu
  2022-05-30  8:45 ` [PATCH 2/2] selftests/bpf: Add test for retrying access to map with read-only perm Roberto Sassu
  0 siblings, 2 replies; 5+ messages in thread
From: Roberto Sassu @ 2022-05-30  8:45 UTC (permalink / raw)
  To: ast, daniel, andrii, kpsingh
  Cc: bpf, netdev, linux-kselftest, linux-kernel, Roberto Sassu

If a map is write-protected, for example by an eBPF program implementing
the bpf_map security hook, some read-like operations like show and dump
cannot be performed by bpftool even if bpftool has the right to do so.

The reason is that bpftool sets the open flags to zero, at the time it gets
a map file descriptor. The kernel interprets this as a request for full
access to the map (with read and write permissions).

The simple solution is to set only the necessary open flags for a requested
operation, so that only those operations requiring more privileges than the
ones granted by the enforcing eBPF programs are denied.

There are different ways to solve the problem. One would be to introduce a
new function to acquire a read-only file descriptor and use it from the
functions implementing read-like operations.

Or more simply, another is to attempt to get a read-only file descriptor in
the original function when the first request with full permissions failed.

This patch set implements the second solution in patch 1, and adds a
corresponding test in patch 2. Depending on the feedback, the first
solution can be implemented.

Roberto Sassu (2):
  libbpf: Retry map access with read-only permission
  selftests/bpf: Add test for retrying access to map with read-only perm

 tools/lib/bpf/bpf.c                           |  5 ++
 .../bpf/prog_tests/test_map_retry_access.c    | 54 +++++++++++++++++++
 .../selftests/bpf/progs/map_retry_access.c    | 36 +++++++++++++
 3 files changed, 95 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/test_map_retry_access.c
 create mode 100644 tools/testing/selftests/bpf/progs/map_retry_access.c

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-31  8:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-30  8:45 [PATCH 0/2] bpf: Retry access to a map in read-only mode Roberto Sassu
2022-05-30  8:45 ` [PATCH 1/2] libbpf: Retry map access with read-only permission Roberto Sassu
2022-05-30 21:55   ` Daniel Borkmann
2022-05-31  8:47     ` Roberto Sassu
2022-05-30  8:45 ` [PATCH 2/2] selftests/bpf: Add test for retrying access to map with read-only perm Roberto Sassu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox