netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org, ast@kernel.org, joe@wand.net.nz,
	yhs@fb.com, andrii.nakryiko@gmail.com, kafai@fb.com,
	Daniel Borkmann <daniel@iogearbox.net>
Subject: [PATCH bpf-next v4 02/16] bpf: do not retain flags that are not tied to map lifetime
Date: Fri,  5 Apr 2019 22:59:28 +0200	[thread overview]
Message-ID: <ac551e3cac2f48fb78c11233802e29d116252e86.1554497408.git.daniel@iogearbox.net> (raw)
In-Reply-To: <cover.1554497408.git.daniel@iogearbox.net>
In-Reply-To: <cover.1554497408.git.daniel@iogearbox.net>

Both BPF_F_WRONLY / BPF_F_RDONLY flags are tied to the map file
descriptor, but not to the map object itself! Meaning, at map
creation time BPF_F_RDONLY can be set to make the map read-only
from syscall side, but this holds only for the returned fd, so
any other fd either retrieved via bpf file system or via map id
for the very same underlying map object can have read-write access
instead.

Given that, keeping the two flags around in the map_flags attribute
and exposing them to user space upon map dump is misleading and
may lead to false conclusions. Since these two flags are not
tied to the map object lets also not store them as map property.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
 kernel/bpf/syscall.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index b4d0aff..ddce0e2 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -166,13 +166,25 @@ void bpf_map_area_free(void *area)
 	kvfree(area);
 }
 
+static u32 bpf_map_flags_retain_permanent(u32 flags)
+{
+	/* Some map creation flags are not tied to the map object but
+	 * rather to the map fd instead, so they have no meaning upon
+	 * map object inspection since multiple file descriptors with
+	 * different (access) properties can exist here. Thus, given
+	 * this has zero meaning for the map itself, lets clear these
+	 * from here.
+	 */
+	return flags & ~(BPF_F_RDONLY | BPF_F_WRONLY);
+}
+
 void bpf_map_init_from_attr(struct bpf_map *map, union bpf_attr *attr)
 {
 	map->map_type = attr->map_type;
 	map->key_size = attr->key_size;
 	map->value_size = attr->value_size;
 	map->max_entries = attr->max_entries;
-	map->map_flags = attr->map_flags;
+	map->map_flags = bpf_map_flags_retain_permanent(attr->map_flags);
 	map->numa_node = bpf_map_attr_numa_node(attr);
 }
 
-- 
2.9.5


  parent reply	other threads:[~2019-04-05 21:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-05 20:59 [PATCH bpf-next v4 00/16] BPF support for global data Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 01/16] bpf: implement lookup-free direct value access for maps Daniel Borkmann
2019-04-06  1:56   ` Alexei Starovoitov
2019-04-06 10:58     ` Daniel Borkmann
2019-04-06 16:54       ` Alexei Starovoitov
2019-04-06 23:55         ` Daniel Borkmann
2019-04-07  2:57           ` Alexei Starovoitov
2019-04-07 18:35             ` Daniel Borkmann
2019-04-05 20:59 ` Daniel Borkmann [this message]
2019-04-05 20:59 ` [PATCH bpf-next v4 03/16] bpf: add program side {rd,wr}only support " Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 04/16] bpf: add syscall side map freeze support Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 05/16] bpf: allow . char as part of the object name Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 06/16] bpf: add specification for BTF Var and DataSec kinds Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 07/16] bpf: kernel side support for BTF Var and DataSec Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 08/16] bpf: allow for key-less BTF in array map Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 09/16] bpf: sync {btf,bpf}.h uapi header from tools infrastructure Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 10/16] bpf, libbpf: refactor relocation handling Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 11/16] bpf, libbpf: support global data/bss/rodata sections Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 12/16] bpf, libbpf: add support for BTF Var and DataSec Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 13/16] bpf: bpftool support for dumping data/bss/rodata sections Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 14/16] bpf, selftest: test {rd,wr}only flags and direct value access Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 15/16] bpf, selftest: test global data/bss/rodata sections Daniel Borkmann
2019-04-05 20:59 ` [PATCH bpf-next v4 16/16] bpf, selftest: add test cases for BTF Var and DataSec Daniel Borkmann
2019-04-06  5:57 ` [PATCH bpf-next v4 00/16] BPF support for global data Martin Lau

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=ac551e3cac2f48fb78c11233802e29d116252e86.1554497408.git.daniel@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=joe@wand.net.nz \
    --cc=kafai@fb.com \
    --cc=netdev@vger.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).