Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1509705
| From | Jann Horn <jann@thejh.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [kernel-hardening] [RFC v4 03/18] bpf,landlock: Add a new arraymap type to deal with (Landlock) handles |
| Date | 2016-10-26 21:10 +0200 |
| Message-ID | <swBKh-809-1@gated-at.bofh.it> (permalink) |
| References | <swqlP-8qD-3@gated-at.bofh.it> <swqvw-i6-33@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
[Multipart message — attachments visible in raw view] - view raw
On Wed, Oct 26, 2016 at 08:56:39AM +0200, Mickaël Salaün wrote:
> This new arraymap looks like a set and brings new properties:
> * strong typing of entries: the eBPF functions get the array type of
> elements instead of CONST_PTR_TO_MAP (e.g.
> CONST_PTR_TO_LANDLOCK_HANDLE_FS);
> * force sequential filling (i.e. replace or append-only update), which
> allow quick browsing of all entries.
>
> This strong typing is useful to statically check if the content of a map
> can be passed to an eBPF function. For example, Landlock use it to store
> and manage kernel objects (e.g. struct file) instead of dealing with
> userland raw data. This improve efficiency and ensure that an eBPF
> program can only call functions with the right high-level arguments.
>
> The enum bpf_map_handle_type list low-level types (e.g.
> BPF_MAP_HANDLE_TYPE_LANDLOCK_FS_FD) which are identified when
> updating a map entry (handle). This handle types are used to infer a
> high-level arraymap type which are listed in enum bpf_map_array_type
> (e.g. BPF_MAP_ARRAY_TYPE_LANDLOCK_FS).
>
> For now, this new arraymap is only used by Landlock LSM (cf. next
> commits) but it could be useful for other needs.
>
> Changes since v3:
> * make handle arraymap safe (RCU) and remove buggy synchronize_rcu()
> * factor out the arraymay walk
>
> Changes since v2:
> * add a RLIMIT_NOFILE-based limit to the maximum number of arraymap
> handle entries (suggested by Andy Lutomirski)
> * remove useless checks
>
> Changes since v1:
> * arraymap of handles replace custom checker groups
> * simpler userland API
[...]
> + case BPF_MAP_HANDLE_TYPE_LANDLOCK_FS_FD:
> + handle_file = fget(handle->fd);
> + if (IS_ERR(handle_file))
> + return ERR_CAST(handle_file);
> + /* check if the FD is tied to a user mount point */
> + if (unlikely(handle_file->f_path.mnt->mnt_flags & MNT_INTERNAL)) {
> + fput(handle_file);
> + return ERR_PTR(-EINVAL);
> + }
> + path_get(&handle_file->f_path);
> + ret = kmalloc(sizeof(*ret), GFP_KERNEL);
> + ret->path = handle_file->f_path;
> + fput(handle_file);
You can use fdget() and fdput() here because the reference to
handle_file is dropped before the end of the syscall.
> + break;
> + case BPF_MAP_HANDLE_TYPE_UNSPEC:
> + default:
> + return ERR_PTR(-EINVAL);
> + }
> + ret->type = handle_type;
> + return ret;
> +}
> +
> +static void *nop_map_lookup_elem(struct bpf_map *map, void *key)
> +{
> + return ERR_PTR(-EINVAL);
> +}
> +
> +/* called from syscall or from eBPF program */
> +static int landlock_array_map_update_elem(struct bpf_map *map, void *key,
> + void *value, u64 map_flags)
> +{
This being callable from eBPF context is IMO pretty surprising and should
at least be well-documented. Also: What is the usecase here?
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[RFC v4 00/18] Landlock LSM: Unprivileged sandboxing Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:00 +0200
[RFC v4 16/18] bpf/cgroup,landlock: Handle Landlock hooks per cgroup Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:00 +0200
[RFC v4 11/18] seccomp,landlock: Handle Landlock hooks per process hierarchy Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:00 +0200
[RFC v4 05/18] bpf,landlock: Define an eBPF program type for Landlock Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 06/18] fs: Constify path_is_under()'s arguments Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 10/18] seccomp: Split put_seccomp_filter() with put_seccomp() Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 14/18] bpf/cgroup: Make cgroup_bpf_update() return an error code Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 13/18] bpf/cgroup: Replace struct bpf_prog with struct bpf_object Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 12/18] bpf: Cosmetic change for bpf_prog_attach() Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 01/18] landlock: Add Kconfig Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 09/18] landlock: Add manager functions Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 03/18] bpf,landlock: Add a new arraymap type to deal with (Landlock) handles Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
Re: [kernel-hardening] [RFC v4 03/18] bpf,landlock: Add a new arraymap type to deal with (Landlock) handles Jann Horn <jann@thejh.net> - 2016-10-26 21:10 +0200
Re: [kernel-hardening] [RFC v4 03/18] bpf,landlock: Add a new arraymap type to deal with (Landlock) handles Mickaël Salaün <mic@digikod.net> - 2016-10-26 22:10 +0200
Re: [kernel-hardening] [RFC v4 03/18] bpf,landlock: Add a new arraymap type to deal with (Landlock) handles Jann Horn <jann@thejh.net> - 2016-10-26 22:20 +0200
[RFC v4 02/18] bpf: Move u64_to_ptr() to BPF headers and inline it Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
Re: [RFC v4 02/18] bpf: Move u64_to_ptr() to BPF headers and inline it Arnd Bergmann <arnd@arndb.de> - 2016-10-26 09:30 +0200
Re: [kernel-hardening] Re: [RFC v4 02/18] bpf: Move u64_to_ptr() to BPF headers and inline it David Sterba <dave@jikos.cz> - 2016-10-26 16:00 +0200
[RFC v4 08/18] landlock: Handle file comparisons Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 04/18] bpf,landlock: Add eBPF program subtype and is_valid_subtype() verifier Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 17/18] landlock: Add update and debug access flags Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
[RFC v4 07/18] landlock: Add LSM hooks Mickaël Salaün <mic@digikod.net> - 2016-10-26 09:10 +0200
Re: [RFC v4 00/18] Landlock LSM: Unprivileged sandboxing Jann Horn <jann@thejh.net> - 2016-10-26 17:00 +0200
Re: [RFC v4 00/18] Landlock LSM: Unprivileged sandboxing Mickaël Salaün <mic@digikod.net> - 2016-10-26 19:00 +0200
Re: [RFC v4 00/18] Landlock LSM: Unprivileged sandboxing Mickaël Salaün <mic@digikod.net> - 2016-10-26 19:30 +0200
csiph-web