aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2018-05-23 13:23:40 -0400
committerDavid S. Miller <davem@davemloft.net>2018-05-23 13:23:40 -0400
commite95a5f548945c1c212b92e3b88cfb571a7bb95ca (patch)
tree96f528cd9829377165a7357e02438248a88c93b9 /include/linux
parent1fe8c06c4a0d3b589f076cd00c25082840f10423 (diff)
parentd2ba09c17a0647f899d6c20a11bab9e6d3382f07 (diff)
Merge branch 'bpfilter'
Alexei Starovoitov says: ==================== bpfilter v2->v3: - followed Luis's suggestion and significantly simplied first patch with shmem_kernel_file_setup+kernel_write. Added kdoc for new helper - fixed typos and race to access pipes with mutex - tested with bpfilter being 'builtin'. CONFIG_BPFILTER_UMH=y|m both work. Interesting to see a usermode executable being embedded inside vmlinux. - it doesn't hurt to enable bpfilter in .config. ip_setsockopt commands sent to usermode via pipes and -ENOPROTOOPT is returned from userspace, so kernel falls back to original iptables code v1->v2: this patch set is almost a full rewrite of the earlier umh modules approach The v1 of patches and follow up discussion was covered by LWN: https://lwn.net/Articles/749108/ I believe the v2 addresses all issues brought up by Andy and others. Mainly there are zero changes to kernel/module.c Instead of teaching module loading logic to recognize special umh module, let normal kernel modules execute part of its own .init.rodata as a new user space process (Andy's idea) Patch 1 introduces this new helper: int fork_usermode_blob(void *data, size_t len, struct umh_info *info); Input: data + len == executable file Output: struct umh_info { struct file *pipe_to_umh; struct file *pipe_from_umh; pid_t pid; }; Advantages vs v1: - the embedded user mode executable is stored as .init.rodata inside normal kernel module. These pages are freed when .ko finishes loading - the elf file is copied into tmpfs file. The user mode process is swappable. - the communication between user mode process and 'parent' kernel module is done via two unix pipes, hence protocol is not exposed to user space - impossible to launch umh on its own (that was the main issue of v1) and impossible to be man-in-the-middle due to pipes - bpfilter.ko consists of tiny kernel part that passes the data between kernel and umh via pipes and much bigger umh part that doing all the work - 'lsmod' shows bpfilter.ko as usual. 'rmmod bpfilter' removes kernel module and kills corresponding umh - signed bpfilter.ko covers the whole image including umh code Few issues: - the user can still attach to the process and debug it with 'gdb /proc/pid/exe pid', but 'gdb -p pid' doesn't work. (a bit worse comparing to v1) - tinyconfig will notice a small increase in .text +766 | TEXT | 7c8b94806bec umh: introduce fork_usermode_blob() helper ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/binfmts.h1
-rw-r--r--include/linux/bpfilter.h15
-rw-r--r--include/linux/umh.h12
3 files changed, 28 insertions, 0 deletions
diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
index 4955e0863b83..c05f24fac4f6 100644
--- a/include/linux/binfmts.h
+++ b/include/linux/binfmts.h
@@ -150,5 +150,6 @@ extern int do_execveat(int, struct filename *,
150 const char __user * const __user *, 150 const char __user * const __user *,
151 const char __user * const __user *, 151 const char __user * const __user *,
152 int); 152 int);
153int do_execve_file(struct file *file, void *__argv, void *__envp);
153 154
154#endif /* _LINUX_BINFMTS_H */ 155#endif /* _LINUX_BINFMTS_H */
diff --git a/include/linux/bpfilter.h b/include/linux/bpfilter.h
new file mode 100644
index 000000000000..687b1760bb9f
--- /dev/null
+++ b/include/linux/bpfilter.h
@@ -0,0 +1,15 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_BPFILTER_H
3#define _LINUX_BPFILTER_H
4
5#include <uapi/linux/bpfilter.h>
6
7struct sock;
8int bpfilter_ip_set_sockopt(struct sock *sk, int optname, char *optval,
9 unsigned int optlen);
10int bpfilter_ip_get_sockopt(struct sock *sk, int optname, char *optval,
11 int *optlen);
12extern int (*bpfilter_process_sockopt)(struct sock *sk, int optname,
13 char __user *optval,
14 unsigned int optlen, bool is_set);
15#endif
diff --git a/include/linux/umh.h b/include/linux/umh.h
index 244aff638220..5c812acbb80a 100644
--- a/include/linux/umh.h
+++ b/include/linux/umh.h
@@ -22,8 +22,10 @@ struct subprocess_info {
22 const char *path; 22 const char *path;
23 char **argv; 23 char **argv;
24 char **envp; 24 char **envp;
25 struct file *file;
25 int wait; 26 int wait;
26 int retval; 27 int retval;
28 pid_t pid;
27 int (*init)(struct subprocess_info *info, struct cred *new); 29 int (*init)(struct subprocess_info *info, struct cred *new);
28 void (*cleanup)(struct subprocess_info *info); 30 void (*cleanup)(struct subprocess_info *info);
29 void *data; 31 void *data;
@@ -38,6 +40,16 @@ call_usermodehelper_setup(const char *path, char **argv, char **envp,
38 int (*init)(struct subprocess_info *info, struct cred *new), 40 int (*init)(struct subprocess_info *info, struct cred *new),
39 void (*cleanup)(struct subprocess_info *), void *data); 41 void (*cleanup)(struct subprocess_info *), void *data);
40 42
43struct subprocess_info *call_usermodehelper_setup_file(struct file *file,
44 int (*init)(struct subprocess_info *info, struct cred *new),
45 void (*cleanup)(struct subprocess_info *), void *data);
46struct umh_info {
47 struct file *pipe_to_umh;
48 struct file *pipe_from_umh;
49 pid_t pid;
50};
51int fork_usermode_blob(void *data, size_t len, struct umh_info *info);
52
41extern int 53extern int
42call_usermodehelper_exec(struct subprocess_info *info, int wait); 54call_usermodehelper_exec(struct subprocess_info *info, int wait);
43 55