diff options
author | James Morris <james.morris@microsoft.com> | 2018-03-22 17:26:16 -0400 |
---|---|---|
committer | James Morris <james.morris@microsoft.com> | 2018-03-22 17:26:16 -0400 |
commit | 5893ed18a26d1f56b97c0290b0cbbc2d49d6de28 (patch) | |
tree | 97aa931519fca28a0a12fad7485347198f8267cc /kernel | |
parent | 7bd698b3c04e61ee9e03d4c2a55003f75df14dca (diff) | |
parent | c698ca5278934c0ae32297a8725ced2e27585d7f (diff) |
Merge tag 'v4.16-rc6' into next-general
Merge to Linux 4.16-rc6 at the request of Jarkko, for his TPM updates.
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/bpf/arraymap.c | 33 | ||||
-rw-r--r-- | kernel/bpf/core.c | 2 | ||||
-rw-r--r-- | kernel/bpf/cpumap.c | 2 | ||||
-rw-r--r-- | kernel/bpf/lpm_trie.c | 14 | ||||
-rw-r--r-- | kernel/bpf/sockmap.c | 3 | ||||
-rw-r--r-- | kernel/bpf/verifier.c | 42 | ||||
-rw-r--r-- | kernel/compat.c | 19 | ||||
-rw-r--r-- | kernel/events/core.c | 4 | ||||
-rw-r--r-- | kernel/extable.c | 2 | ||||
-rw-r--r-- | kernel/fork.c | 15 | ||||
-rw-r--r-- | kernel/irq/matrix.c | 23 | ||||
-rw-r--r-- | kernel/jump_label.c | 28 | ||||
-rw-r--r-- | kernel/locking/rtmutex.c | 5 | ||||
-rw-r--r-- | kernel/memremap.c | 15 | ||||
-rw-r--r-- | kernel/panic.c | 2 | ||||
-rw-r--r-- | kernel/printk/printk.c | 3 | ||||
-rw-r--r-- | kernel/relay.c | 2 | ||||
-rw-r--r-- | kernel/seccomp.c | 6 | ||||
-rw-r--r-- | kernel/time/timer.c | 6 | ||||
-rw-r--r-- | kernel/trace/bpf_trace.c | 2 | ||||
-rw-r--r-- | kernel/user.c | 3 | ||||
-rw-r--r-- | kernel/workqueue.c | 16 |
22 files changed, 149 insertions, 98 deletions
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index b1f66480135b..14750e7c5ee4 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c | |||
@@ -26,8 +26,10 @@ static void bpf_array_free_percpu(struct bpf_array *array) | |||
26 | { | 26 | { |
27 | int i; | 27 | int i; |
28 | 28 | ||
29 | for (i = 0; i < array->map.max_entries; i++) | 29 | for (i = 0; i < array->map.max_entries; i++) { |
30 | free_percpu(array->pptrs[i]); | 30 | free_percpu(array->pptrs[i]); |
31 | cond_resched(); | ||
32 | } | ||
31 | } | 33 | } |
32 | 34 | ||
33 | static int bpf_array_alloc_percpu(struct bpf_array *array) | 35 | static int bpf_array_alloc_percpu(struct bpf_array *array) |
@@ -43,6 +45,7 @@ static int bpf_array_alloc_percpu(struct bpf_array *array) | |||
43 | return -ENOMEM; | 45 | return -ENOMEM; |
44 | } | 46 | } |
45 | array->pptrs[i] = ptr; | 47 | array->pptrs[i] = ptr; |
48 | cond_resched(); | ||
46 | } | 49 | } |
47 | 50 | ||
48 | return 0; | 51 | return 0; |
@@ -73,11 +76,11 @@ static int array_map_alloc_check(union bpf_attr *attr) | |||
73 | static struct bpf_map *array_map_alloc(union bpf_attr *attr) | 76 | static struct bpf_map *array_map_alloc(union bpf_attr *attr) |
74 | { | 77 | { |
75 | bool percpu = attr->map_type == BPF_MAP_TYPE_PERCPU_ARRAY; | 78 | bool percpu = attr->map_type == BPF_MAP_TYPE_PERCPU_ARRAY; |
76 | int numa_node = bpf_map_attr_numa_node(attr); | 79 | int ret, numa_node = bpf_map_attr_numa_node(attr); |
77 | u32 elem_size, index_mask, max_entries; | 80 | u32 elem_size, index_mask, max_entries; |
78 | bool unpriv = !capable(CAP_SYS_ADMIN); | 81 | bool unpriv = !capable(CAP_SYS_ADMIN); |
82 | u64 cost, array_size, mask64; | ||
79 | struct bpf_array *array; | 83 | struct bpf_array *array; |
80 | u64 array_size, mask64; | ||
81 | 84 | ||
82 | elem_size = round_up(attr->value_size, 8); | 85 | elem_size = round_up(attr->value_size, 8); |
83 | 86 | ||
@@ -109,8 +112,19 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr) | |||
109 | array_size += (u64) max_entries * elem_size; | 112 | array_size += (u64) max_entries * elem_size; |
110 | 113 | ||
111 | /* make sure there is no u32 overflow later in round_up() */ | 114 | /* make sure there is no u32 overflow later in round_up() */ |
112 | if (array_size >= U32_MAX - PAGE_SIZE) | 115 | cost = array_size; |
116 | if (cost >= U32_MAX - PAGE_SIZE) | ||
113 | return ERR_PTR(-ENOMEM); | 117 | return ERR_PTR(-ENOMEM); |
118 | if (percpu) { | ||
119 | cost += (u64)attr->max_entries * elem_size * num_possible_cpus(); | ||
120 | if (cost >= U32_MAX - PAGE_SIZE) | ||
121 | return ERR_PTR(-ENOMEM); | ||
122 | } | ||
123 | cost = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT; | ||
124 | |||
125 | ret = bpf_map_precharge_memlock(cost); | ||
126 | if (ret < 0) | ||
127 | return ERR_PTR(ret); | ||
114 | 128 | ||
115 | /* allocate all map elements and zero-initialize them */ | 129 | /* allocate all map elements and zero-initialize them */ |
116 | array = bpf_map_area_alloc(array_size, numa_node); | 130 | array = bpf_map_area_alloc(array_size, numa_node); |
@@ -121,20 +135,13 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr) | |||
121 | 135 | ||
122 | /* copy mandatory map attributes */ | 136 | /* copy mandatory map attributes */ |
123 | bpf_map_init_from_attr(&array->map, attr); | 137 | bpf_map_init_from_attr(&array->map, attr); |
138 | array->map.pages = cost; | ||
124 | array->elem_size = elem_size; | 139 | array->elem_size = elem_size; |
125 | 140 | ||
126 | if (!percpu) | 141 | if (percpu && bpf_array_alloc_percpu(array)) { |
127 | goto out; | ||
128 | |||
129 | array_size += (u64) attr->max_entries * elem_size * num_possible_cpus(); | ||
130 | |||
131 | if (array_size >= U32_MAX - PAGE_SIZE || | ||
132 | bpf_array_alloc_percpu(array)) { | ||
133 | bpf_map_area_free(array); | 142 | bpf_map_area_free(array); |
134 | return ERR_PTR(-ENOMEM); | 143 | return ERR_PTR(-ENOMEM); |
135 | } | 144 | } |
136 | out: | ||
137 | array->map.pages = round_up(array_size, PAGE_SIZE) >> PAGE_SHIFT; | ||
138 | 145 | ||
139 | return &array->map; | 146 | return &array->map; |
140 | } | 147 | } |
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 29ca9208dcfa..d315b393abdd 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c | |||
@@ -1590,7 +1590,7 @@ int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs, | |||
1590 | * so always copy 'cnt' prog_ids to the user. | 1590 | * so always copy 'cnt' prog_ids to the user. |
1591 | * In a rare race the user will see zero prog_ids | 1591 | * In a rare race the user will see zero prog_ids |
1592 | */ | 1592 | */ |
1593 | ids = kcalloc(cnt, sizeof(u32), GFP_USER); | 1593 | ids = kcalloc(cnt, sizeof(u32), GFP_USER | __GFP_NOWARN); |
1594 | if (!ids) | 1594 | if (!ids) |
1595 | return -ENOMEM; | 1595 | return -ENOMEM; |
1596 | rcu_read_lock(); | 1596 | rcu_read_lock(); |
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c index fbfdada6caee..a4bb0b34375a 100644 --- a/kernel/bpf/cpumap.c +++ b/kernel/bpf/cpumap.c | |||
@@ -334,7 +334,7 @@ static int cpu_map_kthread_run(void *data) | |||
334 | static struct bpf_cpu_map_entry *__cpu_map_entry_alloc(u32 qsize, u32 cpu, | 334 | static struct bpf_cpu_map_entry *__cpu_map_entry_alloc(u32 qsize, u32 cpu, |
335 | int map_id) | 335 | int map_id) |
336 | { | 336 | { |
337 | gfp_t gfp = GFP_ATOMIC|__GFP_NOWARN; | 337 | gfp_t gfp = GFP_KERNEL | __GFP_NOWARN; |
338 | struct bpf_cpu_map_entry *rcpu; | 338 | struct bpf_cpu_map_entry *rcpu; |
339 | int numa, err; | 339 | int numa, err; |
340 | 340 | ||
diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c index 7b469d10d0e9..b4b5b81e7251 100644 --- a/kernel/bpf/lpm_trie.c +++ b/kernel/bpf/lpm_trie.c | |||
@@ -555,7 +555,10 @@ static void trie_free(struct bpf_map *map) | |||
555 | struct lpm_trie_node __rcu **slot; | 555 | struct lpm_trie_node __rcu **slot; |
556 | struct lpm_trie_node *node; | 556 | struct lpm_trie_node *node; |
557 | 557 | ||
558 | raw_spin_lock(&trie->lock); | 558 | /* Wait for outstanding programs to complete |
559 | * update/lookup/delete/get_next_key and free the trie. | ||
560 | */ | ||
561 | synchronize_rcu(); | ||
559 | 562 | ||
560 | /* Always start at the root and walk down to a node that has no | 563 | /* Always start at the root and walk down to a node that has no |
561 | * children. Then free that node, nullify its reference in the parent | 564 | * children. Then free that node, nullify its reference in the parent |
@@ -566,10 +569,9 @@ static void trie_free(struct bpf_map *map) | |||
566 | slot = &trie->root; | 569 | slot = &trie->root; |
567 | 570 | ||
568 | for (;;) { | 571 | for (;;) { |
569 | node = rcu_dereference_protected(*slot, | 572 | node = rcu_dereference_protected(*slot, 1); |
570 | lockdep_is_held(&trie->lock)); | ||
571 | if (!node) | 573 | if (!node) |
572 | goto unlock; | 574 | goto out; |
573 | 575 | ||
574 | if (rcu_access_pointer(node->child[0])) { | 576 | if (rcu_access_pointer(node->child[0])) { |
575 | slot = &node->child[0]; | 577 | slot = &node->child[0]; |
@@ -587,8 +589,8 @@ static void trie_free(struct bpf_map *map) | |||
587 | } | 589 | } |
588 | } | 590 | } |
589 | 591 | ||
590 | unlock: | 592 | out: |
591 | raw_spin_unlock(&trie->lock); | 593 | kfree(trie); |
592 | } | 594 | } |
593 | 595 | ||
594 | static int trie_get_next_key(struct bpf_map *map, void *_key, void *_next_key) | 596 | static int trie_get_next_key(struct bpf_map *map, void *_key, void *_next_key) |
diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c index 48c33417d13c..a927e89dad6e 100644 --- a/kernel/bpf/sockmap.c +++ b/kernel/bpf/sockmap.c | |||
@@ -521,8 +521,8 @@ static struct smap_psock *smap_init_psock(struct sock *sock, | |||
521 | static struct bpf_map *sock_map_alloc(union bpf_attr *attr) | 521 | static struct bpf_map *sock_map_alloc(union bpf_attr *attr) |
522 | { | 522 | { |
523 | struct bpf_stab *stab; | 523 | struct bpf_stab *stab; |
524 | int err = -EINVAL; | ||
525 | u64 cost; | 524 | u64 cost; |
525 | int err; | ||
526 | 526 | ||
527 | if (!capable(CAP_NET_ADMIN)) | 527 | if (!capable(CAP_NET_ADMIN)) |
528 | return ERR_PTR(-EPERM); | 528 | return ERR_PTR(-EPERM); |
@@ -547,6 +547,7 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr) | |||
547 | 547 | ||
548 | /* make sure page count doesn't overflow */ | 548 | /* make sure page count doesn't overflow */ |
549 | cost = (u64) stab->map.max_entries * sizeof(struct sock *); | 549 | cost = (u64) stab->map.max_entries * sizeof(struct sock *); |
550 | err = -EINVAL; | ||
550 | if (cost >= U32_MAX - PAGE_SIZE) | 551 | if (cost >= U32_MAX - PAGE_SIZE) |
551 | goto free_stab; | 552 | goto free_stab; |
552 | 553 | ||
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 5fb69a85d967..c6eff108aa99 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c | |||
@@ -1356,6 +1356,13 @@ static bool is_ctx_reg(struct bpf_verifier_env *env, int regno) | |||
1356 | return reg->type == PTR_TO_CTX; | 1356 | return reg->type == PTR_TO_CTX; |
1357 | } | 1357 | } |
1358 | 1358 | ||
1359 | static bool is_pkt_reg(struct bpf_verifier_env *env, int regno) | ||
1360 | { | ||
1361 | const struct bpf_reg_state *reg = cur_regs(env) + regno; | ||
1362 | |||
1363 | return type_is_pkt_pointer(reg->type); | ||
1364 | } | ||
1365 | |||
1359 | static int check_pkt_ptr_alignment(struct bpf_verifier_env *env, | 1366 | static int check_pkt_ptr_alignment(struct bpf_verifier_env *env, |
1360 | const struct bpf_reg_state *reg, | 1367 | const struct bpf_reg_state *reg, |
1361 | int off, int size, bool strict) | 1368 | int off, int size, bool strict) |
@@ -1416,10 +1423,10 @@ static int check_generic_ptr_alignment(struct bpf_verifier_env *env, | |||
1416 | } | 1423 | } |
1417 | 1424 | ||
1418 | static int check_ptr_alignment(struct bpf_verifier_env *env, | 1425 | static int check_ptr_alignment(struct bpf_verifier_env *env, |
1419 | const struct bpf_reg_state *reg, | 1426 | const struct bpf_reg_state *reg, int off, |
1420 | int off, int size) | 1427 | int size, bool strict_alignment_once) |
1421 | { | 1428 | { |
1422 | bool strict = env->strict_alignment; | 1429 | bool strict = env->strict_alignment || strict_alignment_once; |
1423 | const char *pointer_desc = ""; | 1430 | const char *pointer_desc = ""; |
1424 | 1431 | ||
1425 | switch (reg->type) { | 1432 | switch (reg->type) { |
@@ -1576,9 +1583,9 @@ static void coerce_reg_to_size(struct bpf_reg_state *reg, int size) | |||
1576 | * if t==write && value_regno==-1, some unknown value is stored into memory | 1583 | * if t==write && value_regno==-1, some unknown value is stored into memory |
1577 | * if t==read && value_regno==-1, don't care what we read from memory | 1584 | * if t==read && value_regno==-1, don't care what we read from memory |
1578 | */ | 1585 | */ |
1579 | static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regno, int off, | 1586 | static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regno, |
1580 | int bpf_size, enum bpf_access_type t, | 1587 | int off, int bpf_size, enum bpf_access_type t, |
1581 | int value_regno) | 1588 | int value_regno, bool strict_alignment_once) |
1582 | { | 1589 | { |
1583 | struct bpf_reg_state *regs = cur_regs(env); | 1590 | struct bpf_reg_state *regs = cur_regs(env); |
1584 | struct bpf_reg_state *reg = regs + regno; | 1591 | struct bpf_reg_state *reg = regs + regno; |
@@ -1590,7 +1597,7 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regn | |||
1590 | return size; | 1597 | return size; |
1591 | 1598 | ||
1592 | /* alignment checks will add in reg->off themselves */ | 1599 | /* alignment checks will add in reg->off themselves */ |
1593 | err = check_ptr_alignment(env, reg, off, size); | 1600 | err = check_ptr_alignment(env, reg, off, size, strict_alignment_once); |
1594 | if (err) | 1601 | if (err) |
1595 | return err; | 1602 | return err; |
1596 | 1603 | ||
@@ -1735,21 +1742,23 @@ static int check_xadd(struct bpf_verifier_env *env, int insn_idx, struct bpf_ins | |||
1735 | return -EACCES; | 1742 | return -EACCES; |
1736 | } | 1743 | } |
1737 | 1744 | ||
1738 | if (is_ctx_reg(env, insn->dst_reg)) { | 1745 | if (is_ctx_reg(env, insn->dst_reg) || |
1739 | verbose(env, "BPF_XADD stores into R%d context is not allowed\n", | 1746 | is_pkt_reg(env, insn->dst_reg)) { |
1740 | insn->dst_reg); | 1747 | verbose(env, "BPF_XADD stores into R%d %s is not allowed\n", |
1748 | insn->dst_reg, is_ctx_reg(env, insn->dst_reg) ? | ||
1749 | "context" : "packet"); | ||
1741 | return -EACCES; | 1750 | return -EACCES; |
1742 | } | 1751 | } |
1743 | 1752 | ||
1744 | /* check whether atomic_add can read the memory */ | 1753 | /* check whether atomic_add can read the memory */ |
1745 | err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, | 1754 | err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, |
1746 | BPF_SIZE(insn->code), BPF_READ, -1); | 1755 | BPF_SIZE(insn->code), BPF_READ, -1, true); |
1747 | if (err) | 1756 | if (err) |
1748 | return err; | 1757 | return err; |
1749 | 1758 | ||
1750 | /* check whether atomic_add can write into the same memory */ | 1759 | /* check whether atomic_add can write into the same memory */ |
1751 | return check_mem_access(env, insn_idx, insn->dst_reg, insn->off, | 1760 | return check_mem_access(env, insn_idx, insn->dst_reg, insn->off, |
1752 | BPF_SIZE(insn->code), BPF_WRITE, -1); | 1761 | BPF_SIZE(insn->code), BPF_WRITE, -1, true); |
1753 | } | 1762 | } |
1754 | 1763 | ||
1755 | /* when register 'regno' is passed into function that will read 'access_size' | 1764 | /* when register 'regno' is passed into function that will read 'access_size' |
@@ -2388,7 +2397,8 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn | |||
2388 | * is inferred from register state. | 2397 | * is inferred from register state. |
2389 | */ | 2398 | */ |
2390 | for (i = 0; i < meta.access_size; i++) { | 2399 | for (i = 0; i < meta.access_size; i++) { |
2391 | err = check_mem_access(env, insn_idx, meta.regno, i, BPF_B, BPF_WRITE, -1); | 2400 | err = check_mem_access(env, insn_idx, meta.regno, i, BPF_B, |
2401 | BPF_WRITE, -1, false); | ||
2392 | if (err) | 2402 | if (err) |
2393 | return err; | 2403 | return err; |
2394 | } | 2404 | } |
@@ -4632,7 +4642,7 @@ static int do_check(struct bpf_verifier_env *env) | |||
4632 | */ | 4642 | */ |
4633 | err = check_mem_access(env, insn_idx, insn->src_reg, insn->off, | 4643 | err = check_mem_access(env, insn_idx, insn->src_reg, insn->off, |
4634 | BPF_SIZE(insn->code), BPF_READ, | 4644 | BPF_SIZE(insn->code), BPF_READ, |
4635 | insn->dst_reg); | 4645 | insn->dst_reg, false); |
4636 | if (err) | 4646 | if (err) |
4637 | return err; | 4647 | return err; |
4638 | 4648 | ||
@@ -4684,7 +4694,7 @@ static int do_check(struct bpf_verifier_env *env) | |||
4684 | /* check that memory (dst_reg + off) is writeable */ | 4694 | /* check that memory (dst_reg + off) is writeable */ |
4685 | err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, | 4695 | err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, |
4686 | BPF_SIZE(insn->code), BPF_WRITE, | 4696 | BPF_SIZE(insn->code), BPF_WRITE, |
4687 | insn->src_reg); | 4697 | insn->src_reg, false); |
4688 | if (err) | 4698 | if (err) |
4689 | return err; | 4699 | return err; |
4690 | 4700 | ||
@@ -4719,7 +4729,7 @@ static int do_check(struct bpf_verifier_env *env) | |||
4719 | /* check that memory (dst_reg + off) is writeable */ | 4729 | /* check that memory (dst_reg + off) is writeable */ |
4720 | err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, | 4730 | err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, |
4721 | BPF_SIZE(insn->code), BPF_WRITE, | 4731 | BPF_SIZE(insn->code), BPF_WRITE, |
4722 | -1); | 4732 | -1, false); |
4723 | if (err) | 4733 | if (err) |
4724 | return err; | 4734 | return err; |
4725 | 4735 | ||
diff --git a/kernel/compat.c b/kernel/compat.c index 3247fe761f60..3f5fa8902e7d 100644 --- a/kernel/compat.c +++ b/kernel/compat.c | |||
@@ -488,25 +488,6 @@ get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat) | |||
488 | } | 488 | } |
489 | EXPORT_SYMBOL_GPL(get_compat_sigset); | 489 | EXPORT_SYMBOL_GPL(get_compat_sigset); |
490 | 490 | ||
491 | int | ||
492 | put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set, | ||
493 | unsigned int size) | ||
494 | { | ||
495 | /* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */ | ||
496 | #ifdef __BIG_ENDIAN | ||
497 | compat_sigset_t v; | ||
498 | switch (_NSIG_WORDS) { | ||
499 | case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3]; | ||
500 | case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2]; | ||
501 | case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1]; | ||
502 | case 1: v.sig[1] = (set->sig[0] >> 32); v.sig[0] = set->sig[0]; | ||
503 | } | ||
504 | return copy_to_user(compat, &v, size) ? -EFAULT : 0; | ||
505 | #else | ||
506 | return copy_to_user(compat, set, size) ? -EFAULT : 0; | ||
507 | #endif | ||
508 | } | ||
509 | |||
510 | #ifdef CONFIG_NUMA | 491 | #ifdef CONFIG_NUMA |
511 | COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages, | 492 | COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages, |
512 | compat_uptr_t __user *, pages32, | 493 | compat_uptr_t __user *, pages32, |
diff --git a/kernel/events/core.c b/kernel/events/core.c index 96db9ae5d5af..4b838470fac4 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c | |||
@@ -2246,7 +2246,7 @@ static void ctx_resched(struct perf_cpu_context *cpuctx, | |||
2246 | struct perf_event_context *task_ctx, | 2246 | struct perf_event_context *task_ctx, |
2247 | enum event_type_t event_type) | 2247 | enum event_type_t event_type) |
2248 | { | 2248 | { |
2249 | enum event_type_t ctx_event_type = event_type & EVENT_ALL; | 2249 | enum event_type_t ctx_event_type; |
2250 | bool cpu_event = !!(event_type & EVENT_CPU); | 2250 | bool cpu_event = !!(event_type & EVENT_CPU); |
2251 | 2251 | ||
2252 | /* | 2252 | /* |
@@ -2256,6 +2256,8 @@ static void ctx_resched(struct perf_cpu_context *cpuctx, | |||
2256 | if (event_type & EVENT_PINNED) | 2256 | if (event_type & EVENT_PINNED) |
2257 | event_type |= EVENT_FLEXIBLE; | 2257 | event_type |= EVENT_FLEXIBLE; |
2258 | 2258 | ||
2259 | ctx_event_type = event_type & EVENT_ALL; | ||
2260 | |||
2259 | perf_pmu_disable(cpuctx->ctx.pmu); | 2261 | perf_pmu_disable(cpuctx->ctx.pmu); |
2260 | if (task_ctx) | 2262 | if (task_ctx) |
2261 | task_ctx_sched_out(cpuctx, task_ctx, event_type); | 2263 | task_ctx_sched_out(cpuctx, task_ctx, event_type); |
diff --git a/kernel/extable.c b/kernel/extable.c index a17fdb63dc3e..6a5b61ebc66c 100644 --- a/kernel/extable.c +++ b/kernel/extable.c | |||
@@ -64,7 +64,7 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr) | |||
64 | return e; | 64 | return e; |
65 | } | 65 | } |
66 | 66 | ||
67 | static inline int init_kernel_text(unsigned long addr) | 67 | int init_kernel_text(unsigned long addr) |
68 | { | 68 | { |
69 | if (addr >= (unsigned long)_sinittext && | 69 | if (addr >= (unsigned long)_sinittext && |
70 | addr < (unsigned long)_einittext) | 70 | addr < (unsigned long)_einittext) |
diff --git a/kernel/fork.c b/kernel/fork.c index be8aa5b98666..e5d9d405ae4e 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -592,7 +592,7 @@ static void check_mm(struct mm_struct *mm) | |||
592 | * is dropped: either by a lazy thread or by | 592 | * is dropped: either by a lazy thread or by |
593 | * mmput. Free the page directory and the mm. | 593 | * mmput. Free the page directory and the mm. |
594 | */ | 594 | */ |
595 | static void __mmdrop(struct mm_struct *mm) | 595 | void __mmdrop(struct mm_struct *mm) |
596 | { | 596 | { |
597 | BUG_ON(mm == &init_mm); | 597 | BUG_ON(mm == &init_mm); |
598 | mm_free_pgd(mm); | 598 | mm_free_pgd(mm); |
@@ -603,18 +603,7 @@ static void __mmdrop(struct mm_struct *mm) | |||
603 | put_user_ns(mm->user_ns); | 603 | put_user_ns(mm->user_ns); |
604 | free_mm(mm); | 604 | free_mm(mm); |
605 | } | 605 | } |
606 | 606 | EXPORT_SYMBOL_GPL(__mmdrop); | |
607 | void mmdrop(struct mm_struct *mm) | ||
608 | { | ||
609 | /* | ||
610 | * The implicit full barrier implied by atomic_dec_and_test() is | ||
611 | * required by the membarrier system call before returning to | ||
612 | * user-space, after storing to rq->curr. | ||
613 | */ | ||
614 | if (unlikely(atomic_dec_and_test(&mm->mm_count))) | ||
615 | __mmdrop(mm); | ||
616 | } | ||
617 | EXPORT_SYMBOL_GPL(mmdrop); | ||
618 | 607 | ||
619 | static void mmdrop_async_fn(struct work_struct *work) | 608 | static void mmdrop_async_fn(struct work_struct *work) |
620 | { | 609 | { |
diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c index 5187dfe809ac..4c5770407031 100644 --- a/kernel/irq/matrix.c +++ b/kernel/irq/matrix.c | |||
@@ -16,6 +16,7 @@ struct cpumap { | |||
16 | unsigned int available; | 16 | unsigned int available; |
17 | unsigned int allocated; | 17 | unsigned int allocated; |
18 | unsigned int managed; | 18 | unsigned int managed; |
19 | bool initialized; | ||
19 | bool online; | 20 | bool online; |
20 | unsigned long alloc_map[IRQ_MATRIX_SIZE]; | 21 | unsigned long alloc_map[IRQ_MATRIX_SIZE]; |
21 | unsigned long managed_map[IRQ_MATRIX_SIZE]; | 22 | unsigned long managed_map[IRQ_MATRIX_SIZE]; |
@@ -81,9 +82,11 @@ void irq_matrix_online(struct irq_matrix *m) | |||
81 | 82 | ||
82 | BUG_ON(cm->online); | 83 | BUG_ON(cm->online); |
83 | 84 | ||
84 | bitmap_zero(cm->alloc_map, m->matrix_bits); | 85 | if (!cm->initialized) { |
85 | cm->available = m->alloc_size - (cm->managed + m->systembits_inalloc); | 86 | cm->available = m->alloc_size; |
86 | cm->allocated = 0; | 87 | cm->available -= cm->managed + m->systembits_inalloc; |
88 | cm->initialized = true; | ||
89 | } | ||
87 | m->global_available += cm->available; | 90 | m->global_available += cm->available; |
88 | cm->online = true; | 91 | cm->online = true; |
89 | m->online_maps++; | 92 | m->online_maps++; |
@@ -370,14 +373,16 @@ void irq_matrix_free(struct irq_matrix *m, unsigned int cpu, | |||
370 | if (WARN_ON_ONCE(bit < m->alloc_start || bit >= m->alloc_end)) | 373 | if (WARN_ON_ONCE(bit < m->alloc_start || bit >= m->alloc_end)) |
371 | return; | 374 | return; |
372 | 375 | ||
373 | if (cm->online) { | 376 | clear_bit(bit, cm->alloc_map); |
374 | clear_bit(bit, cm->alloc_map); | 377 | cm->allocated--; |
375 | cm->allocated--; | 378 | |
379 | if (cm->online) | ||
376 | m->total_allocated--; | 380 | m->total_allocated--; |
377 | if (!managed) { | 381 | |
378 | cm->available++; | 382 | if (!managed) { |
383 | cm->available++; | ||
384 | if (cm->online) | ||
379 | m->global_available++; | 385 | m->global_available++; |
380 | } | ||
381 | } | 386 | } |
382 | trace_irq_matrix_free(bit, cpu, m, cm); | 387 | trace_irq_matrix_free(bit, cpu, m, cm); |
383 | } | 388 | } |
diff --git a/kernel/jump_label.c b/kernel/jump_label.c index b4517095db6a..e7214093dcd1 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c | |||
@@ -366,12 +366,16 @@ static void __jump_label_update(struct static_key *key, | |||
366 | { | 366 | { |
367 | for (; (entry < stop) && (jump_entry_key(entry) == key); entry++) { | 367 | for (; (entry < stop) && (jump_entry_key(entry) == key); entry++) { |
368 | /* | 368 | /* |
369 | * entry->code set to 0 invalidates module init text sections | 369 | * An entry->code of 0 indicates an entry which has been |
370 | * kernel_text_address() verifies we are not in core kernel | 370 | * disabled because it was in an init text area. |
371 | * init code, see jump_label_invalidate_module_init(). | ||
372 | */ | 371 | */ |
373 | if (entry->code && kernel_text_address(entry->code)) | 372 | if (entry->code) { |
374 | arch_jump_label_transform(entry, jump_label_type(entry)); | 373 | if (kernel_text_address(entry->code)) |
374 | arch_jump_label_transform(entry, jump_label_type(entry)); | ||
375 | else | ||
376 | WARN_ONCE(1, "can't patch jump_label at %pS", | ||
377 | (void *)(unsigned long)entry->code); | ||
378 | } | ||
375 | } | 379 | } |
376 | } | 380 | } |
377 | 381 | ||
@@ -417,6 +421,19 @@ void __init jump_label_init(void) | |||
417 | cpus_read_unlock(); | 421 | cpus_read_unlock(); |
418 | } | 422 | } |
419 | 423 | ||
424 | /* Disable any jump label entries in __init code */ | ||
425 | void __init jump_label_invalidate_init(void) | ||
426 | { | ||
427 | struct jump_entry *iter_start = __start___jump_table; | ||
428 | struct jump_entry *iter_stop = __stop___jump_table; | ||
429 | struct jump_entry *iter; | ||
430 | |||
431 | for (iter = iter_start; iter < iter_stop; iter++) { | ||
432 | if (init_kernel_text(iter->code)) | ||
433 | iter->code = 0; | ||
434 | } | ||
435 | } | ||
436 | |||
420 | #ifdef CONFIG_MODULES | 437 | #ifdef CONFIG_MODULES |
421 | 438 | ||
422 | static enum jump_label_type jump_label_init_type(struct jump_entry *entry) | 439 | static enum jump_label_type jump_label_init_type(struct jump_entry *entry) |
@@ -633,6 +650,7 @@ static void jump_label_del_module(struct module *mod) | |||
633 | } | 650 | } |
634 | } | 651 | } |
635 | 652 | ||
653 | /* Disable any jump label entries in module init code */ | ||
636 | static void jump_label_invalidate_module_init(struct module *mod) | 654 | static void jump_label_invalidate_module_init(struct module *mod) |
637 | { | 655 | { |
638 | struct jump_entry *iter_start = mod->jump_entries; | 656 | struct jump_entry *iter_start = mod->jump_entries; |
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 65cc0cb984e6..940633c63254 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c | |||
@@ -1616,11 +1616,12 @@ bool __sched __rt_mutex_futex_unlock(struct rt_mutex *lock, | |||
1616 | void __sched rt_mutex_futex_unlock(struct rt_mutex *lock) | 1616 | void __sched rt_mutex_futex_unlock(struct rt_mutex *lock) |
1617 | { | 1617 | { |
1618 | DEFINE_WAKE_Q(wake_q); | 1618 | DEFINE_WAKE_Q(wake_q); |
1619 | unsigned long flags; | ||
1619 | bool postunlock; | 1620 | bool postunlock; |
1620 | 1621 | ||
1621 | raw_spin_lock_irq(&lock->wait_lock); | 1622 | raw_spin_lock_irqsave(&lock->wait_lock, flags); |
1622 | postunlock = __rt_mutex_futex_unlock(lock, &wake_q); | 1623 | postunlock = __rt_mutex_futex_unlock(lock, &wake_q); |
1623 | raw_spin_unlock_irq(&lock->wait_lock); | 1624 | raw_spin_unlock_irqrestore(&lock->wait_lock, flags); |
1624 | 1625 | ||
1625 | if (postunlock) | 1626 | if (postunlock) |
1626 | rt_mutex_postunlock(&wake_q); | 1627 | rt_mutex_postunlock(&wake_q); |
diff --git a/kernel/memremap.c b/kernel/memremap.c index 4849be5f9b3c..4dd4274cabe2 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c | |||
@@ -275,8 +275,15 @@ static unsigned long pfn_end(struct dev_pagemap *pgmap) | |||
275 | return (res->start + resource_size(res)) >> PAGE_SHIFT; | 275 | return (res->start + resource_size(res)) >> PAGE_SHIFT; |
276 | } | 276 | } |
277 | 277 | ||
278 | static unsigned long pfn_next(unsigned long pfn) | ||
279 | { | ||
280 | if (pfn % 1024 == 0) | ||
281 | cond_resched(); | ||
282 | return pfn + 1; | ||
283 | } | ||
284 | |||
278 | #define for_each_device_pfn(pfn, map) \ | 285 | #define for_each_device_pfn(pfn, map) \ |
279 | for (pfn = pfn_first(map); pfn < pfn_end(map); pfn++) | 286 | for (pfn = pfn_first(map); pfn < pfn_end(map); pfn = pfn_next(pfn)) |
280 | 287 | ||
281 | static void devm_memremap_pages_release(void *data) | 288 | static void devm_memremap_pages_release(void *data) |
282 | { | 289 | { |
@@ -337,10 +344,10 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) | |||
337 | resource_size_t align_start, align_size, align_end; | 344 | resource_size_t align_start, align_size, align_end; |
338 | struct vmem_altmap *altmap = pgmap->altmap_valid ? | 345 | struct vmem_altmap *altmap = pgmap->altmap_valid ? |
339 | &pgmap->altmap : NULL; | 346 | &pgmap->altmap : NULL; |
347 | struct resource *res = &pgmap->res; | ||
340 | unsigned long pfn, pgoff, order; | 348 | unsigned long pfn, pgoff, order; |
341 | pgprot_t pgprot = PAGE_KERNEL; | 349 | pgprot_t pgprot = PAGE_KERNEL; |
342 | int error, nid, is_ram, i = 0; | 350 | int error, nid, is_ram; |
343 | struct resource *res = &pgmap->res; | ||
344 | 351 | ||
345 | align_start = res->start & ~(SECTION_SIZE - 1); | 352 | align_start = res->start & ~(SECTION_SIZE - 1); |
346 | align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE) | 353 | align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE) |
@@ -409,8 +416,6 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) | |||
409 | list_del(&page->lru); | 416 | list_del(&page->lru); |
410 | page->pgmap = pgmap; | 417 | page->pgmap = pgmap; |
411 | percpu_ref_get(pgmap->ref); | 418 | percpu_ref_get(pgmap->ref); |
412 | if (!(++i % 1024)) | ||
413 | cond_resched(); | ||
414 | } | 419 | } |
415 | 420 | ||
416 | devm_add_action(dev, devm_memremap_pages_release, pgmap); | 421 | devm_add_action(dev, devm_memremap_pages_release, pgmap); |
diff --git a/kernel/panic.c b/kernel/panic.c index 2cfef408fec9..4b794f1d8561 100644 --- a/kernel/panic.c +++ b/kernel/panic.c | |||
@@ -640,7 +640,7 @@ device_initcall(register_warn_debugfs); | |||
640 | */ | 640 | */ |
641 | __visible void __stack_chk_fail(void) | 641 | __visible void __stack_chk_fail(void) |
642 | { | 642 | { |
643 | panic("stack-protector: Kernel stack is corrupted in: %p\n", | 643 | panic("stack-protector: Kernel stack is corrupted in: %pB\n", |
644 | __builtin_return_address(0)); | 644 | __builtin_return_address(0)); |
645 | } | 645 | } |
646 | EXPORT_SYMBOL(__stack_chk_fail); | 646 | EXPORT_SYMBOL(__stack_chk_fail); |
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index fc1123583fa6..f274fbef821d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c | |||
@@ -2397,7 +2397,7 @@ skip: | |||
2397 | 2397 | ||
2398 | if (console_lock_spinning_disable_and_check()) { | 2398 | if (console_lock_spinning_disable_and_check()) { |
2399 | printk_safe_exit_irqrestore(flags); | 2399 | printk_safe_exit_irqrestore(flags); |
2400 | return; | 2400 | goto out; |
2401 | } | 2401 | } |
2402 | 2402 | ||
2403 | printk_safe_exit_irqrestore(flags); | 2403 | printk_safe_exit_irqrestore(flags); |
@@ -2430,6 +2430,7 @@ skip: | |||
2430 | if (retry && console_trylock()) | 2430 | if (retry && console_trylock()) |
2431 | goto again; | 2431 | goto again; |
2432 | 2432 | ||
2433 | out: | ||
2433 | if (wake_klogd) | 2434 | if (wake_klogd) |
2434 | wake_up_klogd(); | 2435 | wake_up_klogd(); |
2435 | } | 2436 | } |
diff --git a/kernel/relay.c b/kernel/relay.c index c3029402f15c..c955b10c973c 100644 --- a/kernel/relay.c +++ b/kernel/relay.c | |||
@@ -163,7 +163,7 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan) | |||
163 | { | 163 | { |
164 | struct rchan_buf *buf; | 164 | struct rchan_buf *buf; |
165 | 165 | ||
166 | if (chan->n_subbufs > UINT_MAX / sizeof(size_t *)) | 166 | if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t *)) |
167 | return NULL; | 167 | return NULL; |
168 | 168 | ||
169 | buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL); | 169 | buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL); |
diff --git a/kernel/seccomp.c b/kernel/seccomp.c index 940fa408a288..dc77548167ef 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c | |||
@@ -1076,14 +1076,16 @@ long seccomp_get_metadata(struct task_struct *task, | |||
1076 | 1076 | ||
1077 | size = min_t(unsigned long, size, sizeof(kmd)); | 1077 | size = min_t(unsigned long, size, sizeof(kmd)); |
1078 | 1078 | ||
1079 | if (copy_from_user(&kmd, data, size)) | 1079 | if (size < sizeof(kmd.filter_off)) |
1080 | return -EINVAL; | ||
1081 | |||
1082 | if (copy_from_user(&kmd.filter_off, data, sizeof(kmd.filter_off))) | ||
1080 | return -EFAULT; | 1083 | return -EFAULT; |
1081 | 1084 | ||
1082 | filter = get_nth_filter(task, kmd.filter_off); | 1085 | filter = get_nth_filter(task, kmd.filter_off); |
1083 | if (IS_ERR(filter)) | 1086 | if (IS_ERR(filter)) |
1084 | return PTR_ERR(filter); | 1087 | return PTR_ERR(filter); |
1085 | 1088 | ||
1086 | memset(&kmd, 0, sizeof(kmd)); | ||
1087 | if (filter->log) | 1089 | if (filter->log) |
1088 | kmd.flags |= SECCOMP_FILTER_FLAG_LOG; | 1090 | kmd.flags |= SECCOMP_FILTER_FLAG_LOG; |
1089 | 1091 | ||
diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 48150ab42de9..4a4fd567fb26 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c | |||
@@ -1894,6 +1894,12 @@ int timers_dead_cpu(unsigned int cpu) | |||
1894 | raw_spin_lock_irq(&new_base->lock); | 1894 | raw_spin_lock_irq(&new_base->lock); |
1895 | raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); | 1895 | raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); |
1896 | 1896 | ||
1897 | /* | ||
1898 | * The current CPUs base clock might be stale. Update it | ||
1899 | * before moving the timers over. | ||
1900 | */ | ||
1901 | forward_timer_base(new_base); | ||
1902 | |||
1897 | BUG_ON(old_base->running_timer); | 1903 | BUG_ON(old_base->running_timer); |
1898 | 1904 | ||
1899 | for (i = 0; i < WHEEL_SIZE; i++) | 1905 | for (i = 0; i < WHEEL_SIZE; i++) |
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index fc2838ac8b78..c0a9e310d715 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c | |||
@@ -872,6 +872,8 @@ int perf_event_query_prog_array(struct perf_event *event, void __user *info) | |||
872 | return -EINVAL; | 872 | return -EINVAL; |
873 | if (copy_from_user(&query, uquery, sizeof(query))) | 873 | if (copy_from_user(&query, uquery, sizeof(query))) |
874 | return -EFAULT; | 874 | return -EFAULT; |
875 | if (query.ids_len > BPF_TRACE_MAX_PROGS) | ||
876 | return -E2BIG; | ||
875 | 877 | ||
876 | mutex_lock(&bpf_event_mutex); | 878 | mutex_lock(&bpf_event_mutex); |
877 | ret = bpf_prog_array_copy_info(event->tp_event->prog_array, | 879 | ret = bpf_prog_array_copy_info(event->tp_event->prog_array, |
diff --git a/kernel/user.c b/kernel/user.c index 9a20acce460d..36288d840675 100644 --- a/kernel/user.c +++ b/kernel/user.c | |||
@@ -101,6 +101,7 @@ struct user_struct root_user = { | |||
101 | .sigpending = ATOMIC_INIT(0), | 101 | .sigpending = ATOMIC_INIT(0), |
102 | .locked_shm = 0, | 102 | .locked_shm = 0, |
103 | .uid = GLOBAL_ROOT_UID, | 103 | .uid = GLOBAL_ROOT_UID, |
104 | .ratelimit = RATELIMIT_STATE_INIT(root_user.ratelimit, 0, 0), | ||
104 | }; | 105 | }; |
105 | 106 | ||
106 | /* | 107 | /* |
@@ -191,6 +192,8 @@ struct user_struct *alloc_uid(kuid_t uid) | |||
191 | 192 | ||
192 | new->uid = uid; | 193 | new->uid = uid; |
193 | atomic_set(&new->__count, 1); | 194 | atomic_set(&new->__count, 1); |
195 | ratelimit_state_init(&new->ratelimit, HZ, 100); | ||
196 | ratelimit_set_flags(&new->ratelimit, RATELIMIT_MSG_ON_RELEASE); | ||
194 | 197 | ||
195 | /* | 198 | /* |
196 | * Before adding this, check whether we raced | 199 | * Before adding this, check whether we raced |
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 017044c26233..bb9a519cbf50 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -4180,6 +4180,22 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active) | |||
4180 | EXPORT_SYMBOL_GPL(workqueue_set_max_active); | 4180 | EXPORT_SYMBOL_GPL(workqueue_set_max_active); |
4181 | 4181 | ||
4182 | /** | 4182 | /** |
4183 | * current_work - retrieve %current task's work struct | ||
4184 | * | ||
4185 | * Determine if %current task is a workqueue worker and what it's working on. | ||
4186 | * Useful to find out the context that the %current task is running in. | ||
4187 | * | ||
4188 | * Return: work struct if %current task is a workqueue worker, %NULL otherwise. | ||
4189 | */ | ||
4190 | struct work_struct *current_work(void) | ||
4191 | { | ||
4192 | struct worker *worker = current_wq_worker(); | ||
4193 | |||
4194 | return worker ? worker->current_work : NULL; | ||
4195 | } | ||
4196 | EXPORT_SYMBOL(current_work); | ||
4197 | |||
4198 | /** | ||
4183 | * current_is_workqueue_rescuer - is %current workqueue rescuer? | 4199 | * current_is_workqueue_rescuer - is %current workqueue rescuer? |
4184 | * | 4200 | * |
4185 | * Determine whether %current is a workqueue rescuer. Can be used from | 4201 | * Determine whether %current is a workqueue rescuer. Can be used from |