aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2018-04-08 19:51:41 -0400
committerDavid S. Miller <davem@davemloft.net>2018-04-08 19:51:41 -0400
commit1f1cba787f5b2c03e3d103829cc02a74a7c9110a (patch)
treed913d7859536871bdd3ecd10fe100ade6f69b4b5
parent4c7c12e0c9b8224170afd974eed9ea032bd7f453 (diff)
parent33491588c1fb2c76ed114a211ad0ee76c16b5a0c (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Daniel Borkmann says: ==================== pull-request: bpf 2018-04-09 The following pull-request contains BPF updates for your *net* tree. The main changes are: 1) Two sockmap fixes: i) fix a potential warning when a socket with pending cork data is closed by freeing the memory right when the socket is closed instead of seeing still outstanding memory at garbage collector time, ii) fix a NULL pointer deref in case of duplicates release calls, so make sure to only reset the sk_prot pointer when it's in a valid state to do so, both from John. 2) Fix a compilation warning in bpf_prog_attach_check_attach_type() by moving the function under CONFIG_CGROUP_BPF ifdef since only used there, from Anders. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--kernel/bpf/sockmap.c12
-rw-r--r--kernel/bpf/syscall.c24
2 files changed, 22 insertions, 14 deletions
diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index d2bda5aa25d7..8dd9210d7db7 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -182,8 +182,10 @@ static void bpf_tcp_release(struct sock *sk)
182 psock->cork = NULL; 182 psock->cork = NULL;
183 } 183 }
184 184
185 sk->sk_prot = psock->sk_proto; 185 if (psock->sk_proto) {
186 psock->sk_proto = NULL; 186 sk->sk_prot = psock->sk_proto;
187 psock->sk_proto = NULL;
188 }
187out: 189out:
188 rcu_read_unlock(); 190 rcu_read_unlock();
189} 191}
@@ -211,6 +213,12 @@ static void bpf_tcp_close(struct sock *sk, long timeout)
211 close_fun = psock->save_close; 213 close_fun = psock->save_close;
212 214
213 write_lock_bh(&sk->sk_callback_lock); 215 write_lock_bh(&sk->sk_callback_lock);
216 if (psock->cork) {
217 free_start_sg(psock->sock, psock->cork);
218 kfree(psock->cork);
219 psock->cork = NULL;
220 }
221
214 list_for_each_entry_safe(md, mtmp, &psock->ingress, list) { 222 list_for_each_entry_safe(md, mtmp, &psock->ingress, list) {
215 list_del(&md->list); 223 list_del(&md->list);
216 free_start_sg(psock->sock, md); 224 free_start_sg(psock->sock, md);
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 0244973ee544..4ca46df19c9a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1226,18 +1226,6 @@ bpf_prog_load_check_attach_type(enum bpf_prog_type prog_type,
1226 } 1226 }
1227} 1227}
1228 1228
1229static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog,
1230 enum bpf_attach_type attach_type)
1231{
1232 switch (prog->type) {
1233 case BPF_PROG_TYPE_CGROUP_SOCK:
1234 case BPF_PROG_TYPE_CGROUP_SOCK_ADDR:
1235 return attach_type == prog->expected_attach_type ? 0 : -EINVAL;
1236 default:
1237 return 0;
1238 }
1239}
1240
1241/* last field in 'union bpf_attr' used by this command */ 1229/* last field in 'union bpf_attr' used by this command */
1242#define BPF_PROG_LOAD_LAST_FIELD expected_attach_type 1230#define BPF_PROG_LOAD_LAST_FIELD expected_attach_type
1243 1231
@@ -1465,6 +1453,18 @@ out_free_tp:
1465 1453
1466#ifdef CONFIG_CGROUP_BPF 1454#ifdef CONFIG_CGROUP_BPF
1467 1455
1456static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog,
1457 enum bpf_attach_type attach_type)
1458{
1459 switch (prog->type) {
1460 case BPF_PROG_TYPE_CGROUP_SOCK:
1461 case BPF_PROG_TYPE_CGROUP_SOCK_ADDR:
1462 return attach_type == prog->expected_attach_type ? 0 : -EINVAL;
1463 default:
1464 return 0;
1465 }
1466}
1467
1468#define BPF_PROG_ATTACH_LAST_FIELD attach_flags 1468#define BPF_PROG_ATTACH_LAST_FIELD attach_flags
1469 1469
1470static int sockmap_get_from_fd(const union bpf_attr *attr, 1470static int sockmap_get_from_fd(const union bpf_attr *attr,