bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mariusz.dudek@gmail.com
To: magnus.karlsson@intel.com, bjorn.topel@intel.com, ast@kernel.org,
	daniel@iogearbox.net, netdev@vger.kernel.org,
	jonathan.lemon@gmail.com
Cc: bpf@vger.kernel.org, Mariusz Dudek <mariuszx.dudek@intel.com>
Subject: [PATCH bpf-next 0/2] libbpf: add support for privileged/unprivileged control separation
Date: Wed,  4 Nov 2020 10:46:24 +0100	[thread overview]
Message-ID: <20201104094626.3406-1-mariuszx.dudek@intel.com> (raw)

From: Mariusz Dudek <mariuszx.dudek@intel.com>

	This patch series adds support for separation of eBPF program
	load and xsk socket creation. In for example a Kubernetes
	environment you can have an AF_XDP CNI or daemonset that is 
	responsible for launching pods that execute an application 
	using AF_XDP sockets. It is desirable that the pod runs with
	as low privileges as possible, CAP_NET_RAW in this case, 
	and that all operations that require privileges are contained
	in the CNI or daemonset.
	
	In this case, you have to be able separate ePBF program load from
	xsk socket creation.

	Currently, this will not work with the xsk_socket__create APIs
	because you need to have CAP_NET_ADMIN privileges to load eBPF
	program and CAP_SYS_ADMIN privileges to create update xsk_bpf_maps.
	To be exact xsk_set_bpf_maps does not need those privileges but
	it takes the prog_fd and xsks_map_fd and those are known only to
	process that was loading eBPF program. The api bpf_prog_get_fd_by_id
	that looks up the fd of the prog using an prog_id and
	bpf_map_get_fd_by_id that looks for xsks_map_fd usinb map_id both
	requires CAP_SYS_ADMIN.

	With this patch, the pod can be run with CAP_NET_RAW capability
	only. In case your umem is larger or equal process limit for
	MEMLOCK you need either increase the limit or CAP_IPC_LOCK capability. 
	Without this patch in case of insufficient rights ENOPERM is
	returned by xsk_socket__create.

	To resolve this privileges issue two new APIs are introduced:
	- xsk_setup_xdp_prog - prepares bpf program if given and
	loads it on a selected network interface or loads the built in
	XDP program, if no XDP program is supplied. It can also return
	xsks_map_fd which is needed by unprivileged process to update
	xsks_map with AF_XDP socket "fd"
	- xsk_update_xskmap - inserts an AF_XDP socket into an xskmap for a
	particular xsk_socket

	Usage example:
	int xsk_setup_xdp_prog(int ifindex, struct bpf_prog_cfg *cfg,
			int *xsks_map_fd)

	if cfg == NULL, then the default program is loaded.

	Instead of NULL user can pass pointer to struct
	bpf_prog_cfg and provide own bpf program. 

	int xsk_update_xskmap(struct xsk_socket *xsk, int xsks_map_fd);

	Inserts AF_XDP socket "fd" into the xskmap.

	The first patch introduces the new APIs. The second patch provides
	a new sample applications working as control and modification to
	existing xdpsock application to work with less privileges.

	This patch set is based on bpf-next commit cb5dc5b062a9
	("Merge branch 'bpf: safeguard hashtab locking in NMI context')

Mariusz Dudek (2):
  libbpf: separate XDP program load with xsk socket creation
  samples/bpf: sample application for eBPF load and socket creation
    split

 samples/bpf/Makefile            |   4 +-
 samples/bpf/xdpsock.h           |   8 ++
 samples/bpf/xdpsock_ctrl_proc.c | 184 ++++++++++++++++++++++++++++++++
 samples/bpf/xdpsock_user.c      | 146 +++++++++++++++++++++++--
 tools/lib/bpf/libbpf.map        |   2 +
 tools/lib/bpf/xsk.c             | 157 ++++++++++++++++++++++-----
 tools/lib/bpf/xsk.h             |  13 +++
 7 files changed, 478 insertions(+), 36 deletions(-)
 create mode 100644 samples/bpf/xdpsock_ctrl_proc.c

-- 
2.20.1


             reply	other threads:[~2020-11-04  9:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-04  9:46 mariusz.dudek [this message]
2020-11-04  9:46 ` [PATCH bpf-next 1/2] libbpf: separate XDP program load with xsk socket creation mariusz.dudek
2020-11-04 21:07   ` Andrii Nakryiko
2020-11-05 13:58     ` Mariusz Dudek
2020-11-04  9:46 ` [PATCH bpf-next 2/2] samples/bpf: sample application for eBPF load and socket creation split mariusz.dudek

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=20201104094626.3406-1-mariuszx.dudek@intel.com \
    --to=mariusz.dudek@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jonathan.lemon@gmail.com \
    --cc=magnus.karlsson@intel.com \
    --cc=mariuszx.dudek@intel.com \
    --cc=netdev@vger.kernel.org \
    /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).