aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2015-10-02 09:17:33 -0400
committerDavid S. Miller <davem@davemloft.net>2015-10-05 09:47:05 -0400
commitbab18991871545dfbd10c931eb0fe8f7637156a9 (patch)
tree1d561750b012be096fce1637fef60a65fbef1fa4 /net
parent0a15afd2eaceceff5be4c8b7166f01c1a68e9642 (diff)
bpf, seccomp: prepare for upcoming criu support
The current ongoing effort to dump existing cBPF seccomp filters back to user space requires to hold the pre-transformed instructions like we do in case of socket filters from sk_attach_filter() side, so they can be reloaded in original form at a later point in time by utilities such as criu. To prepare for this, simply extend the bpf_prog_create_from_user() API to hold a flag that tells whether we should store the original or not. Also, fanout filters could make use of that in future for things like diag. While fanout filters already use bpf_prog_destroy(), move seccomp over to them as well to handle original programs when present. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Cc: Tycho Andersen <tycho.andersen@canonical.com> Cc: Pavel Emelyanov <xemul@parallels.com> Cc: Kees Cook <keescook@chromium.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Alexei Starovoitov <ast@plumgrid.com> Tested-by: Tycho Andersen <tycho.andersen@canonical.com> Acked-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/core/filter.c16
-rw-r--r--net/packet/af_packet.c2
2 files changed, 12 insertions, 6 deletions
diff --git a/net/core/filter.c b/net/core/filter.c
index 53a5036fb32d..da3e5357f138 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1084,16 +1084,18 @@ EXPORT_SYMBOL_GPL(bpf_prog_create);
1084 * @pfp: the unattached filter that is created 1084 * @pfp: the unattached filter that is created
1085 * @fprog: the filter program 1085 * @fprog: the filter program
1086 * @trans: post-classic verifier transformation handler 1086 * @trans: post-classic verifier transformation handler
1087 * @save_orig: save classic BPF program
1087 * 1088 *
1088 * This function effectively does the same as bpf_prog_create(), only 1089 * This function effectively does the same as bpf_prog_create(), only
1089 * that it builds up its insns buffer from user space provided buffer. 1090 * that it builds up its insns buffer from user space provided buffer.
1090 * It also allows for passing a bpf_aux_classic_check_t handler. 1091 * It also allows for passing a bpf_aux_classic_check_t handler.
1091 */ 1092 */
1092int bpf_prog_create_from_user(struct bpf_prog **pfp, struct sock_fprog *fprog, 1093int bpf_prog_create_from_user(struct bpf_prog **pfp, struct sock_fprog *fprog,
1093 bpf_aux_classic_check_t trans) 1094 bpf_aux_classic_check_t trans, bool save_orig)
1094{ 1095{
1095 unsigned int fsize = bpf_classic_proglen(fprog); 1096 unsigned int fsize = bpf_classic_proglen(fprog);
1096 struct bpf_prog *fp; 1097 struct bpf_prog *fp;
1098 int err;
1097 1099
1098 /* Make sure new filter is there and in the right amounts. */ 1100 /* Make sure new filter is there and in the right amounts. */
1099 if (fprog->filter == NULL) 1101 if (fprog->filter == NULL)
@@ -1109,12 +1111,16 @@ int bpf_prog_create_from_user(struct bpf_prog **pfp, struct sock_fprog *fprog,
1109 } 1111 }
1110 1112
1111 fp->len = fprog->len; 1113 fp->len = fprog->len;
1112 /* Since unattached filters are not copied back to user
1113 * space through sk_get_filter(), we do not need to hold
1114 * a copy here, and can spare us the work.
1115 */
1116 fp->orig_prog = NULL; 1114 fp->orig_prog = NULL;
1117 1115
1116 if (save_orig) {
1117 err = bpf_prog_store_orig_filter(fp, fprog);
1118 if (err) {
1119 __bpf_prog_free(fp);
1120 return -ENOMEM;
1121 }
1122 }
1123
1118 /* bpf_prepare_filter() already takes care of freeing 1124 /* bpf_prepare_filter() already takes care of freeing
1119 * memory in case something goes wrong. 1125 * memory in case something goes wrong.
1120 */ 1126 */
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index aa4b15c35884..81c900fbc4a4 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1567,7 +1567,7 @@ static int fanout_set_data_cbpf(struct packet_sock *po, char __user *data,
1567 if (copy_from_user(&fprog, data, len)) 1567 if (copy_from_user(&fprog, data, len))
1568 return -EFAULT; 1568 return -EFAULT;
1569 1569
1570 ret = bpf_prog_create_from_user(&new, &fprog, NULL); 1570 ret = bpf_prog_create_from_user(&new, &fprog, NULL, false);
1571 if (ret) 1571 if (ret)
1572 return ret; 1572 return ret;
1573 1573