Annotation of /trunk/kernel-alx/patches-4.4/0113-4.4.14-all-fixes.patch
Parent Directory | Revision Log
Revision 2822 -
(hide annotations)
(download)
Tue Sep 13 07:17:48 2016 UTC (8 years, 1 month ago) by niro
File size: 158644 byte(s)
Tue Sep 13 07:17:48 2016 UTC (8 years, 1 month ago) by niro
File size: 158644 byte(s)
-linux-4.4.14
1 | niro | 2822 | diff --git a/Makefile b/Makefile |
2 | index f4b33cdf991a..fadbb9d73c6d 100644 | ||
3 | --- a/Makefile | ||
4 | +++ b/Makefile | ||
5 | @@ -1,6 +1,6 @@ | ||
6 | VERSION = 4 | ||
7 | PATCHLEVEL = 4 | ||
8 | -SUBLEVEL = 13 | ||
9 | +SUBLEVEL = 14 | ||
10 | EXTRAVERSION = | ||
11 | NAME = Blurry Fish Butt | ||
12 | |||
13 | diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c | ||
14 | index ef9119f7462e..4d9375814b53 100644 | ||
15 | --- a/arch/arm/kernel/ptrace.c | ||
16 | +++ b/arch/arm/kernel/ptrace.c | ||
17 | @@ -733,8 +733,8 @@ static int vfp_set(struct task_struct *target, | ||
18 | if (ret) | ||
19 | return ret; | ||
20 | |||
21 | - vfp_flush_hwstate(thread); | ||
22 | thread->vfpstate.hard = new_vfp; | ||
23 | + vfp_flush_hwstate(thread); | ||
24 | |||
25 | return 0; | ||
26 | } | ||
27 | diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h | ||
28 | index faad6df49e5b..bc6492b9a924 100644 | ||
29 | --- a/arch/arm64/include/asm/elf.h | ||
30 | +++ b/arch/arm64/include/asm/elf.h | ||
31 | @@ -156,14 +156,14 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm, | ||
32 | #define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12)) | ||
33 | #endif | ||
34 | |||
35 | -#ifdef CONFIG_COMPAT | ||
36 | - | ||
37 | #ifdef __AARCH64EB__ | ||
38 | #define COMPAT_ELF_PLATFORM ("v8b") | ||
39 | #else | ||
40 | #define COMPAT_ELF_PLATFORM ("v8l") | ||
41 | #endif | ||
42 | |||
43 | +#ifdef CONFIG_COMPAT | ||
44 | + | ||
45 | #define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3) | ||
46 | |||
47 | /* AArch32 registers. */ | ||
48 | diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c | ||
49 | index a5f234039616..0166cfbc866c 100644 | ||
50 | --- a/arch/arm64/kernel/cpuinfo.c | ||
51 | +++ b/arch/arm64/kernel/cpuinfo.c | ||
52 | @@ -22,6 +22,8 @@ | ||
53 | |||
54 | #include <linux/bitops.h> | ||
55 | #include <linux/bug.h> | ||
56 | +#include <linux/compat.h> | ||
57 | +#include <linux/elf.h> | ||
58 | #include <linux/init.h> | ||
59 | #include <linux/kernel.h> | ||
60 | #include <linux/personality.h> | ||
61 | @@ -102,6 +104,7 @@ static const char *const compat_hwcap2_str[] = { | ||
62 | static int c_show(struct seq_file *m, void *v) | ||
63 | { | ||
64 | int i, j; | ||
65 | + bool compat = personality(current->personality) == PER_LINUX32; | ||
66 | |||
67 | for_each_online_cpu(i) { | ||
68 | struct cpuinfo_arm64 *cpuinfo = &per_cpu(cpu_data, i); | ||
69 | @@ -113,6 +116,9 @@ static int c_show(struct seq_file *m, void *v) | ||
70 | * "processor". Give glibc what it expects. | ||
71 | */ | ||
72 | seq_printf(m, "processor\t: %d\n", i); | ||
73 | + if (compat) | ||
74 | + seq_printf(m, "model name\t: ARMv8 Processor rev %d (%s)\n", | ||
75 | + MIDR_REVISION(midr), COMPAT_ELF_PLATFORM); | ||
76 | |||
77 | seq_printf(m, "BogoMIPS\t: %lu.%02lu\n", | ||
78 | loops_per_jiffy / (500000UL/HZ), | ||
79 | @@ -125,7 +131,7 @@ static int c_show(struct seq_file *m, void *v) | ||
80 | * software which does already (at least for 32-bit). | ||
81 | */ | ||
82 | seq_puts(m, "Features\t:"); | ||
83 | - if (personality(current->personality) == PER_LINUX32) { | ||
84 | + if (compat) { | ||
85 | #ifdef CONFIG_COMPAT | ||
86 | for (j = 0; compat_hwcap_str[j]; j++) | ||
87 | if (compat_elf_hwcap & (1 << j)) | ||
88 | diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c | ||
89 | index 40f5522245a2..4c1a118c1d09 100644 | ||
90 | --- a/arch/arm64/mm/fault.c | ||
91 | +++ b/arch/arm64/mm/fault.c | ||
92 | @@ -109,7 +109,7 @@ int ptep_set_access_flags(struct vm_area_struct *vma, | ||
93 | * PTE_RDONLY is cleared by default in the asm below, so set it in | ||
94 | * back if necessary (read-only or clean PTE). | ||
95 | */ | ||
96 | - if (!pte_write(entry) || !dirty) | ||
97 | + if (!pte_write(entry) || !pte_sw_dirty(entry)) | ||
98 | pte_val(entry) |= PTE_RDONLY; | ||
99 | |||
100 | /* | ||
101 | diff --git a/arch/mips/include/asm/processor.h b/arch/mips/include/asm/processor.h | ||
102 | index 3f832c3dd8f5..041153f5cf93 100644 | ||
103 | --- a/arch/mips/include/asm/processor.h | ||
104 | +++ b/arch/mips/include/asm/processor.h | ||
105 | @@ -45,7 +45,7 @@ extern unsigned int vced_count, vcei_count; | ||
106 | * User space process size: 2GB. This is hardcoded into a few places, | ||
107 | * so don't change it unless you know what you are doing. | ||
108 | */ | ||
109 | -#define TASK_SIZE 0x7fff8000UL | ||
110 | +#define TASK_SIZE 0x80000000UL | ||
111 | #endif | ||
112 | |||
113 | #define STACK_TOP_MAX TASK_SIZE | ||
114 | diff --git a/arch/parisc/kernel/unaligned.c b/arch/parisc/kernel/unaligned.c | ||
115 | index d7c0acb35ec2..8d49614d600d 100644 | ||
116 | --- a/arch/parisc/kernel/unaligned.c | ||
117 | +++ b/arch/parisc/kernel/unaligned.c | ||
118 | @@ -666,7 +666,7 @@ void handle_unaligned(struct pt_regs *regs) | ||
119 | break; | ||
120 | } | ||
121 | |||
122 | - if (modify && R1(regs->iir)) | ||
123 | + if (ret == 0 && modify && R1(regs->iir)) | ||
124 | regs->gr[R1(regs->iir)] = newbase; | ||
125 | |||
126 | |||
127 | @@ -677,6 +677,14 @@ void handle_unaligned(struct pt_regs *regs) | ||
128 | |||
129 | if (ret) | ||
130 | { | ||
131 | + /* | ||
132 | + * The unaligned handler failed. | ||
133 | + * If we were called by __get_user() or __put_user() jump | ||
134 | + * to it's exception fixup handler instead of crashing. | ||
135 | + */ | ||
136 | + if (!user_mode(regs) && fixup_exception(regs)) | ||
137 | + return; | ||
138 | + | ||
139 | printk(KERN_CRIT "Unaligned handler failed, ret = %d\n", ret); | ||
140 | die_if_kernel("Unaligned data reference", regs, 28); | ||
141 | |||
142 | diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h | ||
143 | index 2220f7a60def..070fa8552051 100644 | ||
144 | --- a/arch/powerpc/include/asm/reg.h | ||
145 | +++ b/arch/powerpc/include/asm/reg.h | ||
146 | @@ -707,7 +707,7 @@ | ||
147 | #define MMCR0_FCWAIT 0x00000002UL /* freeze counter in WAIT state */ | ||
148 | #define MMCR0_FCHV 0x00000001UL /* freeze conditions in hypervisor mode */ | ||
149 | #define SPRN_MMCR1 798 | ||
150 | -#define SPRN_MMCR2 769 | ||
151 | +#define SPRN_MMCR2 785 | ||
152 | #define SPRN_MMCRA 0x312 | ||
153 | #define MMCRA_SDSYNC 0x80000000UL /* SDAR synced with SIAR */ | ||
154 | #define MMCRA_SDAR_DCACHE_MISS 0x40000000UL | ||
155 | @@ -744,13 +744,13 @@ | ||
156 | #define SPRN_PMC6 792 | ||
157 | #define SPRN_PMC7 793 | ||
158 | #define SPRN_PMC8 794 | ||
159 | -#define SPRN_SIAR 780 | ||
160 | -#define SPRN_SDAR 781 | ||
161 | #define SPRN_SIER 784 | ||
162 | #define SIER_SIPR 0x2000000 /* Sampled MSR_PR */ | ||
163 | #define SIER_SIHV 0x1000000 /* Sampled MSR_HV */ | ||
164 | #define SIER_SIAR_VALID 0x0400000 /* SIAR contents valid */ | ||
165 | #define SIER_SDAR_VALID 0x0200000 /* SDAR contents valid */ | ||
166 | +#define SPRN_SIAR 796 | ||
167 | +#define SPRN_SDAR 797 | ||
168 | #define SPRN_TACR 888 | ||
169 | #define SPRN_TCSCR 889 | ||
170 | #define SPRN_CSIGR 890 | ||
171 | diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c | ||
172 | index 92dea8df6b26..e52b82b71d79 100644 | ||
173 | --- a/arch/powerpc/kernel/prom_init.c | ||
174 | +++ b/arch/powerpc/kernel/prom_init.c | ||
175 | @@ -655,6 +655,7 @@ unsigned char ibm_architecture_vec[] = { | ||
176 | W(0xffff0000), W(0x003e0000), /* POWER6 */ | ||
177 | W(0xffff0000), W(0x003f0000), /* POWER7 */ | ||
178 | W(0xffff0000), W(0x004b0000), /* POWER8E */ | ||
179 | + W(0xffff0000), W(0x004c0000), /* POWER8NVL */ | ||
180 | W(0xffff0000), W(0x004d0000), /* POWER8 */ | ||
181 | W(0xffffffff), W(0x0f000004), /* all 2.07-compliant */ | ||
182 | W(0xffffffff), W(0x0f000003), /* all 2.06-compliant */ | ||
183 | diff --git a/arch/powerpc/platforms/pseries/eeh_pseries.c b/arch/powerpc/platforms/pseries/eeh_pseries.c | ||
184 | index ac3ffd97e059..405baaf96864 100644 | ||
185 | --- a/arch/powerpc/platforms/pseries/eeh_pseries.c | ||
186 | +++ b/arch/powerpc/platforms/pseries/eeh_pseries.c | ||
187 | @@ -615,29 +615,50 @@ static int pseries_eeh_configure_bridge(struct eeh_pe *pe) | ||
188 | { | ||
189 | int config_addr; | ||
190 | int ret; | ||
191 | + /* Waiting 0.2s maximum before skipping configuration */ | ||
192 | + int max_wait = 200; | ||
193 | |||
194 | /* Figure out the PE address */ | ||
195 | config_addr = pe->config_addr; | ||
196 | if (pe->addr) | ||
197 | config_addr = pe->addr; | ||
198 | |||
199 | - /* Use new configure-pe function, if supported */ | ||
200 | - if (ibm_configure_pe != RTAS_UNKNOWN_SERVICE) { | ||
201 | - ret = rtas_call(ibm_configure_pe, 3, 1, NULL, | ||
202 | - config_addr, BUID_HI(pe->phb->buid), | ||
203 | - BUID_LO(pe->phb->buid)); | ||
204 | - } else if (ibm_configure_bridge != RTAS_UNKNOWN_SERVICE) { | ||
205 | - ret = rtas_call(ibm_configure_bridge, 3, 1, NULL, | ||
206 | - config_addr, BUID_HI(pe->phb->buid), | ||
207 | - BUID_LO(pe->phb->buid)); | ||
208 | - } else { | ||
209 | - return -EFAULT; | ||
210 | - } | ||
211 | + while (max_wait > 0) { | ||
212 | + /* Use new configure-pe function, if supported */ | ||
213 | + if (ibm_configure_pe != RTAS_UNKNOWN_SERVICE) { | ||
214 | + ret = rtas_call(ibm_configure_pe, 3, 1, NULL, | ||
215 | + config_addr, BUID_HI(pe->phb->buid), | ||
216 | + BUID_LO(pe->phb->buid)); | ||
217 | + } else if (ibm_configure_bridge != RTAS_UNKNOWN_SERVICE) { | ||
218 | + ret = rtas_call(ibm_configure_bridge, 3, 1, NULL, | ||
219 | + config_addr, BUID_HI(pe->phb->buid), | ||
220 | + BUID_LO(pe->phb->buid)); | ||
221 | + } else { | ||
222 | + return -EFAULT; | ||
223 | + } | ||
224 | |||
225 | - if (ret) | ||
226 | - pr_warn("%s: Unable to configure bridge PHB#%d-PE#%x (%d)\n", | ||
227 | - __func__, pe->phb->global_number, pe->addr, ret); | ||
228 | + if (!ret) | ||
229 | + return ret; | ||
230 | + | ||
231 | + /* | ||
232 | + * If RTAS returns a delay value that's above 100ms, cut it | ||
233 | + * down to 100ms in case firmware made a mistake. For more | ||
234 | + * on how these delay values work see rtas_busy_delay_time | ||
235 | + */ | ||
236 | + if (ret > RTAS_EXTENDED_DELAY_MIN+2 && | ||
237 | + ret <= RTAS_EXTENDED_DELAY_MAX) | ||
238 | + ret = RTAS_EXTENDED_DELAY_MIN+2; | ||
239 | + | ||
240 | + max_wait -= rtas_busy_delay_time(ret); | ||
241 | + | ||
242 | + if (max_wait < 0) | ||
243 | + break; | ||
244 | + | ||
245 | + rtas_busy_delay(ret); | ||
246 | + } | ||
247 | |||
248 | + pr_warn("%s: Unable to configure bridge PHB#%d-PE#%x (%d)\n", | ||
249 | + __func__, pe->phb->global_number, pe->addr, ret); | ||
250 | return ret; | ||
251 | } | ||
252 | |||
253 | diff --git a/arch/s390/net/bpf_jit.h b/arch/s390/net/bpf_jit.h | ||
254 | index f010c93a88b1..fda605dbc1b4 100644 | ||
255 | --- a/arch/s390/net/bpf_jit.h | ||
256 | +++ b/arch/s390/net/bpf_jit.h | ||
257 | @@ -37,7 +37,7 @@ extern u8 sk_load_word[], sk_load_half[], sk_load_byte[]; | ||
258 | * | | | | ||
259 | * +---------------+ | | ||
260 | * | 8 byte skbp | | | ||
261 | - * R15+170 -> +---------------+ | | ||
262 | + * R15+176 -> +---------------+ | | ||
263 | * | 8 byte hlen | | | ||
264 | * R15+168 -> +---------------+ | | ||
265 | * | 4 byte align | | | ||
266 | @@ -58,7 +58,7 @@ extern u8 sk_load_word[], sk_load_half[], sk_load_byte[]; | ||
267 | #define STK_OFF (STK_SPACE - STK_160_UNUSED) | ||
268 | #define STK_OFF_TMP 160 /* Offset of tmp buffer on stack */ | ||
269 | #define STK_OFF_HLEN 168 /* Offset of SKB header length on stack */ | ||
270 | -#define STK_OFF_SKBP 170 /* Offset of SKB pointer on stack */ | ||
271 | +#define STK_OFF_SKBP 176 /* Offset of SKB pointer on stack */ | ||
272 | |||
273 | #define STK_OFF_R6 (160 - 11 * 8) /* Offset of r6 on stack */ | ||
274 | #define STK_OFF_TCCNT (160 - 12 * 8) /* Offset of tail_call_cnt on stack */ | ||
275 | diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c | ||
276 | index 9a0c4c22e536..0e2919dd8df3 100644 | ||
277 | --- a/arch/s390/net/bpf_jit_comp.c | ||
278 | +++ b/arch/s390/net/bpf_jit_comp.c | ||
279 | @@ -45,7 +45,7 @@ struct bpf_jit { | ||
280 | int labels[1]; /* Labels for local jumps */ | ||
281 | }; | ||
282 | |||
283 | -#define BPF_SIZE_MAX 0x7ffff /* Max size for program (20 bit signed displ) */ | ||
284 | +#define BPF_SIZE_MAX 0xffff /* Max size for program (16 bit branches) */ | ||
285 | |||
286 | #define SEEN_SKB 1 /* skb access */ | ||
287 | #define SEEN_MEM 2 /* use mem[] for temporary storage */ | ||
288 | @@ -446,7 +446,7 @@ static void bpf_jit_prologue(struct bpf_jit *jit, bool is_classic) | ||
289 | emit_load_skb_data_hlen(jit); | ||
290 | if (jit->seen & SEEN_SKB_CHANGE) | ||
291 | /* stg %b1,ST_OFF_SKBP(%r0,%r15) */ | ||
292 | - EMIT6_DISP_LH(0xe3000000, 0x0024, REG_W1, REG_0, REG_15, | ||
293 | + EMIT6_DISP_LH(0xe3000000, 0x0024, BPF_REG_1, REG_0, REG_15, | ||
294 | STK_OFF_SKBP); | ||
295 | /* Clear A (%b0) and X (%b7) registers for converted BPF programs */ | ||
296 | if (is_classic) { | ||
297 | diff --git a/arch/sparc/include/asm/head_64.h b/arch/sparc/include/asm/head_64.h | ||
298 | index 10e9dabc4c41..f0700cfeedd7 100644 | ||
299 | --- a/arch/sparc/include/asm/head_64.h | ||
300 | +++ b/arch/sparc/include/asm/head_64.h | ||
301 | @@ -15,6 +15,10 @@ | ||
302 | |||
303 | #define PTREGS_OFF (STACK_BIAS + STACKFRAME_SZ) | ||
304 | |||
305 | +#define RTRAP_PSTATE (PSTATE_TSO|PSTATE_PEF|PSTATE_PRIV|PSTATE_IE) | ||
306 | +#define RTRAP_PSTATE_IRQOFF (PSTATE_TSO|PSTATE_PEF|PSTATE_PRIV) | ||
307 | +#define RTRAP_PSTATE_AG_IRQOFF (PSTATE_TSO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG) | ||
308 | + | ||
309 | #define __CHEETAH_ID 0x003e0014 | ||
310 | #define __JALAPENO_ID 0x003e0016 | ||
311 | #define __SERRANO_ID 0x003e0022 | ||
312 | diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h | ||
313 | index 131d36fcd07a..408b715c95a5 100644 | ||
314 | --- a/arch/sparc/include/asm/pgtable_64.h | ||
315 | +++ b/arch/sparc/include/asm/pgtable_64.h | ||
316 | @@ -375,7 +375,7 @@ static inline pgprot_t pgprot_noncached(pgprot_t prot) | ||
317 | #define pgprot_noncached pgprot_noncached | ||
318 | |||
319 | #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE) | ||
320 | -static inline pte_t pte_mkhuge(pte_t pte) | ||
321 | +static inline unsigned long __pte_huge_mask(void) | ||
322 | { | ||
323 | unsigned long mask; | ||
324 | |||
325 | @@ -390,8 +390,19 @@ static inline pte_t pte_mkhuge(pte_t pte) | ||
326 | : "=r" (mask) | ||
327 | : "i" (_PAGE_SZHUGE_4U), "i" (_PAGE_SZHUGE_4V)); | ||
328 | |||
329 | - return __pte(pte_val(pte) | mask); | ||
330 | + return mask; | ||
331 | +} | ||
332 | + | ||
333 | +static inline pte_t pte_mkhuge(pte_t pte) | ||
334 | +{ | ||
335 | + return __pte(pte_val(pte) | __pte_huge_mask()); | ||
336 | +} | ||
337 | + | ||
338 | +static inline bool is_hugetlb_pte(pte_t pte) | ||
339 | +{ | ||
340 | + return !!(pte_val(pte) & __pte_huge_mask()); | ||
341 | } | ||
342 | + | ||
343 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE | ||
344 | static inline pmd_t pmd_mkhuge(pmd_t pmd) | ||
345 | { | ||
346 | @@ -403,6 +414,11 @@ static inline pmd_t pmd_mkhuge(pmd_t pmd) | ||
347 | return __pmd(pte_val(pte)); | ||
348 | } | ||
349 | #endif | ||
350 | +#else | ||
351 | +static inline bool is_hugetlb_pte(pte_t pte) | ||
352 | +{ | ||
353 | + return false; | ||
354 | +} | ||
355 | #endif | ||
356 | |||
357 | static inline pte_t pte_mkdirty(pte_t pte) | ||
358 | @@ -865,6 +881,19 @@ static inline unsigned long pud_pfn(pud_t pud) | ||
359 | void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, | ||
360 | pte_t *ptep, pte_t orig, int fullmm); | ||
361 | |||
362 | +static void maybe_tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, | ||
363 | + pte_t *ptep, pte_t orig, int fullmm) | ||
364 | +{ | ||
365 | + /* It is more efficient to let flush_tlb_kernel_range() | ||
366 | + * handle init_mm tlb flushes. | ||
367 | + * | ||
368 | + * SUN4V NOTE: _PAGE_VALID is the same value in both the SUN4U | ||
369 | + * and SUN4V pte layout, so this inline test is fine. | ||
370 | + */ | ||
371 | + if (likely(mm != &init_mm) && pte_accessible(mm, orig)) | ||
372 | + tlb_batch_add(mm, vaddr, ptep, orig, fullmm); | ||
373 | +} | ||
374 | + | ||
375 | #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR | ||
376 | static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, | ||
377 | unsigned long addr, | ||
378 | @@ -881,15 +910,7 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, | ||
379 | pte_t orig = *ptep; | ||
380 | |||
381 | *ptep = pte; | ||
382 | - | ||
383 | - /* It is more efficient to let flush_tlb_kernel_range() | ||
384 | - * handle init_mm tlb flushes. | ||
385 | - * | ||
386 | - * SUN4V NOTE: _PAGE_VALID is the same value in both the SUN4U | ||
387 | - * and SUN4V pte layout, so this inline test is fine. | ||
388 | - */ | ||
389 | - if (likely(mm != &init_mm) && pte_accessible(mm, orig)) | ||
390 | - tlb_batch_add(mm, addr, ptep, orig, fullmm); | ||
391 | + maybe_tlb_batch_add(mm, addr, ptep, orig, fullmm); | ||
392 | } | ||
393 | |||
394 | #define set_pte_at(mm,addr,ptep,pte) \ | ||
395 | diff --git a/arch/sparc/include/asm/tlbflush_64.h b/arch/sparc/include/asm/tlbflush_64.h | ||
396 | index dea1cfa2122b..a8e192e90700 100644 | ||
397 | --- a/arch/sparc/include/asm/tlbflush_64.h | ||
398 | +++ b/arch/sparc/include/asm/tlbflush_64.h | ||
399 | @@ -8,6 +8,7 @@ | ||
400 | #define TLB_BATCH_NR 192 | ||
401 | |||
402 | struct tlb_batch { | ||
403 | + bool huge; | ||
404 | struct mm_struct *mm; | ||
405 | unsigned long tlb_nr; | ||
406 | unsigned long active; | ||
407 | @@ -16,7 +17,7 @@ struct tlb_batch { | ||
408 | |||
409 | void flush_tsb_kernel_range(unsigned long start, unsigned long end); | ||
410 | void flush_tsb_user(struct tlb_batch *tb); | ||
411 | -void flush_tsb_user_page(struct mm_struct *mm, unsigned long vaddr); | ||
412 | +void flush_tsb_user_page(struct mm_struct *mm, unsigned long vaddr, bool huge); | ||
413 | |||
414 | /* TLB flush operations. */ | ||
415 | |||
416 | diff --git a/arch/sparc/include/asm/ttable.h b/arch/sparc/include/asm/ttable.h | ||
417 | index 71b5a67522ab..781b9f1dbdc2 100644 | ||
418 | --- a/arch/sparc/include/asm/ttable.h | ||
419 | +++ b/arch/sparc/include/asm/ttable.h | ||
420 | @@ -589,8 +589,8 @@ user_rtt_fill_64bit: \ | ||
421 | restored; \ | ||
422 | nop; nop; nop; nop; nop; nop; \ | ||
423 | nop; nop; nop; nop; nop; \ | ||
424 | - ba,a,pt %xcc, user_rtt_fill_fixup; \ | ||
425 | - ba,a,pt %xcc, user_rtt_fill_fixup; \ | ||
426 | + ba,a,pt %xcc, user_rtt_fill_fixup_dax; \ | ||
427 | + ba,a,pt %xcc, user_rtt_fill_fixup_mna; \ | ||
428 | ba,a,pt %xcc, user_rtt_fill_fixup; | ||
429 | |||
430 | |||
431 | @@ -652,8 +652,8 @@ user_rtt_fill_32bit: \ | ||
432 | restored; \ | ||
433 | nop; nop; nop; nop; nop; \ | ||
434 | nop; nop; nop; \ | ||
435 | - ba,a,pt %xcc, user_rtt_fill_fixup; \ | ||
436 | - ba,a,pt %xcc, user_rtt_fill_fixup; \ | ||
437 | + ba,a,pt %xcc, user_rtt_fill_fixup_dax; \ | ||
438 | + ba,a,pt %xcc, user_rtt_fill_fixup_mna; \ | ||
439 | ba,a,pt %xcc, user_rtt_fill_fixup; | ||
440 | |||
441 | |||
442 | diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile | ||
443 | index 7cf9c6ea3f1f..fdb13327fded 100644 | ||
444 | --- a/arch/sparc/kernel/Makefile | ||
445 | +++ b/arch/sparc/kernel/Makefile | ||
446 | @@ -21,6 +21,7 @@ CFLAGS_REMOVE_perf_event.o := -pg | ||
447 | CFLAGS_REMOVE_pcr.o := -pg | ||
448 | endif | ||
449 | |||
450 | +obj-$(CONFIG_SPARC64) += urtt_fill.o | ||
451 | obj-$(CONFIG_SPARC32) += entry.o wof.o wuf.o | ||
452 | obj-$(CONFIG_SPARC32) += etrap_32.o | ||
453 | obj-$(CONFIG_SPARC32) += rtrap_32.o | ||
454 | diff --git a/arch/sparc/kernel/cherrs.S b/arch/sparc/kernel/cherrs.S | ||
455 | index 4ee1ad420862..655628def68e 100644 | ||
456 | --- a/arch/sparc/kernel/cherrs.S | ||
457 | +++ b/arch/sparc/kernel/cherrs.S | ||
458 | @@ -214,8 +214,7 @@ do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */ | ||
459 | subcc %g1, %g2, %g1 ! Next cacheline | ||
460 | bge,pt %icc, 1b | ||
461 | nop | ||
462 | - ba,pt %xcc, dcpe_icpe_tl1_common | ||
463 | - nop | ||
464 | + ba,a,pt %xcc, dcpe_icpe_tl1_common | ||
465 | |||
466 | do_dcpe_tl1_fatal: | ||
467 | sethi %hi(1f), %g7 | ||
468 | @@ -224,8 +223,7 @@ do_dcpe_tl1_fatal: | ||
469 | mov 0x2, %o0 | ||
470 | call cheetah_plus_parity_error | ||
471 | add %sp, PTREGS_OFF, %o1 | ||
472 | - ba,pt %xcc, rtrap | ||
473 | - nop | ||
474 | + ba,a,pt %xcc, rtrap | ||
475 | .size do_dcpe_tl1,.-do_dcpe_tl1 | ||
476 | |||
477 | .globl do_icpe_tl1 | ||
478 | @@ -259,8 +257,7 @@ do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */ | ||
479 | subcc %g1, %g2, %g1 | ||
480 | bge,pt %icc, 1b | ||
481 | nop | ||
482 | - ba,pt %xcc, dcpe_icpe_tl1_common | ||
483 | - nop | ||
484 | + ba,a,pt %xcc, dcpe_icpe_tl1_common | ||
485 | |||
486 | do_icpe_tl1_fatal: | ||
487 | sethi %hi(1f), %g7 | ||
488 | @@ -269,8 +266,7 @@ do_icpe_tl1_fatal: | ||
489 | mov 0x3, %o0 | ||
490 | call cheetah_plus_parity_error | ||
491 | add %sp, PTREGS_OFF, %o1 | ||
492 | - ba,pt %xcc, rtrap | ||
493 | - nop | ||
494 | + ba,a,pt %xcc, rtrap | ||
495 | .size do_icpe_tl1,.-do_icpe_tl1 | ||
496 | |||
497 | .type dcpe_icpe_tl1_common,#function | ||
498 | @@ -456,7 +452,7 @@ __cheetah_log_error: | ||
499 | cmp %g2, 0x63 | ||
500 | be c_cee | ||
501 | nop | ||
502 | - ba,pt %xcc, c_deferred | ||
503 | + ba,a,pt %xcc, c_deferred | ||
504 | .size __cheetah_log_error,.-__cheetah_log_error | ||
505 | |||
506 | /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc | ||
507 | diff --git a/arch/sparc/kernel/entry.S b/arch/sparc/kernel/entry.S | ||
508 | index 33c02b15f478..a83707c83be8 100644 | ||
509 | --- a/arch/sparc/kernel/entry.S | ||
510 | +++ b/arch/sparc/kernel/entry.S | ||
511 | @@ -948,7 +948,24 @@ linux_syscall_trace: | ||
512 | cmp %o0, 0 | ||
513 | bne 3f | ||
514 | mov -ENOSYS, %o0 | ||
515 | + | ||
516 | + /* Syscall tracing can modify the registers. */ | ||
517 | + ld [%sp + STACKFRAME_SZ + PT_G1], %g1 | ||
518 | + sethi %hi(sys_call_table), %l7 | ||
519 | + ld [%sp + STACKFRAME_SZ + PT_I0], %i0 | ||
520 | + or %l7, %lo(sys_call_table), %l7 | ||
521 | + ld [%sp + STACKFRAME_SZ + PT_I1], %i1 | ||
522 | + ld [%sp + STACKFRAME_SZ + PT_I2], %i2 | ||
523 | + ld [%sp + STACKFRAME_SZ + PT_I3], %i3 | ||
524 | + ld [%sp + STACKFRAME_SZ + PT_I4], %i4 | ||
525 | + ld [%sp + STACKFRAME_SZ + PT_I5], %i5 | ||
526 | + cmp %g1, NR_syscalls | ||
527 | + bgeu 3f | ||
528 | + mov -ENOSYS, %o0 | ||
529 | + | ||
530 | + sll %g1, 2, %l4 | ||
531 | mov %i0, %o0 | ||
532 | + ld [%l7 + %l4], %l7 | ||
533 | mov %i1, %o1 | ||
534 | mov %i2, %o2 | ||
535 | mov %i3, %o3 | ||
536 | diff --git a/arch/sparc/kernel/fpu_traps.S b/arch/sparc/kernel/fpu_traps.S | ||
537 | index a6864826a4bd..336d2750fe78 100644 | ||
538 | --- a/arch/sparc/kernel/fpu_traps.S | ||
539 | +++ b/arch/sparc/kernel/fpu_traps.S | ||
540 | @@ -100,8 +100,8 @@ do_fpdis: | ||
541 | fmuld %f0, %f2, %f26 | ||
542 | faddd %f0, %f2, %f28 | ||
543 | fmuld %f0, %f2, %f30 | ||
544 | - b,pt %xcc, fpdis_exit | ||
545 | - nop | ||
546 | + ba,a,pt %xcc, fpdis_exit | ||
547 | + | ||
548 | 2: andcc %g5, FPRS_DU, %g0 | ||
549 | bne,pt %icc, 3f | ||
550 | fzero %f32 | ||
551 | @@ -144,8 +144,8 @@ do_fpdis: | ||
552 | fmuld %f32, %f34, %f58 | ||
553 | faddd %f32, %f34, %f60 | ||
554 | fmuld %f32, %f34, %f62 | ||
555 | - ba,pt %xcc, fpdis_exit | ||
556 | - nop | ||
557 | + ba,a,pt %xcc, fpdis_exit | ||
558 | + | ||
559 | 3: mov SECONDARY_CONTEXT, %g3 | ||
560 | add %g6, TI_FPREGS, %g1 | ||
561 | |||
562 | @@ -197,8 +197,7 @@ fpdis_exit2: | ||
563 | fp_other_bounce: | ||
564 | call do_fpother | ||
565 | add %sp, PTREGS_OFF, %o0 | ||
566 | - ba,pt %xcc, rtrap | ||
567 | - nop | ||
568 | + ba,a,pt %xcc, rtrap | ||
569 | .size fp_other_bounce,.-fp_other_bounce | ||
570 | |||
571 | .align 32 | ||
572 | diff --git a/arch/sparc/kernel/head_64.S b/arch/sparc/kernel/head_64.S | ||
573 | index f2d30cab5b3f..51faf92ace00 100644 | ||
574 | --- a/arch/sparc/kernel/head_64.S | ||
575 | +++ b/arch/sparc/kernel/head_64.S | ||
576 | @@ -461,9 +461,8 @@ sun4v_chip_type: | ||
577 | subcc %g3, 1, %g3 | ||
578 | bne,pt %xcc, 41b | ||
579 | add %g1, 1, %g1 | ||
580 | - mov SUN4V_CHIP_SPARC64X, %g4 | ||
581 | ba,pt %xcc, 5f | ||
582 | - nop | ||
583 | + mov SUN4V_CHIP_SPARC64X, %g4 | ||
584 | |||
585 | 49: | ||
586 | mov SUN4V_CHIP_UNKNOWN, %g4 | ||
587 | @@ -548,8 +547,7 @@ sun4u_init: | ||
588 | stxa %g0, [%g7] ASI_DMMU | ||
589 | membar #Sync | ||
590 | |||
591 | - ba,pt %xcc, sun4u_continue | ||
592 | - nop | ||
593 | + ba,a,pt %xcc, sun4u_continue | ||
594 | |||
595 | sun4v_init: | ||
596 | /* Set ctx 0 */ | ||
597 | @@ -560,14 +558,12 @@ sun4v_init: | ||
598 | mov SECONDARY_CONTEXT, %g7 | ||
599 | stxa %g0, [%g7] ASI_MMU | ||
600 | membar #Sync | ||
601 | - ba,pt %xcc, niagara_tlb_fixup | ||
602 | - nop | ||
603 | + ba,a,pt %xcc, niagara_tlb_fixup | ||
604 | |||
605 | sun4u_continue: | ||
606 | BRANCH_IF_ANY_CHEETAH(g1, g7, cheetah_tlb_fixup) | ||
607 | |||
608 | - ba,pt %xcc, spitfire_tlb_fixup | ||
609 | - nop | ||
610 | + ba,a,pt %xcc, spitfire_tlb_fixup | ||
611 | |||
612 | niagara_tlb_fixup: | ||
613 | mov 3, %g2 /* Set TLB type to hypervisor. */ | ||
614 | @@ -639,8 +635,7 @@ niagara_patch: | ||
615 | call hypervisor_patch_cachetlbops | ||
616 | nop | ||
617 | |||
618 | - ba,pt %xcc, tlb_fixup_done | ||
619 | - nop | ||
620 | + ba,a,pt %xcc, tlb_fixup_done | ||
621 | |||
622 | cheetah_tlb_fixup: | ||
623 | mov 2, %g2 /* Set TLB type to cheetah+. */ | ||
624 | @@ -659,8 +654,7 @@ cheetah_tlb_fixup: | ||
625 | call cheetah_patch_cachetlbops | ||
626 | nop | ||
627 | |||
628 | - ba,pt %xcc, tlb_fixup_done | ||
629 | - nop | ||
630 | + ba,a,pt %xcc, tlb_fixup_done | ||
631 | |||
632 | spitfire_tlb_fixup: | ||
633 | /* Set TLB type to spitfire. */ | ||
634 | @@ -782,8 +776,7 @@ setup_trap_table: | ||
635 | call %o1 | ||
636 | add %sp, (2047 + 128), %o0 | ||
637 | |||
638 | - ba,pt %xcc, 2f | ||
639 | - nop | ||
640 | + ba,a,pt %xcc, 2f | ||
641 | |||
642 | 1: sethi %hi(sparc64_ttable_tl0), %o0 | ||
643 | set prom_set_trap_table_name, %g2 | ||
644 | @@ -822,8 +815,7 @@ setup_trap_table: | ||
645 | |||
646 | BRANCH_IF_ANY_CHEETAH(o2, o3, 1f) | ||
647 | |||
648 | - ba,pt %xcc, 2f | ||
649 | - nop | ||
650 | + ba,a,pt %xcc, 2f | ||
651 | |||
652 | /* Disable STICK_INT interrupts. */ | ||
653 | 1: | ||
654 | diff --git a/arch/sparc/kernel/misctrap.S b/arch/sparc/kernel/misctrap.S | ||
655 | index 753b4f031bfb..34b4933900bf 100644 | ||
656 | --- a/arch/sparc/kernel/misctrap.S | ||
657 | +++ b/arch/sparc/kernel/misctrap.S | ||
658 | @@ -18,8 +18,7 @@ __do_privact: | ||
659 | 109: or %g7, %lo(109b), %g7 | ||
660 | call do_privact | ||
661 | add %sp, PTREGS_OFF, %o0 | ||
662 | - ba,pt %xcc, rtrap | ||
663 | - nop | ||
664 | + ba,a,pt %xcc, rtrap | ||
665 | .size __do_privact,.-__do_privact | ||
666 | |||
667 | .type do_mna,#function | ||
668 | @@ -46,8 +45,7 @@ do_mna: | ||
669 | mov %l5, %o2 | ||
670 | call mem_address_unaligned | ||
671 | add %sp, PTREGS_OFF, %o0 | ||
672 | - ba,pt %xcc, rtrap | ||
673 | - nop | ||
674 | + ba,a,pt %xcc, rtrap | ||
675 | .size do_mna,.-do_mna | ||
676 | |||
677 | .type do_lddfmna,#function | ||
678 | @@ -65,8 +63,7 @@ do_lddfmna: | ||
679 | mov %l5, %o2 | ||
680 | call handle_lddfmna | ||
681 | add %sp, PTREGS_OFF, %o0 | ||
682 | - ba,pt %xcc, rtrap | ||
683 | - nop | ||
684 | + ba,a,pt %xcc, rtrap | ||
685 | .size do_lddfmna,.-do_lddfmna | ||
686 | |||
687 | .type do_stdfmna,#function | ||
688 | @@ -84,8 +81,7 @@ do_stdfmna: | ||
689 | mov %l5, %o2 | ||
690 | call handle_stdfmna | ||
691 | add %sp, PTREGS_OFF, %o0 | ||
692 | - ba,pt %xcc, rtrap | ||
693 | - nop | ||
694 | + ba,a,pt %xcc, rtrap | ||
695 | .size do_stdfmna,.-do_stdfmna | ||
696 | |||
697 | .type breakpoint_trap,#function | ||
698 | diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c | ||
699 | index badf0951d73c..9f9614df9e1e 100644 | ||
700 | --- a/arch/sparc/kernel/pci.c | ||
701 | +++ b/arch/sparc/kernel/pci.c | ||
702 | @@ -994,6 +994,23 @@ void pcibios_set_master(struct pci_dev *dev) | ||
703 | /* No special bus mastering setup handling */ | ||
704 | } | ||
705 | |||
706 | +#ifdef CONFIG_PCI_IOV | ||
707 | +int pcibios_add_device(struct pci_dev *dev) | ||
708 | +{ | ||
709 | + struct pci_dev *pdev; | ||
710 | + | ||
711 | + /* Add sriov arch specific initialization here. | ||
712 | + * Copy dev_archdata from PF to VF | ||
713 | + */ | ||
714 | + if (dev->is_virtfn) { | ||
715 | + pdev = dev->physfn; | ||
716 | + memcpy(&dev->dev.archdata, &pdev->dev.archdata, | ||
717 | + sizeof(struct dev_archdata)); | ||
718 | + } | ||
719 | + return 0; | ||
720 | +} | ||
721 | +#endif /* CONFIG_PCI_IOV */ | ||
722 | + | ||
723 | static int __init pcibios_init(void) | ||
724 | { | ||
725 | pci_dfl_cache_line_size = 64 >> 2; | ||
726 | diff --git a/arch/sparc/kernel/rtrap_64.S b/arch/sparc/kernel/rtrap_64.S | ||
727 | index d08bdaffdbfc..216948ca4382 100644 | ||
728 | --- a/arch/sparc/kernel/rtrap_64.S | ||
729 | +++ b/arch/sparc/kernel/rtrap_64.S | ||
730 | @@ -14,10 +14,6 @@ | ||
731 | #include <asm/visasm.h> | ||
732 | #include <asm/processor.h> | ||
733 | |||
734 | -#define RTRAP_PSTATE (PSTATE_TSO|PSTATE_PEF|PSTATE_PRIV|PSTATE_IE) | ||
735 | -#define RTRAP_PSTATE_IRQOFF (PSTATE_TSO|PSTATE_PEF|PSTATE_PRIV) | ||
736 | -#define RTRAP_PSTATE_AG_IRQOFF (PSTATE_TSO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG) | ||
737 | - | ||
738 | #ifdef CONFIG_CONTEXT_TRACKING | ||
739 | # define SCHEDULE_USER schedule_user | ||
740 | #else | ||
741 | @@ -242,52 +238,17 @@ rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1 | ||
742 | wrpr %g1, %cwp | ||
743 | ba,a,pt %xcc, user_rtt_fill_64bit | ||
744 | |||
745 | -user_rtt_fill_fixup: | ||
746 | - rdpr %cwp, %g1 | ||
747 | - add %g1, 1, %g1 | ||
748 | - wrpr %g1, 0x0, %cwp | ||
749 | - | ||
750 | - rdpr %wstate, %g2 | ||
751 | - sll %g2, 3, %g2 | ||
752 | - wrpr %g2, 0x0, %wstate | ||
753 | - | ||
754 | - /* We know %canrestore and %otherwin are both zero. */ | ||
755 | - | ||
756 | - sethi %hi(sparc64_kern_pri_context), %g2 | ||
757 | - ldx [%g2 + %lo(sparc64_kern_pri_context)], %g2 | ||
758 | - mov PRIMARY_CONTEXT, %g1 | ||
759 | - | ||
760 | -661: stxa %g2, [%g1] ASI_DMMU | ||
761 | - .section .sun4v_1insn_patch, "ax" | ||
762 | - .word 661b | ||
763 | - stxa %g2, [%g1] ASI_MMU | ||
764 | - .previous | ||
765 | - | ||
766 | - sethi %hi(KERNBASE), %g1 | ||
767 | - flush %g1 | ||
768 | +user_rtt_fill_fixup_dax: | ||
769 | + ba,pt %xcc, user_rtt_fill_fixup_common | ||
770 | + mov 1, %g3 | ||
771 | |||
772 | - or %g4, FAULT_CODE_WINFIXUP, %g4 | ||
773 | - stb %g4, [%g6 + TI_FAULT_CODE] | ||
774 | - stx %g5, [%g6 + TI_FAULT_ADDR] | ||
775 | +user_rtt_fill_fixup_mna: | ||
776 | + ba,pt %xcc, user_rtt_fill_fixup_common | ||
777 | + mov 2, %g3 | ||
778 | |||
779 | - mov %g6, %l1 | ||
780 | - wrpr %g0, 0x0, %tl | ||
781 | - | ||
782 | -661: nop | ||
783 | - .section .sun4v_1insn_patch, "ax" | ||
784 | - .word 661b | ||
785 | - SET_GL(0) | ||
786 | - .previous | ||
787 | - | ||
788 | - wrpr %g0, RTRAP_PSTATE, %pstate | ||
789 | - | ||
790 | - mov %l1, %g6 | ||
791 | - ldx [%g6 + TI_TASK], %g4 | ||
792 | - LOAD_PER_CPU_BASE(%g5, %g6, %g1, %g2, %g3) | ||
793 | - call do_sparc64_fault | ||
794 | - add %sp, PTREGS_OFF, %o0 | ||
795 | - ba,pt %xcc, rtrap | ||
796 | - nop | ||
797 | +user_rtt_fill_fixup: | ||
798 | + ba,pt %xcc, user_rtt_fill_fixup_common | ||
799 | + clr %g3 | ||
800 | |||
801 | user_rtt_pre_restore: | ||
802 | add %g1, 1, %g1 | ||
803 | diff --git a/arch/sparc/kernel/signal32.c b/arch/sparc/kernel/signal32.c | ||
804 | index 4eed773a7735..77655f0f0fc7 100644 | ||
805 | --- a/arch/sparc/kernel/signal32.c | ||
806 | +++ b/arch/sparc/kernel/signal32.c | ||
807 | @@ -138,12 +138,24 @@ int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from) | ||
808 | return 0; | ||
809 | } | ||
810 | |||
811 | +/* Checks if the fp is valid. We always build signal frames which are | ||
812 | + * 16-byte aligned, therefore we can always enforce that the restore | ||
813 | + * frame has that property as well. | ||
814 | + */ | ||
815 | +static bool invalid_frame_pointer(void __user *fp, int fplen) | ||
816 | +{ | ||
817 | + if ((((unsigned long) fp) & 15) || | ||
818 | + ((unsigned long)fp) > 0x100000000ULL - fplen) | ||
819 | + return true; | ||
820 | + return false; | ||
821 | +} | ||
822 | + | ||
823 | void do_sigreturn32(struct pt_regs *regs) | ||
824 | { | ||
825 | struct signal_frame32 __user *sf; | ||
826 | compat_uptr_t fpu_save; | ||
827 | compat_uptr_t rwin_save; | ||
828 | - unsigned int psr; | ||
829 | + unsigned int psr, ufp; | ||
830 | unsigned pc, npc; | ||
831 | sigset_t set; | ||
832 | compat_sigset_t seta; | ||
833 | @@ -158,11 +170,16 @@ void do_sigreturn32(struct pt_regs *regs) | ||
834 | sf = (struct signal_frame32 __user *) regs->u_regs[UREG_FP]; | ||
835 | |||
836 | /* 1. Make sure we are not getting garbage from the user */ | ||
837 | - if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) || | ||
838 | - (((unsigned long) sf) & 3)) | ||
839 | + if (invalid_frame_pointer(sf, sizeof(*sf))) | ||
840 | + goto segv; | ||
841 | + | ||
842 | + if (get_user(ufp, &sf->info.si_regs.u_regs[UREG_FP])) | ||
843 | + goto segv; | ||
844 | + | ||
845 | + if (ufp & 0x7) | ||
846 | goto segv; | ||
847 | |||
848 | - if (get_user(pc, &sf->info.si_regs.pc) || | ||
849 | + if (__get_user(pc, &sf->info.si_regs.pc) || | ||
850 | __get_user(npc, &sf->info.si_regs.npc)) | ||
851 | goto segv; | ||
852 | |||
853 | @@ -227,7 +244,7 @@ segv: | ||
854 | asmlinkage void do_rt_sigreturn32(struct pt_regs *regs) | ||
855 | { | ||
856 | struct rt_signal_frame32 __user *sf; | ||
857 | - unsigned int psr, pc, npc; | ||
858 | + unsigned int psr, pc, npc, ufp; | ||
859 | compat_uptr_t fpu_save; | ||
860 | compat_uptr_t rwin_save; | ||
861 | sigset_t set; | ||
862 | @@ -242,11 +259,16 @@ asmlinkage void do_rt_sigreturn32(struct pt_regs *regs) | ||
863 | sf = (struct rt_signal_frame32 __user *) regs->u_regs[UREG_FP]; | ||
864 | |||
865 | /* 1. Make sure we are not getting garbage from the user */ | ||
866 | - if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) || | ||
867 | - (((unsigned long) sf) & 3)) | ||
868 | + if (invalid_frame_pointer(sf, sizeof(*sf))) | ||
869 | goto segv; | ||
870 | |||
871 | - if (get_user(pc, &sf->regs.pc) || | ||
872 | + if (get_user(ufp, &sf->regs.u_regs[UREG_FP])) | ||
873 | + goto segv; | ||
874 | + | ||
875 | + if (ufp & 0x7) | ||
876 | + goto segv; | ||
877 | + | ||
878 | + if (__get_user(pc, &sf->regs.pc) || | ||
879 | __get_user(npc, &sf->regs.npc)) | ||
880 | goto segv; | ||
881 | |||
882 | @@ -307,14 +329,6 @@ segv: | ||
883 | force_sig(SIGSEGV, current); | ||
884 | } | ||
885 | |||
886 | -/* Checks if the fp is valid */ | ||
887 | -static int invalid_frame_pointer(void __user *fp, int fplen) | ||
888 | -{ | ||
889 | - if ((((unsigned long) fp) & 7) || ((unsigned long)fp) > 0x100000000ULL - fplen) | ||
890 | - return 1; | ||
891 | - return 0; | ||
892 | -} | ||
893 | - | ||
894 | static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs, unsigned long framesize) | ||
895 | { | ||
896 | unsigned long sp; | ||
897 | diff --git a/arch/sparc/kernel/signal_32.c b/arch/sparc/kernel/signal_32.c | ||
898 | index 52aa5e4ce5e7..c3c12efe0bc0 100644 | ||
899 | --- a/arch/sparc/kernel/signal_32.c | ||
900 | +++ b/arch/sparc/kernel/signal_32.c | ||
901 | @@ -60,10 +60,22 @@ struct rt_signal_frame { | ||
902 | #define SF_ALIGNEDSZ (((sizeof(struct signal_frame) + 7) & (~7))) | ||
903 | #define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame) + 7) & (~7))) | ||
904 | |||
905 | +/* Checks if the fp is valid. We always build signal frames which are | ||
906 | + * 16-byte aligned, therefore we can always enforce that the restore | ||
907 | + * frame has that property as well. | ||
908 | + */ | ||
909 | +static inline bool invalid_frame_pointer(void __user *fp, int fplen) | ||
910 | +{ | ||
911 | + if ((((unsigned long) fp) & 15) || !__access_ok((unsigned long)fp, fplen)) | ||
912 | + return true; | ||
913 | + | ||
914 | + return false; | ||
915 | +} | ||
916 | + | ||
917 | asmlinkage void do_sigreturn(struct pt_regs *regs) | ||
918 | { | ||
919 | + unsigned long up_psr, pc, npc, ufp; | ||
920 | struct signal_frame __user *sf; | ||
921 | - unsigned long up_psr, pc, npc; | ||
922 | sigset_t set; | ||
923 | __siginfo_fpu_t __user *fpu_save; | ||
924 | __siginfo_rwin_t __user *rwin_save; | ||
925 | @@ -77,10 +89,13 @@ asmlinkage void do_sigreturn(struct pt_regs *regs) | ||
926 | sf = (struct signal_frame __user *) regs->u_regs[UREG_FP]; | ||
927 | |||
928 | /* 1. Make sure we are not getting garbage from the user */ | ||
929 | - if (!access_ok(VERIFY_READ, sf, sizeof(*sf))) | ||
930 | + if (!invalid_frame_pointer(sf, sizeof(*sf))) | ||
931 | + goto segv_and_exit; | ||
932 | + | ||
933 | + if (get_user(ufp, &sf->info.si_regs.u_regs[UREG_FP])) | ||
934 | goto segv_and_exit; | ||
935 | |||
936 | - if (((unsigned long) sf) & 3) | ||
937 | + if (ufp & 0x7) | ||
938 | goto segv_and_exit; | ||
939 | |||
940 | err = __get_user(pc, &sf->info.si_regs.pc); | ||
941 | @@ -127,7 +142,7 @@ segv_and_exit: | ||
942 | asmlinkage void do_rt_sigreturn(struct pt_regs *regs) | ||
943 | { | ||
944 | struct rt_signal_frame __user *sf; | ||
945 | - unsigned int psr, pc, npc; | ||
946 | + unsigned int psr, pc, npc, ufp; | ||
947 | __siginfo_fpu_t __user *fpu_save; | ||
948 | __siginfo_rwin_t __user *rwin_save; | ||
949 | sigset_t set; | ||
950 | @@ -135,8 +150,13 @@ asmlinkage void do_rt_sigreturn(struct pt_regs *regs) | ||
951 | |||
952 | synchronize_user_stack(); | ||
953 | sf = (struct rt_signal_frame __user *) regs->u_regs[UREG_FP]; | ||
954 | - if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) || | ||
955 | - (((unsigned long) sf) & 0x03)) | ||
956 | + if (!invalid_frame_pointer(sf, sizeof(*sf))) | ||
957 | + goto segv; | ||
958 | + | ||
959 | + if (get_user(ufp, &sf->regs.u_regs[UREG_FP])) | ||
960 | + goto segv; | ||
961 | + | ||
962 | + if (ufp & 0x7) | ||
963 | goto segv; | ||
964 | |||
965 | err = __get_user(pc, &sf->regs.pc); | ||
966 | @@ -178,15 +198,6 @@ segv: | ||
967 | force_sig(SIGSEGV, current); | ||
968 | } | ||
969 | |||
970 | -/* Checks if the fp is valid */ | ||
971 | -static inline int invalid_frame_pointer(void __user *fp, int fplen) | ||
972 | -{ | ||
973 | - if ((((unsigned long) fp) & 7) || !__access_ok((unsigned long)fp, fplen)) | ||
974 | - return 1; | ||
975 | - | ||
976 | - return 0; | ||
977 | -} | ||
978 | - | ||
979 | static inline void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs, unsigned long framesize) | ||
980 | { | ||
981 | unsigned long sp = regs->u_regs[UREG_FP]; | ||
982 | diff --git a/arch/sparc/kernel/signal_64.c b/arch/sparc/kernel/signal_64.c | ||
983 | index d88beff47bab..5ee930c48f4c 100644 | ||
984 | --- a/arch/sparc/kernel/signal_64.c | ||
985 | +++ b/arch/sparc/kernel/signal_64.c | ||
986 | @@ -52,7 +52,7 @@ asmlinkage void sparc64_set_context(struct pt_regs *regs) | ||
987 | unsigned char fenab; | ||
988 | int err; | ||
989 | |||
990 | - flush_user_windows(); | ||
991 | + synchronize_user_stack(); | ||
992 | if (get_thread_wsaved() || | ||
993 | (((unsigned long)ucp) & (sizeof(unsigned long)-1)) || | ||
994 | (!__access_ok(ucp, sizeof(*ucp)))) | ||
995 | @@ -234,6 +234,17 @@ do_sigsegv: | ||
996 | goto out; | ||
997 | } | ||
998 | |||
999 | +/* Checks if the fp is valid. We always build rt signal frames which | ||
1000 | + * are 16-byte aligned, therefore we can always enforce that the | ||
1001 | + * restore frame has that property as well. | ||
1002 | + */ | ||
1003 | +static bool invalid_frame_pointer(void __user *fp) | ||
1004 | +{ | ||
1005 | + if (((unsigned long) fp) & 15) | ||
1006 | + return true; | ||
1007 | + return false; | ||
1008 | +} | ||
1009 | + | ||
1010 | struct rt_signal_frame { | ||
1011 | struct sparc_stackf ss; | ||
1012 | siginfo_t info; | ||
1013 | @@ -246,8 +257,8 @@ struct rt_signal_frame { | ||
1014 | |||
1015 | void do_rt_sigreturn(struct pt_regs *regs) | ||
1016 | { | ||
1017 | + unsigned long tpc, tnpc, tstate, ufp; | ||
1018 | struct rt_signal_frame __user *sf; | ||
1019 | - unsigned long tpc, tnpc, tstate; | ||
1020 | __siginfo_fpu_t __user *fpu_save; | ||
1021 | __siginfo_rwin_t __user *rwin_save; | ||
1022 | sigset_t set; | ||
1023 | @@ -261,10 +272,16 @@ void do_rt_sigreturn(struct pt_regs *regs) | ||
1024 | (regs->u_regs [UREG_FP] + STACK_BIAS); | ||
1025 | |||
1026 | /* 1. Make sure we are not getting garbage from the user */ | ||
1027 | - if (((unsigned long) sf) & 3) | ||
1028 | + if (invalid_frame_pointer(sf)) | ||
1029 | + goto segv; | ||
1030 | + | ||
1031 | + if (get_user(ufp, &sf->regs.u_regs[UREG_FP])) | ||
1032 | goto segv; | ||
1033 | |||
1034 | - err = get_user(tpc, &sf->regs.tpc); | ||
1035 | + if ((ufp + STACK_BIAS) & 0x7) | ||
1036 | + goto segv; | ||
1037 | + | ||
1038 | + err = __get_user(tpc, &sf->regs.tpc); | ||
1039 | err |= __get_user(tnpc, &sf->regs.tnpc); | ||
1040 | if (test_thread_flag(TIF_32BIT)) { | ||
1041 | tpc &= 0xffffffff; | ||
1042 | @@ -308,14 +325,6 @@ segv: | ||
1043 | force_sig(SIGSEGV, current); | ||
1044 | } | ||
1045 | |||
1046 | -/* Checks if the fp is valid */ | ||
1047 | -static int invalid_frame_pointer(void __user *fp) | ||
1048 | -{ | ||
1049 | - if (((unsigned long) fp) & 15) | ||
1050 | - return 1; | ||
1051 | - return 0; | ||
1052 | -} | ||
1053 | - | ||
1054 | static inline void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs, unsigned long framesize) | ||
1055 | { | ||
1056 | unsigned long sp = regs->u_regs[UREG_FP] + STACK_BIAS; | ||
1057 | diff --git a/arch/sparc/kernel/sigutil_32.c b/arch/sparc/kernel/sigutil_32.c | ||
1058 | index 0f6eebe71e6c..e5fe8cef9a69 100644 | ||
1059 | --- a/arch/sparc/kernel/sigutil_32.c | ||
1060 | +++ b/arch/sparc/kernel/sigutil_32.c | ||
1061 | @@ -48,6 +48,10 @@ int save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu) | ||
1062 | int restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu) | ||
1063 | { | ||
1064 | int err; | ||
1065 | + | ||
1066 | + if (((unsigned long) fpu) & 3) | ||
1067 | + return -EFAULT; | ||
1068 | + | ||
1069 | #ifdef CONFIG_SMP | ||
1070 | if (test_tsk_thread_flag(current, TIF_USEDFPU)) | ||
1071 | regs->psr &= ~PSR_EF; | ||
1072 | @@ -97,7 +101,10 @@ int restore_rwin_state(__siginfo_rwin_t __user *rp) | ||
1073 | struct thread_info *t = current_thread_info(); | ||
1074 | int i, wsaved, err; | ||
1075 | |||
1076 | - __get_user(wsaved, &rp->wsaved); | ||
1077 | + if (((unsigned long) rp) & 3) | ||
1078 | + return -EFAULT; | ||
1079 | + | ||
1080 | + get_user(wsaved, &rp->wsaved); | ||
1081 | if (wsaved > NSWINS) | ||
1082 | return -EFAULT; | ||
1083 | |||
1084 | diff --git a/arch/sparc/kernel/sigutil_64.c b/arch/sparc/kernel/sigutil_64.c | ||
1085 | index 387834a9c56a..36aadcbeac69 100644 | ||
1086 | --- a/arch/sparc/kernel/sigutil_64.c | ||
1087 | +++ b/arch/sparc/kernel/sigutil_64.c | ||
1088 | @@ -37,7 +37,10 @@ int restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu) | ||
1089 | unsigned long fprs; | ||
1090 | int err; | ||
1091 | |||
1092 | - err = __get_user(fprs, &fpu->si_fprs); | ||
1093 | + if (((unsigned long) fpu) & 7) | ||
1094 | + return -EFAULT; | ||
1095 | + | ||
1096 | + err = get_user(fprs, &fpu->si_fprs); | ||
1097 | fprs_write(0); | ||
1098 | regs->tstate &= ~TSTATE_PEF; | ||
1099 | if (fprs & FPRS_DL) | ||
1100 | @@ -72,7 +75,10 @@ int restore_rwin_state(__siginfo_rwin_t __user *rp) | ||
1101 | struct thread_info *t = current_thread_info(); | ||
1102 | int i, wsaved, err; | ||
1103 | |||
1104 | - __get_user(wsaved, &rp->wsaved); | ||
1105 | + if (((unsigned long) rp) & 7) | ||
1106 | + return -EFAULT; | ||
1107 | + | ||
1108 | + get_user(wsaved, &rp->wsaved); | ||
1109 | if (wsaved > NSWINS) | ||
1110 | return -EFAULT; | ||
1111 | |||
1112 | diff --git a/arch/sparc/kernel/spiterrs.S b/arch/sparc/kernel/spiterrs.S | ||
1113 | index c357e40ffd01..4a73009f66a5 100644 | ||
1114 | --- a/arch/sparc/kernel/spiterrs.S | ||
1115 | +++ b/arch/sparc/kernel/spiterrs.S | ||
1116 | @@ -85,8 +85,7 @@ __spitfire_cee_trap_continue: | ||
1117 | ba,pt %xcc, etraptl1 | ||
1118 | rd %pc, %g7 | ||
1119 | |||
1120 | - ba,pt %xcc, 2f | ||
1121 | - nop | ||
1122 | + ba,a,pt %xcc, 2f | ||
1123 | |||
1124 | 1: ba,pt %xcc, etrap_irq | ||
1125 | rd %pc, %g7 | ||
1126 | @@ -100,8 +99,7 @@ __spitfire_cee_trap_continue: | ||
1127 | mov %l5, %o2 | ||
1128 | call spitfire_access_error | ||
1129 | add %sp, PTREGS_OFF, %o0 | ||
1130 | - ba,pt %xcc, rtrap | ||
1131 | - nop | ||
1132 | + ba,a,pt %xcc, rtrap | ||
1133 | .size __spitfire_access_error,.-__spitfire_access_error | ||
1134 | |||
1135 | /* This is the trap handler entry point for ECC correctable | ||
1136 | @@ -179,8 +177,7 @@ __spitfire_data_access_exception_tl1: | ||
1137 | mov %l5, %o2 | ||
1138 | call spitfire_data_access_exception_tl1 | ||
1139 | add %sp, PTREGS_OFF, %o0 | ||
1140 | - ba,pt %xcc, rtrap | ||
1141 | - nop | ||
1142 | + ba,a,pt %xcc, rtrap | ||
1143 | .size __spitfire_data_access_exception_tl1,.-__spitfire_data_access_exception_tl1 | ||
1144 | |||
1145 | .type __spitfire_data_access_exception,#function | ||
1146 | @@ -200,8 +197,7 @@ __spitfire_data_access_exception: | ||
1147 | mov %l5, %o2 | ||
1148 | call spitfire_data_access_exception | ||
1149 | add %sp, PTREGS_OFF, %o0 | ||
1150 | - ba,pt %xcc, rtrap | ||
1151 | - nop | ||
1152 | + ba,a,pt %xcc, rtrap | ||
1153 | .size __spitfire_data_access_exception,.-__spitfire_data_access_exception | ||
1154 | |||
1155 | .type __spitfire_insn_access_exception_tl1,#function | ||
1156 | @@ -220,8 +216,7 @@ __spitfire_insn_access_exception_tl1: | ||
1157 | mov %l5, %o2 | ||
1158 | call spitfire_insn_access_exception_tl1 | ||
1159 | add %sp, PTREGS_OFF, %o0 | ||
1160 | - ba,pt %xcc, rtrap | ||
1161 | - nop | ||
1162 | + ba,a,pt %xcc, rtrap | ||
1163 | .size __spitfire_insn_access_exception_tl1,.-__spitfire_insn_access_exception_tl1 | ||
1164 | |||
1165 | .type __spitfire_insn_access_exception,#function | ||
1166 | @@ -240,6 +235,5 @@ __spitfire_insn_access_exception: | ||
1167 | mov %l5, %o2 | ||
1168 | call spitfire_insn_access_exception | ||
1169 | add %sp, PTREGS_OFF, %o0 | ||
1170 | - ba,pt %xcc, rtrap | ||
1171 | - nop | ||
1172 | + ba,a,pt %xcc, rtrap | ||
1173 | .size __spitfire_insn_access_exception,.-__spitfire_insn_access_exception | ||
1174 | diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S | ||
1175 | index bb0008927598..c4a1b5c40e4e 100644 | ||
1176 | --- a/arch/sparc/kernel/syscalls.S | ||
1177 | +++ b/arch/sparc/kernel/syscalls.S | ||
1178 | @@ -158,7 +158,25 @@ linux_syscall_trace32: | ||
1179 | add %sp, PTREGS_OFF, %o0 | ||
1180 | brnz,pn %o0, 3f | ||
1181 | mov -ENOSYS, %o0 | ||
1182 | + | ||
1183 | + /* Syscall tracing can modify the registers. */ | ||
1184 | + ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1 | ||
1185 | + sethi %hi(sys_call_table32), %l7 | ||
1186 | + ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0 | ||
1187 | + or %l7, %lo(sys_call_table32), %l7 | ||
1188 | + ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1 | ||
1189 | + ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2 | ||
1190 | + ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3 | ||
1191 | + ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4 | ||
1192 | + ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5 | ||
1193 | + | ||
1194 | + cmp %g1, NR_syscalls | ||
1195 | + bgeu,pn %xcc, 3f | ||
1196 | + mov -ENOSYS, %o0 | ||
1197 | + | ||
1198 | + sll %g1, 2, %l4 | ||
1199 | srl %i0, 0, %o0 | ||
1200 | + lduw [%l7 + %l4], %l7 | ||
1201 | srl %i4, 0, %o4 | ||
1202 | srl %i1, 0, %o1 | ||
1203 | srl %i2, 0, %o2 | ||
1204 | @@ -170,7 +188,25 @@ linux_syscall_trace: | ||
1205 | add %sp, PTREGS_OFF, %o0 | ||
1206 | brnz,pn %o0, 3f | ||
1207 | mov -ENOSYS, %o0 | ||
1208 | + | ||
1209 | + /* Syscall tracing can modify the registers. */ | ||
1210 | + ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1 | ||
1211 | + sethi %hi(sys_call_table64), %l7 | ||
1212 | + ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0 | ||
1213 | + or %l7, %lo(sys_call_table64), %l7 | ||
1214 | + ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1 | ||
1215 | + ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2 | ||
1216 | + ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3 | ||
1217 | + ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4 | ||
1218 | + ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5 | ||
1219 | + | ||
1220 | + cmp %g1, NR_syscalls | ||
1221 | + bgeu,pn %xcc, 3f | ||
1222 | + mov -ENOSYS, %o0 | ||
1223 | + | ||
1224 | + sll %g1, 2, %l4 | ||
1225 | mov %i0, %o0 | ||
1226 | + lduw [%l7 + %l4], %l7 | ||
1227 | mov %i1, %o1 | ||
1228 | mov %i2, %o2 | ||
1229 | mov %i3, %o3 | ||
1230 | diff --git a/arch/sparc/kernel/urtt_fill.S b/arch/sparc/kernel/urtt_fill.S | ||
1231 | new file mode 100644 | ||
1232 | index 000000000000..5604a2b051d4 | ||
1233 | --- /dev/null | ||
1234 | +++ b/arch/sparc/kernel/urtt_fill.S | ||
1235 | @@ -0,0 +1,98 @@ | ||
1236 | +#include <asm/thread_info.h> | ||
1237 | +#include <asm/trap_block.h> | ||
1238 | +#include <asm/spitfire.h> | ||
1239 | +#include <asm/ptrace.h> | ||
1240 | +#include <asm/head.h> | ||
1241 | + | ||
1242 | + .text | ||
1243 | + .align 8 | ||
1244 | + .globl user_rtt_fill_fixup_common | ||
1245 | +user_rtt_fill_fixup_common: | ||
1246 | + rdpr %cwp, %g1 | ||
1247 | + add %g1, 1, %g1 | ||
1248 | + wrpr %g1, 0x0, %cwp | ||
1249 | + | ||
1250 | + rdpr %wstate, %g2 | ||
1251 | + sll %g2, 3, %g2 | ||
1252 | + wrpr %g2, 0x0, %wstate | ||
1253 | + | ||
1254 | + /* We know %canrestore and %otherwin are both zero. */ | ||
1255 | + | ||
1256 | + sethi %hi(sparc64_kern_pri_context), %g2 | ||
1257 | + ldx [%g2 + %lo(sparc64_kern_pri_context)], %g2 | ||
1258 | + mov PRIMARY_CONTEXT, %g1 | ||
1259 | + | ||
1260 | +661: stxa %g2, [%g1] ASI_DMMU | ||
1261 | + .section .sun4v_1insn_patch, "ax" | ||
1262 | + .word 661b | ||
1263 | + stxa %g2, [%g1] ASI_MMU | ||
1264 | + .previous | ||
1265 | + | ||
1266 | + sethi %hi(KERNBASE), %g1 | ||
1267 | + flush %g1 | ||
1268 | + | ||
1269 | + mov %g4, %l4 | ||
1270 | + mov %g5, %l5 | ||
1271 | + brnz,pn %g3, 1f | ||
1272 | + mov %g3, %l3 | ||
1273 | + | ||
1274 | + or %g4, FAULT_CODE_WINFIXUP, %g4 | ||
1275 | + stb %g4, [%g6 + TI_FAULT_CODE] | ||
1276 | + stx %g5, [%g6 + TI_FAULT_ADDR] | ||
1277 | +1: | ||
1278 | + mov %g6, %l1 | ||
1279 | + wrpr %g0, 0x0, %tl | ||
1280 | + | ||
1281 | +661: nop | ||
1282 | + .section .sun4v_1insn_patch, "ax" | ||
1283 | + .word 661b | ||
1284 | + SET_GL(0) | ||
1285 | + .previous | ||
1286 | + | ||
1287 | + wrpr %g0, RTRAP_PSTATE, %pstate | ||
1288 | + | ||
1289 | + mov %l1, %g6 | ||
1290 | + ldx [%g6 + TI_TASK], %g4 | ||
1291 | + LOAD_PER_CPU_BASE(%g5, %g6, %g1, %g2, %g3) | ||
1292 | + | ||
1293 | + brnz,pn %l3, 1f | ||
1294 | + nop | ||
1295 | + | ||
1296 | + call do_sparc64_fault | ||
1297 | + add %sp, PTREGS_OFF, %o0 | ||
1298 | + ba,pt %xcc, rtrap | ||
1299 | + nop | ||
1300 | + | ||
1301 | +1: cmp %g3, 2 | ||
1302 | + bne,pn %xcc, 2f | ||
1303 | + nop | ||
1304 | + | ||
1305 | + sethi %hi(tlb_type), %g1 | ||
1306 | + lduw [%g1 + %lo(tlb_type)], %g1 | ||
1307 | + cmp %g1, 3 | ||
1308 | + bne,pt %icc, 1f | ||
1309 | + add %sp, PTREGS_OFF, %o0 | ||
1310 | + mov %l4, %o2 | ||
1311 | + call sun4v_do_mna | ||
1312 | + mov %l5, %o1 | ||
1313 | + ba,a,pt %xcc, rtrap | ||
1314 | +1: mov %l4, %o1 | ||
1315 | + mov %l5, %o2 | ||
1316 | + call mem_address_unaligned | ||
1317 | + nop | ||
1318 | + ba,a,pt %xcc, rtrap | ||
1319 | + | ||
1320 | +2: sethi %hi(tlb_type), %g1 | ||
1321 | + mov %l4, %o1 | ||
1322 | + lduw [%g1 + %lo(tlb_type)], %g1 | ||
1323 | + mov %l5, %o2 | ||
1324 | + cmp %g1, 3 | ||
1325 | + bne,pt %icc, 1f | ||
1326 | + add %sp, PTREGS_OFF, %o0 | ||
1327 | + call sun4v_data_access_exception | ||
1328 | + nop | ||
1329 | + ba,a,pt %xcc, rtrap | ||
1330 | + | ||
1331 | +1: call spitfire_data_access_exception | ||
1332 | + nop | ||
1333 | + ba,a,pt %xcc, rtrap | ||
1334 | diff --git a/arch/sparc/kernel/utrap.S b/arch/sparc/kernel/utrap.S | ||
1335 | index b7f0f3f3a909..c731e8023d3e 100644 | ||
1336 | --- a/arch/sparc/kernel/utrap.S | ||
1337 | +++ b/arch/sparc/kernel/utrap.S | ||
1338 | @@ -11,8 +11,7 @@ utrap_trap: /* %g3=handler,%g4=level */ | ||
1339 | mov %l4, %o1 | ||
1340 | call bad_trap | ||
1341 | add %sp, PTREGS_OFF, %o0 | ||
1342 | - ba,pt %xcc, rtrap | ||
1343 | - nop | ||
1344 | + ba,a,pt %xcc, rtrap | ||
1345 | |||
1346 | invoke_utrap: | ||
1347 | sllx %g3, 3, %g3 | ||
1348 | diff --git a/arch/sparc/kernel/vmlinux.lds.S b/arch/sparc/kernel/vmlinux.lds.S | ||
1349 | index f1a2f688b28a..4a41d412dd3d 100644 | ||
1350 | --- a/arch/sparc/kernel/vmlinux.lds.S | ||
1351 | +++ b/arch/sparc/kernel/vmlinux.lds.S | ||
1352 | @@ -33,6 +33,10 @@ ENTRY(_start) | ||
1353 | jiffies = jiffies_64; | ||
1354 | #endif | ||
1355 | |||
1356 | +#ifdef CONFIG_SPARC64 | ||
1357 | +ASSERT((swapper_tsb == 0x0000000000408000), "Error: sparc64 early assembler too large") | ||
1358 | +#endif | ||
1359 | + | ||
1360 | SECTIONS | ||
1361 | { | ||
1362 | #ifdef CONFIG_SPARC64 | ||
1363 | diff --git a/arch/sparc/kernel/winfixup.S b/arch/sparc/kernel/winfixup.S | ||
1364 | index 1e67ce958369..855019a8590e 100644 | ||
1365 | --- a/arch/sparc/kernel/winfixup.S | ||
1366 | +++ b/arch/sparc/kernel/winfixup.S | ||
1367 | @@ -32,8 +32,7 @@ fill_fixup: | ||
1368 | rd %pc, %g7 | ||
1369 | call do_sparc64_fault | ||
1370 | add %sp, PTREGS_OFF, %o0 | ||
1371 | - ba,pt %xcc, rtrap | ||
1372 | - nop | ||
1373 | + ba,a,pt %xcc, rtrap | ||
1374 | |||
1375 | /* Be very careful about usage of the trap globals here. | ||
1376 | * You cannot touch %g5 as that has the fault information. | ||
1377 | diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c | ||
1378 | index 131eaf4ad7f5..364d093f46c6 100644 | ||
1379 | --- a/arch/sparc/mm/hugetlbpage.c | ||
1380 | +++ b/arch/sparc/mm/hugetlbpage.c | ||
1381 | @@ -176,17 +176,31 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, | ||
1382 | pte_t *ptep, pte_t entry) | ||
1383 | { | ||
1384 | int i; | ||
1385 | + pte_t orig[2]; | ||
1386 | + unsigned long nptes; | ||
1387 | |||
1388 | if (!pte_present(*ptep) && pte_present(entry)) | ||
1389 | mm->context.huge_pte_count++; | ||
1390 | |||
1391 | addr &= HPAGE_MASK; | ||
1392 | - for (i = 0; i < (1 << HUGETLB_PAGE_ORDER); i++) { | ||
1393 | - set_pte_at(mm, addr, ptep, entry); | ||
1394 | + | ||
1395 | + nptes = 1 << HUGETLB_PAGE_ORDER; | ||
1396 | + orig[0] = *ptep; | ||
1397 | + orig[1] = *(ptep + nptes / 2); | ||
1398 | + for (i = 0; i < nptes; i++) { | ||
1399 | + *ptep = entry; | ||
1400 | ptep++; | ||
1401 | addr += PAGE_SIZE; | ||
1402 | pte_val(entry) += PAGE_SIZE; | ||
1403 | } | ||
1404 | + | ||
1405 | + /* Issue TLB flush at REAL_HPAGE_SIZE boundaries */ | ||
1406 | + addr -= REAL_HPAGE_SIZE; | ||
1407 | + ptep -= nptes / 2; | ||
1408 | + maybe_tlb_batch_add(mm, addr, ptep, orig[1], 0); | ||
1409 | + addr -= REAL_HPAGE_SIZE; | ||
1410 | + ptep -= nptes / 2; | ||
1411 | + maybe_tlb_batch_add(mm, addr, ptep, orig[0], 0); | ||
1412 | } | ||
1413 | |||
1414 | pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, | ||
1415 | @@ -194,19 +208,28 @@ pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, | ||
1416 | { | ||
1417 | pte_t entry; | ||
1418 | int i; | ||
1419 | + unsigned long nptes; | ||
1420 | |||
1421 | entry = *ptep; | ||
1422 | if (pte_present(entry)) | ||
1423 | mm->context.huge_pte_count--; | ||
1424 | |||
1425 | addr &= HPAGE_MASK; | ||
1426 | - | ||
1427 | - for (i = 0; i < (1 << HUGETLB_PAGE_ORDER); i++) { | ||
1428 | - pte_clear(mm, addr, ptep); | ||
1429 | + nptes = 1 << HUGETLB_PAGE_ORDER; | ||
1430 | + for (i = 0; i < nptes; i++) { | ||
1431 | + *ptep = __pte(0UL); | ||
1432 | addr += PAGE_SIZE; | ||
1433 | ptep++; | ||
1434 | } | ||
1435 | |||
1436 | + /* Issue TLB flush at REAL_HPAGE_SIZE boundaries */ | ||
1437 | + addr -= REAL_HPAGE_SIZE; | ||
1438 | + ptep -= nptes / 2; | ||
1439 | + maybe_tlb_batch_add(mm, addr, ptep, entry, 0); | ||
1440 | + addr -= REAL_HPAGE_SIZE; | ||
1441 | + ptep -= nptes / 2; | ||
1442 | + maybe_tlb_batch_add(mm, addr, ptep, entry, 0); | ||
1443 | + | ||
1444 | return entry; | ||
1445 | } | ||
1446 | |||
1447 | diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c | ||
1448 | index 3025bd57f7ab..3c4b8975fa76 100644 | ||
1449 | --- a/arch/sparc/mm/init_64.c | ||
1450 | +++ b/arch/sparc/mm/init_64.c | ||
1451 | @@ -324,18 +324,6 @@ static void __update_mmu_tsb_insert(struct mm_struct *mm, unsigned long tsb_inde | ||
1452 | tsb_insert(tsb, tag, tte); | ||
1453 | } | ||
1454 | |||
1455 | -#if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE) | ||
1456 | -static inline bool is_hugetlb_pte(pte_t pte) | ||
1457 | -{ | ||
1458 | - if ((tlb_type == hypervisor && | ||
1459 | - (pte_val(pte) & _PAGE_SZALL_4V) == _PAGE_SZHUGE_4V) || | ||
1460 | - (tlb_type != hypervisor && | ||
1461 | - (pte_val(pte) & _PAGE_SZALL_4U) == _PAGE_SZHUGE_4U)) | ||
1462 | - return true; | ||
1463 | - return false; | ||
1464 | -} | ||
1465 | -#endif | ||
1466 | - | ||
1467 | void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) | ||
1468 | { | ||
1469 | struct mm_struct *mm; | ||
1470 | @@ -1267,13 +1255,6 @@ static int __init numa_parse_mdesc(void) | ||
1471 | int i, j, err, count; | ||
1472 | u64 node; | ||
1473 | |||
1474 | - /* Some sane defaults for numa latency values */ | ||
1475 | - for (i = 0; i < MAX_NUMNODES; i++) { | ||
1476 | - for (j = 0; j < MAX_NUMNODES; j++) | ||
1477 | - numa_latency[i][j] = (i == j) ? | ||
1478 | - LOCAL_DISTANCE : REMOTE_DISTANCE; | ||
1479 | - } | ||
1480 | - | ||
1481 | node = mdesc_node_by_name(md, MDESC_NODE_NULL, "latency-groups"); | ||
1482 | if (node == MDESC_NODE_NULL) { | ||
1483 | mdesc_release(md); | ||
1484 | @@ -1369,10 +1350,18 @@ static int __init numa_parse_sun4u(void) | ||
1485 | |||
1486 | static int __init bootmem_init_numa(void) | ||
1487 | { | ||
1488 | + int i, j; | ||
1489 | int err = -1; | ||
1490 | |||
1491 | numadbg("bootmem_init_numa()\n"); | ||
1492 | |||
1493 | + /* Some sane defaults for numa latency values */ | ||
1494 | + for (i = 0; i < MAX_NUMNODES; i++) { | ||
1495 | + for (j = 0; j < MAX_NUMNODES; j++) | ||
1496 | + numa_latency[i][j] = (i == j) ? | ||
1497 | + LOCAL_DISTANCE : REMOTE_DISTANCE; | ||
1498 | + } | ||
1499 | + | ||
1500 | if (numa_enabled) { | ||
1501 | if (tlb_type == hypervisor) | ||
1502 | err = numa_parse_mdesc(); | ||
1503 | @@ -2832,9 +2821,10 @@ void hugetlb_setup(struct pt_regs *regs) | ||
1504 | * the Data-TLB for huge pages. | ||
1505 | */ | ||
1506 | if (tlb_type == cheetah_plus) { | ||
1507 | + bool need_context_reload = false; | ||
1508 | unsigned long ctx; | ||
1509 | |||
1510 | - spin_lock(&ctx_alloc_lock); | ||
1511 | + spin_lock_irq(&ctx_alloc_lock); | ||
1512 | ctx = mm->context.sparc64_ctx_val; | ||
1513 | ctx &= ~CTX_PGSZ_MASK; | ||
1514 | ctx |= CTX_PGSZ_BASE << CTX_PGSZ0_SHIFT; | ||
1515 | @@ -2853,9 +2843,12 @@ void hugetlb_setup(struct pt_regs *regs) | ||
1516 | * also executing in this address space. | ||
1517 | */ | ||
1518 | mm->context.sparc64_ctx_val = ctx; | ||
1519 | - on_each_cpu(context_reload, mm, 0); | ||
1520 | + need_context_reload = true; | ||
1521 | } | ||
1522 | - spin_unlock(&ctx_alloc_lock); | ||
1523 | + spin_unlock_irq(&ctx_alloc_lock); | ||
1524 | + | ||
1525 | + if (need_context_reload) | ||
1526 | + on_each_cpu(context_reload, mm, 0); | ||
1527 | } | ||
1528 | } | ||
1529 | #endif | ||
1530 | diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c | ||
1531 | index 9df2190c097e..f81cd9736700 100644 | ||
1532 | --- a/arch/sparc/mm/tlb.c | ||
1533 | +++ b/arch/sparc/mm/tlb.c | ||
1534 | @@ -67,7 +67,7 @@ void arch_leave_lazy_mmu_mode(void) | ||
1535 | } | ||
1536 | |||
1537 | static void tlb_batch_add_one(struct mm_struct *mm, unsigned long vaddr, | ||
1538 | - bool exec) | ||
1539 | + bool exec, bool huge) | ||
1540 | { | ||
1541 | struct tlb_batch *tb = &get_cpu_var(tlb_batch); | ||
1542 | unsigned long nr; | ||
1543 | @@ -84,13 +84,21 @@ static void tlb_batch_add_one(struct mm_struct *mm, unsigned long vaddr, | ||
1544 | } | ||
1545 | |||
1546 | if (!tb->active) { | ||
1547 | - flush_tsb_user_page(mm, vaddr); | ||
1548 | + flush_tsb_user_page(mm, vaddr, huge); | ||
1549 | global_flush_tlb_page(mm, vaddr); | ||
1550 | goto out; | ||
1551 | } | ||
1552 | |||
1553 | - if (nr == 0) | ||
1554 | + if (nr == 0) { | ||
1555 | tb->mm = mm; | ||
1556 | + tb->huge = huge; | ||
1557 | + } | ||
1558 | + | ||
1559 | + if (tb->huge != huge) { | ||
1560 | + flush_tlb_pending(); | ||
1561 | + tb->huge = huge; | ||
1562 | + nr = 0; | ||
1563 | + } | ||
1564 | |||
1565 | tb->vaddrs[nr] = vaddr; | ||
1566 | tb->tlb_nr = ++nr; | ||
1567 | @@ -104,6 +112,8 @@ out: | ||
1568 | void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, | ||
1569 | pte_t *ptep, pte_t orig, int fullmm) | ||
1570 | { | ||
1571 | + bool huge = is_hugetlb_pte(orig); | ||
1572 | + | ||
1573 | if (tlb_type != hypervisor && | ||
1574 | pte_dirty(orig)) { | ||
1575 | unsigned long paddr, pfn = pte_pfn(orig); | ||
1576 | @@ -129,7 +139,7 @@ void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, | ||
1577 | |||
1578 | no_cache_flush: | ||
1579 | if (!fullmm) | ||
1580 | - tlb_batch_add_one(mm, vaddr, pte_exec(orig)); | ||
1581 | + tlb_batch_add_one(mm, vaddr, pte_exec(orig), huge); | ||
1582 | } | ||
1583 | |||
1584 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE | ||
1585 | @@ -145,7 +155,7 @@ static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr, | ||
1586 | if (pte_val(*pte) & _PAGE_VALID) { | ||
1587 | bool exec = pte_exec(*pte); | ||
1588 | |||
1589 | - tlb_batch_add_one(mm, vaddr, exec); | ||
1590 | + tlb_batch_add_one(mm, vaddr, exec, false); | ||
1591 | } | ||
1592 | pte++; | ||
1593 | vaddr += PAGE_SIZE; | ||
1594 | @@ -185,8 +195,9 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr, | ||
1595 | pte_t orig_pte = __pte(pmd_val(orig)); | ||
1596 | bool exec = pte_exec(orig_pte); | ||
1597 | |||
1598 | - tlb_batch_add_one(mm, addr, exec); | ||
1599 | - tlb_batch_add_one(mm, addr + REAL_HPAGE_SIZE, exec); | ||
1600 | + tlb_batch_add_one(mm, addr, exec, true); | ||
1601 | + tlb_batch_add_one(mm, addr + REAL_HPAGE_SIZE, exec, | ||
1602 | + true); | ||
1603 | } else { | ||
1604 | tlb_batch_pmd_scan(mm, addr, orig); | ||
1605 | } | ||
1606 | diff --git a/arch/sparc/mm/tsb.c b/arch/sparc/mm/tsb.c | ||
1607 | index a06576683c38..a0604a493a36 100644 | ||
1608 | --- a/arch/sparc/mm/tsb.c | ||
1609 | +++ b/arch/sparc/mm/tsb.c | ||
1610 | @@ -76,14 +76,15 @@ void flush_tsb_user(struct tlb_batch *tb) | ||
1611 | |||
1612 | spin_lock_irqsave(&mm->context.lock, flags); | ||
1613 | |||
1614 | - base = (unsigned long) mm->context.tsb_block[MM_TSB_BASE].tsb; | ||
1615 | - nentries = mm->context.tsb_block[MM_TSB_BASE].tsb_nentries; | ||
1616 | - if (tlb_type == cheetah_plus || tlb_type == hypervisor) | ||
1617 | - base = __pa(base); | ||
1618 | - __flush_tsb_one(tb, PAGE_SHIFT, base, nentries); | ||
1619 | - | ||
1620 | + if (!tb->huge) { | ||
1621 | + base = (unsigned long) mm->context.tsb_block[MM_TSB_BASE].tsb; | ||
1622 | + nentries = mm->context.tsb_block[MM_TSB_BASE].tsb_nentries; | ||
1623 | + if (tlb_type == cheetah_plus || tlb_type == hypervisor) | ||
1624 | + base = __pa(base); | ||
1625 | + __flush_tsb_one(tb, PAGE_SHIFT, base, nentries); | ||
1626 | + } | ||
1627 | #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE) | ||
1628 | - if (mm->context.tsb_block[MM_TSB_HUGE].tsb) { | ||
1629 | + if (tb->huge && mm->context.tsb_block[MM_TSB_HUGE].tsb) { | ||
1630 | base = (unsigned long) mm->context.tsb_block[MM_TSB_HUGE].tsb; | ||
1631 | nentries = mm->context.tsb_block[MM_TSB_HUGE].tsb_nentries; | ||
1632 | if (tlb_type == cheetah_plus || tlb_type == hypervisor) | ||
1633 | @@ -94,20 +95,21 @@ void flush_tsb_user(struct tlb_batch *tb) | ||
1634 | spin_unlock_irqrestore(&mm->context.lock, flags); | ||
1635 | } | ||
1636 | |||
1637 | -void flush_tsb_user_page(struct mm_struct *mm, unsigned long vaddr) | ||
1638 | +void flush_tsb_user_page(struct mm_struct *mm, unsigned long vaddr, bool huge) | ||
1639 | { | ||
1640 | unsigned long nentries, base, flags; | ||
1641 | |||
1642 | spin_lock_irqsave(&mm->context.lock, flags); | ||
1643 | |||
1644 | - base = (unsigned long) mm->context.tsb_block[MM_TSB_BASE].tsb; | ||
1645 | - nentries = mm->context.tsb_block[MM_TSB_BASE].tsb_nentries; | ||
1646 | - if (tlb_type == cheetah_plus || tlb_type == hypervisor) | ||
1647 | - base = __pa(base); | ||
1648 | - __flush_tsb_one_entry(base, vaddr, PAGE_SHIFT, nentries); | ||
1649 | - | ||
1650 | + if (!huge) { | ||
1651 | + base = (unsigned long) mm->context.tsb_block[MM_TSB_BASE].tsb; | ||
1652 | + nentries = mm->context.tsb_block[MM_TSB_BASE].tsb_nentries; | ||
1653 | + if (tlb_type == cheetah_plus || tlb_type == hypervisor) | ||
1654 | + base = __pa(base); | ||
1655 | + __flush_tsb_one_entry(base, vaddr, PAGE_SHIFT, nentries); | ||
1656 | + } | ||
1657 | #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE) | ||
1658 | - if (mm->context.tsb_block[MM_TSB_HUGE].tsb) { | ||
1659 | + if (huge && mm->context.tsb_block[MM_TSB_HUGE].tsb) { | ||
1660 | base = (unsigned long) mm->context.tsb_block[MM_TSB_HUGE].tsb; | ||
1661 | nentries = mm->context.tsb_block[MM_TSB_HUGE].tsb_nentries; | ||
1662 | if (tlb_type == cheetah_plus || tlb_type == hypervisor) | ||
1663 | diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c | ||
1664 | index ade185a46b1d..679302c312f8 100644 | ||
1665 | --- a/arch/x86/kernel/traps.c | ||
1666 | +++ b/arch/x86/kernel/traps.c | ||
1667 | @@ -109,6 +109,12 @@ static inline void preempt_conditional_cli(struct pt_regs *regs) | ||
1668 | preempt_count_dec(); | ||
1669 | } | ||
1670 | |||
1671 | +/* | ||
1672 | + * In IST context, we explicitly disable preemption. This serves two | ||
1673 | + * purposes: it makes it much less likely that we would accidentally | ||
1674 | + * schedule in IST context and it will force a warning if we somehow | ||
1675 | + * manage to schedule by accident. | ||
1676 | + */ | ||
1677 | void ist_enter(struct pt_regs *regs) | ||
1678 | { | ||
1679 | if (user_mode(regs)) { | ||
1680 | @@ -123,13 +129,7 @@ void ist_enter(struct pt_regs *regs) | ||
1681 | rcu_nmi_enter(); | ||
1682 | } | ||
1683 | |||
1684 | - /* | ||
1685 | - * We are atomic because we're on the IST stack; or we're on | ||
1686 | - * x86_32, in which case we still shouldn't schedule; or we're | ||
1687 | - * on x86_64 and entered from user mode, in which case we're | ||
1688 | - * still atomic unless ist_begin_non_atomic is called. | ||
1689 | - */ | ||
1690 | - preempt_count_add(HARDIRQ_OFFSET); | ||
1691 | + preempt_disable(); | ||
1692 | |||
1693 | /* This code is a bit fragile. Test it. */ | ||
1694 | RCU_LOCKDEP_WARN(!rcu_is_watching(), "ist_enter didn't work"); | ||
1695 | @@ -137,7 +137,7 @@ void ist_enter(struct pt_regs *regs) | ||
1696 | |||
1697 | void ist_exit(struct pt_regs *regs) | ||
1698 | { | ||
1699 | - preempt_count_sub(HARDIRQ_OFFSET); | ||
1700 | + preempt_enable_no_resched(); | ||
1701 | |||
1702 | if (!user_mode(regs)) | ||
1703 | rcu_nmi_exit(); | ||
1704 | @@ -168,7 +168,7 @@ void ist_begin_non_atomic(struct pt_regs *regs) | ||
1705 | BUG_ON((unsigned long)(current_top_of_stack() - | ||
1706 | current_stack_pointer()) >= THREAD_SIZE); | ||
1707 | |||
1708 | - preempt_count_sub(HARDIRQ_OFFSET); | ||
1709 | + preempt_enable_no_resched(); | ||
1710 | } | ||
1711 | |||
1712 | /** | ||
1713 | @@ -178,7 +178,7 @@ void ist_begin_non_atomic(struct pt_regs *regs) | ||
1714 | */ | ||
1715 | void ist_end_non_atomic(void) | ||
1716 | { | ||
1717 | - preempt_count_add(HARDIRQ_OFFSET); | ||
1718 | + preempt_disable(); | ||
1719 | } | ||
1720 | |||
1721 | static nokprobe_inline int | ||
1722 | diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c | ||
1723 | index 605cea75eb0d..be222666b1c2 100644 | ||
1724 | --- a/arch/x86/kvm/x86.c | ||
1725 | +++ b/arch/x86/kvm/x86.c | ||
1726 | @@ -3014,6 +3014,11 @@ static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu, | ||
1727 | if (dbgregs->flags) | ||
1728 | return -EINVAL; | ||
1729 | |||
1730 | + if (dbgregs->dr6 & ~0xffffffffull) | ||
1731 | + return -EINVAL; | ||
1732 | + if (dbgregs->dr7 & ~0xffffffffull) | ||
1733 | + return -EINVAL; | ||
1734 | + | ||
1735 | memcpy(vcpu->arch.db, dbgregs->db, sizeof(vcpu->arch.db)); | ||
1736 | kvm_update_dr0123(vcpu); | ||
1737 | vcpu->arch.dr6 = dbgregs->dr6; | ||
1738 | diff --git a/crypto/asymmetric_keys/Kconfig b/crypto/asymmetric_keys/Kconfig | ||
1739 | index 4870f28403f5..05bfe568cd30 100644 | ||
1740 | --- a/crypto/asymmetric_keys/Kconfig | ||
1741 | +++ b/crypto/asymmetric_keys/Kconfig | ||
1742 | @@ -14,6 +14,7 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE | ||
1743 | select MPILIB | ||
1744 | select PUBLIC_KEY_ALGO_RSA | ||
1745 | select CRYPTO_HASH_INFO | ||
1746 | + select CRYPTO_AKCIPHER | ||
1747 | help | ||
1748 | This option provides support for asymmetric public key type handling. | ||
1749 | If signature generation and/or verification are to be used, | ||
1750 | diff --git a/drivers/crypto/ccp/ccp-crypto-aes-xts.c b/drivers/crypto/ccp/ccp-crypto-aes-xts.c | ||
1751 | index 52c7395cb8d8..0d0d4529ee36 100644 | ||
1752 | --- a/drivers/crypto/ccp/ccp-crypto-aes-xts.c | ||
1753 | +++ b/drivers/crypto/ccp/ccp-crypto-aes-xts.c | ||
1754 | @@ -122,6 +122,7 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req, | ||
1755 | struct ccp_ctx *ctx = crypto_tfm_ctx(req->base.tfm); | ||
1756 | struct ccp_aes_req_ctx *rctx = ablkcipher_request_ctx(req); | ||
1757 | unsigned int unit; | ||
1758 | + u32 unit_size; | ||
1759 | int ret; | ||
1760 | |||
1761 | if (!ctx->u.aes.key_len) | ||
1762 | @@ -133,11 +134,17 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req, | ||
1763 | if (!req->info) | ||
1764 | return -EINVAL; | ||
1765 | |||
1766 | - for (unit = 0; unit < ARRAY_SIZE(unit_size_map); unit++) | ||
1767 | - if (!(req->nbytes & (unit_size_map[unit].size - 1))) | ||
1768 | - break; | ||
1769 | + unit_size = CCP_XTS_AES_UNIT_SIZE__LAST; | ||
1770 | + if (req->nbytes <= unit_size_map[0].size) { | ||
1771 | + for (unit = 0; unit < ARRAY_SIZE(unit_size_map); unit++) { | ||
1772 | + if (!(req->nbytes & (unit_size_map[unit].size - 1))) { | ||
1773 | + unit_size = unit_size_map[unit].value; | ||
1774 | + break; | ||
1775 | + } | ||
1776 | + } | ||
1777 | + } | ||
1778 | |||
1779 | - if ((unit_size_map[unit].value == CCP_XTS_AES_UNIT_SIZE__LAST) || | ||
1780 | + if ((unit_size == CCP_XTS_AES_UNIT_SIZE__LAST) || | ||
1781 | (ctx->u.aes.key_len != AES_KEYSIZE_128)) { | ||
1782 | /* Use the fallback to process the request for any | ||
1783 | * unsupported unit sizes or key sizes | ||
1784 | @@ -158,7 +165,7 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req, | ||
1785 | rctx->cmd.engine = CCP_ENGINE_XTS_AES_128; | ||
1786 | rctx->cmd.u.xts.action = (encrypt) ? CCP_AES_ACTION_ENCRYPT | ||
1787 | : CCP_AES_ACTION_DECRYPT; | ||
1788 | - rctx->cmd.u.xts.unit_size = unit_size_map[unit].value; | ||
1789 | + rctx->cmd.u.xts.unit_size = unit_size; | ||
1790 | rctx->cmd.u.xts.key = &ctx->u.aes.key_sg; | ||
1791 | rctx->cmd.u.xts.key_len = ctx->u.aes.key_len; | ||
1792 | rctx->cmd.u.xts.iv = &rctx->iv_sg; | ||
1793 | diff --git a/drivers/crypto/qat/qat_common/adf_common_drv.h b/drivers/crypto/qat/qat_common/adf_common_drv.h | ||
1794 | index b9178d0a3093..aa1dbeaa9b49 100644 | ||
1795 | --- a/drivers/crypto/qat/qat_common/adf_common_drv.h | ||
1796 | +++ b/drivers/crypto/qat/qat_common/adf_common_drv.h | ||
1797 | @@ -145,8 +145,6 @@ int adf_enable_aer(struct adf_accel_dev *accel_dev, struct pci_driver *adf); | ||
1798 | void adf_disable_aer(struct adf_accel_dev *accel_dev); | ||
1799 | int adf_init_aer(void); | ||
1800 | void adf_exit_aer(void); | ||
1801 | -int adf_init_pf_wq(void); | ||
1802 | -void adf_exit_pf_wq(void); | ||
1803 | int adf_init_admin_comms(struct adf_accel_dev *accel_dev); | ||
1804 | void adf_exit_admin_comms(struct adf_accel_dev *accel_dev); | ||
1805 | int adf_send_admin_init(struct adf_accel_dev *accel_dev); | ||
1806 | @@ -229,6 +227,8 @@ void adf_disable_vf2pf_interrupts(struct adf_accel_dev *accel_dev, | ||
1807 | uint32_t vf_mask); | ||
1808 | void adf_enable_vf2pf_interrupts(struct adf_accel_dev *accel_dev, | ||
1809 | uint32_t vf_mask); | ||
1810 | +int adf_init_pf_wq(void); | ||
1811 | +void adf_exit_pf_wq(void); | ||
1812 | #else | ||
1813 | static inline int adf_sriov_configure(struct pci_dev *pdev, int numvfs) | ||
1814 | { | ||
1815 | @@ -238,5 +238,14 @@ static inline int adf_sriov_configure(struct pci_dev *pdev, int numvfs) | ||
1816 | static inline void adf_disable_sriov(struct adf_accel_dev *accel_dev) | ||
1817 | { | ||
1818 | } | ||
1819 | + | ||
1820 | +static inline int adf_init_pf_wq(void) | ||
1821 | +{ | ||
1822 | + return 0; | ||
1823 | +} | ||
1824 | + | ||
1825 | +static inline void adf_exit_pf_wq(void) | ||
1826 | +{ | ||
1827 | +} | ||
1828 | #endif | ||
1829 | #endif | ||
1830 | diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c | ||
1831 | index 33a1f9779b86..4ea71d505bce 100644 | ||
1832 | --- a/drivers/gpio/gpio-bcm-kona.c | ||
1833 | +++ b/drivers/gpio/gpio-bcm-kona.c | ||
1834 | @@ -551,11 +551,11 @@ static void bcm_kona_gpio_reset(struct bcm_kona_gpio *kona_gpio) | ||
1835 | /* disable interrupts and clear status */ | ||
1836 | for (i = 0; i < kona_gpio->num_bank; i++) { | ||
1837 | /* Unlock the entire bank first */ | ||
1838 | - bcm_kona_gpio_write_lock_regs(kona_gpio, i, UNLOCK_CODE); | ||
1839 | + bcm_kona_gpio_write_lock_regs(reg_base, i, UNLOCK_CODE); | ||
1840 | writel(0xffffffff, reg_base + GPIO_INT_MASK(i)); | ||
1841 | writel(0xffffffff, reg_base + GPIO_INT_STATUS(i)); | ||
1842 | /* Now re-lock the bank */ | ||
1843 | - bcm_kona_gpio_write_lock_regs(kona_gpio, i, LOCK_CODE); | ||
1844 | + bcm_kona_gpio_write_lock_regs(reg_base, i, LOCK_CODE); | ||
1845 | } | ||
1846 | } | ||
1847 | |||
1848 | diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c | ||
1849 | index 24c5434abd1c..a02238c85e18 100644 | ||
1850 | --- a/drivers/gpu/drm/drm_crtc.c | ||
1851 | +++ b/drivers/gpu/drm/drm_crtc.c | ||
1852 | @@ -3316,6 +3316,24 @@ int drm_mode_addfb2(struct drm_device *dev, | ||
1853 | return 0; | ||
1854 | } | ||
1855 | |||
1856 | +struct drm_mode_rmfb_work { | ||
1857 | + struct work_struct work; | ||
1858 | + struct list_head fbs; | ||
1859 | +}; | ||
1860 | + | ||
1861 | +static void drm_mode_rmfb_work_fn(struct work_struct *w) | ||
1862 | +{ | ||
1863 | + struct drm_mode_rmfb_work *arg = container_of(w, typeof(*arg), work); | ||
1864 | + | ||
1865 | + while (!list_empty(&arg->fbs)) { | ||
1866 | + struct drm_framebuffer *fb = | ||
1867 | + list_first_entry(&arg->fbs, typeof(*fb), filp_head); | ||
1868 | + | ||
1869 | + list_del_init(&fb->filp_head); | ||
1870 | + drm_framebuffer_remove(fb); | ||
1871 | + } | ||
1872 | +} | ||
1873 | + | ||
1874 | /** | ||
1875 | * drm_mode_rmfb - remove an FB from the configuration | ||
1876 | * @dev: drm device for the ioctl | ||
1877 | @@ -3356,7 +3374,25 @@ int drm_mode_rmfb(struct drm_device *dev, | ||
1878 | mutex_unlock(&dev->mode_config.fb_lock); | ||
1879 | mutex_unlock(&file_priv->fbs_lock); | ||
1880 | |||
1881 | - drm_framebuffer_unreference(fb); | ||
1882 | + /* | ||
1883 | + * we now own the reference that was stored in the fbs list | ||
1884 | + * | ||
1885 | + * drm_framebuffer_remove may fail with -EINTR on pending signals, | ||
1886 | + * so run this in a separate stack as there's no way to correctly | ||
1887 | + * handle this after the fb is already removed from the lookup table. | ||
1888 | + */ | ||
1889 | + if (atomic_read(&fb->refcount.refcount) > 1) { | ||
1890 | + struct drm_mode_rmfb_work arg; | ||
1891 | + | ||
1892 | + INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn); | ||
1893 | + INIT_LIST_HEAD(&arg.fbs); | ||
1894 | + list_add_tail(&fb->filp_head, &arg.fbs); | ||
1895 | + | ||
1896 | + schedule_work(&arg.work); | ||
1897 | + flush_work(&arg.work); | ||
1898 | + destroy_work_on_stack(&arg.work); | ||
1899 | + } else | ||
1900 | + drm_framebuffer_unreference(fb); | ||
1901 | |||
1902 | return 0; | ||
1903 | |||
1904 | @@ -3509,7 +3545,6 @@ out_err1: | ||
1905 | return ret; | ||
1906 | } | ||
1907 | |||
1908 | - | ||
1909 | /** | ||
1910 | * drm_fb_release - remove and free the FBs on this file | ||
1911 | * @priv: drm file for the ioctl | ||
1912 | @@ -3524,6 +3559,9 @@ out_err1: | ||
1913 | void drm_fb_release(struct drm_file *priv) | ||
1914 | { | ||
1915 | struct drm_framebuffer *fb, *tfb; | ||
1916 | + struct drm_mode_rmfb_work arg; | ||
1917 | + | ||
1918 | + INIT_LIST_HEAD(&arg.fbs); | ||
1919 | |||
1920 | /* | ||
1921 | * When the file gets released that means no one else can access the fb | ||
1922 | @@ -3536,10 +3574,22 @@ void drm_fb_release(struct drm_file *priv) | ||
1923 | * at it any more. | ||
1924 | */ | ||
1925 | list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { | ||
1926 | - list_del_init(&fb->filp_head); | ||
1927 | + if (atomic_read(&fb->refcount.refcount) > 1) { | ||
1928 | + list_move_tail(&fb->filp_head, &arg.fbs); | ||
1929 | + } else { | ||
1930 | + list_del_init(&fb->filp_head); | ||
1931 | |||
1932 | - /* This drops the fpriv->fbs reference. */ | ||
1933 | - drm_framebuffer_unreference(fb); | ||
1934 | + /* This drops the fpriv->fbs reference. */ | ||
1935 | + drm_framebuffer_unreference(fb); | ||
1936 | + } | ||
1937 | + } | ||
1938 | + | ||
1939 | + if (!list_empty(&arg.fbs)) { | ||
1940 | + INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn); | ||
1941 | + | ||
1942 | + schedule_work(&arg.work); | ||
1943 | + flush_work(&arg.work); | ||
1944 | + destroy_work_on_stack(&arg.work); | ||
1945 | } | ||
1946 | } | ||
1947 | |||
1948 | diff --git a/drivers/net/ethernet/rocker/rocker.c b/drivers/net/ethernet/rocker/rocker.c | ||
1949 | index 2b34622a4bfe..3920c3eb6006 100644 | ||
1950 | --- a/drivers/net/ethernet/rocker/rocker.c | ||
1951 | +++ b/drivers/net/ethernet/rocker/rocker.c | ||
1952 | @@ -4475,7 +4475,7 @@ static int rocker_port_obj_add(struct net_device *dev, | ||
1953 | fib4 = SWITCHDEV_OBJ_IPV4_FIB(obj); | ||
1954 | err = rocker_port_fib_ipv4(rocker_port, trans, | ||
1955 | htonl(fib4->dst), fib4->dst_len, | ||
1956 | - &fib4->fi, fib4->tb_id, 0); | ||
1957 | + fib4->fi, fib4->tb_id, 0); | ||
1958 | break; | ||
1959 | case SWITCHDEV_OBJ_ID_PORT_FDB: | ||
1960 | err = rocker_port_fdb_add(rocker_port, trans, | ||
1961 | @@ -4547,7 +4547,7 @@ static int rocker_port_obj_del(struct net_device *dev, | ||
1962 | fib4 = SWITCHDEV_OBJ_IPV4_FIB(obj); | ||
1963 | err = rocker_port_fib_ipv4(rocker_port, NULL, | ||
1964 | htonl(fib4->dst), fib4->dst_len, | ||
1965 | - &fib4->fi, fib4->tb_id, | ||
1966 | + fib4->fi, fib4->tb_id, | ||
1967 | ROCKER_OP_FLAG_REMOVE); | ||
1968 | break; | ||
1969 | case SWITCHDEV_OBJ_ID_PORT_FDB: | ||
1970 | diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c | ||
1971 | index e6a084a6be12..cbe9a330117a 100644 | ||
1972 | --- a/drivers/net/ethernet/sfc/ef10.c | ||
1973 | +++ b/drivers/net/ethernet/sfc/ef10.c | ||
1974 | @@ -619,6 +619,17 @@ fail: | ||
1975 | return rc; | ||
1976 | } | ||
1977 | |||
1978 | +static void efx_ef10_forget_old_piobufs(struct efx_nic *efx) | ||
1979 | +{ | ||
1980 | + struct efx_channel *channel; | ||
1981 | + struct efx_tx_queue *tx_queue; | ||
1982 | + | ||
1983 | + /* All our existing PIO buffers went away */ | ||
1984 | + efx_for_each_channel(channel, efx) | ||
1985 | + efx_for_each_channel_tx_queue(tx_queue, channel) | ||
1986 | + tx_queue->piobuf = NULL; | ||
1987 | +} | ||
1988 | + | ||
1989 | #else /* !EFX_USE_PIO */ | ||
1990 | |||
1991 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) | ||
1992 | @@ -635,6 +646,10 @@ static void efx_ef10_free_piobufs(struct efx_nic *efx) | ||
1993 | { | ||
1994 | } | ||
1995 | |||
1996 | +static void efx_ef10_forget_old_piobufs(struct efx_nic *efx) | ||
1997 | +{ | ||
1998 | +} | ||
1999 | + | ||
2000 | #endif /* EFX_USE_PIO */ | ||
2001 | |||
2002 | static void efx_ef10_remove(struct efx_nic *efx) | ||
2003 | @@ -1018,6 +1033,7 @@ static void efx_ef10_reset_mc_allocations(struct efx_nic *efx) | ||
2004 | nic_data->must_realloc_vis = true; | ||
2005 | nic_data->must_restore_filters = true; | ||
2006 | nic_data->must_restore_piobufs = true; | ||
2007 | + efx_ef10_forget_old_piobufs(efx); | ||
2008 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | ||
2009 | |||
2010 | /* Driver-created vswitches and vports must be re-created */ | ||
2011 | diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c | ||
2012 | index 58efdec12f30..69e31e2a68fc 100644 | ||
2013 | --- a/drivers/net/geneve.c | ||
2014 | +++ b/drivers/net/geneve.c | ||
2015 | @@ -310,15 +310,15 @@ static int geneve_udp_encap_recv(struct sock *sk, struct sk_buff *skb) | ||
2016 | |||
2017 | /* Need Geneve and inner Ethernet header to be present */ | ||
2018 | if (unlikely(!pskb_may_pull(skb, GENEVE_BASE_HLEN))) | ||
2019 | - goto error; | ||
2020 | + goto drop; | ||
2021 | |||
2022 | /* Return packets with reserved bits set */ | ||
2023 | geneveh = geneve_hdr(skb); | ||
2024 | if (unlikely(geneveh->ver != GENEVE_VER)) | ||
2025 | - goto error; | ||
2026 | + goto drop; | ||
2027 | |||
2028 | if (unlikely(geneveh->proto_type != htons(ETH_P_TEB))) | ||
2029 | - goto error; | ||
2030 | + goto drop; | ||
2031 | |||
2032 | opts_len = geneveh->opt_len * 4; | ||
2033 | if (iptunnel_pull_header(skb, GENEVE_BASE_HLEN + opts_len, | ||
2034 | @@ -336,10 +336,6 @@ drop: | ||
2035 | /* Consume bad packet */ | ||
2036 | kfree_skb(skb); | ||
2037 | return 0; | ||
2038 | - | ||
2039 | -error: | ||
2040 | - /* Let the UDP layer deal with the skb */ | ||
2041 | - return 1; | ||
2042 | } | ||
2043 | |||
2044 | static struct socket *geneve_create_sock(struct net *net, bool ipv6, | ||
2045 | @@ -998,6 +994,17 @@ static netdev_tx_t geneve_xmit(struct sk_buff *skb, struct net_device *dev) | ||
2046 | return geneve_xmit_skb(skb, dev, info); | ||
2047 | } | ||
2048 | |||
2049 | +static int geneve_change_mtu(struct net_device *dev, int new_mtu) | ||
2050 | +{ | ||
2051 | + /* GENEVE overhead is not fixed, so we can't enforce a more | ||
2052 | + * precise max MTU. | ||
2053 | + */ | ||
2054 | + if (new_mtu < 68 || new_mtu > IP_MAX_MTU) | ||
2055 | + return -EINVAL; | ||
2056 | + dev->mtu = new_mtu; | ||
2057 | + return 0; | ||
2058 | +} | ||
2059 | + | ||
2060 | static int geneve_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb) | ||
2061 | { | ||
2062 | struct ip_tunnel_info *info = skb_tunnel_info(skb); | ||
2063 | @@ -1042,7 +1049,7 @@ static const struct net_device_ops geneve_netdev_ops = { | ||
2064 | .ndo_stop = geneve_stop, | ||
2065 | .ndo_start_xmit = geneve_xmit, | ||
2066 | .ndo_get_stats64 = ip_tunnel_get_stats64, | ||
2067 | - .ndo_change_mtu = eth_change_mtu, | ||
2068 | + .ndo_change_mtu = geneve_change_mtu, | ||
2069 | .ndo_validate_addr = eth_validate_addr, | ||
2070 | .ndo_set_mac_address = eth_mac_addr, | ||
2071 | .ndo_fill_metadata_dst = geneve_fill_metadata_dst, | ||
2072 | @@ -1349,11 +1356,21 @@ struct net_device *geneve_dev_create_fb(struct net *net, const char *name, | ||
2073 | |||
2074 | err = geneve_configure(net, dev, &geneve_remote_unspec, | ||
2075 | 0, 0, 0, htons(dst_port), true); | ||
2076 | - if (err) { | ||
2077 | - free_netdev(dev); | ||
2078 | - return ERR_PTR(err); | ||
2079 | - } | ||
2080 | + if (err) | ||
2081 | + goto err; | ||
2082 | + | ||
2083 | + /* openvswitch users expect packet sizes to be unrestricted, | ||
2084 | + * so set the largest MTU we can. | ||
2085 | + */ | ||
2086 | + err = geneve_change_mtu(dev, IP_MAX_MTU); | ||
2087 | + if (err) | ||
2088 | + goto err; | ||
2089 | + | ||
2090 | return dev; | ||
2091 | + | ||
2092 | + err: | ||
2093 | + free_netdev(dev); | ||
2094 | + return ERR_PTR(err); | ||
2095 | } | ||
2096 | EXPORT_SYMBOL_GPL(geneve_dev_create_fb); | ||
2097 | |||
2098 | diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c | ||
2099 | index 59fefca74263..a5f392ae30d5 100644 | ||
2100 | --- a/drivers/net/team/team.c | ||
2101 | +++ b/drivers/net/team/team.c | ||
2102 | @@ -969,7 +969,7 @@ static void team_port_disable(struct team *team, | ||
2103 | NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \ | ||
2104 | NETIF_F_HIGHDMA | NETIF_F_LRO) | ||
2105 | |||
2106 | -static void __team_compute_features(struct team *team) | ||
2107 | +static void ___team_compute_features(struct team *team) | ||
2108 | { | ||
2109 | struct team_port *port; | ||
2110 | u32 vlan_features = TEAM_VLAN_FEATURES & NETIF_F_ALL_FOR_ALL; | ||
2111 | @@ -993,15 +993,20 @@ static void __team_compute_features(struct team *team) | ||
2112 | team->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE; | ||
2113 | if (dst_release_flag == (IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM)) | ||
2114 | team->dev->priv_flags |= IFF_XMIT_DST_RELEASE; | ||
2115 | +} | ||
2116 | |||
2117 | +static void __team_compute_features(struct team *team) | ||
2118 | +{ | ||
2119 | + ___team_compute_features(team); | ||
2120 | netdev_change_features(team->dev); | ||
2121 | } | ||
2122 | |||
2123 | static void team_compute_features(struct team *team) | ||
2124 | { | ||
2125 | mutex_lock(&team->lock); | ||
2126 | - __team_compute_features(team); | ||
2127 | + ___team_compute_features(team); | ||
2128 | mutex_unlock(&team->lock); | ||
2129 | + netdev_change_features(team->dev); | ||
2130 | } | ||
2131 | |||
2132 | static int team_port_enter(struct team *team, struct team_port *port) | ||
2133 | diff --git a/drivers/net/tun.c b/drivers/net/tun.c | ||
2134 | index 2d186bd66d43..111b972e3053 100644 | ||
2135 | --- a/drivers/net/tun.c | ||
2136 | +++ b/drivers/net/tun.c | ||
2137 | @@ -567,11 +567,13 @@ static void tun_detach_all(struct net_device *dev) | ||
2138 | for (i = 0; i < n; i++) { | ||
2139 | tfile = rtnl_dereference(tun->tfiles[i]); | ||
2140 | BUG_ON(!tfile); | ||
2141 | + tfile->socket.sk->sk_shutdown = RCV_SHUTDOWN; | ||
2142 | tfile->socket.sk->sk_data_ready(tfile->socket.sk); | ||
2143 | RCU_INIT_POINTER(tfile->tun, NULL); | ||
2144 | --tun->numqueues; | ||
2145 | } | ||
2146 | list_for_each_entry(tfile, &tun->disabled, next) { | ||
2147 | + tfile->socket.sk->sk_shutdown = RCV_SHUTDOWN; | ||
2148 | tfile->socket.sk->sk_data_ready(tfile->socket.sk); | ||
2149 | RCU_INIT_POINTER(tfile->tun, NULL); | ||
2150 | } | ||
2151 | @@ -627,6 +629,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file, bool skip_filte | ||
2152 | goto out; | ||
2153 | } | ||
2154 | tfile->queue_index = tun->numqueues; | ||
2155 | + tfile->socket.sk->sk_shutdown &= ~RCV_SHUTDOWN; | ||
2156 | rcu_assign_pointer(tfile->tun, tun); | ||
2157 | rcu_assign_pointer(tun->tfiles[tun->numqueues], tfile); | ||
2158 | tun->numqueues++; | ||
2159 | @@ -1408,9 +1411,6 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile, | ||
2160 | if (!iov_iter_count(to)) | ||
2161 | return 0; | ||
2162 | |||
2163 | - if (tun->dev->reg_state != NETREG_REGISTERED) | ||
2164 | - return -EIO; | ||
2165 | - | ||
2166 | /* Read frames from queue */ | ||
2167 | skb = __skb_recv_datagram(tfile->socket.sk, noblock ? MSG_DONTWAIT : 0, | ||
2168 | &peeked, &off, &err); | ||
2169 | diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c | ||
2170 | index 3c0df70e2f53..003780901628 100644 | ||
2171 | --- a/drivers/net/vxlan.c | ||
2172 | +++ b/drivers/net/vxlan.c | ||
2173 | @@ -1254,7 +1254,7 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb) | ||
2174 | |||
2175 | /* Need Vxlan and inner Ethernet header to be present */ | ||
2176 | if (!pskb_may_pull(skb, VXLAN_HLEN)) | ||
2177 | - goto error; | ||
2178 | + goto drop; | ||
2179 | |||
2180 | vxh = (struct vxlanhdr *)(udp_hdr(skb) + 1); | ||
2181 | flags = ntohl(vxh->vx_flags); | ||
2182 | @@ -1344,13 +1344,7 @@ drop: | ||
2183 | bad_flags: | ||
2184 | netdev_dbg(skb->dev, "invalid vxlan flags=%#x vni=%#x\n", | ||
2185 | ntohl(vxh->vx_flags), ntohl(vxh->vx_vni)); | ||
2186 | - | ||
2187 | -error: | ||
2188 | - if (tun_dst) | ||
2189 | - dst_release((struct dst_entry *)tun_dst); | ||
2190 | - | ||
2191 | - /* Return non vxlan pkt */ | ||
2192 | - return 1; | ||
2193 | + goto drop; | ||
2194 | } | ||
2195 | |||
2196 | static int arp_reduce(struct net_device *dev, struct sk_buff *skb) | ||
2197 | @@ -2370,29 +2364,43 @@ static void vxlan_set_multicast_list(struct net_device *dev) | ||
2198 | { | ||
2199 | } | ||
2200 | |||
2201 | -static int vxlan_change_mtu(struct net_device *dev, int new_mtu) | ||
2202 | +static int __vxlan_change_mtu(struct net_device *dev, | ||
2203 | + struct net_device *lowerdev, | ||
2204 | + struct vxlan_rdst *dst, int new_mtu, bool strict) | ||
2205 | { | ||
2206 | - struct vxlan_dev *vxlan = netdev_priv(dev); | ||
2207 | - struct vxlan_rdst *dst = &vxlan->default_dst; | ||
2208 | - struct net_device *lowerdev; | ||
2209 | - int max_mtu; | ||
2210 | + int max_mtu = IP_MAX_MTU; | ||
2211 | |||
2212 | - lowerdev = __dev_get_by_index(vxlan->net, dst->remote_ifindex); | ||
2213 | - if (lowerdev == NULL) | ||
2214 | - return eth_change_mtu(dev, new_mtu); | ||
2215 | + if (lowerdev) | ||
2216 | + max_mtu = lowerdev->mtu; | ||
2217 | |||
2218 | if (dst->remote_ip.sa.sa_family == AF_INET6) | ||
2219 | - max_mtu = lowerdev->mtu - VXLAN6_HEADROOM; | ||
2220 | + max_mtu -= VXLAN6_HEADROOM; | ||
2221 | else | ||
2222 | - max_mtu = lowerdev->mtu - VXLAN_HEADROOM; | ||
2223 | + max_mtu -= VXLAN_HEADROOM; | ||
2224 | |||
2225 | - if (new_mtu < 68 || new_mtu > max_mtu) | ||
2226 | + if (new_mtu < 68) | ||
2227 | return -EINVAL; | ||
2228 | |||
2229 | + if (new_mtu > max_mtu) { | ||
2230 | + if (strict) | ||
2231 | + return -EINVAL; | ||
2232 | + | ||
2233 | + new_mtu = max_mtu; | ||
2234 | + } | ||
2235 | + | ||
2236 | dev->mtu = new_mtu; | ||
2237 | return 0; | ||
2238 | } | ||
2239 | |||
2240 | +static int vxlan_change_mtu(struct net_device *dev, int new_mtu) | ||
2241 | +{ | ||
2242 | + struct vxlan_dev *vxlan = netdev_priv(dev); | ||
2243 | + struct vxlan_rdst *dst = &vxlan->default_dst; | ||
2244 | + struct net_device *lowerdev = __dev_get_by_index(vxlan->net, | ||
2245 | + dst->remote_ifindex); | ||
2246 | + return __vxlan_change_mtu(dev, lowerdev, dst, new_mtu, true); | ||
2247 | +} | ||
2248 | + | ||
2249 | static int egress_ipv4_tun_info(struct net_device *dev, struct sk_buff *skb, | ||
2250 | struct ip_tunnel_info *info, | ||
2251 | __be16 sport, __be16 dport) | ||
2252 | @@ -2768,6 +2776,7 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev, | ||
2253 | int err; | ||
2254 | bool use_ipv6 = false; | ||
2255 | __be16 default_port = vxlan->cfg.dst_port; | ||
2256 | + struct net_device *lowerdev = NULL; | ||
2257 | |||
2258 | vxlan->net = src_net; | ||
2259 | |||
2260 | @@ -2788,9 +2797,7 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev, | ||
2261 | } | ||
2262 | |||
2263 | if (conf->remote_ifindex) { | ||
2264 | - struct net_device *lowerdev | ||
2265 | - = __dev_get_by_index(src_net, conf->remote_ifindex); | ||
2266 | - | ||
2267 | + lowerdev = __dev_get_by_index(src_net, conf->remote_ifindex); | ||
2268 | dst->remote_ifindex = conf->remote_ifindex; | ||
2269 | |||
2270 | if (!lowerdev) { | ||
2271 | @@ -2814,6 +2821,12 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev, | ||
2272 | needed_headroom = lowerdev->hard_header_len; | ||
2273 | } | ||
2274 | |||
2275 | + if (conf->mtu) { | ||
2276 | + err = __vxlan_change_mtu(dev, lowerdev, dst, conf->mtu, false); | ||
2277 | + if (err) | ||
2278 | + return err; | ||
2279 | + } | ||
2280 | + | ||
2281 | if (use_ipv6 || conf->flags & VXLAN_F_COLLECT_METADATA) | ||
2282 | needed_headroom += VXLAN6_HEADROOM; | ||
2283 | else | ||
2284 | @@ -2991,6 +3004,9 @@ static int vxlan_newlink(struct net *src_net, struct net_device *dev, | ||
2285 | if (data[IFLA_VXLAN_REMCSUM_NOPARTIAL]) | ||
2286 | conf.flags |= VXLAN_F_REMCSUM_NOPARTIAL; | ||
2287 | |||
2288 | + if (tb[IFLA_MTU]) | ||
2289 | + conf.mtu = nla_get_u32(tb[IFLA_MTU]); | ||
2290 | + | ||
2291 | err = vxlan_dev_configure(src_net, dev, &conf); | ||
2292 | switch (err) { | ||
2293 | case -ENODEV: | ||
2294 | diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c | ||
2295 | index 3d8019eb3d84..181b35879ebd 100644 | ||
2296 | --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c | ||
2297 | +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c | ||
2298 | @@ -1191,9 +1191,10 @@ static void mtk_eint_irq_handler(struct irq_desc *desc) | ||
2299 | const struct mtk_desc_pin *pin; | ||
2300 | |||
2301 | chained_irq_enter(chip, desc); | ||
2302 | - for (eint_num = 0; eint_num < pctl->devdata->ap_num; eint_num += 32) { | ||
2303 | + for (eint_num = 0; | ||
2304 | + eint_num < pctl->devdata->ap_num; | ||
2305 | + eint_num += 32, reg += 4) { | ||
2306 | status = readl(reg); | ||
2307 | - reg += 4; | ||
2308 | while (status) { | ||
2309 | offset = __ffs(status); | ||
2310 | index = eint_num + offset; | ||
2311 | diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c | ||
2312 | index da2e068ee47d..93cbefa75b26 100644 | ||
2313 | --- a/drivers/scsi/scsi_devinfo.c | ||
2314 | +++ b/drivers/scsi/scsi_devinfo.c | ||
2315 | @@ -227,6 +227,7 @@ static struct { | ||
2316 | {"PIONEER", "CD-ROM DRM-624X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, | ||
2317 | {"Promise", "VTrak E610f", NULL, BLIST_SPARSELUN | BLIST_NO_RSOC}, | ||
2318 | {"Promise", "", NULL, BLIST_SPARSELUN}, | ||
2319 | + {"QEMU", "QEMU CD-ROM", NULL, BLIST_SKIP_VPD_PAGES}, | ||
2320 | {"QNAP", "iSCSI Storage", NULL, BLIST_MAX_1024}, | ||
2321 | {"SYNOLOGY", "iSCSI Storage", NULL, BLIST_MAX_1024}, | ||
2322 | {"QUANTUM", "XP34301", "1071", BLIST_NOTQ}, | ||
2323 | diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c | ||
2324 | index dd8ad2a44510..cf5b99e1f12b 100644 | ||
2325 | --- a/drivers/scsi/scsi_lib.c | ||
2326 | +++ b/drivers/scsi/scsi_lib.c | ||
2327 | @@ -910,9 +910,12 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) | ||
2328 | } | ||
2329 | |||
2330 | /* | ||
2331 | - * If we finished all bytes in the request we are done now. | ||
2332 | + * special case: failed zero length commands always need to | ||
2333 | + * drop down into the retry code. Otherwise, if we finished | ||
2334 | + * all bytes in the request we are done now. | ||
2335 | */ | ||
2336 | - if (!scsi_end_request(req, error, good_bytes, 0)) | ||
2337 | + if (!(blk_rq_bytes(req) == 0 && error) && | ||
2338 | + !scsi_end_request(req, error, good_bytes, 0)) | ||
2339 | return; | ||
2340 | |||
2341 | /* | ||
2342 | diff --git a/fs/dcache.c b/fs/dcache.c | ||
2343 | index 18effa378f97..108d7d810be3 100644 | ||
2344 | --- a/fs/dcache.c | ||
2345 | +++ b/fs/dcache.c | ||
2346 | @@ -1618,7 +1618,7 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) | ||
2347 | struct dentry *dentry = __d_alloc(parent->d_sb, name); | ||
2348 | if (!dentry) | ||
2349 | return NULL; | ||
2350 | - | ||
2351 | + dentry->d_flags |= DCACHE_RCUACCESS; | ||
2352 | spin_lock(&parent->d_lock); | ||
2353 | /* | ||
2354 | * don't need child lock because it is not subject | ||
2355 | @@ -2413,7 +2413,6 @@ static void __d_rehash(struct dentry * entry, struct hlist_bl_head *b) | ||
2356 | { | ||
2357 | BUG_ON(!d_unhashed(entry)); | ||
2358 | hlist_bl_lock(b); | ||
2359 | - entry->d_flags |= DCACHE_RCUACCESS; | ||
2360 | hlist_bl_add_head_rcu(&entry->d_hash, b); | ||
2361 | hlist_bl_unlock(b); | ||
2362 | } | ||
2363 | @@ -2632,6 +2631,7 @@ static void __d_move(struct dentry *dentry, struct dentry *target, | ||
2364 | /* ... and switch them in the tree */ | ||
2365 | if (IS_ROOT(dentry)) { | ||
2366 | /* splicing a tree */ | ||
2367 | + dentry->d_flags |= DCACHE_RCUACCESS; | ||
2368 | dentry->d_parent = target->d_parent; | ||
2369 | target->d_parent = target; | ||
2370 | list_del_init(&target->d_child); | ||
2371 | diff --git a/fs/ecryptfs/kthread.c b/fs/ecryptfs/kthread.c | ||
2372 | index 866bb18efefe..e818f5ac7a26 100644 | ||
2373 | --- a/fs/ecryptfs/kthread.c | ||
2374 | +++ b/fs/ecryptfs/kthread.c | ||
2375 | @@ -25,6 +25,7 @@ | ||
2376 | #include <linux/slab.h> | ||
2377 | #include <linux/wait.h> | ||
2378 | #include <linux/mount.h> | ||
2379 | +#include <linux/file.h> | ||
2380 | #include "ecryptfs_kernel.h" | ||
2381 | |||
2382 | struct ecryptfs_open_req { | ||
2383 | @@ -147,7 +148,7 @@ int ecryptfs_privileged_open(struct file **lower_file, | ||
2384 | flags |= IS_RDONLY(d_inode(lower_dentry)) ? O_RDONLY : O_RDWR; | ||
2385 | (*lower_file) = dentry_open(&req.path, flags, cred); | ||
2386 | if (!IS_ERR(*lower_file)) | ||
2387 | - goto out; | ||
2388 | + goto have_file; | ||
2389 | if ((flags & O_ACCMODE) == O_RDONLY) { | ||
2390 | rc = PTR_ERR((*lower_file)); | ||
2391 | goto out; | ||
2392 | @@ -165,8 +166,16 @@ int ecryptfs_privileged_open(struct file **lower_file, | ||
2393 | mutex_unlock(&ecryptfs_kthread_ctl.mux); | ||
2394 | wake_up(&ecryptfs_kthread_ctl.wait); | ||
2395 | wait_for_completion(&req.done); | ||
2396 | - if (IS_ERR(*lower_file)) | ||
2397 | + if (IS_ERR(*lower_file)) { | ||
2398 | rc = PTR_ERR(*lower_file); | ||
2399 | + goto out; | ||
2400 | + } | ||
2401 | +have_file: | ||
2402 | + if ((*lower_file)->f_op->mmap == NULL) { | ||
2403 | + fput(*lower_file); | ||
2404 | + *lower_file = NULL; | ||
2405 | + rc = -EMEDIUMTYPE; | ||
2406 | + } | ||
2407 | out: | ||
2408 | return rc; | ||
2409 | } | ||
2410 | diff --git a/fs/proc/root.c b/fs/proc/root.c | ||
2411 | index 361ab4ee42fc..ec649c92d270 100644 | ||
2412 | --- a/fs/proc/root.c | ||
2413 | +++ b/fs/proc/root.c | ||
2414 | @@ -121,6 +121,13 @@ static struct dentry *proc_mount(struct file_system_type *fs_type, | ||
2415 | if (IS_ERR(sb)) | ||
2416 | return ERR_CAST(sb); | ||
2417 | |||
2418 | + /* | ||
2419 | + * procfs isn't actually a stacking filesystem; however, there is | ||
2420 | + * too much magic going on inside it to permit stacking things on | ||
2421 | + * top of it | ||
2422 | + */ | ||
2423 | + sb->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH; | ||
2424 | + | ||
2425 | if (!proc_parse_options(options, ns)) { | ||
2426 | deactivate_locked_super(sb); | ||
2427 | return ERR_PTR(-EINVAL); | ||
2428 | diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h | ||
2429 | index d5d798b35c1f..e98425058f20 100644 | ||
2430 | --- a/include/linux/irqchip/arm-gic-v3.h | ||
2431 | +++ b/include/linux/irqchip/arm-gic-v3.h | ||
2432 | @@ -301,7 +301,7 @@ | ||
2433 | #define ICC_SGI1R_AFFINITY_1_SHIFT 16 | ||
2434 | #define ICC_SGI1R_AFFINITY_1_MASK (0xff << ICC_SGI1R_AFFINITY_1_SHIFT) | ||
2435 | #define ICC_SGI1R_SGI_ID_SHIFT 24 | ||
2436 | -#define ICC_SGI1R_SGI_ID_MASK (0xff << ICC_SGI1R_SGI_ID_SHIFT) | ||
2437 | +#define ICC_SGI1R_SGI_ID_MASK (0xfULL << ICC_SGI1R_SGI_ID_SHIFT) | ||
2438 | #define ICC_SGI1R_AFFINITY_2_SHIFT 32 | ||
2439 | #define ICC_SGI1R_AFFINITY_2_MASK (0xffULL << ICC_SGI1R_AFFINITY_1_SHIFT) | ||
2440 | #define ICC_SGI1R_IRQ_ROUTING_MODE_BIT 40 | ||
2441 | diff --git a/include/linux/netfilter/x_tables.h b/include/linux/netfilter/x_tables.h | ||
2442 | index c5577410c25d..04078e8a4803 100644 | ||
2443 | --- a/include/linux/netfilter/x_tables.h | ||
2444 | +++ b/include/linux/netfilter/x_tables.h | ||
2445 | @@ -239,11 +239,18 @@ void xt_unregister_match(struct xt_match *target); | ||
2446 | int xt_register_matches(struct xt_match *match, unsigned int n); | ||
2447 | void xt_unregister_matches(struct xt_match *match, unsigned int n); | ||
2448 | |||
2449 | +int xt_check_entry_offsets(const void *base, const char *elems, | ||
2450 | + unsigned int target_offset, | ||
2451 | + unsigned int next_offset); | ||
2452 | + | ||
2453 | int xt_check_match(struct xt_mtchk_param *, unsigned int size, u_int8_t proto, | ||
2454 | bool inv_proto); | ||
2455 | int xt_check_target(struct xt_tgchk_param *, unsigned int size, u_int8_t proto, | ||
2456 | bool inv_proto); | ||
2457 | |||
2458 | +void *xt_copy_counters_from_user(const void __user *user, unsigned int len, | ||
2459 | + struct xt_counters_info *info, bool compat); | ||
2460 | + | ||
2461 | struct xt_table *xt_register_table(struct net *net, | ||
2462 | const struct xt_table *table, | ||
2463 | struct xt_table_info *bootstrap, | ||
2464 | @@ -478,7 +485,7 @@ void xt_compat_init_offsets(u_int8_t af, unsigned int number); | ||
2465 | int xt_compat_calc_jump(u_int8_t af, unsigned int offset); | ||
2466 | |||
2467 | int xt_compat_match_offset(const struct xt_match *match); | ||
2468 | -int xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr, | ||
2469 | +void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr, | ||
2470 | unsigned int *size); | ||
2471 | int xt_compat_match_to_user(const struct xt_entry_match *m, | ||
2472 | void __user **dstptr, unsigned int *size); | ||
2473 | @@ -488,6 +495,9 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr, | ||
2474 | unsigned int *size); | ||
2475 | int xt_compat_target_to_user(const struct xt_entry_target *t, | ||
2476 | void __user **dstptr, unsigned int *size); | ||
2477 | +int xt_compat_check_entry_offsets(const void *base, const char *elems, | ||
2478 | + unsigned int target_offset, | ||
2479 | + unsigned int next_offset); | ||
2480 | |||
2481 | #endif /* CONFIG_COMPAT */ | ||
2482 | #endif /* _X_TABLES_H */ | ||
2483 | diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h | ||
2484 | index 62a750a6a8f8..af40bc586a1b 100644 | ||
2485 | --- a/include/net/ip_tunnels.h | ||
2486 | +++ b/include/net/ip_tunnels.h | ||
2487 | @@ -230,6 +230,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, | ||
2488 | int ip_tunnel_ioctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd); | ||
2489 | int ip_tunnel_encap(struct sk_buff *skb, struct ip_tunnel *t, | ||
2490 | u8 *protocol, struct flowi4 *fl4); | ||
2491 | +int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict); | ||
2492 | int ip_tunnel_change_mtu(struct net_device *dev, int new_mtu); | ||
2493 | |||
2494 | struct rtnl_link_stats64 *ip_tunnel_get_stats64(struct net_device *dev, | ||
2495 | diff --git a/include/net/switchdev.h b/include/net/switchdev.h | ||
2496 | index 1d22ce9f352e..31d0e5143848 100644 | ||
2497 | --- a/include/net/switchdev.h | ||
2498 | +++ b/include/net/switchdev.h | ||
2499 | @@ -88,7 +88,7 @@ struct switchdev_obj_ipv4_fib { | ||
2500 | struct switchdev_obj obj; | ||
2501 | u32 dst; | ||
2502 | int dst_len; | ||
2503 | - struct fib_info fi; | ||
2504 | + struct fib_info *fi; | ||
2505 | u8 tos; | ||
2506 | u8 type; | ||
2507 | u32 nlflags; | ||
2508 | diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h | ||
2509 | index d5e38c73377c..e4f048ee7043 100644 | ||
2510 | --- a/include/uapi/linux/libc-compat.h | ||
2511 | +++ b/include/uapi/linux/libc-compat.h | ||
2512 | @@ -52,7 +52,7 @@ | ||
2513 | #if defined(__GLIBC__) | ||
2514 | |||
2515 | /* Coordinate with glibc net/if.h header. */ | ||
2516 | -#if defined(_NET_IF_H) | ||
2517 | +#if defined(_NET_IF_H) && defined(__USE_MISC) | ||
2518 | |||
2519 | /* GLIBC headers included first so don't define anything | ||
2520 | * that would already be defined. */ | ||
2521 | diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c | ||
2522 | index d1a7646f79c5..cb85d228b1ac 100644 | ||
2523 | --- a/kernel/bpf/inode.c | ||
2524 | +++ b/kernel/bpf/inode.c | ||
2525 | @@ -358,7 +358,7 @@ static int bpf_fill_super(struct super_block *sb, void *data, int silent) | ||
2526 | static struct dentry *bpf_mount(struct file_system_type *type, int flags, | ||
2527 | const char *dev_name, void *data) | ||
2528 | { | ||
2529 | - return mount_ns(type, flags, current->nsproxy->mnt_ns, bpf_fill_super); | ||
2530 | + return mount_nodev(type, flags, data, bpf_fill_super); | ||
2531 | } | ||
2532 | |||
2533 | static struct file_system_type bpf_fs_type = { | ||
2534 | @@ -366,7 +366,6 @@ static struct file_system_type bpf_fs_type = { | ||
2535 | .name = "bpf", | ||
2536 | .mount = bpf_mount, | ||
2537 | .kill_sb = kill_litter_super, | ||
2538 | - .fs_flags = FS_USERNS_MOUNT, | ||
2539 | }; | ||
2540 | |||
2541 | MODULE_ALIAS_FS("bpf"); | ||
2542 | diff --git a/kernel/sched/core.c b/kernel/sched/core.c | ||
2543 | index 55bebf924946..6c0cdb5a73f8 100644 | ||
2544 | --- a/kernel/sched/core.c | ||
2545 | +++ b/kernel/sched/core.c | ||
2546 | @@ -3008,7 +3008,8 @@ static noinline void __schedule_bug(struct task_struct *prev) | ||
2547 | static inline void schedule_debug(struct task_struct *prev) | ||
2548 | { | ||
2549 | #ifdef CONFIG_SCHED_STACK_END_CHECK | ||
2550 | - BUG_ON(task_stack_end_corrupted(prev)); | ||
2551 | + if (task_stack_end_corrupted(prev)) | ||
2552 | + panic("corrupted stack end detected inside scheduler\n"); | ||
2553 | #endif | ||
2554 | |||
2555 | if (unlikely(in_atomic_preempt_off())) { | ||
2556 | diff --git a/mm/memcontrol.c b/mm/memcontrol.c | ||
2557 | index 6ba4dd988e2e..67648e6b2ac8 100644 | ||
2558 | --- a/mm/memcontrol.c | ||
2559 | +++ b/mm/memcontrol.c | ||
2560 | @@ -3661,6 +3661,7 @@ static void memcg_deactivate_kmem(struct mem_cgroup *memcg) | ||
2561 | * ordering is imposed by list_lru_node->lock taken by | ||
2562 | * memcg_drain_all_list_lrus(). | ||
2563 | */ | ||
2564 | + rcu_read_lock(); /* can be called from css_free w/o cgroup_mutex */ | ||
2565 | css_for_each_descendant_pre(css, &memcg->css) { | ||
2566 | child = mem_cgroup_from_css(css); | ||
2567 | BUG_ON(child->kmemcg_id != kmemcg_id); | ||
2568 | @@ -3668,6 +3669,8 @@ static void memcg_deactivate_kmem(struct mem_cgroup *memcg) | ||
2569 | if (!memcg->use_hierarchy) | ||
2570 | break; | ||
2571 | } | ||
2572 | + rcu_read_unlock(); | ||
2573 | + | ||
2574 | memcg_drain_all_list_lrus(kmemcg_id, parent->kmemcg_id); | ||
2575 | |||
2576 | memcg_free_cache_id(kmemcg_id); | ||
2577 | diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c | ||
2578 | index a642bb829d09..09442e0f7f67 100644 | ||
2579 | --- a/net/bridge/br_fdb.c | ||
2580 | +++ b/net/bridge/br_fdb.c | ||
2581 | @@ -278,6 +278,8 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr) | ||
2582 | * change from under us. | ||
2583 | */ | ||
2584 | list_for_each_entry(v, &vg->vlan_list, vlist) { | ||
2585 | + if (!br_vlan_should_use(v)) | ||
2586 | + continue; | ||
2587 | f = __br_fdb_get(br, br->dev->dev_addr, v->vid); | ||
2588 | if (f && f->is_local && !f->dst) | ||
2589 | fdb_delete_local(br, NULL, f); | ||
2590 | diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c | ||
2591 | index 7dc962b89fa1..3e4184088082 100644 | ||
2592 | --- a/net/ipv4/ip_gre.c | ||
2593 | +++ b/net/ipv4/ip_gre.c | ||
2594 | @@ -1247,6 +1247,14 @@ struct net_device *gretap_fb_dev_create(struct net *net, const char *name, | ||
2595 | err = ipgre_newlink(net, dev, tb, NULL); | ||
2596 | if (err < 0) | ||
2597 | goto out; | ||
2598 | + | ||
2599 | + /* openvswitch users expect packet sizes to be unrestricted, | ||
2600 | + * so set the largest MTU we can. | ||
2601 | + */ | ||
2602 | + err = __ip_tunnel_change_mtu(dev, IP_MAX_MTU, false); | ||
2603 | + if (err) | ||
2604 | + goto out; | ||
2605 | + | ||
2606 | return dev; | ||
2607 | out: | ||
2608 | free_netdev(dev); | ||
2609 | diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c | ||
2610 | index ce30c8b72457..3310ac75e3f3 100644 | ||
2611 | --- a/net/ipv4/ip_tunnel.c | ||
2612 | +++ b/net/ipv4/ip_tunnel.c | ||
2613 | @@ -948,17 +948,31 @@ done: | ||
2614 | } | ||
2615 | EXPORT_SYMBOL_GPL(ip_tunnel_ioctl); | ||
2616 | |||
2617 | -int ip_tunnel_change_mtu(struct net_device *dev, int new_mtu) | ||
2618 | +int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict) | ||
2619 | { | ||
2620 | struct ip_tunnel *tunnel = netdev_priv(dev); | ||
2621 | int t_hlen = tunnel->hlen + sizeof(struct iphdr); | ||
2622 | + int max_mtu = 0xFFF8 - dev->hard_header_len - t_hlen; | ||
2623 | |||
2624 | - if (new_mtu < 68 || | ||
2625 | - new_mtu > 0xFFF8 - dev->hard_header_len - t_hlen) | ||
2626 | + if (new_mtu < 68) | ||
2627 | return -EINVAL; | ||
2628 | + | ||
2629 | + if (new_mtu > max_mtu) { | ||
2630 | + if (strict) | ||
2631 | + return -EINVAL; | ||
2632 | + | ||
2633 | + new_mtu = max_mtu; | ||
2634 | + } | ||
2635 | + | ||
2636 | dev->mtu = new_mtu; | ||
2637 | return 0; | ||
2638 | } | ||
2639 | +EXPORT_SYMBOL_GPL(__ip_tunnel_change_mtu); | ||
2640 | + | ||
2641 | +int ip_tunnel_change_mtu(struct net_device *dev, int new_mtu) | ||
2642 | +{ | ||
2643 | + return __ip_tunnel_change_mtu(dev, new_mtu, true); | ||
2644 | +} | ||
2645 | EXPORT_SYMBOL_GPL(ip_tunnel_change_mtu); | ||
2646 | |||
2647 | static void ip_tunnel_dev_free(struct net_device *dev) | ||
2648 | diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c | ||
2649 | index 11dccba474b7..6e3e0e8b1ce3 100644 | ||
2650 | --- a/net/ipv4/netfilter/arp_tables.c | ||
2651 | +++ b/net/ipv4/netfilter/arp_tables.c | ||
2652 | @@ -359,11 +359,24 @@ unsigned int arpt_do_table(struct sk_buff *skb, | ||
2653 | } | ||
2654 | |||
2655 | /* All zeroes == unconditional rule. */ | ||
2656 | -static inline bool unconditional(const struct arpt_arp *arp) | ||
2657 | +static inline bool unconditional(const struct arpt_entry *e) | ||
2658 | { | ||
2659 | static const struct arpt_arp uncond; | ||
2660 | |||
2661 | - return memcmp(arp, &uncond, sizeof(uncond)) == 0; | ||
2662 | + return e->target_offset == sizeof(struct arpt_entry) && | ||
2663 | + memcmp(&e->arp, &uncond, sizeof(uncond)) == 0; | ||
2664 | +} | ||
2665 | + | ||
2666 | +static bool find_jump_target(const struct xt_table_info *t, | ||
2667 | + const struct arpt_entry *target) | ||
2668 | +{ | ||
2669 | + struct arpt_entry *iter; | ||
2670 | + | ||
2671 | + xt_entry_foreach(iter, t->entries, t->size) { | ||
2672 | + if (iter == target) | ||
2673 | + return true; | ||
2674 | + } | ||
2675 | + return false; | ||
2676 | } | ||
2677 | |||
2678 | /* Figures out from what hook each rule can be called: returns 0 if | ||
2679 | @@ -402,11 +415,10 @@ static int mark_source_chains(const struct xt_table_info *newinfo, | ||
2680 | |= ((1 << hook) | (1 << NF_ARP_NUMHOOKS)); | ||
2681 | |||
2682 | /* Unconditional return/END. */ | ||
2683 | - if ((e->target_offset == sizeof(struct arpt_entry) && | ||
2684 | + if ((unconditional(e) && | ||
2685 | (strcmp(t->target.u.user.name, | ||
2686 | XT_STANDARD_TARGET) == 0) && | ||
2687 | - t->verdict < 0 && unconditional(&e->arp)) || | ||
2688 | - visited) { | ||
2689 | + t->verdict < 0) || visited) { | ||
2690 | unsigned int oldpos, size; | ||
2691 | |||
2692 | if ((strcmp(t->target.u.user.name, | ||
2693 | @@ -439,6 +451,8 @@ static int mark_source_chains(const struct xt_table_info *newinfo, | ||
2694 | size = e->next_offset; | ||
2695 | e = (struct arpt_entry *) | ||
2696 | (entry0 + pos + size); | ||
2697 | + if (pos + size >= newinfo->size) | ||
2698 | + return 0; | ||
2699 | e->counters.pcnt = pos; | ||
2700 | pos += size; | ||
2701 | } else { | ||
2702 | @@ -458,9 +472,15 @@ static int mark_source_chains(const struct xt_table_info *newinfo, | ||
2703 | /* This a jump; chase it. */ | ||
2704 | duprintf("Jump rule %u -> %u\n", | ||
2705 | pos, newpos); | ||
2706 | + e = (struct arpt_entry *) | ||
2707 | + (entry0 + newpos); | ||
2708 | + if (!find_jump_target(newinfo, e)) | ||
2709 | + return 0; | ||
2710 | } else { | ||
2711 | /* ... this is a fallthru */ | ||
2712 | newpos = pos + e->next_offset; | ||
2713 | + if (newpos >= newinfo->size) | ||
2714 | + return 0; | ||
2715 | } | ||
2716 | e = (struct arpt_entry *) | ||
2717 | (entry0 + newpos); | ||
2718 | @@ -474,25 +494,6 @@ next: | ||
2719 | return 1; | ||
2720 | } | ||
2721 | |||
2722 | -static inline int check_entry(const struct arpt_entry *e, const char *name) | ||
2723 | -{ | ||
2724 | - const struct xt_entry_target *t; | ||
2725 | - | ||
2726 | - if (!arp_checkentry(&e->arp)) { | ||
2727 | - duprintf("arp_tables: arp check failed %p %s.\n", e, name); | ||
2728 | - return -EINVAL; | ||
2729 | - } | ||
2730 | - | ||
2731 | - if (e->target_offset + sizeof(struct xt_entry_target) > e->next_offset) | ||
2732 | - return -EINVAL; | ||
2733 | - | ||
2734 | - t = arpt_get_target_c(e); | ||
2735 | - if (e->target_offset + t->u.target_size > e->next_offset) | ||
2736 | - return -EINVAL; | ||
2737 | - | ||
2738 | - return 0; | ||
2739 | -} | ||
2740 | - | ||
2741 | static inline int check_target(struct arpt_entry *e, const char *name) | ||
2742 | { | ||
2743 | struct xt_entry_target *t = arpt_get_target(e); | ||
2744 | @@ -522,10 +523,6 @@ find_check_entry(struct arpt_entry *e, const char *name, unsigned int size) | ||
2745 | struct xt_target *target; | ||
2746 | int ret; | ||
2747 | |||
2748 | - ret = check_entry(e, name); | ||
2749 | - if (ret) | ||
2750 | - return ret; | ||
2751 | - | ||
2752 | e->counters.pcnt = xt_percpu_counter_alloc(); | ||
2753 | if (IS_ERR_VALUE(e->counters.pcnt)) | ||
2754 | return -ENOMEM; | ||
2755 | @@ -557,7 +554,7 @@ static bool check_underflow(const struct arpt_entry *e) | ||
2756 | const struct xt_entry_target *t; | ||
2757 | unsigned int verdict; | ||
2758 | |||
2759 | - if (!unconditional(&e->arp)) | ||
2760 | + if (!unconditional(e)) | ||
2761 | return false; | ||
2762 | t = arpt_get_target_c(e); | ||
2763 | if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0) | ||
2764 | @@ -576,9 +573,11 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e, | ||
2765 | unsigned int valid_hooks) | ||
2766 | { | ||
2767 | unsigned int h; | ||
2768 | + int err; | ||
2769 | |||
2770 | if ((unsigned long)e % __alignof__(struct arpt_entry) != 0 || | ||
2771 | - (unsigned char *)e + sizeof(struct arpt_entry) >= limit) { | ||
2772 | + (unsigned char *)e + sizeof(struct arpt_entry) >= limit || | ||
2773 | + (unsigned char *)e + e->next_offset > limit) { | ||
2774 | duprintf("Bad offset %p\n", e); | ||
2775 | return -EINVAL; | ||
2776 | } | ||
2777 | @@ -590,6 +589,14 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e, | ||
2778 | return -EINVAL; | ||
2779 | } | ||
2780 | |||
2781 | + if (!arp_checkentry(&e->arp)) | ||
2782 | + return -EINVAL; | ||
2783 | + | ||
2784 | + err = xt_check_entry_offsets(e, e->elems, e->target_offset, | ||
2785 | + e->next_offset); | ||
2786 | + if (err) | ||
2787 | + return err; | ||
2788 | + | ||
2789 | /* Check hooks & underflows */ | ||
2790 | for (h = 0; h < NF_ARP_NUMHOOKS; h++) { | ||
2791 | if (!(valid_hooks & (1 << h))) | ||
2792 | @@ -598,9 +605,9 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e, | ||
2793 | newinfo->hook_entry[h] = hook_entries[h]; | ||
2794 | if ((unsigned char *)e - base == underflows[h]) { | ||
2795 | if (!check_underflow(e)) { | ||
2796 | - pr_err("Underflows must be unconditional and " | ||
2797 | - "use the STANDARD target with " | ||
2798 | - "ACCEPT/DROP\n"); | ||
2799 | + pr_debug("Underflows must be unconditional and " | ||
2800 | + "use the STANDARD target with " | ||
2801 | + "ACCEPT/DROP\n"); | ||
2802 | return -EINVAL; | ||
2803 | } | ||
2804 | newinfo->underflow[h] = underflows[h]; | ||
2805 | @@ -691,10 +698,8 @@ static int translate_table(struct xt_table_info *newinfo, void *entry0, | ||
2806 | } | ||
2807 | } | ||
2808 | |||
2809 | - if (!mark_source_chains(newinfo, repl->valid_hooks, entry0)) { | ||
2810 | - duprintf("Looping hook\n"); | ||
2811 | + if (!mark_source_chains(newinfo, repl->valid_hooks, entry0)) | ||
2812 | return -ELOOP; | ||
2813 | - } | ||
2814 | |||
2815 | /* Finally, each sanity check must pass */ | ||
2816 | i = 0; | ||
2817 | @@ -1125,55 +1130,17 @@ static int do_add_counters(struct net *net, const void __user *user, | ||
2818 | unsigned int i; | ||
2819 | struct xt_counters_info tmp; | ||
2820 | struct xt_counters *paddc; | ||
2821 | - unsigned int num_counters; | ||
2822 | - const char *name; | ||
2823 | - int size; | ||
2824 | - void *ptmp; | ||
2825 | struct xt_table *t; | ||
2826 | const struct xt_table_info *private; | ||
2827 | int ret = 0; | ||
2828 | struct arpt_entry *iter; | ||
2829 | unsigned int addend; | ||
2830 | -#ifdef CONFIG_COMPAT | ||
2831 | - struct compat_xt_counters_info compat_tmp; | ||
2832 | - | ||
2833 | - if (compat) { | ||
2834 | - ptmp = &compat_tmp; | ||
2835 | - size = sizeof(struct compat_xt_counters_info); | ||
2836 | - } else | ||
2837 | -#endif | ||
2838 | - { | ||
2839 | - ptmp = &tmp; | ||
2840 | - size = sizeof(struct xt_counters_info); | ||
2841 | - } | ||
2842 | |||
2843 | - if (copy_from_user(ptmp, user, size) != 0) | ||
2844 | - return -EFAULT; | ||
2845 | - | ||
2846 | -#ifdef CONFIG_COMPAT | ||
2847 | - if (compat) { | ||
2848 | - num_counters = compat_tmp.num_counters; | ||
2849 | - name = compat_tmp.name; | ||
2850 | - } else | ||
2851 | -#endif | ||
2852 | - { | ||
2853 | - num_counters = tmp.num_counters; | ||
2854 | - name = tmp.name; | ||
2855 | - } | ||
2856 | + paddc = xt_copy_counters_from_user(user, len, &tmp, compat); | ||
2857 | + if (IS_ERR(paddc)) | ||
2858 | + return PTR_ERR(paddc); | ||
2859 | |||
2860 | - if (len != size + num_counters * sizeof(struct xt_counters)) | ||
2861 | - return -EINVAL; | ||
2862 | - | ||
2863 | - paddc = vmalloc(len - size); | ||
2864 | - if (!paddc) | ||
2865 | - return -ENOMEM; | ||
2866 | - | ||
2867 | - if (copy_from_user(paddc, user + size, len - size) != 0) { | ||
2868 | - ret = -EFAULT; | ||
2869 | - goto free; | ||
2870 | - } | ||
2871 | - | ||
2872 | - t = xt_find_table_lock(net, NFPROTO_ARP, name); | ||
2873 | + t = xt_find_table_lock(net, NFPROTO_ARP, tmp.name); | ||
2874 | if (IS_ERR_OR_NULL(t)) { | ||
2875 | ret = t ? PTR_ERR(t) : -ENOENT; | ||
2876 | goto free; | ||
2877 | @@ -1181,7 +1148,7 @@ static int do_add_counters(struct net *net, const void __user *user, | ||
2878 | |||
2879 | local_bh_disable(); | ||
2880 | private = t->private; | ||
2881 | - if (private->number != num_counters) { | ||
2882 | + if (private->number != tmp.num_counters) { | ||
2883 | ret = -EINVAL; | ||
2884 | goto unlock_up_free; | ||
2885 | } | ||
2886 | @@ -1208,6 +1175,18 @@ static int do_add_counters(struct net *net, const void __user *user, | ||
2887 | } | ||
2888 | |||
2889 | #ifdef CONFIG_COMPAT | ||
2890 | +struct compat_arpt_replace { | ||
2891 | + char name[XT_TABLE_MAXNAMELEN]; | ||
2892 | + u32 valid_hooks; | ||
2893 | + u32 num_entries; | ||
2894 | + u32 size; | ||
2895 | + u32 hook_entry[NF_ARP_NUMHOOKS]; | ||
2896 | + u32 underflow[NF_ARP_NUMHOOKS]; | ||
2897 | + u32 num_counters; | ||
2898 | + compat_uptr_t counters; | ||
2899 | + struct compat_arpt_entry entries[0]; | ||
2900 | +}; | ||
2901 | + | ||
2902 | static inline void compat_release_entry(struct compat_arpt_entry *e) | ||
2903 | { | ||
2904 | struct xt_entry_target *t; | ||
2905 | @@ -1216,24 +1195,22 @@ static inline void compat_release_entry(struct compat_arpt_entry *e) | ||
2906 | module_put(t->u.kernel.target->me); | ||
2907 | } | ||
2908 | |||
2909 | -static inline int | ||
2910 | +static int | ||
2911 | check_compat_entry_size_and_hooks(struct compat_arpt_entry *e, | ||
2912 | struct xt_table_info *newinfo, | ||
2913 | unsigned int *size, | ||
2914 | const unsigned char *base, | ||
2915 | - const unsigned char *limit, | ||
2916 | - const unsigned int *hook_entries, | ||
2917 | - const unsigned int *underflows, | ||
2918 | - const char *name) | ||
2919 | + const unsigned char *limit) | ||
2920 | { | ||
2921 | struct xt_entry_target *t; | ||
2922 | struct xt_target *target; | ||
2923 | unsigned int entry_offset; | ||
2924 | - int ret, off, h; | ||
2925 | + int ret, off; | ||
2926 | |||
2927 | duprintf("check_compat_entry_size_and_hooks %p\n", e); | ||
2928 | if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0 || | ||
2929 | - (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit) { | ||
2930 | + (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit || | ||
2931 | + (unsigned char *)e + e->next_offset > limit) { | ||
2932 | duprintf("Bad offset %p, limit = %p\n", e, limit); | ||
2933 | return -EINVAL; | ||
2934 | } | ||
2935 | @@ -1245,8 +1222,11 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e, | ||
2936 | return -EINVAL; | ||
2937 | } | ||
2938 | |||
2939 | - /* For purposes of check_entry casting the compat entry is fine */ | ||
2940 | - ret = check_entry((struct arpt_entry *)e, name); | ||
2941 | + if (!arp_checkentry(&e->arp)) | ||
2942 | + return -EINVAL; | ||
2943 | + | ||
2944 | + ret = xt_compat_check_entry_offsets(e, e->elems, e->target_offset, | ||
2945 | + e->next_offset); | ||
2946 | if (ret) | ||
2947 | return ret; | ||
2948 | |||
2949 | @@ -1270,17 +1250,6 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e, | ||
2950 | if (ret) | ||
2951 | goto release_target; | ||
2952 | |||
2953 | - /* Check hooks & underflows */ | ||
2954 | - for (h = 0; h < NF_ARP_NUMHOOKS; h++) { | ||
2955 | - if ((unsigned char *)e - base == hook_entries[h]) | ||
2956 | - newinfo->hook_entry[h] = hook_entries[h]; | ||
2957 | - if ((unsigned char *)e - base == underflows[h]) | ||
2958 | - newinfo->underflow[h] = underflows[h]; | ||
2959 | - } | ||
2960 | - | ||
2961 | - /* Clear counters and comefrom */ | ||
2962 | - memset(&e->counters, 0, sizeof(e->counters)); | ||
2963 | - e->comefrom = 0; | ||
2964 | return 0; | ||
2965 | |||
2966 | release_target: | ||
2967 | @@ -1289,18 +1258,17 @@ out: | ||
2968 | return ret; | ||
2969 | } | ||
2970 | |||
2971 | -static int | ||
2972 | +static void | ||
2973 | compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr, | ||
2974 | - unsigned int *size, const char *name, | ||
2975 | + unsigned int *size, | ||
2976 | struct xt_table_info *newinfo, unsigned char *base) | ||
2977 | { | ||
2978 | struct xt_entry_target *t; | ||
2979 | struct xt_target *target; | ||
2980 | struct arpt_entry *de; | ||
2981 | unsigned int origsize; | ||
2982 | - int ret, h; | ||
2983 | + int h; | ||
2984 | |||
2985 | - ret = 0; | ||
2986 | origsize = *size; | ||
2987 | de = (struct arpt_entry *)*dstptr; | ||
2988 | memcpy(de, e, sizeof(struct arpt_entry)); | ||
2989 | @@ -1321,148 +1289,82 @@ compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr, | ||
2990 | if ((unsigned char *)de - base < newinfo->underflow[h]) | ||
2991 | newinfo->underflow[h] -= origsize - *size; | ||
2992 | } | ||
2993 | - return ret; | ||
2994 | } | ||
2995 | |||
2996 | -static int translate_compat_table(const char *name, | ||
2997 | - unsigned int valid_hooks, | ||
2998 | - struct xt_table_info **pinfo, | ||
2999 | +static int translate_compat_table(struct xt_table_info **pinfo, | ||
3000 | void **pentry0, | ||
3001 | - unsigned int total_size, | ||
3002 | - unsigned int number, | ||
3003 | - unsigned int *hook_entries, | ||
3004 | - unsigned int *underflows) | ||
3005 | + const struct compat_arpt_replace *compatr) | ||
3006 | { | ||
3007 | unsigned int i, j; | ||
3008 | struct xt_table_info *newinfo, *info; | ||
3009 | void *pos, *entry0, *entry1; | ||
3010 | struct compat_arpt_entry *iter0; | ||
3011 | - struct arpt_entry *iter1; | ||
3012 | + struct arpt_replace repl; | ||
3013 | unsigned int size; | ||
3014 | int ret = 0; | ||
3015 | |||
3016 | info = *pinfo; | ||
3017 | entry0 = *pentry0; | ||
3018 | - size = total_size; | ||
3019 | - info->number = number; | ||
3020 | - | ||
3021 | - /* Init all hooks to impossible value. */ | ||
3022 | - for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | ||
3023 | - info->hook_entry[i] = 0xFFFFFFFF; | ||
3024 | - info->underflow[i] = 0xFFFFFFFF; | ||
3025 | - } | ||
3026 | + size = compatr->size; | ||
3027 | + info->number = compatr->num_entries; | ||
3028 | |||
3029 | duprintf("translate_compat_table: size %u\n", info->size); | ||
3030 | j = 0; | ||
3031 | xt_compat_lock(NFPROTO_ARP); | ||
3032 | - xt_compat_init_offsets(NFPROTO_ARP, number); | ||
3033 | + xt_compat_init_offsets(NFPROTO_ARP, compatr->num_entries); | ||
3034 | /* Walk through entries, checking offsets. */ | ||
3035 | - xt_entry_foreach(iter0, entry0, total_size) { | ||
3036 | + xt_entry_foreach(iter0, entry0, compatr->size) { | ||
3037 | ret = check_compat_entry_size_and_hooks(iter0, info, &size, | ||
3038 | entry0, | ||
3039 | - entry0 + total_size, | ||
3040 | - hook_entries, | ||
3041 | - underflows, | ||
3042 | - name); | ||
3043 | + entry0 + compatr->size); | ||
3044 | if (ret != 0) | ||
3045 | goto out_unlock; | ||
3046 | ++j; | ||
3047 | } | ||
3048 | |||
3049 | ret = -EINVAL; | ||
3050 | - if (j != number) { | ||
3051 | + if (j != compatr->num_entries) { | ||
3052 | duprintf("translate_compat_table: %u not %u entries\n", | ||
3053 | - j, number); | ||
3054 | + j, compatr->num_entries); | ||
3055 | goto out_unlock; | ||
3056 | } | ||
3057 | |||
3058 | - /* Check hooks all assigned */ | ||
3059 | - for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | ||
3060 | - /* Only hooks which are valid */ | ||
3061 | - if (!(valid_hooks & (1 << i))) | ||
3062 | - continue; | ||
3063 | - if (info->hook_entry[i] == 0xFFFFFFFF) { | ||
3064 | - duprintf("Invalid hook entry %u %u\n", | ||
3065 | - i, hook_entries[i]); | ||
3066 | - goto out_unlock; | ||
3067 | - } | ||
3068 | - if (info->underflow[i] == 0xFFFFFFFF) { | ||
3069 | - duprintf("Invalid underflow %u %u\n", | ||
3070 | - i, underflows[i]); | ||
3071 | - goto out_unlock; | ||
3072 | - } | ||
3073 | - } | ||
3074 | - | ||
3075 | ret = -ENOMEM; | ||
3076 | newinfo = xt_alloc_table_info(size); | ||
3077 | if (!newinfo) | ||
3078 | goto out_unlock; | ||
3079 | |||
3080 | - newinfo->number = number; | ||
3081 | + newinfo->number = compatr->num_entries; | ||
3082 | for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | ||
3083 | newinfo->hook_entry[i] = info->hook_entry[i]; | ||
3084 | newinfo->underflow[i] = info->underflow[i]; | ||
3085 | } | ||
3086 | entry1 = newinfo->entries; | ||
3087 | pos = entry1; | ||
3088 | - size = total_size; | ||
3089 | - xt_entry_foreach(iter0, entry0, total_size) { | ||
3090 | - ret = compat_copy_entry_from_user(iter0, &pos, &size, | ||
3091 | - name, newinfo, entry1); | ||
3092 | - if (ret != 0) | ||
3093 | - break; | ||
3094 | - } | ||
3095 | + size = compatr->size; | ||
3096 | + xt_entry_foreach(iter0, entry0, compatr->size) | ||
3097 | + compat_copy_entry_from_user(iter0, &pos, &size, | ||
3098 | + newinfo, entry1); | ||
3099 | + | ||
3100 | + /* all module references in entry0 are now gone */ | ||
3101 | + | ||
3102 | xt_compat_flush_offsets(NFPROTO_ARP); | ||
3103 | xt_compat_unlock(NFPROTO_ARP); | ||
3104 | - if (ret) | ||
3105 | - goto free_newinfo; | ||
3106 | |||
3107 | - ret = -ELOOP; | ||
3108 | - if (!mark_source_chains(newinfo, valid_hooks, entry1)) | ||
3109 | - goto free_newinfo; | ||
3110 | + memcpy(&repl, compatr, sizeof(*compatr)); | ||
3111 | |||
3112 | - i = 0; | ||
3113 | - xt_entry_foreach(iter1, entry1, newinfo->size) { | ||
3114 | - iter1->counters.pcnt = xt_percpu_counter_alloc(); | ||
3115 | - if (IS_ERR_VALUE(iter1->counters.pcnt)) { | ||
3116 | - ret = -ENOMEM; | ||
3117 | - break; | ||
3118 | - } | ||
3119 | - | ||
3120 | - ret = check_target(iter1, name); | ||
3121 | - if (ret != 0) { | ||
3122 | - xt_percpu_counter_free(iter1->counters.pcnt); | ||
3123 | - break; | ||
3124 | - } | ||
3125 | - ++i; | ||
3126 | - if (strcmp(arpt_get_target(iter1)->u.user.name, | ||
3127 | - XT_ERROR_TARGET) == 0) | ||
3128 | - ++newinfo->stacksize; | ||
3129 | - } | ||
3130 | - if (ret) { | ||
3131 | - /* | ||
3132 | - * The first i matches need cleanup_entry (calls ->destroy) | ||
3133 | - * because they had called ->check already. The other j-i | ||
3134 | - * entries need only release. | ||
3135 | - */ | ||
3136 | - int skip = i; | ||
3137 | - j -= i; | ||
3138 | - xt_entry_foreach(iter0, entry0, newinfo->size) { | ||
3139 | - if (skip-- > 0) | ||
3140 | - continue; | ||
3141 | - if (j-- == 0) | ||
3142 | - break; | ||
3143 | - compat_release_entry(iter0); | ||
3144 | - } | ||
3145 | - xt_entry_foreach(iter1, entry1, newinfo->size) { | ||
3146 | - if (i-- == 0) | ||
3147 | - break; | ||
3148 | - cleanup_entry(iter1); | ||
3149 | - } | ||
3150 | - xt_free_table_info(newinfo); | ||
3151 | - return ret; | ||
3152 | + for (i = 0; i < NF_ARP_NUMHOOKS; i++) { | ||
3153 | + repl.hook_entry[i] = newinfo->hook_entry[i]; | ||
3154 | + repl.underflow[i] = newinfo->underflow[i]; | ||
3155 | } | ||
3156 | |||
3157 | + repl.num_counters = 0; | ||
3158 | + repl.counters = NULL; | ||
3159 | + repl.size = newinfo->size; | ||
3160 | + ret = translate_table(newinfo, entry1, &repl); | ||
3161 | + if (ret) | ||
3162 | + goto free_newinfo; | ||
3163 | + | ||
3164 | *pinfo = newinfo; | ||
3165 | *pentry0 = entry1; | ||
3166 | xt_free_table_info(info); | ||
3167 | @@ -1470,31 +1372,18 @@ static int translate_compat_table(const char *name, | ||
3168 | |||
3169 | free_newinfo: | ||
3170 | xt_free_table_info(newinfo); | ||
3171 | -out: | ||
3172 | - xt_entry_foreach(iter0, entry0, total_size) { | ||
3173 | + return ret; | ||
3174 | +out_unlock: | ||
3175 | + xt_compat_flush_offsets(NFPROTO_ARP); | ||
3176 | + xt_compat_unlock(NFPROTO_ARP); | ||
3177 | + xt_entry_foreach(iter0, entry0, compatr->size) { | ||
3178 | if (j-- == 0) | ||
3179 | break; | ||
3180 | compat_release_entry(iter0); | ||
3181 | } | ||
3182 | return ret; | ||
3183 | -out_unlock: | ||
3184 | - xt_compat_flush_offsets(NFPROTO_ARP); | ||
3185 | - xt_compat_unlock(NFPROTO_ARP); | ||
3186 | - goto out; | ||
3187 | } | ||
3188 | |||
3189 | -struct compat_arpt_replace { | ||
3190 | - char name[XT_TABLE_MAXNAMELEN]; | ||
3191 | - u32 valid_hooks; | ||
3192 | - u32 num_entries; | ||
3193 | - u32 size; | ||
3194 | - u32 hook_entry[NF_ARP_NUMHOOKS]; | ||
3195 | - u32 underflow[NF_ARP_NUMHOOKS]; | ||
3196 | - u32 num_counters; | ||
3197 | - compat_uptr_t counters; | ||
3198 | - struct compat_arpt_entry entries[0]; | ||
3199 | -}; | ||
3200 | - | ||
3201 | static int compat_do_replace(struct net *net, void __user *user, | ||
3202 | unsigned int len) | ||
3203 | { | ||
3204 | @@ -1527,10 +1416,7 @@ static int compat_do_replace(struct net *net, void __user *user, | ||
3205 | goto free_newinfo; | ||
3206 | } | ||
3207 | |||
3208 | - ret = translate_compat_table(tmp.name, tmp.valid_hooks, | ||
3209 | - &newinfo, &loc_cpu_entry, tmp.size, | ||
3210 | - tmp.num_entries, tmp.hook_entry, | ||
3211 | - tmp.underflow); | ||
3212 | + ret = translate_compat_table(&newinfo, &loc_cpu_entry, &tmp); | ||
3213 | if (ret != 0) | ||
3214 | goto free_newinfo; | ||
3215 | |||
3216 | diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c | ||
3217 | index b99affad6ba1..a399c5419622 100644 | ||
3218 | --- a/net/ipv4/netfilter/ip_tables.c | ||
3219 | +++ b/net/ipv4/netfilter/ip_tables.c | ||
3220 | @@ -168,11 +168,12 @@ get_entry(const void *base, unsigned int offset) | ||
3221 | |||
3222 | /* All zeroes == unconditional rule. */ | ||
3223 | /* Mildly perf critical (only if packet tracing is on) */ | ||
3224 | -static inline bool unconditional(const struct ipt_ip *ip) | ||
3225 | +static inline bool unconditional(const struct ipt_entry *e) | ||
3226 | { | ||
3227 | static const struct ipt_ip uncond; | ||
3228 | |||
3229 | - return memcmp(ip, &uncond, sizeof(uncond)) == 0; | ||
3230 | + return e->target_offset == sizeof(struct ipt_entry) && | ||
3231 | + memcmp(&e->ip, &uncond, sizeof(uncond)) == 0; | ||
3232 | #undef FWINV | ||
3233 | } | ||
3234 | |||
3235 | @@ -229,11 +230,10 @@ get_chainname_rulenum(const struct ipt_entry *s, const struct ipt_entry *e, | ||
3236 | } else if (s == e) { | ||
3237 | (*rulenum)++; | ||
3238 | |||
3239 | - if (s->target_offset == sizeof(struct ipt_entry) && | ||
3240 | + if (unconditional(s) && | ||
3241 | strcmp(t->target.u.kernel.target->name, | ||
3242 | XT_STANDARD_TARGET) == 0 && | ||
3243 | - t->verdict < 0 && | ||
3244 | - unconditional(&s->ip)) { | ||
3245 | + t->verdict < 0) { | ||
3246 | /* Tail of chains: STANDARD target (return/policy) */ | ||
3247 | *comment = *chainname == hookname | ||
3248 | ? comments[NF_IP_TRACE_COMMENT_POLICY] | ||
3249 | @@ -443,6 +443,18 @@ ipt_do_table(struct sk_buff *skb, | ||
3250 | #endif | ||
3251 | } | ||
3252 | |||
3253 | +static bool find_jump_target(const struct xt_table_info *t, | ||
3254 | + const struct ipt_entry *target) | ||
3255 | +{ | ||
3256 | + struct ipt_entry *iter; | ||
3257 | + | ||
3258 | + xt_entry_foreach(iter, t->entries, t->size) { | ||
3259 | + if (iter == target) | ||
3260 | + return true; | ||
3261 | + } | ||
3262 | + return false; | ||
3263 | +} | ||
3264 | + | ||
3265 | /* Figures out from what hook each rule can be called: returns 0 if | ||
3266 | there are loops. Puts hook bitmask in comefrom. */ | ||
3267 | static int | ||
3268 | @@ -476,11 +488,10 @@ mark_source_chains(const struct xt_table_info *newinfo, | ||
3269 | e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS)); | ||
3270 | |||
3271 | /* Unconditional return/END. */ | ||
3272 | - if ((e->target_offset == sizeof(struct ipt_entry) && | ||
3273 | + if ((unconditional(e) && | ||
3274 | (strcmp(t->target.u.user.name, | ||
3275 | XT_STANDARD_TARGET) == 0) && | ||
3276 | - t->verdict < 0 && unconditional(&e->ip)) || | ||
3277 | - visited) { | ||
3278 | + t->verdict < 0) || visited) { | ||
3279 | unsigned int oldpos, size; | ||
3280 | |||
3281 | if ((strcmp(t->target.u.user.name, | ||
3282 | @@ -521,6 +532,8 @@ mark_source_chains(const struct xt_table_info *newinfo, | ||
3283 | size = e->next_offset; | ||
3284 | e = (struct ipt_entry *) | ||
3285 | (entry0 + pos + size); | ||
3286 | + if (pos + size >= newinfo->size) | ||
3287 | + return 0; | ||
3288 | e->counters.pcnt = pos; | ||
3289 | pos += size; | ||
3290 | } else { | ||
3291 | @@ -539,9 +552,15 @@ mark_source_chains(const struct xt_table_info *newinfo, | ||
3292 | /* This a jump; chase it. */ | ||
3293 | duprintf("Jump rule %u -> %u\n", | ||
3294 | pos, newpos); | ||
3295 | + e = (struct ipt_entry *) | ||
3296 | + (entry0 + newpos); | ||
3297 | + if (!find_jump_target(newinfo, e)) | ||
3298 | + return 0; | ||
3299 | } else { | ||
3300 | /* ... this is a fallthru */ | ||
3301 | newpos = pos + e->next_offset; | ||
3302 | + if (newpos >= newinfo->size) | ||
3303 | + return 0; | ||
3304 | } | ||
3305 | e = (struct ipt_entry *) | ||
3306 | (entry0 + newpos); | ||
3307 | @@ -569,27 +588,6 @@ static void cleanup_match(struct xt_entry_match *m, struct net *net) | ||
3308 | } | ||
3309 | |||
3310 | static int | ||
3311 | -check_entry(const struct ipt_entry *e, const char *name) | ||
3312 | -{ | ||
3313 | - const struct xt_entry_target *t; | ||
3314 | - | ||
3315 | - if (!ip_checkentry(&e->ip)) { | ||
3316 | - duprintf("ip check failed %p %s.\n", e, name); | ||
3317 | - return -EINVAL; | ||
3318 | - } | ||
3319 | - | ||
3320 | - if (e->target_offset + sizeof(struct xt_entry_target) > | ||
3321 | - e->next_offset) | ||
3322 | - return -EINVAL; | ||
3323 | - | ||
3324 | - t = ipt_get_target_c(e); | ||
3325 | - if (e->target_offset + t->u.target_size > e->next_offset) | ||
3326 | - return -EINVAL; | ||
3327 | - | ||
3328 | - return 0; | ||
3329 | -} | ||
3330 | - | ||
3331 | -static int | ||
3332 | check_match(struct xt_entry_match *m, struct xt_mtchk_param *par) | ||
3333 | { | ||
3334 | const struct ipt_ip *ip = par->entryinfo; | ||
3335 | @@ -666,10 +664,6 @@ find_check_entry(struct ipt_entry *e, struct net *net, const char *name, | ||
3336 | struct xt_mtchk_param mtpar; | ||
3337 | struct xt_entry_match *ematch; | ||
3338 | |||
3339 | - ret = check_entry(e, name); | ||
3340 | - if (ret) | ||
3341 | - return ret; | ||
3342 | - | ||
3343 | e->counters.pcnt = xt_percpu_counter_alloc(); | ||
3344 | if (IS_ERR_VALUE(e->counters.pcnt)) | ||
3345 | return -ENOMEM; | ||
3346 | @@ -721,7 +715,7 @@ static bool check_underflow(const struct ipt_entry *e) | ||
3347 | const struct xt_entry_target *t; | ||
3348 | unsigned int verdict; | ||
3349 | |||
3350 | - if (!unconditional(&e->ip)) | ||
3351 | + if (!unconditional(e)) | ||
3352 | return false; | ||
3353 | t = ipt_get_target_c(e); | ||
3354 | if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0) | ||
3355 | @@ -741,9 +735,11 @@ check_entry_size_and_hooks(struct ipt_entry *e, | ||
3356 | unsigned int valid_hooks) | ||
3357 | { | ||
3358 | unsigned int h; | ||
3359 | + int err; | ||
3360 | |||
3361 | if ((unsigned long)e % __alignof__(struct ipt_entry) != 0 || | ||
3362 | - (unsigned char *)e + sizeof(struct ipt_entry) >= limit) { | ||
3363 | + (unsigned char *)e + sizeof(struct ipt_entry) >= limit || | ||
3364 | + (unsigned char *)e + e->next_offset > limit) { | ||
3365 | duprintf("Bad offset %p\n", e); | ||
3366 | return -EINVAL; | ||
3367 | } | ||
3368 | @@ -755,6 +751,14 @@ check_entry_size_and_hooks(struct ipt_entry *e, | ||
3369 | return -EINVAL; | ||
3370 | } | ||
3371 | |||
3372 | + if (!ip_checkentry(&e->ip)) | ||
3373 | + return -EINVAL; | ||
3374 | + | ||
3375 | + err = xt_check_entry_offsets(e, e->elems, e->target_offset, | ||
3376 | + e->next_offset); | ||
3377 | + if (err) | ||
3378 | + return err; | ||
3379 | + | ||
3380 | /* Check hooks & underflows */ | ||
3381 | for (h = 0; h < NF_INET_NUMHOOKS; h++) { | ||
3382 | if (!(valid_hooks & (1 << h))) | ||
3383 | @@ -763,9 +767,9 @@ check_entry_size_and_hooks(struct ipt_entry *e, | ||
3384 | newinfo->hook_entry[h] = hook_entries[h]; | ||
3385 | if ((unsigned char *)e - base == underflows[h]) { | ||
3386 | if (!check_underflow(e)) { | ||
3387 | - pr_err("Underflows must be unconditional and " | ||
3388 | - "use the STANDARD target with " | ||
3389 | - "ACCEPT/DROP\n"); | ||
3390 | + pr_debug("Underflows must be unconditional and " | ||
3391 | + "use the STANDARD target with " | ||
3392 | + "ACCEPT/DROP\n"); | ||
3393 | return -EINVAL; | ||
3394 | } | ||
3395 | newinfo->underflow[h] = underflows[h]; | ||
3396 | @@ -1309,55 +1313,17 @@ do_add_counters(struct net *net, const void __user *user, | ||
3397 | unsigned int i; | ||
3398 | struct xt_counters_info tmp; | ||
3399 | struct xt_counters *paddc; | ||
3400 | - unsigned int num_counters; | ||
3401 | - const char *name; | ||
3402 | - int size; | ||
3403 | - void *ptmp; | ||
3404 | struct xt_table *t; | ||
3405 | const struct xt_table_info *private; | ||
3406 | int ret = 0; | ||
3407 | struct ipt_entry *iter; | ||
3408 | unsigned int addend; | ||
3409 | -#ifdef CONFIG_COMPAT | ||
3410 | - struct compat_xt_counters_info compat_tmp; | ||
3411 | - | ||
3412 | - if (compat) { | ||
3413 | - ptmp = &compat_tmp; | ||
3414 | - size = sizeof(struct compat_xt_counters_info); | ||
3415 | - } else | ||
3416 | -#endif | ||
3417 | - { | ||
3418 | - ptmp = &tmp; | ||
3419 | - size = sizeof(struct xt_counters_info); | ||
3420 | - } | ||
3421 | - | ||
3422 | - if (copy_from_user(ptmp, user, size) != 0) | ||
3423 | - return -EFAULT; | ||
3424 | - | ||
3425 | -#ifdef CONFIG_COMPAT | ||
3426 | - if (compat) { | ||
3427 | - num_counters = compat_tmp.num_counters; | ||
3428 | - name = compat_tmp.name; | ||
3429 | - } else | ||
3430 | -#endif | ||
3431 | - { | ||
3432 | - num_counters = tmp.num_counters; | ||
3433 | - name = tmp.name; | ||
3434 | - } | ||
3435 | |||
3436 | - if (len != size + num_counters * sizeof(struct xt_counters)) | ||
3437 | - return -EINVAL; | ||
3438 | - | ||
3439 | - paddc = vmalloc(len - size); | ||
3440 | - if (!paddc) | ||
3441 | - return -ENOMEM; | ||
3442 | + paddc = xt_copy_counters_from_user(user, len, &tmp, compat); | ||
3443 | + if (IS_ERR(paddc)) | ||
3444 | + return PTR_ERR(paddc); | ||
3445 | |||
3446 | - if (copy_from_user(paddc, user + size, len - size) != 0) { | ||
3447 | - ret = -EFAULT; | ||
3448 | - goto free; | ||
3449 | - } | ||
3450 | - | ||
3451 | - t = xt_find_table_lock(net, AF_INET, name); | ||
3452 | + t = xt_find_table_lock(net, AF_INET, tmp.name); | ||
3453 | if (IS_ERR_OR_NULL(t)) { | ||
3454 | ret = t ? PTR_ERR(t) : -ENOENT; | ||
3455 | goto free; | ||
3456 | @@ -1365,7 +1331,7 @@ do_add_counters(struct net *net, const void __user *user, | ||
3457 | |||
3458 | local_bh_disable(); | ||
3459 | private = t->private; | ||
3460 | - if (private->number != num_counters) { | ||
3461 | + if (private->number != tmp.num_counters) { | ||
3462 | ret = -EINVAL; | ||
3463 | goto unlock_up_free; | ||
3464 | } | ||
3465 | @@ -1444,7 +1410,6 @@ compat_copy_entry_to_user(struct ipt_entry *e, void __user **dstptr, | ||
3466 | |||
3467 | static int | ||
3468 | compat_find_calc_match(struct xt_entry_match *m, | ||
3469 | - const char *name, | ||
3470 | const struct ipt_ip *ip, | ||
3471 | int *size) | ||
3472 | { | ||
3473 | @@ -1479,21 +1444,19 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e, | ||
3474 | struct xt_table_info *newinfo, | ||
3475 | unsigned int *size, | ||
3476 | const unsigned char *base, | ||
3477 | - const unsigned char *limit, | ||
3478 | - const unsigned int *hook_entries, | ||
3479 | - const unsigned int *underflows, | ||
3480 | - const char *name) | ||
3481 | + const unsigned char *limit) | ||
3482 | { | ||
3483 | struct xt_entry_match *ematch; | ||
3484 | struct xt_entry_target *t; | ||
3485 | struct xt_target *target; | ||
3486 | unsigned int entry_offset; | ||
3487 | unsigned int j; | ||
3488 | - int ret, off, h; | ||
3489 | + int ret, off; | ||
3490 | |||
3491 | duprintf("check_compat_entry_size_and_hooks %p\n", e); | ||
3492 | if ((unsigned long)e % __alignof__(struct compat_ipt_entry) != 0 || | ||
3493 | - (unsigned char *)e + sizeof(struct compat_ipt_entry) >= limit) { | ||
3494 | + (unsigned char *)e + sizeof(struct compat_ipt_entry) >= limit || | ||
3495 | + (unsigned char *)e + e->next_offset > limit) { | ||
3496 | duprintf("Bad offset %p, limit = %p\n", e, limit); | ||
3497 | return -EINVAL; | ||
3498 | } | ||
3499 | @@ -1505,8 +1468,11 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e, | ||
3500 | return -EINVAL; | ||
3501 | } | ||
3502 | |||
3503 | - /* For purposes of check_entry casting the compat entry is fine */ | ||
3504 | - ret = check_entry((struct ipt_entry *)e, name); | ||
3505 | + if (!ip_checkentry(&e->ip)) | ||
3506 | + return -EINVAL; | ||
3507 | + | ||
3508 | + ret = xt_compat_check_entry_offsets(e, e->elems, | ||
3509 | + e->target_offset, e->next_offset); | ||
3510 | if (ret) | ||
3511 | return ret; | ||
3512 | |||
3513 | @@ -1514,7 +1480,7 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e, | ||
3514 | entry_offset = (void *)e - (void *)base; | ||
3515 | j = 0; | ||
3516 | xt_ematch_foreach(ematch, e) { | ||
3517 | - ret = compat_find_calc_match(ematch, name, &e->ip, &off); | ||
3518 | + ret = compat_find_calc_match(ematch, &e->ip, &off); | ||
3519 | if (ret != 0) | ||
3520 | goto release_matches; | ||
3521 | ++j; | ||
3522 | @@ -1537,17 +1503,6 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e, | ||
3523 | if (ret) | ||
3524 | goto out; | ||
3525 | |||
3526 | - /* Check hooks & underflows */ | ||
3527 | - for (h = 0; h < NF_INET_NUMHOOKS; h++) { | ||
3528 | - if ((unsigned char *)e - base == hook_entries[h]) | ||
3529 | - newinfo->hook_entry[h] = hook_entries[h]; | ||
3530 | - if ((unsigned char *)e - base == underflows[h]) | ||
3531 | - newinfo->underflow[h] = underflows[h]; | ||
3532 | - } | ||
3533 | - | ||
3534 | - /* Clear counters and comefrom */ | ||
3535 | - memset(&e->counters, 0, sizeof(e->counters)); | ||
3536 | - e->comefrom = 0; | ||
3537 | return 0; | ||
3538 | |||
3539 | out: | ||
3540 | @@ -1561,19 +1516,18 @@ release_matches: | ||
3541 | return ret; | ||
3542 | } | ||
3543 | |||
3544 | -static int | ||
3545 | +static void | ||
3546 | compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr, | ||
3547 | - unsigned int *size, const char *name, | ||
3548 | + unsigned int *size, | ||
3549 | struct xt_table_info *newinfo, unsigned char *base) | ||
3550 | { | ||
3551 | struct xt_entry_target *t; | ||
3552 | struct xt_target *target; | ||
3553 | struct ipt_entry *de; | ||
3554 | unsigned int origsize; | ||
3555 | - int ret, h; | ||
3556 | + int h; | ||
3557 | struct xt_entry_match *ematch; | ||
3558 | |||
3559 | - ret = 0; | ||
3560 | origsize = *size; | ||
3561 | de = (struct ipt_entry *)*dstptr; | ||
3562 | memcpy(de, e, sizeof(struct ipt_entry)); | ||
3563 | @@ -1582,201 +1536,105 @@ compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr, | ||
3564 | *dstptr += sizeof(struct ipt_entry); | ||
3565 | *size += sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry); | ||
3566 | |||
3567 | - xt_ematch_foreach(ematch, e) { | ||
3568 | - ret = xt_compat_match_from_user(ematch, dstptr, size); | ||
3569 | - if (ret != 0) | ||
3570 | - return ret; | ||
3571 | - } | ||
3572 | + xt_ematch_foreach(ematch, e) | ||
3573 | + xt_compat_match_from_user(ematch, dstptr, size); | ||
3574 | + | ||
3575 | de->target_offset = e->target_offset - (origsize - *size); | ||
3576 | t = compat_ipt_get_target(e); | ||
3577 | target = t->u.kernel.target; | ||
3578 | xt_compat_target_from_user(t, dstptr, size); | ||
3579 | |||
3580 | de->next_offset = e->next_offset - (origsize - *size); | ||
3581 | + | ||
3582 | for (h = 0; h < NF_INET_NUMHOOKS; h++) { | ||
3583 | if ((unsigned char *)de - base < newinfo->hook_entry[h]) | ||
3584 | newinfo->hook_entry[h] -= origsize - *size; | ||
3585 | if ((unsigned char *)de - base < newinfo->underflow[h]) | ||
3586 | newinfo->underflow[h] -= origsize - *size; | ||
3587 | } | ||
3588 | - return ret; | ||
3589 | -} | ||
3590 | - | ||
3591 | -static int | ||
3592 | -compat_check_entry(struct ipt_entry *e, struct net *net, const char *name) | ||
3593 | -{ | ||
3594 | - struct xt_entry_match *ematch; | ||
3595 | - struct xt_mtchk_param mtpar; | ||
3596 | - unsigned int j; | ||
3597 | - int ret = 0; | ||
3598 | - | ||
3599 | - e->counters.pcnt = xt_percpu_counter_alloc(); | ||
3600 | - if (IS_ERR_VALUE(e->counters.pcnt)) | ||
3601 | - return -ENOMEM; | ||
3602 | - | ||
3603 | - j = 0; | ||
3604 | - mtpar.net = net; | ||
3605 | - mtpar.table = name; | ||
3606 | - mtpar.entryinfo = &e->ip; | ||
3607 | - mtpar.hook_mask = e->comefrom; | ||
3608 | - mtpar.family = NFPROTO_IPV4; | ||
3609 | - xt_ematch_foreach(ematch, e) { | ||
3610 | - ret = check_match(ematch, &mtpar); | ||
3611 | - if (ret != 0) | ||
3612 | - goto cleanup_matches; | ||
3613 | - ++j; | ||
3614 | - } | ||
3615 | - | ||
3616 | - ret = check_target(e, net, name); | ||
3617 | - if (ret) | ||
3618 | - goto cleanup_matches; | ||
3619 | - return 0; | ||
3620 | - | ||
3621 | - cleanup_matches: | ||
3622 | - xt_ematch_foreach(ematch, e) { | ||
3623 | - if (j-- == 0) | ||
3624 | - break; | ||
3625 | - cleanup_match(ematch, net); | ||
3626 | - } | ||
3627 | - | ||
3628 | - xt_percpu_counter_free(e->counters.pcnt); | ||
3629 | - | ||
3630 | - return ret; | ||
3631 | } | ||
3632 | |||
3633 | static int | ||
3634 | translate_compat_table(struct net *net, | ||
3635 | - const char *name, | ||
3636 | - unsigned int valid_hooks, | ||
3637 | struct xt_table_info **pinfo, | ||
3638 | void **pentry0, | ||
3639 | - unsigned int total_size, | ||
3640 | - unsigned int number, | ||
3641 | - unsigned int *hook_entries, | ||
3642 | - unsigned int *underflows) | ||
3643 | + const struct compat_ipt_replace *compatr) | ||
3644 | { | ||
3645 | unsigned int i, j; | ||
3646 | struct xt_table_info *newinfo, *info; | ||
3647 | void *pos, *entry0, *entry1; | ||
3648 | struct compat_ipt_entry *iter0; | ||
3649 | - struct ipt_entry *iter1; | ||
3650 | + struct ipt_replace repl; | ||
3651 | unsigned int size; | ||
3652 | int ret; | ||
3653 | |||
3654 | info = *pinfo; | ||
3655 | entry0 = *pentry0; | ||
3656 | - size = total_size; | ||
3657 | - info->number = number; | ||
3658 | - | ||
3659 | - /* Init all hooks to impossible value. */ | ||
3660 | - for (i = 0; i < NF_INET_NUMHOOKS; i++) { | ||
3661 | - info->hook_entry[i] = 0xFFFFFFFF; | ||
3662 | - info->underflow[i] = 0xFFFFFFFF; | ||
3663 | - } | ||
3664 | + size = compatr->size; | ||
3665 | + info->number = compatr->num_entries; | ||
3666 | |||
3667 | duprintf("translate_compat_table: size %u\n", info->size); | ||
3668 | j = 0; | ||
3669 | xt_compat_lock(AF_INET); | ||
3670 | - xt_compat_init_offsets(AF_INET, number); | ||
3671 | + xt_compat_init_offsets(AF_INET, compatr->num_entries); | ||
3672 | /* Walk through entries, checking offsets. */ | ||
3673 | - xt_entry_foreach(iter0, entry0, total_size) { | ||
3674 | + xt_entry_foreach(iter0, entry0, compatr->size) { | ||
3675 | ret = check_compat_entry_size_and_hooks(iter0, info, &size, | ||
3676 | entry0, | ||
3677 | - entry0 + total_size, | ||
3678 | - hook_entries, | ||
3679 | - underflows, | ||
3680 | - name); | ||
3681 | + entry0 + compatr->size); | ||
3682 | if (ret != 0) | ||
3683 | goto out_unlock; | ||
3684 | ++j; | ||
3685 | } | ||
3686 | |||
3687 | ret = -EINVAL; | ||
3688 | - if (j != number) { | ||
3689 | + if (j != compatr->num_entries) { | ||
3690 | duprintf("translate_compat_table: %u not %u entries\n", | ||
3691 | - j, number); | ||
3692 | + j, compatr->num_entries); | ||
3693 | goto out_unlock; | ||
3694 | } | ||
3695 | |||
3696 | - /* Check hooks all assigned */ | ||
3697 | - for (i = 0; i < NF_INET_NUMHOOKS; i++) { | ||
3698 | - /* Only hooks which are valid */ | ||
3699 | - if (!(valid_hooks & (1 << i))) | ||
3700 | - continue; | ||
3701 | - if (info->hook_entry[i] == 0xFFFFFFFF) { | ||
3702 | - duprintf("Invalid hook entry %u %u\n", | ||
3703 | - i, hook_entries[i]); | ||
3704 | - goto out_unlock; | ||
3705 | - } | ||
3706 | - if (info->underflow[i] == 0xFFFFFFFF) { | ||
3707 | - duprintf("Invalid underflow %u %u\n", | ||
3708 | - i, underflows[i]); | ||
3709 | - goto out_unlock; | ||
3710 | - } | ||
3711 | - } | ||
3712 | - | ||
3713 | ret = -ENOMEM; | ||
3714 | newinfo = xt_alloc_table_info(size); | ||
3715 | if (!newinfo) | ||
3716 | goto out_unlock; | ||
3717 | |||
3718 | - newinfo->number = number; | ||
3719 | + newinfo->number = compatr->num_entries; | ||
3720 | for (i = 0; i < NF_INET_NUMHOOKS; i++) { | ||
3721 | - newinfo->hook_entry[i] = info->hook_entry[i]; | ||
3722 | - newinfo->underflow[i] = info->underflow[i]; | ||
3723 | + newinfo->hook_entry[i] = compatr->hook_entry[i]; | ||
3724 | + newinfo->underflow[i] = compatr->underflow[i]; | ||
3725 | } | ||
3726 | entry1 = newinfo->entries; | ||
3727 | pos = entry1; | ||
3728 | - size = total_size; | ||
3729 | - xt_entry_foreach(iter0, entry0, total_size) { | ||
3730 | - ret = compat_copy_entry_from_user(iter0, &pos, &size, | ||
3731 | - name, newinfo, entry1); | ||
3732 | - if (ret != 0) | ||
3733 | - break; | ||
3734 | - } | ||
3735 | + size = compatr->size; | ||
3736 | + xt_entry_foreach(iter0, entry0, compatr->size) | ||
3737 | + compat_copy_entry_from_user(iter0, &pos, &size, | ||
3738 | + newinfo, entry1); | ||
3739 | + | ||
3740 | + /* all module references in entry0 are now gone. | ||
3741 | + * entry1/newinfo contains a 64bit ruleset that looks exactly as | ||
3742 | + * generated by 64bit userspace. | ||
3743 | + * | ||
3744 | + * Call standard translate_table() to validate all hook_entrys, | ||
3745 | + * underflows, check for loops, etc. | ||
3746 | + */ | ||
3747 | xt_compat_flush_offsets(AF_INET); | ||
3748 | xt_compat_unlock(AF_INET); | ||
3749 | - if (ret) | ||
3750 | - goto free_newinfo; | ||
3751 | |||
3752 | - ret = -ELOOP; | ||
3753 | - if (!mark_source_chains(newinfo, valid_hooks, entry1)) | ||
3754 | - goto free_newinfo; | ||
3755 | + memcpy(&repl, compatr, sizeof(*compatr)); | ||
3756 | |||
3757 | - i = 0; | ||
3758 | - xt_entry_foreach(iter1, entry1, newinfo->size) { | ||
3759 | - ret = compat_check_entry(iter1, net, name); | ||
3760 | - if (ret != 0) | ||
3761 | - break; | ||
3762 | - ++i; | ||
3763 | - if (strcmp(ipt_get_target(iter1)->u.user.name, | ||
3764 | - XT_ERROR_TARGET) == 0) | ||
3765 | - ++newinfo->stacksize; | ||
3766 | - } | ||
3767 | - if (ret) { | ||
3768 | - /* | ||
3769 | - * The first i matches need cleanup_entry (calls ->destroy) | ||
3770 | - * because they had called ->check already. The other j-i | ||
3771 | - * entries need only release. | ||
3772 | - */ | ||
3773 | - int skip = i; | ||
3774 | - j -= i; | ||
3775 | - xt_entry_foreach(iter0, entry0, newinfo->size) { | ||
3776 | - if (skip-- > 0) | ||
3777 | - continue; | ||
3778 | - if (j-- == 0) | ||
3779 | - break; | ||
3780 | - compat_release_entry(iter0); | ||
3781 | - } | ||
3782 | - xt_entry_foreach(iter1, entry1, newinfo->size) { | ||
3783 | - if (i-- == 0) | ||
3784 | - break; | ||
3785 | - cleanup_entry(iter1, net); | ||
3786 | - } | ||
3787 | - xt_free_table_info(newinfo); | ||
3788 | - return ret; | ||
3789 | + for (i = 0; i < NF_INET_NUMHOOKS; i++) { | ||
3790 | + repl.hook_entry[i] = newinfo->hook_entry[i]; | ||
3791 | + repl.underflow[i] = newinfo->underflow[i]; | ||
3792 | } | ||
3793 | |||
3794 | + repl.num_counters = 0; | ||
3795 | + repl.counters = NULL; | ||
3796 | + repl.size = newinfo->size; | ||
3797 | + ret = translate_table(net, newinfo, entry1, &repl); | ||
3798 | + if (ret) | ||
3799 | + goto free_newinfo; | ||
3800 | + | ||
3801 | *pinfo = newinfo; | ||
3802 | *pentry0 = entry1; | ||
3803 | xt_free_table_info(info); | ||
3804 | @@ -1784,17 +1642,16 @@ translate_compat_table(struct net *net, | ||
3805 | |||
3806 | free_newinfo: | ||
3807 | xt_free_table_info(newinfo); | ||
3808 | -out: | ||
3809 | - xt_entry_foreach(iter0, entry0, total_size) { | ||
3810 | + return ret; | ||
3811 | +out_unlock: | ||
3812 | + xt_compat_flush_offsets(AF_INET); | ||
3813 | + xt_compat_unlock(AF_INET); | ||
3814 | + xt_entry_foreach(iter0, entry0, compatr->size) { | ||
3815 | if (j-- == 0) | ||
3816 | break; | ||
3817 | compat_release_entry(iter0); | ||
3818 | } | ||
3819 | return ret; | ||
3820 | -out_unlock: | ||
3821 | - xt_compat_flush_offsets(AF_INET); | ||
3822 | - xt_compat_unlock(AF_INET); | ||
3823 | - goto out; | ||
3824 | } | ||
3825 | |||
3826 | static int | ||
3827 | @@ -1830,10 +1687,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len) | ||
3828 | goto free_newinfo; | ||
3829 | } | ||
3830 | |||
3831 | - ret = translate_compat_table(net, tmp.name, tmp.valid_hooks, | ||
3832 | - &newinfo, &loc_cpu_entry, tmp.size, | ||
3833 | - tmp.num_entries, tmp.hook_entry, | ||
3834 | - tmp.underflow); | ||
3835 | + ret = translate_compat_table(net, &newinfo, &loc_cpu_entry, &tmp); | ||
3836 | if (ret != 0) | ||
3837 | goto free_newinfo; | ||
3838 | |||
3839 | diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c | ||
3840 | index 21fbb54f11d0..44e1632370dd 100644 | ||
3841 | --- a/net/ipv4/udp.c | ||
3842 | +++ b/net/ipv4/udp.c | ||
3843 | @@ -1531,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) | ||
3844 | |||
3845 | /* if we're overly short, let UDP handle it */ | ||
3846 | encap_rcv = ACCESS_ONCE(up->encap_rcv); | ||
3847 | - if (skb->len > sizeof(struct udphdr) && encap_rcv) { | ||
3848 | + if (encap_rcv) { | ||
3849 | int ret; | ||
3850 | |||
3851 | /* Verify checksum before giving to encap */ | ||
3852 | diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c | ||
3853 | index a175152d3e46..58900c21e4e4 100644 | ||
3854 | --- a/net/ipv6/ip6_output.c | ||
3855 | +++ b/net/ipv6/ip6_output.c | ||
3856 | @@ -1072,17 +1072,12 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6, | ||
3857 | const struct in6_addr *final_dst) | ||
3858 | { | ||
3859 | struct dst_entry *dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie); | ||
3860 | - int err; | ||
3861 | |||
3862 | dst = ip6_sk_dst_check(sk, dst, fl6); | ||
3863 | + if (!dst) | ||
3864 | + dst = ip6_dst_lookup_flow(sk, fl6, final_dst); | ||
3865 | |||
3866 | - err = ip6_dst_lookup_tail(sock_net(sk), sk, &dst, fl6); | ||
3867 | - if (err) | ||
3868 | - return ERR_PTR(err); | ||
3869 | - if (final_dst) | ||
3870 | - fl6->daddr = *final_dst; | ||
3871 | - | ||
3872 | - return xfrm_lookup_route(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0); | ||
3873 | + return dst; | ||
3874 | } | ||
3875 | EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup_flow); | ||
3876 | |||
3877 | diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c | ||
3878 | index 99425cf2819b..22f39e00bef3 100644 | ||
3879 | --- a/net/ipv6/netfilter/ip6_tables.c | ||
3880 | +++ b/net/ipv6/netfilter/ip6_tables.c | ||
3881 | @@ -198,11 +198,12 @@ get_entry(const void *base, unsigned int offset) | ||
3882 | |||
3883 | /* All zeroes == unconditional rule. */ | ||
3884 | /* Mildly perf critical (only if packet tracing is on) */ | ||
3885 | -static inline bool unconditional(const struct ip6t_ip6 *ipv6) | ||
3886 | +static inline bool unconditional(const struct ip6t_entry *e) | ||
3887 | { | ||
3888 | static const struct ip6t_ip6 uncond; | ||
3889 | |||
3890 | - return memcmp(ipv6, &uncond, sizeof(uncond)) == 0; | ||
3891 | + return e->target_offset == sizeof(struct ip6t_entry) && | ||
3892 | + memcmp(&e->ipv6, &uncond, sizeof(uncond)) == 0; | ||
3893 | } | ||
3894 | |||
3895 | static inline const struct xt_entry_target * | ||
3896 | @@ -258,11 +259,10 @@ get_chainname_rulenum(const struct ip6t_entry *s, const struct ip6t_entry *e, | ||
3897 | } else if (s == e) { | ||
3898 | (*rulenum)++; | ||
3899 | |||
3900 | - if (s->target_offset == sizeof(struct ip6t_entry) && | ||
3901 | + if (unconditional(s) && | ||
3902 | strcmp(t->target.u.kernel.target->name, | ||
3903 | XT_STANDARD_TARGET) == 0 && | ||
3904 | - t->verdict < 0 && | ||
3905 | - unconditional(&s->ipv6)) { | ||
3906 | + t->verdict < 0) { | ||
3907 | /* Tail of chains: STANDARD target (return/policy) */ | ||
3908 | *comment = *chainname == hookname | ||
3909 | ? comments[NF_IP6_TRACE_COMMENT_POLICY] | ||
3910 | @@ -455,6 +455,18 @@ ip6t_do_table(struct sk_buff *skb, | ||
3911 | #endif | ||
3912 | } | ||
3913 | |||
3914 | +static bool find_jump_target(const struct xt_table_info *t, | ||
3915 | + const struct ip6t_entry *target) | ||
3916 | +{ | ||
3917 | + struct ip6t_entry *iter; | ||
3918 | + | ||
3919 | + xt_entry_foreach(iter, t->entries, t->size) { | ||
3920 | + if (iter == target) | ||
3921 | + return true; | ||
3922 | + } | ||
3923 | + return false; | ||
3924 | +} | ||
3925 | + | ||
3926 | /* Figures out from what hook each rule can be called: returns 0 if | ||
3927 | there are loops. Puts hook bitmask in comefrom. */ | ||
3928 | static int | ||
3929 | @@ -488,11 +500,10 @@ mark_source_chains(const struct xt_table_info *newinfo, | ||
3930 | e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS)); | ||
3931 | |||
3932 | /* Unconditional return/END. */ | ||
3933 | - if ((e->target_offset == sizeof(struct ip6t_entry) && | ||
3934 | + if ((unconditional(e) && | ||
3935 | (strcmp(t->target.u.user.name, | ||
3936 | XT_STANDARD_TARGET) == 0) && | ||
3937 | - t->verdict < 0 && | ||
3938 | - unconditional(&e->ipv6)) || visited) { | ||
3939 | + t->verdict < 0) || visited) { | ||
3940 | unsigned int oldpos, size; | ||
3941 | |||
3942 | if ((strcmp(t->target.u.user.name, | ||
3943 | @@ -533,6 +544,8 @@ mark_source_chains(const struct xt_table_info *newinfo, | ||
3944 | size = e->next_offset; | ||
3945 | e = (struct ip6t_entry *) | ||
3946 | (entry0 + pos + size); | ||
3947 | + if (pos + size >= newinfo->size) | ||
3948 | + return 0; | ||
3949 | e->counters.pcnt = pos; | ||
3950 | pos += size; | ||
3951 | } else { | ||
3952 | @@ -551,9 +564,15 @@ mark_source_chains(const struct xt_table_info *newinfo, | ||
3953 | /* This a jump; chase it. */ | ||
3954 | duprintf("Jump rule %u -> %u\n", | ||
3955 | pos, newpos); | ||
3956 | + e = (struct ip6t_entry *) | ||
3957 | + (entry0 + newpos); | ||
3958 | + if (!find_jump_target(newinfo, e)) | ||
3959 | + return 0; | ||
3960 | } else { | ||
3961 | /* ... this is a fallthru */ | ||
3962 | newpos = pos + e->next_offset; | ||
3963 | + if (newpos >= newinfo->size) | ||
3964 | + return 0; | ||
3965 | } | ||
3966 | e = (struct ip6t_entry *) | ||
3967 | (entry0 + newpos); | ||
3968 | @@ -580,27 +599,6 @@ static void cleanup_match(struct xt_entry_match *m, struct net *net) | ||
3969 | module_put(par.match->me); | ||
3970 | } | ||
3971 | |||
3972 | -static int | ||
3973 | -check_entry(const struct ip6t_entry *e, const char *name) | ||
3974 | -{ | ||
3975 | - const struct xt_entry_target *t; | ||
3976 | - | ||
3977 | - if (!ip6_checkentry(&e->ipv6)) { | ||
3978 | - duprintf("ip_tables: ip check failed %p %s.\n", e, name); | ||
3979 | - return -EINVAL; | ||
3980 | - } | ||
3981 | - | ||
3982 | - if (e->target_offset + sizeof(struct xt_entry_target) > | ||
3983 | - e->next_offset) | ||
3984 | - return -EINVAL; | ||
3985 | - | ||
3986 | - t = ip6t_get_target_c(e); | ||
3987 | - if (e->target_offset + t->u.target_size > e->next_offset) | ||
3988 | - return -EINVAL; | ||
3989 | - | ||
3990 | - return 0; | ||
3991 | -} | ||
3992 | - | ||
3993 | static int check_match(struct xt_entry_match *m, struct xt_mtchk_param *par) | ||
3994 | { | ||
3995 | const struct ip6t_ip6 *ipv6 = par->entryinfo; | ||
3996 | @@ -679,10 +677,6 @@ find_check_entry(struct ip6t_entry *e, struct net *net, const char *name, | ||
3997 | struct xt_mtchk_param mtpar; | ||
3998 | struct xt_entry_match *ematch; | ||
3999 | |||
4000 | - ret = check_entry(e, name); | ||
4001 | - if (ret) | ||
4002 | - return ret; | ||
4003 | - | ||
4004 | e->counters.pcnt = xt_percpu_counter_alloc(); | ||
4005 | if (IS_ERR_VALUE(e->counters.pcnt)) | ||
4006 | return -ENOMEM; | ||
4007 | @@ -733,7 +727,7 @@ static bool check_underflow(const struct ip6t_entry *e) | ||
4008 | const struct xt_entry_target *t; | ||
4009 | unsigned int verdict; | ||
4010 | |||
4011 | - if (!unconditional(&e->ipv6)) | ||
4012 | + if (!unconditional(e)) | ||
4013 | return false; | ||
4014 | t = ip6t_get_target_c(e); | ||
4015 | if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0) | ||
4016 | @@ -753,9 +747,11 @@ check_entry_size_and_hooks(struct ip6t_entry *e, | ||
4017 | unsigned int valid_hooks) | ||
4018 | { | ||
4019 | unsigned int h; | ||
4020 | + int err; | ||
4021 | |||
4022 | if ((unsigned long)e % __alignof__(struct ip6t_entry) != 0 || | ||
4023 | - (unsigned char *)e + sizeof(struct ip6t_entry) >= limit) { | ||
4024 | + (unsigned char *)e + sizeof(struct ip6t_entry) >= limit || | ||
4025 | + (unsigned char *)e + e->next_offset > limit) { | ||
4026 | duprintf("Bad offset %p\n", e); | ||
4027 | return -EINVAL; | ||
4028 | } | ||
4029 | @@ -767,6 +763,14 @@ check_entry_size_and_hooks(struct ip6t_entry *e, | ||
4030 | return -EINVAL; | ||
4031 | } | ||
4032 | |||
4033 | + if (!ip6_checkentry(&e->ipv6)) | ||
4034 | + return -EINVAL; | ||
4035 | + | ||
4036 | + err = xt_check_entry_offsets(e, e->elems, e->target_offset, | ||
4037 | + e->next_offset); | ||
4038 | + if (err) | ||
4039 | + return err; | ||
4040 | + | ||
4041 | /* Check hooks & underflows */ | ||
4042 | for (h = 0; h < NF_INET_NUMHOOKS; h++) { | ||
4043 | if (!(valid_hooks & (1 << h))) | ||
4044 | @@ -775,9 +779,9 @@ check_entry_size_and_hooks(struct ip6t_entry *e, | ||
4045 | newinfo->hook_entry[h] = hook_entries[h]; | ||
4046 | if ((unsigned char *)e - base == underflows[h]) { | ||
4047 | if (!check_underflow(e)) { | ||
4048 | - pr_err("Underflows must be unconditional and " | ||
4049 | - "use the STANDARD target with " | ||
4050 | - "ACCEPT/DROP\n"); | ||
4051 | + pr_debug("Underflows must be unconditional and " | ||
4052 | + "use the STANDARD target with " | ||
4053 | + "ACCEPT/DROP\n"); | ||
4054 | return -EINVAL; | ||
4055 | } | ||
4056 | newinfo->underflow[h] = underflows[h]; | ||
4057 | @@ -1321,55 +1325,16 @@ do_add_counters(struct net *net, const void __user *user, unsigned int len, | ||
4058 | unsigned int i; | ||
4059 | struct xt_counters_info tmp; | ||
4060 | struct xt_counters *paddc; | ||
4061 | - unsigned int num_counters; | ||
4062 | - char *name; | ||
4063 | - int size; | ||
4064 | - void *ptmp; | ||
4065 | struct xt_table *t; | ||
4066 | const struct xt_table_info *private; | ||
4067 | int ret = 0; | ||
4068 | struct ip6t_entry *iter; | ||
4069 | unsigned int addend; | ||
4070 | -#ifdef CONFIG_COMPAT | ||
4071 | - struct compat_xt_counters_info compat_tmp; | ||
4072 | - | ||
4073 | - if (compat) { | ||
4074 | - ptmp = &compat_tmp; | ||
4075 | - size = sizeof(struct compat_xt_counters_info); | ||
4076 | - } else | ||
4077 | -#endif | ||
4078 | - { | ||
4079 | - ptmp = &tmp; | ||
4080 | - size = sizeof(struct xt_counters_info); | ||
4081 | - } | ||
4082 | - | ||
4083 | - if (copy_from_user(ptmp, user, size) != 0) | ||
4084 | - return -EFAULT; | ||
4085 | |||
4086 | -#ifdef CONFIG_COMPAT | ||
4087 | - if (compat) { | ||
4088 | - num_counters = compat_tmp.num_counters; | ||
4089 | - name = compat_tmp.name; | ||
4090 | - } else | ||
4091 | -#endif | ||
4092 | - { | ||
4093 | - num_counters = tmp.num_counters; | ||
4094 | - name = tmp.name; | ||
4095 | - } | ||
4096 | - | ||
4097 | - if (len != size + num_counters * sizeof(struct xt_counters)) | ||
4098 | - return -EINVAL; | ||
4099 | - | ||
4100 | - paddc = vmalloc(len - size); | ||
4101 | - if (!paddc) | ||
4102 | - return -ENOMEM; | ||
4103 | - | ||
4104 | - if (copy_from_user(paddc, user + size, len - size) != 0) { | ||
4105 | - ret = -EFAULT; | ||
4106 | - goto free; | ||
4107 | - } | ||
4108 | - | ||
4109 | - t = xt_find_table_lock(net, AF_INET6, name); | ||
4110 | + paddc = xt_copy_counters_from_user(user, len, &tmp, compat); | ||
4111 | + if (IS_ERR(paddc)) | ||
4112 | + return PTR_ERR(paddc); | ||
4113 | + t = xt_find_table_lock(net, AF_INET6, tmp.name); | ||
4114 | if (IS_ERR_OR_NULL(t)) { | ||
4115 | ret = t ? PTR_ERR(t) : -ENOENT; | ||
4116 | goto free; | ||
4117 | @@ -1377,7 +1342,7 @@ do_add_counters(struct net *net, const void __user *user, unsigned int len, | ||
4118 | |||
4119 | local_bh_disable(); | ||
4120 | private = t->private; | ||
4121 | - if (private->number != num_counters) { | ||
4122 | + if (private->number != tmp.num_counters) { | ||
4123 | ret = -EINVAL; | ||
4124 | goto unlock_up_free; | ||
4125 | } | ||
4126 | @@ -1456,7 +1421,6 @@ compat_copy_entry_to_user(struct ip6t_entry *e, void __user **dstptr, | ||
4127 | |||
4128 | static int | ||
4129 | compat_find_calc_match(struct xt_entry_match *m, | ||
4130 | - const char *name, | ||
4131 | const struct ip6t_ip6 *ipv6, | ||
4132 | int *size) | ||
4133 | { | ||
4134 | @@ -1491,21 +1455,19 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e, | ||
4135 | struct xt_table_info *newinfo, | ||
4136 | unsigned int *size, | ||
4137 | const unsigned char *base, | ||
4138 | - const unsigned char *limit, | ||
4139 | - const unsigned int *hook_entries, | ||
4140 | - const unsigned int *underflows, | ||
4141 | - const char *name) | ||
4142 | + const unsigned char *limit) | ||
4143 | { | ||
4144 | struct xt_entry_match *ematch; | ||
4145 | struct xt_entry_target *t; | ||
4146 | struct xt_target *target; | ||
4147 | unsigned int entry_offset; | ||
4148 | unsigned int j; | ||
4149 | - int ret, off, h; | ||
4150 | + int ret, off; | ||
4151 | |||
4152 | duprintf("check_compat_entry_size_and_hooks %p\n", e); | ||
4153 | if ((unsigned long)e % __alignof__(struct compat_ip6t_entry) != 0 || | ||
4154 | - (unsigned char *)e + sizeof(struct compat_ip6t_entry) >= limit) { | ||
4155 | + (unsigned char *)e + sizeof(struct compat_ip6t_entry) >= limit || | ||
4156 | + (unsigned char *)e + e->next_offset > limit) { | ||
4157 | duprintf("Bad offset %p, limit = %p\n", e, limit); | ||
4158 | return -EINVAL; | ||
4159 | } | ||
4160 | @@ -1517,8 +1479,11 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e, | ||
4161 | return -EINVAL; | ||
4162 | } | ||
4163 | |||
4164 | - /* For purposes of check_entry casting the compat entry is fine */ | ||
4165 | - ret = check_entry((struct ip6t_entry *)e, name); | ||
4166 | + if (!ip6_checkentry(&e->ipv6)) | ||
4167 | + return -EINVAL; | ||
4168 | + | ||
4169 | + ret = xt_compat_check_entry_offsets(e, e->elems, | ||
4170 | + e->target_offset, e->next_offset); | ||
4171 | if (ret) | ||
4172 | return ret; | ||
4173 | |||
4174 | @@ -1526,7 +1491,7 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e, | ||
4175 | entry_offset = (void *)e - (void *)base; | ||
4176 | j = 0; | ||
4177 | xt_ematch_foreach(ematch, e) { | ||
4178 | - ret = compat_find_calc_match(ematch, name, &e->ipv6, &off); | ||
4179 | + ret = compat_find_calc_match(ematch, &e->ipv6, &off); | ||
4180 | if (ret != 0) | ||
4181 | goto release_matches; | ||
4182 | ++j; | ||
4183 | @@ -1549,17 +1514,6 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e, | ||
4184 | if (ret) | ||
4185 | goto out; | ||
4186 | |||
4187 | - /* Check hooks & underflows */ | ||
4188 | - for (h = 0; h < NF_INET_NUMHOOKS; h++) { | ||
4189 | - if ((unsigned char *)e - base == hook_entries[h]) | ||
4190 | - newinfo->hook_entry[h] = hook_entries[h]; | ||
4191 | - if ((unsigned char *)e - base == underflows[h]) | ||
4192 | - newinfo->underflow[h] = underflows[h]; | ||
4193 | - } | ||
4194 | - | ||
4195 | - /* Clear counters and comefrom */ | ||
4196 | - memset(&e->counters, 0, sizeof(e->counters)); | ||
4197 | - e->comefrom = 0; | ||
4198 | return 0; | ||
4199 | |||
4200 | out: | ||
4201 | @@ -1573,18 +1527,17 @@ release_matches: | ||
4202 | return ret; | ||
4203 | } | ||
4204 | |||
4205 | -static int | ||
4206 | +static void | ||
4207 | compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr, | ||
4208 | - unsigned int *size, const char *name, | ||
4209 | + unsigned int *size, | ||
4210 | struct xt_table_info *newinfo, unsigned char *base) | ||
4211 | { | ||
4212 | struct xt_entry_target *t; | ||
4213 | struct ip6t_entry *de; | ||
4214 | unsigned int origsize; | ||
4215 | - int ret, h; | ||
4216 | + int h; | ||
4217 | struct xt_entry_match *ematch; | ||
4218 | |||
4219 | - ret = 0; | ||
4220 | origsize = *size; | ||
4221 | de = (struct ip6t_entry *)*dstptr; | ||
4222 | memcpy(de, e, sizeof(struct ip6t_entry)); | ||
4223 | @@ -1593,11 +1546,9 @@ compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr, | ||
4224 | *dstptr += sizeof(struct ip6t_entry); | ||
4225 | *size += sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry); | ||
4226 | |||
4227 | - xt_ematch_foreach(ematch, e) { | ||
4228 | - ret = xt_compat_match_from_user(ematch, dstptr, size); | ||
4229 | - if (ret != 0) | ||
4230 | - return ret; | ||
4231 | - } | ||
4232 | + xt_ematch_foreach(ematch, e) | ||
4233 | + xt_compat_match_from_user(ematch, dstptr, size); | ||
4234 | + | ||
4235 | de->target_offset = e->target_offset - (origsize - *size); | ||
4236 | t = compat_ip6t_get_target(e); | ||
4237 | xt_compat_target_from_user(t, dstptr, size); | ||
4238 | @@ -1609,183 +1560,83 @@ compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr, | ||
4239 | if ((unsigned char *)de - base < newinfo->underflow[h]) | ||
4240 | newinfo->underflow[h] -= origsize - *size; | ||
4241 | } | ||
4242 | - return ret; | ||
4243 | -} | ||
4244 | - | ||
4245 | -static int compat_check_entry(struct ip6t_entry *e, struct net *net, | ||
4246 | - const char *name) | ||
4247 | -{ | ||
4248 | - unsigned int j; | ||
4249 | - int ret = 0; | ||
4250 | - struct xt_mtchk_param mtpar; | ||
4251 | - struct xt_entry_match *ematch; | ||
4252 | - | ||
4253 | - e->counters.pcnt = xt_percpu_counter_alloc(); | ||
4254 | - if (IS_ERR_VALUE(e->counters.pcnt)) | ||
4255 | - return -ENOMEM; | ||
4256 | - j = 0; | ||
4257 | - mtpar.net = net; | ||
4258 | - mtpar.table = name; | ||
4259 | - mtpar.entryinfo = &e->ipv6; | ||
4260 | - mtpar.hook_mask = e->comefrom; | ||
4261 | - mtpar.family = NFPROTO_IPV6; | ||
4262 | - xt_ematch_foreach(ematch, e) { | ||
4263 | - ret = check_match(ematch, &mtpar); | ||
4264 | - if (ret != 0) | ||
4265 | - goto cleanup_matches; | ||
4266 | - ++j; | ||
4267 | - } | ||
4268 | - | ||
4269 | - ret = check_target(e, net, name); | ||
4270 | - if (ret) | ||
4271 | - goto cleanup_matches; | ||
4272 | - return 0; | ||
4273 | - | ||
4274 | - cleanup_matches: | ||
4275 | - xt_ematch_foreach(ematch, e) { | ||
4276 | - if (j-- == 0) | ||
4277 | - break; | ||
4278 | - cleanup_match(ematch, net); | ||
4279 | - } | ||
4280 | - | ||
4281 | - xt_percpu_counter_free(e->counters.pcnt); | ||
4282 | - | ||
4283 | - return ret; | ||
4284 | } | ||
4285 | |||
4286 | static int | ||
4287 | translate_compat_table(struct net *net, | ||
4288 | - const char *name, | ||
4289 | - unsigned int valid_hooks, | ||
4290 | struct xt_table_info **pinfo, | ||
4291 | void **pentry0, | ||
4292 | - unsigned int total_size, | ||
4293 | - unsigned int number, | ||
4294 | - unsigned int *hook_entries, | ||
4295 | - unsigned int *underflows) | ||
4296 | + const struct compat_ip6t_replace *compatr) | ||
4297 | { | ||
4298 | unsigned int i, j; | ||
4299 | struct xt_table_info *newinfo, *info; | ||
4300 | void *pos, *entry0, *entry1; | ||
4301 | struct compat_ip6t_entry *iter0; | ||
4302 | - struct ip6t_entry *iter1; | ||
4303 | + struct ip6t_replace repl; | ||
4304 | unsigned int size; | ||
4305 | int ret = 0; | ||
4306 | |||
4307 | info = *pinfo; | ||
4308 | entry0 = *pentry0; | ||
4309 | - size = total_size; | ||
4310 | - info->number = number; | ||
4311 | - | ||
4312 | - /* Init all hooks to impossible value. */ | ||
4313 | - for (i = 0; i < NF_INET_NUMHOOKS; i++) { | ||
4314 | - info->hook_entry[i] = 0xFFFFFFFF; | ||
4315 | - info->underflow[i] = 0xFFFFFFFF; | ||
4316 | - } | ||
4317 | + size = compatr->size; | ||
4318 | + info->number = compatr->num_entries; | ||
4319 | |||
4320 | duprintf("translate_compat_table: size %u\n", info->size); | ||
4321 | j = 0; | ||
4322 | xt_compat_lock(AF_INET6); | ||
4323 | - xt_compat_init_offsets(AF_INET6, number); | ||
4324 | + xt_compat_init_offsets(AF_INET6, compatr->num_entries); | ||
4325 | /* Walk through entries, checking offsets. */ | ||
4326 | - xt_entry_foreach(iter0, entry0, total_size) { | ||
4327 | + xt_entry_foreach(iter0, entry0, compatr->size) { | ||
4328 | ret = check_compat_entry_size_and_hooks(iter0, info, &size, | ||
4329 | entry0, | ||
4330 | - entry0 + total_size, | ||
4331 | - hook_entries, | ||
4332 | - underflows, | ||
4333 | - name); | ||
4334 | + entry0 + compatr->size); | ||
4335 | if (ret != 0) | ||
4336 | goto out_unlock; | ||
4337 | ++j; | ||
4338 | } | ||
4339 | |||
4340 | ret = -EINVAL; | ||
4341 | - if (j != number) { | ||
4342 | + if (j != compatr->num_entries) { | ||
4343 | duprintf("translate_compat_table: %u not %u entries\n", | ||
4344 | - j, number); | ||
4345 | + j, compatr->num_entries); | ||
4346 | goto out_unlock; | ||
4347 | } | ||
4348 | |||
4349 | - /* Check hooks all assigned */ | ||
4350 | - for (i = 0; i < NF_INET_NUMHOOKS; i++) { | ||
4351 | - /* Only hooks which are valid */ | ||
4352 | - if (!(valid_hooks & (1 << i))) | ||
4353 | - continue; | ||
4354 | - if (info->hook_entry[i] == 0xFFFFFFFF) { | ||
4355 | - duprintf("Invalid hook entry %u %u\n", | ||
4356 | - i, hook_entries[i]); | ||
4357 | - goto out_unlock; | ||
4358 | - } | ||
4359 | - if (info->underflow[i] == 0xFFFFFFFF) { | ||
4360 | - duprintf("Invalid underflow %u %u\n", | ||
4361 | - i, underflows[i]); | ||
4362 | - goto out_unlock; | ||
4363 | - } | ||
4364 | - } | ||
4365 | - | ||
4366 | ret = -ENOMEM; | ||
4367 | newinfo = xt_alloc_table_info(size); | ||
4368 | if (!newinfo) | ||
4369 | goto out_unlock; | ||
4370 | |||
4371 | - newinfo->number = number; | ||
4372 | + newinfo->number = compatr->num_entries; | ||
4373 | for (i = 0; i < NF_INET_NUMHOOKS; i++) { | ||
4374 | - newinfo->hook_entry[i] = info->hook_entry[i]; | ||
4375 | - newinfo->underflow[i] = info->underflow[i]; | ||
4376 | + newinfo->hook_entry[i] = compatr->hook_entry[i]; | ||
4377 | + newinfo->underflow[i] = compatr->underflow[i]; | ||
4378 | } | ||
4379 | entry1 = newinfo->entries; | ||
4380 | pos = entry1; | ||
4381 | - size = total_size; | ||
4382 | - xt_entry_foreach(iter0, entry0, total_size) { | ||
4383 | - ret = compat_copy_entry_from_user(iter0, &pos, &size, | ||
4384 | - name, newinfo, entry1); | ||
4385 | - if (ret != 0) | ||
4386 | - break; | ||
4387 | - } | ||
4388 | + size = compatr->size; | ||
4389 | + xt_entry_foreach(iter0, entry0, compatr->size) | ||
4390 | + compat_copy_entry_from_user(iter0, &pos, &size, | ||
4391 | + newinfo, entry1); | ||
4392 | + | ||
4393 | + /* all module references in entry0 are now gone. */ | ||
4394 | xt_compat_flush_offsets(AF_INET6); | ||
4395 | xt_compat_unlock(AF_INET6); | ||
4396 | - if (ret) | ||
4397 | - goto free_newinfo; | ||
4398 | |||
4399 | - ret = -ELOOP; | ||
4400 | - if (!mark_source_chains(newinfo, valid_hooks, entry1)) | ||
4401 | - goto free_newinfo; | ||
4402 | + memcpy(&repl, compatr, sizeof(*compatr)); | ||
4403 | |||
4404 | - i = 0; | ||
4405 | - xt_entry_foreach(iter1, entry1, newinfo->size) { | ||
4406 | - ret = compat_check_entry(iter1, net, name); | ||
4407 | - if (ret != 0) | ||
4408 | - break; | ||
4409 | - ++i; | ||
4410 | - if (strcmp(ip6t_get_target(iter1)->u.user.name, | ||
4411 | - XT_ERROR_TARGET) == 0) | ||
4412 | - ++newinfo->stacksize; | ||
4413 | - } | ||
4414 | - if (ret) { | ||
4415 | - /* | ||
4416 | - * The first i matches need cleanup_entry (calls ->destroy) | ||
4417 | - * because they had called ->check already. The other j-i | ||
4418 | - * entries need only release. | ||
4419 | - */ | ||
4420 | - int skip = i; | ||
4421 | - j -= i; | ||
4422 | - xt_entry_foreach(iter0, entry0, newinfo->size) { | ||
4423 | - if (skip-- > 0) | ||
4424 | - continue; | ||
4425 | - if (j-- == 0) | ||
4426 | - break; | ||
4427 | - compat_release_entry(iter0); | ||
4428 | - } | ||
4429 | - xt_entry_foreach(iter1, entry1, newinfo->size) { | ||
4430 | - if (i-- == 0) | ||
4431 | - break; | ||
4432 | - cleanup_entry(iter1, net); | ||
4433 | - } | ||
4434 | - xt_free_table_info(newinfo); | ||
4435 | - return ret; | ||
4436 | + for (i = 0; i < NF_INET_NUMHOOKS; i++) { | ||
4437 | + repl.hook_entry[i] = newinfo->hook_entry[i]; | ||
4438 | + repl.underflow[i] = newinfo->underflow[i]; | ||
4439 | } | ||
4440 | |||
4441 | + repl.num_counters = 0; | ||
4442 | + repl.counters = NULL; | ||
4443 | + repl.size = newinfo->size; | ||
4444 | + ret = translate_table(net, newinfo, entry1, &repl); | ||
4445 | + if (ret) | ||
4446 | + goto free_newinfo; | ||
4447 | + | ||
4448 | *pinfo = newinfo; | ||
4449 | *pentry0 = entry1; | ||
4450 | xt_free_table_info(info); | ||
4451 | @@ -1793,17 +1644,16 @@ translate_compat_table(struct net *net, | ||
4452 | |||
4453 | free_newinfo: | ||
4454 | xt_free_table_info(newinfo); | ||
4455 | -out: | ||
4456 | - xt_entry_foreach(iter0, entry0, total_size) { | ||
4457 | + return ret; | ||
4458 | +out_unlock: | ||
4459 | + xt_compat_flush_offsets(AF_INET6); | ||
4460 | + xt_compat_unlock(AF_INET6); | ||
4461 | + xt_entry_foreach(iter0, entry0, compatr->size) { | ||
4462 | if (j-- == 0) | ||
4463 | break; | ||
4464 | compat_release_entry(iter0); | ||
4465 | } | ||
4466 | return ret; | ||
4467 | -out_unlock: | ||
4468 | - xt_compat_flush_offsets(AF_INET6); | ||
4469 | - xt_compat_unlock(AF_INET6); | ||
4470 | - goto out; | ||
4471 | } | ||
4472 | |||
4473 | static int | ||
4474 | @@ -1839,10 +1689,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len) | ||
4475 | goto free_newinfo; | ||
4476 | } | ||
4477 | |||
4478 | - ret = translate_compat_table(net, tmp.name, tmp.valid_hooks, | ||
4479 | - &newinfo, &loc_cpu_entry, tmp.size, | ||
4480 | - tmp.num_entries, tmp.hook_entry, | ||
4481 | - tmp.underflow); | ||
4482 | + ret = translate_compat_table(net, &newinfo, &loc_cpu_entry, &tmp); | ||
4483 | if (ret != 0) | ||
4484 | goto free_newinfo; | ||
4485 | |||
4486 | diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c | ||
4487 | index b8d405623f4f..1a1cd3938fd0 100644 | ||
4488 | --- a/net/ipv6/tcp_ipv6.c | ||
4489 | +++ b/net/ipv6/tcp_ipv6.c | ||
4490 | @@ -1706,7 +1706,9 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i) | ||
4491 | destp = ntohs(inet->inet_dport); | ||
4492 | srcp = ntohs(inet->inet_sport); | ||
4493 | |||
4494 | - if (icsk->icsk_pending == ICSK_TIME_RETRANS) { | ||
4495 | + if (icsk->icsk_pending == ICSK_TIME_RETRANS || | ||
4496 | + icsk->icsk_pending == ICSK_TIME_EARLY_RETRANS || | ||
4497 | + icsk->icsk_pending == ICSK_TIME_LOSS_PROBE) { | ||
4498 | timer_active = 1; | ||
4499 | timer_expires = icsk->icsk_timeout; | ||
4500 | } else if (icsk->icsk_pending == ICSK_TIME_PROBE0) { | ||
4501 | diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c | ||
4502 | index 6665e1a0bfe1..275af43306f9 100644 | ||
4503 | --- a/net/ipv6/udp.c | ||
4504 | +++ b/net/ipv6/udp.c | ||
4505 | @@ -647,7 +647,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) | ||
4506 | |||
4507 | /* if we're overly short, let UDP handle it */ | ||
4508 | encap_rcv = ACCESS_ONCE(up->encap_rcv); | ||
4509 | - if (skb->len > sizeof(struct udphdr) && encap_rcv) { | ||
4510 | + if (encap_rcv) { | ||
4511 | int ret; | ||
4512 | |||
4513 | /* Verify checksum before giving to encap */ | ||
4514 | diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c | ||
4515 | index afca2eb4dfa7..ec17cbe8a02b 100644 | ||
4516 | --- a/net/l2tp/l2tp_core.c | ||
4517 | +++ b/net/l2tp/l2tp_core.c | ||
4518 | @@ -1581,7 +1581,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 | ||
4519 | /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */ | ||
4520 | tunnel->encap = encap; | ||
4521 | if (encap == L2TP_ENCAPTYPE_UDP) { | ||
4522 | - struct udp_tunnel_sock_cfg udp_cfg; | ||
4523 | + struct udp_tunnel_sock_cfg udp_cfg = { }; | ||
4524 | |||
4525 | udp_cfg.sk_user_data = tunnel; | ||
4526 | udp_cfg.encap_type = UDP_ENCAP_L2TPINUDP; | ||
4527 | diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c | ||
4528 | index d4aaad747ea9..25391fb25516 100644 | ||
4529 | --- a/net/netfilter/x_tables.c | ||
4530 | +++ b/net/netfilter/x_tables.c | ||
4531 | @@ -415,6 +415,47 @@ int xt_check_match(struct xt_mtchk_param *par, | ||
4532 | } | ||
4533 | EXPORT_SYMBOL_GPL(xt_check_match); | ||
4534 | |||
4535 | +/** xt_check_entry_match - check that matches end before start of target | ||
4536 | + * | ||
4537 | + * @match: beginning of xt_entry_match | ||
4538 | + * @target: beginning of this rules target (alleged end of matches) | ||
4539 | + * @alignment: alignment requirement of match structures | ||
4540 | + * | ||
4541 | + * Validates that all matches add up to the beginning of the target, | ||
4542 | + * and that each match covers at least the base structure size. | ||
4543 | + * | ||
4544 | + * Return: 0 on success, negative errno on failure. | ||
4545 | + */ | ||
4546 | +static int xt_check_entry_match(const char *match, const char *target, | ||
4547 | + const size_t alignment) | ||
4548 | +{ | ||
4549 | + const struct xt_entry_match *pos; | ||
4550 | + int length = target - match; | ||
4551 | + | ||
4552 | + if (length == 0) /* no matches */ | ||
4553 | + return 0; | ||
4554 | + | ||
4555 | + pos = (struct xt_entry_match *)match; | ||
4556 | + do { | ||
4557 | + if ((unsigned long)pos % alignment) | ||
4558 | + return -EINVAL; | ||
4559 | + | ||
4560 | + if (length < (int)sizeof(struct xt_entry_match)) | ||
4561 | + return -EINVAL; | ||
4562 | + | ||
4563 | + if (pos->u.match_size < sizeof(struct xt_entry_match)) | ||
4564 | + return -EINVAL; | ||
4565 | + | ||
4566 | + if (pos->u.match_size > length) | ||
4567 | + return -EINVAL; | ||
4568 | + | ||
4569 | + length -= pos->u.match_size; | ||
4570 | + pos = ((void *)((char *)(pos) + (pos)->u.match_size)); | ||
4571 | + } while (length > 0); | ||
4572 | + | ||
4573 | + return 0; | ||
4574 | +} | ||
4575 | + | ||
4576 | #ifdef CONFIG_COMPAT | ||
4577 | int xt_compat_add_offset(u_int8_t af, unsigned int offset, int delta) | ||
4578 | { | ||
4579 | @@ -484,13 +525,14 @@ int xt_compat_match_offset(const struct xt_match *match) | ||
4580 | } | ||
4581 | EXPORT_SYMBOL_GPL(xt_compat_match_offset); | ||
4582 | |||
4583 | -int xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr, | ||
4584 | - unsigned int *size) | ||
4585 | +void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr, | ||
4586 | + unsigned int *size) | ||
4587 | { | ||
4588 | const struct xt_match *match = m->u.kernel.match; | ||
4589 | struct compat_xt_entry_match *cm = (struct compat_xt_entry_match *)m; | ||
4590 | int pad, off = xt_compat_match_offset(match); | ||
4591 | u_int16_t msize = cm->u.user.match_size; | ||
4592 | + char name[sizeof(m->u.user.name)]; | ||
4593 | |||
4594 | m = *dstptr; | ||
4595 | memcpy(m, cm, sizeof(*cm)); | ||
4596 | @@ -504,10 +546,12 @@ int xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr, | ||
4597 | |||
4598 | msize += off; | ||
4599 | m->u.user.match_size = msize; | ||
4600 | + strlcpy(name, match->name, sizeof(name)); | ||
4601 | + module_put(match->me); | ||
4602 | + strncpy(m->u.user.name, name, sizeof(m->u.user.name)); | ||
4603 | |||
4604 | *size += off; | ||
4605 | *dstptr += msize; | ||
4606 | - return 0; | ||
4607 | } | ||
4608 | EXPORT_SYMBOL_GPL(xt_compat_match_from_user); | ||
4609 | |||
4610 | @@ -538,8 +582,125 @@ int xt_compat_match_to_user(const struct xt_entry_match *m, | ||
4611 | return 0; | ||
4612 | } | ||
4613 | EXPORT_SYMBOL_GPL(xt_compat_match_to_user); | ||
4614 | + | ||
4615 | +/* non-compat version may have padding after verdict */ | ||
4616 | +struct compat_xt_standard_target { | ||
4617 | + struct compat_xt_entry_target t; | ||
4618 | + compat_uint_t verdict; | ||
4619 | +}; | ||
4620 | + | ||
4621 | +int xt_compat_check_entry_offsets(const void *base, const char *elems, | ||
4622 | + unsigned int target_offset, | ||
4623 | + unsigned int next_offset) | ||
4624 | +{ | ||
4625 | + long size_of_base_struct = elems - (const char *)base; | ||
4626 | + const struct compat_xt_entry_target *t; | ||
4627 | + const char *e = base; | ||
4628 | + | ||
4629 | + if (target_offset < size_of_base_struct) | ||
4630 | + return -EINVAL; | ||
4631 | + | ||
4632 | + if (target_offset + sizeof(*t) > next_offset) | ||
4633 | + return -EINVAL; | ||
4634 | + | ||
4635 | + t = (void *)(e + target_offset); | ||
4636 | + if (t->u.target_size < sizeof(*t)) | ||
4637 | + return -EINVAL; | ||
4638 | + | ||
4639 | + if (target_offset + t->u.target_size > next_offset) | ||
4640 | + return -EINVAL; | ||
4641 | + | ||
4642 | + if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0 && | ||
4643 | + COMPAT_XT_ALIGN(target_offset + sizeof(struct compat_xt_standard_target)) != next_offset) | ||
4644 | + return -EINVAL; | ||
4645 | + | ||
4646 | + /* compat_xt_entry match has less strict aligment requirements, | ||
4647 | + * otherwise they are identical. In case of padding differences | ||
4648 | + * we need to add compat version of xt_check_entry_match. | ||
4649 | + */ | ||
4650 | + BUILD_BUG_ON(sizeof(struct compat_xt_entry_match) != sizeof(struct xt_entry_match)); | ||
4651 | + | ||
4652 | + return xt_check_entry_match(elems, base + target_offset, | ||
4653 | + __alignof__(struct compat_xt_entry_match)); | ||
4654 | +} | ||
4655 | +EXPORT_SYMBOL(xt_compat_check_entry_offsets); | ||
4656 | #endif /* CONFIG_COMPAT */ | ||
4657 | |||
4658 | +/** | ||
4659 | + * xt_check_entry_offsets - validate arp/ip/ip6t_entry | ||
4660 | + * | ||
4661 | + * @base: pointer to arp/ip/ip6t_entry | ||
4662 | + * @elems: pointer to first xt_entry_match, i.e. ip(6)t_entry->elems | ||
4663 | + * @target_offset: the arp/ip/ip6_t->target_offset | ||
4664 | + * @next_offset: the arp/ip/ip6_t->next_offset | ||
4665 | + * | ||
4666 | + * validates that target_offset and next_offset are sane and that all | ||
4667 | + * match sizes (if any) align with the target offset. | ||
4668 | + * | ||
4669 | + * This function does not validate the targets or matches themselves, it | ||
4670 | + * only tests that all the offsets and sizes are correct, that all | ||
4671 | + * match structures are aligned, and that the last structure ends where | ||
4672 | + * the target structure begins. | ||
4673 | + * | ||
4674 | + * Also see xt_compat_check_entry_offsets for CONFIG_COMPAT version. | ||
4675 | + * | ||
4676 | + * The arp/ip/ip6t_entry structure @base must have passed following tests: | ||
4677 | + * - it must point to a valid memory location | ||
4678 | + * - base to base + next_offset must be accessible, i.e. not exceed allocated | ||
4679 | + * length. | ||
4680 | + * | ||
4681 | + * A well-formed entry looks like this: | ||
4682 | + * | ||
4683 | + * ip(6)t_entry match [mtdata] match [mtdata] target [tgdata] ip(6)t_entry | ||
4684 | + * e->elems[]-----' | | | ||
4685 | + * matchsize | | | ||
4686 | + * matchsize | | | ||
4687 | + * | | | ||
4688 | + * target_offset---------------------------------' | | ||
4689 | + * next_offset---------------------------------------------------' | ||
4690 | + * | ||
4691 | + * elems[]: flexible array member at end of ip(6)/arpt_entry struct. | ||
4692 | + * This is where matches (if any) and the target reside. | ||
4693 | + * target_offset: beginning of target. | ||
4694 | + * next_offset: start of the next rule; also: size of this rule. | ||
4695 | + * Since targets have a minimum size, target_offset + minlen <= next_offset. | ||
4696 | + * | ||
4697 | + * Every match stores its size, sum of sizes must not exceed target_offset. | ||
4698 | + * | ||
4699 | + * Return: 0 on success, negative errno on failure. | ||
4700 | + */ | ||
4701 | +int xt_check_entry_offsets(const void *base, | ||
4702 | + const char *elems, | ||
4703 | + unsigned int target_offset, | ||
4704 | + unsigned int next_offset) | ||
4705 | +{ | ||
4706 | + long size_of_base_struct = elems - (const char *)base; | ||
4707 | + const struct xt_entry_target *t; | ||
4708 | + const char *e = base; | ||
4709 | + | ||
4710 | + /* target start is within the ip/ip6/arpt_entry struct */ | ||
4711 | + if (target_offset < size_of_base_struct) | ||
4712 | + return -EINVAL; | ||
4713 | + | ||
4714 | + if (target_offset + sizeof(*t) > next_offset) | ||
4715 | + return -EINVAL; | ||
4716 | + | ||
4717 | + t = (void *)(e + target_offset); | ||
4718 | + if (t->u.target_size < sizeof(*t)) | ||
4719 | + return -EINVAL; | ||
4720 | + | ||
4721 | + if (target_offset + t->u.target_size > next_offset) | ||
4722 | + return -EINVAL; | ||
4723 | + | ||
4724 | + if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0 && | ||
4725 | + XT_ALIGN(target_offset + sizeof(struct xt_standard_target)) != next_offset) | ||
4726 | + return -EINVAL; | ||
4727 | + | ||
4728 | + return xt_check_entry_match(elems, base + target_offset, | ||
4729 | + __alignof__(struct xt_entry_match)); | ||
4730 | +} | ||
4731 | +EXPORT_SYMBOL(xt_check_entry_offsets); | ||
4732 | + | ||
4733 | int xt_check_target(struct xt_tgchk_param *par, | ||
4734 | unsigned int size, u_int8_t proto, bool inv_proto) | ||
4735 | { | ||
4736 | @@ -590,6 +751,80 @@ int xt_check_target(struct xt_tgchk_param *par, | ||
4737 | } | ||
4738 | EXPORT_SYMBOL_GPL(xt_check_target); | ||
4739 | |||
4740 | +/** | ||
4741 | + * xt_copy_counters_from_user - copy counters and metadata from userspace | ||
4742 | + * | ||
4743 | + * @user: src pointer to userspace memory | ||
4744 | + * @len: alleged size of userspace memory | ||
4745 | + * @info: where to store the xt_counters_info metadata | ||
4746 | + * @compat: true if we setsockopt call is done by 32bit task on 64bit kernel | ||
4747 | + * | ||
4748 | + * Copies counter meta data from @user and stores it in @info. | ||
4749 | + * | ||
4750 | + * vmallocs memory to hold the counters, then copies the counter data | ||
4751 | + * from @user to the new memory and returns a pointer to it. | ||
4752 | + * | ||
4753 | + * If @compat is true, @info gets converted automatically to the 64bit | ||
4754 | + * representation. | ||
4755 | + * | ||
4756 | + * The metadata associated with the counters is stored in @info. | ||
4757 | + * | ||
4758 | + * Return: returns pointer that caller has to test via IS_ERR(). | ||
4759 | + * If IS_ERR is false, caller has to vfree the pointer. | ||
4760 | + */ | ||
4761 | +void *xt_copy_counters_from_user(const void __user *user, unsigned int len, | ||
4762 | + struct xt_counters_info *info, bool compat) | ||
4763 | +{ | ||
4764 | + void *mem; | ||
4765 | + u64 size; | ||
4766 | + | ||
4767 | +#ifdef CONFIG_COMPAT | ||
4768 | + if (compat) { | ||
4769 | + /* structures only differ in size due to alignment */ | ||
4770 | + struct compat_xt_counters_info compat_tmp; | ||
4771 | + | ||
4772 | + if (len <= sizeof(compat_tmp)) | ||
4773 | + return ERR_PTR(-EINVAL); | ||
4774 | + | ||
4775 | + len -= sizeof(compat_tmp); | ||
4776 | + if (copy_from_user(&compat_tmp, user, sizeof(compat_tmp)) != 0) | ||
4777 | + return ERR_PTR(-EFAULT); | ||
4778 | + | ||
4779 | + strlcpy(info->name, compat_tmp.name, sizeof(info->name)); | ||
4780 | + info->num_counters = compat_tmp.num_counters; | ||
4781 | + user += sizeof(compat_tmp); | ||
4782 | + } else | ||
4783 | +#endif | ||
4784 | + { | ||
4785 | + if (len <= sizeof(*info)) | ||
4786 | + return ERR_PTR(-EINVAL); | ||
4787 | + | ||
4788 | + len -= sizeof(*info); | ||
4789 | + if (copy_from_user(info, user, sizeof(*info)) != 0) | ||
4790 | + return ERR_PTR(-EFAULT); | ||
4791 | + | ||
4792 | + info->name[sizeof(info->name) - 1] = '\0'; | ||
4793 | + user += sizeof(*info); | ||
4794 | + } | ||
4795 | + | ||
4796 | + size = sizeof(struct xt_counters); | ||
4797 | + size *= info->num_counters; | ||
4798 | + | ||
4799 | + if (size != (u64)len) | ||
4800 | + return ERR_PTR(-EINVAL); | ||
4801 | + | ||
4802 | + mem = vmalloc(len); | ||
4803 | + if (!mem) | ||
4804 | + return ERR_PTR(-ENOMEM); | ||
4805 | + | ||
4806 | + if (copy_from_user(mem, user, len) == 0) | ||
4807 | + return mem; | ||
4808 | + | ||
4809 | + vfree(mem); | ||
4810 | + return ERR_PTR(-EFAULT); | ||
4811 | +} | ||
4812 | +EXPORT_SYMBOL_GPL(xt_copy_counters_from_user); | ||
4813 | + | ||
4814 | #ifdef CONFIG_COMPAT | ||
4815 | int xt_compat_target_offset(const struct xt_target *target) | ||
4816 | { | ||
4817 | @@ -605,6 +840,7 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr, | ||
4818 | struct compat_xt_entry_target *ct = (struct compat_xt_entry_target *)t; | ||
4819 | int pad, off = xt_compat_target_offset(target); | ||
4820 | u_int16_t tsize = ct->u.user.target_size; | ||
4821 | + char name[sizeof(t->u.user.name)]; | ||
4822 | |||
4823 | t = *dstptr; | ||
4824 | memcpy(t, ct, sizeof(*ct)); | ||
4825 | @@ -618,6 +854,9 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr, | ||
4826 | |||
4827 | tsize += off; | ||
4828 | t->u.user.target_size = tsize; | ||
4829 | + strlcpy(name, target->name, sizeof(name)); | ||
4830 | + module_put(target->me); | ||
4831 | + strncpy(t->u.user.name, name, sizeof(t->u.user.name)); | ||
4832 | |||
4833 | *size += off; | ||
4834 | *dstptr += tsize; | ||
4835 | diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c | ||
4836 | index 992b35fb8615..7a5fa0c98377 100644 | ||
4837 | --- a/net/netlink/af_netlink.c | ||
4838 | +++ b/net/netlink/af_netlink.c | ||
4839 | @@ -2784,6 +2784,7 @@ static int netlink_dump(struct sock *sk) | ||
4840 | struct netlink_callback *cb; | ||
4841 | struct sk_buff *skb = NULL; | ||
4842 | struct nlmsghdr *nlh; | ||
4843 | + struct module *module; | ||
4844 | int len, err = -ENOBUFS; | ||
4845 | int alloc_min_size; | ||
4846 | int alloc_size; | ||
4847 | @@ -2863,9 +2864,11 @@ static int netlink_dump(struct sock *sk) | ||
4848 | cb->done(cb); | ||
4849 | |||
4850 | nlk->cb_running = false; | ||
4851 | + module = cb->module; | ||
4852 | + skb = cb->skb; | ||
4853 | mutex_unlock(nlk->cb_mutex); | ||
4854 | - module_put(cb->module); | ||
4855 | - consume_skb(cb->skb); | ||
4856 | + module_put(module); | ||
4857 | + consume_skb(skb); | ||
4858 | return 0; | ||
4859 | |||
4860 | errout_skb: | ||
4861 | diff --git a/net/openvswitch/vport-vxlan.c b/net/openvswitch/vport-vxlan.c | ||
4862 | index d933cb89efac..5eb7694348b5 100644 | ||
4863 | --- a/net/openvswitch/vport-vxlan.c | ||
4864 | +++ b/net/openvswitch/vport-vxlan.c | ||
4865 | @@ -91,6 +91,8 @@ static struct vport *vxlan_tnl_create(const struct vport_parms *parms) | ||
4866 | struct vxlan_config conf = { | ||
4867 | .no_share = true, | ||
4868 | .flags = VXLAN_F_COLLECT_METADATA | VXLAN_F_UDP_ZERO_CSUM6_RX, | ||
4869 | + /* Don't restrict the packets that can be sent by MTU */ | ||
4870 | + .mtu = IP_MAX_MTU, | ||
4871 | }; | ||
4872 | |||
4873 | if (!options) { | ||
4874 | diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c | ||
4875 | index d5d7132ac847..1b58866175e6 100644 | ||
4876 | --- a/net/switchdev/switchdev.c | ||
4877 | +++ b/net/switchdev/switchdev.c | ||
4878 | @@ -1169,6 +1169,7 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, | ||
4879 | .obj.id = SWITCHDEV_OBJ_ID_IPV4_FIB, | ||
4880 | .dst = dst, | ||
4881 | .dst_len = dst_len, | ||
4882 | + .fi = fi, | ||
4883 | .tos = tos, | ||
4884 | .type = type, | ||
4885 | .nlflags = nlflags, | ||
4886 | @@ -1177,8 +1178,6 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, | ||
4887 | struct net_device *dev; | ||
4888 | int err = 0; | ||
4889 | |||
4890 | - memcpy(&ipv4_fib.fi, fi, sizeof(ipv4_fib.fi)); | ||
4891 | - | ||
4892 | /* Don't offload route if using custom ip rules or if | ||
4893 | * IPv4 FIB offloading has been disabled completely. | ||
4894 | */ | ||
4895 | @@ -1222,6 +1221,7 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, | ||
4896 | .obj.id = SWITCHDEV_OBJ_ID_IPV4_FIB, | ||
4897 | .dst = dst, | ||
4898 | .dst_len = dst_len, | ||
4899 | + .fi = fi, | ||
4900 | .tos = tos, | ||
4901 | .type = type, | ||
4902 | .nlflags = 0, | ||
4903 | @@ -1230,8 +1230,6 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, | ||
4904 | struct net_device *dev; | ||
4905 | int err = 0; | ||
4906 | |||
4907 | - memcpy(&ipv4_fib.fi, fi, sizeof(ipv4_fib.fi)); | ||
4908 | - | ||
4909 | if (!(fi->fib_flags & RTNH_F_OFFLOAD)) | ||
4910 | return 0; | ||
4911 | |||
4912 | diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c | ||
4913 | index 1eadc95e1132..2ed732bfe94b 100644 | ||
4914 | --- a/net/tipc/netlink_compat.c | ||
4915 | +++ b/net/tipc/netlink_compat.c | ||
4916 | @@ -802,7 +802,7 @@ static int tipc_nl_compat_name_table_dump(struct tipc_nl_compat_msg *msg, | ||
4917 | goto out; | ||
4918 | |||
4919 | tipc_tlv_sprintf(msg->rep, "%-10u %s", | ||
4920 | - nla_get_u32(publ[TIPC_NLA_PUBL_REF]), | ||
4921 | + nla_get_u32(publ[TIPC_NLA_PUBL_KEY]), | ||
4922 | scope_str[nla_get_u32(publ[TIPC_NLA_PUBL_SCOPE])]); | ||
4923 | out: | ||
4924 | tipc_tlv_sprintf(msg->rep, "\n"); | ||
4925 | diff --git a/net/tipc/socket.c b/net/tipc/socket.c | ||
4926 | index e53003cf7703..9b713e0ce00d 100644 | ||
4927 | --- a/net/tipc/socket.c | ||
4928 | +++ b/net/tipc/socket.c | ||
4929 | @@ -2814,6 +2814,9 @@ int tipc_nl_publ_dump(struct sk_buff *skb, struct netlink_callback *cb) | ||
4930 | if (err) | ||
4931 | return err; | ||
4932 | |||
4933 | + if (!attrs[TIPC_NLA_SOCK]) | ||
4934 | + return -EINVAL; | ||
4935 | + | ||
4936 | err = nla_parse_nested(sock, TIPC_NLA_SOCK_MAX, | ||
4937 | attrs[TIPC_NLA_SOCK], | ||
4938 | tipc_nl_sock_policy); | ||
4939 | diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c | ||
4940 | index b50ee5d622e1..c753211cb83f 100644 | ||
4941 | --- a/net/wireless/wext-core.c | ||
4942 | +++ b/net/wireless/wext-core.c | ||
4943 | @@ -955,8 +955,29 @@ static int wireless_process_ioctl(struct net *net, struct ifreq *ifr, | ||
4944 | return private(dev, iwr, cmd, info, handler); | ||
4945 | } | ||
4946 | /* Old driver API : call driver ioctl handler */ | ||
4947 | - if (dev->netdev_ops->ndo_do_ioctl) | ||
4948 | - return dev->netdev_ops->ndo_do_ioctl(dev, ifr, cmd); | ||
4949 | + if (dev->netdev_ops->ndo_do_ioctl) { | ||
4950 | +#ifdef CONFIG_COMPAT | ||
4951 | + if (info->flags & IW_REQUEST_FLAG_COMPAT) { | ||
4952 | + int ret = 0; | ||
4953 | + struct iwreq iwr_lcl; | ||
4954 | + struct compat_iw_point *iwp_compat = (void *) &iwr->u.data; | ||
4955 | + | ||
4956 | + memcpy(&iwr_lcl, iwr, sizeof(struct iwreq)); | ||
4957 | + iwr_lcl.u.data.pointer = compat_ptr(iwp_compat->pointer); | ||
4958 | + iwr_lcl.u.data.length = iwp_compat->length; | ||
4959 | + iwr_lcl.u.data.flags = iwp_compat->flags; | ||
4960 | + | ||
4961 | + ret = dev->netdev_ops->ndo_do_ioctl(dev, (void *) &iwr_lcl, cmd); | ||
4962 | + | ||
4963 | + iwp_compat->pointer = ptr_to_compat(iwr_lcl.u.data.pointer); | ||
4964 | + iwp_compat->length = iwr_lcl.u.data.length; | ||
4965 | + iwp_compat->flags = iwr_lcl.u.data.flags; | ||
4966 | + | ||
4967 | + return ret; | ||
4968 | + } else | ||
4969 | +#endif | ||
4970 | + return dev->netdev_ops->ndo_do_ioctl(dev, ifr, cmd); | ||
4971 | + } | ||
4972 | return -EOPNOTSUPP; | ||
4973 | } | ||
4974 | |||
4975 | diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c | ||
4976 | index 411630e9c034..1475440b70aa 100644 | ||
4977 | --- a/sound/pci/hda/hda_intel.c | ||
4978 | +++ b/sound/pci/hda/hda_intel.c | ||
4979 | @@ -359,8 +359,11 @@ enum { | ||
4980 | |||
4981 | #define IS_SKL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa170) | ||
4982 | #define IS_SKL_LP(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x9d70) | ||
4983 | +#define IS_KBL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa171) | ||
4984 | +#define IS_KBL_LP(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x9d71) | ||
4985 | #define IS_BXT(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x5a98) | ||
4986 | -#define IS_SKL_PLUS(pci) (IS_SKL(pci) || IS_SKL_LP(pci) || IS_BXT(pci)) | ||
4987 | +#define IS_SKL_PLUS(pci) (IS_SKL(pci) || IS_SKL_LP(pci) || IS_BXT(pci)) || \ | ||
4988 | + IS_KBL(pci) || IS_KBL_LP(pci) | ||
4989 | |||
4990 | static char *driver_short_names[] = { | ||
4991 | [AZX_DRIVER_ICH] = "HDA Intel", | ||
4992 | @@ -2204,6 +2207,12 @@ static const struct pci_device_id azx_ids[] = { | ||
4993 | /* Sunrise Point-LP */ | ||
4994 | { PCI_DEVICE(0x8086, 0x9d70), | ||
4995 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE }, | ||
4996 | + /* Kabylake */ | ||
4997 | + { PCI_DEVICE(0x8086, 0xa171), | ||
4998 | + .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE }, | ||
4999 | + /* Kabylake-LP */ | ||
5000 | + { PCI_DEVICE(0x8086, 0x9d71), | ||
5001 | + .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_SKYLAKE }, | ||
5002 | /* Broxton-P(Apollolake) */ | ||
5003 | { PCI_DEVICE(0x8086, 0x5a98), | ||
5004 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_BROXTON }, | ||
5005 | diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c | ||
5006 | index d53c25e7a1c1..0fe18ede3e85 100644 | ||
5007 | --- a/sound/pci/hda/patch_realtek.c | ||
5008 | +++ b/sound/pci/hda/patch_realtek.c | ||
5009 | @@ -346,6 +346,9 @@ static void alc_fill_eapd_coef(struct hda_codec *codec) | ||
5010 | case 0x10ec0234: | ||
5011 | case 0x10ec0274: | ||
5012 | case 0x10ec0294: | ||
5013 | + case 0x10ec0700: | ||
5014 | + case 0x10ec0701: | ||
5015 | + case 0x10ec0703: | ||
5016 | alc_update_coef_idx(codec, 0x10, 1<<15, 0); | ||
5017 | break; | ||
5018 | case 0x10ec0662: | ||
5019 | @@ -2655,6 +2658,7 @@ enum { | ||
5020 | ALC269_TYPE_ALC256, | ||
5021 | ALC269_TYPE_ALC225, | ||
5022 | ALC269_TYPE_ALC294, | ||
5023 | + ALC269_TYPE_ALC700, | ||
5024 | }; | ||
5025 | |||
5026 | /* | ||
5027 | @@ -2686,6 +2690,7 @@ static int alc269_parse_auto_config(struct hda_codec *codec) | ||
5028 | case ALC269_TYPE_ALC256: | ||
5029 | case ALC269_TYPE_ALC225: | ||
5030 | case ALC269_TYPE_ALC294: | ||
5031 | + case ALC269_TYPE_ALC700: | ||
5032 | ssids = alc269_ssids; | ||
5033 | break; | ||
5034 | default: | ||
5035 | @@ -3618,13 +3623,20 @@ static void alc269_fixup_hp_line1_mic1_led(struct hda_codec *codec, | ||
5036 | static void alc_headset_mode_unplugged(struct hda_codec *codec) | ||
5037 | { | ||
5038 | static struct coef_fw coef0255[] = { | ||
5039 | - WRITE_COEF(0x1b, 0x0c0b), /* LDO and MISC control */ | ||
5040 | WRITE_COEF(0x45, 0xd089), /* UAJ function set to menual mode */ | ||
5041 | UPDATE_COEFEX(0x57, 0x05, 1<<14, 0), /* Direct Drive HP Amp control(Set to verb control)*/ | ||
5042 | WRITE_COEF(0x06, 0x6104), /* Set MIC2 Vref gate with HP */ | ||
5043 | WRITE_COEFEX(0x57, 0x03, 0x8aa6), /* Direct Drive HP Amp control */ | ||
5044 | {} | ||
5045 | }; | ||
5046 | + static struct coef_fw coef0255_1[] = { | ||
5047 | + WRITE_COEF(0x1b, 0x0c0b), /* LDO and MISC control */ | ||
5048 | + {} | ||
5049 | + }; | ||
5050 | + static struct coef_fw coef0256[] = { | ||
5051 | + WRITE_COEF(0x1b, 0x0c4b), /* LDO and MISC control */ | ||
5052 | + {} | ||
5053 | + }; | ||
5054 | static struct coef_fw coef0233[] = { | ||
5055 | WRITE_COEF(0x1b, 0x0c0b), | ||
5056 | WRITE_COEF(0x45, 0xc429), | ||
5057 | @@ -3677,7 +3689,11 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec) | ||
5058 | |||
5059 | switch (codec->core.vendor_id) { | ||
5060 | case 0x10ec0255: | ||
5061 | + alc_process_coef_fw(codec, coef0255_1); | ||
5062 | + alc_process_coef_fw(codec, coef0255); | ||
5063 | + break; | ||
5064 | case 0x10ec0256: | ||
5065 | + alc_process_coef_fw(codec, coef0256); | ||
5066 | alc_process_coef_fw(codec, coef0255); | ||
5067 | break; | ||
5068 | case 0x10ec0233: | ||
5069 | @@ -3896,6 +3912,12 @@ static void alc_headset_mode_ctia(struct hda_codec *codec) | ||
5070 | WRITE_COEFEX(0x57, 0x03, 0x8ea6), | ||
5071 | {} | ||
5072 | }; | ||
5073 | + static struct coef_fw coef0256[] = { | ||
5074 | + WRITE_COEF(0x45, 0xd489), /* Set to CTIA type */ | ||
5075 | + WRITE_COEF(0x1b, 0x0c6b), | ||
5076 | + WRITE_COEFEX(0x57, 0x03, 0x8ea6), | ||
5077 | + {} | ||
5078 | + }; | ||
5079 | static struct coef_fw coef0233[] = { | ||
5080 | WRITE_COEF(0x45, 0xd429), | ||
5081 | WRITE_COEF(0x1b, 0x0c2b), | ||
5082 | @@ -3936,9 +3958,11 @@ static void alc_headset_mode_ctia(struct hda_codec *codec) | ||
5083 | |||
5084 | switch (codec->core.vendor_id) { | ||
5085 | case 0x10ec0255: | ||
5086 | - case 0x10ec0256: | ||
5087 | alc_process_coef_fw(codec, coef0255); | ||
5088 | break; | ||
5089 | + case 0x10ec0256: | ||
5090 | + alc_process_coef_fw(codec, coef0256); | ||
5091 | + break; | ||
5092 | case 0x10ec0233: | ||
5093 | case 0x10ec0283: | ||
5094 | alc_process_coef_fw(codec, coef0233); | ||
5095 | @@ -3978,6 +4002,12 @@ static void alc_headset_mode_omtp(struct hda_codec *codec) | ||
5096 | WRITE_COEFEX(0x57, 0x03, 0x8ea6), | ||
5097 | {} | ||
5098 | }; | ||
5099 | + static struct coef_fw coef0256[] = { | ||
5100 | + WRITE_COEF(0x45, 0xe489), /* Set to OMTP Type */ | ||
5101 | + WRITE_COEF(0x1b, 0x0c6b), | ||
5102 | + WRITE_COEFEX(0x57, 0x03, 0x8ea6), | ||
5103 | + {} | ||
5104 | + }; | ||
5105 | static struct coef_fw coef0233[] = { | ||
5106 | WRITE_COEF(0x45, 0xe429), | ||
5107 | WRITE_COEF(0x1b, 0x0c2b), | ||
5108 | @@ -4018,9 +4048,11 @@ static void alc_headset_mode_omtp(struct hda_codec *codec) | ||
5109 | |||
5110 | switch (codec->core.vendor_id) { | ||
5111 | case 0x10ec0255: | ||
5112 | - case 0x10ec0256: | ||
5113 | alc_process_coef_fw(codec, coef0255); | ||
5114 | break; | ||
5115 | + case 0x10ec0256: | ||
5116 | + alc_process_coef_fw(codec, coef0256); | ||
5117 | + break; | ||
5118 | case 0x10ec0233: | ||
5119 | case 0x10ec0283: | ||
5120 | alc_process_coef_fw(codec, coef0233); | ||
5121 | @@ -4266,7 +4298,7 @@ static void alc_fixup_headset_mode_no_hp_mic(struct hda_codec *codec, | ||
5122 | static void alc255_set_default_jack_type(struct hda_codec *codec) | ||
5123 | { | ||
5124 | /* Set to iphone type */ | ||
5125 | - static struct coef_fw fw[] = { | ||
5126 | + static struct coef_fw alc255fw[] = { | ||
5127 | WRITE_COEF(0x1b, 0x880b), | ||
5128 | WRITE_COEF(0x45, 0xd089), | ||
5129 | WRITE_COEF(0x1b, 0x080b), | ||
5130 | @@ -4274,7 +4306,22 @@ static void alc255_set_default_jack_type(struct hda_codec *codec) | ||
5131 | WRITE_COEF(0x1b, 0x0c0b), | ||
5132 | {} | ||
5133 | }; | ||
5134 | - alc_process_coef_fw(codec, fw); | ||
5135 | + static struct coef_fw alc256fw[] = { | ||
5136 | + WRITE_COEF(0x1b, 0x884b), | ||
5137 | + WRITE_COEF(0x45, 0xd089), | ||
5138 | + WRITE_COEF(0x1b, 0x084b), | ||
5139 | + WRITE_COEF(0x46, 0x0004), | ||
5140 | + WRITE_COEF(0x1b, 0x0c4b), | ||
5141 | + {} | ||
5142 | + }; | ||
5143 | + switch (codec->core.vendor_id) { | ||
5144 | + case 0x10ec0255: | ||
5145 | + alc_process_coef_fw(codec, alc255fw); | ||
5146 | + break; | ||
5147 | + case 0x10ec0256: | ||
5148 | + alc_process_coef_fw(codec, alc256fw); | ||
5149 | + break; | ||
5150 | + } | ||
5151 | msleep(30); | ||
5152 | } | ||
5153 | |||
5154 | @@ -5587,6 +5634,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = { | ||
5155 | SND_PCI_QUIRK(0x17aa, 0x2218, "Thinkpad X1 Carbon 2nd", ALC292_FIXUP_TPT440_DOCK), | ||
5156 | SND_PCI_QUIRK(0x17aa, 0x2223, "ThinkPad T550", ALC292_FIXUP_TPT440_DOCK), | ||
5157 | SND_PCI_QUIRK(0x17aa, 0x2226, "ThinkPad X250", ALC292_FIXUP_TPT440_DOCK), | ||
5158 | + SND_PCI_QUIRK(0x17aa, 0x2231, "Thinkpad T560", ALC292_FIXUP_TPT460), | ||
5159 | SND_PCI_QUIRK(0x17aa, 0x2233, "Thinkpad", ALC292_FIXUP_TPT460), | ||
5160 | SND_PCI_QUIRK(0x17aa, 0x30bb, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY), | ||
5161 | SND_PCI_QUIRK(0x17aa, 0x30e2, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY), | ||
5162 | @@ -5775,6 +5823,10 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = { | ||
5163 | {0x12, 0x90a60180}, | ||
5164 | {0x14, 0x90170130}, | ||
5165 | {0x21, 0x02211040}), | ||
5166 | + SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell Inspiron 5565", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, | ||
5167 | + {0x12, 0x90a60180}, | ||
5168 | + {0x14, 0x90170120}, | ||
5169 | + {0x21, 0x02211030}), | ||
5170 | SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, | ||
5171 | {0x12, 0x90a60160}, | ||
5172 | {0x14, 0x90170120}, | ||
5173 | @@ -6053,6 +6105,14 @@ static int patch_alc269(struct hda_codec *codec) | ||
5174 | case 0x10ec0294: | ||
5175 | spec->codec_variant = ALC269_TYPE_ALC294; | ||
5176 | break; | ||
5177 | + case 0x10ec0700: | ||
5178 | + case 0x10ec0701: | ||
5179 | + case 0x10ec0703: | ||
5180 | + spec->codec_variant = ALC269_TYPE_ALC700; | ||
5181 | + spec->gen.mixer_nid = 0; /* ALC700 does not have any loopback mixer path */ | ||
5182 | + alc_update_coef_idx(codec, 0x4a, 0, 1 << 15); /* Combo jack auto trigger control */ | ||
5183 | + break; | ||
5184 | + | ||
5185 | } | ||
5186 | |||
5187 | if (snd_hda_codec_read(codec, 0x51, 0, AC_VERB_PARAMETERS, 0) == 0x10ec5505) { | ||
5188 | @@ -7008,6 +7068,9 @@ static const struct hda_device_id snd_hda_id_realtek[] = { | ||
5189 | HDA_CODEC_ENTRY(0x10ec0670, "ALC670", patch_alc662), | ||
5190 | HDA_CODEC_ENTRY(0x10ec0671, "ALC671", patch_alc662), | ||
5191 | HDA_CODEC_ENTRY(0x10ec0680, "ALC680", patch_alc680), | ||
5192 | + HDA_CODEC_ENTRY(0x10ec0700, "ALC700", patch_alc269), | ||
5193 | + HDA_CODEC_ENTRY(0x10ec0701, "ALC701", patch_alc269), | ||
5194 | + HDA_CODEC_ENTRY(0x10ec0703, "ALC703", patch_alc269), | ||
5195 | HDA_CODEC_ENTRY(0x10ec0867, "ALC891", patch_alc882), | ||
5196 | HDA_CODEC_ENTRY(0x10ec0880, "ALC880", patch_alc880), | ||
5197 | HDA_CODEC_ENTRY(0x10ec0882, "ALC882", patch_alc882), | ||
5198 | diff --git a/virt/kvm/irqchip.c b/virt/kvm/irqchip.c | ||
5199 | index f0b08a2a48ba..7d31d8c5b9ea 100644 | ||
5200 | --- a/virt/kvm/irqchip.c | ||
5201 | +++ b/virt/kvm/irqchip.c | ||
5202 | @@ -40,7 +40,7 @@ int kvm_irq_map_gsi(struct kvm *kvm, | ||
5203 | |||
5204 | irq_rt = srcu_dereference_check(kvm->irq_routing, &kvm->irq_srcu, | ||
5205 | lockdep_is_held(&kvm->irq_lock)); | ||
5206 | - if (gsi < irq_rt->nr_rt_entries) { | ||
5207 | + if (irq_rt && gsi < irq_rt->nr_rt_entries) { | ||
5208 | hlist_for_each_entry(e, &irq_rt->map[gsi], link) { | ||
5209 | entries[n] = *e; | ||
5210 | ++n; |