]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.2.2-3.2.1-201201252020.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-3.2.1-201201252020.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index dfa6fc6..0095943 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -5,6 +5,7 @@
6 *.cis
7 *.cpio
8 *.csp
9 +*.dbg
10 *.dsp
11 *.dvi
12 *.elf
13 @@ -14,6 +15,7 @@
14 *.gcov
15 *.gen.S
16 *.gif
17 +*.gmo
18 *.grep
19 *.grp
20 *.gz
21 @@ -48,9 +50,11 @@
22 *.tab.h
23 *.tex
24 *.ver
25 +*.vim
26 *.xml
27 *.xz
28 *_MODULES
29 +*_reg_safe.h
30 *_vga16.c
31 *~
32 \#*#
33 @@ -70,6 +74,7 @@ Kerntypes
34 Module.markers
35 Module.symvers
36 PENDING
37 +PERF*
38 SCCS
39 System.map*
40 TAGS
41 @@ -93,19 +98,24 @@ bounds.h
42 bsetup
43 btfixupprep
44 build
45 +builtin-policy.h
46 bvmlinux
47 bzImage*
48 capability_names.h
49 capflags.c
50 classlist.h*
51 +clut_vga16.c
52 +common-cmds.h
53 comp*.log
54 compile.h*
55 conf
56 config
57 config-*
58 config_data.h*
59 +config.c
60 config.mak
61 config.mak.autogen
62 +config.tmp
63 conmakehash
64 consolemap_deftbl.c*
65 cpustr.h
66 @@ -119,6 +129,7 @@ dslm
67 elf2ecoff
68 elfconfig.h*
69 evergreen_reg_safe.h
70 +exception_policy.conf
71 fixdep
72 flask.h
73 fore200e_mkfirm
74 @@ -126,12 +137,15 @@ fore200e_pca_fw.c*
75 gconf
76 gconf.glade.h
77 gen-devlist
78 +gen-kdb_cmds.c
79 gen_crc32table
80 gen_init_cpio
81 generated
82 genheaders
83 genksyms
84 *_gray256.c
85 +hash
86 +hid-example
87 hpet_example
88 hugepage-mmap
89 hugepage-shm
90 @@ -146,7 +160,7 @@ int32.c
91 int4.c
92 int8.c
93 kallsyms
94 -kconfig
95 +kern_constants.h
96 keywords.c
97 ksym.c*
98 ksym.h*
99 @@ -154,7 +168,6 @@ kxgettext
100 lkc_defs.h
101 lex.c
102 lex.*.c
103 -linux
104 logo_*.c
105 logo_*_clut224.c
106 logo_*_mono.c
107 @@ -166,14 +179,15 @@ machtypes.h
108 map
109 map_hugetlb
110 maui_boot.h
111 -media
112 mconf
113 +mdp
114 miboot*
115 mk_elfconfig
116 mkboot
117 mkbugboot
118 mkcpustr
119 mkdep
120 +mkpiggy
121 mkprep
122 mkregtable
123 mktables
124 @@ -209,6 +223,7 @@ r300_reg_safe.h
125 r420_reg_safe.h
126 r600_reg_safe.h
127 recordmcount
128 +regdb.c
129 relocs
130 rlim_names.h
131 rn50_reg_safe.h
132 @@ -219,6 +234,7 @@ setup
133 setup.bin
134 setup.elf
135 sImage
136 +slabinfo
137 sm_tbl*
138 split-include
139 syscalltab.h
140 @@ -229,6 +245,7 @@ tftpboot.img
141 timeconst.h
142 times.h*
143 trix_boot.h
144 +user_constants.h
145 utsrelease.h*
146 vdso-syms.lds
147 vdso.lds
148 @@ -246,7 +263,9 @@ vmlinux
149 vmlinux-*
150 vmlinux.aout
151 vmlinux.bin.all
152 +vmlinux.bin.bz2
153 vmlinux.lds
154 +vmlinux.relocs
155 vmlinuz
156 voffset.h
157 vsyscall.lds
158 @@ -254,9 +273,11 @@ vsyscall_32.lds
159 wanxlfw.inc
160 uImage
161 unifdef
162 +utsrelease.h
163 wakeup.bin
164 wakeup.elf
165 wakeup.lds
166 zImage*
167 zconf.hash.c
168 +zconf.lex.c
169 zoffset.h
170 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
171 index 81c287f..d456d02 100644
172 --- a/Documentation/kernel-parameters.txt
173 +++ b/Documentation/kernel-parameters.txt
174 @@ -1935,6 +1935,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
175 the specified number of seconds. This is to be used if
176 your oopses keep scrolling off the screen.
177
178 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
179 + virtualization environments that don't cope well with the
180 + expand down segment used by UDEREF on X86-32 or the frequent
181 + page table updates on X86-64.
182 +
183 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
184 +
185 pcbit= [HW,ISDN]
186
187 pcd. [PARIDE]
188 diff --git a/Makefile b/Makefile
189 index c5edffa..26654d7 100644
190 --- a/Makefile
191 +++ b/Makefile
192 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
193
194 HOSTCC = gcc
195 HOSTCXX = g++
196 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
197 -HOSTCXXFLAGS = -O2
198 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
199 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
200 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
201
202 # Decide whether to build built-in, modular, or both.
203 # Normally, just do built-in.
204 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
205 # Rules shared between *config targets and build targets
206
207 # Basic helpers built in scripts/
208 -PHONY += scripts_basic
209 -scripts_basic:
210 +PHONY += scripts_basic gcc-plugins
211 +scripts_basic: gcc-plugins
212 $(Q)$(MAKE) $(build)=scripts/basic
213 $(Q)rm -f .tmp_quiet_recordmcount
214
215 @@ -564,6 +565,46 @@ else
216 KBUILD_CFLAGS += -O2
217 endif
218
219 +ifndef DISABLE_PAX_PLUGINS
220 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
221 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
222 +CONSTIFY_PLUGIN := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
223 +endif
224 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
225 +STACKLEAK_PLUGIN := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
226 +STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
227 +endif
228 +ifdef CONFIG_KALLOCSTAT_PLUGIN
229 +KALLOCSTAT_PLUGIN := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
230 +endif
231 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
232 +KERNEXEC_PLUGIN := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
233 +KERNEXEC_PLUGIN += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD)
234 +endif
235 +ifdef CONFIG_CHECKER_PLUGIN
236 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
237 +CHECKER_PLUGIN := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
238 +endif
239 +endif
240 +GCC_PLUGINS := $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN) $(KALLOCSTAT_PLUGIN) $(KERNEXEC_PLUGIN) $(CHECKER_PLUGIN)
241 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
242 +ifeq ($(KBUILD_EXTMOD),)
243 +gcc-plugins:
244 + $(Q)$(MAKE) $(build)=tools/gcc
245 +else
246 +gcc-plugins: ;
247 +endif
248 +else
249 +gcc-plugins:
250 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
251 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
252 +else
253 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
254 +endif
255 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
256 +endif
257 +endif
258 +
259 include $(srctree)/arch/$(SRCARCH)/Makefile
260
261 ifneq ($(CONFIG_FRAME_WARN),0)
262 @@ -708,7 +749,7 @@ export mod_strip_cmd
263
264
265 ifeq ($(KBUILD_EXTMOD),)
266 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
267 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
268
269 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
270 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
271 @@ -932,6 +973,7 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
272
273 # The actual objects are generated when descending,
274 # make sure no implicit rule kicks in
275 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS)
276 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
277
278 # Handle descending into subdirectories listed in $(vmlinux-dirs)
279 @@ -941,7 +983,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
280 # Error messages still appears in the original language
281
282 PHONY += $(vmlinux-dirs)
283 -$(vmlinux-dirs): prepare scripts
284 +$(vmlinux-dirs): gcc-plugins prepare scripts
285 $(Q)$(MAKE) $(build)=$@
286
287 # Store (new) KERNELRELASE string in include/config/kernel.release
288 @@ -985,6 +1027,7 @@ prepare0: archprepare FORCE
289 $(Q)$(MAKE) $(build)=.
290
291 # All the preparing..
292 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS),$(KBUILD_CFLAGS))
293 prepare: prepare0
294
295 # Generate some files
296 @@ -1086,6 +1129,7 @@ all: modules
297 # using awk while concatenating to the final file.
298
299 PHONY += modules
300 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
301 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
302 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
303 @$(kecho) ' Building modules, stage 2.';
304 @@ -1101,7 +1145,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
305
306 # Target to prepare building external modules
307 PHONY += modules_prepare
308 -modules_prepare: prepare scripts
309 +modules_prepare: gcc-plugins prepare scripts
310
311 # Target to install modules
312 PHONY += modules_install
313 @@ -1198,6 +1242,7 @@ distclean: mrproper
314 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
315 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
316 -o -name '.*.rej' \
317 + -o -name '.*.rej' -o -name '*.so' \
318 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
319 -type f -print | xargs rm -f
320
321 @@ -1358,6 +1403,7 @@ PHONY += $(module-dirs) modules
322 $(module-dirs): crmodverdir $(objtree)/Module.symvers
323 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
324
325 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
326 modules: $(module-dirs)
327 @$(kecho) ' Building modules, stage 2.';
328 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
329 @@ -1484,17 +1530,19 @@ else
330 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
331 endif
332
333 -%.s: %.c prepare scripts FORCE
334 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS)
335 +%.s: %.c gcc-plugins prepare scripts FORCE
336 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
337 %.i: %.c prepare scripts FORCE
338 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
339 -%.o: %.c prepare scripts FORCE
340 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS)
341 +%.o: %.c gcc-plugins prepare scripts FORCE
342 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
343 %.lst: %.c prepare scripts FORCE
344 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
345 -%.s: %.S prepare scripts FORCE
346 +%.s: %.S gcc-plugins prepare scripts FORCE
347 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
348 -%.o: %.S prepare scripts FORCE
349 +%.o: %.S gcc-plugins prepare scripts FORCE
350 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
351 %.symtypes: %.c prepare scripts FORCE
352 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
353 @@ -1504,11 +1552,13 @@ endif
354 $(cmd_crmodverdir)
355 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
356 $(build)=$(build-dir)
357 -%/: prepare scripts FORCE
358 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS)
359 +%/: gcc-plugins prepare scripts FORCE
360 $(cmd_crmodverdir)
361 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
362 $(build)=$(build-dir)
363 -%.ko: prepare scripts FORCE
364 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS)
365 +%.ko: gcc-plugins prepare scripts FORCE
366 $(cmd_crmodverdir)
367 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
368 $(build)=$(build-dir) $(@:.ko=.o)
369 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
370 index da5449e..7418343 100644
371 --- a/arch/alpha/include/asm/elf.h
372 +++ b/arch/alpha/include/asm/elf.h
373 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
374
375 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
376
377 +#ifdef CONFIG_PAX_ASLR
378 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
379 +
380 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
381 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
382 +#endif
383 +
384 /* $0 is set by ld.so to a pointer to a function which might be
385 registered using atexit. This provides a mean for the dynamic
386 linker to call DT_FINI functions for shared libraries that have
387 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
388 index de98a73..bd4f1f8 100644
389 --- a/arch/alpha/include/asm/pgtable.h
390 +++ b/arch/alpha/include/asm/pgtable.h
391 @@ -101,6 +101,17 @@ struct vm_area_struct;
392 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
393 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
394 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
395 +
396 +#ifdef CONFIG_PAX_PAGEEXEC
397 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
398 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
399 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
400 +#else
401 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
402 +# define PAGE_COPY_NOEXEC PAGE_COPY
403 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
404 +#endif
405 +
406 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
407
408 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
409 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
410 index 2fd00b7..cfd5069 100644
411 --- a/arch/alpha/kernel/module.c
412 +++ b/arch/alpha/kernel/module.c
413 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
414
415 /* The small sections were sorted to the end of the segment.
416 The following should definitely cover them. */
417 - gp = (u64)me->module_core + me->core_size - 0x8000;
418 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
419 got = sechdrs[me->arch.gotsecindex].sh_addr;
420
421 for (i = 0; i < n; i++) {
422 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
423 index 01e8715..be0e80f 100644
424 --- a/arch/alpha/kernel/osf_sys.c
425 +++ b/arch/alpha/kernel/osf_sys.c
426 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
427 /* At this point: (!vma || addr < vma->vm_end). */
428 if (limit - len < addr)
429 return -ENOMEM;
430 - if (!vma || addr + len <= vma->vm_start)
431 + if (check_heap_stack_gap(vma, addr, len))
432 return addr;
433 addr = vma->vm_end;
434 vma = vma->vm_next;
435 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
436 merely specific addresses, but regions of memory -- perhaps
437 this feature should be incorporated into all ports? */
438
439 +#ifdef CONFIG_PAX_RANDMMAP
440 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
441 +#endif
442 +
443 if (addr) {
444 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
445 if (addr != (unsigned long) -ENOMEM)
446 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
447 }
448
449 /* Next, try allocating at TASK_UNMAPPED_BASE. */
450 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
451 - len, limit);
452 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
453 +
454 if (addr != (unsigned long) -ENOMEM)
455 return addr;
456
457 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
458 index fadd5f8..904e73a 100644
459 --- a/arch/alpha/mm/fault.c
460 +++ b/arch/alpha/mm/fault.c
461 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
462 __reload_thread(pcb);
463 }
464
465 +#ifdef CONFIG_PAX_PAGEEXEC
466 +/*
467 + * PaX: decide what to do with offenders (regs->pc = fault address)
468 + *
469 + * returns 1 when task should be killed
470 + * 2 when patched PLT trampoline was detected
471 + * 3 when unpatched PLT trampoline was detected
472 + */
473 +static int pax_handle_fetch_fault(struct pt_regs *regs)
474 +{
475 +
476 +#ifdef CONFIG_PAX_EMUPLT
477 + int err;
478 +
479 + do { /* PaX: patched PLT emulation #1 */
480 + unsigned int ldah, ldq, jmp;
481 +
482 + err = get_user(ldah, (unsigned int *)regs->pc);
483 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
484 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
485 +
486 + if (err)
487 + break;
488 +
489 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
490 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
491 + jmp == 0x6BFB0000U)
492 + {
493 + unsigned long r27, addr;
494 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
495 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
496 +
497 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
498 + err = get_user(r27, (unsigned long *)addr);
499 + if (err)
500 + break;
501 +
502 + regs->r27 = r27;
503 + regs->pc = r27;
504 + return 2;
505 + }
506 + } while (0);
507 +
508 + do { /* PaX: patched PLT emulation #2 */
509 + unsigned int ldah, lda, br;
510 +
511 + err = get_user(ldah, (unsigned int *)regs->pc);
512 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
513 + err |= get_user(br, (unsigned int *)(regs->pc+8));
514 +
515 + if (err)
516 + break;
517 +
518 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
519 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
520 + (br & 0xFFE00000U) == 0xC3E00000U)
521 + {
522 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
523 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
524 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
525 +
526 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
527 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
528 + return 2;
529 + }
530 + } while (0);
531 +
532 + do { /* PaX: unpatched PLT emulation */
533 + unsigned int br;
534 +
535 + err = get_user(br, (unsigned int *)regs->pc);
536 +
537 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
538 + unsigned int br2, ldq, nop, jmp;
539 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
540 +
541 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
542 + err = get_user(br2, (unsigned int *)addr);
543 + err |= get_user(ldq, (unsigned int *)(addr+4));
544 + err |= get_user(nop, (unsigned int *)(addr+8));
545 + err |= get_user(jmp, (unsigned int *)(addr+12));
546 + err |= get_user(resolver, (unsigned long *)(addr+16));
547 +
548 + if (err)
549 + break;
550 +
551 + if (br2 == 0xC3600000U &&
552 + ldq == 0xA77B000CU &&
553 + nop == 0x47FF041FU &&
554 + jmp == 0x6B7B0000U)
555 + {
556 + regs->r28 = regs->pc+4;
557 + regs->r27 = addr+16;
558 + regs->pc = resolver;
559 + return 3;
560 + }
561 + }
562 + } while (0);
563 +#endif
564 +
565 + return 1;
566 +}
567 +
568 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
569 +{
570 + unsigned long i;
571 +
572 + printk(KERN_ERR "PAX: bytes at PC: ");
573 + for (i = 0; i < 5; i++) {
574 + unsigned int c;
575 + if (get_user(c, (unsigned int *)pc+i))
576 + printk(KERN_CONT "???????? ");
577 + else
578 + printk(KERN_CONT "%08x ", c);
579 + }
580 + printk("\n");
581 +}
582 +#endif
583
584 /*
585 * This routine handles page faults. It determines the address,
586 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
587 good_area:
588 si_code = SEGV_ACCERR;
589 if (cause < 0) {
590 - if (!(vma->vm_flags & VM_EXEC))
591 + if (!(vma->vm_flags & VM_EXEC)) {
592 +
593 +#ifdef CONFIG_PAX_PAGEEXEC
594 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
595 + goto bad_area;
596 +
597 + up_read(&mm->mmap_sem);
598 + switch (pax_handle_fetch_fault(regs)) {
599 +
600 +#ifdef CONFIG_PAX_EMUPLT
601 + case 2:
602 + case 3:
603 + return;
604 +#endif
605 +
606 + }
607 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
608 + do_group_exit(SIGKILL);
609 +#else
610 goto bad_area;
611 +#endif
612 +
613 + }
614 } else if (!cause) {
615 /* Allow reads even for write-only mappings */
616 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
617 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
618 index 86976d0..8a57797 100644
619 --- a/arch/arm/include/asm/atomic.h
620 +++ b/arch/arm/include/asm/atomic.h
621 @@ -239,6 +239,14 @@ typedef struct {
622 u64 __aligned(8) counter;
623 } atomic64_t;
624
625 +#ifdef CONFIG_PAX_REFCOUNT
626 +typedef struct {
627 + u64 __aligned(8) counter;
628 +} atomic64_unchecked_t;
629 +#else
630 +typedef atomic64_t atomic64_unchecked_t;
631 +#endif
632 +
633 #define ATOMIC64_INIT(i) { (i) }
634
635 static inline u64 atomic64_read(atomic64_t *v)
636 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
637 index 0e9ce8d..6ef1e03 100644
638 --- a/arch/arm/include/asm/elf.h
639 +++ b/arch/arm/include/asm/elf.h
640 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
641 the loader. We need to make sure that it is out of the way of the program
642 that it will "exec", and that there is sufficient room for the brk. */
643
644 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
645 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
646 +
647 +#ifdef CONFIG_PAX_ASLR
648 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
649 +
650 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
651 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
652 +#endif
653
654 /* When the program starts, a1 contains a pointer to a function to be
655 registered with atexit, as per the SVR4 ABI. A value of 0 means we
656 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
657 extern void elf_set_personality(const struct elf32_hdr *);
658 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
659
660 -struct mm_struct;
661 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
662 -#define arch_randomize_brk arch_randomize_brk
663 -
664 extern int vectors_user_mapping(void);
665 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
666 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
667 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
668 index e51b1e8..32a3113 100644
669 --- a/arch/arm/include/asm/kmap_types.h
670 +++ b/arch/arm/include/asm/kmap_types.h
671 @@ -21,6 +21,7 @@ enum km_type {
672 KM_L1_CACHE,
673 KM_L2_CACHE,
674 KM_KDB,
675 + KM_CLEARPAGE,
676 KM_TYPE_NR
677 };
678
679 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
680 index b293616..96310e5 100644
681 --- a/arch/arm/include/asm/uaccess.h
682 +++ b/arch/arm/include/asm/uaccess.h
683 @@ -22,6 +22,8 @@
684 #define VERIFY_READ 0
685 #define VERIFY_WRITE 1
686
687 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
688 +
689 /*
690 * The exception table consists of pairs of addresses: the first is the
691 * address of an instruction that is allowed to fault, and the second is
692 @@ -387,8 +389,23 @@ do { \
693
694
695 #ifdef CONFIG_MMU
696 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
697 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
698 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
699 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
700 +
701 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
702 +{
703 + if (!__builtin_constant_p(n))
704 + check_object_size(to, n, false);
705 + return ___copy_from_user(to, from, n);
706 +}
707 +
708 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
709 +{
710 + if (!__builtin_constant_p(n))
711 + check_object_size(from, n, true);
712 + return ___copy_to_user(to, from, n);
713 +}
714 +
715 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
716 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
717 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
718 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
719
720 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
721 {
722 + if ((long)n < 0)
723 + return n;
724 +
725 if (access_ok(VERIFY_READ, from, n))
726 n = __copy_from_user(to, from, n);
727 else /* security hole - plug it */
728 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
729
730 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
731 {
732 + if ((long)n < 0)
733 + return n;
734 +
735 if (access_ok(VERIFY_WRITE, to, n))
736 n = __copy_to_user(to, from, n);
737 return n;
738 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
739 index 5b0bce6..becd81c 100644
740 --- a/arch/arm/kernel/armksyms.c
741 +++ b/arch/arm/kernel/armksyms.c
742 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
743 #ifdef CONFIG_MMU
744 EXPORT_SYMBOL(copy_page);
745
746 -EXPORT_SYMBOL(__copy_from_user);
747 -EXPORT_SYMBOL(__copy_to_user);
748 +EXPORT_SYMBOL(___copy_from_user);
749 +EXPORT_SYMBOL(___copy_to_user);
750 EXPORT_SYMBOL(__clear_user);
751
752 EXPORT_SYMBOL(__get_user_1);
753 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
754 index 3d0c6fb..3dcae52 100644
755 --- a/arch/arm/kernel/process.c
756 +++ b/arch/arm/kernel/process.c
757 @@ -28,7 +28,6 @@
758 #include <linux/tick.h>
759 #include <linux/utsname.h>
760 #include <linux/uaccess.h>
761 -#include <linux/random.h>
762 #include <linux/hw_breakpoint.h>
763 #include <linux/cpuidle.h>
764
765 @@ -484,12 +483,6 @@ unsigned long get_wchan(struct task_struct *p)
766 return 0;
767 }
768
769 -unsigned long arch_randomize_brk(struct mm_struct *mm)
770 -{
771 - unsigned long range_end = mm->brk + 0x02000000;
772 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
773 -}
774 -
775 #ifdef CONFIG_MMU
776 /*
777 * The vectors page is always readable from user space for the
778 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
779 index 99a5727..a3d5bb1 100644
780 --- a/arch/arm/kernel/traps.c
781 +++ b/arch/arm/kernel/traps.c
782 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
783
784 static DEFINE_RAW_SPINLOCK(die_lock);
785
786 +extern void gr_handle_kernel_exploit(void);
787 +
788 /*
789 * This function is protected against re-entrancy.
790 */
791 @@ -288,6 +290,9 @@ void die(const char *str, struct pt_regs *regs, int err)
792 panic("Fatal exception in interrupt");
793 if (panic_on_oops)
794 panic("Fatal exception");
795 +
796 + gr_handle_kernel_exploit();
797 +
798 if (ret != NOTIFY_STOP)
799 do_exit(SIGSEGV);
800 }
801 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
802 index 66a477a..bee61d3 100644
803 --- a/arch/arm/lib/copy_from_user.S
804 +++ b/arch/arm/lib/copy_from_user.S
805 @@ -16,7 +16,7 @@
806 /*
807 * Prototype:
808 *
809 - * size_t __copy_from_user(void *to, const void *from, size_t n)
810 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
811 *
812 * Purpose:
813 *
814 @@ -84,11 +84,11 @@
815
816 .text
817
818 -ENTRY(__copy_from_user)
819 +ENTRY(___copy_from_user)
820
821 #include "copy_template.S"
822
823 -ENDPROC(__copy_from_user)
824 +ENDPROC(___copy_from_user)
825
826 .pushsection .fixup,"ax"
827 .align 0
828 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
829 index d066df6..df28194 100644
830 --- a/arch/arm/lib/copy_to_user.S
831 +++ b/arch/arm/lib/copy_to_user.S
832 @@ -16,7 +16,7 @@
833 /*
834 * Prototype:
835 *
836 - * size_t __copy_to_user(void *to, const void *from, size_t n)
837 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
838 *
839 * Purpose:
840 *
841 @@ -88,11 +88,11 @@
842 .text
843
844 ENTRY(__copy_to_user_std)
845 -WEAK(__copy_to_user)
846 +WEAK(___copy_to_user)
847
848 #include "copy_template.S"
849
850 -ENDPROC(__copy_to_user)
851 +ENDPROC(___copy_to_user)
852 ENDPROC(__copy_to_user_std)
853
854 .pushsection .fixup,"ax"
855 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
856 index d0ece2a..5ae2f39 100644
857 --- a/arch/arm/lib/uaccess.S
858 +++ b/arch/arm/lib/uaccess.S
859 @@ -20,7 +20,7 @@
860
861 #define PAGE_SHIFT 12
862
863 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
864 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
865 * Purpose : copy a block to user memory from kernel memory
866 * Params : to - user memory
867 * : from - kernel memory
868 @@ -40,7 +40,7 @@ USER( T(strgtb) r3, [r0], #1) @ May fault
869 sub r2, r2, ip
870 b .Lc2u_dest_aligned
871
872 -ENTRY(__copy_to_user)
873 +ENTRY(___copy_to_user)
874 stmfd sp!, {r2, r4 - r7, lr}
875 cmp r2, #4
876 blt .Lc2u_not_enough
877 @@ -278,14 +278,14 @@ USER( T(strgeb) r3, [r0], #1) @ May fault
878 ldrgtb r3, [r1], #0
879 USER( T(strgtb) r3, [r0], #1) @ May fault
880 b .Lc2u_finished
881 -ENDPROC(__copy_to_user)
882 +ENDPROC(___copy_to_user)
883
884 .pushsection .fixup,"ax"
885 .align 0
886 9001: ldmfd sp!, {r0, r4 - r7, pc}
887 .popsection
888
889 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
890 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
891 * Purpose : copy a block from user memory to kernel memory
892 * Params : to - kernel memory
893 * : from - user memory
894 @@ -304,7 +304,7 @@ USER( T(ldrgtb) r3, [r1], #1) @ May fault
895 sub r2, r2, ip
896 b .Lcfu_dest_aligned
897
898 -ENTRY(__copy_from_user)
899 +ENTRY(___copy_from_user)
900 stmfd sp!, {r0, r2, r4 - r7, lr}
901 cmp r2, #4
902 blt .Lcfu_not_enough
903 @@ -544,7 +544,7 @@ USER( T(ldrgeb) r3, [r1], #1) @ May fault
904 USER( T(ldrgtb) r3, [r1], #1) @ May fault
905 strgtb r3, [r0], #1
906 b .Lcfu_finished
907 -ENDPROC(__copy_from_user)
908 +ENDPROC(___copy_from_user)
909
910 .pushsection .fixup,"ax"
911 .align 0
912 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
913 index 025f742..8432b08 100644
914 --- a/arch/arm/lib/uaccess_with_memcpy.c
915 +++ b/arch/arm/lib/uaccess_with_memcpy.c
916 @@ -104,7 +104,7 @@ out:
917 }
918
919 unsigned long
920 -__copy_to_user(void __user *to, const void *from, unsigned long n)
921 +___copy_to_user(void __user *to, const void *from, unsigned long n)
922 {
923 /*
924 * This test is stubbed out of the main function above to keep
925 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
926 index 2b2d51c..0127490 100644
927 --- a/arch/arm/mach-ux500/mbox-db5500.c
928 +++ b/arch/arm/mach-ux500/mbox-db5500.c
929 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
930 return sprintf(buf, "0x%X\n", mbox_value);
931 }
932
933 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
934 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
935
936 static int mbox_show(struct seq_file *s, void *data)
937 {
938 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
939 index aa33949..b242a2f 100644
940 --- a/arch/arm/mm/fault.c
941 +++ b/arch/arm/mm/fault.c
942 @@ -183,6 +183,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
943 }
944 #endif
945
946 +#ifdef CONFIG_PAX_PAGEEXEC
947 + if (fsr & FSR_LNX_PF) {
948 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
949 + do_group_exit(SIGKILL);
950 + }
951 +#endif
952 +
953 tsk->thread.address = addr;
954 tsk->thread.error_code = fsr;
955 tsk->thread.trap_no = 14;
956 @@ -384,6 +391,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
957 }
958 #endif /* CONFIG_MMU */
959
960 +#ifdef CONFIG_PAX_PAGEEXEC
961 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
962 +{
963 + long i;
964 +
965 + printk(KERN_ERR "PAX: bytes at PC: ");
966 + for (i = 0; i < 20; i++) {
967 + unsigned char c;
968 + if (get_user(c, (__force unsigned char __user *)pc+i))
969 + printk(KERN_CONT "?? ");
970 + else
971 + printk(KERN_CONT "%02x ", c);
972 + }
973 + printk("\n");
974 +
975 + printk(KERN_ERR "PAX: bytes at SP-4: ");
976 + for (i = -1; i < 20; i++) {
977 + unsigned long c;
978 + if (get_user(c, (__force unsigned long __user *)sp+i))
979 + printk(KERN_CONT "???????? ");
980 + else
981 + printk(KERN_CONT "%08lx ", c);
982 + }
983 + printk("\n");
984 +}
985 +#endif
986 +
987 /*
988 * First Level Translation Fault Handler
989 *
990 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
991 index 44b628e..623ee2a 100644
992 --- a/arch/arm/mm/mmap.c
993 +++ b/arch/arm/mm/mmap.c
994 @@ -54,6 +54,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
995 if (len > TASK_SIZE)
996 return -ENOMEM;
997
998 +#ifdef CONFIG_PAX_RANDMMAP
999 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1000 +#endif
1001 +
1002 if (addr) {
1003 if (do_align)
1004 addr = COLOUR_ALIGN(addr, pgoff);
1005 @@ -61,15 +65,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1006 addr = PAGE_ALIGN(addr);
1007
1008 vma = find_vma(mm, addr);
1009 - if (TASK_SIZE - len >= addr &&
1010 - (!vma || addr + len <= vma->vm_start))
1011 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1012 return addr;
1013 }
1014 if (len > mm->cached_hole_size) {
1015 - start_addr = addr = mm->free_area_cache;
1016 + start_addr = addr = mm->free_area_cache;
1017 } else {
1018 - start_addr = addr = TASK_UNMAPPED_BASE;
1019 - mm->cached_hole_size = 0;
1020 + start_addr = addr = mm->mmap_base;
1021 + mm->cached_hole_size = 0;
1022 }
1023 /* 8 bits of randomness in 20 address space bits */
1024 if ((current->flags & PF_RANDOMIZE) &&
1025 @@ -89,14 +92,14 @@ full_search:
1026 * Start a new search - just in case we missed
1027 * some holes.
1028 */
1029 - if (start_addr != TASK_UNMAPPED_BASE) {
1030 - start_addr = addr = TASK_UNMAPPED_BASE;
1031 + if (start_addr != mm->mmap_base) {
1032 + start_addr = addr = mm->mmap_base;
1033 mm->cached_hole_size = 0;
1034 goto full_search;
1035 }
1036 return -ENOMEM;
1037 }
1038 - if (!vma || addr + len <= vma->vm_start) {
1039 + if (check_heap_stack_gap(vma, addr, len)) {
1040 /*
1041 * Remember the place where we stopped the search:
1042 */
1043 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1044 index 3b3159b..425ea94 100644
1045 --- a/arch/avr32/include/asm/elf.h
1046 +++ b/arch/avr32/include/asm/elf.h
1047 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1048 the loader. We need to make sure that it is out of the way of the program
1049 that it will "exec", and that there is sufficient room for the brk. */
1050
1051 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1052 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1053
1054 +#ifdef CONFIG_PAX_ASLR
1055 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1056 +
1057 +#define PAX_DELTA_MMAP_LEN 15
1058 +#define PAX_DELTA_STACK_LEN 15
1059 +#endif
1060
1061 /* This yields a mask that user programs can use to figure out what
1062 instruction set this CPU supports. This could be done in user space,
1063 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1064 index b7f5c68..556135c 100644
1065 --- a/arch/avr32/include/asm/kmap_types.h
1066 +++ b/arch/avr32/include/asm/kmap_types.h
1067 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1068 D(11) KM_IRQ1,
1069 D(12) KM_SOFTIRQ0,
1070 D(13) KM_SOFTIRQ1,
1071 -D(14) KM_TYPE_NR
1072 +D(14) KM_CLEARPAGE,
1073 +D(15) KM_TYPE_NR
1074 };
1075
1076 #undef D
1077 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1078 index f7040a1..db9f300 100644
1079 --- a/arch/avr32/mm/fault.c
1080 +++ b/arch/avr32/mm/fault.c
1081 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1082
1083 int exception_trace = 1;
1084
1085 +#ifdef CONFIG_PAX_PAGEEXEC
1086 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1087 +{
1088 + unsigned long i;
1089 +
1090 + printk(KERN_ERR "PAX: bytes at PC: ");
1091 + for (i = 0; i < 20; i++) {
1092 + unsigned char c;
1093 + if (get_user(c, (unsigned char *)pc+i))
1094 + printk(KERN_CONT "???????? ");
1095 + else
1096 + printk(KERN_CONT "%02x ", c);
1097 + }
1098 + printk("\n");
1099 +}
1100 +#endif
1101 +
1102 /*
1103 * This routine handles page faults. It determines the address and the
1104 * problem, and then passes it off to one of the appropriate routines.
1105 @@ -156,6 +173,16 @@ bad_area:
1106 up_read(&mm->mmap_sem);
1107
1108 if (user_mode(regs)) {
1109 +
1110 +#ifdef CONFIG_PAX_PAGEEXEC
1111 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1112 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1113 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1114 + do_group_exit(SIGKILL);
1115 + }
1116 + }
1117 +#endif
1118 +
1119 if (exception_trace && printk_ratelimit())
1120 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1121 "sp %08lx ecr %lu\n",
1122 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
1123 index f8e16b2..c73ff79 100644
1124 --- a/arch/frv/include/asm/kmap_types.h
1125 +++ b/arch/frv/include/asm/kmap_types.h
1126 @@ -23,6 +23,7 @@ enum km_type {
1127 KM_IRQ1,
1128 KM_SOFTIRQ0,
1129 KM_SOFTIRQ1,
1130 + KM_CLEARPAGE,
1131 KM_TYPE_NR
1132 };
1133
1134 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
1135 index 385fd30..6c3d97e 100644
1136 --- a/arch/frv/mm/elf-fdpic.c
1137 +++ b/arch/frv/mm/elf-fdpic.c
1138 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1139 if (addr) {
1140 addr = PAGE_ALIGN(addr);
1141 vma = find_vma(current->mm, addr);
1142 - if (TASK_SIZE - len >= addr &&
1143 - (!vma || addr + len <= vma->vm_start))
1144 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1145 goto success;
1146 }
1147
1148 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1149 for (; vma; vma = vma->vm_next) {
1150 if (addr > limit)
1151 break;
1152 - if (addr + len <= vma->vm_start)
1153 + if (check_heap_stack_gap(vma, addr, len))
1154 goto success;
1155 addr = vma->vm_end;
1156 }
1157 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1158 for (; vma; vma = vma->vm_next) {
1159 if (addr > limit)
1160 break;
1161 - if (addr + len <= vma->vm_start)
1162 + if (check_heap_stack_gap(vma, addr, len))
1163 goto success;
1164 addr = vma->vm_end;
1165 }
1166 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
1167 index b5298eb..67c6e62 100644
1168 --- a/arch/ia64/include/asm/elf.h
1169 +++ b/arch/ia64/include/asm/elf.h
1170 @@ -42,6 +42,13 @@
1171 */
1172 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1173
1174 +#ifdef CONFIG_PAX_ASLR
1175 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1176 +
1177 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1178 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1179 +#endif
1180 +
1181 #define PT_IA_64_UNWIND 0x70000001
1182
1183 /* IA-64 relocations: */
1184 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
1185 index 1a97af3..7529d31 100644
1186 --- a/arch/ia64/include/asm/pgtable.h
1187 +++ b/arch/ia64/include/asm/pgtable.h
1188 @@ -12,7 +12,7 @@
1189 * David Mosberger-Tang <davidm@hpl.hp.com>
1190 */
1191
1192 -
1193 +#include <linux/const.h>
1194 #include <asm/mman.h>
1195 #include <asm/page.h>
1196 #include <asm/processor.h>
1197 @@ -143,6 +143,17 @@
1198 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1199 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1200 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1201 +
1202 +#ifdef CONFIG_PAX_PAGEEXEC
1203 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1204 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1205 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1206 +#else
1207 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1208 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1209 +# define PAGE_COPY_NOEXEC PAGE_COPY
1210 +#endif
1211 +
1212 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1213 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1214 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1215 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
1216 index b77768d..e0795eb 100644
1217 --- a/arch/ia64/include/asm/spinlock.h
1218 +++ b/arch/ia64/include/asm/spinlock.h
1219 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
1220 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1221
1222 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1223 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1224 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1225 }
1226
1227 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
1228 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
1229 index 449c8c0..432a3d2 100644
1230 --- a/arch/ia64/include/asm/uaccess.h
1231 +++ b/arch/ia64/include/asm/uaccess.h
1232 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1233 const void *__cu_from = (from); \
1234 long __cu_len = (n); \
1235 \
1236 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1237 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1238 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1239 __cu_len; \
1240 })
1241 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1242 long __cu_len = (n); \
1243 \
1244 __chk_user_ptr(__cu_from); \
1245 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
1246 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1247 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1248 __cu_len; \
1249 })
1250 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
1251 index 24603be..948052d 100644
1252 --- a/arch/ia64/kernel/module.c
1253 +++ b/arch/ia64/kernel/module.c
1254 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
1255 void
1256 module_free (struct module *mod, void *module_region)
1257 {
1258 - if (mod && mod->arch.init_unw_table &&
1259 - module_region == mod->module_init) {
1260 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1261 unw_remove_unwind_table(mod->arch.init_unw_table);
1262 mod->arch.init_unw_table = NULL;
1263 }
1264 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
1265 }
1266
1267 static inline int
1268 +in_init_rx (const struct module *mod, uint64_t addr)
1269 +{
1270 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1271 +}
1272 +
1273 +static inline int
1274 +in_init_rw (const struct module *mod, uint64_t addr)
1275 +{
1276 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1277 +}
1278 +
1279 +static inline int
1280 in_init (const struct module *mod, uint64_t addr)
1281 {
1282 - return addr - (uint64_t) mod->module_init < mod->init_size;
1283 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1284 +}
1285 +
1286 +static inline int
1287 +in_core_rx (const struct module *mod, uint64_t addr)
1288 +{
1289 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1290 +}
1291 +
1292 +static inline int
1293 +in_core_rw (const struct module *mod, uint64_t addr)
1294 +{
1295 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1296 }
1297
1298 static inline int
1299 in_core (const struct module *mod, uint64_t addr)
1300 {
1301 - return addr - (uint64_t) mod->module_core < mod->core_size;
1302 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1303 }
1304
1305 static inline int
1306 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
1307 break;
1308
1309 case RV_BDREL:
1310 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1311 + if (in_init_rx(mod, val))
1312 + val -= (uint64_t) mod->module_init_rx;
1313 + else if (in_init_rw(mod, val))
1314 + val -= (uint64_t) mod->module_init_rw;
1315 + else if (in_core_rx(mod, val))
1316 + val -= (uint64_t) mod->module_core_rx;
1317 + else if (in_core_rw(mod, val))
1318 + val -= (uint64_t) mod->module_core_rw;
1319 break;
1320
1321 case RV_LTV:
1322 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
1323 * addresses have been selected...
1324 */
1325 uint64_t gp;
1326 - if (mod->core_size > MAX_LTOFF)
1327 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1328 /*
1329 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1330 * at the end of the module.
1331 */
1332 - gp = mod->core_size - MAX_LTOFF / 2;
1333 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1334 else
1335 - gp = mod->core_size / 2;
1336 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1337 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1338 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1339 mod->arch.gp = gp;
1340 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1341 }
1342 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
1343 index 609d500..7dde2a8 100644
1344 --- a/arch/ia64/kernel/sys_ia64.c
1345 +++ b/arch/ia64/kernel/sys_ia64.c
1346 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1347 if (REGION_NUMBER(addr) == RGN_HPAGE)
1348 addr = 0;
1349 #endif
1350 +
1351 +#ifdef CONFIG_PAX_RANDMMAP
1352 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1353 + addr = mm->free_area_cache;
1354 + else
1355 +#endif
1356 +
1357 if (!addr)
1358 addr = mm->free_area_cache;
1359
1360 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1361 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1362 /* At this point: (!vma || addr < vma->vm_end). */
1363 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1364 - if (start_addr != TASK_UNMAPPED_BASE) {
1365 + if (start_addr != mm->mmap_base) {
1366 /* Start a new search --- just in case we missed some holes. */
1367 - addr = TASK_UNMAPPED_BASE;
1368 + addr = mm->mmap_base;
1369 goto full_search;
1370 }
1371 return -ENOMEM;
1372 }
1373 - if (!vma || addr + len <= vma->vm_start) {
1374 + if (check_heap_stack_gap(vma, addr, len)) {
1375 /* Remember the address where we stopped this search: */
1376 mm->free_area_cache = addr + len;
1377 return addr;
1378 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
1379 index 53c0ba0..2accdde 100644
1380 --- a/arch/ia64/kernel/vmlinux.lds.S
1381 +++ b/arch/ia64/kernel/vmlinux.lds.S
1382 @@ -199,7 +199,7 @@ SECTIONS {
1383 /* Per-cpu data: */
1384 . = ALIGN(PERCPU_PAGE_SIZE);
1385 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
1386 - __phys_per_cpu_start = __per_cpu_load;
1387 + __phys_per_cpu_start = per_cpu_load;
1388 /*
1389 * ensure percpu data fits
1390 * into percpu page size
1391 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
1392 index 20b3593..1ce77f0 100644
1393 --- a/arch/ia64/mm/fault.c
1394 +++ b/arch/ia64/mm/fault.c
1395 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
1396 return pte_present(pte);
1397 }
1398
1399 +#ifdef CONFIG_PAX_PAGEEXEC
1400 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1401 +{
1402 + unsigned long i;
1403 +
1404 + printk(KERN_ERR "PAX: bytes at PC: ");
1405 + for (i = 0; i < 8; i++) {
1406 + unsigned int c;
1407 + if (get_user(c, (unsigned int *)pc+i))
1408 + printk(KERN_CONT "???????? ");
1409 + else
1410 + printk(KERN_CONT "%08x ", c);
1411 + }
1412 + printk("\n");
1413 +}
1414 +#endif
1415 +
1416 void __kprobes
1417 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1418 {
1419 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
1420 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1421 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1422
1423 - if ((vma->vm_flags & mask) != mask)
1424 + if ((vma->vm_flags & mask) != mask) {
1425 +
1426 +#ifdef CONFIG_PAX_PAGEEXEC
1427 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1428 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1429 + goto bad_area;
1430 +
1431 + up_read(&mm->mmap_sem);
1432 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1433 + do_group_exit(SIGKILL);
1434 + }
1435 +#endif
1436 +
1437 goto bad_area;
1438
1439 + }
1440 +
1441 /*
1442 * If for any reason at all we couldn't handle the fault, make
1443 * sure we exit gracefully rather than endlessly redo the
1444 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
1445 index 5ca674b..e0e1b70 100644
1446 --- a/arch/ia64/mm/hugetlbpage.c
1447 +++ b/arch/ia64/mm/hugetlbpage.c
1448 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
1449 /* At this point: (!vmm || addr < vmm->vm_end). */
1450 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1451 return -ENOMEM;
1452 - if (!vmm || (addr + len) <= vmm->vm_start)
1453 + if (check_heap_stack_gap(vmm, addr, len))
1454 return addr;
1455 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1456 }
1457 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
1458 index 00cb0e2..2ad8024 100644
1459 --- a/arch/ia64/mm/init.c
1460 +++ b/arch/ia64/mm/init.c
1461 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
1462 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1463 vma->vm_end = vma->vm_start + PAGE_SIZE;
1464 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1465 +
1466 +#ifdef CONFIG_PAX_PAGEEXEC
1467 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1468 + vma->vm_flags &= ~VM_EXEC;
1469 +
1470 +#ifdef CONFIG_PAX_MPROTECT
1471 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1472 + vma->vm_flags &= ~VM_MAYEXEC;
1473 +#endif
1474 +
1475 + }
1476 +#endif
1477 +
1478 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1479 down_write(&current->mm->mmap_sem);
1480 if (insert_vm_struct(current->mm, vma)) {
1481 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
1482 index 82abd15..d95ae5d 100644
1483 --- a/arch/m32r/lib/usercopy.c
1484 +++ b/arch/m32r/lib/usercopy.c
1485 @@ -14,6 +14,9 @@
1486 unsigned long
1487 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1488 {
1489 + if ((long)n < 0)
1490 + return n;
1491 +
1492 prefetch(from);
1493 if (access_ok(VERIFY_WRITE, to, n))
1494 __copy_user(to,from,n);
1495 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1496 unsigned long
1497 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1498 {
1499 + if ((long)n < 0)
1500 + return n;
1501 +
1502 prefetchw(to);
1503 if (access_ok(VERIFY_READ, from, n))
1504 __copy_user_zeroing(to,from,n);
1505 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
1506 index 455c0ac..ad65fbe 100644
1507 --- a/arch/mips/include/asm/elf.h
1508 +++ b/arch/mips/include/asm/elf.h
1509 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
1510 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1511 #endif
1512
1513 +#ifdef CONFIG_PAX_ASLR
1514 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1515 +
1516 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1517 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1518 +#endif
1519 +
1520 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1521 struct linux_binprm;
1522 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
1523 int uses_interp);
1524
1525 -struct mm_struct;
1526 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1527 -#define arch_randomize_brk arch_randomize_brk
1528 -
1529 #endif /* _ASM_ELF_H */
1530 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
1531 index e59cd1a..8e329d6 100644
1532 --- a/arch/mips/include/asm/page.h
1533 +++ b/arch/mips/include/asm/page.h
1534 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
1535 #ifdef CONFIG_CPU_MIPS32
1536 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1537 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1538 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1539 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1540 #else
1541 typedef struct { unsigned long long pte; } pte_t;
1542 #define pte_val(x) ((x).pte)
1543 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
1544 index 6018c80..7c37203 100644
1545 --- a/arch/mips/include/asm/system.h
1546 +++ b/arch/mips/include/asm/system.h
1547 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1548 */
1549 #define __ARCH_WANT_UNLOCKED_CTXSW
1550
1551 -extern unsigned long arch_align_stack(unsigned long sp);
1552 +#define arch_align_stack(x) ((x) & ~0xfUL)
1553
1554 #endif /* _ASM_SYSTEM_H */
1555 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
1556 index 9fdd8bc..4bd7f1a 100644
1557 --- a/arch/mips/kernel/binfmt_elfn32.c
1558 +++ b/arch/mips/kernel/binfmt_elfn32.c
1559 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1560 #undef ELF_ET_DYN_BASE
1561 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1562
1563 +#ifdef CONFIG_PAX_ASLR
1564 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1565 +
1566 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1567 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1568 +#endif
1569 +
1570 #include <asm/processor.h>
1571 #include <linux/module.h>
1572 #include <linux/elfcore.h>
1573 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
1574 index ff44823..97f8906 100644
1575 --- a/arch/mips/kernel/binfmt_elfo32.c
1576 +++ b/arch/mips/kernel/binfmt_elfo32.c
1577 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1578 #undef ELF_ET_DYN_BASE
1579 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1580
1581 +#ifdef CONFIG_PAX_ASLR
1582 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1583 +
1584 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1585 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1586 +#endif
1587 +
1588 #include <asm/processor.h>
1589
1590 /*
1591 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
1592 index c47f96e..661d418 100644
1593 --- a/arch/mips/kernel/process.c
1594 +++ b/arch/mips/kernel/process.c
1595 @@ -481,15 +481,3 @@ unsigned long get_wchan(struct task_struct *task)
1596 out:
1597 return pc;
1598 }
1599 -
1600 -/*
1601 - * Don't forget that the stack pointer must be aligned on a 8 bytes
1602 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
1603 - */
1604 -unsigned long arch_align_stack(unsigned long sp)
1605 -{
1606 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1607 - sp -= get_random_int() & ~PAGE_MASK;
1608 -
1609 - return sp & ALMASK;
1610 -}
1611 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
1612 index 937cf33..adb39bb 100644
1613 --- a/arch/mips/mm/fault.c
1614 +++ b/arch/mips/mm/fault.c
1615 @@ -28,6 +28,23 @@
1616 #include <asm/highmem.h> /* For VMALLOC_END */
1617 #include <linux/kdebug.h>
1618
1619 +#ifdef CONFIG_PAX_PAGEEXEC
1620 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1621 +{
1622 + unsigned long i;
1623 +
1624 + printk(KERN_ERR "PAX: bytes at PC: ");
1625 + for (i = 0; i < 5; i++) {
1626 + unsigned int c;
1627 + if (get_user(c, (unsigned int *)pc+i))
1628 + printk(KERN_CONT "???????? ");
1629 + else
1630 + printk(KERN_CONT "%08x ", c);
1631 + }
1632 + printk("\n");
1633 +}
1634 +#endif
1635 +
1636 /*
1637 * This routine handles page faults. It determines the address,
1638 * and the problem, and then passes it off to one of the appropriate
1639 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
1640 index 302d779..7d35bf8 100644
1641 --- a/arch/mips/mm/mmap.c
1642 +++ b/arch/mips/mm/mmap.c
1643 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1644 do_color_align = 1;
1645
1646 /* requesting a specific address */
1647 +
1648 +#ifdef CONFIG_PAX_RANDMMAP
1649 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1650 +#endif
1651 +
1652 if (addr) {
1653 if (do_color_align)
1654 addr = COLOUR_ALIGN(addr, pgoff);
1655 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1656 addr = PAGE_ALIGN(addr);
1657
1658 vma = find_vma(mm, addr);
1659 - if (TASK_SIZE - len >= addr &&
1660 - (!vma || addr + len <= vma->vm_start))
1661 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
1662 return addr;
1663 }
1664
1665 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1666 /* At this point: (!vma || addr < vma->vm_end). */
1667 if (TASK_SIZE - len < addr)
1668 return -ENOMEM;
1669 - if (!vma || addr + len <= vma->vm_start)
1670 + if (check_heap_stack_gap(vmm, addr, len))
1671 return addr;
1672 addr = vma->vm_end;
1673 if (do_color_align)
1674 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1675 /* make sure it can fit in the remaining address space */
1676 if (likely(addr > len)) {
1677 vma = find_vma(mm, addr - len);
1678 - if (!vma || addr <= vma->vm_start) {
1679 + if (check_heap_stack_gap(vmm, addr - len, len))
1680 /* cache the address as a hint for next time */
1681 return mm->free_area_cache = addr - len;
1682 }
1683 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1684 * return with success:
1685 */
1686 vma = find_vma(mm, addr);
1687 - if (likely(!vma || addr + len <= vma->vm_start)) {
1688 + if (check_heap_stack_gap(vmm, addr, len)) {
1689 /* cache the address as a hint for next time */
1690 return mm->free_area_cache = addr;
1691 }
1692 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1693 mm->unmap_area = arch_unmap_area_topdown;
1694 }
1695 }
1696 -
1697 -static inline unsigned long brk_rnd(void)
1698 -{
1699 - unsigned long rnd = get_random_int();
1700 -
1701 - rnd = rnd << PAGE_SHIFT;
1702 - /* 8MB for 32bit, 256MB for 64bit */
1703 - if (TASK_IS_32BIT_ADDR)
1704 - rnd = rnd & 0x7ffffful;
1705 - else
1706 - rnd = rnd & 0xffffffful;
1707 -
1708 - return rnd;
1709 -}
1710 -
1711 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1712 -{
1713 - unsigned long base = mm->brk;
1714 - unsigned long ret;
1715 -
1716 - ret = PAGE_ALIGN(base + brk_rnd());
1717 -
1718 - if (ret < mm->brk)
1719 - return mm->brk;
1720 -
1721 - return ret;
1722 -}
1723 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
1724 index 19f6cb1..6c78cf2 100644
1725 --- a/arch/parisc/include/asm/elf.h
1726 +++ b/arch/parisc/include/asm/elf.h
1727 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
1728
1729 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
1730
1731 +#ifdef CONFIG_PAX_ASLR
1732 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
1733 +
1734 +#define PAX_DELTA_MMAP_LEN 16
1735 +#define PAX_DELTA_STACK_LEN 16
1736 +#endif
1737 +
1738 /* This yields a mask that user programs can use to figure out what
1739 instruction set this CPU supports. This could be done in user space,
1740 but it's not easy, and we've already done it here. */
1741 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
1742 index 22dadeb..f6c2be4 100644
1743 --- a/arch/parisc/include/asm/pgtable.h
1744 +++ b/arch/parisc/include/asm/pgtable.h
1745 @@ -210,6 +210,17 @@ struct vm_area_struct;
1746 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
1747 #define PAGE_COPY PAGE_EXECREAD
1748 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
1749 +
1750 +#ifdef CONFIG_PAX_PAGEEXEC
1751 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
1752 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1753 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1754 +#else
1755 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1756 +# define PAGE_COPY_NOEXEC PAGE_COPY
1757 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1758 +#endif
1759 +
1760 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
1761 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
1762 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
1763 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
1764 index 5e34ccf..672bc9c 100644
1765 --- a/arch/parisc/kernel/module.c
1766 +++ b/arch/parisc/kernel/module.c
1767 @@ -98,16 +98,38 @@
1768
1769 /* three functions to determine where in the module core
1770 * or init pieces the location is */
1771 +static inline int in_init_rx(struct module *me, void *loc)
1772 +{
1773 + return (loc >= me->module_init_rx &&
1774 + loc < (me->module_init_rx + me->init_size_rx));
1775 +}
1776 +
1777 +static inline int in_init_rw(struct module *me, void *loc)
1778 +{
1779 + return (loc >= me->module_init_rw &&
1780 + loc < (me->module_init_rw + me->init_size_rw));
1781 +}
1782 +
1783 static inline int in_init(struct module *me, void *loc)
1784 {
1785 - return (loc >= me->module_init &&
1786 - loc <= (me->module_init + me->init_size));
1787 + return in_init_rx(me, loc) || in_init_rw(me, loc);
1788 +}
1789 +
1790 +static inline int in_core_rx(struct module *me, void *loc)
1791 +{
1792 + return (loc >= me->module_core_rx &&
1793 + loc < (me->module_core_rx + me->core_size_rx));
1794 +}
1795 +
1796 +static inline int in_core_rw(struct module *me, void *loc)
1797 +{
1798 + return (loc >= me->module_core_rw &&
1799 + loc < (me->module_core_rw + me->core_size_rw));
1800 }
1801
1802 static inline int in_core(struct module *me, void *loc)
1803 {
1804 - return (loc >= me->module_core &&
1805 - loc <= (me->module_core + me->core_size));
1806 + return in_core_rx(me, loc) || in_core_rw(me, loc);
1807 }
1808
1809 static inline int in_local(struct module *me, void *loc)
1810 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
1811 }
1812
1813 /* align things a bit */
1814 - me->core_size = ALIGN(me->core_size, 16);
1815 - me->arch.got_offset = me->core_size;
1816 - me->core_size += gots * sizeof(struct got_entry);
1817 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
1818 + me->arch.got_offset = me->core_size_rw;
1819 + me->core_size_rw += gots * sizeof(struct got_entry);
1820
1821 - me->core_size = ALIGN(me->core_size, 16);
1822 - me->arch.fdesc_offset = me->core_size;
1823 - me->core_size += fdescs * sizeof(Elf_Fdesc);
1824 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
1825 + me->arch.fdesc_offset = me->core_size_rw;
1826 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1827
1828 me->arch.got_max = gots;
1829 me->arch.fdesc_max = fdescs;
1830 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
1831
1832 BUG_ON(value == 0);
1833
1834 - got = me->module_core + me->arch.got_offset;
1835 + got = me->module_core_rw + me->arch.got_offset;
1836 for (i = 0; got[i].addr; i++)
1837 if (got[i].addr == value)
1838 goto out;
1839 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
1840 #ifdef CONFIG_64BIT
1841 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1842 {
1843 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1844 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1845
1846 if (!value) {
1847 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1848 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1849
1850 /* Create new one */
1851 fdesc->addr = value;
1852 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1853 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1854 return (Elf_Addr)fdesc;
1855 }
1856 #endif /* CONFIG_64BIT */
1857 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
1858
1859 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1860 end = table + sechdrs[me->arch.unwind_section].sh_size;
1861 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1862 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1863
1864 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1865 me->arch.unwind_section, table, end, gp);
1866 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
1867 index c9b9322..02d8940 100644
1868 --- a/arch/parisc/kernel/sys_parisc.c
1869 +++ b/arch/parisc/kernel/sys_parisc.c
1870 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
1871 /* At this point: (!vma || addr < vma->vm_end). */
1872 if (TASK_SIZE - len < addr)
1873 return -ENOMEM;
1874 - if (!vma || addr + len <= vma->vm_start)
1875 + if (check_heap_stack_gap(vma, addr, len))
1876 return addr;
1877 addr = vma->vm_end;
1878 }
1879 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
1880 /* At this point: (!vma || addr < vma->vm_end). */
1881 if (TASK_SIZE - len < addr)
1882 return -ENOMEM;
1883 - if (!vma || addr + len <= vma->vm_start)
1884 + if (check_heap_stack_gap(vma, addr, len))
1885 return addr;
1886 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
1887 if (addr < vma->vm_end) /* handle wraparound */
1888 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
1889 if (flags & MAP_FIXED)
1890 return addr;
1891 if (!addr)
1892 - addr = TASK_UNMAPPED_BASE;
1893 + addr = current->mm->mmap_base;
1894
1895 if (filp) {
1896 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1897 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
1898 index f19e660..414fe24 100644
1899 --- a/arch/parisc/kernel/traps.c
1900 +++ b/arch/parisc/kernel/traps.c
1901 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
1902
1903 down_read(&current->mm->mmap_sem);
1904 vma = find_vma(current->mm,regs->iaoq[0]);
1905 - if (vma && (regs->iaoq[0] >= vma->vm_start)
1906 - && (vma->vm_flags & VM_EXEC)) {
1907 -
1908 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
1909 fault_address = regs->iaoq[0];
1910 fault_space = regs->iasq[0];
1911
1912 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
1913 index 18162ce..94de376 100644
1914 --- a/arch/parisc/mm/fault.c
1915 +++ b/arch/parisc/mm/fault.c
1916 @@ -15,6 +15,7 @@
1917 #include <linux/sched.h>
1918 #include <linux/interrupt.h>
1919 #include <linux/module.h>
1920 +#include <linux/unistd.h>
1921
1922 #include <asm/uaccess.h>
1923 #include <asm/traps.h>
1924 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
1925 static unsigned long
1926 parisc_acctyp(unsigned long code, unsigned int inst)
1927 {
1928 - if (code == 6 || code == 16)
1929 + if (code == 6 || code == 7 || code == 16)
1930 return VM_EXEC;
1931
1932 switch (inst & 0xf0000000) {
1933 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
1934 }
1935 #endif
1936
1937 +#ifdef CONFIG_PAX_PAGEEXEC
1938 +/*
1939 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
1940 + *
1941 + * returns 1 when task should be killed
1942 + * 2 when rt_sigreturn trampoline was detected
1943 + * 3 when unpatched PLT trampoline was detected
1944 + */
1945 +static int pax_handle_fetch_fault(struct pt_regs *regs)
1946 +{
1947 +
1948 +#ifdef CONFIG_PAX_EMUPLT
1949 + int err;
1950 +
1951 + do { /* PaX: unpatched PLT emulation */
1952 + unsigned int bl, depwi;
1953 +
1954 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
1955 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
1956 +
1957 + if (err)
1958 + break;
1959 +
1960 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
1961 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
1962 +
1963 + err = get_user(ldw, (unsigned int *)addr);
1964 + err |= get_user(bv, (unsigned int *)(addr+4));
1965 + err |= get_user(ldw2, (unsigned int *)(addr+8));
1966 +
1967 + if (err)
1968 + break;
1969 +
1970 + if (ldw == 0x0E801096U &&
1971 + bv == 0xEAC0C000U &&
1972 + ldw2 == 0x0E881095U)
1973 + {
1974 + unsigned int resolver, map;
1975 +
1976 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
1977 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
1978 + if (err)
1979 + break;
1980 +
1981 + regs->gr[20] = instruction_pointer(regs)+8;
1982 + regs->gr[21] = map;
1983 + regs->gr[22] = resolver;
1984 + regs->iaoq[0] = resolver | 3UL;
1985 + regs->iaoq[1] = regs->iaoq[0] + 4;
1986 + return 3;
1987 + }
1988 + }
1989 + } while (0);
1990 +#endif
1991 +
1992 +#ifdef CONFIG_PAX_EMUTRAMP
1993 +
1994 +#ifndef CONFIG_PAX_EMUSIGRT
1995 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
1996 + return 1;
1997 +#endif
1998 +
1999 + do { /* PaX: rt_sigreturn emulation */
2000 + unsigned int ldi1, ldi2, bel, nop;
2001 +
2002 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
2003 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
2004 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
2005 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
2006 +
2007 + if (err)
2008 + break;
2009 +
2010 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2011 + ldi2 == 0x3414015AU &&
2012 + bel == 0xE4008200U &&
2013 + nop == 0x08000240U)
2014 + {
2015 + regs->gr[25] = (ldi1 & 2) >> 1;
2016 + regs->gr[20] = __NR_rt_sigreturn;
2017 + regs->gr[31] = regs->iaoq[1] + 16;
2018 + regs->sr[0] = regs->iasq[1];
2019 + regs->iaoq[0] = 0x100UL;
2020 + regs->iaoq[1] = regs->iaoq[0] + 4;
2021 + regs->iasq[0] = regs->sr[2];
2022 + regs->iasq[1] = regs->sr[2];
2023 + return 2;
2024 + }
2025 + } while (0);
2026 +#endif
2027 +
2028 + return 1;
2029 +}
2030 +
2031 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2032 +{
2033 + unsigned long i;
2034 +
2035 + printk(KERN_ERR "PAX: bytes at PC: ");
2036 + for (i = 0; i < 5; i++) {
2037 + unsigned int c;
2038 + if (get_user(c, (unsigned int *)pc+i))
2039 + printk(KERN_CONT "???????? ");
2040 + else
2041 + printk(KERN_CONT "%08x ", c);
2042 + }
2043 + printk("\n");
2044 +}
2045 +#endif
2046 +
2047 int fixup_exception(struct pt_regs *regs)
2048 {
2049 const struct exception_table_entry *fix;
2050 @@ -192,8 +303,33 @@ good_area:
2051
2052 acc_type = parisc_acctyp(code,regs->iir);
2053
2054 - if ((vma->vm_flags & acc_type) != acc_type)
2055 + if ((vma->vm_flags & acc_type) != acc_type) {
2056 +
2057 +#ifdef CONFIG_PAX_PAGEEXEC
2058 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2059 + (address & ~3UL) == instruction_pointer(regs))
2060 + {
2061 + up_read(&mm->mmap_sem);
2062 + switch (pax_handle_fetch_fault(regs)) {
2063 +
2064 +#ifdef CONFIG_PAX_EMUPLT
2065 + case 3:
2066 + return;
2067 +#endif
2068 +
2069 +#ifdef CONFIG_PAX_EMUTRAMP
2070 + case 2:
2071 + return;
2072 +#endif
2073 +
2074 + }
2075 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2076 + do_group_exit(SIGKILL);
2077 + }
2078 +#endif
2079 +
2080 goto bad_area;
2081 + }
2082
2083 /*
2084 * If for any reason at all we couldn't handle the fault, make
2085 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
2086 index 3bf9cca..e7457d0 100644
2087 --- a/arch/powerpc/include/asm/elf.h
2088 +++ b/arch/powerpc/include/asm/elf.h
2089 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
2090 the loader. We need to make sure that it is out of the way of the program
2091 that it will "exec", and that there is sufficient room for the brk. */
2092
2093 -extern unsigned long randomize_et_dyn(unsigned long base);
2094 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
2095 +#define ELF_ET_DYN_BASE (0x20000000)
2096 +
2097 +#ifdef CONFIG_PAX_ASLR
2098 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2099 +
2100 +#ifdef __powerpc64__
2101 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
2102 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
2103 +#else
2104 +#define PAX_DELTA_MMAP_LEN 15
2105 +#define PAX_DELTA_STACK_LEN 15
2106 +#endif
2107 +#endif
2108
2109 /*
2110 * Our registers are always unsigned longs, whether we're a 32 bit
2111 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2112 (0x7ff >> (PAGE_SHIFT - 12)) : \
2113 (0x3ffff >> (PAGE_SHIFT - 12)))
2114
2115 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2116 -#define arch_randomize_brk arch_randomize_brk
2117 -
2118 #endif /* __KERNEL__ */
2119
2120 /*
2121 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
2122 index bca8fdc..61e9580 100644
2123 --- a/arch/powerpc/include/asm/kmap_types.h
2124 +++ b/arch/powerpc/include/asm/kmap_types.h
2125 @@ -27,6 +27,7 @@ enum km_type {
2126 KM_PPC_SYNC_PAGE,
2127 KM_PPC_SYNC_ICACHE,
2128 KM_KDB,
2129 + KM_CLEARPAGE,
2130 KM_TYPE_NR
2131 };
2132
2133 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
2134 index d4a7f64..451de1c 100644
2135 --- a/arch/powerpc/include/asm/mman.h
2136 +++ b/arch/powerpc/include/asm/mman.h
2137 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
2138 }
2139 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
2140
2141 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
2142 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
2143 {
2144 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
2145 }
2146 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
2147 index dd9c4fd..a2ced87 100644
2148 --- a/arch/powerpc/include/asm/page.h
2149 +++ b/arch/powerpc/include/asm/page.h
2150 @@ -141,8 +141,9 @@ extern phys_addr_t kernstart_addr;
2151 * and needs to be executable. This means the whole heap ends
2152 * up being executable.
2153 */
2154 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2155 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2156 +#define VM_DATA_DEFAULT_FLAGS32 \
2157 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2158 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2159
2160 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2161 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2162 @@ -170,6 +171,9 @@ extern phys_addr_t kernstart_addr;
2163 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
2164 #endif
2165
2166 +#define ktla_ktva(addr) (addr)
2167 +#define ktva_ktla(addr) (addr)
2168 +
2169 /*
2170 * Use the top bit of the higher-level page table entries to indicate whether
2171 * the entries we point to contain hugepages. This works because we know that
2172 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
2173 index fb40ede..d3ce956 100644
2174 --- a/arch/powerpc/include/asm/page_64.h
2175 +++ b/arch/powerpc/include/asm/page_64.h
2176 @@ -144,15 +144,18 @@ do { \
2177 * stack by default, so in the absence of a PT_GNU_STACK program header
2178 * we turn execute permission off.
2179 */
2180 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2181 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2182 +#define VM_STACK_DEFAULT_FLAGS32 \
2183 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2184 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2185
2186 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2187 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2188
2189 +#ifndef CONFIG_PAX_PAGEEXEC
2190 #define VM_STACK_DEFAULT_FLAGS \
2191 (is_32bit_task() ? \
2192 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2193 +#endif
2194
2195 #include <asm-generic/getorder.h>
2196
2197 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
2198 index 88b0bd9..e32bc67 100644
2199 --- a/arch/powerpc/include/asm/pgtable.h
2200 +++ b/arch/powerpc/include/asm/pgtable.h
2201 @@ -2,6 +2,7 @@
2202 #define _ASM_POWERPC_PGTABLE_H
2203 #ifdef __KERNEL__
2204
2205 +#include <linux/const.h>
2206 #ifndef __ASSEMBLY__
2207 #include <asm/processor.h> /* For TASK_SIZE */
2208 #include <asm/mmu.h>
2209 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
2210 index 4aad413..85d86bf 100644
2211 --- a/arch/powerpc/include/asm/pte-hash32.h
2212 +++ b/arch/powerpc/include/asm/pte-hash32.h
2213 @@ -21,6 +21,7 @@
2214 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2215 #define _PAGE_USER 0x004 /* usermode access allowed */
2216 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2217 +#define _PAGE_EXEC _PAGE_GUARDED
2218 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2219 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2220 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2221 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
2222 index 559da19..7e5835c 100644
2223 --- a/arch/powerpc/include/asm/reg.h
2224 +++ b/arch/powerpc/include/asm/reg.h
2225 @@ -212,6 +212,7 @@
2226 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2227 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2228 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2229 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2230 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2231 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2232 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2233 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
2234 index e30a13d..2b7d994 100644
2235 --- a/arch/powerpc/include/asm/system.h
2236 +++ b/arch/powerpc/include/asm/system.h
2237 @@ -530,7 +530,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
2238 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2239 #endif
2240
2241 -extern unsigned long arch_align_stack(unsigned long sp);
2242 +#define arch_align_stack(x) ((x) & ~0xfUL)
2243
2244 /* Used in very early kernel initialization. */
2245 extern unsigned long reloc_offset(void);
2246 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
2247 index bd0fb84..a42a14b 100644
2248 --- a/arch/powerpc/include/asm/uaccess.h
2249 +++ b/arch/powerpc/include/asm/uaccess.h
2250 @@ -13,6 +13,8 @@
2251 #define VERIFY_READ 0
2252 #define VERIFY_WRITE 1
2253
2254 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
2255 +
2256 /*
2257 * The fs value determines whether argument validity checking should be
2258 * performed or not. If get_fs() == USER_DS, checking is performed, with
2259 @@ -327,52 +329,6 @@ do { \
2260 extern unsigned long __copy_tofrom_user(void __user *to,
2261 const void __user *from, unsigned long size);
2262
2263 -#ifndef __powerpc64__
2264 -
2265 -static inline unsigned long copy_from_user(void *to,
2266 - const void __user *from, unsigned long n)
2267 -{
2268 - unsigned long over;
2269 -
2270 - if (access_ok(VERIFY_READ, from, n))
2271 - return __copy_tofrom_user((__force void __user *)to, from, n);
2272 - if ((unsigned long)from < TASK_SIZE) {
2273 - over = (unsigned long)from + n - TASK_SIZE;
2274 - return __copy_tofrom_user((__force void __user *)to, from,
2275 - n - over) + over;
2276 - }
2277 - return n;
2278 -}
2279 -
2280 -static inline unsigned long copy_to_user(void __user *to,
2281 - const void *from, unsigned long n)
2282 -{
2283 - unsigned long over;
2284 -
2285 - if (access_ok(VERIFY_WRITE, to, n))
2286 - return __copy_tofrom_user(to, (__force void __user *)from, n);
2287 - if ((unsigned long)to < TASK_SIZE) {
2288 - over = (unsigned long)to + n - TASK_SIZE;
2289 - return __copy_tofrom_user(to, (__force void __user *)from,
2290 - n - over) + over;
2291 - }
2292 - return n;
2293 -}
2294 -
2295 -#else /* __powerpc64__ */
2296 -
2297 -#define __copy_in_user(to, from, size) \
2298 - __copy_tofrom_user((to), (from), (size))
2299 -
2300 -extern unsigned long copy_from_user(void *to, const void __user *from,
2301 - unsigned long n);
2302 -extern unsigned long copy_to_user(void __user *to, const void *from,
2303 - unsigned long n);
2304 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
2305 - unsigned long n);
2306 -
2307 -#endif /* __powerpc64__ */
2308 -
2309 static inline unsigned long __copy_from_user_inatomic(void *to,
2310 const void __user *from, unsigned long n)
2311 {
2312 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
2313 if (ret == 0)
2314 return 0;
2315 }
2316 +
2317 + if (!__builtin_constant_p(n))
2318 + check_object_size(to, n, false);
2319 +
2320 return __copy_tofrom_user((__force void __user *)to, from, n);
2321 }
2322
2323 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
2324 if (ret == 0)
2325 return 0;
2326 }
2327 +
2328 + if (!__builtin_constant_p(n))
2329 + check_object_size(from, n, true);
2330 +
2331 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2332 }
2333
2334 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
2335 return __copy_to_user_inatomic(to, from, size);
2336 }
2337
2338 +#ifndef __powerpc64__
2339 +
2340 +static inline unsigned long __must_check copy_from_user(void *to,
2341 + const void __user *from, unsigned long n)
2342 +{
2343 + unsigned long over;
2344 +
2345 + if ((long)n < 0)
2346 + return n;
2347 +
2348 + if (access_ok(VERIFY_READ, from, n)) {
2349 + if (!__builtin_constant_p(n))
2350 + check_object_size(to, n, false);
2351 + return __copy_tofrom_user((__force void __user *)to, from, n);
2352 + }
2353 + if ((unsigned long)from < TASK_SIZE) {
2354 + over = (unsigned long)from + n - TASK_SIZE;
2355 + if (!__builtin_constant_p(n - over))
2356 + check_object_size(to, n - over, false);
2357 + return __copy_tofrom_user((__force void __user *)to, from,
2358 + n - over) + over;
2359 + }
2360 + return n;
2361 +}
2362 +
2363 +static inline unsigned long __must_check copy_to_user(void __user *to,
2364 + const void *from, unsigned long n)
2365 +{
2366 + unsigned long over;
2367 +
2368 + if ((long)n < 0)
2369 + return n;
2370 +
2371 + if (access_ok(VERIFY_WRITE, to, n)) {
2372 + if (!__builtin_constant_p(n))
2373 + check_object_size(from, n, true);
2374 + return __copy_tofrom_user(to, (__force void __user *)from, n);
2375 + }
2376 + if ((unsigned long)to < TASK_SIZE) {
2377 + over = (unsigned long)to + n - TASK_SIZE;
2378 + if (!__builtin_constant_p(n))
2379 + check_object_size(from, n - over, true);
2380 + return __copy_tofrom_user(to, (__force void __user *)from,
2381 + n - over) + over;
2382 + }
2383 + return n;
2384 +}
2385 +
2386 +#else /* __powerpc64__ */
2387 +
2388 +#define __copy_in_user(to, from, size) \
2389 + __copy_tofrom_user((to), (from), (size))
2390 +
2391 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2392 +{
2393 + if ((long)n < 0 || n > INT_MAX)
2394 + return n;
2395 +
2396 + if (!__builtin_constant_p(n))
2397 + check_object_size(to, n, false);
2398 +
2399 + if (likely(access_ok(VERIFY_READ, from, n)))
2400 + n = __copy_from_user(to, from, n);
2401 + else
2402 + memset(to, 0, n);
2403 + return n;
2404 +}
2405 +
2406 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2407 +{
2408 + if ((long)n < 0 || n > INT_MAX)
2409 + return n;
2410 +
2411 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
2412 + if (!__builtin_constant_p(n))
2413 + check_object_size(from, n, true);
2414 + n = __copy_to_user(to, from, n);
2415 + }
2416 + return n;
2417 +}
2418 +
2419 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
2420 + unsigned long n);
2421 +
2422 +#endif /* __powerpc64__ */
2423 +
2424 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2425
2426 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2427 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
2428 index 429983c..7af363b 100644
2429 --- a/arch/powerpc/kernel/exceptions-64e.S
2430 +++ b/arch/powerpc/kernel/exceptions-64e.S
2431 @@ -587,6 +587,7 @@ storage_fault_common:
2432 std r14,_DAR(r1)
2433 std r15,_DSISR(r1)
2434 addi r3,r1,STACK_FRAME_OVERHEAD
2435 + bl .save_nvgprs
2436 mr r4,r14
2437 mr r5,r15
2438 ld r14,PACA_EXGEN+EX_R14(r13)
2439 @@ -596,8 +597,7 @@ storage_fault_common:
2440 cmpdi r3,0
2441 bne- 1f
2442 b .ret_from_except_lite
2443 -1: bl .save_nvgprs
2444 - mr r5,r3
2445 +1: mr r5,r3
2446 addi r3,r1,STACK_FRAME_OVERHEAD
2447 ld r4,_DAR(r1)
2448 bl .bad_page_fault
2449 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
2450 index cf9c69b..ebc9640 100644
2451 --- a/arch/powerpc/kernel/exceptions-64s.S
2452 +++ b/arch/powerpc/kernel/exceptions-64s.S
2453 @@ -1004,10 +1004,10 @@ handle_page_fault:
2454 11: ld r4,_DAR(r1)
2455 ld r5,_DSISR(r1)
2456 addi r3,r1,STACK_FRAME_OVERHEAD
2457 + bl .save_nvgprs
2458 bl .do_page_fault
2459 cmpdi r3,0
2460 beq+ 13f
2461 - bl .save_nvgprs
2462 mr r5,r3
2463 addi r3,r1,STACK_FRAME_OVERHEAD
2464 lwz r4,_DAR(r1)
2465 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
2466 index 0b6d796..d760ddb 100644
2467 --- a/arch/powerpc/kernel/module_32.c
2468 +++ b/arch/powerpc/kernel/module_32.c
2469 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
2470 me->arch.core_plt_section = i;
2471 }
2472 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
2473 - printk("Module doesn't contain .plt or .init.plt sections.\n");
2474 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
2475 return -ENOEXEC;
2476 }
2477
2478 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
2479
2480 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
2481 /* Init, or core PLT? */
2482 - if (location >= mod->module_core
2483 - && location < mod->module_core + mod->core_size)
2484 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
2485 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
2486 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
2487 - else
2488 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
2489 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
2490 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
2491 + else {
2492 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
2493 + return ~0UL;
2494 + }
2495
2496 /* Find this entry, or if that fails, the next avail. entry */
2497 while (entry->jump[0]) {
2498 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
2499 index 6457574..08b28d3 100644
2500 --- a/arch/powerpc/kernel/process.c
2501 +++ b/arch/powerpc/kernel/process.c
2502 @@ -660,8 +660,8 @@ void show_regs(struct pt_regs * regs)
2503 * Lookup NIP late so we have the best change of getting the
2504 * above info out without failing
2505 */
2506 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
2507 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
2508 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
2509 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
2510 #endif
2511 show_stack(current, (unsigned long *) regs->gpr[1]);
2512 if (!user_mode(regs))
2513 @@ -1165,10 +1165,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
2514 newsp = stack[0];
2515 ip = stack[STACK_FRAME_LR_SAVE];
2516 if (!firstframe || ip != lr) {
2517 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
2518 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
2519 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
2520 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
2521 - printk(" (%pS)",
2522 + printk(" (%pA)",
2523 (void *)current->ret_stack[curr_frame].ret);
2524 curr_frame--;
2525 }
2526 @@ -1188,7 +1188,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
2527 struct pt_regs *regs = (struct pt_regs *)
2528 (sp + STACK_FRAME_OVERHEAD);
2529 lr = regs->link;
2530 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
2531 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
2532 regs->trap, (void *)regs->nip, (void *)lr);
2533 firstframe = 1;
2534 }
2535 @@ -1263,58 +1263,3 @@ void thread_info_cache_init(void)
2536 }
2537
2538 #endif /* THREAD_SHIFT < PAGE_SHIFT */
2539 -
2540 -unsigned long arch_align_stack(unsigned long sp)
2541 -{
2542 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2543 - sp -= get_random_int() & ~PAGE_MASK;
2544 - return sp & ~0xf;
2545 -}
2546 -
2547 -static inline unsigned long brk_rnd(void)
2548 -{
2549 - unsigned long rnd = 0;
2550 -
2551 - /* 8MB for 32bit, 1GB for 64bit */
2552 - if (is_32bit_task())
2553 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
2554 - else
2555 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
2556 -
2557 - return rnd << PAGE_SHIFT;
2558 -}
2559 -
2560 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2561 -{
2562 - unsigned long base = mm->brk;
2563 - unsigned long ret;
2564 -
2565 -#ifdef CONFIG_PPC_STD_MMU_64
2566 - /*
2567 - * If we are using 1TB segments and we are allowed to randomise
2568 - * the heap, we can put it above 1TB so it is backed by a 1TB
2569 - * segment. Otherwise the heap will be in the bottom 1TB
2570 - * which always uses 256MB segments and this may result in a
2571 - * performance penalty.
2572 - */
2573 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
2574 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
2575 -#endif
2576 -
2577 - ret = PAGE_ALIGN(base + brk_rnd());
2578 -
2579 - if (ret < mm->brk)
2580 - return mm->brk;
2581 -
2582 - return ret;
2583 -}
2584 -
2585 -unsigned long randomize_et_dyn(unsigned long base)
2586 -{
2587 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2588 -
2589 - if (ret < base)
2590 - return base;
2591 -
2592 - return ret;
2593 -}
2594 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
2595 index 836a5a1..27289a3 100644
2596 --- a/arch/powerpc/kernel/signal_32.c
2597 +++ b/arch/powerpc/kernel/signal_32.c
2598 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
2599 /* Save user registers on the stack */
2600 frame = &rt_sf->uc.uc_mcontext;
2601 addr = frame;
2602 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
2603 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2604 if (save_user_regs(regs, frame, 0, 1))
2605 goto badframe;
2606 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
2607 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
2608 index a50b5ec..547078a 100644
2609 --- a/arch/powerpc/kernel/signal_64.c
2610 +++ b/arch/powerpc/kernel/signal_64.c
2611 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
2612 current->thread.fpscr.val = 0;
2613
2614 /* Set up to return from userspace. */
2615 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
2616 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2617 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
2618 } else {
2619 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
2620 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
2621 index 5459d14..10f8070 100644
2622 --- a/arch/powerpc/kernel/traps.c
2623 +++ b/arch/powerpc/kernel/traps.c
2624 @@ -98,6 +98,8 @@ static void pmac_backlight_unblank(void)
2625 static inline void pmac_backlight_unblank(void) { }
2626 #endif
2627
2628 +extern void gr_handle_kernel_exploit(void);
2629 +
2630 int die(const char *str, struct pt_regs *regs, long err)
2631 {
2632 static struct {
2633 @@ -171,6 +173,8 @@ int die(const char *str, struct pt_regs *regs, long err)
2634 if (panic_on_oops)
2635 panic("Fatal exception");
2636
2637 + gr_handle_kernel_exploit();
2638 +
2639 oops_exit();
2640 do_exit(err);
2641
2642 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
2643 index 7d14bb6..1305601 100644
2644 --- a/arch/powerpc/kernel/vdso.c
2645 +++ b/arch/powerpc/kernel/vdso.c
2646 @@ -35,6 +35,7 @@
2647 #include <asm/firmware.h>
2648 #include <asm/vdso.h>
2649 #include <asm/vdso_datapage.h>
2650 +#include <asm/mman.h>
2651
2652 #include "setup.h"
2653
2654 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2655 vdso_base = VDSO32_MBASE;
2656 #endif
2657
2658 - current->mm->context.vdso_base = 0;
2659 + current->mm->context.vdso_base = ~0UL;
2660
2661 /* vDSO has a problem and was disabled, just don't "enable" it for the
2662 * process
2663 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2664 vdso_base = get_unmapped_area(NULL, vdso_base,
2665 (vdso_pages << PAGE_SHIFT) +
2666 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
2667 - 0, 0);
2668 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
2669 if (IS_ERR_VALUE(vdso_base)) {
2670 rc = vdso_base;
2671 goto fail_mmapsem;
2672 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
2673 index 5eea6f3..5d10396 100644
2674 --- a/arch/powerpc/lib/usercopy_64.c
2675 +++ b/arch/powerpc/lib/usercopy_64.c
2676 @@ -9,22 +9,6 @@
2677 #include <linux/module.h>
2678 #include <asm/uaccess.h>
2679
2680 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
2681 -{
2682 - if (likely(access_ok(VERIFY_READ, from, n)))
2683 - n = __copy_from_user(to, from, n);
2684 - else
2685 - memset(to, 0, n);
2686 - return n;
2687 -}
2688 -
2689 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
2690 -{
2691 - if (likely(access_ok(VERIFY_WRITE, to, n)))
2692 - n = __copy_to_user(to, from, n);
2693 - return n;
2694 -}
2695 -
2696 unsigned long copy_in_user(void __user *to, const void __user *from,
2697 unsigned long n)
2698 {
2699 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
2700 return n;
2701 }
2702
2703 -EXPORT_SYMBOL(copy_from_user);
2704 -EXPORT_SYMBOL(copy_to_user);
2705 EXPORT_SYMBOL(copy_in_user);
2706
2707 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
2708 index 5efe8c9..db9ceef 100644
2709 --- a/arch/powerpc/mm/fault.c
2710 +++ b/arch/powerpc/mm/fault.c
2711 @@ -32,6 +32,10 @@
2712 #include <linux/perf_event.h>
2713 #include <linux/magic.h>
2714 #include <linux/ratelimit.h>
2715 +#include <linux/slab.h>
2716 +#include <linux/pagemap.h>
2717 +#include <linux/compiler.h>
2718 +#include <linux/unistd.h>
2719
2720 #include <asm/firmware.h>
2721 #include <asm/page.h>
2722 @@ -43,6 +47,7 @@
2723 #include <asm/tlbflush.h>
2724 #include <asm/siginfo.h>
2725 #include <mm/mmu_decl.h>
2726 +#include <asm/ptrace.h>
2727
2728 #ifdef CONFIG_KPROBES
2729 static inline int notify_page_fault(struct pt_regs *regs)
2730 @@ -66,6 +71,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
2731 }
2732 #endif
2733
2734 +#ifdef CONFIG_PAX_PAGEEXEC
2735 +/*
2736 + * PaX: decide what to do with offenders (regs->nip = fault address)
2737 + *
2738 + * returns 1 when task should be killed
2739 + */
2740 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2741 +{
2742 + return 1;
2743 +}
2744 +
2745 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2746 +{
2747 + unsigned long i;
2748 +
2749 + printk(KERN_ERR "PAX: bytes at PC: ");
2750 + for (i = 0; i < 5; i++) {
2751 + unsigned int c;
2752 + if (get_user(c, (unsigned int __user *)pc+i))
2753 + printk(KERN_CONT "???????? ");
2754 + else
2755 + printk(KERN_CONT "%08x ", c);
2756 + }
2757 + printk("\n");
2758 +}
2759 +#endif
2760 +
2761 /*
2762 * Check whether the instruction at regs->nip is a store using
2763 * an update addressing form which will update r1.
2764 @@ -136,7 +168,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
2765 * indicate errors in DSISR but can validly be set in SRR1.
2766 */
2767 if (trap == 0x400)
2768 - error_code &= 0x48200000;
2769 + error_code &= 0x58200000;
2770 else
2771 is_write = error_code & DSISR_ISSTORE;
2772 #else
2773 @@ -259,7 +291,7 @@ good_area:
2774 * "undefined". Of those that can be set, this is the only
2775 * one which seems bad.
2776 */
2777 - if (error_code & 0x10000000)
2778 + if (error_code & DSISR_GUARDED)
2779 /* Guarded storage error. */
2780 goto bad_area;
2781 #endif /* CONFIG_8xx */
2782 @@ -274,7 +306,7 @@ good_area:
2783 * processors use the same I/D cache coherency mechanism
2784 * as embedded.
2785 */
2786 - if (error_code & DSISR_PROTFAULT)
2787 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
2788 goto bad_area;
2789 #endif /* CONFIG_PPC_STD_MMU */
2790
2791 @@ -343,6 +375,23 @@ bad_area:
2792 bad_area_nosemaphore:
2793 /* User mode accesses cause a SIGSEGV */
2794 if (user_mode(regs)) {
2795 +
2796 +#ifdef CONFIG_PAX_PAGEEXEC
2797 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2798 +#ifdef CONFIG_PPC_STD_MMU
2799 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
2800 +#else
2801 + if (is_exec && regs->nip == address) {
2802 +#endif
2803 + switch (pax_handle_fetch_fault(regs)) {
2804 + }
2805 +
2806 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
2807 + do_group_exit(SIGKILL);
2808 + }
2809 + }
2810 +#endif
2811 +
2812 _exception(SIGSEGV, regs, code, address);
2813 return 0;
2814 }
2815 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
2816 index 5a783d8..c23e14b 100644
2817 --- a/arch/powerpc/mm/mmap_64.c
2818 +++ b/arch/powerpc/mm/mmap_64.c
2819 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2820 */
2821 if (mmap_is_legacy()) {
2822 mm->mmap_base = TASK_UNMAPPED_BASE;
2823 +
2824 +#ifdef CONFIG_PAX_RANDMMAP
2825 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2826 + mm->mmap_base += mm->delta_mmap;
2827 +#endif
2828 +
2829 mm->get_unmapped_area = arch_get_unmapped_area;
2830 mm->unmap_area = arch_unmap_area;
2831 } else {
2832 mm->mmap_base = mmap_base();
2833 +
2834 +#ifdef CONFIG_PAX_RANDMMAP
2835 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2836 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2837 +#endif
2838 +
2839 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2840 mm->unmap_area = arch_unmap_area_topdown;
2841 }
2842 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
2843 index 73709f7..6b90313 100644
2844 --- a/arch/powerpc/mm/slice.c
2845 +++ b/arch/powerpc/mm/slice.c
2846 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
2847 if ((mm->task_size - len) < addr)
2848 return 0;
2849 vma = find_vma(mm, addr);
2850 - return (!vma || (addr + len) <= vma->vm_start);
2851 + return check_heap_stack_gap(vma, addr, len);
2852 }
2853
2854 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
2855 @@ -256,7 +256,7 @@ full_search:
2856 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
2857 continue;
2858 }
2859 - if (!vma || addr + len <= vma->vm_start) {
2860 + if (check_heap_stack_gap(vma, addr, len)) {
2861 /*
2862 * Remember the place where we stopped the search:
2863 */
2864 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
2865 }
2866 }
2867
2868 - addr = mm->mmap_base;
2869 - while (addr > len) {
2870 + if (mm->mmap_base < len)
2871 + addr = -ENOMEM;
2872 + else
2873 + addr = mm->mmap_base - len;
2874 +
2875 + while (!IS_ERR_VALUE(addr)) {
2876 /* Go down by chunk size */
2877 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
2878 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
2879
2880 /* Check for hit with different page size */
2881 mask = slice_range_to_mask(addr, len);
2882 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
2883 * return with success:
2884 */
2885 vma = find_vma(mm, addr);
2886 - if (!vma || (addr + len) <= vma->vm_start) {
2887 + if (check_heap_stack_gap(vma, addr, len)) {
2888 /* remember the address as a hint for next time */
2889 if (use_cache)
2890 mm->free_area_cache = addr;
2891 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
2892 mm->cached_hole_size = vma->vm_start - addr;
2893
2894 /* try just below the current vma->vm_start */
2895 - addr = vma->vm_start;
2896 + addr = skip_heap_stack_gap(vma, len);
2897 }
2898
2899 /*
2900 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
2901 if (fixed && addr > (mm->task_size - len))
2902 return -EINVAL;
2903
2904 +#ifdef CONFIG_PAX_RANDMMAP
2905 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
2906 + addr = 0;
2907 +#endif
2908 +
2909 /* If hint, make sure it matches our alignment restrictions */
2910 if (!fixed && addr) {
2911 addr = _ALIGN_UP(addr, 1ul << pshift);
2912 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
2913 index 547f1a6..3fff354 100644
2914 --- a/arch/s390/include/asm/elf.h
2915 +++ b/arch/s390/include/asm/elf.h
2916 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
2917 the loader. We need to make sure that it is out of the way of the program
2918 that it will "exec", and that there is sufficient room for the brk. */
2919
2920 -extern unsigned long randomize_et_dyn(unsigned long base);
2921 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
2922 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
2923 +
2924 +#ifdef CONFIG_PAX_ASLR
2925 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
2926 +
2927 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
2928 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
2929 +#endif
2930
2931 /* This yields a mask that user programs can use to figure out what
2932 instruction set this CPU supports. */
2933 @@ -211,7 +217,4 @@ struct linux_binprm;
2934 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2935 int arch_setup_additional_pages(struct linux_binprm *, int);
2936
2937 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2938 -#define arch_randomize_brk arch_randomize_brk
2939 -
2940 #endif
2941 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
2942 index ef573c1..75a1ce6 100644
2943 --- a/arch/s390/include/asm/system.h
2944 +++ b/arch/s390/include/asm/system.h
2945 @@ -262,7 +262,7 @@ extern void (*_machine_restart)(char *command);
2946 extern void (*_machine_halt)(void);
2947 extern void (*_machine_power_off)(void);
2948
2949 -extern unsigned long arch_align_stack(unsigned long sp);
2950 +#define arch_align_stack(x) ((x) & ~0xfUL)
2951
2952 static inline int tprot(unsigned long addr)
2953 {
2954 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
2955 index 2b23885..e136e31 100644
2956 --- a/arch/s390/include/asm/uaccess.h
2957 +++ b/arch/s390/include/asm/uaccess.h
2958 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
2959 copy_to_user(void __user *to, const void *from, unsigned long n)
2960 {
2961 might_fault();
2962 +
2963 + if ((long)n < 0)
2964 + return n;
2965 +
2966 if (access_ok(VERIFY_WRITE, to, n))
2967 n = __copy_to_user(to, from, n);
2968 return n;
2969 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
2970 static inline unsigned long __must_check
2971 __copy_from_user(void *to, const void __user *from, unsigned long n)
2972 {
2973 + if ((long)n < 0)
2974 + return n;
2975 +
2976 if (__builtin_constant_p(n) && (n <= 256))
2977 return uaccess.copy_from_user_small(n, from, to);
2978 else
2979 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
2980 unsigned int sz = __compiletime_object_size(to);
2981
2982 might_fault();
2983 +
2984 + if ((long)n < 0)
2985 + return n;
2986 +
2987 if (unlikely(sz != -1 && sz < n)) {
2988 copy_from_user_overflow();
2989 return n;
2990 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
2991 index dfcb343..eda788a 100644
2992 --- a/arch/s390/kernel/module.c
2993 +++ b/arch/s390/kernel/module.c
2994 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
2995
2996 /* Increase core size by size of got & plt and set start
2997 offsets for got and plt. */
2998 - me->core_size = ALIGN(me->core_size, 4);
2999 - me->arch.got_offset = me->core_size;
3000 - me->core_size += me->arch.got_size;
3001 - me->arch.plt_offset = me->core_size;
3002 - me->core_size += me->arch.plt_size;
3003 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
3004 + me->arch.got_offset = me->core_size_rw;
3005 + me->core_size_rw += me->arch.got_size;
3006 + me->arch.plt_offset = me->core_size_rx;
3007 + me->core_size_rx += me->arch.plt_size;
3008 return 0;
3009 }
3010
3011 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3012 if (info->got_initialized == 0) {
3013 Elf_Addr *gotent;
3014
3015 - gotent = me->module_core + me->arch.got_offset +
3016 + gotent = me->module_core_rw + me->arch.got_offset +
3017 info->got_offset;
3018 *gotent = val;
3019 info->got_initialized = 1;
3020 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3021 else if (r_type == R_390_GOTENT ||
3022 r_type == R_390_GOTPLTENT)
3023 *(unsigned int *) loc =
3024 - (val + (Elf_Addr) me->module_core - loc) >> 1;
3025 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3026 else if (r_type == R_390_GOT64 ||
3027 r_type == R_390_GOTPLT64)
3028 *(unsigned long *) loc = val;
3029 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3030 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3031 if (info->plt_initialized == 0) {
3032 unsigned int *ip;
3033 - ip = me->module_core + me->arch.plt_offset +
3034 + ip = me->module_core_rx + me->arch.plt_offset +
3035 info->plt_offset;
3036 #ifndef CONFIG_64BIT
3037 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3038 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3039 val - loc + 0xffffUL < 0x1ffffeUL) ||
3040 (r_type == R_390_PLT32DBL &&
3041 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3042 - val = (Elf_Addr) me->module_core +
3043 + val = (Elf_Addr) me->module_core_rx +
3044 me->arch.plt_offset +
3045 info->plt_offset;
3046 val += rela->r_addend - loc;
3047 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3048 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3049 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3050 val = val + rela->r_addend -
3051 - ((Elf_Addr) me->module_core + me->arch.got_offset);
3052 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3053 if (r_type == R_390_GOTOFF16)
3054 *(unsigned short *) loc = val;
3055 else if (r_type == R_390_GOTOFF32)
3056 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3057 break;
3058 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3059 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3060 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
3061 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3062 rela->r_addend - loc;
3063 if (r_type == R_390_GOTPC)
3064 *(unsigned int *) loc = val;
3065 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
3066 index 9451b21..ed8956f 100644
3067 --- a/arch/s390/kernel/process.c
3068 +++ b/arch/s390/kernel/process.c
3069 @@ -321,39 +321,3 @@ unsigned long get_wchan(struct task_struct *p)
3070 }
3071 return 0;
3072 }
3073 -
3074 -unsigned long arch_align_stack(unsigned long sp)
3075 -{
3076 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3077 - sp -= get_random_int() & ~PAGE_MASK;
3078 - return sp & ~0xf;
3079 -}
3080 -
3081 -static inline unsigned long brk_rnd(void)
3082 -{
3083 - /* 8MB for 32bit, 1GB for 64bit */
3084 - if (is_32bit_task())
3085 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
3086 - else
3087 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
3088 -}
3089 -
3090 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3091 -{
3092 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
3093 -
3094 - if (ret < mm->brk)
3095 - return mm->brk;
3096 - return ret;
3097 -}
3098 -
3099 -unsigned long randomize_et_dyn(unsigned long base)
3100 -{
3101 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3102 -
3103 - if (!(current->flags & PF_RANDOMIZE))
3104 - return base;
3105 - if (ret < base)
3106 - return base;
3107 - return ret;
3108 -}
3109 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
3110 index f09c748..cf9ec1d 100644
3111 --- a/arch/s390/mm/mmap.c
3112 +++ b/arch/s390/mm/mmap.c
3113 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3114 */
3115 if (mmap_is_legacy()) {
3116 mm->mmap_base = TASK_UNMAPPED_BASE;
3117 +
3118 +#ifdef CONFIG_PAX_RANDMMAP
3119 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3120 + mm->mmap_base += mm->delta_mmap;
3121 +#endif
3122 +
3123 mm->get_unmapped_area = arch_get_unmapped_area;
3124 mm->unmap_area = arch_unmap_area;
3125 } else {
3126 mm->mmap_base = mmap_base();
3127 +
3128 +#ifdef CONFIG_PAX_RANDMMAP
3129 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3130 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3131 +#endif
3132 +
3133 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3134 mm->unmap_area = arch_unmap_area_topdown;
3135 }
3136 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3137 */
3138 if (mmap_is_legacy()) {
3139 mm->mmap_base = TASK_UNMAPPED_BASE;
3140 +
3141 +#ifdef CONFIG_PAX_RANDMMAP
3142 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3143 + mm->mmap_base += mm->delta_mmap;
3144 +#endif
3145 +
3146 mm->get_unmapped_area = s390_get_unmapped_area;
3147 mm->unmap_area = arch_unmap_area;
3148 } else {
3149 mm->mmap_base = mmap_base();
3150 +
3151 +#ifdef CONFIG_PAX_RANDMMAP
3152 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3153 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3154 +#endif
3155 +
3156 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
3157 mm->unmap_area = arch_unmap_area_topdown;
3158 }
3159 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
3160 index 589d5c7..669e274 100644
3161 --- a/arch/score/include/asm/system.h
3162 +++ b/arch/score/include/asm/system.h
3163 @@ -17,7 +17,7 @@ do { \
3164 #define finish_arch_switch(prev) do {} while (0)
3165
3166 typedef void (*vi_handler_t)(void);
3167 -extern unsigned long arch_align_stack(unsigned long sp);
3168 +#define arch_align_stack(x) (x)
3169
3170 #define mb() barrier()
3171 #define rmb() barrier()
3172 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
3173 index 25d0803..d6c8e36 100644
3174 --- a/arch/score/kernel/process.c
3175 +++ b/arch/score/kernel/process.c
3176 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
3177
3178 return task_pt_regs(task)->cp0_epc;
3179 }
3180 -
3181 -unsigned long arch_align_stack(unsigned long sp)
3182 -{
3183 - return sp;
3184 -}
3185 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
3186 index afeb710..d1d1289 100644
3187 --- a/arch/sh/mm/mmap.c
3188 +++ b/arch/sh/mm/mmap.c
3189 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3190 addr = PAGE_ALIGN(addr);
3191
3192 vma = find_vma(mm, addr);
3193 - if (TASK_SIZE - len >= addr &&
3194 - (!vma || addr + len <= vma->vm_start))
3195 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3196 return addr;
3197 }
3198
3199 @@ -106,7 +105,7 @@ full_search:
3200 }
3201 return -ENOMEM;
3202 }
3203 - if (likely(!vma || addr + len <= vma->vm_start)) {
3204 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3205 /*
3206 * Remember the place where we stopped the search:
3207 */
3208 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3209 addr = PAGE_ALIGN(addr);
3210
3211 vma = find_vma(mm, addr);
3212 - if (TASK_SIZE - len >= addr &&
3213 - (!vma || addr + len <= vma->vm_start))
3214 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3215 return addr;
3216 }
3217
3218 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3219 /* make sure it can fit in the remaining address space */
3220 if (likely(addr > len)) {
3221 vma = find_vma(mm, addr-len);
3222 - if (!vma || addr <= vma->vm_start) {
3223 + if (check_heap_stack_gap(vma, addr - len, len)) {
3224 /* remember the address as a hint for next time */
3225 return (mm->free_area_cache = addr-len);
3226 }
3227 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3228 if (unlikely(mm->mmap_base < len))
3229 goto bottomup;
3230
3231 - addr = mm->mmap_base-len;
3232 - if (do_colour_align)
3233 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3234 + addr = mm->mmap_base - len;
3235
3236 do {
3237 + if (do_colour_align)
3238 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3239 /*
3240 * Lookup failure means no vma is above this address,
3241 * else if new region fits below vma->vm_start,
3242 * return with success:
3243 */
3244 vma = find_vma(mm, addr);
3245 - if (likely(!vma || addr+len <= vma->vm_start)) {
3246 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3247 /* remember the address as a hint for next time */
3248 return (mm->free_area_cache = addr);
3249 }
3250 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3251 mm->cached_hole_size = vma->vm_start - addr;
3252
3253 /* try just below the current vma->vm_start */
3254 - addr = vma->vm_start-len;
3255 - if (do_colour_align)
3256 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3257 - } while (likely(len < vma->vm_start));
3258 + addr = skip_heap_stack_gap(vma, len);
3259 + } while (!IS_ERR_VALUE(addr));
3260
3261 bottomup:
3262 /*
3263 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
3264 index ad1fb5d..fc5315b 100644
3265 --- a/arch/sparc/Makefile
3266 +++ b/arch/sparc/Makefile
3267 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
3268 # Export what is needed by arch/sparc/boot/Makefile
3269 export VMLINUX_INIT VMLINUX_MAIN
3270 VMLINUX_INIT := $(head-y) $(init-y)
3271 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
3272 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
3273 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
3274 VMLINUX_MAIN += $(drivers-y) $(net-y)
3275
3276 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
3277 index 9f421df..b81fc12 100644
3278 --- a/arch/sparc/include/asm/atomic_64.h
3279 +++ b/arch/sparc/include/asm/atomic_64.h
3280 @@ -14,18 +14,40 @@
3281 #define ATOMIC64_INIT(i) { (i) }
3282
3283 #define atomic_read(v) (*(volatile int *)&(v)->counter)
3284 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
3285 +{
3286 + return v->counter;
3287 +}
3288 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
3289 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
3290 +{
3291 + return v->counter;
3292 +}
3293
3294 #define atomic_set(v, i) (((v)->counter) = i)
3295 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
3296 +{
3297 + v->counter = i;
3298 +}
3299 #define atomic64_set(v, i) (((v)->counter) = i)
3300 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
3301 +{
3302 + v->counter = i;
3303 +}
3304
3305 extern void atomic_add(int, atomic_t *);
3306 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
3307 extern void atomic64_add(long, atomic64_t *);
3308 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
3309 extern void atomic_sub(int, atomic_t *);
3310 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
3311 extern void atomic64_sub(long, atomic64_t *);
3312 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
3313
3314 extern int atomic_add_ret(int, atomic_t *);
3315 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
3316 extern long atomic64_add_ret(long, atomic64_t *);
3317 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
3318 extern int atomic_sub_ret(int, atomic_t *);
3319 extern long atomic64_sub_ret(long, atomic64_t *);
3320
3321 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3322 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
3323
3324 #define atomic_inc_return(v) atomic_add_ret(1, v)
3325 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
3326 +{
3327 + return atomic_add_ret_unchecked(1, v);
3328 +}
3329 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
3330 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
3331 +{
3332 + return atomic64_add_ret_unchecked(1, v);
3333 +}
3334
3335 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
3336 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
3337
3338 #define atomic_add_return(i, v) atomic_add_ret(i, v)
3339 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
3340 +{
3341 + return atomic_add_ret_unchecked(i, v);
3342 +}
3343 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
3344 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
3345 +{
3346 + return atomic64_add_ret_unchecked(i, v);
3347 +}
3348
3349 /*
3350 * atomic_inc_and_test - increment and test
3351 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3352 * other cases.
3353 */
3354 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
3355 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
3356 +{
3357 + return atomic_inc_return_unchecked(v) == 0;
3358 +}
3359 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
3360
3361 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
3362 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3363 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
3364
3365 #define atomic_inc(v) atomic_add(1, v)
3366 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
3367 +{
3368 + atomic_add_unchecked(1, v);
3369 +}
3370 #define atomic64_inc(v) atomic64_add(1, v)
3371 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
3372 +{
3373 + atomic64_add_unchecked(1, v);
3374 +}
3375
3376 #define atomic_dec(v) atomic_sub(1, v)
3377 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
3378 +{
3379 + atomic_sub_unchecked(1, v);
3380 +}
3381 #define atomic64_dec(v) atomic64_sub(1, v)
3382 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
3383 +{
3384 + atomic64_sub_unchecked(1, v);
3385 +}
3386
3387 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
3388 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
3389
3390 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
3391 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
3392 +{
3393 + return cmpxchg(&v->counter, old, new);
3394 +}
3395 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
3396 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
3397 +{
3398 + return xchg(&v->counter, new);
3399 +}
3400
3401 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
3402 {
3403 - int c, old;
3404 + int c, old, new;
3405 c = atomic_read(v);
3406 for (;;) {
3407 - if (unlikely(c == (u)))
3408 + if (unlikely(c == u))
3409 break;
3410 - old = atomic_cmpxchg((v), c, c + (a));
3411 +
3412 + asm volatile("addcc %2, %0, %0\n"
3413 +
3414 +#ifdef CONFIG_PAX_REFCOUNT
3415 + "tvs %%icc, 6\n"
3416 +#endif
3417 +
3418 + : "=r" (new)
3419 + : "0" (c), "ir" (a)
3420 + : "cc");
3421 +
3422 + old = atomic_cmpxchg(v, c, new);
3423 if (likely(old == c))
3424 break;
3425 c = old;
3426 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
3427 #define atomic64_cmpxchg(v, o, n) \
3428 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
3429 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
3430 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
3431 +{
3432 + return xchg(&v->counter, new);
3433 +}
3434
3435 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
3436 {
3437 - long c, old;
3438 + long c, old, new;
3439 c = atomic64_read(v);
3440 for (;;) {
3441 - if (unlikely(c == (u)))
3442 + if (unlikely(c == u))
3443 break;
3444 - old = atomic64_cmpxchg((v), c, c + (a));
3445 +
3446 + asm volatile("addcc %2, %0, %0\n"
3447 +
3448 +#ifdef CONFIG_PAX_REFCOUNT
3449 + "tvs %%xcc, 6\n"
3450 +#endif
3451 +
3452 + : "=r" (new)
3453 + : "0" (c), "ir" (a)
3454 + : "cc");
3455 +
3456 + old = atomic64_cmpxchg(v, c, new);
3457 if (likely(old == c))
3458 break;
3459 c = old;
3460 }
3461 - return c != (u);
3462 + return c != u;
3463 }
3464
3465 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3466 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
3467 index 69358b5..17b4745 100644
3468 --- a/arch/sparc/include/asm/cache.h
3469 +++ b/arch/sparc/include/asm/cache.h
3470 @@ -10,7 +10,7 @@
3471 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
3472
3473 #define L1_CACHE_SHIFT 5
3474 -#define L1_CACHE_BYTES 32
3475 +#define L1_CACHE_BYTES 32UL
3476
3477 #ifdef CONFIG_SPARC32
3478 #define SMP_CACHE_BYTES_SHIFT 5
3479 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
3480 index 4269ca6..e3da77f 100644
3481 --- a/arch/sparc/include/asm/elf_32.h
3482 +++ b/arch/sparc/include/asm/elf_32.h
3483 @@ -114,6 +114,13 @@ typedef struct {
3484
3485 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3486
3487 +#ifdef CONFIG_PAX_ASLR
3488 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3489 +
3490 +#define PAX_DELTA_MMAP_LEN 16
3491 +#define PAX_DELTA_STACK_LEN 16
3492 +#endif
3493 +
3494 /* This yields a mask that user programs can use to figure out what
3495 instruction set this cpu supports. This can NOT be done in userspace
3496 on Sparc. */
3497 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
3498 index 7df8b7f..4946269 100644
3499 --- a/arch/sparc/include/asm/elf_64.h
3500 +++ b/arch/sparc/include/asm/elf_64.h
3501 @@ -180,6 +180,13 @@ typedef struct {
3502 #define ELF_ET_DYN_BASE 0x0000010000000000UL
3503 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
3504
3505 +#ifdef CONFIG_PAX_ASLR
3506 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3507 +
3508 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
3509 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
3510 +#endif
3511 +
3512 extern unsigned long sparc64_elf_hwcap;
3513 #define ELF_HWCAP sparc64_elf_hwcap
3514
3515 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
3516 index a790cc6..091ed94 100644
3517 --- a/arch/sparc/include/asm/pgtable_32.h
3518 +++ b/arch/sparc/include/asm/pgtable_32.h
3519 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
3520 BTFIXUPDEF_INT(page_none)
3521 BTFIXUPDEF_INT(page_copy)
3522 BTFIXUPDEF_INT(page_readonly)
3523 +
3524 +#ifdef CONFIG_PAX_PAGEEXEC
3525 +BTFIXUPDEF_INT(page_shared_noexec)
3526 +BTFIXUPDEF_INT(page_copy_noexec)
3527 +BTFIXUPDEF_INT(page_readonly_noexec)
3528 +#endif
3529 +
3530 BTFIXUPDEF_INT(page_kernel)
3531
3532 #define PMD_SHIFT SUN4C_PMD_SHIFT
3533 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
3534 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
3535 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
3536
3537 +#ifdef CONFIG_PAX_PAGEEXEC
3538 +extern pgprot_t PAGE_SHARED_NOEXEC;
3539 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
3540 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
3541 +#else
3542 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3543 +# define PAGE_COPY_NOEXEC PAGE_COPY
3544 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3545 +#endif
3546 +
3547 extern unsigned long page_kernel;
3548
3549 #ifdef MODULE
3550 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
3551 index f6ae2b2..b03ffc7 100644
3552 --- a/arch/sparc/include/asm/pgtsrmmu.h
3553 +++ b/arch/sparc/include/asm/pgtsrmmu.h
3554 @@ -115,6 +115,13 @@
3555 SRMMU_EXEC | SRMMU_REF)
3556 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
3557 SRMMU_EXEC | SRMMU_REF)
3558 +
3559 +#ifdef CONFIG_PAX_PAGEEXEC
3560 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
3561 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3562 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3563 +#endif
3564 +
3565 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
3566 SRMMU_DIRTY | SRMMU_REF)
3567
3568 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
3569 index 9689176..63c18ea 100644
3570 --- a/arch/sparc/include/asm/spinlock_64.h
3571 +++ b/arch/sparc/include/asm/spinlock_64.h
3572 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
3573
3574 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
3575
3576 -static void inline arch_read_lock(arch_rwlock_t *lock)
3577 +static inline void arch_read_lock(arch_rwlock_t *lock)
3578 {
3579 unsigned long tmp1, tmp2;
3580
3581 __asm__ __volatile__ (
3582 "1: ldsw [%2], %0\n"
3583 " brlz,pn %0, 2f\n"
3584 -"4: add %0, 1, %1\n"
3585 +"4: addcc %0, 1, %1\n"
3586 +
3587 +#ifdef CONFIG_PAX_REFCOUNT
3588 +" tvs %%icc, 6\n"
3589 +#endif
3590 +
3591 " cas [%2], %0, %1\n"
3592 " cmp %0, %1\n"
3593 " bne,pn %%icc, 1b\n"
3594 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
3595 " .previous"
3596 : "=&r" (tmp1), "=&r" (tmp2)
3597 : "r" (lock)
3598 - : "memory");
3599 + : "memory", "cc");
3600 }
3601
3602 -static int inline arch_read_trylock(arch_rwlock_t *lock)
3603 +static inline int arch_read_trylock(arch_rwlock_t *lock)
3604 {
3605 int tmp1, tmp2;
3606
3607 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
3608 "1: ldsw [%2], %0\n"
3609 " brlz,a,pn %0, 2f\n"
3610 " mov 0, %0\n"
3611 -" add %0, 1, %1\n"
3612 +" addcc %0, 1, %1\n"
3613 +
3614 +#ifdef CONFIG_PAX_REFCOUNT
3615 +" tvs %%icc, 6\n"
3616 +#endif
3617 +
3618 " cas [%2], %0, %1\n"
3619 " cmp %0, %1\n"
3620 " bne,pn %%icc, 1b\n"
3621 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
3622 return tmp1;
3623 }
3624
3625 -static void inline arch_read_unlock(arch_rwlock_t *lock)
3626 +static inline void arch_read_unlock(arch_rwlock_t *lock)
3627 {
3628 unsigned long tmp1, tmp2;
3629
3630 __asm__ __volatile__(
3631 "1: lduw [%2], %0\n"
3632 -" sub %0, 1, %1\n"
3633 +" subcc %0, 1, %1\n"
3634 +
3635 +#ifdef CONFIG_PAX_REFCOUNT
3636 +" tvs %%icc, 6\n"
3637 +#endif
3638 +
3639 " cas [%2], %0, %1\n"
3640 " cmp %0, %1\n"
3641 " bne,pn %%xcc, 1b\n"
3642 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
3643 : "memory");
3644 }
3645
3646 -static void inline arch_write_lock(arch_rwlock_t *lock)
3647 +static inline void arch_write_lock(arch_rwlock_t *lock)
3648 {
3649 unsigned long mask, tmp1, tmp2;
3650
3651 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
3652 : "memory");
3653 }
3654
3655 -static void inline arch_write_unlock(arch_rwlock_t *lock)
3656 +static inline void arch_write_unlock(arch_rwlock_t *lock)
3657 {
3658 __asm__ __volatile__(
3659 " stw %%g0, [%0]"
3660 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
3661 : "memory");
3662 }
3663
3664 -static int inline arch_write_trylock(arch_rwlock_t *lock)
3665 +static inline int arch_write_trylock(arch_rwlock_t *lock)
3666 {
3667 unsigned long mask, tmp1, tmp2, result;
3668
3669 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
3670 index fa57532..e1a4c53 100644
3671 --- a/arch/sparc/include/asm/thread_info_32.h
3672 +++ b/arch/sparc/include/asm/thread_info_32.h
3673 @@ -50,6 +50,8 @@ struct thread_info {
3674 unsigned long w_saved;
3675
3676 struct restart_block restart_block;
3677 +
3678 + unsigned long lowest_stack;
3679 };
3680
3681 /*
3682 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
3683 index 60d86be..952dea1 100644
3684 --- a/arch/sparc/include/asm/thread_info_64.h
3685 +++ b/arch/sparc/include/asm/thread_info_64.h
3686 @@ -63,6 +63,8 @@ struct thread_info {
3687 struct pt_regs *kern_una_regs;
3688 unsigned int kern_una_insn;
3689
3690 + unsigned long lowest_stack;
3691 +
3692 unsigned long fpregs[0] __attribute__ ((aligned(64)));
3693 };
3694
3695 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
3696 index e88fbe5..96b0ce5 100644
3697 --- a/arch/sparc/include/asm/uaccess.h
3698 +++ b/arch/sparc/include/asm/uaccess.h
3699 @@ -1,5 +1,13 @@
3700 #ifndef ___ASM_SPARC_UACCESS_H
3701 #define ___ASM_SPARC_UACCESS_H
3702 +
3703 +#ifdef __KERNEL__
3704 +#ifndef __ASSEMBLY__
3705 +#include <linux/types.h>
3706 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3707 +#endif
3708 +#endif
3709 +
3710 #if defined(__sparc__) && defined(__arch64__)
3711 #include <asm/uaccess_64.h>
3712 #else
3713 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
3714 index 8303ac4..07f333d 100644
3715 --- a/arch/sparc/include/asm/uaccess_32.h
3716 +++ b/arch/sparc/include/asm/uaccess_32.h
3717 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
3718
3719 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3720 {
3721 - if (n && __access_ok((unsigned long) to, n))
3722 + if ((long)n < 0)
3723 + return n;
3724 +
3725 + if (n && __access_ok((unsigned long) to, n)) {
3726 + if (!__builtin_constant_p(n))
3727 + check_object_size(from, n, true);
3728 return __copy_user(to, (__force void __user *) from, n);
3729 - else
3730 + } else
3731 return n;
3732 }
3733
3734 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
3735 {
3736 + if ((long)n < 0)
3737 + return n;
3738 +
3739 + if (!__builtin_constant_p(n))
3740 + check_object_size(from, n, true);
3741 +
3742 return __copy_user(to, (__force void __user *) from, n);
3743 }
3744
3745 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3746 {
3747 - if (n && __access_ok((unsigned long) from, n))
3748 + if ((long)n < 0)
3749 + return n;
3750 +
3751 + if (n && __access_ok((unsigned long) from, n)) {
3752 + if (!__builtin_constant_p(n))
3753 + check_object_size(to, n, false);
3754 return __copy_user((__force void __user *) to, from, n);
3755 - else
3756 + } else
3757 return n;
3758 }
3759
3760 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
3761 {
3762 + if ((long)n < 0)
3763 + return n;
3764 +
3765 return __copy_user((__force void __user *) to, from, n);
3766 }
3767
3768 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
3769 index 3e1449f..5293a0e 100644
3770 --- a/arch/sparc/include/asm/uaccess_64.h
3771 +++ b/arch/sparc/include/asm/uaccess_64.h
3772 @@ -10,6 +10,7 @@
3773 #include <linux/compiler.h>
3774 #include <linux/string.h>
3775 #include <linux/thread_info.h>
3776 +#include <linux/kernel.h>
3777 #include <asm/asi.h>
3778 #include <asm/system.h>
3779 #include <asm/spitfire.h>
3780 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
3781 static inline unsigned long __must_check
3782 copy_from_user(void *to, const void __user *from, unsigned long size)
3783 {
3784 - unsigned long ret = ___copy_from_user(to, from, size);
3785 + unsigned long ret;
3786
3787 + if ((long)size < 0 || size > INT_MAX)
3788 + return size;
3789 +
3790 + if (!__builtin_constant_p(size))
3791 + check_object_size(to, size, false);
3792 +
3793 + ret = ___copy_from_user(to, from, size);
3794 if (unlikely(ret))
3795 ret = copy_from_user_fixup(to, from, size);
3796
3797 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
3798 static inline unsigned long __must_check
3799 copy_to_user(void __user *to, const void *from, unsigned long size)
3800 {
3801 - unsigned long ret = ___copy_to_user(to, from, size);
3802 + unsigned long ret;
3803
3804 + if ((long)size < 0 || size > INT_MAX)
3805 + return size;
3806 +
3807 + if (!__builtin_constant_p(size))
3808 + check_object_size(from, size, true);
3809 +
3810 + ret = ___copy_to_user(to, from, size);
3811 if (unlikely(ret))
3812 ret = copy_to_user_fixup(to, from, size);
3813 return ret;
3814 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
3815 index cb85458..e063f17 100644
3816 --- a/arch/sparc/kernel/Makefile
3817 +++ b/arch/sparc/kernel/Makefile
3818 @@ -3,7 +3,7 @@
3819 #
3820
3821 asflags-y := -ansi
3822 -ccflags-y := -Werror
3823 +#ccflags-y := -Werror
3824
3825 extra-y := head_$(BITS).o
3826 extra-y += init_task.o
3827 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
3828 index f793742..4d880af 100644
3829 --- a/arch/sparc/kernel/process_32.c
3830 +++ b/arch/sparc/kernel/process_32.c
3831 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
3832 rw->ins[4], rw->ins[5],
3833 rw->ins[6],
3834 rw->ins[7]);
3835 - printk("%pS\n", (void *) rw->ins[7]);
3836 + printk("%pA\n", (void *) rw->ins[7]);
3837 rw = (struct reg_window32 *) rw->ins[6];
3838 }
3839 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
3840 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
3841
3842 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
3843 r->psr, r->pc, r->npc, r->y, print_tainted());
3844 - printk("PC: <%pS>\n", (void *) r->pc);
3845 + printk("PC: <%pA>\n", (void *) r->pc);
3846 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
3847 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
3848 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
3849 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
3850 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
3851 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
3852 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
3853 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
3854
3855 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
3856 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
3857 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
3858 rw = (struct reg_window32 *) fp;
3859 pc = rw->ins[7];
3860 printk("[%08lx : ", pc);
3861 - printk("%pS ] ", (void *) pc);
3862 + printk("%pA ] ", (void *) pc);
3863 fp = rw->ins[6];
3864 } while (++count < 16);
3865 printk("\n");
3866 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
3867 index 3739a06..48b2ff0 100644
3868 --- a/arch/sparc/kernel/process_64.c
3869 +++ b/arch/sparc/kernel/process_64.c
3870 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_regs *regs)
3871 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
3872 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
3873 if (regs->tstate & TSTATE_PRIV)
3874 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
3875 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
3876 }
3877
3878 void show_regs(struct pt_regs *regs)
3879 {
3880 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
3881 regs->tpc, regs->tnpc, regs->y, print_tainted());
3882 - printk("TPC: <%pS>\n", (void *) regs->tpc);
3883 + printk("TPC: <%pA>\n", (void *) regs->tpc);
3884 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
3885 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
3886 regs->u_regs[3]);
3887 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
3888 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
3889 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
3890 regs->u_regs[15]);
3891 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
3892 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
3893 show_regwindow(regs);
3894 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
3895 }
3896 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void)
3897 ((tp && tp->task) ? tp->task->pid : -1));
3898
3899 if (gp->tstate & TSTATE_PRIV) {
3900 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
3901 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
3902 (void *) gp->tpc,
3903 (void *) gp->o7,
3904 (void *) gp->i7,
3905 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
3906 index 42b282f..28ce9f2 100644
3907 --- a/arch/sparc/kernel/sys_sparc_32.c
3908 +++ b/arch/sparc/kernel/sys_sparc_32.c
3909 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3910 if (ARCH_SUN4C && len > 0x20000000)
3911 return -ENOMEM;
3912 if (!addr)
3913 - addr = TASK_UNMAPPED_BASE;
3914 + addr = current->mm->mmap_base;
3915
3916 if (flags & MAP_SHARED)
3917 addr = COLOUR_ALIGN(addr);
3918 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3919 }
3920 if (TASK_SIZE - PAGE_SIZE - len < addr)
3921 return -ENOMEM;
3922 - if (!vmm || addr + len <= vmm->vm_start)
3923 + if (check_heap_stack_gap(vmm, addr, len))
3924 return addr;
3925 addr = vmm->vm_end;
3926 if (flags & MAP_SHARED)
3927 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
3928 index 441521a..b767073 100644
3929 --- a/arch/sparc/kernel/sys_sparc_64.c
3930 +++ b/arch/sparc/kernel/sys_sparc_64.c
3931 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3932 /* We do not accept a shared mapping if it would violate
3933 * cache aliasing constraints.
3934 */
3935 - if ((flags & MAP_SHARED) &&
3936 + if ((filp || (flags & MAP_SHARED)) &&
3937 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
3938 return -EINVAL;
3939 return addr;
3940 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3941 if (filp || (flags & MAP_SHARED))
3942 do_color_align = 1;
3943
3944 +#ifdef CONFIG_PAX_RANDMMAP
3945 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3946 +#endif
3947 +
3948 if (addr) {
3949 if (do_color_align)
3950 addr = COLOUR_ALIGN(addr, pgoff);
3951 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3952 addr = PAGE_ALIGN(addr);
3953
3954 vma = find_vma(mm, addr);
3955 - if (task_size - len >= addr &&
3956 - (!vma || addr + len <= vma->vm_start))
3957 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
3958 return addr;
3959 }
3960
3961 if (len > mm->cached_hole_size) {
3962 - start_addr = addr = mm->free_area_cache;
3963 + start_addr = addr = mm->free_area_cache;
3964 } else {
3965 - start_addr = addr = TASK_UNMAPPED_BASE;
3966 + start_addr = addr = mm->mmap_base;
3967 mm->cached_hole_size = 0;
3968 }
3969
3970 @@ -174,14 +177,14 @@ full_search:
3971 vma = find_vma(mm, VA_EXCLUDE_END);
3972 }
3973 if (unlikely(task_size < addr)) {
3974 - if (start_addr != TASK_UNMAPPED_BASE) {
3975 - start_addr = addr = TASK_UNMAPPED_BASE;
3976 + if (start_addr != mm->mmap_base) {
3977 + start_addr = addr = mm->mmap_base;
3978 mm->cached_hole_size = 0;
3979 goto full_search;
3980 }
3981 return -ENOMEM;
3982 }
3983 - if (likely(!vma || addr + len <= vma->vm_start)) {
3984 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3985 /*
3986 * Remember the place where we stopped the search:
3987 */
3988 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3989 /* We do not accept a shared mapping if it would violate
3990 * cache aliasing constraints.
3991 */
3992 - if ((flags & MAP_SHARED) &&
3993 + if ((filp || (flags & MAP_SHARED)) &&
3994 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
3995 return -EINVAL;
3996 return addr;
3997 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3998 addr = PAGE_ALIGN(addr);
3999
4000 vma = find_vma(mm, addr);
4001 - if (task_size - len >= addr &&
4002 - (!vma || addr + len <= vma->vm_start))
4003 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4004 return addr;
4005 }
4006
4007 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4008 /* make sure it can fit in the remaining address space */
4009 if (likely(addr > len)) {
4010 vma = find_vma(mm, addr-len);
4011 - if (!vma || addr <= vma->vm_start) {
4012 + if (check_heap_stack_gap(vma, addr - len, len)) {
4013 /* remember the address as a hint for next time */
4014 return (mm->free_area_cache = addr-len);
4015 }
4016 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4017 if (unlikely(mm->mmap_base < len))
4018 goto bottomup;
4019
4020 - addr = mm->mmap_base-len;
4021 - if (do_color_align)
4022 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4023 + addr = mm->mmap_base - len;
4024
4025 do {
4026 + if (do_color_align)
4027 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4028 /*
4029 * Lookup failure means no vma is above this address,
4030 * else if new region fits below vma->vm_start,
4031 * return with success:
4032 */
4033 vma = find_vma(mm, addr);
4034 - if (likely(!vma || addr+len <= vma->vm_start)) {
4035 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4036 /* remember the address as a hint for next time */
4037 return (mm->free_area_cache = addr);
4038 }
4039 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4040 mm->cached_hole_size = vma->vm_start - addr;
4041
4042 /* try just below the current vma->vm_start */
4043 - addr = vma->vm_start-len;
4044 - if (do_color_align)
4045 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4046 - } while (likely(len < vma->vm_start));
4047 + addr = skip_heap_stack_gap(vma, len);
4048 + } while (!IS_ERR_VALUE(addr));
4049
4050 bottomup:
4051 /*
4052 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4053 gap == RLIM_INFINITY ||
4054 sysctl_legacy_va_layout) {
4055 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4056 +
4057 +#ifdef CONFIG_PAX_RANDMMAP
4058 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4059 + mm->mmap_base += mm->delta_mmap;
4060 +#endif
4061 +
4062 mm->get_unmapped_area = arch_get_unmapped_area;
4063 mm->unmap_area = arch_unmap_area;
4064 } else {
4065 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4066 gap = (task_size / 6 * 5);
4067
4068 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4069 +
4070 +#ifdef CONFIG_PAX_RANDMMAP
4071 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4072 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4073 +#endif
4074 +
4075 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4076 mm->unmap_area = arch_unmap_area_topdown;
4077 }
4078 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
4079 index 591f20c..0f1b925 100644
4080 --- a/arch/sparc/kernel/traps_32.c
4081 +++ b/arch/sparc/kernel/traps_32.c
4082 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
4083 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
4084 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
4085
4086 +extern void gr_handle_kernel_exploit(void);
4087 +
4088 void die_if_kernel(char *str, struct pt_regs *regs)
4089 {
4090 static int die_counter;
4091 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4092 count++ < 30 &&
4093 (((unsigned long) rw) >= PAGE_OFFSET) &&
4094 !(((unsigned long) rw) & 0x7)) {
4095 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
4096 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
4097 (void *) rw->ins[7]);
4098 rw = (struct reg_window32 *)rw->ins[6];
4099 }
4100 }
4101 printk("Instruction DUMP:");
4102 instruction_dump ((unsigned long *) regs->pc);
4103 - if(regs->psr & PSR_PS)
4104 + if(regs->psr & PSR_PS) {
4105 + gr_handle_kernel_exploit();
4106 do_exit(SIGKILL);
4107 + }
4108 do_exit(SIGSEGV);
4109 }
4110
4111 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
4112 index 0cbdaa4..438e4c9 100644
4113 --- a/arch/sparc/kernel/traps_64.c
4114 +++ b/arch/sparc/kernel/traps_64.c
4115 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
4116 i + 1,
4117 p->trapstack[i].tstate, p->trapstack[i].tpc,
4118 p->trapstack[i].tnpc, p->trapstack[i].tt);
4119 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
4120 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
4121 }
4122 }
4123
4124 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
4125
4126 lvl -= 0x100;
4127 if (regs->tstate & TSTATE_PRIV) {
4128 +
4129 +#ifdef CONFIG_PAX_REFCOUNT
4130 + if (lvl == 6)
4131 + pax_report_refcount_overflow(regs);
4132 +#endif
4133 +
4134 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
4135 die_if_kernel(buffer, regs);
4136 }
4137 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
4138 void bad_trap_tl1(struct pt_regs *regs, long lvl)
4139 {
4140 char buffer[32];
4141 -
4142 +
4143 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
4144 0, lvl, SIGTRAP) == NOTIFY_STOP)
4145 return;
4146
4147 +#ifdef CONFIG_PAX_REFCOUNT
4148 + if (lvl == 6)
4149 + pax_report_refcount_overflow(regs);
4150 +#endif
4151 +
4152 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
4153
4154 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
4155 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
4156 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
4157 printk("%s" "ERROR(%d): ",
4158 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
4159 - printk("TPC<%pS>\n", (void *) regs->tpc);
4160 + printk("TPC<%pA>\n", (void *) regs->tpc);
4161 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
4162 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
4163 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
4164 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
4165 smp_processor_id(),
4166 (type & 0x1) ? 'I' : 'D',
4167 regs->tpc);
4168 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
4169 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
4170 panic("Irrecoverable Cheetah+ parity error.");
4171 }
4172
4173 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
4174 smp_processor_id(),
4175 (type & 0x1) ? 'I' : 'D',
4176 regs->tpc);
4177 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
4178 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
4179 }
4180
4181 struct sun4v_error_entry {
4182 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
4183
4184 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
4185 regs->tpc, tl);
4186 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
4187 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
4188 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4189 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
4190 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
4191 (void *) regs->u_regs[UREG_I7]);
4192 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
4193 "pte[%lx] error[%lx]\n",
4194 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
4195
4196 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
4197 regs->tpc, tl);
4198 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
4199 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
4200 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4201 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
4202 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
4203 (void *) regs->u_regs[UREG_I7]);
4204 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
4205 "pte[%lx] error[%lx]\n",
4206 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
4207 fp = (unsigned long)sf->fp + STACK_BIAS;
4208 }
4209
4210 - printk(" [%016lx] %pS\n", pc, (void *) pc);
4211 + printk(" [%016lx] %pA\n", pc, (void *) pc);
4212 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4213 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
4214 int index = tsk->curr_ret_stack;
4215 if (tsk->ret_stack && index >= graph) {
4216 pc = tsk->ret_stack[index - graph].ret;
4217 - printk(" [%016lx] %pS\n", pc, (void *) pc);
4218 + printk(" [%016lx] %pA\n", pc, (void *) pc);
4219 graph++;
4220 }
4221 }
4222 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
4223 return (struct reg_window *) (fp + STACK_BIAS);
4224 }
4225
4226 +extern void gr_handle_kernel_exploit(void);
4227 +
4228 void die_if_kernel(char *str, struct pt_regs *regs)
4229 {
4230 static int die_counter;
4231 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4232 while (rw &&
4233 count++ < 30 &&
4234 kstack_valid(tp, (unsigned long) rw)) {
4235 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
4236 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
4237 (void *) rw->ins[7]);
4238
4239 rw = kernel_stack_up(rw);
4240 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4241 }
4242 user_instruction_dump ((unsigned int __user *) regs->tpc);
4243 }
4244 - if (regs->tstate & TSTATE_PRIV)
4245 + if (regs->tstate & TSTATE_PRIV) {
4246 + gr_handle_kernel_exploit();
4247 do_exit(SIGKILL);
4248 + }
4249 do_exit(SIGSEGV);
4250 }
4251 EXPORT_SYMBOL(die_if_kernel);
4252 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
4253 index 76e4ac1..78f8bb1 100644
4254 --- a/arch/sparc/kernel/unaligned_64.c
4255 +++ b/arch/sparc/kernel/unaligned_64.c
4256 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
4257 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
4258
4259 if (__ratelimit(&ratelimit)) {
4260 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
4261 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
4262 regs->tpc, (void *) regs->tpc);
4263 }
4264 }
4265 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
4266 index a3fc437..fea9957 100644
4267 --- a/arch/sparc/lib/Makefile
4268 +++ b/arch/sparc/lib/Makefile
4269 @@ -2,7 +2,7 @@
4270 #
4271
4272 asflags-y := -ansi -DST_DIV0=0x02
4273 -ccflags-y := -Werror
4274 +#ccflags-y := -Werror
4275
4276 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
4277 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
4278 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
4279 index 59186e0..f747d7a 100644
4280 --- a/arch/sparc/lib/atomic_64.S
4281 +++ b/arch/sparc/lib/atomic_64.S
4282 @@ -18,7 +18,12 @@
4283 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4284 BACKOFF_SETUP(%o2)
4285 1: lduw [%o1], %g1
4286 - add %g1, %o0, %g7
4287 + addcc %g1, %o0, %g7
4288 +
4289 +#ifdef CONFIG_PAX_REFCOUNT
4290 + tvs %icc, 6
4291 +#endif
4292 +
4293 cas [%o1], %g1, %g7
4294 cmp %g1, %g7
4295 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4296 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4297 2: BACKOFF_SPIN(%o2, %o3, 1b)
4298 .size atomic_add, .-atomic_add
4299
4300 + .globl atomic_add_unchecked
4301 + .type atomic_add_unchecked,#function
4302 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4303 + BACKOFF_SETUP(%o2)
4304 +1: lduw [%o1], %g1
4305 + add %g1, %o0, %g7
4306 + cas [%o1], %g1, %g7
4307 + cmp %g1, %g7
4308 + bne,pn %icc, 2f
4309 + nop
4310 + retl
4311 + nop
4312 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4313 + .size atomic_add_unchecked, .-atomic_add_unchecked
4314 +
4315 .globl atomic_sub
4316 .type atomic_sub,#function
4317 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4318 BACKOFF_SETUP(%o2)
4319 1: lduw [%o1], %g1
4320 - sub %g1, %o0, %g7
4321 + subcc %g1, %o0, %g7
4322 +
4323 +#ifdef CONFIG_PAX_REFCOUNT
4324 + tvs %icc, 6
4325 +#endif
4326 +
4327 cas [%o1], %g1, %g7
4328 cmp %g1, %g7
4329 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4330 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4331 2: BACKOFF_SPIN(%o2, %o3, 1b)
4332 .size atomic_sub, .-atomic_sub
4333
4334 + .globl atomic_sub_unchecked
4335 + .type atomic_sub_unchecked,#function
4336 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4337 + BACKOFF_SETUP(%o2)
4338 +1: lduw [%o1], %g1
4339 + sub %g1, %o0, %g7
4340 + cas [%o1], %g1, %g7
4341 + cmp %g1, %g7
4342 + bne,pn %icc, 2f
4343 + nop
4344 + retl
4345 + nop
4346 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4347 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
4348 +
4349 .globl atomic_add_ret
4350 .type atomic_add_ret,#function
4351 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4352 BACKOFF_SETUP(%o2)
4353 1: lduw [%o1], %g1
4354 - add %g1, %o0, %g7
4355 + addcc %g1, %o0, %g7
4356 +
4357 +#ifdef CONFIG_PAX_REFCOUNT
4358 + tvs %icc, 6
4359 +#endif
4360 +
4361 cas [%o1], %g1, %g7
4362 cmp %g1, %g7
4363 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4364 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4365 2: BACKOFF_SPIN(%o2, %o3, 1b)
4366 .size atomic_add_ret, .-atomic_add_ret
4367
4368 + .globl atomic_add_ret_unchecked
4369 + .type atomic_add_ret_unchecked,#function
4370 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4371 + BACKOFF_SETUP(%o2)
4372 +1: lduw [%o1], %g1
4373 + addcc %g1, %o0, %g7
4374 + cas [%o1], %g1, %g7
4375 + cmp %g1, %g7
4376 + bne,pn %icc, 2f
4377 + add %g7, %o0, %g7
4378 + sra %g7, 0, %o0
4379 + retl
4380 + nop
4381 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4382 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
4383 +
4384 .globl atomic_sub_ret
4385 .type atomic_sub_ret,#function
4386 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4387 BACKOFF_SETUP(%o2)
4388 1: lduw [%o1], %g1
4389 - sub %g1, %o0, %g7
4390 + subcc %g1, %o0, %g7
4391 +
4392 +#ifdef CONFIG_PAX_REFCOUNT
4393 + tvs %icc, 6
4394 +#endif
4395 +
4396 cas [%o1], %g1, %g7
4397 cmp %g1, %g7
4398 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4399 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4400 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4401 BACKOFF_SETUP(%o2)
4402 1: ldx [%o1], %g1
4403 - add %g1, %o0, %g7
4404 + addcc %g1, %o0, %g7
4405 +
4406 +#ifdef CONFIG_PAX_REFCOUNT
4407 + tvs %xcc, 6
4408 +#endif
4409 +
4410 casx [%o1], %g1, %g7
4411 cmp %g1, %g7
4412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4413 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4414 2: BACKOFF_SPIN(%o2, %o3, 1b)
4415 .size atomic64_add, .-atomic64_add
4416
4417 + .globl atomic64_add_unchecked
4418 + .type atomic64_add_unchecked,#function
4419 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4420 + BACKOFF_SETUP(%o2)
4421 +1: ldx [%o1], %g1
4422 + addcc %g1, %o0, %g7
4423 + casx [%o1], %g1, %g7
4424 + cmp %g1, %g7
4425 + bne,pn %xcc, 2f
4426 + nop
4427 + retl
4428 + nop
4429 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4430 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
4431 +
4432 .globl atomic64_sub
4433 .type atomic64_sub,#function
4434 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4435 BACKOFF_SETUP(%o2)
4436 1: ldx [%o1], %g1
4437 - sub %g1, %o0, %g7
4438 + subcc %g1, %o0, %g7
4439 +
4440 +#ifdef CONFIG_PAX_REFCOUNT
4441 + tvs %xcc, 6
4442 +#endif
4443 +
4444 casx [%o1], %g1, %g7
4445 cmp %g1, %g7
4446 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4447 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4448 2: BACKOFF_SPIN(%o2, %o3, 1b)
4449 .size atomic64_sub, .-atomic64_sub
4450
4451 + .globl atomic64_sub_unchecked
4452 + .type atomic64_sub_unchecked,#function
4453 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4454 + BACKOFF_SETUP(%o2)
4455 +1: ldx [%o1], %g1
4456 + subcc %g1, %o0, %g7
4457 + casx [%o1], %g1, %g7
4458 + cmp %g1, %g7
4459 + bne,pn %xcc, 2f
4460 + nop
4461 + retl
4462 + nop
4463 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4464 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
4465 +
4466 .globl atomic64_add_ret
4467 .type atomic64_add_ret,#function
4468 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4469 BACKOFF_SETUP(%o2)
4470 1: ldx [%o1], %g1
4471 - add %g1, %o0, %g7
4472 + addcc %g1, %o0, %g7
4473 +
4474 +#ifdef CONFIG_PAX_REFCOUNT
4475 + tvs %xcc, 6
4476 +#endif
4477 +
4478 casx [%o1], %g1, %g7
4479 cmp %g1, %g7
4480 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4481 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4482 2: BACKOFF_SPIN(%o2, %o3, 1b)
4483 .size atomic64_add_ret, .-atomic64_add_ret
4484
4485 + .globl atomic64_add_ret_unchecked
4486 + .type atomic64_add_ret_unchecked,#function
4487 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4488 + BACKOFF_SETUP(%o2)
4489 +1: ldx [%o1], %g1
4490 + addcc %g1, %o0, %g7
4491 + casx [%o1], %g1, %g7
4492 + cmp %g1, %g7
4493 + bne,pn %xcc, 2f
4494 + add %g7, %o0, %g7
4495 + mov %g7, %o0
4496 + retl
4497 + nop
4498 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4499 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
4500 +
4501 .globl atomic64_sub_ret
4502 .type atomic64_sub_ret,#function
4503 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4504 BACKOFF_SETUP(%o2)
4505 1: ldx [%o1], %g1
4506 - sub %g1, %o0, %g7
4507 + subcc %g1, %o0, %g7
4508 +
4509 +#ifdef CONFIG_PAX_REFCOUNT
4510 + tvs %xcc, 6
4511 +#endif
4512 +
4513 casx [%o1], %g1, %g7
4514 cmp %g1, %g7
4515 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4516 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
4517 index 1b30bb3..b4a16c7 100644
4518 --- a/arch/sparc/lib/ksyms.c
4519 +++ b/arch/sparc/lib/ksyms.c
4520 @@ -142,12 +142,18 @@ EXPORT_SYMBOL(__downgrade_write);
4521
4522 /* Atomic counter implementation. */
4523 EXPORT_SYMBOL(atomic_add);
4524 +EXPORT_SYMBOL(atomic_add_unchecked);
4525 EXPORT_SYMBOL(atomic_add_ret);
4526 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
4527 EXPORT_SYMBOL(atomic_sub);
4528 +EXPORT_SYMBOL(atomic_sub_unchecked);
4529 EXPORT_SYMBOL(atomic_sub_ret);
4530 EXPORT_SYMBOL(atomic64_add);
4531 +EXPORT_SYMBOL(atomic64_add_unchecked);
4532 EXPORT_SYMBOL(atomic64_add_ret);
4533 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
4534 EXPORT_SYMBOL(atomic64_sub);
4535 +EXPORT_SYMBOL(atomic64_sub_unchecked);
4536 EXPORT_SYMBOL(atomic64_sub_ret);
4537
4538 /* Atomic bit operations. */
4539 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
4540 index 301421c..e2535d1 100644
4541 --- a/arch/sparc/mm/Makefile
4542 +++ b/arch/sparc/mm/Makefile
4543 @@ -2,7 +2,7 @@
4544 #
4545
4546 asflags-y := -ansi
4547 -ccflags-y := -Werror
4548 +#ccflags-y := -Werror
4549
4550 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
4551 obj-y += fault_$(BITS).o
4552 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
4553 index 8023fd7..c8e89e9 100644
4554 --- a/arch/sparc/mm/fault_32.c
4555 +++ b/arch/sparc/mm/fault_32.c
4556 @@ -21,6 +21,9 @@
4557 #include <linux/perf_event.h>
4558 #include <linux/interrupt.h>
4559 #include <linux/kdebug.h>
4560 +#include <linux/slab.h>
4561 +#include <linux/pagemap.h>
4562 +#include <linux/compiler.h>
4563
4564 #include <asm/system.h>
4565 #include <asm/page.h>
4566 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
4567 return safe_compute_effective_address(regs, insn);
4568 }
4569
4570 +#ifdef CONFIG_PAX_PAGEEXEC
4571 +#ifdef CONFIG_PAX_DLRESOLVE
4572 +static void pax_emuplt_close(struct vm_area_struct *vma)
4573 +{
4574 + vma->vm_mm->call_dl_resolve = 0UL;
4575 +}
4576 +
4577 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4578 +{
4579 + unsigned int *kaddr;
4580 +
4581 + vmf->page = alloc_page(GFP_HIGHUSER);
4582 + if (!vmf->page)
4583 + return VM_FAULT_OOM;
4584 +
4585 + kaddr = kmap(vmf->page);
4586 + memset(kaddr, 0, PAGE_SIZE);
4587 + kaddr[0] = 0x9DE3BFA8U; /* save */
4588 + flush_dcache_page(vmf->page);
4589 + kunmap(vmf->page);
4590 + return VM_FAULT_MAJOR;
4591 +}
4592 +
4593 +static const struct vm_operations_struct pax_vm_ops = {
4594 + .close = pax_emuplt_close,
4595 + .fault = pax_emuplt_fault
4596 +};
4597 +
4598 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4599 +{
4600 + int ret;
4601 +
4602 + INIT_LIST_HEAD(&vma->anon_vma_chain);
4603 + vma->vm_mm = current->mm;
4604 + vma->vm_start = addr;
4605 + vma->vm_end = addr + PAGE_SIZE;
4606 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4607 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4608 + vma->vm_ops = &pax_vm_ops;
4609 +
4610 + ret = insert_vm_struct(current->mm, vma);
4611 + if (ret)
4612 + return ret;
4613 +
4614 + ++current->mm->total_vm;
4615 + return 0;
4616 +}
4617 +#endif
4618 +
4619 +/*
4620 + * PaX: decide what to do with offenders (regs->pc = fault address)
4621 + *
4622 + * returns 1 when task should be killed
4623 + * 2 when patched PLT trampoline was detected
4624 + * 3 when unpatched PLT trampoline was detected
4625 + */
4626 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4627 +{
4628 +
4629 +#ifdef CONFIG_PAX_EMUPLT
4630 + int err;
4631 +
4632 + do { /* PaX: patched PLT emulation #1 */
4633 + unsigned int sethi1, sethi2, jmpl;
4634 +
4635 + err = get_user(sethi1, (unsigned int *)regs->pc);
4636 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
4637 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
4638 +
4639 + if (err)
4640 + break;
4641 +
4642 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4643 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
4644 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
4645 + {
4646 + unsigned int addr;
4647 +
4648 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4649 + addr = regs->u_regs[UREG_G1];
4650 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4651 + regs->pc = addr;
4652 + regs->npc = addr+4;
4653 + return 2;
4654 + }
4655 + } while (0);
4656 +
4657 + { /* PaX: patched PLT emulation #2 */
4658 + unsigned int ba;
4659 +
4660 + err = get_user(ba, (unsigned int *)regs->pc);
4661 +
4662 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4663 + unsigned int addr;
4664 +
4665 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4666 + regs->pc = addr;
4667 + regs->npc = addr+4;
4668 + return 2;
4669 + }
4670 + }
4671 +
4672 + do { /* PaX: patched PLT emulation #3 */
4673 + unsigned int sethi, jmpl, nop;
4674 +
4675 + err = get_user(sethi, (unsigned int *)regs->pc);
4676 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
4677 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
4678 +
4679 + if (err)
4680 + break;
4681 +
4682 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
4683 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
4684 + nop == 0x01000000U)
4685 + {
4686 + unsigned int addr;
4687 +
4688 + addr = (sethi & 0x003FFFFFU) << 10;
4689 + regs->u_regs[UREG_G1] = addr;
4690 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4691 + regs->pc = addr;
4692 + regs->npc = addr+4;
4693 + return 2;
4694 + }
4695 + } while (0);
4696 +
4697 + do { /* PaX: unpatched PLT emulation step 1 */
4698 + unsigned int sethi, ba, nop;
4699 +
4700 + err = get_user(sethi, (unsigned int *)regs->pc);
4701 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
4702 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
4703 +
4704 + if (err)
4705 + break;
4706 +
4707 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
4708 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
4709 + nop == 0x01000000U)
4710 + {
4711 + unsigned int addr, save, call;
4712 +
4713 + if ((ba & 0xFFC00000U) == 0x30800000U)
4714 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4715 + else
4716 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
4717 +
4718 + err = get_user(save, (unsigned int *)addr);
4719 + err |= get_user(call, (unsigned int *)(addr+4));
4720 + err |= get_user(nop, (unsigned int *)(addr+8));
4721 + if (err)
4722 + break;
4723 +
4724 +#ifdef CONFIG_PAX_DLRESOLVE
4725 + if (save == 0x9DE3BFA8U &&
4726 + (call & 0xC0000000U) == 0x40000000U &&
4727 + nop == 0x01000000U)
4728 + {
4729 + struct vm_area_struct *vma;
4730 + unsigned long call_dl_resolve;
4731 +
4732 + down_read(&current->mm->mmap_sem);
4733 + call_dl_resolve = current->mm->call_dl_resolve;
4734 + up_read(&current->mm->mmap_sem);
4735 + if (likely(call_dl_resolve))
4736 + goto emulate;
4737 +
4738 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
4739 +
4740 + down_write(&current->mm->mmap_sem);
4741 + if (current->mm->call_dl_resolve) {
4742 + call_dl_resolve = current->mm->call_dl_resolve;
4743 + up_write(&current->mm->mmap_sem);
4744 + if (vma)
4745 + kmem_cache_free(vm_area_cachep, vma);
4746 + goto emulate;
4747 + }
4748 +
4749 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4750 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4751 + up_write(&current->mm->mmap_sem);
4752 + if (vma)
4753 + kmem_cache_free(vm_area_cachep, vma);
4754 + return 1;
4755 + }
4756 +
4757 + if (pax_insert_vma(vma, call_dl_resolve)) {
4758 + up_write(&current->mm->mmap_sem);
4759 + kmem_cache_free(vm_area_cachep, vma);
4760 + return 1;
4761 + }
4762 +
4763 + current->mm->call_dl_resolve = call_dl_resolve;
4764 + up_write(&current->mm->mmap_sem);
4765 +
4766 +emulate:
4767 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4768 + regs->pc = call_dl_resolve;
4769 + regs->npc = addr+4;
4770 + return 3;
4771 + }
4772 +#endif
4773 +
4774 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
4775 + if ((save & 0xFFC00000U) == 0x05000000U &&
4776 + (call & 0xFFFFE000U) == 0x85C0A000U &&
4777 + nop == 0x01000000U)
4778 + {
4779 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4780 + regs->u_regs[UREG_G2] = addr + 4;
4781 + addr = (save & 0x003FFFFFU) << 10;
4782 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4783 + regs->pc = addr;
4784 + regs->npc = addr+4;
4785 + return 3;
4786 + }
4787 + }
4788 + } while (0);
4789 +
4790 + do { /* PaX: unpatched PLT emulation step 2 */
4791 + unsigned int save, call, nop;
4792 +
4793 + err = get_user(save, (unsigned int *)(regs->pc-4));
4794 + err |= get_user(call, (unsigned int *)regs->pc);
4795 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
4796 + if (err)
4797 + break;
4798 +
4799 + if (save == 0x9DE3BFA8U &&
4800 + (call & 0xC0000000U) == 0x40000000U &&
4801 + nop == 0x01000000U)
4802 + {
4803 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
4804 +
4805 + regs->u_regs[UREG_RETPC] = regs->pc;
4806 + regs->pc = dl_resolve;
4807 + regs->npc = dl_resolve+4;
4808 + return 3;
4809 + }
4810 + } while (0);
4811 +#endif
4812 +
4813 + return 1;
4814 +}
4815 +
4816 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4817 +{
4818 + unsigned long i;
4819 +
4820 + printk(KERN_ERR "PAX: bytes at PC: ");
4821 + for (i = 0; i < 8; i++) {
4822 + unsigned int c;
4823 + if (get_user(c, (unsigned int *)pc+i))
4824 + printk(KERN_CONT "???????? ");
4825 + else
4826 + printk(KERN_CONT "%08x ", c);
4827 + }
4828 + printk("\n");
4829 +}
4830 +#endif
4831 +
4832 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
4833 int text_fault)
4834 {
4835 @@ -280,6 +545,24 @@ good_area:
4836 if(!(vma->vm_flags & VM_WRITE))
4837 goto bad_area;
4838 } else {
4839 +
4840 +#ifdef CONFIG_PAX_PAGEEXEC
4841 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
4842 + up_read(&mm->mmap_sem);
4843 + switch (pax_handle_fetch_fault(regs)) {
4844 +
4845 +#ifdef CONFIG_PAX_EMUPLT
4846 + case 2:
4847 + case 3:
4848 + return;
4849 +#endif
4850 +
4851 + }
4852 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
4853 + do_group_exit(SIGKILL);
4854 + }
4855 +#endif
4856 +
4857 /* Allow reads even for write-only mappings */
4858 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
4859 goto bad_area;
4860 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
4861 index 504c062..6fcb9c6 100644
4862 --- a/arch/sparc/mm/fault_64.c
4863 +++ b/arch/sparc/mm/fault_64.c
4864 @@ -21,6 +21,9 @@
4865 #include <linux/kprobes.h>
4866 #include <linux/kdebug.h>
4867 #include <linux/percpu.h>
4868 +#include <linux/slab.h>
4869 +#include <linux/pagemap.h>
4870 +#include <linux/compiler.h>
4871
4872 #include <asm/page.h>
4873 #include <asm/pgtable.h>
4874 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
4875 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
4876 regs->tpc);
4877 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
4878 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
4879 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
4880 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
4881 dump_stack();
4882 unhandled_fault(regs->tpc, current, regs);
4883 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
4884 show_regs(regs);
4885 }
4886
4887 +#ifdef CONFIG_PAX_PAGEEXEC
4888 +#ifdef CONFIG_PAX_DLRESOLVE
4889 +static void pax_emuplt_close(struct vm_area_struct *vma)
4890 +{
4891 + vma->vm_mm->call_dl_resolve = 0UL;
4892 +}
4893 +
4894 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4895 +{
4896 + unsigned int *kaddr;
4897 +
4898 + vmf->page = alloc_page(GFP_HIGHUSER);
4899 + if (!vmf->page)
4900 + return VM_FAULT_OOM;
4901 +
4902 + kaddr = kmap(vmf->page);
4903 + memset(kaddr, 0, PAGE_SIZE);
4904 + kaddr[0] = 0x9DE3BFA8U; /* save */
4905 + flush_dcache_page(vmf->page);
4906 + kunmap(vmf->page);
4907 + return VM_FAULT_MAJOR;
4908 +}
4909 +
4910 +static const struct vm_operations_struct pax_vm_ops = {
4911 + .close = pax_emuplt_close,
4912 + .fault = pax_emuplt_fault
4913 +};
4914 +
4915 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4916 +{
4917 + int ret;
4918 +
4919 + INIT_LIST_HEAD(&vma->anon_vma_chain);
4920 + vma->vm_mm = current->mm;
4921 + vma->vm_start = addr;
4922 + vma->vm_end = addr + PAGE_SIZE;
4923 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4924 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4925 + vma->vm_ops = &pax_vm_ops;
4926 +
4927 + ret = insert_vm_struct(current->mm, vma);
4928 + if (ret)
4929 + return ret;
4930 +
4931 + ++current->mm->total_vm;
4932 + return 0;
4933 +}
4934 +#endif
4935 +
4936 +/*
4937 + * PaX: decide what to do with offenders (regs->tpc = fault address)
4938 + *
4939 + * returns 1 when task should be killed
4940 + * 2 when patched PLT trampoline was detected
4941 + * 3 when unpatched PLT trampoline was detected
4942 + */
4943 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4944 +{
4945 +
4946 +#ifdef CONFIG_PAX_EMUPLT
4947 + int err;
4948 +
4949 + do { /* PaX: patched PLT emulation #1 */
4950 + unsigned int sethi1, sethi2, jmpl;
4951 +
4952 + err = get_user(sethi1, (unsigned int *)regs->tpc);
4953 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
4954 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
4955 +
4956 + if (err)
4957 + break;
4958 +
4959 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4960 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
4961 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
4962 + {
4963 + unsigned long addr;
4964 +
4965 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4966 + addr = regs->u_regs[UREG_G1];
4967 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
4968 +
4969 + if (test_thread_flag(TIF_32BIT))
4970 + addr &= 0xFFFFFFFFUL;
4971 +
4972 + regs->tpc = addr;
4973 + regs->tnpc = addr+4;
4974 + return 2;
4975 + }
4976 + } while (0);
4977 +
4978 + { /* PaX: patched PLT emulation #2 */
4979 + unsigned int ba;
4980 +
4981 + err = get_user(ba, (unsigned int *)regs->tpc);
4982 +
4983 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4984 + unsigned long addr;
4985 +
4986 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
4987 +
4988 + if (test_thread_flag(TIF_32BIT))
4989 + addr &= 0xFFFFFFFFUL;
4990 +
4991 + regs->tpc = addr;
4992 + regs->tnpc = addr+4;
4993 + return 2;
4994 + }
4995 + }
4996 +
4997 + do { /* PaX: patched PLT emulation #3 */
4998 + unsigned int sethi, jmpl, nop;
4999 +
5000 + err = get_user(sethi, (unsigned int *)regs->tpc);
5001 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
5002 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5003 +
5004 + if (err)
5005 + break;
5006 +
5007 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5008 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5009 + nop == 0x01000000U)
5010 + {
5011 + unsigned long addr;
5012 +
5013 + addr = (sethi & 0x003FFFFFU) << 10;
5014 + regs->u_regs[UREG_G1] = addr;
5015 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5016 +
5017 + if (test_thread_flag(TIF_32BIT))
5018 + addr &= 0xFFFFFFFFUL;
5019 +
5020 + regs->tpc = addr;
5021 + regs->tnpc = addr+4;
5022 + return 2;
5023 + }
5024 + } while (0);
5025 +
5026 + do { /* PaX: patched PLT emulation #4 */
5027 + unsigned int sethi, mov1, call, mov2;
5028 +
5029 + err = get_user(sethi, (unsigned int *)regs->tpc);
5030 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
5031 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
5032 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
5033 +
5034 + if (err)
5035 + break;
5036 +
5037 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5038 + mov1 == 0x8210000FU &&
5039 + (call & 0xC0000000U) == 0x40000000U &&
5040 + mov2 == 0x9E100001U)
5041 + {
5042 + unsigned long addr;
5043 +
5044 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
5045 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5046 +
5047 + if (test_thread_flag(TIF_32BIT))
5048 + addr &= 0xFFFFFFFFUL;
5049 +
5050 + regs->tpc = addr;
5051 + regs->tnpc = addr+4;
5052 + return 2;
5053 + }
5054 + } while (0);
5055 +
5056 + do { /* PaX: patched PLT emulation #5 */
5057 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
5058 +
5059 + err = get_user(sethi, (unsigned int *)regs->tpc);
5060 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5061 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5062 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
5063 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
5064 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
5065 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
5066 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
5067 +
5068 + if (err)
5069 + break;
5070 +
5071 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5072 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
5073 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5074 + (or1 & 0xFFFFE000U) == 0x82106000U &&
5075 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
5076 + sllx == 0x83287020U &&
5077 + jmpl == 0x81C04005U &&
5078 + nop == 0x01000000U)
5079 + {
5080 + unsigned long addr;
5081 +
5082 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5083 + regs->u_regs[UREG_G1] <<= 32;
5084 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5085 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5086 + regs->tpc = addr;
5087 + regs->tnpc = addr+4;
5088 + return 2;
5089 + }
5090 + } while (0);
5091 +
5092 + do { /* PaX: patched PLT emulation #6 */
5093 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
5094 +
5095 + err = get_user(sethi, (unsigned int *)regs->tpc);
5096 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5097 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5098 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
5099 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
5100 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
5101 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
5102 +
5103 + if (err)
5104 + break;
5105 +
5106 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5107 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
5108 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5109 + sllx == 0x83287020U &&
5110 + (or & 0xFFFFE000U) == 0x8A116000U &&
5111 + jmpl == 0x81C04005U &&
5112 + nop == 0x01000000U)
5113 + {
5114 + unsigned long addr;
5115 +
5116 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
5117 + regs->u_regs[UREG_G1] <<= 32;
5118 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
5119 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5120 + regs->tpc = addr;
5121 + regs->tnpc = addr+4;
5122 + return 2;
5123 + }
5124 + } while (0);
5125 +
5126 + do { /* PaX: unpatched PLT emulation step 1 */
5127 + unsigned int sethi, ba, nop;
5128 +
5129 + err = get_user(sethi, (unsigned int *)regs->tpc);
5130 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5131 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5132 +
5133 + if (err)
5134 + break;
5135 +
5136 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5137 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5138 + nop == 0x01000000U)
5139 + {
5140 + unsigned long addr;
5141 + unsigned int save, call;
5142 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
5143 +
5144 + if ((ba & 0xFFC00000U) == 0x30800000U)
5145 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5146 + else
5147 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5148 +
5149 + if (test_thread_flag(TIF_32BIT))
5150 + addr &= 0xFFFFFFFFUL;
5151 +
5152 + err = get_user(save, (unsigned int *)addr);
5153 + err |= get_user(call, (unsigned int *)(addr+4));
5154 + err |= get_user(nop, (unsigned int *)(addr+8));
5155 + if (err)
5156 + break;
5157 +
5158 +#ifdef CONFIG_PAX_DLRESOLVE
5159 + if (save == 0x9DE3BFA8U &&
5160 + (call & 0xC0000000U) == 0x40000000U &&
5161 + nop == 0x01000000U)
5162 + {
5163 + struct vm_area_struct *vma;
5164 + unsigned long call_dl_resolve;
5165 +
5166 + down_read(&current->mm->mmap_sem);
5167 + call_dl_resolve = current->mm->call_dl_resolve;
5168 + up_read(&current->mm->mmap_sem);
5169 + if (likely(call_dl_resolve))
5170 + goto emulate;
5171 +
5172 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5173 +
5174 + down_write(&current->mm->mmap_sem);
5175 + if (current->mm->call_dl_resolve) {
5176 + call_dl_resolve = current->mm->call_dl_resolve;
5177 + up_write(&current->mm->mmap_sem);
5178 + if (vma)
5179 + kmem_cache_free(vm_area_cachep, vma);
5180 + goto emulate;
5181 + }
5182 +
5183 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5184 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5185 + up_write(&current->mm->mmap_sem);
5186 + if (vma)
5187 + kmem_cache_free(vm_area_cachep, vma);
5188 + return 1;
5189 + }
5190 +
5191 + if (pax_insert_vma(vma, call_dl_resolve)) {
5192 + up_write(&current->mm->mmap_sem);
5193 + kmem_cache_free(vm_area_cachep, vma);
5194 + return 1;
5195 + }
5196 +
5197 + current->mm->call_dl_resolve = call_dl_resolve;
5198 + up_write(&current->mm->mmap_sem);
5199 +
5200 +emulate:
5201 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5202 + regs->tpc = call_dl_resolve;
5203 + regs->tnpc = addr+4;
5204 + return 3;
5205 + }
5206 +#endif
5207 +
5208 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5209 + if ((save & 0xFFC00000U) == 0x05000000U &&
5210 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5211 + nop == 0x01000000U)
5212 + {
5213 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5214 + regs->u_regs[UREG_G2] = addr + 4;
5215 + addr = (save & 0x003FFFFFU) << 10;
5216 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5217 +
5218 + if (test_thread_flag(TIF_32BIT))
5219 + addr &= 0xFFFFFFFFUL;
5220 +
5221 + regs->tpc = addr;
5222 + regs->tnpc = addr+4;
5223 + return 3;
5224 + }
5225 +
5226 + /* PaX: 64-bit PLT stub */
5227 + err = get_user(sethi1, (unsigned int *)addr);
5228 + err |= get_user(sethi2, (unsigned int *)(addr+4));
5229 + err |= get_user(or1, (unsigned int *)(addr+8));
5230 + err |= get_user(or2, (unsigned int *)(addr+12));
5231 + err |= get_user(sllx, (unsigned int *)(addr+16));
5232 + err |= get_user(add, (unsigned int *)(addr+20));
5233 + err |= get_user(jmpl, (unsigned int *)(addr+24));
5234 + err |= get_user(nop, (unsigned int *)(addr+28));
5235 + if (err)
5236 + break;
5237 +
5238 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
5239 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5240 + (or1 & 0xFFFFE000U) == 0x88112000U &&
5241 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
5242 + sllx == 0x89293020U &&
5243 + add == 0x8A010005U &&
5244 + jmpl == 0x89C14000U &&
5245 + nop == 0x01000000U)
5246 + {
5247 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5248 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5249 + regs->u_regs[UREG_G4] <<= 32;
5250 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5251 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
5252 + regs->u_regs[UREG_G4] = addr + 24;
5253 + addr = regs->u_regs[UREG_G5];
5254 + regs->tpc = addr;
5255 + regs->tnpc = addr+4;
5256 + return 3;
5257 + }
5258 + }
5259 + } while (0);
5260 +
5261 +#ifdef CONFIG_PAX_DLRESOLVE
5262 + do { /* PaX: unpatched PLT emulation step 2 */
5263 + unsigned int save, call, nop;
5264 +
5265 + err = get_user(save, (unsigned int *)(regs->tpc-4));
5266 + err |= get_user(call, (unsigned int *)regs->tpc);
5267 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
5268 + if (err)
5269 + break;
5270 +
5271 + if (save == 0x9DE3BFA8U &&
5272 + (call & 0xC0000000U) == 0x40000000U &&
5273 + nop == 0x01000000U)
5274 + {
5275 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5276 +
5277 + if (test_thread_flag(TIF_32BIT))
5278 + dl_resolve &= 0xFFFFFFFFUL;
5279 +
5280 + regs->u_regs[UREG_RETPC] = regs->tpc;
5281 + regs->tpc = dl_resolve;
5282 + regs->tnpc = dl_resolve+4;
5283 + return 3;
5284 + }
5285 + } while (0);
5286 +#endif
5287 +
5288 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
5289 + unsigned int sethi, ba, nop;
5290 +
5291 + err = get_user(sethi, (unsigned int *)regs->tpc);
5292 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5293 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5294 +
5295 + if (err)
5296 + break;
5297 +
5298 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5299 + (ba & 0xFFF00000U) == 0x30600000U &&
5300 + nop == 0x01000000U)
5301 + {
5302 + unsigned long addr;
5303 +
5304 + addr = (sethi & 0x003FFFFFU) << 10;
5305 + regs->u_regs[UREG_G1] = addr;
5306 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5307 +
5308 + if (test_thread_flag(TIF_32BIT))
5309 + addr &= 0xFFFFFFFFUL;
5310 +
5311 + regs->tpc = addr;
5312 + regs->tnpc = addr+4;
5313 + return 2;
5314 + }
5315 + } while (0);
5316 +
5317 +#endif
5318 +
5319 + return 1;
5320 +}
5321 +
5322 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5323 +{
5324 + unsigned long i;
5325 +
5326 + printk(KERN_ERR "PAX: bytes at PC: ");
5327 + for (i = 0; i < 8; i++) {
5328 + unsigned int c;
5329 + if (get_user(c, (unsigned int *)pc+i))
5330 + printk(KERN_CONT "???????? ");
5331 + else
5332 + printk(KERN_CONT "%08x ", c);
5333 + }
5334 + printk("\n");
5335 +}
5336 +#endif
5337 +
5338 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5339 {
5340 struct mm_struct *mm = current->mm;
5341 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5342 if (!vma)
5343 goto bad_area;
5344
5345 +#ifdef CONFIG_PAX_PAGEEXEC
5346 + /* PaX: detect ITLB misses on non-exec pages */
5347 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
5348 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
5349 + {
5350 + if (address != regs->tpc)
5351 + goto good_area;
5352 +
5353 + up_read(&mm->mmap_sem);
5354 + switch (pax_handle_fetch_fault(regs)) {
5355 +
5356 +#ifdef CONFIG_PAX_EMUPLT
5357 + case 2:
5358 + case 3:
5359 + return;
5360 +#endif
5361 +
5362 + }
5363 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
5364 + do_group_exit(SIGKILL);
5365 + }
5366 +#endif
5367 +
5368 /* Pure DTLB misses do not tell us whether the fault causing
5369 * load/store/atomic was a write or not, it only says that there
5370 * was no match. So in such a case we (carefully) read the
5371 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
5372 index 07e1453..0a7d9e9 100644
5373 --- a/arch/sparc/mm/hugetlbpage.c
5374 +++ b/arch/sparc/mm/hugetlbpage.c
5375 @@ -67,7 +67,7 @@ full_search:
5376 }
5377 return -ENOMEM;
5378 }
5379 - if (likely(!vma || addr + len <= vma->vm_start)) {
5380 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5381 /*
5382 * Remember the place where we stopped the search:
5383 */
5384 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5385 /* make sure it can fit in the remaining address space */
5386 if (likely(addr > len)) {
5387 vma = find_vma(mm, addr-len);
5388 - if (!vma || addr <= vma->vm_start) {
5389 + if (check_heap_stack_gap(vma, addr - len, len)) {
5390 /* remember the address as a hint for next time */
5391 return (mm->free_area_cache = addr-len);
5392 }
5393 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5394 if (unlikely(mm->mmap_base < len))
5395 goto bottomup;
5396
5397 - addr = (mm->mmap_base-len) & HPAGE_MASK;
5398 + addr = mm->mmap_base - len;
5399
5400 do {
5401 + addr &= HPAGE_MASK;
5402 /*
5403 * Lookup failure means no vma is above this address,
5404 * else if new region fits below vma->vm_start,
5405 * return with success:
5406 */
5407 vma = find_vma(mm, addr);
5408 - if (likely(!vma || addr+len <= vma->vm_start)) {
5409 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5410 /* remember the address as a hint for next time */
5411 return (mm->free_area_cache = addr);
5412 }
5413 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5414 mm->cached_hole_size = vma->vm_start - addr;
5415
5416 /* try just below the current vma->vm_start */
5417 - addr = (vma->vm_start-len) & HPAGE_MASK;
5418 - } while (likely(len < vma->vm_start));
5419 + addr = skip_heap_stack_gap(vma, len);
5420 + } while (!IS_ERR_VALUE(addr));
5421
5422 bottomup:
5423 /*
5424 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
5425 if (addr) {
5426 addr = ALIGN(addr, HPAGE_SIZE);
5427 vma = find_vma(mm, addr);
5428 - if (task_size - len >= addr &&
5429 - (!vma || addr + len <= vma->vm_start))
5430 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5431 return addr;
5432 }
5433 if (mm->get_unmapped_area == arch_get_unmapped_area)
5434 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
5435 index 7b00de6..78239f4 100644
5436 --- a/arch/sparc/mm/init_32.c
5437 +++ b/arch/sparc/mm/init_32.c
5438 @@ -316,6 +316,9 @@ extern void device_scan(void);
5439 pgprot_t PAGE_SHARED __read_mostly;
5440 EXPORT_SYMBOL(PAGE_SHARED);
5441
5442 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
5443 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
5444 +
5445 void __init paging_init(void)
5446 {
5447 switch(sparc_cpu_model) {
5448 @@ -344,17 +347,17 @@ void __init paging_init(void)
5449
5450 /* Initialize the protection map with non-constant, MMU dependent values. */
5451 protection_map[0] = PAGE_NONE;
5452 - protection_map[1] = PAGE_READONLY;
5453 - protection_map[2] = PAGE_COPY;
5454 - protection_map[3] = PAGE_COPY;
5455 + protection_map[1] = PAGE_READONLY_NOEXEC;
5456 + protection_map[2] = PAGE_COPY_NOEXEC;
5457 + protection_map[3] = PAGE_COPY_NOEXEC;
5458 protection_map[4] = PAGE_READONLY;
5459 protection_map[5] = PAGE_READONLY;
5460 protection_map[6] = PAGE_COPY;
5461 protection_map[7] = PAGE_COPY;
5462 protection_map[8] = PAGE_NONE;
5463 - protection_map[9] = PAGE_READONLY;
5464 - protection_map[10] = PAGE_SHARED;
5465 - protection_map[11] = PAGE_SHARED;
5466 + protection_map[9] = PAGE_READONLY_NOEXEC;
5467 + protection_map[10] = PAGE_SHARED_NOEXEC;
5468 + protection_map[11] = PAGE_SHARED_NOEXEC;
5469 protection_map[12] = PAGE_READONLY;
5470 protection_map[13] = PAGE_READONLY;
5471 protection_map[14] = PAGE_SHARED;
5472 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
5473 index cbef74e..c38fead 100644
5474 --- a/arch/sparc/mm/srmmu.c
5475 +++ b/arch/sparc/mm/srmmu.c
5476 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
5477 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
5478 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
5479 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
5480 +
5481 +#ifdef CONFIG_PAX_PAGEEXEC
5482 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
5483 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
5484 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
5485 +#endif
5486 +
5487 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
5488 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
5489
5490 diff --git a/arch/um/Makefile b/arch/um/Makefile
5491 index 7730af6..cce5b19 100644
5492 --- a/arch/um/Makefile
5493 +++ b/arch/um/Makefile
5494 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
5495 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
5496 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
5497
5498 +ifdef CONSTIFY_PLUGIN
5499 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5500 +endif
5501 +
5502 #This will adjust *FLAGS accordingly to the platform.
5503 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
5504
5505 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
5506 index 6c03acd..a5e0215 100644
5507 --- a/arch/um/include/asm/kmap_types.h
5508 +++ b/arch/um/include/asm/kmap_types.h
5509 @@ -23,6 +23,7 @@ enum km_type {
5510 KM_IRQ1,
5511 KM_SOFTIRQ0,
5512 KM_SOFTIRQ1,
5513 + KM_CLEARPAGE,
5514 KM_TYPE_NR
5515 };
5516
5517 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
5518 index 7cfc3ce..cbd1a58 100644
5519 --- a/arch/um/include/asm/page.h
5520 +++ b/arch/um/include/asm/page.h
5521 @@ -14,6 +14,9 @@
5522 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
5523 #define PAGE_MASK (~(PAGE_SIZE-1))
5524
5525 +#define ktla_ktva(addr) (addr)
5526 +#define ktva_ktla(addr) (addr)
5527 +
5528 #ifndef __ASSEMBLY__
5529
5530 struct page;
5531 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
5532 index c533835..84db18e 100644
5533 --- a/arch/um/kernel/process.c
5534 +++ b/arch/um/kernel/process.c
5535 @@ -406,22 +406,6 @@ int singlestepping(void * t)
5536 return 2;
5537 }
5538
5539 -/*
5540 - * Only x86 and x86_64 have an arch_align_stack().
5541 - * All other arches have "#define arch_align_stack(x) (x)"
5542 - * in their asm/system.h
5543 - * As this is included in UML from asm-um/system-generic.h,
5544 - * we can use it to behave as the subarch does.
5545 - */
5546 -#ifndef arch_align_stack
5547 -unsigned long arch_align_stack(unsigned long sp)
5548 -{
5549 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5550 - sp -= get_random_int() % 8192;
5551 - return sp & ~0xf;
5552 -}
5553 -#endif
5554 -
5555 unsigned long get_wchan(struct task_struct *p)
5556 {
5557 unsigned long stack_page, sp, ip;
5558 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
5559 index efb4294..61bc18c 100644
5560 --- a/arch/x86/Kconfig
5561 +++ b/arch/x86/Kconfig
5562 @@ -235,7 +235,7 @@ config X86_HT
5563
5564 config X86_32_LAZY_GS
5565 def_bool y
5566 - depends on X86_32 && !CC_STACKPROTECTOR
5567 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
5568
5569 config ARCH_HWEIGHT_CFLAGS
5570 string
5571 @@ -1022,7 +1022,7 @@ choice
5572
5573 config NOHIGHMEM
5574 bool "off"
5575 - depends on !X86_NUMAQ
5576 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
5577 ---help---
5578 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
5579 However, the address space of 32-bit x86 processors is only 4
5580 @@ -1059,7 +1059,7 @@ config NOHIGHMEM
5581
5582 config HIGHMEM4G
5583 bool "4GB"
5584 - depends on !X86_NUMAQ
5585 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
5586 ---help---
5587 Select this if you have a 32-bit processor and between 1 and 4
5588 gigabytes of physical RAM.
5589 @@ -1113,7 +1113,7 @@ config PAGE_OFFSET
5590 hex
5591 default 0xB0000000 if VMSPLIT_3G_OPT
5592 default 0x80000000 if VMSPLIT_2G
5593 - default 0x78000000 if VMSPLIT_2G_OPT
5594 + default 0x70000000 if VMSPLIT_2G_OPT
5595 default 0x40000000 if VMSPLIT_1G
5596 default 0xC0000000
5597 depends on X86_32
5598 @@ -1496,6 +1496,7 @@ config SECCOMP
5599
5600 config CC_STACKPROTECTOR
5601 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
5602 + depends on X86_64 || !PAX_MEMORY_UDEREF
5603 ---help---
5604 This option turns on the -fstack-protector GCC feature. This
5605 feature puts, at the beginning of functions, a canary value on
5606 @@ -1553,6 +1554,7 @@ config KEXEC_JUMP
5607 config PHYSICAL_START
5608 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
5609 default "0x1000000"
5610 + range 0x400000 0x40000000
5611 ---help---
5612 This gives the physical address where the kernel is loaded.
5613
5614 @@ -1616,6 +1618,7 @@ config X86_NEED_RELOCS
5615 config PHYSICAL_ALIGN
5616 hex "Alignment value to which kernel should be aligned" if X86_32
5617 default "0x1000000"
5618 + range 0x400000 0x1000000 if PAX_KERNEXEC
5619 range 0x2000 0x1000000
5620 ---help---
5621 This value puts the alignment restrictions on physical address
5622 @@ -1647,9 +1650,10 @@ config HOTPLUG_CPU
5623 Say N if you want to disable CPU hotplug.
5624
5625 config COMPAT_VDSO
5626 - def_bool y
5627 + def_bool n
5628 prompt "Compat VDSO support"
5629 depends on X86_32 || IA32_EMULATION
5630 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
5631 ---help---
5632 Map the 32-bit VDSO to the predictable old-style address too.
5633
5634 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
5635 index e3ca7e0..b30b28a 100644
5636 --- a/arch/x86/Kconfig.cpu
5637 +++ b/arch/x86/Kconfig.cpu
5638 @@ -341,7 +341,7 @@ config X86_PPRO_FENCE
5639
5640 config X86_F00F_BUG
5641 def_bool y
5642 - depends on M586MMX || M586TSC || M586 || M486 || M386
5643 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
5644
5645 config X86_INVD_BUG
5646 def_bool y
5647 @@ -365,7 +365,7 @@ config X86_POPAD_OK
5648
5649 config X86_ALIGNMENT_16
5650 def_bool y
5651 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
5652 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
5653
5654 config X86_INTEL_USERCOPY
5655 def_bool y
5656 @@ -411,7 +411,7 @@ config X86_CMPXCHG64
5657 # generates cmov.
5658 config X86_CMOV
5659 def_bool y
5660 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
5661 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
5662
5663 config X86_MINIMUM_CPU_FAMILY
5664 int
5665 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
5666 index bf56e17..05f9891 100644
5667 --- a/arch/x86/Kconfig.debug
5668 +++ b/arch/x86/Kconfig.debug
5669 @@ -81,7 +81,7 @@ config X86_PTDUMP
5670 config DEBUG_RODATA
5671 bool "Write protect kernel read-only data structures"
5672 default y
5673 - depends on DEBUG_KERNEL
5674 + depends on DEBUG_KERNEL && BROKEN
5675 ---help---
5676 Mark the kernel read-only data as write-protected in the pagetables,
5677 in order to catch accidental (and incorrect) writes to such const
5678 @@ -99,7 +99,7 @@ config DEBUG_RODATA_TEST
5679
5680 config DEBUG_SET_MODULE_RONX
5681 bool "Set loadable kernel module data as NX and text as RO"
5682 - depends on MODULES
5683 + depends on MODULES && BROKEN
5684 ---help---
5685 This option helps catch unintended modifications to loadable
5686 kernel module's text and read-only data. It also prevents execution
5687 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
5688 index b02e509..2631e48 100644
5689 --- a/arch/x86/Makefile
5690 +++ b/arch/x86/Makefile
5691 @@ -46,6 +46,7 @@ else
5692 UTS_MACHINE := x86_64
5693 CHECKFLAGS += -D__x86_64__ -m64
5694
5695 + biarch := $(call cc-option,-m64)
5696 KBUILD_AFLAGS += -m64
5697 KBUILD_CFLAGS += -m64
5698
5699 @@ -195,3 +196,12 @@ define archhelp
5700 echo ' FDARGS="..." arguments for the booted kernel'
5701 echo ' FDINITRD=file initrd for the booted kernel'
5702 endef
5703 +
5704 +define OLD_LD
5705 +
5706 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
5707 +*** Please upgrade your binutils to 2.18 or newer
5708 +endef
5709 +
5710 +archprepare:
5711 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
5712 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
5713 index 95365a8..52f857b 100644
5714 --- a/arch/x86/boot/Makefile
5715 +++ b/arch/x86/boot/Makefile
5716 @@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
5717 $(call cc-option, -fno-stack-protector) \
5718 $(call cc-option, -mpreferred-stack-boundary=2)
5719 KBUILD_CFLAGS += $(call cc-option, -m32)
5720 +ifdef CONSTIFY_PLUGIN
5721 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5722 +endif
5723 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5724 GCOV_PROFILE := n
5725
5726 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
5727 index 878e4b9..20537ab 100644
5728 --- a/arch/x86/boot/bitops.h
5729 +++ b/arch/x86/boot/bitops.h
5730 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
5731 u8 v;
5732 const u32 *p = (const u32 *)addr;
5733
5734 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5735 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5736 return v;
5737 }
5738
5739 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
5740
5741 static inline void set_bit(int nr, void *addr)
5742 {
5743 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5744 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5745 }
5746
5747 #endif /* BOOT_BITOPS_H */
5748 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
5749 index c7093bd..d4247ffe0 100644
5750 --- a/arch/x86/boot/boot.h
5751 +++ b/arch/x86/boot/boot.h
5752 @@ -85,7 +85,7 @@ static inline void io_delay(void)
5753 static inline u16 ds(void)
5754 {
5755 u16 seg;
5756 - asm("movw %%ds,%0" : "=rm" (seg));
5757 + asm volatile("movw %%ds,%0" : "=rm" (seg));
5758 return seg;
5759 }
5760
5761 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
5762 static inline int memcmp(const void *s1, const void *s2, size_t len)
5763 {
5764 u8 diff;
5765 - asm("repe; cmpsb; setnz %0"
5766 + asm volatile("repe; cmpsb; setnz %0"
5767 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
5768 return diff;
5769 }
5770 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
5771 index 09664ef..edc5d03 100644
5772 --- a/arch/x86/boot/compressed/Makefile
5773 +++ b/arch/x86/boot/compressed/Makefile
5774 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
5775 KBUILD_CFLAGS += $(cflags-y)
5776 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
5777 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
5778 +ifdef CONSTIFY_PLUGIN
5779 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5780 +endif
5781
5782 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5783 GCOV_PROFILE := n
5784 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
5785 index 67a655a..b924059 100644
5786 --- a/arch/x86/boot/compressed/head_32.S
5787 +++ b/arch/x86/boot/compressed/head_32.S
5788 @@ -76,7 +76,7 @@ ENTRY(startup_32)
5789 notl %eax
5790 andl %eax, %ebx
5791 #else
5792 - movl $LOAD_PHYSICAL_ADDR, %ebx
5793 + movl $____LOAD_PHYSICAL_ADDR, %ebx
5794 #endif
5795
5796 /* Target address to relocate to for decompression */
5797 @@ -162,7 +162,7 @@ relocated:
5798 * and where it was actually loaded.
5799 */
5800 movl %ebp, %ebx
5801 - subl $LOAD_PHYSICAL_ADDR, %ebx
5802 + subl $____LOAD_PHYSICAL_ADDR, %ebx
5803 jz 2f /* Nothing to be done if loaded at compiled addr. */
5804 /*
5805 * Process relocations.
5806 @@ -170,8 +170,7 @@ relocated:
5807
5808 1: subl $4, %edi
5809 movl (%edi), %ecx
5810 - testl %ecx, %ecx
5811 - jz 2f
5812 + jecxz 2f
5813 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
5814 jmp 1b
5815 2:
5816 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
5817 index 35af09d..99c9676 100644
5818 --- a/arch/x86/boot/compressed/head_64.S
5819 +++ b/arch/x86/boot/compressed/head_64.S
5820 @@ -91,7 +91,7 @@ ENTRY(startup_32)
5821 notl %eax
5822 andl %eax, %ebx
5823 #else
5824 - movl $LOAD_PHYSICAL_ADDR, %ebx
5825 + movl $____LOAD_PHYSICAL_ADDR, %ebx
5826 #endif
5827
5828 /* Target address to relocate to for decompression */
5829 @@ -233,7 +233,7 @@ ENTRY(startup_64)
5830 notq %rax
5831 andq %rax, %rbp
5832 #else
5833 - movq $LOAD_PHYSICAL_ADDR, %rbp
5834 + movq $____LOAD_PHYSICAL_ADDR, %rbp
5835 #endif
5836
5837 /* Target address to relocate to for decompression */
5838 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
5839 index 3a19d04..7c1d55a 100644
5840 --- a/arch/x86/boot/compressed/misc.c
5841 +++ b/arch/x86/boot/compressed/misc.c
5842 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
5843 case PT_LOAD:
5844 #ifdef CONFIG_RELOCATABLE
5845 dest = output;
5846 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
5847 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
5848 #else
5849 dest = (void *)(phdr->p_paddr);
5850 #endif
5851 @@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
5852 error("Destination address too large");
5853 #endif
5854 #ifndef CONFIG_RELOCATABLE
5855 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
5856 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
5857 error("Wrong destination address");
5858 #endif
5859
5860 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
5861 index 89bbf4e..869908e 100644
5862 --- a/arch/x86/boot/compressed/relocs.c
5863 +++ b/arch/x86/boot/compressed/relocs.c
5864 @@ -13,8 +13,11 @@
5865
5866 static void die(char *fmt, ...);
5867
5868 +#include "../../../../include/generated/autoconf.h"
5869 +
5870 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
5871 static Elf32_Ehdr ehdr;
5872 +static Elf32_Phdr *phdr;
5873 static unsigned long reloc_count, reloc_idx;
5874 static unsigned long *relocs;
5875
5876 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
5877 }
5878 }
5879
5880 +static void read_phdrs(FILE *fp)
5881 +{
5882 + unsigned int i;
5883 +
5884 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
5885 + if (!phdr) {
5886 + die("Unable to allocate %d program headers\n",
5887 + ehdr.e_phnum);
5888 + }
5889 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
5890 + die("Seek to %d failed: %s\n",
5891 + ehdr.e_phoff, strerror(errno));
5892 + }
5893 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
5894 + die("Cannot read ELF program headers: %s\n",
5895 + strerror(errno));
5896 + }
5897 + for(i = 0; i < ehdr.e_phnum; i++) {
5898 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
5899 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
5900 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
5901 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
5902 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
5903 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
5904 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
5905 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
5906 + }
5907 +
5908 +}
5909 +
5910 static void read_shdrs(FILE *fp)
5911 {
5912 - int i;
5913 + unsigned int i;
5914 Elf32_Shdr shdr;
5915
5916 secs = calloc(ehdr.e_shnum, sizeof(struct section));
5917 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
5918
5919 static void read_strtabs(FILE *fp)
5920 {
5921 - int i;
5922 + unsigned int i;
5923 for (i = 0; i < ehdr.e_shnum; i++) {
5924 struct section *sec = &secs[i];
5925 if (sec->shdr.sh_type != SHT_STRTAB) {
5926 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
5927
5928 static void read_symtabs(FILE *fp)
5929 {
5930 - int i,j;
5931 + unsigned int i,j;
5932 for (i = 0; i < ehdr.e_shnum; i++) {
5933 struct section *sec = &secs[i];
5934 if (sec->shdr.sh_type != SHT_SYMTAB) {
5935 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
5936
5937 static void read_relocs(FILE *fp)
5938 {
5939 - int i,j;
5940 + unsigned int i,j;
5941 + uint32_t base;
5942 +
5943 for (i = 0; i < ehdr.e_shnum; i++) {
5944 struct section *sec = &secs[i];
5945 if (sec->shdr.sh_type != SHT_REL) {
5946 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
5947 die("Cannot read symbol table: %s\n",
5948 strerror(errno));
5949 }
5950 + base = 0;
5951 + for (j = 0; j < ehdr.e_phnum; j++) {
5952 + if (phdr[j].p_type != PT_LOAD )
5953 + continue;
5954 + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
5955 + continue;
5956 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
5957 + break;
5958 + }
5959 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
5960 Elf32_Rel *rel = &sec->reltab[j];
5961 - rel->r_offset = elf32_to_cpu(rel->r_offset);
5962 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
5963 rel->r_info = elf32_to_cpu(rel->r_info);
5964 }
5965 }
5966 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
5967
5968 static void print_absolute_symbols(void)
5969 {
5970 - int i;
5971 + unsigned int i;
5972 printf("Absolute symbols\n");
5973 printf(" Num: Value Size Type Bind Visibility Name\n");
5974 for (i = 0; i < ehdr.e_shnum; i++) {
5975 struct section *sec = &secs[i];
5976 char *sym_strtab;
5977 Elf32_Sym *sh_symtab;
5978 - int j;
5979 + unsigned int j;
5980
5981 if (sec->shdr.sh_type != SHT_SYMTAB) {
5982 continue;
5983 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
5984
5985 static void print_absolute_relocs(void)
5986 {
5987 - int i, printed = 0;
5988 + unsigned int i, printed = 0;
5989
5990 for (i = 0; i < ehdr.e_shnum; i++) {
5991 struct section *sec = &secs[i];
5992 struct section *sec_applies, *sec_symtab;
5993 char *sym_strtab;
5994 Elf32_Sym *sh_symtab;
5995 - int j;
5996 + unsigned int j;
5997 if (sec->shdr.sh_type != SHT_REL) {
5998 continue;
5999 }
6000 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
6001
6002 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6003 {
6004 - int i;
6005 + unsigned int i;
6006 /* Walk through the relocations */
6007 for (i = 0; i < ehdr.e_shnum; i++) {
6008 char *sym_strtab;
6009 Elf32_Sym *sh_symtab;
6010 struct section *sec_applies, *sec_symtab;
6011 - int j;
6012 + unsigned int j;
6013 struct section *sec = &secs[i];
6014
6015 if (sec->shdr.sh_type != SHT_REL) {
6016 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6017 !is_rel_reloc(sym_name(sym_strtab, sym))) {
6018 continue;
6019 }
6020 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
6021 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
6022 + continue;
6023 +
6024 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
6025 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
6026 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
6027 + continue;
6028 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
6029 + continue;
6030 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
6031 + continue;
6032 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
6033 + continue;
6034 +#endif
6035 +
6036 switch (r_type) {
6037 case R_386_NONE:
6038 case R_386_PC32:
6039 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
6040
6041 static void emit_relocs(int as_text)
6042 {
6043 - int i;
6044 + unsigned int i;
6045 /* Count how many relocations I have and allocate space for them. */
6046 reloc_count = 0;
6047 walk_relocs(count_reloc);
6048 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
6049 fname, strerror(errno));
6050 }
6051 read_ehdr(fp);
6052 + read_phdrs(fp);
6053 read_shdrs(fp);
6054 read_strtabs(fp);
6055 read_symtabs(fp);
6056 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
6057 index 4d3ff03..e4972ff 100644
6058 --- a/arch/x86/boot/cpucheck.c
6059 +++ b/arch/x86/boot/cpucheck.c
6060 @@ -74,7 +74,7 @@ static int has_fpu(void)
6061 u16 fcw = -1, fsw = -1;
6062 u32 cr0;
6063
6064 - asm("movl %%cr0,%0" : "=r" (cr0));
6065 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
6066 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
6067 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
6068 asm volatile("movl %0,%%cr0" : : "r" (cr0));
6069 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
6070 {
6071 u32 f0, f1;
6072
6073 - asm("pushfl ; "
6074 + asm volatile("pushfl ; "
6075 "pushfl ; "
6076 "popl %0 ; "
6077 "movl %0,%1 ; "
6078 @@ -115,7 +115,7 @@ static void get_flags(void)
6079 set_bit(X86_FEATURE_FPU, cpu.flags);
6080
6081 if (has_eflag(X86_EFLAGS_ID)) {
6082 - asm("cpuid"
6083 + asm volatile("cpuid"
6084 : "=a" (max_intel_level),
6085 "=b" (cpu_vendor[0]),
6086 "=d" (cpu_vendor[1]),
6087 @@ -124,7 +124,7 @@ static void get_flags(void)
6088
6089 if (max_intel_level >= 0x00000001 &&
6090 max_intel_level <= 0x0000ffff) {
6091 - asm("cpuid"
6092 + asm volatile("cpuid"
6093 : "=a" (tfms),
6094 "=c" (cpu.flags[4]),
6095 "=d" (cpu.flags[0])
6096 @@ -136,7 +136,7 @@ static void get_flags(void)
6097 cpu.model += ((tfms >> 16) & 0xf) << 4;
6098 }
6099
6100 - asm("cpuid"
6101 + asm volatile("cpuid"
6102 : "=a" (max_amd_level)
6103 : "a" (0x80000000)
6104 : "ebx", "ecx", "edx");
6105 @@ -144,7 +144,7 @@ static void get_flags(void)
6106 if (max_amd_level >= 0x80000001 &&
6107 max_amd_level <= 0x8000ffff) {
6108 u32 eax = 0x80000001;
6109 - asm("cpuid"
6110 + asm volatile("cpuid"
6111 : "+a" (eax),
6112 "=c" (cpu.flags[6]),
6113 "=d" (cpu.flags[1])
6114 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6115 u32 ecx = MSR_K7_HWCR;
6116 u32 eax, edx;
6117
6118 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6119 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6120 eax &= ~(1 << 15);
6121 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6122 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6123
6124 get_flags(); /* Make sure it really did something */
6125 err = check_flags();
6126 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6127 u32 ecx = MSR_VIA_FCR;
6128 u32 eax, edx;
6129
6130 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6131 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6132 eax |= (1<<1)|(1<<7);
6133 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6134 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6135
6136 set_bit(X86_FEATURE_CX8, cpu.flags);
6137 err = check_flags();
6138 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6139 u32 eax, edx;
6140 u32 level = 1;
6141
6142 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6143 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6144 - asm("cpuid"
6145 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6146 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6147 + asm volatile("cpuid"
6148 : "+a" (level), "=d" (cpu.flags[0])
6149 : : "ecx", "ebx");
6150 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6151 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6152
6153 err = check_flags();
6154 }
6155 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
6156 index bdb4d45..0476680 100644
6157 --- a/arch/x86/boot/header.S
6158 +++ b/arch/x86/boot/header.S
6159 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
6160 # single linked list of
6161 # struct setup_data
6162
6163 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
6164 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
6165
6166 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
6167 #define VO_INIT_SIZE (VO__end - VO__text)
6168 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
6169 index db75d07..8e6d0af 100644
6170 --- a/arch/x86/boot/memory.c
6171 +++ b/arch/x86/boot/memory.c
6172 @@ -19,7 +19,7 @@
6173
6174 static int detect_memory_e820(void)
6175 {
6176 - int count = 0;
6177 + unsigned int count = 0;
6178 struct biosregs ireg, oreg;
6179 struct e820entry *desc = boot_params.e820_map;
6180 static struct e820entry buf; /* static so it is zeroed */
6181 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
6182 index 11e8c6e..fdbb1ed 100644
6183 --- a/arch/x86/boot/video-vesa.c
6184 +++ b/arch/x86/boot/video-vesa.c
6185 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
6186
6187 boot_params.screen_info.vesapm_seg = oreg.es;
6188 boot_params.screen_info.vesapm_off = oreg.di;
6189 + boot_params.screen_info.vesapm_size = oreg.cx;
6190 }
6191
6192 /*
6193 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
6194 index 43eda28..5ab5fdb 100644
6195 --- a/arch/x86/boot/video.c
6196 +++ b/arch/x86/boot/video.c
6197 @@ -96,7 +96,7 @@ static void store_mode_params(void)
6198 static unsigned int get_entry(void)
6199 {
6200 char entry_buf[4];
6201 - int i, len = 0;
6202 + unsigned int i, len = 0;
6203 int key;
6204 unsigned int v;
6205
6206 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
6207 index 5b577d5..3c1fed4 100644
6208 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
6209 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
6210 @@ -8,6 +8,8 @@
6211 * including this sentence is retained in full.
6212 */
6213
6214 +#include <asm/alternative-asm.h>
6215 +
6216 .extern crypto_ft_tab
6217 .extern crypto_it_tab
6218 .extern crypto_fl_tab
6219 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
6220 je B192; \
6221 leaq 32(r9),r9;
6222
6223 +#define ret pax_force_retaddr 0, 1; ret
6224 +
6225 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
6226 movq r1,r2; \
6227 movq r3,r4; \
6228 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
6229 index be6d9e3..21fbbca 100644
6230 --- a/arch/x86/crypto/aesni-intel_asm.S
6231 +++ b/arch/x86/crypto/aesni-intel_asm.S
6232 @@ -31,6 +31,7 @@
6233
6234 #include <linux/linkage.h>
6235 #include <asm/inst.h>
6236 +#include <asm/alternative-asm.h>
6237
6238 #ifdef __x86_64__
6239 .data
6240 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
6241 pop %r14
6242 pop %r13
6243 pop %r12
6244 + pax_force_retaddr 0, 1
6245 ret
6246 +ENDPROC(aesni_gcm_dec)
6247
6248
6249 /*****************************************************************************
6250 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
6251 pop %r14
6252 pop %r13
6253 pop %r12
6254 + pax_force_retaddr 0, 1
6255 ret
6256 +ENDPROC(aesni_gcm_enc)
6257
6258 #endif
6259
6260 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
6261 pxor %xmm1, %xmm0
6262 movaps %xmm0, (TKEYP)
6263 add $0x10, TKEYP
6264 + pax_force_retaddr_bts
6265 ret
6266
6267 .align 4
6268 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
6269 shufps $0b01001110, %xmm2, %xmm1
6270 movaps %xmm1, 0x10(TKEYP)
6271 add $0x20, TKEYP
6272 + pax_force_retaddr_bts
6273 ret
6274
6275 .align 4
6276 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
6277
6278 movaps %xmm0, (TKEYP)
6279 add $0x10, TKEYP
6280 + pax_force_retaddr_bts
6281 ret
6282
6283 .align 4
6284 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
6285 pxor %xmm1, %xmm2
6286 movaps %xmm2, (TKEYP)
6287 add $0x10, TKEYP
6288 + pax_force_retaddr_bts
6289 ret
6290
6291 /*
6292 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
6293 #ifndef __x86_64__
6294 popl KEYP
6295 #endif
6296 + pax_force_retaddr 0, 1
6297 ret
6298 +ENDPROC(aesni_set_key)
6299
6300 /*
6301 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
6302 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
6303 popl KLEN
6304 popl KEYP
6305 #endif
6306 + pax_force_retaddr 0, 1
6307 ret
6308 +ENDPROC(aesni_enc)
6309
6310 /*
6311 * _aesni_enc1: internal ABI
6312 @@ -1959,6 +1972,7 @@ _aesni_enc1:
6313 AESENC KEY STATE
6314 movaps 0x70(TKEYP), KEY
6315 AESENCLAST KEY STATE
6316 + pax_force_retaddr_bts
6317 ret
6318
6319 /*
6320 @@ -2067,6 +2081,7 @@ _aesni_enc4:
6321 AESENCLAST KEY STATE2
6322 AESENCLAST KEY STATE3
6323 AESENCLAST KEY STATE4
6324 + pax_force_retaddr_bts
6325 ret
6326
6327 /*
6328 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
6329 popl KLEN
6330 popl KEYP
6331 #endif
6332 + pax_force_retaddr 0, 1
6333 ret
6334 +ENDPROC(aesni_dec)
6335
6336 /*
6337 * _aesni_dec1: internal ABI
6338 @@ -2146,6 +2163,7 @@ _aesni_dec1:
6339 AESDEC KEY STATE
6340 movaps 0x70(TKEYP), KEY
6341 AESDECLAST KEY STATE
6342 + pax_force_retaddr_bts
6343 ret
6344
6345 /*
6346 @@ -2254,6 +2272,7 @@ _aesni_dec4:
6347 AESDECLAST KEY STATE2
6348 AESDECLAST KEY STATE3
6349 AESDECLAST KEY STATE4
6350 + pax_force_retaddr_bts
6351 ret
6352
6353 /*
6354 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
6355 popl KEYP
6356 popl LEN
6357 #endif
6358 + pax_force_retaddr 0, 1
6359 ret
6360 +ENDPROC(aesni_ecb_enc)
6361
6362 /*
6363 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6364 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
6365 popl KEYP
6366 popl LEN
6367 #endif
6368 + pax_force_retaddr 0, 1
6369 ret
6370 +ENDPROC(aesni_ecb_dec)
6371
6372 /*
6373 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6374 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
6375 popl LEN
6376 popl IVP
6377 #endif
6378 + pax_force_retaddr 0, 1
6379 ret
6380 +ENDPROC(aesni_cbc_enc)
6381
6382 /*
6383 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6384 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
6385 popl LEN
6386 popl IVP
6387 #endif
6388 + pax_force_retaddr 0, 1
6389 ret
6390 +ENDPROC(aesni_cbc_dec)
6391
6392 #ifdef __x86_64__
6393 .align 16
6394 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
6395 mov $1, TCTR_LOW
6396 MOVQ_R64_XMM TCTR_LOW INC
6397 MOVQ_R64_XMM CTR TCTR_LOW
6398 + pax_force_retaddr_bts
6399 ret
6400
6401 /*
6402 @@ -2552,6 +2580,7 @@ _aesni_inc:
6403 .Linc_low:
6404 movaps CTR, IV
6405 PSHUFB_XMM BSWAP_MASK IV
6406 + pax_force_retaddr_bts
6407 ret
6408
6409 /*
6410 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
6411 .Lctr_enc_ret:
6412 movups IV, (IVP)
6413 .Lctr_enc_just_ret:
6414 + pax_force_retaddr 0, 1
6415 ret
6416 +ENDPROC(aesni_ctr_enc)
6417 #endif
6418 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
6419 index 391d245..67f35c2 100644
6420 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
6421 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
6422 @@ -20,6 +20,8 @@
6423 *
6424 */
6425
6426 +#include <asm/alternative-asm.h>
6427 +
6428 .file "blowfish-x86_64-asm.S"
6429 .text
6430
6431 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
6432 jnz __enc_xor;
6433
6434 write_block();
6435 + pax_force_retaddr 0, 1
6436 ret;
6437 __enc_xor:
6438 xor_block();
6439 + pax_force_retaddr 0, 1
6440 ret;
6441
6442 .align 8
6443 @@ -188,6 +192,7 @@ blowfish_dec_blk:
6444
6445 movq %r11, %rbp;
6446
6447 + pax_force_retaddr 0, 1
6448 ret;
6449
6450 /**********************************************************************
6451 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
6452
6453 popq %rbx;
6454 popq %rbp;
6455 + pax_force_retaddr 0, 1
6456 ret;
6457
6458 __enc_xor4:
6459 @@ -349,6 +355,7 @@ __enc_xor4:
6460
6461 popq %rbx;
6462 popq %rbp;
6463 + pax_force_retaddr 0, 1
6464 ret;
6465
6466 .align 8
6467 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
6468 popq %rbx;
6469 popq %rbp;
6470
6471 + pax_force_retaddr 0, 1
6472 ret;
6473
6474 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
6475 index 6214a9b..1f4fc9a 100644
6476 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
6477 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
6478 @@ -1,3 +1,5 @@
6479 +#include <asm/alternative-asm.h>
6480 +
6481 # enter ECRYPT_encrypt_bytes
6482 .text
6483 .p2align 5
6484 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
6485 add %r11,%rsp
6486 mov %rdi,%rax
6487 mov %rsi,%rdx
6488 + pax_force_retaddr 0, 1
6489 ret
6490 # bytesatleast65:
6491 ._bytesatleast65:
6492 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
6493 add %r11,%rsp
6494 mov %rdi,%rax
6495 mov %rsi,%rdx
6496 + pax_force_retaddr
6497 ret
6498 # enter ECRYPT_ivsetup
6499 .text
6500 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
6501 add %r11,%rsp
6502 mov %rdi,%rax
6503 mov %rsi,%rdx
6504 + pax_force_retaddr
6505 ret
6506 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
6507 index b2c2f57..8470cab 100644
6508 --- a/arch/x86/crypto/sha1_ssse3_asm.S
6509 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
6510 @@ -28,6 +28,8 @@
6511 * (at your option) any later version.
6512 */
6513
6514 +#include <asm/alternative-asm.h>
6515 +
6516 #define CTX %rdi // arg1
6517 #define BUF %rsi // arg2
6518 #define CNT %rdx // arg3
6519 @@ -104,6 +106,7 @@
6520 pop %r12
6521 pop %rbp
6522 pop %rbx
6523 + pax_force_retaddr 0, 1
6524 ret
6525
6526 .size \name, .-\name
6527 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
6528 index 5b012a2..36d5364 100644
6529 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
6530 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
6531 @@ -20,6 +20,8 @@
6532 *
6533 */
6534
6535 +#include <asm/alternative-asm.h>
6536 +
6537 .file "twofish-x86_64-asm-3way.S"
6538 .text
6539
6540 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
6541 popq %r13;
6542 popq %r14;
6543 popq %r15;
6544 + pax_force_retaddr 0, 1
6545 ret;
6546
6547 __enc_xor3:
6548 @@ -271,6 +274,7 @@ __enc_xor3:
6549 popq %r13;
6550 popq %r14;
6551 popq %r15;
6552 + pax_force_retaddr 0, 1
6553 ret;
6554
6555 .global twofish_dec_blk_3way
6556 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
6557 popq %r13;
6558 popq %r14;
6559 popq %r15;
6560 + pax_force_retaddr 0, 1
6561 ret;
6562
6563 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
6564 index 7bcf3fc..f53832f 100644
6565 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
6566 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
6567 @@ -21,6 +21,7 @@
6568 .text
6569
6570 #include <asm/asm-offsets.h>
6571 +#include <asm/alternative-asm.h>
6572
6573 #define a_offset 0
6574 #define b_offset 4
6575 @@ -268,6 +269,7 @@ twofish_enc_blk:
6576
6577 popq R1
6578 movq $1,%rax
6579 + pax_force_retaddr 0, 1
6580 ret
6581
6582 twofish_dec_blk:
6583 @@ -319,4 +321,5 @@ twofish_dec_blk:
6584
6585 popq R1
6586 movq $1,%rax
6587 + pax_force_retaddr 0, 1
6588 ret
6589 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
6590 index fd84387..0b4af7d 100644
6591 --- a/arch/x86/ia32/ia32_aout.c
6592 +++ b/arch/x86/ia32/ia32_aout.c
6593 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
6594 unsigned long dump_start, dump_size;
6595 struct user32 dump;
6596
6597 + memset(&dump, 0, sizeof(dump));
6598 +
6599 fs = get_fs();
6600 set_fs(KERNEL_DS);
6601 has_dumped = 1;
6602 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
6603 index 6557769..ef6ae89 100644
6604 --- a/arch/x86/ia32/ia32_signal.c
6605 +++ b/arch/x86/ia32/ia32_signal.c
6606 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
6607 }
6608 seg = get_fs();
6609 set_fs(KERNEL_DS);
6610 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
6611 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
6612 set_fs(seg);
6613 if (ret >= 0 && uoss_ptr) {
6614 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
6615 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
6616 */
6617 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6618 size_t frame_size,
6619 - void **fpstate)
6620 + void __user **fpstate)
6621 {
6622 unsigned long sp;
6623
6624 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6625
6626 if (used_math()) {
6627 sp = sp - sig_xstate_ia32_size;
6628 - *fpstate = (struct _fpstate_ia32 *) sp;
6629 + *fpstate = (struct _fpstate_ia32 __user *) sp;
6630 if (save_i387_xstate_ia32(*fpstate) < 0)
6631 return (void __user *) -1L;
6632 }
6633 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6634 sp -= frame_size;
6635 /* Align the stack pointer according to the i386 ABI,
6636 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
6637 - sp = ((sp + 4) & -16ul) - 4;
6638 + sp = ((sp - 12) & -16ul) - 4;
6639 return (void __user *) sp;
6640 }
6641
6642 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
6643 * These are actually not used anymore, but left because some
6644 * gdb versions depend on them as a marker.
6645 */
6646 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6647 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
6648 } put_user_catch(err);
6649
6650 if (err)
6651 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
6652 0xb8,
6653 __NR_ia32_rt_sigreturn,
6654 0x80cd,
6655 - 0,
6656 + 0
6657 };
6658
6659 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
6660 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
6661
6662 if (ka->sa.sa_flags & SA_RESTORER)
6663 restorer = ka->sa.sa_restorer;
6664 + else if (current->mm->context.vdso)
6665 + /* Return stub is in 32bit vsyscall page */
6666 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6667 else
6668 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
6669 - rt_sigreturn);
6670 + restorer = &frame->retcode;
6671 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
6672
6673 /*
6674 * Not actually used anymore, but left because some gdb
6675 * versions need it.
6676 */
6677 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6678 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
6679 } put_user_catch(err);
6680
6681 if (err)
6682 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
6683 index a6253ec..4ad2120 100644
6684 --- a/arch/x86/ia32/ia32entry.S
6685 +++ b/arch/x86/ia32/ia32entry.S
6686 @@ -13,7 +13,9 @@
6687 #include <asm/thread_info.h>
6688 #include <asm/segment.h>
6689 #include <asm/irqflags.h>
6690 +#include <asm/pgtable.h>
6691 #include <linux/linkage.h>
6692 +#include <asm/alternative-asm.h>
6693
6694 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
6695 #include <linux/elf-em.h>
6696 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
6697 ENDPROC(native_irq_enable_sysexit)
6698 #endif
6699
6700 + .macro pax_enter_kernel_user
6701 + pax_set_fptr_mask
6702 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6703 + call pax_enter_kernel_user
6704 +#endif
6705 + .endm
6706 +
6707 + .macro pax_exit_kernel_user
6708 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6709 + call pax_exit_kernel_user
6710 +#endif
6711 +#ifdef CONFIG_PAX_RANDKSTACK
6712 + pushq %rax
6713 + pushq %r11
6714 + call pax_randomize_kstack
6715 + popq %r11
6716 + popq %rax
6717 +#endif
6718 + .endm
6719 +
6720 +.macro pax_erase_kstack
6721 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
6722 + call pax_erase_kstack
6723 +#endif
6724 +.endm
6725 +
6726 /*
6727 * 32bit SYSENTER instruction entry.
6728 *
6729 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
6730 CFI_REGISTER rsp,rbp
6731 SWAPGS_UNSAFE_STACK
6732 movq PER_CPU_VAR(kernel_stack), %rsp
6733 - addq $(KERNEL_STACK_OFFSET),%rsp
6734 - /*
6735 - * No need to follow this irqs on/off section: the syscall
6736 - * disabled irqs, here we enable it straight after entry:
6737 - */
6738 - ENABLE_INTERRUPTS(CLBR_NONE)
6739 movl %ebp,%ebp /* zero extension */
6740 pushq_cfi $__USER32_DS
6741 /*CFI_REL_OFFSET ss,0*/
6742 @@ -134,25 +156,39 @@ ENTRY(ia32_sysenter_target)
6743 CFI_REL_OFFSET rsp,0
6744 pushfq_cfi
6745 /*CFI_REL_OFFSET rflags,0*/
6746 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
6747 - CFI_REGISTER rip,r10
6748 + orl $X86_EFLAGS_IF,(%rsp)
6749 + GET_THREAD_INFO(%r11)
6750 + movl TI_sysenter_return(%r11), %r11d
6751 + CFI_REGISTER rip,r11
6752 pushq_cfi $__USER32_CS
6753 /*CFI_REL_OFFSET cs,0*/
6754 movl %eax, %eax
6755 - pushq_cfi %r10
6756 + pushq_cfi %r11
6757 CFI_REL_OFFSET rip,0
6758 pushq_cfi %rax
6759 cld
6760 SAVE_ARGS 0,1,0
6761 + pax_enter_kernel_user
6762 + /*
6763 + * No need to follow this irqs on/off section: the syscall
6764 + * disabled irqs, here we enable it straight after entry:
6765 + */
6766 + ENABLE_INTERRUPTS(CLBR_NONE)
6767 /* no need to do an access_ok check here because rbp has been
6768 32bit zero extended */
6769 +
6770 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6771 + mov $PAX_USER_SHADOW_BASE,%r11
6772 + add %r11,%rbp
6773 +#endif
6774 +
6775 1: movl (%rbp),%ebp
6776 .section __ex_table,"a"
6777 .quad 1b,ia32_badarg
6778 .previous
6779 - GET_THREAD_INFO(%r10)
6780 - orl $TS_COMPAT,TI_status(%r10)
6781 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
6782 + GET_THREAD_INFO(%r11)
6783 + orl $TS_COMPAT,TI_status(%r11)
6784 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
6785 CFI_REMEMBER_STATE
6786 jnz sysenter_tracesys
6787 cmpq $(IA32_NR_syscalls-1),%rax
6788 @@ -162,13 +198,15 @@ sysenter_do_call:
6789 sysenter_dispatch:
6790 call *ia32_sys_call_table(,%rax,8)
6791 movq %rax,RAX-ARGOFFSET(%rsp)
6792 - GET_THREAD_INFO(%r10)
6793 + GET_THREAD_INFO(%r11)
6794 DISABLE_INTERRUPTS(CLBR_NONE)
6795 TRACE_IRQS_OFF
6796 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6797 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
6798 jnz sysexit_audit
6799 sysexit_from_sys_call:
6800 - andl $~TS_COMPAT,TI_status(%r10)
6801 + pax_exit_kernel_user
6802 + pax_erase_kstack
6803 + andl $~TS_COMPAT,TI_status(%r11)
6804 /* clear IF, that popfq doesn't enable interrupts early */
6805 andl $~0x200,EFLAGS-R11(%rsp)
6806 movl RIP-R11(%rsp),%edx /* User %eip */
6807 @@ -194,6 +232,9 @@ sysexit_from_sys_call:
6808 movl %eax,%esi /* 2nd arg: syscall number */
6809 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
6810 call audit_syscall_entry
6811 +
6812 + pax_erase_kstack
6813 +
6814 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
6815 cmpq $(IA32_NR_syscalls-1),%rax
6816 ja ia32_badsys
6817 @@ -205,7 +246,7 @@ sysexit_from_sys_call:
6818 .endm
6819
6820 .macro auditsys_exit exit
6821 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
6822 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
6823 jnz ia32_ret_from_sys_call
6824 TRACE_IRQS_ON
6825 sti
6826 @@ -215,12 +256,12 @@ sysexit_from_sys_call:
6827 movzbl %al,%edi /* zero-extend that into %edi */
6828 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
6829 call audit_syscall_exit
6830 - GET_THREAD_INFO(%r10)
6831 + GET_THREAD_INFO(%r11)
6832 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
6833 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
6834 cli
6835 TRACE_IRQS_OFF
6836 - testl %edi,TI_flags(%r10)
6837 + testl %edi,TI_flags(%r11)
6838 jz \exit
6839 CLEAR_RREGS -ARGOFFSET
6840 jmp int_with_check
6841 @@ -238,7 +279,7 @@ sysexit_audit:
6842
6843 sysenter_tracesys:
6844 #ifdef CONFIG_AUDITSYSCALL
6845 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
6846 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
6847 jz sysenter_auditsys
6848 #endif
6849 SAVE_REST
6850 @@ -246,6 +287,9 @@ sysenter_tracesys:
6851 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
6852 movq %rsp,%rdi /* &pt_regs -> arg1 */
6853 call syscall_trace_enter
6854 +
6855 + pax_erase_kstack
6856 +
6857 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
6858 RESTORE_REST
6859 cmpq $(IA32_NR_syscalls-1),%rax
6860 @@ -277,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
6861 ENTRY(ia32_cstar_target)
6862 CFI_STARTPROC32 simple
6863 CFI_SIGNAL_FRAME
6864 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
6865 + CFI_DEF_CFA rsp,0
6866 CFI_REGISTER rip,rcx
6867 /*CFI_REGISTER rflags,r11*/
6868 SWAPGS_UNSAFE_STACK
6869 movl %esp,%r8d
6870 CFI_REGISTER rsp,r8
6871 movq PER_CPU_VAR(kernel_stack),%rsp
6872 + SAVE_ARGS 8*6,0,0
6873 + pax_enter_kernel_user
6874 /*
6875 * No need to follow this irqs on/off section: the syscall
6876 * disabled irqs and here we enable it straight after entry:
6877 */
6878 ENABLE_INTERRUPTS(CLBR_NONE)
6879 - SAVE_ARGS 8,0,0
6880 movl %eax,%eax /* zero extension */
6881 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
6882 movq %rcx,RIP-ARGOFFSET(%rsp)
6883 @@ -305,13 +350,19 @@ ENTRY(ia32_cstar_target)
6884 /* no need to do an access_ok check here because r8 has been
6885 32bit zero extended */
6886 /* hardware stack frame is complete now */
6887 +
6888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6889 + mov $PAX_USER_SHADOW_BASE,%r11
6890 + add %r11,%r8
6891 +#endif
6892 +
6893 1: movl (%r8),%r9d
6894 .section __ex_table,"a"
6895 .quad 1b,ia32_badarg
6896 .previous
6897 - GET_THREAD_INFO(%r10)
6898 - orl $TS_COMPAT,TI_status(%r10)
6899 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
6900 + GET_THREAD_INFO(%r11)
6901 + orl $TS_COMPAT,TI_status(%r11)
6902 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
6903 CFI_REMEMBER_STATE
6904 jnz cstar_tracesys
6905 cmpq $IA32_NR_syscalls-1,%rax
6906 @@ -321,13 +372,15 @@ cstar_do_call:
6907 cstar_dispatch:
6908 call *ia32_sys_call_table(,%rax,8)
6909 movq %rax,RAX-ARGOFFSET(%rsp)
6910 - GET_THREAD_INFO(%r10)
6911 + GET_THREAD_INFO(%r11)
6912 DISABLE_INTERRUPTS(CLBR_NONE)
6913 TRACE_IRQS_OFF
6914 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6915 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
6916 jnz sysretl_audit
6917 sysretl_from_sys_call:
6918 - andl $~TS_COMPAT,TI_status(%r10)
6919 + pax_exit_kernel_user
6920 + pax_erase_kstack
6921 + andl $~TS_COMPAT,TI_status(%r11)
6922 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
6923 movl RIP-ARGOFFSET(%rsp),%ecx
6924 CFI_REGISTER rip,rcx
6925 @@ -355,7 +408,7 @@ sysretl_audit:
6926
6927 cstar_tracesys:
6928 #ifdef CONFIG_AUDITSYSCALL
6929 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
6930 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
6931 jz cstar_auditsys
6932 #endif
6933 xchgl %r9d,%ebp
6934 @@ -364,6 +417,9 @@ cstar_tracesys:
6935 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
6936 movq %rsp,%rdi /* &pt_regs -> arg1 */
6937 call syscall_trace_enter
6938 +
6939 + pax_erase_kstack
6940 +
6941 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
6942 RESTORE_REST
6943 xchgl %ebp,%r9d
6944 @@ -409,20 +465,21 @@ ENTRY(ia32_syscall)
6945 CFI_REL_OFFSET rip,RIP-RIP
6946 PARAVIRT_ADJUST_EXCEPTION_FRAME
6947 SWAPGS
6948 - /*
6949 - * No need to follow this irqs on/off section: the syscall
6950 - * disabled irqs and here we enable it straight after entry:
6951 - */
6952 - ENABLE_INTERRUPTS(CLBR_NONE)
6953 movl %eax,%eax
6954 pushq_cfi %rax
6955 cld
6956 /* note the registers are not zero extended to the sf.
6957 this could be a problem. */
6958 SAVE_ARGS 0,1,0
6959 - GET_THREAD_INFO(%r10)
6960 - orl $TS_COMPAT,TI_status(%r10)
6961 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
6962 + pax_enter_kernel_user
6963 + /*
6964 + * No need to follow this irqs on/off section: the syscall
6965 + * disabled irqs and here we enable it straight after entry:
6966 + */
6967 + ENABLE_INTERRUPTS(CLBR_NONE)
6968 + GET_THREAD_INFO(%r11)
6969 + orl $TS_COMPAT,TI_status(%r11)
6970 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
6971 jnz ia32_tracesys
6972 cmpq $(IA32_NR_syscalls-1),%rax
6973 ja ia32_badsys
6974 @@ -441,6 +498,9 @@ ia32_tracesys:
6975 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
6976 movq %rsp,%rdi /* &pt_regs -> arg1 */
6977 call syscall_trace_enter
6978 +
6979 + pax_erase_kstack
6980 +
6981 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
6982 RESTORE_REST
6983 cmpq $(IA32_NR_syscalls-1),%rax
6984 @@ -455,6 +515,7 @@ ia32_badsys:
6985
6986 quiet_ni_syscall:
6987 movq $-ENOSYS,%rax
6988 + pax_force_retaddr
6989 ret
6990 CFI_ENDPROC
6991
6992 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
6993 index f6f5c53..b358b28 100644
6994 --- a/arch/x86/ia32/sys_ia32.c
6995 +++ b/arch/x86/ia32/sys_ia32.c
6996 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
6997 */
6998 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
6999 {
7000 - typeof(ubuf->st_uid) uid = 0;
7001 - typeof(ubuf->st_gid) gid = 0;
7002 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
7003 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
7004 SET_UID(uid, stat->uid);
7005 SET_GID(gid, stat->gid);
7006 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
7007 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
7008 }
7009 set_fs(KERNEL_DS);
7010 ret = sys_rt_sigprocmask(how,
7011 - set ? (sigset_t __user *)&s : NULL,
7012 - oset ? (sigset_t __user *)&s : NULL,
7013 + set ? (sigset_t __force_user *)&s : NULL,
7014 + oset ? (sigset_t __force_user *)&s : NULL,
7015 sigsetsize);
7016 set_fs(old_fs);
7017 if (ret)
7018 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
7019 return alarm_setitimer(seconds);
7020 }
7021
7022 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
7023 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
7024 int options)
7025 {
7026 return compat_sys_wait4(pid, stat_addr, options, NULL);
7027 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
7028 mm_segment_t old_fs = get_fs();
7029
7030 set_fs(KERNEL_DS);
7031 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
7032 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
7033 set_fs(old_fs);
7034 if (put_compat_timespec(&t, interval))
7035 return -EFAULT;
7036 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
7037 mm_segment_t old_fs = get_fs();
7038
7039 set_fs(KERNEL_DS);
7040 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
7041 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
7042 set_fs(old_fs);
7043 if (!ret) {
7044 switch (_NSIG_WORDS) {
7045 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
7046 if (copy_siginfo_from_user32(&info, uinfo))
7047 return -EFAULT;
7048 set_fs(KERNEL_DS);
7049 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
7050 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
7051 set_fs(old_fs);
7052 return ret;
7053 }
7054 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
7055 return -EFAULT;
7056
7057 set_fs(KERNEL_DS);
7058 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
7059 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
7060 count);
7061 set_fs(old_fs);
7062
7063 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
7064 index 091508b..e245ff2 100644
7065 --- a/arch/x86/include/asm/alternative-asm.h
7066 +++ b/arch/x86/include/asm/alternative-asm.h
7067 @@ -4,10 +4,10 @@
7068
7069 #ifdef CONFIG_SMP
7070 .macro LOCK_PREFIX
7071 -1: lock
7072 +672: lock
7073 .section .smp_locks,"a"
7074 .balign 4
7075 - .long 1b - .
7076 + .long 672b - .
7077 .previous
7078 .endm
7079 #else
7080 @@ -15,6 +15,45 @@
7081 .endm
7082 #endif
7083
7084 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
7085 + .macro pax_force_retaddr_bts rip=0
7086 + btsq $63,\rip(%rsp)
7087 + .endm
7088 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
7089 + .macro pax_force_retaddr rip=0, reload=0
7090 + btsq $63,\rip(%rsp)
7091 + .endm
7092 + .macro pax_force_fptr ptr
7093 + btsq $63,\ptr
7094 + .endm
7095 + .macro pax_set_fptr_mask
7096 + .endm
7097 +#endif
7098 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
7099 + .macro pax_force_retaddr rip=0, reload=0
7100 + .if \reload
7101 + pax_set_fptr_mask
7102 + .endif
7103 + orq %r10,\rip(%rsp)
7104 + .endm
7105 + .macro pax_force_fptr ptr
7106 + orq %r10,\ptr
7107 + .endm
7108 + .macro pax_set_fptr_mask
7109 + movabs $0x8000000000000000,%r10
7110 + .endm
7111 +#endif
7112 +#else
7113 + .macro pax_force_retaddr rip=0, reload=0
7114 + .endm
7115 + .macro pax_force_fptr ptr
7116 + .endm
7117 + .macro pax_force_retaddr_bts rip=0
7118 + .endm
7119 + .macro pax_set_fptr_mask
7120 + .endm
7121 +#endif
7122 +
7123 .macro altinstruction_entry orig alt feature orig_len alt_len
7124 .long \orig - .
7125 .long \alt - .
7126 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
7127 index 37ad100..7d47faa 100644
7128 --- a/arch/x86/include/asm/alternative.h
7129 +++ b/arch/x86/include/asm/alternative.h
7130 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
7131 ".section .discard,\"aw\",@progbits\n" \
7132 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
7133 ".previous\n" \
7134 - ".section .altinstr_replacement, \"ax\"\n" \
7135 + ".section .altinstr_replacement, \"a\"\n" \
7136 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
7137 ".previous"
7138
7139 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
7140 index 1a6c09a..fec2432 100644
7141 --- a/arch/x86/include/asm/apic.h
7142 +++ b/arch/x86/include/asm/apic.h
7143 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
7144
7145 #ifdef CONFIG_X86_LOCAL_APIC
7146
7147 -extern unsigned int apic_verbosity;
7148 +extern int apic_verbosity;
7149 extern int local_apic_timer_c2_ok;
7150
7151 extern int disable_apic;
7152 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
7153 index 20370c6..a2eb9b0 100644
7154 --- a/arch/x86/include/asm/apm.h
7155 +++ b/arch/x86/include/asm/apm.h
7156 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
7157 __asm__ __volatile__(APM_DO_ZERO_SEGS
7158 "pushl %%edi\n\t"
7159 "pushl %%ebp\n\t"
7160 - "lcall *%%cs:apm_bios_entry\n\t"
7161 + "lcall *%%ss:apm_bios_entry\n\t"
7162 "setc %%al\n\t"
7163 "popl %%ebp\n\t"
7164 "popl %%edi\n\t"
7165 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
7166 __asm__ __volatile__(APM_DO_ZERO_SEGS
7167 "pushl %%edi\n\t"
7168 "pushl %%ebp\n\t"
7169 - "lcall *%%cs:apm_bios_entry\n\t"
7170 + "lcall *%%ss:apm_bios_entry\n\t"
7171 "setc %%bl\n\t"
7172 "popl %%ebp\n\t"
7173 "popl %%edi\n\t"
7174 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
7175 index 58cb6d4..ca9010d 100644
7176 --- a/arch/x86/include/asm/atomic.h
7177 +++ b/arch/x86/include/asm/atomic.h
7178 @@ -22,7 +22,18 @@
7179 */
7180 static inline int atomic_read(const atomic_t *v)
7181 {
7182 - return (*(volatile int *)&(v)->counter);
7183 + return (*(volatile const int *)&(v)->counter);
7184 +}
7185 +
7186 +/**
7187 + * atomic_read_unchecked - read atomic variable
7188 + * @v: pointer of type atomic_unchecked_t
7189 + *
7190 + * Atomically reads the value of @v.
7191 + */
7192 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7193 +{
7194 + return (*(volatile const int *)&(v)->counter);
7195 }
7196
7197 /**
7198 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
7199 }
7200
7201 /**
7202 + * atomic_set_unchecked - set atomic variable
7203 + * @v: pointer of type atomic_unchecked_t
7204 + * @i: required value
7205 + *
7206 + * Atomically sets the value of @v to @i.
7207 + */
7208 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7209 +{
7210 + v->counter = i;
7211 +}
7212 +
7213 +/**
7214 * atomic_add - add integer to atomic variable
7215 * @i: integer value to add
7216 * @v: pointer of type atomic_t
7217 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
7218 */
7219 static inline void atomic_add(int i, atomic_t *v)
7220 {
7221 - asm volatile(LOCK_PREFIX "addl %1,%0"
7222 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
7223 +
7224 +#ifdef CONFIG_PAX_REFCOUNT
7225 + "jno 0f\n"
7226 + LOCK_PREFIX "subl %1,%0\n"
7227 + "int $4\n0:\n"
7228 + _ASM_EXTABLE(0b, 0b)
7229 +#endif
7230 +
7231 + : "+m" (v->counter)
7232 + : "ir" (i));
7233 +}
7234 +
7235 +/**
7236 + * atomic_add_unchecked - add integer to atomic variable
7237 + * @i: integer value to add
7238 + * @v: pointer of type atomic_unchecked_t
7239 + *
7240 + * Atomically adds @i to @v.
7241 + */
7242 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
7243 +{
7244 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
7245 : "+m" (v->counter)
7246 : "ir" (i));
7247 }
7248 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
7249 */
7250 static inline void atomic_sub(int i, atomic_t *v)
7251 {
7252 - asm volatile(LOCK_PREFIX "subl %1,%0"
7253 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7254 +
7255 +#ifdef CONFIG_PAX_REFCOUNT
7256 + "jno 0f\n"
7257 + LOCK_PREFIX "addl %1,%0\n"
7258 + "int $4\n0:\n"
7259 + _ASM_EXTABLE(0b, 0b)
7260 +#endif
7261 +
7262 + : "+m" (v->counter)
7263 + : "ir" (i));
7264 +}
7265 +
7266 +/**
7267 + * atomic_sub_unchecked - subtract integer from atomic variable
7268 + * @i: integer value to subtract
7269 + * @v: pointer of type atomic_unchecked_t
7270 + *
7271 + * Atomically subtracts @i from @v.
7272 + */
7273 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7274 +{
7275 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7276 : "+m" (v->counter)
7277 : "ir" (i));
7278 }
7279 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
7280 {
7281 unsigned char c;
7282
7283 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7284 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
7285 +
7286 +#ifdef CONFIG_PAX_REFCOUNT
7287 + "jno 0f\n"
7288 + LOCK_PREFIX "addl %2,%0\n"
7289 + "int $4\n0:\n"
7290 + _ASM_EXTABLE(0b, 0b)
7291 +#endif
7292 +
7293 + "sete %1\n"
7294 : "+m" (v->counter), "=qm" (c)
7295 : "ir" (i) : "memory");
7296 return c;
7297 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
7298 */
7299 static inline void atomic_inc(atomic_t *v)
7300 {
7301 - asm volatile(LOCK_PREFIX "incl %0"
7302 + asm volatile(LOCK_PREFIX "incl %0\n"
7303 +
7304 +#ifdef CONFIG_PAX_REFCOUNT
7305 + "jno 0f\n"
7306 + LOCK_PREFIX "decl %0\n"
7307 + "int $4\n0:\n"
7308 + _ASM_EXTABLE(0b, 0b)
7309 +#endif
7310 +
7311 + : "+m" (v->counter));
7312 +}
7313 +
7314 +/**
7315 + * atomic_inc_unchecked - increment atomic variable
7316 + * @v: pointer of type atomic_unchecked_t
7317 + *
7318 + * Atomically increments @v by 1.
7319 + */
7320 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7321 +{
7322 + asm volatile(LOCK_PREFIX "incl %0\n"
7323 : "+m" (v->counter));
7324 }
7325
7326 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
7327 */
7328 static inline void atomic_dec(atomic_t *v)
7329 {
7330 - asm volatile(LOCK_PREFIX "decl %0"
7331 + asm volatile(LOCK_PREFIX "decl %0\n"
7332 +
7333 +#ifdef CONFIG_PAX_REFCOUNT
7334 + "jno 0f\n"
7335 + LOCK_PREFIX "incl %0\n"
7336 + "int $4\n0:\n"
7337 + _ASM_EXTABLE(0b, 0b)
7338 +#endif
7339 +
7340 + : "+m" (v->counter));
7341 +}
7342 +
7343 +/**
7344 + * atomic_dec_unchecked - decrement atomic variable
7345 + * @v: pointer of type atomic_unchecked_t
7346 + *
7347 + * Atomically decrements @v by 1.
7348 + */
7349 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7350 +{
7351 + asm volatile(LOCK_PREFIX "decl %0\n"
7352 : "+m" (v->counter));
7353 }
7354
7355 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
7356 {
7357 unsigned char c;
7358
7359 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
7360 + asm volatile(LOCK_PREFIX "decl %0\n"
7361 +
7362 +#ifdef CONFIG_PAX_REFCOUNT
7363 + "jno 0f\n"
7364 + LOCK_PREFIX "incl %0\n"
7365 + "int $4\n0:\n"
7366 + _ASM_EXTABLE(0b, 0b)
7367 +#endif
7368 +
7369 + "sete %1\n"
7370 : "+m" (v->counter), "=qm" (c)
7371 : : "memory");
7372 return c != 0;
7373 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
7374 {
7375 unsigned char c;
7376
7377 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
7378 + asm volatile(LOCK_PREFIX "incl %0\n"
7379 +
7380 +#ifdef CONFIG_PAX_REFCOUNT
7381 + "jno 0f\n"
7382 + LOCK_PREFIX "decl %0\n"
7383 + "int $4\n0:\n"
7384 + _ASM_EXTABLE(0b, 0b)
7385 +#endif
7386 +
7387 + "sete %1\n"
7388 + : "+m" (v->counter), "=qm" (c)
7389 + : : "memory");
7390 + return c != 0;
7391 +}
7392 +
7393 +/**
7394 + * atomic_inc_and_test_unchecked - increment and test
7395 + * @v: pointer of type atomic_unchecked_t
7396 + *
7397 + * Atomically increments @v by 1
7398 + * and returns true if the result is zero, or false for all
7399 + * other cases.
7400 + */
7401 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7402 +{
7403 + unsigned char c;
7404 +
7405 + asm volatile(LOCK_PREFIX "incl %0\n"
7406 + "sete %1\n"
7407 : "+m" (v->counter), "=qm" (c)
7408 : : "memory");
7409 return c != 0;
7410 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
7411 {
7412 unsigned char c;
7413
7414 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7415 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
7416 +
7417 +#ifdef CONFIG_PAX_REFCOUNT
7418 + "jno 0f\n"
7419 + LOCK_PREFIX "subl %2,%0\n"
7420 + "int $4\n0:\n"
7421 + _ASM_EXTABLE(0b, 0b)
7422 +#endif
7423 +
7424 + "sets %1\n"
7425 : "+m" (v->counter), "=qm" (c)
7426 : "ir" (i) : "memory");
7427 return c;
7428 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
7429 goto no_xadd;
7430 #endif
7431 /* Modern 486+ processor */
7432 - return i + xadd(&v->counter, i);
7433 + return i + xadd_check_overflow(&v->counter, i);
7434
7435 #ifdef CONFIG_M386
7436 no_xadd: /* Legacy 386 processor */
7437 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
7438 }
7439
7440 /**
7441 + * atomic_add_return_unchecked - add integer and return
7442 + * @i: integer value to add
7443 + * @v: pointer of type atomic_unchecked_t
7444 + *
7445 + * Atomically adds @i to @v and returns @i + @v
7446 + */
7447 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7448 +{
7449 +#ifdef CONFIG_M386
7450 + int __i;
7451 + unsigned long flags;
7452 + if (unlikely(boot_cpu_data.x86 <= 3))
7453 + goto no_xadd;
7454 +#endif
7455 + /* Modern 486+ processor */
7456 + return i + xadd(&v->counter, i);
7457 +
7458 +#ifdef CONFIG_M386
7459 +no_xadd: /* Legacy 386 processor */
7460 + raw_local_irq_save(flags);
7461 + __i = atomic_read_unchecked(v);
7462 + atomic_set_unchecked(v, i + __i);
7463 + raw_local_irq_restore(flags);
7464 + return i + __i;
7465 +#endif
7466 +}
7467 +
7468 +/**
7469 * atomic_sub_return - subtract integer and return
7470 * @v: pointer of type atomic_t
7471 * @i: integer value to subtract
7472 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
7473 }
7474
7475 #define atomic_inc_return(v) (atomic_add_return(1, v))
7476 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7477 +{
7478 + return atomic_add_return_unchecked(1, v);
7479 +}
7480 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7481
7482 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
7483 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
7484 return cmpxchg(&v->counter, old, new);
7485 }
7486
7487 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7488 +{
7489 + return cmpxchg(&v->counter, old, new);
7490 +}
7491 +
7492 static inline int atomic_xchg(atomic_t *v, int new)
7493 {
7494 return xchg(&v->counter, new);
7495 }
7496
7497 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7498 +{
7499 + return xchg(&v->counter, new);
7500 +}
7501 +
7502 /**
7503 * __atomic_add_unless - add unless the number is already a given value
7504 * @v: pointer of type atomic_t
7505 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
7506 */
7507 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7508 {
7509 - int c, old;
7510 + int c, old, new;
7511 c = atomic_read(v);
7512 for (;;) {
7513 - if (unlikely(c == (u)))
7514 + if (unlikely(c == u))
7515 break;
7516 - old = atomic_cmpxchg((v), c, c + (a));
7517 +
7518 + asm volatile("addl %2,%0\n"
7519 +
7520 +#ifdef CONFIG_PAX_REFCOUNT
7521 + "jno 0f\n"
7522 + "subl %2,%0\n"
7523 + "int $4\n0:\n"
7524 + _ASM_EXTABLE(0b, 0b)
7525 +#endif
7526 +
7527 + : "=r" (new)
7528 + : "0" (c), "ir" (a));
7529 +
7530 + old = atomic_cmpxchg(v, c, new);
7531 if (likely(old == c))
7532 break;
7533 c = old;
7534 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7535 return c;
7536 }
7537
7538 +/**
7539 + * atomic_inc_not_zero_hint - increment if not null
7540 + * @v: pointer of type atomic_t
7541 + * @hint: probable value of the atomic before the increment
7542 + *
7543 + * This version of atomic_inc_not_zero() gives a hint of probable
7544 + * value of the atomic. This helps processor to not read the memory
7545 + * before doing the atomic read/modify/write cycle, lowering
7546 + * number of bus transactions on some arches.
7547 + *
7548 + * Returns: 0 if increment was not done, 1 otherwise.
7549 + */
7550 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
7551 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
7552 +{
7553 + int val, c = hint, new;
7554 +
7555 + /* sanity test, should be removed by compiler if hint is a constant */
7556 + if (!hint)
7557 + return __atomic_add_unless(v, 1, 0);
7558 +
7559 + do {
7560 + asm volatile("incl %0\n"
7561 +
7562 +#ifdef CONFIG_PAX_REFCOUNT
7563 + "jno 0f\n"
7564 + "decl %0\n"
7565 + "int $4\n0:\n"
7566 + _ASM_EXTABLE(0b, 0b)
7567 +#endif
7568 +
7569 + : "=r" (new)
7570 + : "0" (c));
7571 +
7572 + val = atomic_cmpxchg(v, c, new);
7573 + if (val == c)
7574 + return 1;
7575 + c = val;
7576 + } while (c);
7577 +
7578 + return 0;
7579 +}
7580
7581 /*
7582 * atomic_dec_if_positive - decrement by 1 if old value positive
7583 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
7584 index 24098aa..1e37723 100644
7585 --- a/arch/x86/include/asm/atomic64_32.h
7586 +++ b/arch/x86/include/asm/atomic64_32.h
7587 @@ -12,6 +12,14 @@ typedef struct {
7588 u64 __aligned(8) counter;
7589 } atomic64_t;
7590
7591 +#ifdef CONFIG_PAX_REFCOUNT
7592 +typedef struct {
7593 + u64 __aligned(8) counter;
7594 +} atomic64_unchecked_t;
7595 +#else
7596 +typedef atomic64_t atomic64_unchecked_t;
7597 +#endif
7598 +
7599 #define ATOMIC64_INIT(val) { (val) }
7600
7601 #ifdef CONFIG_X86_CMPXCHG64
7602 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
7603 }
7604
7605 /**
7606 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
7607 + * @p: pointer to type atomic64_unchecked_t
7608 + * @o: expected value
7609 + * @n: new value
7610 + *
7611 + * Atomically sets @v to @n if it was equal to @o and returns
7612 + * the old value.
7613 + */
7614 +
7615 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
7616 +{
7617 + return cmpxchg64(&v->counter, o, n);
7618 +}
7619 +
7620 +/**
7621 * atomic64_xchg - xchg atomic64 variable
7622 * @v: pointer to type atomic64_t
7623 * @n: value to assign
7624 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
7625 }
7626
7627 /**
7628 + * atomic64_set_unchecked - set atomic64 variable
7629 + * @v: pointer to type atomic64_unchecked_t
7630 + * @n: value to assign
7631 + *
7632 + * Atomically sets the value of @v to @n.
7633 + */
7634 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
7635 +{
7636 + unsigned high = (unsigned)(i >> 32);
7637 + unsigned low = (unsigned)i;
7638 + asm volatile(ATOMIC64_ALTERNATIVE(set)
7639 + : "+b" (low), "+c" (high)
7640 + : "S" (v)
7641 + : "eax", "edx", "memory"
7642 + );
7643 +}
7644 +
7645 +/**
7646 * atomic64_read - read atomic64 variable
7647 * @v: pointer to type atomic64_t
7648 *
7649 @@ -93,6 +134,22 @@ static inline long long atomic64_read(atomic64_t *v)
7650 }
7651
7652 /**
7653 + * atomic64_read_unchecked - read atomic64 variable
7654 + * @v: pointer to type atomic64_unchecked_t
7655 + *
7656 + * Atomically reads the value of @v and returns it.
7657 + */
7658 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
7659 +{
7660 + long long r;
7661 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
7662 + : "=A" (r), "+c" (v)
7663 + : : "memory"
7664 + );
7665 + return r;
7666 + }
7667 +
7668 +/**
7669 * atomic64_add_return - add and return
7670 * @i: integer value to add
7671 * @v: pointer to type atomic64_t
7672 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
7673 return i;
7674 }
7675
7676 +/**
7677 + * atomic64_add_return_unchecked - add and return
7678 + * @i: integer value to add
7679 + * @v: pointer to type atomic64_unchecked_t
7680 + *
7681 + * Atomically adds @i to @v and returns @i + *@v
7682 + */
7683 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
7684 +{
7685 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
7686 + : "+A" (i), "+c" (v)
7687 + : : "memory"
7688 + );
7689 + return i;
7690 +}
7691 +
7692 /*
7693 * Other variants with different arithmetic operators:
7694 */
7695 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
7696 return a;
7697 }
7698
7699 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7700 +{
7701 + long long a;
7702 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
7703 + : "=A" (a)
7704 + : "S" (v)
7705 + : "memory", "ecx"
7706 + );
7707 + return a;
7708 +}
7709 +
7710 static inline long long atomic64_dec_return(atomic64_t *v)
7711 {
7712 long long a;
7713 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
7714 }
7715
7716 /**
7717 + * atomic64_add_unchecked - add integer to atomic64 variable
7718 + * @i: integer value to add
7719 + * @v: pointer to type atomic64_unchecked_t
7720 + *
7721 + * Atomically adds @i to @v.
7722 + */
7723 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
7724 +{
7725 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
7726 + : "+A" (i), "+c" (v)
7727 + : : "memory"
7728 + );
7729 + return i;
7730 +}
7731 +
7732 +/**
7733 * atomic64_sub - subtract the atomic64 variable
7734 * @i: integer value to subtract
7735 * @v: pointer to type atomic64_t
7736 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
7737 index 0e1cbfc..5623683 100644
7738 --- a/arch/x86/include/asm/atomic64_64.h
7739 +++ b/arch/x86/include/asm/atomic64_64.h
7740 @@ -18,7 +18,19 @@
7741 */
7742 static inline long atomic64_read(const atomic64_t *v)
7743 {
7744 - return (*(volatile long *)&(v)->counter);
7745 + return (*(volatile const long *)&(v)->counter);
7746 +}
7747 +
7748 +/**
7749 + * atomic64_read_unchecked - read atomic64 variable
7750 + * @v: pointer of type atomic64_unchecked_t
7751 + *
7752 + * Atomically reads the value of @v.
7753 + * Doesn't imply a read memory barrier.
7754 + */
7755 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7756 +{
7757 + return (*(volatile const long *)&(v)->counter);
7758 }
7759
7760 /**
7761 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
7762 }
7763
7764 /**
7765 + * atomic64_set_unchecked - set atomic64 variable
7766 + * @v: pointer to type atomic64_unchecked_t
7767 + * @i: required value
7768 + *
7769 + * Atomically sets the value of @v to @i.
7770 + */
7771 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7772 +{
7773 + v->counter = i;
7774 +}
7775 +
7776 +/**
7777 * atomic64_add - add integer to atomic64 variable
7778 * @i: integer value to add
7779 * @v: pointer to type atomic64_t
7780 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
7781 */
7782 static inline void atomic64_add(long i, atomic64_t *v)
7783 {
7784 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
7785 +
7786 +#ifdef CONFIG_PAX_REFCOUNT
7787 + "jno 0f\n"
7788 + LOCK_PREFIX "subq %1,%0\n"
7789 + "int $4\n0:\n"
7790 + _ASM_EXTABLE(0b, 0b)
7791 +#endif
7792 +
7793 + : "=m" (v->counter)
7794 + : "er" (i), "m" (v->counter));
7795 +}
7796 +
7797 +/**
7798 + * atomic64_add_unchecked - add integer to atomic64 variable
7799 + * @i: integer value to add
7800 + * @v: pointer to type atomic64_unchecked_t
7801 + *
7802 + * Atomically adds @i to @v.
7803 + */
7804 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
7805 +{
7806 asm volatile(LOCK_PREFIX "addq %1,%0"
7807 : "=m" (v->counter)
7808 : "er" (i), "m" (v->counter));
7809 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
7810 */
7811 static inline void atomic64_sub(long i, atomic64_t *v)
7812 {
7813 - asm volatile(LOCK_PREFIX "subq %1,%0"
7814 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
7815 +
7816 +#ifdef CONFIG_PAX_REFCOUNT
7817 + "jno 0f\n"
7818 + LOCK_PREFIX "addq %1,%0\n"
7819 + "int $4\n0:\n"
7820 + _ASM_EXTABLE(0b, 0b)
7821 +#endif
7822 +
7823 + : "=m" (v->counter)
7824 + : "er" (i), "m" (v->counter));
7825 +}
7826 +
7827 +/**
7828 + * atomic64_sub_unchecked - subtract the atomic64 variable
7829 + * @i: integer value to subtract
7830 + * @v: pointer to type atomic64_unchecked_t
7831 + *
7832 + * Atomically subtracts @i from @v.
7833 + */
7834 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
7835 +{
7836 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
7837 : "=m" (v->counter)
7838 : "er" (i), "m" (v->counter));
7839 }
7840 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
7841 {
7842 unsigned char c;
7843
7844 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
7845 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
7846 +
7847 +#ifdef CONFIG_PAX_REFCOUNT
7848 + "jno 0f\n"
7849 + LOCK_PREFIX "addq %2,%0\n"
7850 + "int $4\n0:\n"
7851 + _ASM_EXTABLE(0b, 0b)
7852 +#endif
7853 +
7854 + "sete %1\n"
7855 : "=m" (v->counter), "=qm" (c)
7856 : "er" (i), "m" (v->counter) : "memory");
7857 return c;
7858 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
7859 */
7860 static inline void atomic64_inc(atomic64_t *v)
7861 {
7862 + asm volatile(LOCK_PREFIX "incq %0\n"
7863 +
7864 +#ifdef CONFIG_PAX_REFCOUNT
7865 + "jno 0f\n"
7866 + LOCK_PREFIX "decq %0\n"
7867 + "int $4\n0:\n"
7868 + _ASM_EXTABLE(0b, 0b)
7869 +#endif
7870 +
7871 + : "=m" (v->counter)
7872 + : "m" (v->counter));
7873 +}
7874 +
7875 +/**
7876 + * atomic64_inc_unchecked - increment atomic64 variable
7877 + * @v: pointer to type atomic64_unchecked_t
7878 + *
7879 + * Atomically increments @v by 1.
7880 + */
7881 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7882 +{
7883 asm volatile(LOCK_PREFIX "incq %0"
7884 : "=m" (v->counter)
7885 : "m" (v->counter));
7886 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
7887 */
7888 static inline void atomic64_dec(atomic64_t *v)
7889 {
7890 - asm volatile(LOCK_PREFIX "decq %0"
7891 + asm volatile(LOCK_PREFIX "decq %0\n"
7892 +
7893 +#ifdef CONFIG_PAX_REFCOUNT
7894 + "jno 0f\n"
7895 + LOCK_PREFIX "incq %0\n"
7896 + "int $4\n0:\n"
7897 + _ASM_EXTABLE(0b, 0b)
7898 +#endif
7899 +
7900 + : "=m" (v->counter)
7901 + : "m" (v->counter));
7902 +}
7903 +
7904 +/**
7905 + * atomic64_dec_unchecked - decrement atomic64 variable
7906 + * @v: pointer to type atomic64_t
7907 + *
7908 + * Atomically decrements @v by 1.
7909 + */
7910 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7911 +{
7912 + asm volatile(LOCK_PREFIX "decq %0\n"
7913 : "=m" (v->counter)
7914 : "m" (v->counter));
7915 }
7916 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
7917 {
7918 unsigned char c;
7919
7920 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
7921 + asm volatile(LOCK_PREFIX "decq %0\n"
7922 +
7923 +#ifdef CONFIG_PAX_REFCOUNT
7924 + "jno 0f\n"
7925 + LOCK_PREFIX "incq %0\n"
7926 + "int $4\n0:\n"
7927 + _ASM_EXTABLE(0b, 0b)
7928 +#endif
7929 +
7930 + "sete %1\n"
7931 : "=m" (v->counter), "=qm" (c)
7932 : "m" (v->counter) : "memory");
7933 return c != 0;
7934 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
7935 {
7936 unsigned char c;
7937
7938 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
7939 + asm volatile(LOCK_PREFIX "incq %0\n"
7940 +
7941 +#ifdef CONFIG_PAX_REFCOUNT
7942 + "jno 0f\n"
7943 + LOCK_PREFIX "decq %0\n"
7944 + "int $4\n0:\n"
7945 + _ASM_EXTABLE(0b, 0b)
7946 +#endif
7947 +
7948 + "sete %1\n"
7949 : "=m" (v->counter), "=qm" (c)
7950 : "m" (v->counter) : "memory");
7951 return c != 0;
7952 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
7953 {
7954 unsigned char c;
7955
7956 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
7957 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
7958 +
7959 +#ifdef CONFIG_PAX_REFCOUNT
7960 + "jno 0f\n"
7961 + LOCK_PREFIX "subq %2,%0\n"
7962 + "int $4\n0:\n"
7963 + _ASM_EXTABLE(0b, 0b)
7964 +#endif
7965 +
7966 + "sets %1\n"
7967 : "=m" (v->counter), "=qm" (c)
7968 : "er" (i), "m" (v->counter) : "memory");
7969 return c;
7970 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
7971 */
7972 static inline long atomic64_add_return(long i, atomic64_t *v)
7973 {
7974 + return i + xadd_check_overflow(&v->counter, i);
7975 +}
7976 +
7977 +/**
7978 + * atomic64_add_return_unchecked - add and return
7979 + * @i: integer value to add
7980 + * @v: pointer to type atomic64_unchecked_t
7981 + *
7982 + * Atomically adds @i to @v and returns @i + @v
7983 + */
7984 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7985 +{
7986 return i + xadd(&v->counter, i);
7987 }
7988
7989 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
7990 }
7991
7992 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
7993 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7994 +{
7995 + return atomic64_add_return_unchecked(1, v);
7996 +}
7997 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
7998
7999 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8000 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8001 return cmpxchg(&v->counter, old, new);
8002 }
8003
8004 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8005 +{
8006 + return cmpxchg(&v->counter, old, new);
8007 +}
8008 +
8009 static inline long atomic64_xchg(atomic64_t *v, long new)
8010 {
8011 return xchg(&v->counter, new);
8012 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
8013 */
8014 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8015 {
8016 - long c, old;
8017 + long c, old, new;
8018 c = atomic64_read(v);
8019 for (;;) {
8020 - if (unlikely(c == (u)))
8021 + if (unlikely(c == u))
8022 break;
8023 - old = atomic64_cmpxchg((v), c, c + (a));
8024 +
8025 + asm volatile("add %2,%0\n"
8026 +
8027 +#ifdef CONFIG_PAX_REFCOUNT
8028 + "jno 0f\n"
8029 + "sub %2,%0\n"
8030 + "int $4\n0:\n"
8031 + _ASM_EXTABLE(0b, 0b)
8032 +#endif
8033 +
8034 + : "=r" (new)
8035 + : "0" (c), "ir" (a));
8036 +
8037 + old = atomic64_cmpxchg(v, c, new);
8038 if (likely(old == c))
8039 break;
8040 c = old;
8041 }
8042 - return c != (u);
8043 + return c != u;
8044 }
8045
8046 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8047 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
8048 index 1775d6e..b65017f 100644
8049 --- a/arch/x86/include/asm/bitops.h
8050 +++ b/arch/x86/include/asm/bitops.h
8051 @@ -38,7 +38,7 @@
8052 * a mask operation on a byte.
8053 */
8054 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
8055 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
8056 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
8057 #define CONST_MASK(nr) (1 << ((nr) & 7))
8058
8059 /**
8060 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
8061 index 5e1a2ee..c9f9533 100644
8062 --- a/arch/x86/include/asm/boot.h
8063 +++ b/arch/x86/include/asm/boot.h
8064 @@ -11,10 +11,15 @@
8065 #include <asm/pgtable_types.h>
8066
8067 /* Physical address where kernel should be loaded. */
8068 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8069 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8070 + (CONFIG_PHYSICAL_ALIGN - 1)) \
8071 & ~(CONFIG_PHYSICAL_ALIGN - 1))
8072
8073 +#ifndef __ASSEMBLY__
8074 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
8075 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
8076 +#endif
8077 +
8078 /* Minimum kernel alignment, as a power of two */
8079 #ifdef CONFIG_X86_64
8080 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
8081 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
8082 index 48f99f1..d78ebf9 100644
8083 --- a/arch/x86/include/asm/cache.h
8084 +++ b/arch/x86/include/asm/cache.h
8085 @@ -5,12 +5,13 @@
8086
8087 /* L1 cache line size */
8088 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8089 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8090 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8091
8092 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8093 +#define __read_only __attribute__((__section__(".data..read_only")))
8094
8095 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
8096 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
8097 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
8098
8099 #ifdef CONFIG_X86_VSMP
8100 #ifdef CONFIG_SMP
8101 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
8102 index 4e12668..501d239 100644
8103 --- a/arch/x86/include/asm/cacheflush.h
8104 +++ b/arch/x86/include/asm/cacheflush.h
8105 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
8106 unsigned long pg_flags = pg->flags & _PGMT_MASK;
8107
8108 if (pg_flags == _PGMT_DEFAULT)
8109 - return -1;
8110 + return ~0UL;
8111 else if (pg_flags == _PGMT_WC)
8112 return _PAGE_CACHE_WC;
8113 else if (pg_flags == _PGMT_UC_MINUS)
8114 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
8115 index 46fc474..b02b0f9 100644
8116 --- a/arch/x86/include/asm/checksum_32.h
8117 +++ b/arch/x86/include/asm/checksum_32.h
8118 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
8119 int len, __wsum sum,
8120 int *src_err_ptr, int *dst_err_ptr);
8121
8122 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
8123 + int len, __wsum sum,
8124 + int *src_err_ptr, int *dst_err_ptr);
8125 +
8126 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
8127 + int len, __wsum sum,
8128 + int *src_err_ptr, int *dst_err_ptr);
8129 +
8130 /*
8131 * Note: when you get a NULL pointer exception here this means someone
8132 * passed in an incorrect kernel address to one of these functions.
8133 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
8134 int *err_ptr)
8135 {
8136 might_sleep();
8137 - return csum_partial_copy_generic((__force void *)src, dst,
8138 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
8139 len, sum, err_ptr, NULL);
8140 }
8141
8142 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
8143 {
8144 might_sleep();
8145 if (access_ok(VERIFY_WRITE, dst, len))
8146 - return csum_partial_copy_generic(src, (__force void *)dst,
8147 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
8148 len, sum, NULL, err_ptr);
8149
8150 if (len)
8151 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
8152 index 5d3acdf..6447a02 100644
8153 --- a/arch/x86/include/asm/cmpxchg.h
8154 +++ b/arch/x86/include/asm/cmpxchg.h
8155 @@ -14,6 +14,8 @@ extern void __cmpxchg_wrong_size(void)
8156 __compiletime_error("Bad argument size for cmpxchg");
8157 extern void __xadd_wrong_size(void)
8158 __compiletime_error("Bad argument size for xadd");
8159 +extern void __xadd_check_overflow_wrong_size(void)
8160 + __compiletime_error("Bad argument size for xadd_check_overflow");
8161
8162 /*
8163 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
8164 @@ -195,6 +197,34 @@ extern void __xadd_wrong_size(void)
8165 __ret; \
8166 })
8167
8168 +#define __xadd_check_overflow(ptr, inc, lock) \
8169 + ({ \
8170 + __typeof__ (*(ptr)) __ret = (inc); \
8171 + switch (sizeof(*(ptr))) { \
8172 + case __X86_CASE_L: \
8173 + asm volatile (lock "xaddl %0, %1\n" \
8174 + "jno 0f\n" \
8175 + "mov %0,%1\n" \
8176 + "int $4\n0:\n" \
8177 + _ASM_EXTABLE(0b, 0b) \
8178 + : "+r" (__ret), "+m" (*(ptr)) \
8179 + : : "memory", "cc"); \
8180 + break; \
8181 + case __X86_CASE_Q: \
8182 + asm volatile (lock "xaddq %q0, %1\n" \
8183 + "jno 0f\n" \
8184 + "mov %0,%1\n" \
8185 + "int $4\n0:\n" \
8186 + _ASM_EXTABLE(0b, 0b) \
8187 + : "+r" (__ret), "+m" (*(ptr)) \
8188 + : : "memory", "cc"); \
8189 + break; \
8190 + default: \
8191 + __xadd_check_overflow_wrong_size(); \
8192 + } \
8193 + __ret; \
8194 + })
8195 +
8196 /*
8197 * xadd() adds "inc" to "*ptr" and atomically returns the previous
8198 * value of "*ptr".
8199 @@ -207,4 +237,6 @@ extern void __xadd_wrong_size(void)
8200 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
8201 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
8202
8203 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
8204 +
8205 #endif /* ASM_X86_CMPXCHG_H */
8206 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
8207 index f3444f7..051a196 100644
8208 --- a/arch/x86/include/asm/cpufeature.h
8209 +++ b/arch/x86/include/asm/cpufeature.h
8210 @@ -363,7 +363,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
8211 ".section .discard,\"aw\",@progbits\n"
8212 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
8213 ".previous\n"
8214 - ".section .altinstr_replacement,\"ax\"\n"
8215 + ".section .altinstr_replacement,\"a\"\n"
8216 "3: movb $1,%0\n"
8217 "4:\n"
8218 ".previous\n"
8219 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
8220 index 41935fa..3b40db8 100644
8221 --- a/arch/x86/include/asm/desc.h
8222 +++ b/arch/x86/include/asm/desc.h
8223 @@ -4,6 +4,7 @@
8224 #include <asm/desc_defs.h>
8225 #include <asm/ldt.h>
8226 #include <asm/mmu.h>
8227 +#include <asm/pgtable.h>
8228
8229 #include <linux/smp.h>
8230
8231 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
8232
8233 desc->type = (info->read_exec_only ^ 1) << 1;
8234 desc->type |= info->contents << 2;
8235 + desc->type |= info->seg_not_present ^ 1;
8236
8237 desc->s = 1;
8238 desc->dpl = 0x3;
8239 @@ -34,17 +36,12 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
8240 }
8241
8242 extern struct desc_ptr idt_descr;
8243 -extern gate_desc idt_table[];
8244 -
8245 -struct gdt_page {
8246 - struct desc_struct gdt[GDT_ENTRIES];
8247 -} __attribute__((aligned(PAGE_SIZE)));
8248 -
8249 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
8250 +extern gate_desc idt_table[256];
8251
8252 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
8253 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
8254 {
8255 - return per_cpu(gdt_page, cpu).gdt;
8256 + return cpu_gdt_table[cpu];
8257 }
8258
8259 #ifdef CONFIG_X86_64
8260 @@ -69,8 +66,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
8261 unsigned long base, unsigned dpl, unsigned flags,
8262 unsigned short seg)
8263 {
8264 - gate->a = (seg << 16) | (base & 0xffff);
8265 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
8266 + gate->gate.offset_low = base;
8267 + gate->gate.seg = seg;
8268 + gate->gate.reserved = 0;
8269 + gate->gate.type = type;
8270 + gate->gate.s = 0;
8271 + gate->gate.dpl = dpl;
8272 + gate->gate.p = 1;
8273 + gate->gate.offset_high = base >> 16;
8274 }
8275
8276 #endif
8277 @@ -115,12 +118,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
8278
8279 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
8280 {
8281 + pax_open_kernel();
8282 memcpy(&idt[entry], gate, sizeof(*gate));
8283 + pax_close_kernel();
8284 }
8285
8286 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
8287 {
8288 + pax_open_kernel();
8289 memcpy(&ldt[entry], desc, 8);
8290 + pax_close_kernel();
8291 }
8292
8293 static inline void
8294 @@ -134,7 +141,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
8295 default: size = sizeof(*gdt); break;
8296 }
8297
8298 + pax_open_kernel();
8299 memcpy(&gdt[entry], desc, size);
8300 + pax_close_kernel();
8301 }
8302
8303 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
8304 @@ -207,7 +216,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
8305
8306 static inline void native_load_tr_desc(void)
8307 {
8308 + pax_open_kernel();
8309 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
8310 + pax_close_kernel();
8311 }
8312
8313 static inline void native_load_gdt(const struct desc_ptr *dtr)
8314 @@ -244,8 +255,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
8315 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
8316 unsigned int i;
8317
8318 + pax_open_kernel();
8319 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
8320 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
8321 + pax_close_kernel();
8322 }
8323
8324 #define _LDT_empty(info) \
8325 @@ -307,7 +320,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
8326 desc->limit = (limit >> 16) & 0xf;
8327 }
8328
8329 -static inline void _set_gate(int gate, unsigned type, void *addr,
8330 +static inline void _set_gate(int gate, unsigned type, const void *addr,
8331 unsigned dpl, unsigned ist, unsigned seg)
8332 {
8333 gate_desc s;
8334 @@ -326,7 +339,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
8335 * Pentium F0 0F bugfix can have resulted in the mapped
8336 * IDT being write-protected.
8337 */
8338 -static inline void set_intr_gate(unsigned int n, void *addr)
8339 +static inline void set_intr_gate(unsigned int n, const void *addr)
8340 {
8341 BUG_ON((unsigned)n > 0xFF);
8342 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
8343 @@ -356,19 +369,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
8344 /*
8345 * This routine sets up an interrupt gate at directory privilege level 3.
8346 */
8347 -static inline void set_system_intr_gate(unsigned int n, void *addr)
8348 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
8349 {
8350 BUG_ON((unsigned)n > 0xFF);
8351 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
8352 }
8353
8354 -static inline void set_system_trap_gate(unsigned int n, void *addr)
8355 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
8356 {
8357 BUG_ON((unsigned)n > 0xFF);
8358 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
8359 }
8360
8361 -static inline void set_trap_gate(unsigned int n, void *addr)
8362 +static inline void set_trap_gate(unsigned int n, const void *addr)
8363 {
8364 BUG_ON((unsigned)n > 0xFF);
8365 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
8366 @@ -377,19 +390,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
8367 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
8368 {
8369 BUG_ON((unsigned)n > 0xFF);
8370 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
8371 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
8372 }
8373
8374 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
8375 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
8376 {
8377 BUG_ON((unsigned)n > 0xFF);
8378 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
8379 }
8380
8381 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
8382 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
8383 {
8384 BUG_ON((unsigned)n > 0xFF);
8385 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
8386 }
8387
8388 +#ifdef CONFIG_X86_32
8389 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
8390 +{
8391 + struct desc_struct d;
8392 +
8393 + if (likely(limit))
8394 + limit = (limit - 1UL) >> PAGE_SHIFT;
8395 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
8396 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
8397 +}
8398 +#endif
8399 +
8400 #endif /* _ASM_X86_DESC_H */
8401 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
8402 index 278441f..b95a174 100644
8403 --- a/arch/x86/include/asm/desc_defs.h
8404 +++ b/arch/x86/include/asm/desc_defs.h
8405 @@ -31,6 +31,12 @@ struct desc_struct {
8406 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
8407 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
8408 };
8409 + struct {
8410 + u16 offset_low;
8411 + u16 seg;
8412 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
8413 + unsigned offset_high: 16;
8414 + } gate;
8415 };
8416 } __attribute__((packed));
8417
8418 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
8419 index 908b969..a1f4eb4 100644
8420 --- a/arch/x86/include/asm/e820.h
8421 +++ b/arch/x86/include/asm/e820.h
8422 @@ -69,7 +69,7 @@ struct e820map {
8423 #define ISA_START_ADDRESS 0xa0000
8424 #define ISA_END_ADDRESS 0x100000
8425
8426 -#define BIOS_BEGIN 0x000a0000
8427 +#define BIOS_BEGIN 0x000c0000
8428 #define BIOS_END 0x00100000
8429
8430 #define BIOS_ROM_BASE 0xffe00000
8431 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
8432 index 5f962df..7289f09 100644
8433 --- a/arch/x86/include/asm/elf.h
8434 +++ b/arch/x86/include/asm/elf.h
8435 @@ -238,7 +238,25 @@ extern int force_personality32;
8436 the loader. We need to make sure that it is out of the way of the program
8437 that it will "exec", and that there is sufficient room for the brk. */
8438
8439 +#ifdef CONFIG_PAX_SEGMEXEC
8440 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
8441 +#else
8442 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
8443 +#endif
8444 +
8445 +#ifdef CONFIG_PAX_ASLR
8446 +#ifdef CONFIG_X86_32
8447 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
8448 +
8449 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8450 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8451 +#else
8452 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
8453 +
8454 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8455 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8456 +#endif
8457 +#endif
8458
8459 /* This yields a mask that user programs can use to figure out what
8460 instruction set this CPU supports. This could be done in user space,
8461 @@ -291,9 +309,7 @@ do { \
8462
8463 #define ARCH_DLINFO \
8464 do { \
8465 - if (vdso_enabled) \
8466 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
8467 - (unsigned long)current->mm->context.vdso); \
8468 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
8469 } while (0)
8470
8471 #define AT_SYSINFO 32
8472 @@ -304,7 +320,7 @@ do { \
8473
8474 #endif /* !CONFIG_X86_32 */
8475
8476 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
8477 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
8478
8479 #define VDSO_ENTRY \
8480 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
8481 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8482 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
8483 #define compat_arch_setup_additional_pages syscall32_setup_pages
8484
8485 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8486 -#define arch_randomize_brk arch_randomize_brk
8487 -
8488 /*
8489 * True on X86_32 or when emulating IA32 on X86_64
8490 */
8491 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
8492 index cc70c1c..d96d011 100644
8493 --- a/arch/x86/include/asm/emergency-restart.h
8494 +++ b/arch/x86/include/asm/emergency-restart.h
8495 @@ -15,6 +15,6 @@ enum reboot_type {
8496
8497 extern enum reboot_type reboot_type;
8498
8499 -extern void machine_emergency_restart(void);
8500 +extern void machine_emergency_restart(void) __noreturn;
8501
8502 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
8503 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
8504 index d09bb03..4ea4194 100644
8505 --- a/arch/x86/include/asm/futex.h
8506 +++ b/arch/x86/include/asm/futex.h
8507 @@ -12,16 +12,18 @@
8508 #include <asm/system.h>
8509
8510 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
8511 + typecheck(u32 __user *, uaddr); \
8512 asm volatile("1:\t" insn "\n" \
8513 "2:\t.section .fixup,\"ax\"\n" \
8514 "3:\tmov\t%3, %1\n" \
8515 "\tjmp\t2b\n" \
8516 "\t.previous\n" \
8517 _ASM_EXTABLE(1b, 3b) \
8518 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
8519 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
8520 : "i" (-EFAULT), "0" (oparg), "1" (0))
8521
8522 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
8523 + typecheck(u32 __user *, uaddr); \
8524 asm volatile("1:\tmovl %2, %0\n" \
8525 "\tmovl\t%0, %3\n" \
8526 "\t" insn "\n" \
8527 @@ -34,7 +36,7 @@
8528 _ASM_EXTABLE(1b, 4b) \
8529 _ASM_EXTABLE(2b, 4b) \
8530 : "=&a" (oldval), "=&r" (ret), \
8531 - "+m" (*uaddr), "=&r" (tem) \
8532 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
8533 : "r" (oparg), "i" (-EFAULT), "1" (0))
8534
8535 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8536 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8537
8538 switch (op) {
8539 case FUTEX_OP_SET:
8540 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
8541 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
8542 break;
8543 case FUTEX_OP_ADD:
8544 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
8545 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
8546 uaddr, oparg);
8547 break;
8548 case FUTEX_OP_OR:
8549 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
8550 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
8551 return -EFAULT;
8552
8553 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
8554 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
8555 "2:\t.section .fixup, \"ax\"\n"
8556 "3:\tmov %3, %0\n"
8557 "\tjmp 2b\n"
8558 "\t.previous\n"
8559 _ASM_EXTABLE(1b, 3b)
8560 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
8561 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
8562 : "i" (-EFAULT), "r" (newval), "1" (oldval)
8563 : "memory"
8564 );
8565 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
8566 index eb92a6e..b98b2f4 100644
8567 --- a/arch/x86/include/asm/hw_irq.h
8568 +++ b/arch/x86/include/asm/hw_irq.h
8569 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
8570 extern void enable_IO_APIC(void);
8571
8572 /* Statistics */
8573 -extern atomic_t irq_err_count;
8574 -extern atomic_t irq_mis_count;
8575 +extern atomic_unchecked_t irq_err_count;
8576 +extern atomic_unchecked_t irq_mis_count;
8577
8578 /* EISA */
8579 extern void eisa_set_level_irq(unsigned int irq);
8580 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
8581 index c9e09ea..73888df 100644
8582 --- a/arch/x86/include/asm/i387.h
8583 +++ b/arch/x86/include/asm/i387.h
8584 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
8585 {
8586 int err;
8587
8588 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8589 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8590 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
8591 +#endif
8592 +
8593 /* See comment in fxsave() below. */
8594 #ifdef CONFIG_AS_FXSAVEQ
8595 asm volatile("1: fxrstorq %[fx]\n\t"
8596 @@ -121,6 +126,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
8597 {
8598 int err;
8599
8600 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8601 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8602 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
8603 +#endif
8604 +
8605 /*
8606 * Clear the bytes not touched by the fxsave and reserved
8607 * for the SW usage.
8608 @@ -213,13 +223,8 @@ static inline void fpu_fxsave(struct fpu *fpu)
8609 #endif /* CONFIG_X86_64 */
8610
8611 /* We need a safe address that is cheap to find and that is already
8612 - in L1 during context switch. The best choices are unfortunately
8613 - different for UP and SMP */
8614 -#ifdef CONFIG_SMP
8615 -#define safe_address (__per_cpu_offset[0])
8616 -#else
8617 -#define safe_address (kstat_cpu(0).cpustat.user)
8618 -#endif
8619 + in L1 during context switch. */
8620 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
8621
8622 /*
8623 * These must be called with preempt disabled
8624 @@ -312,7 +317,7 @@ static inline void kernel_fpu_begin(void)
8625 struct thread_info *me = current_thread_info();
8626 preempt_disable();
8627 if (me->status & TS_USEDFPU)
8628 - __save_init_fpu(me->task);
8629 + __save_init_fpu(current);
8630 else
8631 clts();
8632 }
8633 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
8634 index d8e8eef..99f81ae 100644
8635 --- a/arch/x86/include/asm/io.h
8636 +++ b/arch/x86/include/asm/io.h
8637 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
8638
8639 #include <linux/vmalloc.h>
8640
8641 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
8642 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
8643 +{
8644 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8645 +}
8646 +
8647 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
8648 +{
8649 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8650 +}
8651 +
8652 /*
8653 * Convert a virtual cached pointer to an uncached pointer
8654 */
8655 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
8656 index bba3cf8..06bc8da 100644
8657 --- a/arch/x86/include/asm/irqflags.h
8658 +++ b/arch/x86/include/asm/irqflags.h
8659 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
8660 sti; \
8661 sysexit
8662
8663 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
8664 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
8665 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
8666 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
8667 +
8668 #else
8669 #define INTERRUPT_RETURN iret
8670 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
8671 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
8672 index 5478825..839e88c 100644
8673 --- a/arch/x86/include/asm/kprobes.h
8674 +++ b/arch/x86/include/asm/kprobes.h
8675 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
8676 #define RELATIVEJUMP_SIZE 5
8677 #define RELATIVECALL_OPCODE 0xe8
8678 #define RELATIVE_ADDR_SIZE 4
8679 -#define MAX_STACK_SIZE 64
8680 -#define MIN_STACK_SIZE(ADDR) \
8681 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
8682 - THREAD_SIZE - (unsigned long)(ADDR))) \
8683 - ? (MAX_STACK_SIZE) \
8684 - : (((unsigned long)current_thread_info()) + \
8685 - THREAD_SIZE - (unsigned long)(ADDR)))
8686 +#define MAX_STACK_SIZE 64UL
8687 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
8688
8689 #define flush_insn_slot(p) do { } while (0)
8690
8691 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
8692 index b4973f4..7c4d3fc 100644
8693 --- a/arch/x86/include/asm/kvm_host.h
8694 +++ b/arch/x86/include/asm/kvm_host.h
8695 @@ -459,7 +459,7 @@ struct kvm_arch {
8696 unsigned int n_requested_mmu_pages;
8697 unsigned int n_max_mmu_pages;
8698 unsigned int indirect_shadow_pages;
8699 - atomic_t invlpg_counter;
8700 + atomic_unchecked_t invlpg_counter;
8701 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
8702 /*
8703 * Hash table of struct kvm_mmu_page.
8704 @@ -638,7 +638,7 @@ struct kvm_x86_ops {
8705 int (*check_intercept)(struct kvm_vcpu *vcpu,
8706 struct x86_instruction_info *info,
8707 enum x86_intercept_stage stage);
8708 -};
8709 +} __do_const;
8710
8711 struct kvm_arch_async_pf {
8712 u32 token;
8713 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
8714 index 9cdae5d..300d20f 100644
8715 --- a/arch/x86/include/asm/local.h
8716 +++ b/arch/x86/include/asm/local.h
8717 @@ -18,26 +18,58 @@ typedef struct {
8718
8719 static inline void local_inc(local_t *l)
8720 {
8721 - asm volatile(_ASM_INC "%0"
8722 + asm volatile(_ASM_INC "%0\n"
8723 +
8724 +#ifdef CONFIG_PAX_REFCOUNT
8725 + "jno 0f\n"
8726 + _ASM_DEC "%0\n"
8727 + "int $4\n0:\n"
8728 + _ASM_EXTABLE(0b, 0b)
8729 +#endif
8730 +
8731 : "+m" (l->a.counter));
8732 }
8733
8734 static inline void local_dec(local_t *l)
8735 {
8736 - asm volatile(_ASM_DEC "%0"
8737 + asm volatile(_ASM_DEC "%0\n"
8738 +
8739 +#ifdef CONFIG_PAX_REFCOUNT
8740 + "jno 0f\n"
8741 + _ASM_INC "%0\n"
8742 + "int $4\n0:\n"
8743 + _ASM_EXTABLE(0b, 0b)
8744 +#endif
8745 +
8746 : "+m" (l->a.counter));
8747 }
8748
8749 static inline void local_add(long i, local_t *l)
8750 {
8751 - asm volatile(_ASM_ADD "%1,%0"
8752 + asm volatile(_ASM_ADD "%1,%0\n"
8753 +
8754 +#ifdef CONFIG_PAX_REFCOUNT
8755 + "jno 0f\n"
8756 + _ASM_SUB "%1,%0\n"
8757 + "int $4\n0:\n"
8758 + _ASM_EXTABLE(0b, 0b)
8759 +#endif
8760 +
8761 : "+m" (l->a.counter)
8762 : "ir" (i));
8763 }
8764
8765 static inline void local_sub(long i, local_t *l)
8766 {
8767 - asm volatile(_ASM_SUB "%1,%0"
8768 + asm volatile(_ASM_SUB "%1,%0\n"
8769 +
8770 +#ifdef CONFIG_PAX_REFCOUNT
8771 + "jno 0f\n"
8772 + _ASM_ADD "%1,%0\n"
8773 + "int $4\n0:\n"
8774 + _ASM_EXTABLE(0b, 0b)
8775 +#endif
8776 +
8777 : "+m" (l->a.counter)
8778 : "ir" (i));
8779 }
8780 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
8781 {
8782 unsigned char c;
8783
8784 - asm volatile(_ASM_SUB "%2,%0; sete %1"
8785 + asm volatile(_ASM_SUB "%2,%0\n"
8786 +
8787 +#ifdef CONFIG_PAX_REFCOUNT
8788 + "jno 0f\n"
8789 + _ASM_ADD "%2,%0\n"
8790 + "int $4\n0:\n"
8791 + _ASM_EXTABLE(0b, 0b)
8792 +#endif
8793 +
8794 + "sete %1\n"
8795 : "+m" (l->a.counter), "=qm" (c)
8796 : "ir" (i) : "memory");
8797 return c;
8798 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
8799 {
8800 unsigned char c;
8801
8802 - asm volatile(_ASM_DEC "%0; sete %1"
8803 + asm volatile(_ASM_DEC "%0\n"
8804 +
8805 +#ifdef CONFIG_PAX_REFCOUNT
8806 + "jno 0f\n"
8807 + _ASM_INC "%0\n"
8808 + "int $4\n0:\n"
8809 + _ASM_EXTABLE(0b, 0b)
8810 +#endif
8811 +
8812 + "sete %1\n"
8813 : "+m" (l->a.counter), "=qm" (c)
8814 : : "memory");
8815 return c != 0;
8816 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
8817 {
8818 unsigned char c;
8819
8820 - asm volatile(_ASM_INC "%0; sete %1"
8821 + asm volatile(_ASM_INC "%0\n"
8822 +
8823 +#ifdef CONFIG_PAX_REFCOUNT
8824 + "jno 0f\n"
8825 + _ASM_DEC "%0\n"
8826 + "int $4\n0:\n"
8827 + _ASM_EXTABLE(0b, 0b)
8828 +#endif
8829 +
8830 + "sete %1\n"
8831 : "+m" (l->a.counter), "=qm" (c)
8832 : : "memory");
8833 return c != 0;
8834 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
8835 {
8836 unsigned char c;
8837
8838 - asm volatile(_ASM_ADD "%2,%0; sets %1"
8839 + asm volatile(_ASM_ADD "%2,%0\n"
8840 +
8841 +#ifdef CONFIG_PAX_REFCOUNT
8842 + "jno 0f\n"
8843 + _ASM_SUB "%2,%0\n"
8844 + "int $4\n0:\n"
8845 + _ASM_EXTABLE(0b, 0b)
8846 +#endif
8847 +
8848 + "sets %1\n"
8849 : "+m" (l->a.counter), "=qm" (c)
8850 : "ir" (i) : "memory");
8851 return c;
8852 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
8853 #endif
8854 /* Modern 486+ processor */
8855 __i = i;
8856 - asm volatile(_ASM_XADD "%0, %1;"
8857 + asm volatile(_ASM_XADD "%0, %1\n"
8858 +
8859 +#ifdef CONFIG_PAX_REFCOUNT
8860 + "jno 0f\n"
8861 + _ASM_MOV "%0,%1\n"
8862 + "int $4\n0:\n"
8863 + _ASM_EXTABLE(0b, 0b)
8864 +#endif
8865 +
8866 : "+r" (i), "+m" (l->a.counter)
8867 : : "memory");
8868 return i + __i;
8869 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
8870 index 593e51d..fa69c9a 100644
8871 --- a/arch/x86/include/asm/mman.h
8872 +++ b/arch/x86/include/asm/mman.h
8873 @@ -5,4 +5,14 @@
8874
8875 #include <asm-generic/mman.h>
8876
8877 +#ifdef __KERNEL__
8878 +#ifndef __ASSEMBLY__
8879 +#ifdef CONFIG_X86_32
8880 +#define arch_mmap_check i386_mmap_check
8881 +int i386_mmap_check(unsigned long addr, unsigned long len,
8882 + unsigned long flags);
8883 +#endif
8884 +#endif
8885 +#endif
8886 +
8887 #endif /* _ASM_X86_MMAN_H */
8888 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
8889 index 5f55e69..e20bfb1 100644
8890 --- a/arch/x86/include/asm/mmu.h
8891 +++ b/arch/x86/include/asm/mmu.h
8892 @@ -9,7 +9,7 @@
8893 * we put the segment information here.
8894 */
8895 typedef struct {
8896 - void *ldt;
8897 + struct desc_struct *ldt;
8898 int size;
8899
8900 #ifdef CONFIG_X86_64
8901 @@ -18,7 +18,19 @@ typedef struct {
8902 #endif
8903
8904 struct mutex lock;
8905 - void *vdso;
8906 + unsigned long vdso;
8907 +
8908 +#ifdef CONFIG_X86_32
8909 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
8910 + unsigned long user_cs_base;
8911 + unsigned long user_cs_limit;
8912 +
8913 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
8914 + cpumask_t cpu_user_cs_mask;
8915 +#endif
8916 +
8917 +#endif
8918 +#endif
8919 } mm_context_t;
8920
8921 #ifdef CONFIG_SMP
8922 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
8923 index 6902152..399f3a2 100644
8924 --- a/arch/x86/include/asm/mmu_context.h
8925 +++ b/arch/x86/include/asm/mmu_context.h
8926 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
8927
8928 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
8929 {
8930 +
8931 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8932 + unsigned int i;
8933 + pgd_t *pgd;
8934 +
8935 + pax_open_kernel();
8936 + pgd = get_cpu_pgd(smp_processor_id());
8937 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
8938 + set_pgd_batched(pgd+i, native_make_pgd(0));
8939 + pax_close_kernel();
8940 +#endif
8941 +
8942 #ifdef CONFIG_SMP
8943 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
8944 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
8945 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
8946 struct task_struct *tsk)
8947 {
8948 unsigned cpu = smp_processor_id();
8949 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8950 + int tlbstate = TLBSTATE_OK;
8951 +#endif
8952
8953 if (likely(prev != next)) {
8954 #ifdef CONFIG_SMP
8955 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8956 + tlbstate = percpu_read(cpu_tlbstate.state);
8957 +#endif
8958 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
8959 percpu_write(cpu_tlbstate.active_mm, next);
8960 #endif
8961 cpumask_set_cpu(cpu, mm_cpumask(next));
8962
8963 /* Re-load page tables */
8964 +#ifdef CONFIG_PAX_PER_CPU_PGD
8965 + pax_open_kernel();
8966 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
8967 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
8968 + pax_close_kernel();
8969 + load_cr3(get_cpu_pgd(cpu));
8970 +#else
8971 load_cr3(next->pgd);
8972 +#endif
8973
8974 /* stop flush ipis for the previous mm */
8975 cpumask_clear_cpu(cpu, mm_cpumask(prev));
8976 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
8977 */
8978 if (unlikely(prev->context.ldt != next->context.ldt))
8979 load_LDT_nolock(&next->context);
8980 - }
8981 +
8982 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
8983 + if (!(__supported_pte_mask & _PAGE_NX)) {
8984 + smp_mb__before_clear_bit();
8985 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
8986 + smp_mb__after_clear_bit();
8987 + cpu_set(cpu, next->context.cpu_user_cs_mask);
8988 + }
8989 +#endif
8990 +
8991 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8992 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
8993 + prev->context.user_cs_limit != next->context.user_cs_limit))
8994 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8995 #ifdef CONFIG_SMP
8996 + else if (unlikely(tlbstate != TLBSTATE_OK))
8997 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8998 +#endif
8999 +#endif
9000 +
9001 + }
9002 else {
9003 +
9004 +#ifdef CONFIG_PAX_PER_CPU_PGD
9005 + pax_open_kernel();
9006 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9007 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9008 + pax_close_kernel();
9009 + load_cr3(get_cpu_pgd(cpu));
9010 +#endif
9011 +
9012 +#ifdef CONFIG_SMP
9013 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
9014 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
9015
9016 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
9017 * tlb flush IPI delivery. We must reload CR3
9018 * to make sure to use no freed page tables.
9019 */
9020 +
9021 +#ifndef CONFIG_PAX_PER_CPU_PGD
9022 load_cr3(next->pgd);
9023 +#endif
9024 +
9025 load_LDT_nolock(&next->context);
9026 +
9027 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
9028 + if (!(__supported_pte_mask & _PAGE_NX))
9029 + cpu_set(cpu, next->context.cpu_user_cs_mask);
9030 +#endif
9031 +
9032 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9033 +#ifdef CONFIG_PAX_PAGEEXEC
9034 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
9035 +#endif
9036 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9037 +#endif
9038 +
9039 }
9040 +#endif
9041 }
9042 -#endif
9043 }
9044
9045 #define activate_mm(prev, next) \
9046 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
9047 index 9eae775..c914fea 100644
9048 --- a/arch/x86/include/asm/module.h
9049 +++ b/arch/x86/include/asm/module.h
9050 @@ -5,6 +5,7 @@
9051
9052 #ifdef CONFIG_X86_64
9053 /* X86_64 does not define MODULE_PROC_FAMILY */
9054 +#define MODULE_PROC_FAMILY ""
9055 #elif defined CONFIG_M386
9056 #define MODULE_PROC_FAMILY "386 "
9057 #elif defined CONFIG_M486
9058 @@ -59,8 +60,20 @@
9059 #error unknown processor family
9060 #endif
9061
9062 -#ifdef CONFIG_X86_32
9063 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
9064 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9065 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
9066 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
9067 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
9068 +#else
9069 +#define MODULE_PAX_KERNEXEC ""
9070 #endif
9071
9072 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9073 +#define MODULE_PAX_UDEREF "UDEREF "
9074 +#else
9075 +#define MODULE_PAX_UDEREF ""
9076 +#endif
9077 +
9078 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
9079 +
9080 #endif /* _ASM_X86_MODULE_H */
9081 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
9082 index 7639dbf..e08a58c 100644
9083 --- a/arch/x86/include/asm/page_64_types.h
9084 +++ b/arch/x86/include/asm/page_64_types.h
9085 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
9086
9087 /* duplicated to the one in bootmem.h */
9088 extern unsigned long max_pfn;
9089 -extern unsigned long phys_base;
9090 +extern const unsigned long phys_base;
9091
9092 extern unsigned long __phys_addr(unsigned long);
9093 #define __phys_reloc_hide(x) (x)
9094 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
9095 index a7d2db9..edb023e 100644
9096 --- a/arch/x86/include/asm/paravirt.h
9097 +++ b/arch/x86/include/asm/paravirt.h
9098 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
9099 val);
9100 }
9101
9102 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
9103 +{
9104 + pgdval_t val = native_pgd_val(pgd);
9105 +
9106 + if (sizeof(pgdval_t) > sizeof(long))
9107 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
9108 + val, (u64)val >> 32);
9109 + else
9110 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
9111 + val);
9112 +}
9113 +
9114 static inline void pgd_clear(pgd_t *pgdp)
9115 {
9116 set_pgd(pgdp, __pgd(0));
9117 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
9118 pv_mmu_ops.set_fixmap(idx, phys, flags);
9119 }
9120
9121 +#ifdef CONFIG_PAX_KERNEXEC
9122 +static inline unsigned long pax_open_kernel(void)
9123 +{
9124 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
9125 +}
9126 +
9127 +static inline unsigned long pax_close_kernel(void)
9128 +{
9129 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
9130 +}
9131 +#else
9132 +static inline unsigned long pax_open_kernel(void) { return 0; }
9133 +static inline unsigned long pax_close_kernel(void) { return 0; }
9134 +#endif
9135 +
9136 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
9137
9138 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
9139 @@ -964,7 +991,7 @@ extern void default_banner(void);
9140
9141 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
9142 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
9143 -#define PARA_INDIRECT(addr) *%cs:addr
9144 +#define PARA_INDIRECT(addr) *%ss:addr
9145 #endif
9146
9147 #define INTERRUPT_RETURN \
9148 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
9149 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
9150 CLBR_NONE, \
9151 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
9152 +
9153 +#define GET_CR0_INTO_RDI \
9154 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
9155 + mov %rax,%rdi
9156 +
9157 +#define SET_RDI_INTO_CR0 \
9158 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
9159 +
9160 +#define GET_CR3_INTO_RDI \
9161 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
9162 + mov %rax,%rdi
9163 +
9164 +#define SET_RDI_INTO_CR3 \
9165 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
9166 +
9167 #endif /* CONFIG_X86_32 */
9168
9169 #endif /* __ASSEMBLY__ */
9170 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
9171 index 8e8b9a4..f07d725 100644
9172 --- a/arch/x86/include/asm/paravirt_types.h
9173 +++ b/arch/x86/include/asm/paravirt_types.h
9174 @@ -84,20 +84,20 @@ struct pv_init_ops {
9175 */
9176 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
9177 unsigned long addr, unsigned len);
9178 -};
9179 +} __no_const;
9180
9181
9182 struct pv_lazy_ops {
9183 /* Set deferred update mode, used for batching operations. */
9184 void (*enter)(void);
9185 void (*leave)(void);
9186 -};
9187 +} __no_const;
9188
9189 struct pv_time_ops {
9190 unsigned long long (*sched_clock)(void);
9191 unsigned long long (*steal_clock)(int cpu);
9192 unsigned long (*get_tsc_khz)(void);
9193 -};
9194 +} __no_const;
9195
9196 struct pv_cpu_ops {
9197 /* hooks for various privileged instructions */
9198 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
9199
9200 void (*start_context_switch)(struct task_struct *prev);
9201 void (*end_context_switch)(struct task_struct *next);
9202 -};
9203 +} __no_const;
9204
9205 struct pv_irq_ops {
9206 /*
9207 @@ -224,7 +224,7 @@ struct pv_apic_ops {
9208 unsigned long start_eip,
9209 unsigned long start_esp);
9210 #endif
9211 -};
9212 +} __no_const;
9213
9214 struct pv_mmu_ops {
9215 unsigned long (*read_cr2)(void);
9216 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
9217 struct paravirt_callee_save make_pud;
9218
9219 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
9220 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
9221 #endif /* PAGETABLE_LEVELS == 4 */
9222 #endif /* PAGETABLE_LEVELS >= 3 */
9223
9224 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
9225 an mfn. We can tell which is which from the index. */
9226 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
9227 phys_addr_t phys, pgprot_t flags);
9228 +
9229 +#ifdef CONFIG_PAX_KERNEXEC
9230 + unsigned long (*pax_open_kernel)(void);
9231 + unsigned long (*pax_close_kernel)(void);
9232 +#endif
9233 +
9234 };
9235
9236 struct arch_spinlock;
9237 @@ -334,7 +341,7 @@ struct pv_lock_ops {
9238 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
9239 int (*spin_trylock)(struct arch_spinlock *lock);
9240 void (*spin_unlock)(struct arch_spinlock *lock);
9241 -};
9242 +} __no_const;
9243
9244 /* This contains all the paravirt structures: we get a convenient
9245 * number for each function using the offset which we use to indicate
9246 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
9247 index b4389a4..b7ff22c 100644
9248 --- a/arch/x86/include/asm/pgalloc.h
9249 +++ b/arch/x86/include/asm/pgalloc.h
9250 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
9251 pmd_t *pmd, pte_t *pte)
9252 {
9253 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9254 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
9255 +}
9256 +
9257 +static inline void pmd_populate_user(struct mm_struct *mm,
9258 + pmd_t *pmd, pte_t *pte)
9259 +{
9260 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9261 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
9262 }
9263
9264 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
9265 index 98391db..8f6984e 100644
9266 --- a/arch/x86/include/asm/pgtable-2level.h
9267 +++ b/arch/x86/include/asm/pgtable-2level.h
9268 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
9269
9270 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9271 {
9272 + pax_open_kernel();
9273 *pmdp = pmd;
9274 + pax_close_kernel();
9275 }
9276
9277 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9278 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
9279 index effff47..f9e4035 100644
9280 --- a/arch/x86/include/asm/pgtable-3level.h
9281 +++ b/arch/x86/include/asm/pgtable-3level.h
9282 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9283
9284 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9285 {
9286 + pax_open_kernel();
9287 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
9288 + pax_close_kernel();
9289 }
9290
9291 static inline void native_set_pud(pud_t *pudp, pud_t pud)
9292 {
9293 + pax_open_kernel();
9294 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
9295 + pax_close_kernel();
9296 }
9297
9298 /*
9299 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
9300 index 18601c8..3d716d1 100644
9301 --- a/arch/x86/include/asm/pgtable.h
9302 +++ b/arch/x86/include/asm/pgtable.h
9303 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
9304
9305 #ifndef __PAGETABLE_PUD_FOLDED
9306 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
9307 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
9308 #define pgd_clear(pgd) native_pgd_clear(pgd)
9309 #endif
9310
9311 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
9312
9313 #define arch_end_context_switch(prev) do {} while(0)
9314
9315 +#define pax_open_kernel() native_pax_open_kernel()
9316 +#define pax_close_kernel() native_pax_close_kernel()
9317 #endif /* CONFIG_PARAVIRT */
9318
9319 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
9320 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
9321 +
9322 +#ifdef CONFIG_PAX_KERNEXEC
9323 +static inline unsigned long native_pax_open_kernel(void)
9324 +{
9325 + unsigned long cr0;
9326 +
9327 + preempt_disable();
9328 + barrier();
9329 + cr0 = read_cr0() ^ X86_CR0_WP;
9330 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
9331 + write_cr0(cr0);
9332 + return cr0 ^ X86_CR0_WP;
9333 +}
9334 +
9335 +static inline unsigned long native_pax_close_kernel(void)
9336 +{
9337 + unsigned long cr0;
9338 +
9339 + cr0 = read_cr0() ^ X86_CR0_WP;
9340 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
9341 + write_cr0(cr0);
9342 + barrier();
9343 + preempt_enable_no_resched();
9344 + return cr0 ^ X86_CR0_WP;
9345 +}
9346 +#else
9347 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
9348 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
9349 +#endif
9350 +
9351 /*
9352 * The following only work if pte_present() is true.
9353 * Undefined behaviour if not..
9354 */
9355 +static inline int pte_user(pte_t pte)
9356 +{
9357 + return pte_val(pte) & _PAGE_USER;
9358 +}
9359 +
9360 static inline int pte_dirty(pte_t pte)
9361 {
9362 return pte_flags(pte) & _PAGE_DIRTY;
9363 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
9364 return pte_clear_flags(pte, _PAGE_RW);
9365 }
9366
9367 +static inline pte_t pte_mkread(pte_t pte)
9368 +{
9369 + return __pte(pte_val(pte) | _PAGE_USER);
9370 +}
9371 +
9372 static inline pte_t pte_mkexec(pte_t pte)
9373 {
9374 - return pte_clear_flags(pte, _PAGE_NX);
9375 +#ifdef CONFIG_X86_PAE
9376 + if (__supported_pte_mask & _PAGE_NX)
9377 + return pte_clear_flags(pte, _PAGE_NX);
9378 + else
9379 +#endif
9380 + return pte_set_flags(pte, _PAGE_USER);
9381 +}
9382 +
9383 +static inline pte_t pte_exprotect(pte_t pte)
9384 +{
9385 +#ifdef CONFIG_X86_PAE
9386 + if (__supported_pte_mask & _PAGE_NX)
9387 + return pte_set_flags(pte, _PAGE_NX);
9388 + else
9389 +#endif
9390 + return pte_clear_flags(pte, _PAGE_USER);
9391 }
9392
9393 static inline pte_t pte_mkdirty(pte_t pte)
9394 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
9395 #endif
9396
9397 #ifndef __ASSEMBLY__
9398 +
9399 +#ifdef CONFIG_PAX_PER_CPU_PGD
9400 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
9401 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
9402 +{
9403 + return cpu_pgd[cpu];
9404 +}
9405 +#endif
9406 +
9407 #include <linux/mm_types.h>
9408
9409 static inline int pte_none(pte_t pte)
9410 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
9411
9412 static inline int pgd_bad(pgd_t pgd)
9413 {
9414 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
9415 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
9416 }
9417
9418 static inline int pgd_none(pgd_t pgd)
9419 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
9420 * pgd_offset() returns a (pgd_t *)
9421 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
9422 */
9423 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
9424 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
9425 +
9426 +#ifdef CONFIG_PAX_PER_CPU_PGD
9427 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
9428 +#endif
9429 +
9430 /*
9431 * a shortcut which implies the use of the kernel's pgd, instead
9432 * of a process's
9433 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
9434 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
9435 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
9436
9437 +#ifdef CONFIG_X86_32
9438 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
9439 +#else
9440 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
9441 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
9442 +
9443 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9444 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
9445 +#else
9446 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
9447 +#endif
9448 +
9449 +#endif
9450 +
9451 #ifndef __ASSEMBLY__
9452
9453 extern int direct_gbpages;
9454 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
9455 * dst and src can be on the same page, but the range must not overlap,
9456 * and must not cross a page boundary.
9457 */
9458 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
9459 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
9460 {
9461 - memcpy(dst, src, count * sizeof(pgd_t));
9462 + pax_open_kernel();
9463 + while (count--)
9464 + *dst++ = *src++;
9465 + pax_close_kernel();
9466 }
9467
9468 +#ifdef CONFIG_PAX_PER_CPU_PGD
9469 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9470 +#endif
9471 +
9472 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9473 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9474 +#else
9475 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
9476 +#endif
9477
9478 #include <asm-generic/pgtable.h>
9479 #endif /* __ASSEMBLY__ */
9480 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
9481 index 0c92113..34a77c6 100644
9482 --- a/arch/x86/include/asm/pgtable_32.h
9483 +++ b/arch/x86/include/asm/pgtable_32.h
9484 @@ -25,9 +25,6 @@
9485 struct mm_struct;
9486 struct vm_area_struct;
9487
9488 -extern pgd_t swapper_pg_dir[1024];
9489 -extern pgd_t initial_page_table[1024];
9490 -
9491 static inline void pgtable_cache_init(void) { }
9492 static inline void check_pgt_cache(void) { }
9493 void paging_init(void);
9494 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
9495 # include <asm/pgtable-2level.h>
9496 #endif
9497
9498 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
9499 +extern pgd_t initial_page_table[PTRS_PER_PGD];
9500 +#ifdef CONFIG_X86_PAE
9501 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
9502 +#endif
9503 +
9504 #if defined(CONFIG_HIGHPTE)
9505 #define pte_offset_map(dir, address) \
9506 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
9507 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
9508 /* Clear a kernel PTE and flush it from the TLB */
9509 #define kpte_clear_flush(ptep, vaddr) \
9510 do { \
9511 + pax_open_kernel(); \
9512 pte_clear(&init_mm, (vaddr), (ptep)); \
9513 + pax_close_kernel(); \
9514 __flush_tlb_one((vaddr)); \
9515 } while (0)
9516
9517 @@ -74,6 +79,9 @@ do { \
9518
9519 #endif /* !__ASSEMBLY__ */
9520
9521 +#define HAVE_ARCH_UNMAPPED_AREA
9522 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
9523 +
9524 /*
9525 * kern_addr_valid() is (1) for FLATMEM and (0) for
9526 * SPARSEMEM and DISCONTIGMEM
9527 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
9528 index ed5903b..c7fe163 100644
9529 --- a/arch/x86/include/asm/pgtable_32_types.h
9530 +++ b/arch/x86/include/asm/pgtable_32_types.h
9531 @@ -8,7 +8,7 @@
9532 */
9533 #ifdef CONFIG_X86_PAE
9534 # include <asm/pgtable-3level_types.h>
9535 -# define PMD_SIZE (1UL << PMD_SHIFT)
9536 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
9537 # define PMD_MASK (~(PMD_SIZE - 1))
9538 #else
9539 # include <asm/pgtable-2level_types.h>
9540 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
9541 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
9542 #endif
9543
9544 +#ifdef CONFIG_PAX_KERNEXEC
9545 +#ifndef __ASSEMBLY__
9546 +extern unsigned char MODULES_EXEC_VADDR[];
9547 +extern unsigned char MODULES_EXEC_END[];
9548 +#endif
9549 +#include <asm/boot.h>
9550 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
9551 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
9552 +#else
9553 +#define ktla_ktva(addr) (addr)
9554 +#define ktva_ktla(addr) (addr)
9555 +#endif
9556 +
9557 #define MODULES_VADDR VMALLOC_START
9558 #define MODULES_END VMALLOC_END
9559 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
9560 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
9561 index 975f709..107976d 100644
9562 --- a/arch/x86/include/asm/pgtable_64.h
9563 +++ b/arch/x86/include/asm/pgtable_64.h
9564 @@ -16,10 +16,14 @@
9565
9566 extern pud_t level3_kernel_pgt[512];
9567 extern pud_t level3_ident_pgt[512];
9568 +extern pud_t level3_vmalloc_start_pgt[512];
9569 +extern pud_t level3_vmalloc_end_pgt[512];
9570 +extern pud_t level3_vmemmap_pgt[512];
9571 +extern pud_t level2_vmemmap_pgt[512];
9572 extern pmd_t level2_kernel_pgt[512];
9573 extern pmd_t level2_fixmap_pgt[512];
9574 -extern pmd_t level2_ident_pgt[512];
9575 -extern pgd_t init_level4_pgt[];
9576 +extern pmd_t level2_ident_pgt[512*2];
9577 +extern pgd_t init_level4_pgt[512];
9578
9579 #define swapper_pg_dir init_level4_pgt
9580
9581 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9582
9583 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9584 {
9585 + pax_open_kernel();
9586 *pmdp = pmd;
9587 + pax_close_kernel();
9588 }
9589
9590 static inline void native_pmd_clear(pmd_t *pmd)
9591 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
9592
9593 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
9594 {
9595 + pax_open_kernel();
9596 + *pgdp = pgd;
9597 + pax_close_kernel();
9598 +}
9599 +
9600 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
9601 +{
9602 *pgdp = pgd;
9603 }
9604
9605 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
9606 index 766ea16..5b96cb3 100644
9607 --- a/arch/x86/include/asm/pgtable_64_types.h
9608 +++ b/arch/x86/include/asm/pgtable_64_types.h
9609 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
9610 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
9611 #define MODULES_END _AC(0xffffffffff000000, UL)
9612 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
9613 +#define MODULES_EXEC_VADDR MODULES_VADDR
9614 +#define MODULES_EXEC_END MODULES_END
9615 +
9616 +#define ktla_ktva(addr) (addr)
9617 +#define ktva_ktla(addr) (addr)
9618
9619 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
9620 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
9621 index 013286a..8b42f4f 100644
9622 --- a/arch/x86/include/asm/pgtable_types.h
9623 +++ b/arch/x86/include/asm/pgtable_types.h
9624 @@ -16,13 +16,12 @@
9625 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
9626 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
9627 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
9628 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
9629 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
9630 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
9631 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
9632 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
9633 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
9634 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
9635 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
9636 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
9637 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
9638 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
9639
9640 /* If _PAGE_BIT_PRESENT is clear, we use these: */
9641 @@ -40,7 +39,6 @@
9642 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
9643 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
9644 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
9645 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
9646 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
9647 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
9648 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
9649 @@ -57,8 +55,10 @@
9650
9651 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
9652 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
9653 -#else
9654 +#elif defined(CONFIG_KMEMCHECK)
9655 #define _PAGE_NX (_AT(pteval_t, 0))
9656 +#else
9657 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
9658 #endif
9659
9660 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
9661 @@ -96,6 +96,9 @@
9662 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
9663 _PAGE_ACCESSED)
9664
9665 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
9666 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
9667 +
9668 #define __PAGE_KERNEL_EXEC \
9669 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
9670 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
9671 @@ -106,7 +109,7 @@
9672 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
9673 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
9674 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
9675 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
9676 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
9677 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
9678 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
9679 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
9680 @@ -168,8 +171,8 @@
9681 * bits are combined, this will alow user to access the high address mapped
9682 * VDSO in the presence of CONFIG_COMPAT_VDSO
9683 */
9684 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
9685 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
9686 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9687 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9688 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
9689 #endif
9690
9691 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
9692 {
9693 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
9694 }
9695 +#endif
9696
9697 +#if PAGETABLE_LEVELS == 3
9698 +#include <asm-generic/pgtable-nopud.h>
9699 +#endif
9700 +
9701 +#if PAGETABLE_LEVELS == 2
9702 +#include <asm-generic/pgtable-nopmd.h>
9703 +#endif
9704 +
9705 +#ifndef __ASSEMBLY__
9706 #if PAGETABLE_LEVELS > 3
9707 typedef struct { pudval_t pud; } pud_t;
9708
9709 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
9710 return pud.pud;
9711 }
9712 #else
9713 -#include <asm-generic/pgtable-nopud.h>
9714 -
9715 static inline pudval_t native_pud_val(pud_t pud)
9716 {
9717 return native_pgd_val(pud.pgd);
9718 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
9719 return pmd.pmd;
9720 }
9721 #else
9722 -#include <asm-generic/pgtable-nopmd.h>
9723 -
9724 static inline pmdval_t native_pmd_val(pmd_t pmd)
9725 {
9726 return native_pgd_val(pmd.pud.pgd);
9727 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
9728
9729 extern pteval_t __supported_pte_mask;
9730 extern void set_nx(void);
9731 -extern int nx_enabled;
9732
9733 #define pgprot_writecombine pgprot_writecombine
9734 extern pgprot_t pgprot_writecombine(pgprot_t prot);
9735 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
9736 index b650435..eefa566 100644
9737 --- a/arch/x86/include/asm/processor.h
9738 +++ b/arch/x86/include/asm/processor.h
9739 @@ -268,7 +268,7 @@ struct tss_struct {
9740
9741 } ____cacheline_aligned;
9742
9743 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
9744 +extern struct tss_struct init_tss[NR_CPUS];
9745
9746 /*
9747 * Save the original ist values for checking stack pointers during debugging
9748 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
9749 */
9750 #define TASK_SIZE PAGE_OFFSET
9751 #define TASK_SIZE_MAX TASK_SIZE
9752 +
9753 +#ifdef CONFIG_PAX_SEGMEXEC
9754 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
9755 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
9756 +#else
9757 #define STACK_TOP TASK_SIZE
9758 -#define STACK_TOP_MAX STACK_TOP
9759 +#endif
9760 +
9761 +#define STACK_TOP_MAX TASK_SIZE
9762
9763 #define INIT_THREAD { \
9764 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
9765 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9766 .vm86_info = NULL, \
9767 .sysenter_cs = __KERNEL_CS, \
9768 .io_bitmap_ptr = NULL, \
9769 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
9770 */
9771 #define INIT_TSS { \
9772 .x86_tss = { \
9773 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
9774 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9775 .ss0 = __KERNEL_DS, \
9776 .ss1 = __KERNEL_CS, \
9777 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
9778 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
9779 extern unsigned long thread_saved_pc(struct task_struct *tsk);
9780
9781 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
9782 -#define KSTK_TOP(info) \
9783 -({ \
9784 - unsigned long *__ptr = (unsigned long *)(info); \
9785 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
9786 -})
9787 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
9788
9789 /*
9790 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
9791 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
9792 #define task_pt_regs(task) \
9793 ({ \
9794 struct pt_regs *__regs__; \
9795 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
9796 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
9797 __regs__ - 1; \
9798 })
9799
9800 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
9801 /*
9802 * User space process size. 47bits minus one guard page.
9803 */
9804 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
9805 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
9806
9807 /* This decides where the kernel will search for a free chunk of vm
9808 * space during mmap's.
9809 */
9810 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
9811 - 0xc0000000 : 0xFFFFe000)
9812 + 0xc0000000 : 0xFFFFf000)
9813
9814 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
9815 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
9816 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
9817 #define STACK_TOP_MAX TASK_SIZE_MAX
9818
9819 #define INIT_THREAD { \
9820 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
9821 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
9822 }
9823
9824 #define INIT_TSS { \
9825 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
9826 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
9827 }
9828
9829 /*
9830 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
9831 */
9832 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
9833
9834 +#ifdef CONFIG_PAX_SEGMEXEC
9835 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
9836 +#endif
9837 +
9838 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
9839
9840 /* Get/set a process' ability to use the timestamp counter instruction */
9841 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
9842 index 3566454..4bdfb8c 100644
9843 --- a/arch/x86/include/asm/ptrace.h
9844 +++ b/arch/x86/include/asm/ptrace.h
9845 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
9846 }
9847
9848 /*
9849 - * user_mode_vm(regs) determines whether a register set came from user mode.
9850 + * user_mode(regs) determines whether a register set came from user mode.
9851 * This is true if V8086 mode was enabled OR if the register set was from
9852 * protected mode with RPL-3 CS value. This tricky test checks that with
9853 * one comparison. Many places in the kernel can bypass this full check
9854 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
9855 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
9856 + * be used.
9857 */
9858 -static inline int user_mode(struct pt_regs *regs)
9859 +static inline int user_mode_novm(struct pt_regs *regs)
9860 {
9861 #ifdef CONFIG_X86_32
9862 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
9863 #else
9864 - return !!(regs->cs & 3);
9865 + return !!(regs->cs & SEGMENT_RPL_MASK);
9866 #endif
9867 }
9868
9869 -static inline int user_mode_vm(struct pt_regs *regs)
9870 +static inline int user_mode(struct pt_regs *regs)
9871 {
9872 #ifdef CONFIG_X86_32
9873 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
9874 USER_RPL;
9875 #else
9876 - return user_mode(regs);
9877 + return user_mode_novm(regs);
9878 #endif
9879 }
9880
9881 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
9882 #ifdef CONFIG_X86_64
9883 static inline bool user_64bit_mode(struct pt_regs *regs)
9884 {
9885 + unsigned long cs = regs->cs & 0xffff;
9886 #ifndef CONFIG_PARAVIRT
9887 /*
9888 * On non-paravirt systems, this is the only long mode CPL 3
9889 * selector. We do not allow long mode selectors in the LDT.
9890 */
9891 - return regs->cs == __USER_CS;
9892 + return cs == __USER_CS;
9893 #else
9894 /* Headers are too twisted for this to go in paravirt.h. */
9895 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
9896 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
9897 #endif
9898 }
9899 #endif
9900 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
9901 index 92f29706..a79cbbb 100644
9902 --- a/arch/x86/include/asm/reboot.h
9903 +++ b/arch/x86/include/asm/reboot.h
9904 @@ -6,19 +6,19 @@
9905 struct pt_regs;
9906
9907 struct machine_ops {
9908 - void (*restart)(char *cmd);
9909 - void (*halt)(void);
9910 - void (*power_off)(void);
9911 + void (* __noreturn restart)(char *cmd);
9912 + void (* __noreturn halt)(void);
9913 + void (* __noreturn power_off)(void);
9914 void (*shutdown)(void);
9915 void (*crash_shutdown)(struct pt_regs *);
9916 - void (*emergency_restart)(void);
9917 -};
9918 + void (* __noreturn emergency_restart)(void);
9919 +} __no_const;
9920
9921 extern struct machine_ops machine_ops;
9922
9923 void native_machine_crash_shutdown(struct pt_regs *regs);
9924 void native_machine_shutdown(void);
9925 -void machine_real_restart(unsigned int type);
9926 +void machine_real_restart(unsigned int type) __noreturn;
9927 /* These must match dispatch_table in reboot_32.S */
9928 #define MRR_BIOS 0
9929 #define MRR_APM 1
9930 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
9931 index 2dbe4a7..ce1db00 100644
9932 --- a/arch/x86/include/asm/rwsem.h
9933 +++ b/arch/x86/include/asm/rwsem.h
9934 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
9935 {
9936 asm volatile("# beginning down_read\n\t"
9937 LOCK_PREFIX _ASM_INC "(%1)\n\t"
9938 +
9939 +#ifdef CONFIG_PAX_REFCOUNT
9940 + "jno 0f\n"
9941 + LOCK_PREFIX _ASM_DEC "(%1)\n"
9942 + "int $4\n0:\n"
9943 + _ASM_EXTABLE(0b, 0b)
9944 +#endif
9945 +
9946 /* adds 0x00000001 */
9947 " jns 1f\n"
9948 " call call_rwsem_down_read_failed\n"
9949 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
9950 "1:\n\t"
9951 " mov %1,%2\n\t"
9952 " add %3,%2\n\t"
9953 +
9954 +#ifdef CONFIG_PAX_REFCOUNT
9955 + "jno 0f\n"
9956 + "sub %3,%2\n"
9957 + "int $4\n0:\n"
9958 + _ASM_EXTABLE(0b, 0b)
9959 +#endif
9960 +
9961 " jle 2f\n\t"
9962 LOCK_PREFIX " cmpxchg %2,%0\n\t"
9963 " jnz 1b\n\t"
9964 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
9965 long tmp;
9966 asm volatile("# beginning down_write\n\t"
9967 LOCK_PREFIX " xadd %1,(%2)\n\t"
9968 +
9969 +#ifdef CONFIG_PAX_REFCOUNT
9970 + "jno 0f\n"
9971 + "mov %1,(%2)\n"
9972 + "int $4\n0:\n"
9973 + _ASM_EXTABLE(0b, 0b)
9974 +#endif
9975 +
9976 /* adds 0xffff0001, returns the old value */
9977 " test %1,%1\n\t"
9978 /* was the count 0 before? */
9979 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
9980 long tmp;
9981 asm volatile("# beginning __up_read\n\t"
9982 LOCK_PREFIX " xadd %1,(%2)\n\t"
9983 +
9984 +#ifdef CONFIG_PAX_REFCOUNT
9985 + "jno 0f\n"
9986 + "mov %1,(%2)\n"
9987 + "int $4\n0:\n"
9988 + _ASM_EXTABLE(0b, 0b)
9989 +#endif
9990 +
9991 /* subtracts 1, returns the old value */
9992 " jns 1f\n\t"
9993 " call call_rwsem_wake\n" /* expects old value in %edx */
9994 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
9995 long tmp;
9996 asm volatile("# beginning __up_write\n\t"
9997 LOCK_PREFIX " xadd %1,(%2)\n\t"
9998 +
9999 +#ifdef CONFIG_PAX_REFCOUNT
10000 + "jno 0f\n"
10001 + "mov %1,(%2)\n"
10002 + "int $4\n0:\n"
10003 + _ASM_EXTABLE(0b, 0b)
10004 +#endif
10005 +
10006 /* subtracts 0xffff0001, returns the old value */
10007 " jns 1f\n\t"
10008 " call call_rwsem_wake\n" /* expects old value in %edx */
10009 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
10010 {
10011 asm volatile("# beginning __downgrade_write\n\t"
10012 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
10013 +
10014 +#ifdef CONFIG_PAX_REFCOUNT
10015 + "jno 0f\n"
10016 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
10017 + "int $4\n0:\n"
10018 + _ASM_EXTABLE(0b, 0b)
10019 +#endif
10020 +
10021 /*
10022 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
10023 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
10024 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
10025 */
10026 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
10027 {
10028 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
10029 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
10030 +
10031 +#ifdef CONFIG_PAX_REFCOUNT
10032 + "jno 0f\n"
10033 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
10034 + "int $4\n0:\n"
10035 + _ASM_EXTABLE(0b, 0b)
10036 +#endif
10037 +
10038 : "+m" (sem->count)
10039 : "er" (delta));
10040 }
10041 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
10042 */
10043 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
10044 {
10045 - return delta + xadd(&sem->count, delta);
10046 + return delta + xadd_check_overflow(&sem->count, delta);
10047 }
10048
10049 #endif /* __KERNEL__ */
10050 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
10051 index 5e64171..f58957e 100644
10052 --- a/arch/x86/include/asm/segment.h
10053 +++ b/arch/x86/include/asm/segment.h
10054 @@ -64,10 +64,15 @@
10055 * 26 - ESPFIX small SS
10056 * 27 - per-cpu [ offset to per-cpu data area ]
10057 * 28 - stack_canary-20 [ for stack protector ]
10058 - * 29 - unused
10059 - * 30 - unused
10060 + * 29 - PCI BIOS CS
10061 + * 30 - PCI BIOS DS
10062 * 31 - TSS for double fault handler
10063 */
10064 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
10065 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
10066 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
10067 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
10068 +
10069 #define GDT_ENTRY_TLS_MIN 6
10070 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
10071
10072 @@ -79,6 +84,8 @@
10073
10074 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
10075
10076 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
10077 +
10078 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
10079
10080 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
10081 @@ -104,6 +111,12 @@
10082 #define __KERNEL_STACK_CANARY 0
10083 #endif
10084
10085 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
10086 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
10087 +
10088 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
10089 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
10090 +
10091 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
10092
10093 /*
10094 @@ -141,7 +154,7 @@
10095 */
10096
10097 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
10098 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
10099 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
10100
10101
10102 #else
10103 @@ -165,6 +178,8 @@
10104 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
10105 #define __USER32_DS __USER_DS
10106
10107 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
10108 +
10109 #define GDT_ENTRY_TSS 8 /* needs two entries */
10110 #define GDT_ENTRY_LDT 10 /* needs two entries */
10111 #define GDT_ENTRY_TLS_MIN 12
10112 @@ -185,6 +200,7 @@
10113 #endif
10114
10115 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
10116 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
10117 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
10118 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
10119 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
10120 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
10121 index 73b11bc..d4a3b63 100644
10122 --- a/arch/x86/include/asm/smp.h
10123 +++ b/arch/x86/include/asm/smp.h
10124 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
10125 /* cpus sharing the last level cache: */
10126 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
10127 DECLARE_PER_CPU(u16, cpu_llc_id);
10128 -DECLARE_PER_CPU(int, cpu_number);
10129 +DECLARE_PER_CPU(unsigned int, cpu_number);
10130
10131 static inline struct cpumask *cpu_sibling_mask(int cpu)
10132 {
10133 @@ -77,7 +77,7 @@ struct smp_ops {
10134
10135 void (*send_call_func_ipi)(const struct cpumask *mask);
10136 void (*send_call_func_single_ipi)(int cpu);
10137 -};
10138 +} __no_const;
10139
10140 /* Globals due to paravirt */
10141 extern void set_cpu_sibling_map(int cpu);
10142 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
10143 extern int safe_smp_processor_id(void);
10144
10145 #elif defined(CONFIG_X86_64_SMP)
10146 -#define raw_smp_processor_id() (percpu_read(cpu_number))
10147 -
10148 -#define stack_smp_processor_id() \
10149 -({ \
10150 - struct thread_info *ti; \
10151 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
10152 - ti->cpu; \
10153 -})
10154 +#define raw_smp_processor_id() (percpu_read(cpu_number))
10155 +#define stack_smp_processor_id() raw_smp_processor_id()
10156 #define safe_smp_processor_id() smp_processor_id()
10157
10158 #endif
10159 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
10160 index 972c260..43ab1fd 100644
10161 --- a/arch/x86/include/asm/spinlock.h
10162 +++ b/arch/x86/include/asm/spinlock.h
10163 @@ -188,6 +188,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
10164 static inline void arch_read_lock(arch_rwlock_t *rw)
10165 {
10166 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
10167 +
10168 +#ifdef CONFIG_PAX_REFCOUNT
10169 + "jno 0f\n"
10170 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
10171 + "int $4\n0:\n"
10172 + _ASM_EXTABLE(0b, 0b)
10173 +#endif
10174 +
10175 "jns 1f\n"
10176 "call __read_lock_failed\n\t"
10177 "1:\n"
10178 @@ -197,6 +205,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
10179 static inline void arch_write_lock(arch_rwlock_t *rw)
10180 {
10181 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
10182 +
10183 +#ifdef CONFIG_PAX_REFCOUNT
10184 + "jno 0f\n"
10185 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
10186 + "int $4\n0:\n"
10187 + _ASM_EXTABLE(0b, 0b)
10188 +#endif
10189 +
10190 "jz 1f\n"
10191 "call __write_lock_failed\n\t"
10192 "1:\n"
10193 @@ -226,13 +242,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
10194
10195 static inline void arch_read_unlock(arch_rwlock_t *rw)
10196 {
10197 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
10198 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
10199 +
10200 +#ifdef CONFIG_PAX_REFCOUNT
10201 + "jno 0f\n"
10202 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
10203 + "int $4\n0:\n"
10204 + _ASM_EXTABLE(0b, 0b)
10205 +#endif
10206 +
10207 :"+m" (rw->lock) : : "memory");
10208 }
10209
10210 static inline void arch_write_unlock(arch_rwlock_t *rw)
10211 {
10212 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
10213 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
10214 +
10215 +#ifdef CONFIG_PAX_REFCOUNT
10216 + "jno 0f\n"
10217 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
10218 + "int $4\n0:\n"
10219 + _ASM_EXTABLE(0b, 0b)
10220 +#endif
10221 +
10222 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
10223 }
10224
10225 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
10226 index 1575177..cb23f52 100644
10227 --- a/arch/x86/include/asm/stackprotector.h
10228 +++ b/arch/x86/include/asm/stackprotector.h
10229 @@ -48,7 +48,7 @@
10230 * head_32 for boot CPU and setup_per_cpu_areas() for others.
10231 */
10232 #define GDT_STACK_CANARY_INIT \
10233 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
10234 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
10235
10236 /*
10237 * Initialize the stackprotector canary value.
10238 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
10239
10240 static inline void load_stack_canary_segment(void)
10241 {
10242 -#ifdef CONFIG_X86_32
10243 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
10244 asm volatile ("mov %0, %%gs" : : "r" (0));
10245 #endif
10246 }
10247 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
10248 index 70bbe39..4ae2bd4 100644
10249 --- a/arch/x86/include/asm/stacktrace.h
10250 +++ b/arch/x86/include/asm/stacktrace.h
10251 @@ -11,28 +11,20 @@
10252
10253 extern int kstack_depth_to_print;
10254
10255 -struct thread_info;
10256 +struct task_struct;
10257 struct stacktrace_ops;
10258
10259 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
10260 - unsigned long *stack,
10261 - unsigned long bp,
10262 - const struct stacktrace_ops *ops,
10263 - void *data,
10264 - unsigned long *end,
10265 - int *graph);
10266 +typedef unsigned long walk_stack_t(struct task_struct *task,
10267 + void *stack_start,
10268 + unsigned long *stack,
10269 + unsigned long bp,
10270 + const struct stacktrace_ops *ops,
10271 + void *data,
10272 + unsigned long *end,
10273 + int *graph);
10274
10275 -extern unsigned long
10276 -print_context_stack(struct thread_info *tinfo,
10277 - unsigned long *stack, unsigned long bp,
10278 - const struct stacktrace_ops *ops, void *data,
10279 - unsigned long *end, int *graph);
10280 -
10281 -extern unsigned long
10282 -print_context_stack_bp(struct thread_info *tinfo,
10283 - unsigned long *stack, unsigned long bp,
10284 - const struct stacktrace_ops *ops, void *data,
10285 - unsigned long *end, int *graph);
10286 +extern walk_stack_t print_context_stack;
10287 +extern walk_stack_t print_context_stack_bp;
10288
10289 /* Generic stack tracer with callbacks */
10290
10291 @@ -40,7 +32,7 @@ struct stacktrace_ops {
10292 void (*address)(void *data, unsigned long address, int reliable);
10293 /* On negative return stop dumping */
10294 int (*stack)(void *data, char *name);
10295 - walk_stack_t walk_stack;
10296 + walk_stack_t *walk_stack;
10297 };
10298
10299 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
10300 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
10301 index cb23852..2dde194 100644
10302 --- a/arch/x86/include/asm/sys_ia32.h
10303 +++ b/arch/x86/include/asm/sys_ia32.h
10304 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
10305 compat_sigset_t __user *, unsigned int);
10306 asmlinkage long sys32_alarm(unsigned int);
10307
10308 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
10309 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
10310 asmlinkage long sys32_sysfs(int, u32, u32);
10311
10312 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
10313 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
10314 index 2d2f01c..f985723 100644
10315 --- a/arch/x86/include/asm/system.h
10316 +++ b/arch/x86/include/asm/system.h
10317 @@ -129,7 +129,7 @@ do { \
10318 "call __switch_to\n\t" \
10319 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
10320 __switch_canary \
10321 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
10322 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
10323 "movq %%rax,%%rdi\n\t" \
10324 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
10325 "jnz ret_from_fork\n\t" \
10326 @@ -140,7 +140,7 @@ do { \
10327 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
10328 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
10329 [_tif_fork] "i" (_TIF_FORK), \
10330 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
10331 + [thread_info] "m" (current_tinfo), \
10332 [current_task] "m" (current_task) \
10333 __switch_canary_iparam \
10334 : "memory", "cc" __EXTRA_CLOBBER)
10335 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
10336 {
10337 unsigned long __limit;
10338 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
10339 - return __limit + 1;
10340 + return __limit;
10341 }
10342
10343 static inline void native_clts(void)
10344 @@ -397,13 +397,13 @@ void enable_hlt(void);
10345
10346 void cpu_idle_wait(void);
10347
10348 -extern unsigned long arch_align_stack(unsigned long sp);
10349 +#define arch_align_stack(x) ((x) & ~0xfUL)
10350 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
10351
10352 void default_idle(void);
10353 bool set_pm_idle_to_default(void);
10354
10355 -void stop_this_cpu(void *dummy);
10356 +void stop_this_cpu(void *dummy) __noreturn;
10357
10358 /*
10359 * Force strict CPU ordering.
10360 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
10361 index a1fe5c1..ee326d8 100644
10362 --- a/arch/x86/include/asm/thread_info.h
10363 +++ b/arch/x86/include/asm/thread_info.h
10364 @@ -10,6 +10,7 @@
10365 #include <linux/compiler.h>
10366 #include <asm/page.h>
10367 #include <asm/types.h>
10368 +#include <asm/percpu.h>
10369
10370 /*
10371 * low level task data that entry.S needs immediate access to
10372 @@ -24,7 +25,6 @@ struct exec_domain;
10373 #include <linux/atomic.h>
10374
10375 struct thread_info {
10376 - struct task_struct *task; /* main task structure */
10377 struct exec_domain *exec_domain; /* execution domain */
10378 __u32 flags; /* low level flags */
10379 __u32 status; /* thread synchronous flags */
10380 @@ -34,18 +34,12 @@ struct thread_info {
10381 mm_segment_t addr_limit;
10382 struct restart_block restart_block;
10383 void __user *sysenter_return;
10384 -#ifdef CONFIG_X86_32
10385 - unsigned long previous_esp; /* ESP of the previous stack in
10386 - case of nested (IRQ) stacks
10387 - */
10388 - __u8 supervisor_stack[0];
10389 -#endif
10390 + unsigned long lowest_stack;
10391 int uaccess_err;
10392 };
10393
10394 -#define INIT_THREAD_INFO(tsk) \
10395 +#define INIT_THREAD_INFO \
10396 { \
10397 - .task = &tsk, \
10398 .exec_domain = &default_exec_domain, \
10399 .flags = 0, \
10400 .cpu = 0, \
10401 @@ -56,7 +50,7 @@ struct thread_info {
10402 }, \
10403 }
10404
10405 -#define init_thread_info (init_thread_union.thread_info)
10406 +#define init_thread_info (init_thread_union.stack)
10407 #define init_stack (init_thread_union.stack)
10408
10409 #else /* !__ASSEMBLY__ */
10410 @@ -170,45 +164,40 @@ struct thread_info {
10411 ret; \
10412 })
10413
10414 -#ifdef CONFIG_X86_32
10415 -
10416 -#define STACK_WARN (THREAD_SIZE/8)
10417 -/*
10418 - * macros/functions for gaining access to the thread information structure
10419 - *
10420 - * preempt_count needs to be 1 initially, until the scheduler is functional.
10421 - */
10422 -#ifndef __ASSEMBLY__
10423 -
10424 -
10425 -/* how to get the current stack pointer from C */
10426 -register unsigned long current_stack_pointer asm("esp") __used;
10427 -
10428 -/* how to get the thread information struct from C */
10429 -static inline struct thread_info *current_thread_info(void)
10430 -{
10431 - return (struct thread_info *)
10432 - (current_stack_pointer & ~(THREAD_SIZE - 1));
10433 -}
10434 -
10435 -#else /* !__ASSEMBLY__ */
10436 -
10437 +#ifdef __ASSEMBLY__
10438 /* how to get the thread information struct from ASM */
10439 #define GET_THREAD_INFO(reg) \
10440 - movl $-THREAD_SIZE, reg; \
10441 - andl %esp, reg
10442 + mov PER_CPU_VAR(current_tinfo), reg
10443
10444 /* use this one if reg already contains %esp */
10445 -#define GET_THREAD_INFO_WITH_ESP(reg) \
10446 - andl $-THREAD_SIZE, reg
10447 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
10448 +#else
10449 +/* how to get the thread information struct from C */
10450 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
10451 +
10452 +static __always_inline struct thread_info *current_thread_info(void)
10453 +{
10454 + return percpu_read_stable(current_tinfo);
10455 +}
10456 +#endif
10457 +
10458 +#ifdef CONFIG_X86_32
10459 +
10460 +#define STACK_WARN (THREAD_SIZE/8)
10461 +/*
10462 + * macros/functions for gaining access to the thread information structure
10463 + *
10464 + * preempt_count needs to be 1 initially, until the scheduler is functional.
10465 + */
10466 +#ifndef __ASSEMBLY__
10467 +
10468 +/* how to get the current stack pointer from C */
10469 +register unsigned long current_stack_pointer asm("esp") __used;
10470
10471 #endif
10472
10473 #else /* X86_32 */
10474
10475 -#include <asm/percpu.h>
10476 -#define KERNEL_STACK_OFFSET (5*8)
10477 -
10478 /*
10479 * macros/functions for gaining access to the thread information structure
10480 * preempt_count needs to be 1 initially, until the scheduler is functional.
10481 @@ -216,21 +205,8 @@ static inline struct thread_info *current_thread_info(void)
10482 #ifndef __ASSEMBLY__
10483 DECLARE_PER_CPU(unsigned long, kernel_stack);
10484
10485 -static inline struct thread_info *current_thread_info(void)
10486 -{
10487 - struct thread_info *ti;
10488 - ti = (void *)(percpu_read_stable(kernel_stack) +
10489 - KERNEL_STACK_OFFSET - THREAD_SIZE);
10490 - return ti;
10491 -}
10492 -
10493 -#else /* !__ASSEMBLY__ */
10494 -
10495 -/* how to get the thread information struct from ASM */
10496 -#define GET_THREAD_INFO(reg) \
10497 - movq PER_CPU_VAR(kernel_stack),reg ; \
10498 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
10499 -
10500 +/* how to get the current stack pointer from C */
10501 +register unsigned long current_stack_pointer asm("rsp") __used;
10502 #endif
10503
10504 #endif /* !X86_32 */
10505 @@ -266,5 +242,16 @@ extern void arch_task_cache_init(void);
10506 extern void free_thread_info(struct thread_info *ti);
10507 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
10508 #define arch_task_cache_init arch_task_cache_init
10509 +
10510 +#define __HAVE_THREAD_FUNCTIONS
10511 +#define task_thread_info(task) (&(task)->tinfo)
10512 +#define task_stack_page(task) ((task)->stack)
10513 +#define setup_thread_stack(p, org) do {} while (0)
10514 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
10515 +
10516 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
10517 +extern struct task_struct *alloc_task_struct_node(int node);
10518 +extern void free_task_struct(struct task_struct *);
10519 +
10520 #endif
10521 #endif /* _ASM_X86_THREAD_INFO_H */
10522 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
10523 index 36361bf..324f262 100644
10524 --- a/arch/x86/include/asm/uaccess.h
10525 +++ b/arch/x86/include/asm/uaccess.h
10526 @@ -7,12 +7,15 @@
10527 #include <linux/compiler.h>
10528 #include <linux/thread_info.h>
10529 #include <linux/string.h>
10530 +#include <linux/sched.h>
10531 #include <asm/asm.h>
10532 #include <asm/page.h>
10533
10534 #define VERIFY_READ 0
10535 #define VERIFY_WRITE 1
10536
10537 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
10538 +
10539 /*
10540 * The fs value determines whether argument validity checking should be
10541 * performed or not. If get_fs() == USER_DS, checking is performed, with
10542 @@ -28,7 +31,12 @@
10543
10544 #define get_ds() (KERNEL_DS)
10545 #define get_fs() (current_thread_info()->addr_limit)
10546 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
10547 +void __set_fs(mm_segment_t x);
10548 +void set_fs(mm_segment_t x);
10549 +#else
10550 #define set_fs(x) (current_thread_info()->addr_limit = (x))
10551 +#endif
10552
10553 #define segment_eq(a, b) ((a).seg == (b).seg)
10554
10555 @@ -76,7 +84,33 @@
10556 * checks that the pointer is in the user space range - after calling
10557 * this function, memory access functions may still return -EFAULT.
10558 */
10559 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
10560 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
10561 +#define access_ok(type, addr, size) \
10562 +({ \
10563 + long __size = size; \
10564 + unsigned long __addr = (unsigned long)addr; \
10565 + unsigned long __addr_ao = __addr & PAGE_MASK; \
10566 + unsigned long __end_ao = __addr + __size - 1; \
10567 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
10568 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
10569 + while(__addr_ao <= __end_ao) { \
10570 + char __c_ao; \
10571 + __addr_ao += PAGE_SIZE; \
10572 + if (__size > PAGE_SIZE) \
10573 + cond_resched(); \
10574 + if (__get_user(__c_ao, (char __user *)__addr)) \
10575 + break; \
10576 + if (type != VERIFY_WRITE) { \
10577 + __addr = __addr_ao; \
10578 + continue; \
10579 + } \
10580 + if (__put_user(__c_ao, (char __user *)__addr)) \
10581 + break; \
10582 + __addr = __addr_ao; \
10583 + } \
10584 + } \
10585 + __ret_ao; \
10586 +})
10587
10588 /*
10589 * The exception table consists of pairs of addresses: the first is the
10590 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
10591 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
10592 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
10593
10594 -
10595 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
10596 +#define __copyuser_seg "gs;"
10597 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
10598 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
10599 +#else
10600 +#define __copyuser_seg
10601 +#define __COPYUSER_SET_ES
10602 +#define __COPYUSER_RESTORE_ES
10603 +#endif
10604
10605 #ifdef CONFIG_X86_32
10606 #define __put_user_asm_u64(x, addr, err, errret) \
10607 - asm volatile("1: movl %%eax,0(%2)\n" \
10608 - "2: movl %%edx,4(%2)\n" \
10609 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
10610 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
10611 "3:\n" \
10612 ".section .fixup,\"ax\"\n" \
10613 "4: movl %3,%0\n" \
10614 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
10615 : "A" (x), "r" (addr), "i" (errret), "0" (err))
10616
10617 #define __put_user_asm_ex_u64(x, addr) \
10618 - asm volatile("1: movl %%eax,0(%1)\n" \
10619 - "2: movl %%edx,4(%1)\n" \
10620 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
10621 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
10622 "3:\n" \
10623 _ASM_EXTABLE(1b, 2b - 1b) \
10624 _ASM_EXTABLE(2b, 3b - 2b) \
10625 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
10626 __typeof__(*(ptr)) __pu_val; \
10627 __chk_user_ptr(ptr); \
10628 might_fault(); \
10629 - __pu_val = x; \
10630 + __pu_val = (x); \
10631 switch (sizeof(*(ptr))) { \
10632 case 1: \
10633 __put_user_x(1, __pu_val, ptr, __ret_pu); \
10634 @@ -373,7 +415,7 @@ do { \
10635 } while (0)
10636
10637 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
10638 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
10639 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
10640 "2:\n" \
10641 ".section .fixup,\"ax\"\n" \
10642 "3: mov %3,%0\n" \
10643 @@ -381,7 +423,7 @@ do { \
10644 " jmp 2b\n" \
10645 ".previous\n" \
10646 _ASM_EXTABLE(1b, 3b) \
10647 - : "=r" (err), ltype(x) \
10648 + : "=r" (err), ltype (x) \
10649 : "m" (__m(addr)), "i" (errret), "0" (err))
10650
10651 #define __get_user_size_ex(x, ptr, size) \
10652 @@ -406,7 +448,7 @@ do { \
10653 } while (0)
10654
10655 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
10656 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
10657 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
10658 "2:\n" \
10659 _ASM_EXTABLE(1b, 2b - 1b) \
10660 : ltype(x) : "m" (__m(addr)))
10661 @@ -423,13 +465,24 @@ do { \
10662 int __gu_err; \
10663 unsigned long __gu_val; \
10664 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
10665 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
10666 + (x) = (__typeof__(*(ptr)))__gu_val; \
10667 __gu_err; \
10668 })
10669
10670 /* FIXME: this hack is definitely wrong -AK */
10671 struct __large_struct { unsigned long buf[100]; };
10672 -#define __m(x) (*(struct __large_struct __user *)(x))
10673 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10674 +#define ____m(x) \
10675 +({ \
10676 + unsigned long ____x = (unsigned long)(x); \
10677 + if (____x < PAX_USER_SHADOW_BASE) \
10678 + ____x += PAX_USER_SHADOW_BASE; \
10679 + (void __user *)____x; \
10680 +})
10681 +#else
10682 +#define ____m(x) (x)
10683 +#endif
10684 +#define __m(x) (*(struct __large_struct __user *)____m(x))
10685
10686 /*
10687 * Tell gcc we read from memory instead of writing: this is because
10688 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
10689 * aliasing issues.
10690 */
10691 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
10692 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
10693 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
10694 "2:\n" \
10695 ".section .fixup,\"ax\"\n" \
10696 "3: mov %3,%0\n" \
10697 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
10698 ".previous\n" \
10699 _ASM_EXTABLE(1b, 3b) \
10700 : "=r"(err) \
10701 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
10702 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
10703
10704 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
10705 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
10706 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
10707 "2:\n" \
10708 _ASM_EXTABLE(1b, 2b - 1b) \
10709 : : ltype(x), "m" (__m(addr)))
10710 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
10711 * On error, the variable @x is set to zero.
10712 */
10713
10714 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10715 +#define __get_user(x, ptr) get_user((x), (ptr))
10716 +#else
10717 #define __get_user(x, ptr) \
10718 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
10719 +#endif
10720
10721 /**
10722 * __put_user: - Write a simple value into user space, with less checking.
10723 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
10724 * Returns zero on success, or -EFAULT on error.
10725 */
10726
10727 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10728 +#define __put_user(x, ptr) put_user((x), (ptr))
10729 +#else
10730 #define __put_user(x, ptr) \
10731 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
10732 +#endif
10733
10734 #define __get_user_unaligned __get_user
10735 #define __put_user_unaligned __put_user
10736 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
10737 #define get_user_ex(x, ptr) do { \
10738 unsigned long __gue_val; \
10739 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
10740 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
10741 + (x) = (__typeof__(*(ptr)))__gue_val; \
10742 } while (0)
10743
10744 #ifdef CONFIG_X86_WP_WORKS_OK
10745 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
10746 index 566e803..b9521e9 100644
10747 --- a/arch/x86/include/asm/uaccess_32.h
10748 +++ b/arch/x86/include/asm/uaccess_32.h
10749 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
10750 static __always_inline unsigned long __must_check
10751 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
10752 {
10753 + if ((long)n < 0)
10754 + return n;
10755 +
10756 if (__builtin_constant_p(n)) {
10757 unsigned long ret;
10758
10759 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
10760 return ret;
10761 }
10762 }
10763 + if (!__builtin_constant_p(n))
10764 + check_object_size(from, n, true);
10765 return __copy_to_user_ll(to, from, n);
10766 }
10767
10768 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
10769 __copy_to_user(void __user *to, const void *from, unsigned long n)
10770 {
10771 might_fault();
10772 +
10773 return __copy_to_user_inatomic(to, from, n);
10774 }
10775
10776 static __always_inline unsigned long
10777 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
10778 {
10779 + if ((long)n < 0)
10780 + return n;
10781 +
10782 /* Avoid zeroing the tail if the copy fails..
10783 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
10784 * but as the zeroing behaviour is only significant when n is not
10785 @@ -137,6 +146,10 @@ static __always_inline unsigned long
10786 __copy_from_user(void *to, const void __user *from, unsigned long n)
10787 {
10788 might_fault();
10789 +
10790 + if ((long)n < 0)
10791 + return n;
10792 +
10793 if (__builtin_constant_p(n)) {
10794 unsigned long ret;
10795
10796 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
10797 return ret;
10798 }
10799 }
10800 + if (!__builtin_constant_p(n))
10801 + check_object_size(to, n, false);
10802 return __copy_from_user_ll(to, from, n);
10803 }
10804
10805 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
10806 const void __user *from, unsigned long n)
10807 {
10808 might_fault();
10809 +
10810 + if ((long)n < 0)
10811 + return n;
10812 +
10813 if (__builtin_constant_p(n)) {
10814 unsigned long ret;
10815
10816 @@ -181,15 +200,19 @@ static __always_inline unsigned long
10817 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
10818 unsigned long n)
10819 {
10820 - return __copy_from_user_ll_nocache_nozero(to, from, n);
10821 + if ((long)n < 0)
10822 + return n;
10823 +
10824 + return __copy_from_user_ll_nocache_nozero(to, from, n);
10825 }
10826
10827 -unsigned long __must_check copy_to_user(void __user *to,
10828 - const void *from, unsigned long n);
10829 -unsigned long __must_check _copy_from_user(void *to,
10830 - const void __user *from,
10831 - unsigned long n);
10832 -
10833 +extern void copy_to_user_overflow(void)
10834 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
10835 + __compiletime_error("copy_to_user() buffer size is not provably correct")
10836 +#else
10837 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
10838 +#endif
10839 +;
10840
10841 extern void copy_from_user_overflow(void)
10842 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
10843 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
10844 #endif
10845 ;
10846
10847 -static inline unsigned long __must_check copy_from_user(void *to,
10848 - const void __user *from,
10849 - unsigned long n)
10850 +/**
10851 + * copy_to_user: - Copy a block of data into user space.
10852 + * @to: Destination address, in user space.
10853 + * @from: Source address, in kernel space.
10854 + * @n: Number of bytes to copy.
10855 + *
10856 + * Context: User context only. This function may sleep.
10857 + *
10858 + * Copy data from kernel space to user space.
10859 + *
10860 + * Returns number of bytes that could not be copied.
10861 + * On success, this will be zero.
10862 + */
10863 +static inline unsigned long __must_check
10864 +copy_to_user(void __user *to, const void *from, unsigned long n)
10865 +{
10866 + int sz = __compiletime_object_size(from);
10867 +
10868 + if (unlikely(sz != -1 && sz < n))
10869 + copy_to_user_overflow();
10870 + else if (access_ok(VERIFY_WRITE, to, n))
10871 + n = __copy_to_user(to, from, n);
10872 + return n;
10873 +}
10874 +
10875 +/**
10876 + * copy_from_user: - Copy a block of data from user space.
10877 + * @to: Destination address, in kernel space.
10878 + * @from: Source address, in user space.
10879 + * @n: Number of bytes to copy.
10880 + *
10881 + * Context: User context only. This function may sleep.
10882 + *
10883 + * Copy data from user space to kernel space.
10884 + *
10885 + * Returns number of bytes that could not be copied.
10886 + * On success, this will be zero.
10887 + *
10888 + * If some data could not be copied, this function will pad the copied
10889 + * data to the requested size using zero bytes.
10890 + */
10891 +static inline unsigned long __must_check
10892 +copy_from_user(void *to, const void __user *from, unsigned long n)
10893 {
10894 int sz = __compiletime_object_size(to);
10895
10896 - if (likely(sz == -1 || sz >= n))
10897 - n = _copy_from_user(to, from, n);
10898 - else
10899 + if (unlikely(sz != -1 && sz < n))
10900 copy_from_user_overflow();
10901 -
10902 + else if (access_ok(VERIFY_READ, from, n))
10903 + n = __copy_from_user(to, from, n);
10904 + else if ((long)n > 0) {
10905 + if (!__builtin_constant_p(n))
10906 + check_object_size(to, n, false);
10907 + memset(to, 0, n);
10908 + }
10909 return n;
10910 }
10911
10912 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
10913 index 1c66d30..23ab77d 100644
10914 --- a/arch/x86/include/asm/uaccess_64.h
10915 +++ b/arch/x86/include/asm/uaccess_64.h
10916 @@ -10,6 +10,9 @@
10917 #include <asm/alternative.h>
10918 #include <asm/cpufeature.h>
10919 #include <asm/page.h>
10920 +#include <asm/pgtable.h>
10921 +
10922 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
10923
10924 /*
10925 * Copy To/From Userspace
10926 @@ -17,12 +20,12 @@
10927
10928 /* Handles exceptions in both to and from, but doesn't do access_ok */
10929 __must_check unsigned long
10930 -copy_user_generic_string(void *to, const void *from, unsigned len);
10931 +copy_user_generic_string(void *to, const void *from, unsigned long len);
10932 __must_check unsigned long
10933 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
10934 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len);
10935
10936 static __always_inline __must_check unsigned long
10937 -copy_user_generic(void *to, const void *from, unsigned len)
10938 +copy_user_generic(void *to, const void *from, unsigned long len)
10939 {
10940 unsigned ret;
10941
10942 @@ -36,138 +39,222 @@ copy_user_generic(void *to, const void *from, unsigned len)
10943 return ret;
10944 }
10945
10946 +static __always_inline __must_check unsigned long
10947 +__copy_to_user(void __user *to, const void *from, unsigned long len);
10948 +static __always_inline __must_check unsigned long
10949 +__copy_from_user(void *to, const void __user *from, unsigned long len);
10950 __must_check unsigned long
10951 -_copy_to_user(void __user *to, const void *from, unsigned len);
10952 -__must_check unsigned long
10953 -_copy_from_user(void *to, const void __user *from, unsigned len);
10954 -__must_check unsigned long
10955 -copy_in_user(void __user *to, const void __user *from, unsigned len);
10956 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
10957
10958 static inline unsigned long __must_check copy_from_user(void *to,
10959 const void __user *from,
10960 unsigned long n)
10961 {
10962 - int sz = __compiletime_object_size(to);
10963 -
10964 might_fault();
10965 - if (likely(sz == -1 || sz >= n))
10966 - n = _copy_from_user(to, from, n);
10967 -#ifdef CONFIG_DEBUG_VM
10968 - else
10969 - WARN(1, "Buffer overflow detected!\n");
10970 -#endif
10971 +
10972 + if (access_ok(VERIFY_READ, from, n))
10973 + n = __copy_from_user(to, from, n);
10974 + else if (n < INT_MAX) {
10975 + if (!__builtin_constant_p(n))
10976 + check_object_size(to, n, false);
10977 + memset(to, 0, n);
10978 + }
10979 return n;
10980 }
10981
10982 static __always_inline __must_check
10983 -int copy_to_user(void __user *dst, const void *src, unsigned size)
10984 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
10985 {
10986 might_fault();
10987
10988 - return _copy_to_user(dst, src, size);
10989 + if (access_ok(VERIFY_WRITE, dst, size))
10990 + size = __copy_to_user(dst, src, size);
10991 + return size;
10992 }
10993
10994 static __always_inline __must_check
10995 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
10996 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
10997 {
10998 - int ret = 0;
10999 + int sz = __compiletime_object_size(dst);
11000 + unsigned ret = 0;
11001
11002 might_fault();
11003 - if (!__builtin_constant_p(size))
11004 - return copy_user_generic(dst, (__force void *)src, size);
11005 +
11006 + if (size > INT_MAX)
11007 + return size;
11008 +
11009 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11010 + if (!__access_ok(VERIFY_READ, src, size))
11011 + return size;
11012 +#endif
11013 +
11014 + if (unlikely(sz != -1 && sz < size)) {
11015 +#ifdef CONFIG_DEBUG_VM
11016 + WARN(1, "Buffer overflow detected!\n");
11017 +#endif
11018 + return size;
11019 + }
11020 +
11021 + if (!__builtin_constant_p(size)) {
11022 + check_object_size(dst, size, false);
11023 +
11024 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11025 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11026 + src += PAX_USER_SHADOW_BASE;
11027 +#endif
11028 +
11029 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11030 + }
11031 switch (size) {
11032 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
11033 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
11034 ret, "b", "b", "=q", 1);
11035 return ret;
11036 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
11037 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
11038 ret, "w", "w", "=r", 2);
11039 return ret;
11040 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
11041 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
11042 ret, "l", "k", "=r", 4);
11043 return ret;
11044 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
11045 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11046 ret, "q", "", "=r", 8);
11047 return ret;
11048 case 10:
11049 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11050 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11051 ret, "q", "", "=r", 10);
11052 if (unlikely(ret))
11053 return ret;
11054 __get_user_asm(*(u16 *)(8 + (char *)dst),
11055 - (u16 __user *)(8 + (char __user *)src),
11056 + (const u16 __user *)(8 + (const char __user *)src),
11057 ret, "w", "w", "=r", 2);
11058 return ret;
11059 case 16:
11060 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11061 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11062 ret, "q", "", "=r", 16);
11063 if (unlikely(ret))
11064 return ret;
11065 __get_user_asm(*(u64 *)(8 + (char *)dst),
11066 - (u64 __user *)(8 + (char __user *)src),
11067 + (const u64 __user *)(8 + (const char __user *)src),
11068 ret, "q", "", "=r", 8);
11069 return ret;
11070 default:
11071 - return copy_user_generic(dst, (__force void *)src, size);
11072 +
11073 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11074 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11075 + src += PAX_USER_SHADOW_BASE;
11076 +#endif
11077 +
11078 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11079 }
11080 }
11081
11082 static __always_inline __must_check
11083 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
11084 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
11085 {
11086 - int ret = 0;
11087 + int sz = __compiletime_object_size(src);
11088 + unsigned ret = 0;
11089
11090 might_fault();
11091 - if (!__builtin_constant_p(size))
11092 - return copy_user_generic((__force void *)dst, src, size);
11093 +
11094 + if (size > INT_MAX)
11095 + return size;
11096 +
11097 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11098 + if (!__access_ok(VERIFY_WRITE, dst, size))
11099 + return size;
11100 +#endif
11101 +
11102 + if (unlikely(sz != -1 && sz < size)) {
11103 +#ifdef CONFIG_DEBUG_VM
11104 + WARN(1, "Buffer overflow detected!\n");
11105 +#endif
11106 + return size;
11107 + }
11108 +
11109 + if (!__builtin_constant_p(size)) {
11110 + check_object_size(src, size, true);
11111 +
11112 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11113 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11114 + dst += PAX_USER_SHADOW_BASE;
11115 +#endif
11116 +
11117 + return copy_user_generic((__force_kernel void *)dst, src, size);
11118 + }
11119 switch (size) {
11120 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
11121 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
11122 ret, "b", "b", "iq", 1);
11123 return ret;
11124 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
11125 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
11126 ret, "w", "w", "ir", 2);
11127 return ret;
11128 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
11129 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
11130 ret, "l", "k", "ir", 4);
11131 return ret;
11132 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
11133 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11134 ret, "q", "", "er", 8);
11135 return ret;
11136 case 10:
11137 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11138 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11139 ret, "q", "", "er", 10);
11140 if (unlikely(ret))
11141 return ret;
11142 asm("":::"memory");
11143 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
11144 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
11145 ret, "w", "w", "ir", 2);
11146 return ret;
11147 case 16:
11148 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11149 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11150 ret, "q", "", "er", 16);
11151 if (unlikely(ret))
11152 return ret;
11153 asm("":::"memory");
11154 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
11155 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
11156 ret, "q", "", "er", 8);
11157 return ret;
11158 default:
11159 - return copy_user_generic((__force void *)dst, src, size);
11160 +
11161 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11162 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11163 + dst += PAX_USER_SHADOW_BASE;
11164 +#endif
11165 +
11166 + return copy_user_generic((__force_kernel void *)dst, src, size);
11167 }
11168 }
11169
11170 static __always_inline __must_check
11171 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11172 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
11173 {
11174 - int ret = 0;
11175 + unsigned ret = 0;
11176
11177 might_fault();
11178 - if (!__builtin_constant_p(size))
11179 - return copy_user_generic((__force void *)dst,
11180 - (__force void *)src, size);
11181 +
11182 + if (size > INT_MAX)
11183 + return size;
11184 +
11185 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11186 + if (!__access_ok(VERIFY_READ, src, size))
11187 + return size;
11188 + if (!__access_ok(VERIFY_WRITE, dst, size))
11189 + return size;
11190 +#endif
11191 +
11192 + if (!__builtin_constant_p(size)) {
11193 +
11194 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11195 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11196 + src += PAX_USER_SHADOW_BASE;
11197 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11198 + dst += PAX_USER_SHADOW_BASE;
11199 +#endif
11200 +
11201 + return copy_user_generic((__force_kernel void *)dst,
11202 + (__force_kernel const void *)src, size);
11203 + }
11204 switch (size) {
11205 case 1: {
11206 u8 tmp;
11207 - __get_user_asm(tmp, (u8 __user *)src,
11208 + __get_user_asm(tmp, (const u8 __user *)src,
11209 ret, "b", "b", "=q", 1);
11210 if (likely(!ret))
11211 __put_user_asm(tmp, (u8 __user *)dst,
11212 @@ -176,7 +263,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11213 }
11214 case 2: {
11215 u16 tmp;
11216 - __get_user_asm(tmp, (u16 __user *)src,
11217 + __get_user_asm(tmp, (const u16 __user *)src,
11218 ret, "w", "w", "=r", 2);
11219 if (likely(!ret))
11220 __put_user_asm(tmp, (u16 __user *)dst,
11221 @@ -186,7 +273,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11222
11223 case 4: {
11224 u32 tmp;
11225 - __get_user_asm(tmp, (u32 __user *)src,
11226 + __get_user_asm(tmp, (const u32 __user *)src,
11227 ret, "l", "k", "=r", 4);
11228 if (likely(!ret))
11229 __put_user_asm(tmp, (u32 __user *)dst,
11230 @@ -195,7 +282,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11231 }
11232 case 8: {
11233 u64 tmp;
11234 - __get_user_asm(tmp, (u64 __user *)src,
11235 + __get_user_asm(tmp, (const u64 __user *)src,
11236 ret, "q", "", "=r", 8);
11237 if (likely(!ret))
11238 __put_user_asm(tmp, (u64 __user *)dst,
11239 @@ -203,8 +290,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11240 return ret;
11241 }
11242 default:
11243 - return copy_user_generic((__force void *)dst,
11244 - (__force void *)src, size);
11245 +
11246 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11247 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11248 + src += PAX_USER_SHADOW_BASE;
11249 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11250 + dst += PAX_USER_SHADOW_BASE;
11251 +#endif
11252 +
11253 + return copy_user_generic((__force_kernel void *)dst,
11254 + (__force_kernel const void *)src, size);
11255 }
11256 }
11257
11258 @@ -219,35 +314,72 @@ __must_check unsigned long clear_user(void __user *mem, unsigned long len);
11259 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
11260
11261 static __must_check __always_inline int
11262 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
11263 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
11264 {
11265 - return copy_user_generic(dst, (__force const void *)src, size);
11266 + if (size > INT_MAX)
11267 + return size;
11268 +
11269 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11270 + if (!__access_ok(VERIFY_READ, src, size))
11271 + return size;
11272 +
11273 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11274 + src += PAX_USER_SHADOW_BASE;
11275 +#endif
11276 +
11277 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11278 }
11279
11280 -static __must_check __always_inline int
11281 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
11282 +static __must_check __always_inline unsigned long
11283 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
11284 {
11285 - return copy_user_generic((__force void *)dst, src, size);
11286 + if (size > INT_MAX)
11287 + return size;
11288 +
11289 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11290 + if (!__access_ok(VERIFY_WRITE, dst, size))
11291 + return size;
11292 +
11293 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11294 + dst += PAX_USER_SHADOW_BASE;
11295 +#endif
11296 +
11297 + return copy_user_generic((__force_kernel void *)dst, src, size);
11298 }
11299
11300 -extern long __copy_user_nocache(void *dst, const void __user *src,
11301 - unsigned size, int zerorest);
11302 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
11303 + unsigned long size, int zerorest);
11304
11305 -static inline int
11306 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
11307 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
11308 {
11309 might_sleep();
11310 +
11311 + if (size > INT_MAX)
11312 + return size;
11313 +
11314 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11315 + if (!__access_ok(VERIFY_READ, src, size))
11316 + return size;
11317 +#endif
11318 +
11319 return __copy_user_nocache(dst, src, size, 1);
11320 }
11321
11322 -static inline int
11323 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11324 - unsigned size)
11325 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11326 + unsigned long size)
11327 {
11328 + if (size > INT_MAX)
11329 + return size;
11330 +
11331 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11332 + if (!__access_ok(VERIFY_READ, src, size))
11333 + return size;
11334 +#endif
11335 +
11336 return __copy_user_nocache(dst, src, size, 0);
11337 }
11338
11339 -unsigned long
11340 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
11341 +extern unsigned long
11342 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
11343
11344 #endif /* _ASM_X86_UACCESS_64_H */
11345 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
11346 index bb05228..d763d5b 100644
11347 --- a/arch/x86/include/asm/vdso.h
11348 +++ b/arch/x86/include/asm/vdso.h
11349 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
11350 #define VDSO32_SYMBOL(base, name) \
11351 ({ \
11352 extern const char VDSO32_##name[]; \
11353 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
11354 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
11355 })
11356 #endif
11357
11358 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
11359 index 1971e65..1e3559b 100644
11360 --- a/arch/x86/include/asm/x86_init.h
11361 +++ b/arch/x86/include/asm/x86_init.h
11362 @@ -28,7 +28,7 @@ struct x86_init_mpparse {
11363 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
11364 void (*find_smp_config)(void);
11365 void (*get_smp_config)(unsigned int early);
11366 -};
11367 +} __no_const;
11368
11369 /**
11370 * struct x86_init_resources - platform specific resource related ops
11371 @@ -42,7 +42,7 @@ struct x86_init_resources {
11372 void (*probe_roms)(void);
11373 void (*reserve_resources)(void);
11374 char *(*memory_setup)(void);
11375 -};
11376 +} __no_const;
11377
11378 /**
11379 * struct x86_init_irqs - platform specific interrupt setup
11380 @@ -55,7 +55,7 @@ struct x86_init_irqs {
11381 void (*pre_vector_init)(void);
11382 void (*intr_init)(void);
11383 void (*trap_init)(void);
11384 -};
11385 +} __no_const;
11386
11387 /**
11388 * struct x86_init_oem - oem platform specific customizing functions
11389 @@ -65,7 +65,7 @@ struct x86_init_irqs {
11390 struct x86_init_oem {
11391 void (*arch_setup)(void);
11392 void (*banner)(void);
11393 -};
11394 +} __no_const;
11395
11396 /**
11397 * struct x86_init_mapping - platform specific initial kernel pagetable setup
11398 @@ -76,7 +76,7 @@ struct x86_init_oem {
11399 */
11400 struct x86_init_mapping {
11401 void (*pagetable_reserve)(u64 start, u64 end);
11402 -};
11403 +} __no_const;
11404
11405 /**
11406 * struct x86_init_paging - platform specific paging functions
11407 @@ -86,7 +86,7 @@ struct x86_init_mapping {
11408 struct x86_init_paging {
11409 void (*pagetable_setup_start)(pgd_t *base);
11410 void (*pagetable_setup_done)(pgd_t *base);
11411 -};
11412 +} __no_const;
11413
11414 /**
11415 * struct x86_init_timers - platform specific timer setup
11416 @@ -101,7 +101,7 @@ struct x86_init_timers {
11417 void (*tsc_pre_init)(void);
11418 void (*timer_init)(void);
11419 void (*wallclock_init)(void);
11420 -};
11421 +} __no_const;
11422
11423 /**
11424 * struct x86_init_iommu - platform specific iommu setup
11425 @@ -109,7 +109,7 @@ struct x86_init_timers {
11426 */
11427 struct x86_init_iommu {
11428 int (*iommu_init)(void);
11429 -};
11430 +} __no_const;
11431
11432 /**
11433 * struct x86_init_pci - platform specific pci init functions
11434 @@ -123,7 +123,7 @@ struct x86_init_pci {
11435 int (*init)(void);
11436 void (*init_irq)(void);
11437 void (*fixup_irqs)(void);
11438 -};
11439 +} __no_const;
11440
11441 /**
11442 * struct x86_init_ops - functions for platform specific setup
11443 @@ -139,7 +139,7 @@ struct x86_init_ops {
11444 struct x86_init_timers timers;
11445 struct x86_init_iommu iommu;
11446 struct x86_init_pci pci;
11447 -};
11448 +} __no_const;
11449
11450 /**
11451 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
11452 @@ -147,7 +147,7 @@ struct x86_init_ops {
11453 */
11454 struct x86_cpuinit_ops {
11455 void (*setup_percpu_clockev)(void);
11456 -};
11457 +} __no_const;
11458
11459 /**
11460 * struct x86_platform_ops - platform specific runtime functions
11461 @@ -169,7 +169,7 @@ struct x86_platform_ops {
11462 void (*nmi_init)(void);
11463 unsigned char (*get_nmi_reason)(void);
11464 int (*i8042_detect)(void);
11465 -};
11466 +} __no_const;
11467
11468 struct pci_dev;
11469
11470 @@ -177,7 +177,7 @@ struct x86_msi_ops {
11471 int (*setup_msi_irqs)(struct pci_dev *dev, int nvec, int type);
11472 void (*teardown_msi_irq)(unsigned int irq);
11473 void (*teardown_msi_irqs)(struct pci_dev *dev);
11474 -};
11475 +} __no_const;
11476
11477 extern struct x86_init_ops x86_init;
11478 extern struct x86_cpuinit_ops x86_cpuinit;
11479 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
11480 index c6ce245..ffbdab7 100644
11481 --- a/arch/x86/include/asm/xsave.h
11482 +++ b/arch/x86/include/asm/xsave.h
11483 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
11484 {
11485 int err;
11486
11487 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11488 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
11489 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
11490 +#endif
11491 +
11492 /*
11493 * Clear the xsave header first, so that reserved fields are
11494 * initialized to zero.
11495 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
11496 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
11497 {
11498 int err;
11499 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
11500 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
11501 u32 lmask = mask;
11502 u32 hmask = mask >> 32;
11503
11504 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11505 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
11506 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
11507 +#endif
11508 +
11509 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
11510 "2:\n"
11511 ".section .fixup,\"ax\"\n"
11512 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
11513 index 6a564ac..9b1340c 100644
11514 --- a/arch/x86/kernel/acpi/realmode/Makefile
11515 +++ b/arch/x86/kernel/acpi/realmode/Makefile
11516 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
11517 $(call cc-option, -fno-stack-protector) \
11518 $(call cc-option, -mpreferred-stack-boundary=2)
11519 KBUILD_CFLAGS += $(call cc-option, -m32)
11520 +ifdef CONSTIFY_PLUGIN
11521 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
11522 +endif
11523 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11524 GCOV_PROFILE := n
11525
11526 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
11527 index b4fd836..4358fe3 100644
11528 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
11529 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
11530 @@ -108,6 +108,9 @@ wakeup_code:
11531 /* Do any other stuff... */
11532
11533 #ifndef CONFIG_64BIT
11534 + /* Recheck NX bit overrides (64bit path does this in trampoline */
11535 + call verify_cpu
11536 +
11537 /* This could also be done in C code... */
11538 movl pmode_cr3, %eax
11539 movl %eax, %cr3
11540 @@ -131,6 +134,7 @@ wakeup_code:
11541 movl pmode_cr0, %eax
11542 movl %eax, %cr0
11543 jmp pmode_return
11544 +# include "../../verify_cpu.S"
11545 #else
11546 pushw $0
11547 pushw trampoline_segment
11548 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
11549 index 103b6ab..2004d0a 100644
11550 --- a/arch/x86/kernel/acpi/sleep.c
11551 +++ b/arch/x86/kernel/acpi/sleep.c
11552 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
11553 header->trampoline_segment = trampoline_address() >> 4;
11554 #ifdef CONFIG_SMP
11555 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
11556 +
11557 + pax_open_kernel();
11558 early_gdt_descr.address =
11559 (unsigned long)get_cpu_gdt_table(smp_processor_id());
11560 + pax_close_kernel();
11561 +
11562 initial_gs = per_cpu_offset(smp_processor_id());
11563 #endif
11564 initial_code = (unsigned long)wakeup_long64;
11565 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
11566 index 13ab720..95d5442 100644
11567 --- a/arch/x86/kernel/acpi/wakeup_32.S
11568 +++ b/arch/x86/kernel/acpi/wakeup_32.S
11569 @@ -30,13 +30,11 @@ wakeup_pmode_return:
11570 # and restore the stack ... but you need gdt for this to work
11571 movl saved_context_esp, %esp
11572
11573 - movl %cs:saved_magic, %eax
11574 - cmpl $0x12345678, %eax
11575 + cmpl $0x12345678, saved_magic
11576 jne bogus_magic
11577
11578 # jump to place where we left off
11579 - movl saved_eip, %eax
11580 - jmp *%eax
11581 + jmp *(saved_eip)
11582
11583 bogus_magic:
11584 jmp bogus_magic
11585 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
11586 index 1f84794..e23f862 100644
11587 --- a/arch/x86/kernel/alternative.c
11588 +++ b/arch/x86/kernel/alternative.c
11589 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
11590 */
11591 for (a = start; a < end; a++) {
11592 instr = (u8 *)&a->instr_offset + a->instr_offset;
11593 +
11594 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11595 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11596 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
11597 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11598 +#endif
11599 +
11600 replacement = (u8 *)&a->repl_offset + a->repl_offset;
11601 BUG_ON(a->replacementlen > a->instrlen);
11602 BUG_ON(a->instrlen > sizeof(insnbuf));
11603 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
11604 for (poff = start; poff < end; poff++) {
11605 u8 *ptr = (u8 *)poff + *poff;
11606
11607 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11608 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11609 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
11610 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11611 +#endif
11612 +
11613 if (!*poff || ptr < text || ptr >= text_end)
11614 continue;
11615 /* turn DS segment override prefix into lock prefix */
11616 - if (*ptr == 0x3e)
11617 + if (*ktla_ktva(ptr) == 0x3e)
11618 text_poke(ptr, ((unsigned char []){0xf0}), 1);
11619 };
11620 mutex_unlock(&text_mutex);
11621 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
11622 for (poff = start; poff < end; poff++) {
11623 u8 *ptr = (u8 *)poff + *poff;
11624
11625 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11626 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11627 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
11628 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11629 +#endif
11630 +
11631 if (!*poff || ptr < text || ptr >= text_end)
11632 continue;
11633 /* turn lock prefix into DS segment override prefix */
11634 - if (*ptr == 0xf0)
11635 + if (*ktla_ktva(ptr) == 0xf0)
11636 text_poke(ptr, ((unsigned char []){0x3E}), 1);
11637 };
11638 mutex_unlock(&text_mutex);
11639 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
11640
11641 BUG_ON(p->len > MAX_PATCH_LEN);
11642 /* prep the buffer with the original instructions */
11643 - memcpy(insnbuf, p->instr, p->len);
11644 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
11645 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
11646 (unsigned long)p->instr, p->len);
11647
11648 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
11649 if (smp_alt_once)
11650 free_init_pages("SMP alternatives",
11651 (unsigned long)__smp_locks,
11652 - (unsigned long)__smp_locks_end);
11653 + PAGE_ALIGN((unsigned long)__smp_locks_end));
11654
11655 restart_nmi();
11656 }
11657 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
11658 * instructions. And on the local CPU you need to be protected again NMI or MCE
11659 * handlers seeing an inconsistent instruction while you patch.
11660 */
11661 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
11662 +void *__kprobes text_poke_early(void *addr, const void *opcode,
11663 size_t len)
11664 {
11665 unsigned long flags;
11666 local_irq_save(flags);
11667 - memcpy(addr, opcode, len);
11668 +
11669 + pax_open_kernel();
11670 + memcpy(ktla_ktva(addr), opcode, len);
11671 sync_core();
11672 + pax_close_kernel();
11673 +
11674 local_irq_restore(flags);
11675 /* Could also do a CLFLUSH here to speed up CPU recovery; but
11676 that causes hangs on some VIA CPUs. */
11677 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
11678 */
11679 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
11680 {
11681 - unsigned long flags;
11682 - char *vaddr;
11683 + unsigned char *vaddr = ktla_ktva(addr);
11684 struct page *pages[2];
11685 - int i;
11686 + size_t i;
11687
11688 if (!core_kernel_text((unsigned long)addr)) {
11689 - pages[0] = vmalloc_to_page(addr);
11690 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
11691 + pages[0] = vmalloc_to_page(vaddr);
11692 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
11693 } else {
11694 - pages[0] = virt_to_page(addr);
11695 + pages[0] = virt_to_page(vaddr);
11696 WARN_ON(!PageReserved(pages[0]));
11697 - pages[1] = virt_to_page(addr + PAGE_SIZE);
11698 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
11699 }
11700 BUG_ON(!pages[0]);
11701 - local_irq_save(flags);
11702 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
11703 - if (pages[1])
11704 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
11705 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
11706 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
11707 - clear_fixmap(FIX_TEXT_POKE0);
11708 - if (pages[1])
11709 - clear_fixmap(FIX_TEXT_POKE1);
11710 - local_flush_tlb();
11711 - sync_core();
11712 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
11713 - that causes hangs on some VIA CPUs. */
11714 + text_poke_early(addr, opcode, len);
11715 for (i = 0; i < len; i++)
11716 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
11717 - local_irq_restore(flags);
11718 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
11719 return addr;
11720 }
11721
11722 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
11723 index f98d84c..e402a69 100644
11724 --- a/arch/x86/kernel/apic/apic.c
11725 +++ b/arch/x86/kernel/apic/apic.c
11726 @@ -174,7 +174,7 @@ int first_system_vector = 0xfe;
11727 /*
11728 * Debug level, exported for io_apic.c
11729 */
11730 -unsigned int apic_verbosity;
11731 +int apic_verbosity;
11732
11733 int pic_mode;
11734
11735 @@ -1853,7 +1853,7 @@ void smp_error_interrupt(struct pt_regs *regs)
11736 apic_write(APIC_ESR, 0);
11737 v1 = apic_read(APIC_ESR);
11738 ack_APIC_irq();
11739 - atomic_inc(&irq_err_count);
11740 + atomic_inc_unchecked(&irq_err_count);
11741
11742 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
11743 smp_processor_id(), v0 , v1);
11744 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
11745 index 6d939d7..0697fcc 100644
11746 --- a/arch/x86/kernel/apic/io_apic.c
11747 +++ b/arch/x86/kernel/apic/io_apic.c
11748 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
11749 }
11750 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
11751
11752 -void lock_vector_lock(void)
11753 +void lock_vector_lock(void) __acquires(vector_lock)
11754 {
11755 /* Used to the online set of cpus does not change
11756 * during assign_irq_vector.
11757 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
11758 raw_spin_lock(&vector_lock);
11759 }
11760
11761 -void unlock_vector_lock(void)
11762 +void unlock_vector_lock(void) __releases(vector_lock)
11763 {
11764 raw_spin_unlock(&vector_lock);
11765 }
11766 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
11767 ack_APIC_irq();
11768 }
11769
11770 -atomic_t irq_mis_count;
11771 +atomic_unchecked_t irq_mis_count;
11772
11773 static void ack_apic_level(struct irq_data *data)
11774 {
11775 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
11776 * at the cpu.
11777 */
11778 if (!(v & (1 << (i & 0x1f)))) {
11779 - atomic_inc(&irq_mis_count);
11780 + atomic_inc_unchecked(&irq_mis_count);
11781
11782 eoi_ioapic_irq(irq, cfg);
11783 }
11784 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
11785 index a46bd38..6b906d7 100644
11786 --- a/arch/x86/kernel/apm_32.c
11787 +++ b/arch/x86/kernel/apm_32.c
11788 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
11789 * This is for buggy BIOS's that refer to (real mode) segment 0x40
11790 * even though they are called in protected mode.
11791 */
11792 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
11793 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
11794 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
11795
11796 static const char driver_version[] = "1.16ac"; /* no spaces */
11797 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
11798 BUG_ON(cpu != 0);
11799 gdt = get_cpu_gdt_table(cpu);
11800 save_desc_40 = gdt[0x40 / 8];
11801 +
11802 + pax_open_kernel();
11803 gdt[0x40 / 8] = bad_bios_desc;
11804 + pax_close_kernel();
11805
11806 apm_irq_save(flags);
11807 APM_DO_SAVE_SEGS;
11808 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
11809 &call->esi);
11810 APM_DO_RESTORE_SEGS;
11811 apm_irq_restore(flags);
11812 +
11813 + pax_open_kernel();
11814 gdt[0x40 / 8] = save_desc_40;
11815 + pax_close_kernel();
11816 +
11817 put_cpu();
11818
11819 return call->eax & 0xff;
11820 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
11821 BUG_ON(cpu != 0);
11822 gdt = get_cpu_gdt_table(cpu);
11823 save_desc_40 = gdt[0x40 / 8];
11824 +
11825 + pax_open_kernel();
11826 gdt[0x40 / 8] = bad_bios_desc;
11827 + pax_close_kernel();
11828
11829 apm_irq_save(flags);
11830 APM_DO_SAVE_SEGS;
11831 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
11832 &call->eax);
11833 APM_DO_RESTORE_SEGS;
11834 apm_irq_restore(flags);
11835 +
11836 + pax_open_kernel();
11837 gdt[0x40 / 8] = save_desc_40;
11838 + pax_close_kernel();
11839 +
11840 put_cpu();
11841 return error;
11842 }
11843 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
11844 * code to that CPU.
11845 */
11846 gdt = get_cpu_gdt_table(0);
11847 +
11848 + pax_open_kernel();
11849 set_desc_base(&gdt[APM_CS >> 3],
11850 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
11851 set_desc_base(&gdt[APM_CS_16 >> 3],
11852 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
11853 set_desc_base(&gdt[APM_DS >> 3],
11854 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
11855 + pax_close_kernel();
11856
11857 proc_create("apm", 0, NULL, &apm_file_ops);
11858
11859 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
11860 index 4f13faf..87db5d2 100644
11861 --- a/arch/x86/kernel/asm-offsets.c
11862 +++ b/arch/x86/kernel/asm-offsets.c
11863 @@ -33,6 +33,8 @@ void common(void) {
11864 OFFSET(TI_status, thread_info, status);
11865 OFFSET(TI_addr_limit, thread_info, addr_limit);
11866 OFFSET(TI_preempt_count, thread_info, preempt_count);
11867 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
11868 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
11869
11870 BLANK();
11871 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
11872 @@ -53,8 +55,26 @@ void common(void) {
11873 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
11874 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
11875 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
11876 +
11877 +#ifdef CONFIG_PAX_KERNEXEC
11878 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
11879 #endif
11880
11881 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11882 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
11883 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
11884 +#ifdef CONFIG_X86_64
11885 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
11886 +#endif
11887 +#endif
11888 +
11889 +#endif
11890 +
11891 + BLANK();
11892 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
11893 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
11894 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
11895 +
11896 #ifdef CONFIG_XEN
11897 BLANK();
11898 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
11899 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
11900 index e72a119..6e2955d 100644
11901 --- a/arch/x86/kernel/asm-offsets_64.c
11902 +++ b/arch/x86/kernel/asm-offsets_64.c
11903 @@ -69,6 +69,7 @@ int main(void)
11904 BLANK();
11905 #undef ENTRY
11906
11907 + DEFINE(TSS_size, sizeof(struct tss_struct));
11908 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
11909 BLANK();
11910
11911 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
11912 index 25f24dc..4094a7f 100644
11913 --- a/arch/x86/kernel/cpu/Makefile
11914 +++ b/arch/x86/kernel/cpu/Makefile
11915 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
11916 CFLAGS_REMOVE_perf_event.o = -pg
11917 endif
11918
11919 -# Make sure load_percpu_segment has no stackprotector
11920 -nostackp := $(call cc-option, -fno-stack-protector)
11921 -CFLAGS_common.o := $(nostackp)
11922 -
11923 obj-y := intel_cacheinfo.o scattered.o topology.o
11924 obj-y += proc.o capflags.o powerflags.o common.o
11925 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
11926 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
11927 index 0bab2b1..d0a1bf8 100644
11928 --- a/arch/x86/kernel/cpu/amd.c
11929 +++ b/arch/x86/kernel/cpu/amd.c
11930 @@ -664,7 +664,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
11931 unsigned int size)
11932 {
11933 /* AMD errata T13 (order #21922) */
11934 - if ((c->x86 == 6)) {
11935 + if (c->x86 == 6) {
11936 /* Duron Rev A0 */
11937 if (c->x86_model == 3 && c->x86_mask == 0)
11938 size = 64;
11939 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
11940 index aa003b1..47ea638 100644
11941 --- a/arch/x86/kernel/cpu/common.c
11942 +++ b/arch/x86/kernel/cpu/common.c
11943 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
11944
11945 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
11946
11947 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
11948 -#ifdef CONFIG_X86_64
11949 - /*
11950 - * We need valid kernel segments for data and code in long mode too
11951 - * IRET will check the segment types kkeil 2000/10/28
11952 - * Also sysret mandates a special GDT layout
11953 - *
11954 - * TLS descriptors are currently at a different place compared to i386.
11955 - * Hopefully nobody expects them at a fixed place (Wine?)
11956 - */
11957 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
11958 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
11959 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
11960 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
11961 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
11962 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
11963 -#else
11964 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
11965 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
11966 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
11967 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
11968 - /*
11969 - * Segments used for calling PnP BIOS have byte granularity.
11970 - * They code segments and data segments have fixed 64k limits,
11971 - * the transfer segment sizes are set at run time.
11972 - */
11973 - /* 32-bit code */
11974 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
11975 - /* 16-bit code */
11976 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
11977 - /* 16-bit data */
11978 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
11979 - /* 16-bit data */
11980 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
11981 - /* 16-bit data */
11982 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
11983 - /*
11984 - * The APM segments have byte granularity and their bases
11985 - * are set at run time. All have 64k limits.
11986 - */
11987 - /* 32-bit code */
11988 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
11989 - /* 16-bit code */
11990 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
11991 - /* data */
11992 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
11993 -
11994 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
11995 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
11996 - GDT_STACK_CANARY_INIT
11997 -#endif
11998 -} };
11999 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
12000 -
12001 static int __init x86_xsave_setup(char *s)
12002 {
12003 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
12004 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
12005 {
12006 struct desc_ptr gdt_descr;
12007
12008 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
12009 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
12010 gdt_descr.size = GDT_SIZE - 1;
12011 load_gdt(&gdt_descr);
12012 /* Reload the per-cpu base */
12013 @@ -844,6 +790,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
12014 /* Filter out anything that depends on CPUID levels we don't have */
12015 filter_cpuid_features(c, true);
12016
12017 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
12018 + setup_clear_cpu_cap(X86_FEATURE_SEP);
12019 +#endif
12020 +
12021 /* If the model name is still unset, do table lookup. */
12022 if (!c->x86_model_id[0]) {
12023 const char *p;
12024 @@ -1024,6 +974,9 @@ static __init int setup_disablecpuid(char *arg)
12025 }
12026 __setup("clearcpuid=", setup_disablecpuid);
12027
12028 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
12029 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
12030 +
12031 #ifdef CONFIG_X86_64
12032 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
12033
12034 @@ -1039,7 +992,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
12035 EXPORT_PER_CPU_SYMBOL(current_task);
12036
12037 DEFINE_PER_CPU(unsigned long, kernel_stack) =
12038 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
12039 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
12040 EXPORT_PER_CPU_SYMBOL(kernel_stack);
12041
12042 DEFINE_PER_CPU(char *, irq_stack_ptr) =
12043 @@ -1104,7 +1057,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
12044 {
12045 memset(regs, 0, sizeof(struct pt_regs));
12046 regs->fs = __KERNEL_PERCPU;
12047 - regs->gs = __KERNEL_STACK_CANARY;
12048 + savesegment(gs, regs->gs);
12049
12050 return regs;
12051 }
12052 @@ -1159,7 +1112,7 @@ void __cpuinit cpu_init(void)
12053 int i;
12054
12055 cpu = stack_smp_processor_id();
12056 - t = &per_cpu(init_tss, cpu);
12057 + t = init_tss + cpu;
12058 oist = &per_cpu(orig_ist, cpu);
12059
12060 #ifdef CONFIG_NUMA
12061 @@ -1185,7 +1138,7 @@ void __cpuinit cpu_init(void)
12062 switch_to_new_gdt(cpu);
12063 loadsegment(fs, 0);
12064
12065 - load_idt((const struct desc_ptr *)&idt_descr);
12066 + load_idt(&idt_descr);
12067
12068 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
12069 syscall_init();
12070 @@ -1194,7 +1147,6 @@ void __cpuinit cpu_init(void)
12071 wrmsrl(MSR_KERNEL_GS_BASE, 0);
12072 barrier();
12073
12074 - x86_configure_nx();
12075 if (cpu != 0)
12076 enable_x2apic();
12077
12078 @@ -1248,7 +1200,7 @@ void __cpuinit cpu_init(void)
12079 {
12080 int cpu = smp_processor_id();
12081 struct task_struct *curr = current;
12082 - struct tss_struct *t = &per_cpu(init_tss, cpu);
12083 + struct tss_struct *t = init_tss + cpu;
12084 struct thread_struct *thread = &curr->thread;
12085
12086 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
12087 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
12088 index 5231312..a78a987 100644
12089 --- a/arch/x86/kernel/cpu/intel.c
12090 +++ b/arch/x86/kernel/cpu/intel.c
12091 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
12092 * Update the IDT descriptor and reload the IDT so that
12093 * it uses the read-only mapped virtual address.
12094 */
12095 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
12096 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
12097 load_idt(&idt_descr);
12098 }
12099 #endif
12100 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
12101 index 2af127d..8ff7ac0 100644
12102 --- a/arch/x86/kernel/cpu/mcheck/mce.c
12103 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
12104 @@ -42,6 +42,7 @@
12105 #include <asm/processor.h>
12106 #include <asm/mce.h>
12107 #include <asm/msr.h>
12108 +#include <asm/local.h>
12109
12110 #include "mce-internal.h"
12111
12112 @@ -202,7 +203,7 @@ static void print_mce(struct mce *m)
12113 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
12114 m->cs, m->ip);
12115
12116 - if (m->cs == __KERNEL_CS)
12117 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
12118 print_symbol("{%s}", m->ip);
12119 pr_cont("\n");
12120 }
12121 @@ -235,10 +236,10 @@ static void print_mce(struct mce *m)
12122
12123 #define PANIC_TIMEOUT 5 /* 5 seconds */
12124
12125 -static atomic_t mce_paniced;
12126 +static atomic_unchecked_t mce_paniced;
12127
12128 static int fake_panic;
12129 -static atomic_t mce_fake_paniced;
12130 +static atomic_unchecked_t mce_fake_paniced;
12131
12132 /* Panic in progress. Enable interrupts and wait for final IPI */
12133 static void wait_for_panic(void)
12134 @@ -262,7 +263,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
12135 /*
12136 * Make sure only one CPU runs in machine check panic
12137 */
12138 - if (atomic_inc_return(&mce_paniced) > 1)
12139 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
12140 wait_for_panic();
12141 barrier();
12142
12143 @@ -270,7 +271,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
12144 console_verbose();
12145 } else {
12146 /* Don't log too much for fake panic */
12147 - if (atomic_inc_return(&mce_fake_paniced) > 1)
12148 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
12149 return;
12150 }
12151 /* First print corrected ones that are still unlogged */
12152 @@ -610,7 +611,7 @@ static int mce_timed_out(u64 *t)
12153 * might have been modified by someone else.
12154 */
12155 rmb();
12156 - if (atomic_read(&mce_paniced))
12157 + if (atomic_read_unchecked(&mce_paniced))
12158 wait_for_panic();
12159 if (!monarch_timeout)
12160 goto out;
12161 @@ -1398,7 +1399,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
12162 }
12163
12164 /* Call the installed machine check handler for this CPU setup. */
12165 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
12166 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
12167 unexpected_machine_check;
12168
12169 /*
12170 @@ -1421,7 +1422,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
12171 return;
12172 }
12173
12174 + pax_open_kernel();
12175 machine_check_vector = do_machine_check;
12176 + pax_close_kernel();
12177
12178 __mcheck_cpu_init_generic();
12179 __mcheck_cpu_init_vendor(c);
12180 @@ -1435,7 +1438,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
12181 */
12182
12183 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
12184 -static int mce_chrdev_open_count; /* #times opened */
12185 +static local_t mce_chrdev_open_count; /* #times opened */
12186 static int mce_chrdev_open_exclu; /* already open exclusive? */
12187
12188 static int mce_chrdev_open(struct inode *inode, struct file *file)
12189 @@ -1443,7 +1446,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
12190 spin_lock(&mce_chrdev_state_lock);
12191
12192 if (mce_chrdev_open_exclu ||
12193 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
12194 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
12195 spin_unlock(&mce_chrdev_state_lock);
12196
12197 return -EBUSY;
12198 @@ -1451,7 +1454,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
12199
12200 if (file->f_flags & O_EXCL)
12201 mce_chrdev_open_exclu = 1;
12202 - mce_chrdev_open_count++;
12203 + local_inc(&mce_chrdev_open_count);
12204
12205 spin_unlock(&mce_chrdev_state_lock);
12206
12207 @@ -1462,7 +1465,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
12208 {
12209 spin_lock(&mce_chrdev_state_lock);
12210
12211 - mce_chrdev_open_count--;
12212 + local_dec(&mce_chrdev_open_count);
12213 mce_chrdev_open_exclu = 0;
12214
12215 spin_unlock(&mce_chrdev_state_lock);
12216 @@ -2171,7 +2174,7 @@ struct dentry *mce_get_debugfs_dir(void)
12217 static void mce_reset(void)
12218 {
12219 cpu_missing = 0;
12220 - atomic_set(&mce_fake_paniced, 0);
12221 + atomic_set_unchecked(&mce_fake_paniced, 0);
12222 atomic_set(&mce_executing, 0);
12223 atomic_set(&mce_callin, 0);
12224 atomic_set(&global_nwo, 0);
12225 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
12226 index 5c0e653..1e82c7c 100644
12227 --- a/arch/x86/kernel/cpu/mcheck/p5.c
12228 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
12229 @@ -50,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
12230 if (!cpu_has(c, X86_FEATURE_MCE))
12231 return;
12232
12233 + pax_open_kernel();
12234 machine_check_vector = pentium_machine_check;
12235 + pax_close_kernel();
12236 /* Make sure the vector pointer is visible before we enable MCEs: */
12237 wmb();
12238
12239 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
12240 index 54060f5..e6ba93d 100644
12241 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
12242 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
12243 @@ -24,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
12244 {
12245 u32 lo, hi;
12246
12247 + pax_open_kernel();
12248 machine_check_vector = winchip_machine_check;
12249 + pax_close_kernel();
12250 /* Make sure the vector pointer is visible before we enable MCEs: */
12251 wmb();
12252
12253 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
12254 index 6b96110..0da73eb 100644
12255 --- a/arch/x86/kernel/cpu/mtrr/main.c
12256 +++ b/arch/x86/kernel/cpu/mtrr/main.c
12257 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
12258 u64 size_or_mask, size_and_mask;
12259 static bool mtrr_aps_delayed_init;
12260
12261 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
12262 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
12263
12264 const struct mtrr_ops *mtrr_if;
12265
12266 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
12267 index df5e41f..816c719 100644
12268 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
12269 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
12270 @@ -25,7 +25,7 @@ struct mtrr_ops {
12271 int (*validate_add_page)(unsigned long base, unsigned long size,
12272 unsigned int type);
12273 int (*have_wrcomb)(void);
12274 -};
12275 +} __do_const;
12276
12277 extern int generic_get_free_region(unsigned long base, unsigned long size,
12278 int replace_reg);
12279 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
12280 index 2bda212..78cc605 100644
12281 --- a/arch/x86/kernel/cpu/perf_event.c
12282 +++ b/arch/x86/kernel/cpu/perf_event.c
12283 @@ -1529,7 +1529,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
12284 break;
12285
12286 perf_callchain_store(entry, frame.return_address);
12287 - fp = frame.next_frame;
12288 + fp = (const void __force_user *)frame.next_frame;
12289 }
12290 }
12291
12292 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
12293 index 13ad899..f642b9a 100644
12294 --- a/arch/x86/kernel/crash.c
12295 +++ b/arch/x86/kernel/crash.c
12296 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
12297 {
12298 #ifdef CONFIG_X86_32
12299 struct pt_regs fixed_regs;
12300 -#endif
12301
12302 -#ifdef CONFIG_X86_32
12303 - if (!user_mode_vm(regs)) {
12304 + if (!user_mode(regs)) {
12305 crash_fixup_ss_esp(&fixed_regs, regs);
12306 regs = &fixed_regs;
12307 }
12308 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
12309 index 37250fe..bf2ec74 100644
12310 --- a/arch/x86/kernel/doublefault_32.c
12311 +++ b/arch/x86/kernel/doublefault_32.c
12312 @@ -11,7 +11,7 @@
12313
12314 #define DOUBLEFAULT_STACKSIZE (1024)
12315 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
12316 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
12317 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
12318
12319 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
12320
12321 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
12322 unsigned long gdt, tss;
12323
12324 store_gdt(&gdt_desc);
12325 - gdt = gdt_desc.address;
12326 + gdt = (unsigned long)gdt_desc.address;
12327
12328 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
12329
12330 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
12331 /* 0x2 bit is always set */
12332 .flags = X86_EFLAGS_SF | 0x2,
12333 .sp = STACK_START,
12334 - .es = __USER_DS,
12335 + .es = __KERNEL_DS,
12336 .cs = __KERNEL_CS,
12337 .ss = __KERNEL_DS,
12338 - .ds = __USER_DS,
12339 + .ds = __KERNEL_DS,
12340 .fs = __KERNEL_PERCPU,
12341
12342 .__cr3 = __pa_nodebug(swapper_pg_dir),
12343 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
12344 index 1aae78f..aab3a3d 100644
12345 --- a/arch/x86/kernel/dumpstack.c
12346 +++ b/arch/x86/kernel/dumpstack.c
12347 @@ -2,6 +2,9 @@
12348 * Copyright (C) 1991, 1992 Linus Torvalds
12349 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
12350 */
12351 +#ifdef CONFIG_GRKERNSEC_HIDESYM
12352 +#define __INCLUDED_BY_HIDESYM 1
12353 +#endif
12354 #include <linux/kallsyms.h>
12355 #include <linux/kprobes.h>
12356 #include <linux/uaccess.h>
12357 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
12358 static void
12359 print_ftrace_graph_addr(unsigned long addr, void *data,
12360 const struct stacktrace_ops *ops,
12361 - struct thread_info *tinfo, int *graph)
12362 + struct task_struct *task, int *graph)
12363 {
12364 - struct task_struct *task = tinfo->task;
12365 unsigned long ret_addr;
12366 int index = task->curr_ret_stack;
12367
12368 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
12369 static inline void
12370 print_ftrace_graph_addr(unsigned long addr, void *data,
12371 const struct stacktrace_ops *ops,
12372 - struct thread_info *tinfo, int *graph)
12373 + struct task_struct *task, int *graph)
12374 { }
12375 #endif
12376
12377 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
12378 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
12379 */
12380
12381 -static inline int valid_stack_ptr(struct thread_info *tinfo,
12382 - void *p, unsigned int size, void *end)
12383 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
12384 {
12385 - void *t = tinfo;
12386 if (end) {
12387 if (p < end && p >= (end-THREAD_SIZE))
12388 return 1;
12389 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
12390 }
12391
12392 unsigned long
12393 -print_context_stack(struct thread_info *tinfo,
12394 +print_context_stack(struct task_struct *task, void *stack_start,
12395 unsigned long *stack, unsigned long bp,
12396 const struct stacktrace_ops *ops, void *data,
12397 unsigned long *end, int *graph)
12398 {
12399 struct stack_frame *frame = (struct stack_frame *)bp;
12400
12401 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
12402 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
12403 unsigned long addr;
12404
12405 addr = *stack;
12406 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
12407 } else {
12408 ops->address(data, addr, 0);
12409 }
12410 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12411 + print_ftrace_graph_addr(addr, data, ops, task, graph);
12412 }
12413 stack++;
12414 }
12415 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
12416 EXPORT_SYMBOL_GPL(print_context_stack);
12417
12418 unsigned long
12419 -print_context_stack_bp(struct thread_info *tinfo,
12420 +print_context_stack_bp(struct task_struct *task, void *stack_start,
12421 unsigned long *stack, unsigned long bp,
12422 const struct stacktrace_ops *ops, void *data,
12423 unsigned long *end, int *graph)
12424 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
12425 struct stack_frame *frame = (struct stack_frame *)bp;
12426 unsigned long *ret_addr = &frame->return_address;
12427
12428 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
12429 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
12430 unsigned long addr = *ret_addr;
12431
12432 if (!__kernel_text_address(addr))
12433 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
12434 ops->address(data, addr, 1);
12435 frame = frame->next_frame;
12436 ret_addr = &frame->return_address;
12437 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12438 + print_ftrace_graph_addr(addr, data, ops, task, graph);
12439 }
12440
12441 return (unsigned long)frame;
12442 @@ -186,7 +186,7 @@ void dump_stack(void)
12443
12444 bp = stack_frame(current, NULL);
12445 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
12446 - current->pid, current->comm, print_tainted(),
12447 + task_pid_nr(current), current->comm, print_tainted(),
12448 init_utsname()->release,
12449 (int)strcspn(init_utsname()->version, " "),
12450 init_utsname()->version);
12451 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
12452 }
12453 EXPORT_SYMBOL_GPL(oops_begin);
12454
12455 +extern void gr_handle_kernel_exploit(void);
12456 +
12457 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12458 {
12459 if (regs && kexec_should_crash(current))
12460 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12461 panic("Fatal exception in interrupt");
12462 if (panic_on_oops)
12463 panic("Fatal exception");
12464 - do_exit(signr);
12465 +
12466 + gr_handle_kernel_exploit();
12467 +
12468 + do_group_exit(signr);
12469 }
12470
12471 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12472 @@ -269,7 +274,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12473
12474 show_registers(regs);
12475 #ifdef CONFIG_X86_32
12476 - if (user_mode_vm(regs)) {
12477 + if (user_mode(regs)) {
12478 sp = regs->sp;
12479 ss = regs->ss & 0xffff;
12480 } else {
12481 @@ -297,7 +302,7 @@ void die(const char *str, struct pt_regs *regs, long err)
12482 unsigned long flags = oops_begin();
12483 int sig = SIGSEGV;
12484
12485 - if (!user_mode_vm(regs))
12486 + if (!user_mode(regs))
12487 report_bug(regs->ip, regs);
12488
12489 if (__die(str, regs, err))
12490 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
12491 index c99f9ed..2a15d80 100644
12492 --- a/arch/x86/kernel/dumpstack_32.c
12493 +++ b/arch/x86/kernel/dumpstack_32.c
12494 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12495 bp = stack_frame(task, regs);
12496
12497 for (;;) {
12498 - struct thread_info *context;
12499 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12500
12501 - context = (struct thread_info *)
12502 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
12503 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
12504 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12505
12506 - stack = (unsigned long *)context->previous_esp;
12507 - if (!stack)
12508 + if (stack_start == task_stack_page(task))
12509 break;
12510 + stack = *(unsigned long **)stack_start;
12511 if (ops->stack(data, "IRQ") < 0)
12512 break;
12513 touch_nmi_watchdog();
12514 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
12515 * When in-kernel, we also print out the stack and code at the
12516 * time of the fault..
12517 */
12518 - if (!user_mode_vm(regs)) {
12519 + if (!user_mode(regs)) {
12520 unsigned int code_prologue = code_bytes * 43 / 64;
12521 unsigned int code_len = code_bytes;
12522 unsigned char c;
12523 u8 *ip;
12524 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
12525
12526 printk(KERN_EMERG "Stack:\n");
12527 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
12528
12529 printk(KERN_EMERG "Code: ");
12530
12531 - ip = (u8 *)regs->ip - code_prologue;
12532 + ip = (u8 *)regs->ip - code_prologue + cs_base;
12533 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
12534 /* try starting at IP */
12535 - ip = (u8 *)regs->ip;
12536 + ip = (u8 *)regs->ip + cs_base;
12537 code_len = code_len - code_prologue + 1;
12538 }
12539 for (i = 0; i < code_len; i++, ip++) {
12540 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
12541 printk(KERN_CONT " Bad EIP value.");
12542 break;
12543 }
12544 - if (ip == (u8 *)regs->ip)
12545 + if (ip == (u8 *)regs->ip + cs_base)
12546 printk(KERN_CONT "<%02x> ", c);
12547 else
12548 printk(KERN_CONT "%02x ", c);
12549 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
12550 {
12551 unsigned short ud2;
12552
12553 + ip = ktla_ktva(ip);
12554 if (ip < PAGE_OFFSET)
12555 return 0;
12556 if (probe_kernel_address((unsigned short *)ip, ud2))
12557 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
12558
12559 return ud2 == 0x0b0f;
12560 }
12561 +
12562 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12563 +void pax_check_alloca(unsigned long size)
12564 +{
12565 + unsigned long sp = (unsigned long)&sp, stack_left;
12566 +
12567 + /* all kernel stacks are of the same size */
12568 + stack_left = sp & (THREAD_SIZE - 1);
12569 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12570 +}
12571 +EXPORT_SYMBOL(pax_check_alloca);
12572 +#endif
12573 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
12574 index 6d728d9..279514e 100644
12575 --- a/arch/x86/kernel/dumpstack_64.c
12576 +++ b/arch/x86/kernel/dumpstack_64.c
12577 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12578 unsigned long *irq_stack_end =
12579 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
12580 unsigned used = 0;
12581 - struct thread_info *tinfo;
12582 int graph = 0;
12583 unsigned long dummy;
12584 + void *stack_start;
12585
12586 if (!task)
12587 task = current;
12588 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12589 * current stack address. If the stacks consist of nested
12590 * exceptions
12591 */
12592 - tinfo = task_thread_info(task);
12593 for (;;) {
12594 char *id;
12595 unsigned long *estack_end;
12596 +
12597 estack_end = in_exception_stack(cpu, (unsigned long)stack,
12598 &used, &id);
12599
12600 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12601 if (ops->stack(data, id) < 0)
12602 break;
12603
12604 - bp = ops->walk_stack(tinfo, stack, bp, ops,
12605 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
12606 data, estack_end, &graph);
12607 ops->stack(data, "<EOE>");
12608 /*
12609 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12610 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
12611 if (ops->stack(data, "IRQ") < 0)
12612 break;
12613 - bp = ops->walk_stack(tinfo, stack, bp,
12614 + bp = ops->walk_stack(task, irq_stack, stack, bp,
12615 ops, data, irq_stack_end, &graph);
12616 /*
12617 * We link to the next stack (which would be
12618 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12619 /*
12620 * This handles the process stack:
12621 */
12622 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
12623 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12624 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12625 put_cpu();
12626 }
12627 EXPORT_SYMBOL(dump_trace);
12628 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
12629
12630 return ud2 == 0x0b0f;
12631 }
12632 +
12633 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12634 +void pax_check_alloca(unsigned long size)
12635 +{
12636 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
12637 + unsigned cpu, used;
12638 + char *id;
12639 +
12640 + /* check the process stack first */
12641 + stack_start = (unsigned long)task_stack_page(current);
12642 + stack_end = stack_start + THREAD_SIZE;
12643 + if (likely(stack_start <= sp && sp < stack_end)) {
12644 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
12645 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12646 + return;
12647 + }
12648 +
12649 + cpu = get_cpu();
12650 +
12651 + /* check the irq stacks */
12652 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
12653 + stack_start = stack_end - IRQ_STACK_SIZE;
12654 + if (stack_start <= sp && sp < stack_end) {
12655 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
12656 + put_cpu();
12657 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12658 + return;
12659 + }
12660 +
12661 + /* check the exception stacks */
12662 + used = 0;
12663 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
12664 + stack_start = stack_end - EXCEPTION_STKSZ;
12665 + if (stack_end && stack_start <= sp && sp < stack_end) {
12666 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
12667 + put_cpu();
12668 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12669 + return;
12670 + }
12671 +
12672 + put_cpu();
12673 +
12674 + /* unknown stack */
12675 + BUG();
12676 +}
12677 +EXPORT_SYMBOL(pax_check_alloca);
12678 +#endif
12679 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
12680 index cd28a35..c72ed9a 100644
12681 --- a/arch/x86/kernel/early_printk.c
12682 +++ b/arch/x86/kernel/early_printk.c
12683 @@ -7,6 +7,7 @@
12684 #include <linux/pci_regs.h>
12685 #include <linux/pci_ids.h>
12686 #include <linux/errno.h>
12687 +#include <linux/sched.h>
12688 #include <asm/io.h>
12689 #include <asm/processor.h>
12690 #include <asm/fcntl.h>
12691 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
12692 index f3f6f53..0841b66 100644
12693 --- a/arch/x86/kernel/entry_32.S
12694 +++ b/arch/x86/kernel/entry_32.S
12695 @@ -186,13 +186,146 @@
12696 /*CFI_REL_OFFSET gs, PT_GS*/
12697 .endm
12698 .macro SET_KERNEL_GS reg
12699 +
12700 +#ifdef CONFIG_CC_STACKPROTECTOR
12701 movl $(__KERNEL_STACK_CANARY), \reg
12702 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
12703 + movl $(__USER_DS), \reg
12704 +#else
12705 + xorl \reg, \reg
12706 +#endif
12707 +
12708 movl \reg, %gs
12709 .endm
12710
12711 #endif /* CONFIG_X86_32_LAZY_GS */
12712
12713 -.macro SAVE_ALL
12714 +.macro pax_enter_kernel
12715 +#ifdef CONFIG_PAX_KERNEXEC
12716 + call pax_enter_kernel
12717 +#endif
12718 +.endm
12719 +
12720 +.macro pax_exit_kernel
12721 +#ifdef CONFIG_PAX_KERNEXEC
12722 + call pax_exit_kernel
12723 +#endif
12724 +.endm
12725 +
12726 +#ifdef CONFIG_PAX_KERNEXEC
12727 +ENTRY(pax_enter_kernel)
12728 +#ifdef CONFIG_PARAVIRT
12729 + pushl %eax
12730 + pushl %ecx
12731 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
12732 + mov %eax, %esi
12733 +#else
12734 + mov %cr0, %esi
12735 +#endif
12736 + bts $16, %esi
12737 + jnc 1f
12738 + mov %cs, %esi
12739 + cmp $__KERNEL_CS, %esi
12740 + jz 3f
12741 + ljmp $__KERNEL_CS, $3f
12742 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
12743 +2:
12744 +#ifdef CONFIG_PARAVIRT
12745 + mov %esi, %eax
12746 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12747 +#else
12748 + mov %esi, %cr0
12749 +#endif
12750 +3:
12751 +#ifdef CONFIG_PARAVIRT
12752 + popl %ecx
12753 + popl %eax
12754 +#endif
12755 + ret
12756 +ENDPROC(pax_enter_kernel)
12757 +
12758 +ENTRY(pax_exit_kernel)
12759 +#ifdef CONFIG_PARAVIRT
12760 + pushl %eax
12761 + pushl %ecx
12762 +#endif
12763 + mov %cs, %esi
12764 + cmp $__KERNEXEC_KERNEL_CS, %esi
12765 + jnz 2f
12766 +#ifdef CONFIG_PARAVIRT
12767 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
12768 + mov %eax, %esi
12769 +#else
12770 + mov %cr0, %esi
12771 +#endif
12772 + btr $16, %esi
12773 + ljmp $__KERNEL_CS, $1f
12774 +1:
12775 +#ifdef CONFIG_PARAVIRT
12776 + mov %esi, %eax
12777 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
12778 +#else
12779 + mov %esi, %cr0
12780 +#endif
12781 +2:
12782 +#ifdef CONFIG_PARAVIRT
12783 + popl %ecx
12784 + popl %eax
12785 +#endif
12786 + ret
12787 +ENDPROC(pax_exit_kernel)
12788 +#endif
12789 +
12790 +.macro pax_erase_kstack
12791 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12792 + call pax_erase_kstack
12793 +#endif
12794 +.endm
12795 +
12796 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12797 +/*
12798 + * ebp: thread_info
12799 + * ecx, edx: can be clobbered
12800 + */
12801 +ENTRY(pax_erase_kstack)
12802 + pushl %edi
12803 + pushl %eax
12804 +
12805 + mov TI_lowest_stack(%ebp), %edi
12806 + mov $-0xBEEF, %eax
12807 + std
12808 +
12809 +1: mov %edi, %ecx
12810 + and $THREAD_SIZE_asm - 1, %ecx
12811 + shr $2, %ecx
12812 + repne scasl
12813 + jecxz 2f
12814 +
12815 + cmp $2*16, %ecx
12816 + jc 2f
12817 +
12818 + mov $2*16, %ecx
12819 + repe scasl
12820 + jecxz 2f
12821 + jne 1b
12822 +
12823 +2: cld
12824 + mov %esp, %ecx
12825 + sub %edi, %ecx
12826 + shr $2, %ecx
12827 + rep stosl
12828 +
12829 + mov TI_task_thread_sp0(%ebp), %edi
12830 + sub $128, %edi
12831 + mov %edi, TI_lowest_stack(%ebp)
12832 +
12833 + popl %eax
12834 + popl %edi
12835 + ret
12836 +ENDPROC(pax_erase_kstack)
12837 +#endif
12838 +
12839 +.macro __SAVE_ALL _DS
12840 cld
12841 PUSH_GS
12842 pushl_cfi %fs
12843 @@ -215,7 +348,7 @@
12844 CFI_REL_OFFSET ecx, 0
12845 pushl_cfi %ebx
12846 CFI_REL_OFFSET ebx, 0
12847 - movl $(__USER_DS), %edx
12848 + movl $\_DS, %edx
12849 movl %edx, %ds
12850 movl %edx, %es
12851 movl $(__KERNEL_PERCPU), %edx
12852 @@ -223,6 +356,15 @@
12853 SET_KERNEL_GS %edx
12854 .endm
12855
12856 +.macro SAVE_ALL
12857 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
12858 + __SAVE_ALL __KERNEL_DS
12859 + pax_enter_kernel
12860 +#else
12861 + __SAVE_ALL __USER_DS
12862 +#endif
12863 +.endm
12864 +
12865 .macro RESTORE_INT_REGS
12866 popl_cfi %ebx
12867 CFI_RESTORE ebx
12868 @@ -308,7 +450,7 @@ ENTRY(ret_from_fork)
12869 popfl_cfi
12870 jmp syscall_exit
12871 CFI_ENDPROC
12872 -END(ret_from_fork)
12873 +ENDPROC(ret_from_fork)
12874
12875 /*
12876 * Interrupt exit functions should be protected against kprobes
12877 @@ -333,7 +475,15 @@ check_userspace:
12878 movb PT_CS(%esp), %al
12879 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
12880 cmpl $USER_RPL, %eax
12881 +
12882 +#ifdef CONFIG_PAX_KERNEXEC
12883 + jae resume_userspace
12884 +
12885 + PAX_EXIT_KERNEL
12886 + jmp resume_kernel
12887 +#else
12888 jb resume_kernel # not returning to v8086 or userspace
12889 +#endif
12890
12891 ENTRY(resume_userspace)
12892 LOCKDEP_SYS_EXIT
12893 @@ -345,8 +495,8 @@ ENTRY(resume_userspace)
12894 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
12895 # int/exception return?
12896 jne work_pending
12897 - jmp restore_all
12898 -END(ret_from_exception)
12899 + jmp restore_all_pax
12900 +ENDPROC(ret_from_exception)
12901
12902 #ifdef CONFIG_PREEMPT
12903 ENTRY(resume_kernel)
12904 @@ -361,7 +511,7 @@ need_resched:
12905 jz restore_all
12906 call preempt_schedule_irq
12907 jmp need_resched
12908 -END(resume_kernel)
12909 +ENDPROC(resume_kernel)
12910 #endif
12911 CFI_ENDPROC
12912 /*
12913 @@ -395,23 +545,34 @@ sysenter_past_esp:
12914 /*CFI_REL_OFFSET cs, 0*/
12915 /*
12916 * Push current_thread_info()->sysenter_return to the stack.
12917 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
12918 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
12919 */
12920 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
12921 + pushl_cfi $0
12922 CFI_REL_OFFSET eip, 0
12923
12924 pushl_cfi %eax
12925 SAVE_ALL
12926 + GET_THREAD_INFO(%ebp)
12927 + movl TI_sysenter_return(%ebp),%ebp
12928 + movl %ebp,PT_EIP(%esp)
12929 ENABLE_INTERRUPTS(CLBR_NONE)
12930
12931 /*
12932 * Load the potential sixth argument from user stack.
12933 * Careful about security.
12934 */
12935 + movl PT_OLDESP(%esp),%ebp
12936 +
12937 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12938 + mov PT_OLDSS(%esp),%ds
12939 +1: movl %ds:(%ebp),%ebp
12940 + push %ss
12941 + pop %ds
12942 +#else
12943 cmpl $__PAGE_OFFSET-3,%ebp
12944 jae syscall_fault
12945 1: movl (%ebp),%ebp
12946 +#endif
12947 +
12948 movl %ebp,PT_EBP(%esp)
12949 .section __ex_table,"a"
12950 .align 4
12951 @@ -434,12 +595,24 @@ sysenter_do_call:
12952 testl $_TIF_ALLWORK_MASK, %ecx
12953 jne sysexit_audit
12954 sysenter_exit:
12955 +
12956 +#ifdef CONFIG_PAX_RANDKSTACK
12957 + pushl_cfi %eax
12958 + movl %esp, %eax
12959 + call pax_randomize_kstack
12960 + popl_cfi %eax
12961 +#endif
12962 +
12963 + pax_erase_kstack
12964 +
12965 /* if something modifies registers it must also disable sysexit */
12966 movl PT_EIP(%esp), %edx
12967 movl PT_OLDESP(%esp), %ecx
12968 xorl %ebp,%ebp
12969 TRACE_IRQS_ON
12970 1: mov PT_FS(%esp), %fs
12971 +2: mov PT_DS(%esp), %ds
12972 +3: mov PT_ES(%esp), %es
12973 PTGS_TO_GS
12974 ENABLE_INTERRUPTS_SYSEXIT
12975
12976 @@ -456,6 +629,9 @@ sysenter_audit:
12977 movl %eax,%edx /* 2nd arg: syscall number */
12978 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
12979 call audit_syscall_entry
12980 +
12981 + pax_erase_kstack
12982 +
12983 pushl_cfi %ebx
12984 movl PT_EAX(%esp),%eax /* reload syscall number */
12985 jmp sysenter_do_call
12986 @@ -482,11 +658,17 @@ sysexit_audit:
12987
12988 CFI_ENDPROC
12989 .pushsection .fixup,"ax"
12990 -2: movl $0,PT_FS(%esp)
12991 +4: movl $0,PT_FS(%esp)
12992 + jmp 1b
12993 +5: movl $0,PT_DS(%esp)
12994 + jmp 1b
12995 +6: movl $0,PT_ES(%esp)
12996 jmp 1b
12997 .section __ex_table,"a"
12998 .align 4
12999 - .long 1b,2b
13000 + .long 1b,4b
13001 + .long 2b,5b
13002 + .long 3b,6b
13003 .popsection
13004 PTGS_TO_GS_EX
13005 ENDPROC(ia32_sysenter_target)
13006 @@ -519,6 +701,15 @@ syscall_exit:
13007 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13008 jne syscall_exit_work
13009
13010 +restore_all_pax:
13011 +
13012 +#ifdef CONFIG_PAX_RANDKSTACK
13013 + movl %esp, %eax
13014 + call pax_randomize_kstack
13015 +#endif
13016 +
13017 + pax_erase_kstack
13018 +
13019 restore_all:
13020 TRACE_IRQS_IRET
13021 restore_all_notrace:
13022 @@ -578,14 +769,34 @@ ldt_ss:
13023 * compensating for the offset by changing to the ESPFIX segment with
13024 * a base address that matches for the difference.
13025 */
13026 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
13027 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
13028 mov %esp, %edx /* load kernel esp */
13029 mov PT_OLDESP(%esp), %eax /* load userspace esp */
13030 mov %dx, %ax /* eax: new kernel esp */
13031 sub %eax, %edx /* offset (low word is 0) */
13032 +#ifdef CONFIG_SMP
13033 + movl PER_CPU_VAR(cpu_number), %ebx
13034 + shll $PAGE_SHIFT_asm, %ebx
13035 + addl $cpu_gdt_table, %ebx
13036 +#else
13037 + movl $cpu_gdt_table, %ebx
13038 +#endif
13039 shr $16, %edx
13040 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
13041 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
13042 +
13043 +#ifdef CONFIG_PAX_KERNEXEC
13044 + mov %cr0, %esi
13045 + btr $16, %esi
13046 + mov %esi, %cr0
13047 +#endif
13048 +
13049 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
13050 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
13051 +
13052 +#ifdef CONFIG_PAX_KERNEXEC
13053 + bts $16, %esi
13054 + mov %esi, %cr0
13055 +#endif
13056 +
13057 pushl_cfi $__ESPFIX_SS
13058 pushl_cfi %eax /* new kernel esp */
13059 /* Disable interrupts, but do not irqtrace this section: we
13060 @@ -614,34 +825,28 @@ work_resched:
13061 movl TI_flags(%ebp), %ecx
13062 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
13063 # than syscall tracing?
13064 - jz restore_all
13065 + jz restore_all_pax
13066 testb $_TIF_NEED_RESCHED, %cl
13067 jnz work_resched
13068
13069 work_notifysig: # deal with pending signals and
13070 # notify-resume requests
13071 + movl %esp, %eax
13072 #ifdef CONFIG_VM86
13073 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
13074 - movl %esp, %eax
13075 - jne work_notifysig_v86 # returning to kernel-space or
13076 + jz 1f # returning to kernel-space or
13077 # vm86-space
13078 - xorl %edx, %edx
13079 - call do_notify_resume
13080 - jmp resume_userspace_sig
13081
13082 - ALIGN
13083 -work_notifysig_v86:
13084 pushl_cfi %ecx # save ti_flags for do_notify_resume
13085 call save_v86_state # %eax contains pt_regs pointer
13086 popl_cfi %ecx
13087 movl %eax, %esp
13088 -#else
13089 - movl %esp, %eax
13090 +1:
13091 #endif
13092 xorl %edx, %edx
13093 call do_notify_resume
13094 jmp resume_userspace_sig
13095 -END(work_pending)
13096 +ENDPROC(work_pending)
13097
13098 # perform syscall exit tracing
13099 ALIGN
13100 @@ -649,11 +854,14 @@ syscall_trace_entry:
13101 movl $-ENOSYS,PT_EAX(%esp)
13102 movl %esp, %eax
13103 call syscall_trace_enter
13104 +
13105 + pax_erase_kstack
13106 +
13107 /* What it returned is what we'll actually use. */
13108 cmpl $(nr_syscalls), %eax
13109 jnae syscall_call
13110 jmp syscall_exit
13111 -END(syscall_trace_entry)
13112 +ENDPROC(syscall_trace_entry)
13113
13114 # perform syscall exit tracing
13115 ALIGN
13116 @@ -666,20 +874,24 @@ syscall_exit_work:
13117 movl %esp, %eax
13118 call syscall_trace_leave
13119 jmp resume_userspace
13120 -END(syscall_exit_work)
13121 +ENDPROC(syscall_exit_work)
13122 CFI_ENDPROC
13123
13124 RING0_INT_FRAME # can't unwind into user space anyway
13125 syscall_fault:
13126 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13127 + push %ss
13128 + pop %ds
13129 +#endif
13130 GET_THREAD_INFO(%ebp)
13131 movl $-EFAULT,PT_EAX(%esp)
13132 jmp resume_userspace
13133 -END(syscall_fault)
13134 +ENDPROC(syscall_fault)
13135
13136 syscall_badsys:
13137 movl $-ENOSYS,PT_EAX(%esp)
13138 jmp resume_userspace
13139 -END(syscall_badsys)
13140 +ENDPROC(syscall_badsys)
13141 CFI_ENDPROC
13142 /*
13143 * End of kprobes section
13144 @@ -753,6 +965,36 @@ ptregs_clone:
13145 CFI_ENDPROC
13146 ENDPROC(ptregs_clone)
13147
13148 + ALIGN;
13149 +ENTRY(kernel_execve)
13150 + CFI_STARTPROC
13151 + pushl_cfi %ebp
13152 + sub $PT_OLDSS+4,%esp
13153 + pushl_cfi %edi
13154 + pushl_cfi %ecx
13155 + pushl_cfi %eax
13156 + lea 3*4(%esp),%edi
13157 + mov $PT_OLDSS/4+1,%ecx
13158 + xorl %eax,%eax
13159 + rep stosl
13160 + popl_cfi %eax
13161 + popl_cfi %ecx
13162 + popl_cfi %edi
13163 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
13164 + pushl_cfi %esp
13165 + call sys_execve
13166 + add $4,%esp
13167 + CFI_ADJUST_CFA_OFFSET -4
13168 + GET_THREAD_INFO(%ebp)
13169 + test %eax,%eax
13170 + jz syscall_exit
13171 + add $PT_OLDSS+4,%esp
13172 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
13173 + popl_cfi %ebp
13174 + ret
13175 + CFI_ENDPROC
13176 +ENDPROC(kernel_execve)
13177 +
13178 .macro FIXUP_ESPFIX_STACK
13179 /*
13180 * Switch back for ESPFIX stack to the normal zerobased stack
13181 @@ -762,8 +1004,15 @@ ENDPROC(ptregs_clone)
13182 * normal stack and adjusts ESP with the matching offset.
13183 */
13184 /* fixup the stack */
13185 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
13186 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
13187 +#ifdef CONFIG_SMP
13188 + movl PER_CPU_VAR(cpu_number), %ebx
13189 + shll $PAGE_SHIFT_asm, %ebx
13190 + addl $cpu_gdt_table, %ebx
13191 +#else
13192 + movl $cpu_gdt_table, %ebx
13193 +#endif
13194 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
13195 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
13196 shl $16, %eax
13197 addl %esp, %eax /* the adjusted stack pointer */
13198 pushl_cfi $__KERNEL_DS
13199 @@ -816,7 +1065,7 @@ vector=vector+1
13200 .endr
13201 2: jmp common_interrupt
13202 .endr
13203 -END(irq_entries_start)
13204 +ENDPROC(irq_entries_start)
13205
13206 .previous
13207 END(interrupt)
13208 @@ -864,7 +1113,7 @@ ENTRY(coprocessor_error)
13209 pushl_cfi $do_coprocessor_error
13210 jmp error_code
13211 CFI_ENDPROC
13212 -END(coprocessor_error)
13213 +ENDPROC(coprocessor_error)
13214
13215 ENTRY(simd_coprocessor_error)
13216 RING0_INT_FRAME
13217 @@ -885,7 +1134,7 @@ ENTRY(simd_coprocessor_error)
13218 #endif
13219 jmp error_code
13220 CFI_ENDPROC
13221 -END(simd_coprocessor_error)
13222 +ENDPROC(simd_coprocessor_error)
13223
13224 ENTRY(device_not_available)
13225 RING0_INT_FRAME
13226 @@ -893,7 +1142,7 @@ ENTRY(device_not_available)
13227 pushl_cfi $do_device_not_available
13228 jmp error_code
13229 CFI_ENDPROC
13230 -END(device_not_available)
13231 +ENDPROC(device_not_available)
13232
13233 #ifdef CONFIG_PARAVIRT
13234 ENTRY(native_iret)
13235 @@ -902,12 +1151,12 @@ ENTRY(native_iret)
13236 .align 4
13237 .long native_iret, iret_exc
13238 .previous
13239 -END(native_iret)
13240 +ENDPROC(native_iret)
13241
13242 ENTRY(native_irq_enable_sysexit)
13243 sti
13244 sysexit
13245 -END(native_irq_enable_sysexit)
13246 +ENDPROC(native_irq_enable_sysexit)
13247 #endif
13248
13249 ENTRY(overflow)
13250 @@ -916,7 +1165,7 @@ ENTRY(overflow)
13251 pushl_cfi $do_overflow
13252 jmp error_code
13253 CFI_ENDPROC
13254 -END(overflow)
13255 +ENDPROC(overflow)
13256
13257 ENTRY(bounds)
13258 RING0_INT_FRAME
13259 @@ -924,7 +1173,7 @@ ENTRY(bounds)
13260 pushl_cfi $do_bounds
13261 jmp error_code
13262 CFI_ENDPROC
13263 -END(bounds)
13264 +ENDPROC(bounds)
13265
13266 ENTRY(invalid_op)
13267 RING0_INT_FRAME
13268 @@ -932,7 +1181,7 @@ ENTRY(invalid_op)
13269 pushl_cfi $do_invalid_op
13270 jmp error_code
13271 CFI_ENDPROC
13272 -END(invalid_op)
13273 +ENDPROC(invalid_op)
13274
13275 ENTRY(coprocessor_segment_overrun)
13276 RING0_INT_FRAME
13277 @@ -940,35 +1189,35 @@ ENTRY(coprocessor_segment_overrun)
13278 pushl_cfi $do_coprocessor_segment_overrun
13279 jmp error_code
13280 CFI_ENDPROC
13281 -END(coprocessor_segment_overrun)
13282 +ENDPROC(coprocessor_segment_overrun)
13283
13284 ENTRY(invalid_TSS)
13285 RING0_EC_FRAME
13286 pushl_cfi $do_invalid_TSS
13287 jmp error_code
13288 CFI_ENDPROC
13289 -END(invalid_TSS)
13290 +ENDPROC(invalid_TSS)
13291
13292 ENTRY(segment_not_present)
13293 RING0_EC_FRAME
13294 pushl_cfi $do_segment_not_present
13295 jmp error_code
13296 CFI_ENDPROC
13297 -END(segment_not_present)
13298 +ENDPROC(segment_not_present)
13299
13300 ENTRY(stack_segment)
13301 RING0_EC_FRAME
13302 pushl_cfi $do_stack_segment
13303 jmp error_code
13304 CFI_ENDPROC
13305 -END(stack_segment)
13306 +ENDPROC(stack_segment)
13307
13308 ENTRY(alignment_check)
13309 RING0_EC_FRAME
13310 pushl_cfi $do_alignment_check
13311 jmp error_code
13312 CFI_ENDPROC
13313 -END(alignment_check)
13314 +ENDPROC(alignment_check)
13315
13316 ENTRY(divide_error)
13317 RING0_INT_FRAME
13318 @@ -976,7 +1225,7 @@ ENTRY(divide_error)
13319 pushl_cfi $do_divide_error
13320 jmp error_code
13321 CFI_ENDPROC
13322 -END(divide_error)
13323 +ENDPROC(divide_error)
13324
13325 #ifdef CONFIG_X86_MCE
13326 ENTRY(machine_check)
13327 @@ -985,7 +1234,7 @@ ENTRY(machine_check)
13328 pushl_cfi machine_check_vector
13329 jmp error_code
13330 CFI_ENDPROC
13331 -END(machine_check)
13332 +ENDPROC(machine_check)
13333 #endif
13334
13335 ENTRY(spurious_interrupt_bug)
13336 @@ -994,7 +1243,7 @@ ENTRY(spurious_interrupt_bug)
13337 pushl_cfi $do_spurious_interrupt_bug
13338 jmp error_code
13339 CFI_ENDPROC
13340 -END(spurious_interrupt_bug)
13341 +ENDPROC(spurious_interrupt_bug)
13342 /*
13343 * End of kprobes section
13344 */
13345 @@ -1109,7 +1358,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
13346
13347 ENTRY(mcount)
13348 ret
13349 -END(mcount)
13350 +ENDPROC(mcount)
13351
13352 ENTRY(ftrace_caller)
13353 cmpl $0, function_trace_stop
13354 @@ -1138,7 +1387,7 @@ ftrace_graph_call:
13355 .globl ftrace_stub
13356 ftrace_stub:
13357 ret
13358 -END(ftrace_caller)
13359 +ENDPROC(ftrace_caller)
13360
13361 #else /* ! CONFIG_DYNAMIC_FTRACE */
13362
13363 @@ -1174,7 +1423,7 @@ trace:
13364 popl %ecx
13365 popl %eax
13366 jmp ftrace_stub
13367 -END(mcount)
13368 +ENDPROC(mcount)
13369 #endif /* CONFIG_DYNAMIC_FTRACE */
13370 #endif /* CONFIG_FUNCTION_TRACER */
13371
13372 @@ -1195,7 +1444,7 @@ ENTRY(ftrace_graph_caller)
13373 popl %ecx
13374 popl %eax
13375 ret
13376 -END(ftrace_graph_caller)
13377 +ENDPROC(ftrace_graph_caller)
13378
13379 .globl return_to_handler
13380 return_to_handler:
13381 @@ -1209,7 +1458,6 @@ return_to_handler:
13382 jmp *%ecx
13383 #endif
13384
13385 -.section .rodata,"a"
13386 #include "syscall_table_32.S"
13387
13388 syscall_table_size=(.-sys_call_table)
13389 @@ -1255,15 +1503,18 @@ error_code:
13390 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
13391 REG_TO_PTGS %ecx
13392 SET_KERNEL_GS %ecx
13393 - movl $(__USER_DS), %ecx
13394 + movl $(__KERNEL_DS), %ecx
13395 movl %ecx, %ds
13396 movl %ecx, %es
13397 +
13398 + pax_enter_kernel
13399 +
13400 TRACE_IRQS_OFF
13401 movl %esp,%eax # pt_regs pointer
13402 call *%edi
13403 jmp ret_from_exception
13404 CFI_ENDPROC
13405 -END(page_fault)
13406 +ENDPROC(page_fault)
13407
13408 /*
13409 * Debug traps and NMI can happen at the one SYSENTER instruction
13410 @@ -1305,7 +1556,7 @@ debug_stack_correct:
13411 call do_debug
13412 jmp ret_from_exception
13413 CFI_ENDPROC
13414 -END(debug)
13415 +ENDPROC(debug)
13416
13417 /*
13418 * NMI is doubly nasty. It can happen _while_ we're handling
13419 @@ -1342,6 +1593,9 @@ nmi_stack_correct:
13420 xorl %edx,%edx # zero error code
13421 movl %esp,%eax # pt_regs pointer
13422 call do_nmi
13423 +
13424 + pax_exit_kernel
13425 +
13426 jmp restore_all_notrace
13427 CFI_ENDPROC
13428
13429 @@ -1378,12 +1632,15 @@ nmi_espfix_stack:
13430 FIXUP_ESPFIX_STACK # %eax == %esp
13431 xorl %edx,%edx # zero error code
13432 call do_nmi
13433 +
13434 + pax_exit_kernel
13435 +
13436 RESTORE_REGS
13437 lss 12+4(%esp), %esp # back to espfix stack
13438 CFI_ADJUST_CFA_OFFSET -24
13439 jmp irq_return
13440 CFI_ENDPROC
13441 -END(nmi)
13442 +ENDPROC(nmi)
13443
13444 ENTRY(int3)
13445 RING0_INT_FRAME
13446 @@ -1395,14 +1652,14 @@ ENTRY(int3)
13447 call do_int3
13448 jmp ret_from_exception
13449 CFI_ENDPROC
13450 -END(int3)
13451 +ENDPROC(int3)
13452
13453 ENTRY(general_protection)
13454 RING0_EC_FRAME
13455 pushl_cfi $do_general_protection
13456 jmp error_code
13457 CFI_ENDPROC
13458 -END(general_protection)
13459 +ENDPROC(general_protection)
13460
13461 #ifdef CONFIG_KVM_GUEST
13462 ENTRY(async_page_fault)
13463 @@ -1410,7 +1667,7 @@ ENTRY(async_page_fault)
13464 pushl_cfi $do_async_page_fault
13465 jmp error_code
13466 CFI_ENDPROC
13467 -END(async_page_fault)
13468 +ENDPROC(async_page_fault)
13469 #endif
13470
13471 /*
13472 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
13473 index faf8d5e..f58c441 100644
13474 --- a/arch/x86/kernel/entry_64.S
13475 +++ b/arch/x86/kernel/entry_64.S
13476 @@ -55,6 +55,8 @@
13477 #include <asm/paravirt.h>
13478 #include <asm/ftrace.h>
13479 #include <asm/percpu.h>
13480 +#include <asm/pgtable.h>
13481 +#include <asm/alternative-asm.h>
13482
13483 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13484 #include <linux/elf-em.h>
13485 @@ -68,8 +70,9 @@
13486 #ifdef CONFIG_FUNCTION_TRACER
13487 #ifdef CONFIG_DYNAMIC_FTRACE
13488 ENTRY(mcount)
13489 + pax_force_retaddr
13490 retq
13491 -END(mcount)
13492 +ENDPROC(mcount)
13493
13494 ENTRY(ftrace_caller)
13495 cmpl $0, function_trace_stop
13496 @@ -92,8 +95,9 @@ GLOBAL(ftrace_graph_call)
13497 #endif
13498
13499 GLOBAL(ftrace_stub)
13500 + pax_force_retaddr
13501 retq
13502 -END(ftrace_caller)
13503 +ENDPROC(ftrace_caller)
13504
13505 #else /* ! CONFIG_DYNAMIC_FTRACE */
13506 ENTRY(mcount)
13507 @@ -112,6 +116,7 @@ ENTRY(mcount)
13508 #endif
13509
13510 GLOBAL(ftrace_stub)
13511 + pax_force_retaddr
13512 retq
13513
13514 trace:
13515 @@ -121,12 +126,13 @@ trace:
13516 movq 8(%rbp), %rsi
13517 subq $MCOUNT_INSN_SIZE, %rdi
13518
13519 + pax_force_fptr ftrace_trace_function
13520 call *ftrace_trace_function
13521
13522 MCOUNT_RESTORE_FRAME
13523
13524 jmp ftrace_stub
13525 -END(mcount)
13526 +ENDPROC(mcount)
13527 #endif /* CONFIG_DYNAMIC_FTRACE */
13528 #endif /* CONFIG_FUNCTION_TRACER */
13529
13530 @@ -146,8 +152,9 @@ ENTRY(ftrace_graph_caller)
13531
13532 MCOUNT_RESTORE_FRAME
13533
13534 + pax_force_retaddr
13535 retq
13536 -END(ftrace_graph_caller)
13537 +ENDPROC(ftrace_graph_caller)
13538
13539 GLOBAL(return_to_handler)
13540 subq $24, %rsp
13541 @@ -163,6 +170,7 @@ GLOBAL(return_to_handler)
13542 movq 8(%rsp), %rdx
13543 movq (%rsp), %rax
13544 addq $24, %rsp
13545 + pax_force_fptr %rdi
13546 jmp *%rdi
13547 #endif
13548
13549 @@ -178,6 +186,282 @@ ENTRY(native_usergs_sysret64)
13550 ENDPROC(native_usergs_sysret64)
13551 #endif /* CONFIG_PARAVIRT */
13552
13553 + .macro ljmpq sel, off
13554 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
13555 + .byte 0x48; ljmp *1234f(%rip)
13556 + .pushsection .rodata
13557 + .align 16
13558 + 1234: .quad \off; .word \sel
13559 + .popsection
13560 +#else
13561 + pushq $\sel
13562 + pushq $\off
13563 + lretq
13564 +#endif
13565 + .endm
13566 +
13567 + .macro pax_enter_kernel
13568 + pax_set_fptr_mask
13569 +#ifdef CONFIG_PAX_KERNEXEC
13570 + call pax_enter_kernel
13571 +#endif
13572 + .endm
13573 +
13574 + .macro pax_exit_kernel
13575 +#ifdef CONFIG_PAX_KERNEXEC
13576 + call pax_exit_kernel
13577 +#endif
13578 + .endm
13579 +
13580 +#ifdef CONFIG_PAX_KERNEXEC
13581 +ENTRY(pax_enter_kernel)
13582 + pushq %rdi
13583 +
13584 +#ifdef CONFIG_PARAVIRT
13585 + PV_SAVE_REGS(CLBR_RDI)
13586 +#endif
13587 +
13588 + GET_CR0_INTO_RDI
13589 + bts $16,%rdi
13590 + jnc 3f
13591 + mov %cs,%edi
13592 + cmp $__KERNEL_CS,%edi
13593 + jnz 2f
13594 +1:
13595 +
13596 +#ifdef CONFIG_PARAVIRT
13597 + PV_RESTORE_REGS(CLBR_RDI)
13598 +#endif
13599 +
13600 + popq %rdi
13601 + pax_force_retaddr
13602 + retq
13603 +
13604 +2: ljmpq __KERNEL_CS,1f
13605 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
13606 +4: SET_RDI_INTO_CR0
13607 + jmp 1b
13608 +ENDPROC(pax_enter_kernel)
13609 +
13610 +ENTRY(pax_exit_kernel)
13611 + pushq %rdi
13612 +
13613 +#ifdef CONFIG_PARAVIRT
13614 + PV_SAVE_REGS(CLBR_RDI)
13615 +#endif
13616 +
13617 + mov %cs,%rdi
13618 + cmp $__KERNEXEC_KERNEL_CS,%edi
13619 + jz 2f
13620 +1:
13621 +
13622 +#ifdef CONFIG_PARAVIRT
13623 + PV_RESTORE_REGS(CLBR_RDI);
13624 +#endif
13625 +
13626 + popq %rdi
13627 + pax_force_retaddr
13628 + retq
13629 +
13630 +2: GET_CR0_INTO_RDI
13631 + btr $16,%rdi
13632 + ljmpq __KERNEL_CS,3f
13633 +3: SET_RDI_INTO_CR0
13634 + jmp 1b
13635 +#ifdef CONFIG_PARAVIRT
13636 + PV_RESTORE_REGS(CLBR_RDI);
13637 +#endif
13638 +
13639 + popq %rdi
13640 + pax_force_retaddr
13641 + retq
13642 +ENDPROC(pax_exit_kernel)
13643 +#endif
13644 +
13645 + .macro pax_enter_kernel_user
13646 + pax_set_fptr_mask
13647 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13648 + call pax_enter_kernel_user
13649 +#endif
13650 + .endm
13651 +
13652 + .macro pax_exit_kernel_user
13653 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13654 + call pax_exit_kernel_user
13655 +#endif
13656 +#ifdef CONFIG_PAX_RANDKSTACK
13657 + pushq %rax
13658 + call pax_randomize_kstack
13659 + popq %rax
13660 +#endif
13661 + .endm
13662 +
13663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13664 +ENTRY(pax_enter_kernel_user)
13665 + pushq %rdi
13666 + pushq %rbx
13667 +
13668 +#ifdef CONFIG_PARAVIRT
13669 + PV_SAVE_REGS(CLBR_RDI)
13670 +#endif
13671 +
13672 + GET_CR3_INTO_RDI
13673 + mov %rdi,%rbx
13674 + add $__START_KERNEL_map,%rbx
13675 + sub phys_base(%rip),%rbx
13676 +
13677 +#ifdef CONFIG_PARAVIRT
13678 + pushq %rdi
13679 + cmpl $0, pv_info+PARAVIRT_enabled
13680 + jz 1f
13681 + i = 0
13682 + .rept USER_PGD_PTRS
13683 + mov i*8(%rbx),%rsi
13684 + mov $0,%sil
13685 + lea i*8(%rbx),%rdi
13686 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
13687 + i = i + 1
13688 + .endr
13689 + jmp 2f
13690 +1:
13691 +#endif
13692 +
13693 + i = 0
13694 + .rept USER_PGD_PTRS
13695 + movb $0,i*8(%rbx)
13696 + i = i + 1
13697 + .endr
13698 +
13699 +#ifdef CONFIG_PARAVIRT
13700 +2: popq %rdi
13701 +#endif
13702 + SET_RDI_INTO_CR3
13703 +
13704 +#ifdef CONFIG_PAX_KERNEXEC
13705 + GET_CR0_INTO_RDI
13706 + bts $16,%rdi
13707 + SET_RDI_INTO_CR0
13708 +#endif
13709 +
13710 +#ifdef CONFIG_PARAVIRT
13711 + PV_RESTORE_REGS(CLBR_RDI)
13712 +#endif
13713 +
13714 + popq %rbx
13715 + popq %rdi
13716 + pax_force_retaddr
13717 + retq
13718 +ENDPROC(pax_enter_kernel_user)
13719 +
13720 +ENTRY(pax_exit_kernel_user)
13721 + push %rdi
13722 +
13723 +#ifdef CONFIG_PARAVIRT
13724 + pushq %rbx
13725 + PV_SAVE_REGS(CLBR_RDI)
13726 +#endif
13727 +
13728 +#ifdef CONFIG_PAX_KERNEXEC
13729 + GET_CR0_INTO_RDI
13730 + btr $16,%rdi
13731 + SET_RDI_INTO_CR0
13732 +#endif
13733 +
13734 + GET_CR3_INTO_RDI
13735 + add $__START_KERNEL_map,%rdi
13736 + sub phys_base(%rip),%rdi
13737 +
13738 +#ifdef CONFIG_PARAVIRT
13739 + cmpl $0, pv_info+PARAVIRT_enabled
13740 + jz 1f
13741 + mov %rdi,%rbx
13742 + i = 0
13743 + .rept USER_PGD_PTRS
13744 + mov i*8(%rbx),%rsi
13745 + mov $0x67,%sil
13746 + lea i*8(%rbx),%rdi
13747 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
13748 + i = i + 1
13749 + .endr
13750 + jmp 2f
13751 +1:
13752 +#endif
13753 +
13754 + i = 0
13755 + .rept USER_PGD_PTRS
13756 + movb $0x67,i*8(%rdi)
13757 + i = i + 1
13758 + .endr
13759 +
13760 +#ifdef CONFIG_PARAVIRT
13761 +2: PV_RESTORE_REGS(CLBR_RDI)
13762 + popq %rbx
13763 +#endif
13764 +
13765 + popq %rdi
13766 + pax_force_retaddr
13767 + retq
13768 +ENDPROC(pax_exit_kernel_user)
13769 +#endif
13770 +
13771 +.macro pax_erase_kstack
13772 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13773 + call pax_erase_kstack
13774 +#endif
13775 +.endm
13776 +
13777 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13778 +/*
13779 + * r11: thread_info
13780 + * rcx, rdx: can be clobbered
13781 + */
13782 +ENTRY(pax_erase_kstack)
13783 + pushq %rdi
13784 + pushq %rax
13785 + pushq %r11
13786 +
13787 + GET_THREAD_INFO(%r11)
13788 + mov TI_lowest_stack(%r11), %rdi
13789 + mov $-0xBEEF, %rax
13790 + std
13791 +
13792 +1: mov %edi, %ecx
13793 + and $THREAD_SIZE_asm - 1, %ecx
13794 + shr $3, %ecx
13795 + repne scasq
13796 + jecxz 2f
13797 +
13798 + cmp $2*8, %ecx
13799 + jc 2f
13800 +
13801 + mov $2*8, %ecx
13802 + repe scasq
13803 + jecxz 2f
13804 + jne 1b
13805 +
13806 +2: cld
13807 + mov %esp, %ecx
13808 + sub %edi, %ecx
13809 +
13810 + cmp $THREAD_SIZE_asm, %rcx
13811 + jb 3f
13812 + ud2
13813 +3:
13814 +
13815 + shr $3, %ecx
13816 + rep stosq
13817 +
13818 + mov TI_task_thread_sp0(%r11), %rdi
13819 + sub $256, %rdi
13820 + mov %rdi, TI_lowest_stack(%r11)
13821 +
13822 + popq %r11
13823 + popq %rax
13824 + popq %rdi
13825 + pax_force_retaddr
13826 + ret
13827 +ENDPROC(pax_erase_kstack)
13828 +#endif
13829
13830 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
13831 #ifdef CONFIG_TRACE_IRQFLAGS
13832 @@ -231,8 +515,8 @@ ENDPROC(native_usergs_sysret64)
13833 .endm
13834
13835 .macro UNFAKE_STACK_FRAME
13836 - addq $8*6, %rsp
13837 - CFI_ADJUST_CFA_OFFSET -(6*8)
13838 + addq $8*6 + ARG_SKIP, %rsp
13839 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
13840 .endm
13841
13842 /*
13843 @@ -319,7 +603,7 @@ ENDPROC(native_usergs_sysret64)
13844 movq %rsp, %rsi
13845
13846 leaq -RBP(%rsp),%rdi /* arg1 for handler */
13847 - testl $3, CS(%rdi)
13848 + testb $3, CS(%rdi)
13849 je 1f
13850 SWAPGS
13851 /*
13852 @@ -355,9 +639,10 @@ ENTRY(save_rest)
13853 movq_cfi r15, R15+16
13854 movq %r11, 8(%rsp) /* return address */
13855 FIXUP_TOP_OF_STACK %r11, 16
13856 + pax_force_retaddr
13857 ret
13858 CFI_ENDPROC
13859 -END(save_rest)
13860 +ENDPROC(save_rest)
13861
13862 /* save complete stack frame */
13863 .pushsection .kprobes.text, "ax"
13864 @@ -386,9 +671,10 @@ ENTRY(save_paranoid)
13865 js 1f /* negative -> in kernel */
13866 SWAPGS
13867 xorl %ebx,%ebx
13868 -1: ret
13869 +1: pax_force_retaddr_bts
13870 + ret
13871 CFI_ENDPROC
13872 -END(save_paranoid)
13873 +ENDPROC(save_paranoid)
13874 .popsection
13875
13876 /*
13877 @@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
13878
13879 RESTORE_REST
13880
13881 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13882 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13883 je int_ret_from_sys_call
13884
13885 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
13886 @@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
13887 jmp ret_from_sys_call # go to the SYSRET fastpath
13888
13889 CFI_ENDPROC
13890 -END(ret_from_fork)
13891 +ENDPROC(ret_from_fork)
13892
13893 /*
13894 * System call entry. Up to 6 arguments in registers are supported.
13895 @@ -456,7 +742,7 @@ END(ret_from_fork)
13896 ENTRY(system_call)
13897 CFI_STARTPROC simple
13898 CFI_SIGNAL_FRAME
13899 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13900 + CFI_DEF_CFA rsp,0
13901 CFI_REGISTER rip,rcx
13902 /*CFI_REGISTER rflags,r11*/
13903 SWAPGS_UNSAFE_STACK
13904 @@ -469,12 +755,13 @@ ENTRY(system_call_after_swapgs)
13905
13906 movq %rsp,PER_CPU_VAR(old_rsp)
13907 movq PER_CPU_VAR(kernel_stack),%rsp
13908 + SAVE_ARGS 8*6,0
13909 + pax_enter_kernel_user
13910 /*
13911 * No need to follow this irqs off/on section - it's straight
13912 * and short:
13913 */
13914 ENABLE_INTERRUPTS(CLBR_NONE)
13915 - SAVE_ARGS 8,0
13916 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13917 movq %rcx,RIP-ARGOFFSET(%rsp)
13918 CFI_REL_OFFSET rip,RIP-ARGOFFSET
13919 @@ -484,7 +771,7 @@ ENTRY(system_call_after_swapgs)
13920 system_call_fastpath:
13921 cmpq $__NR_syscall_max,%rax
13922 ja badsys
13923 - movq %r10,%rcx
13924 + movq R10-ARGOFFSET(%rsp),%rcx
13925 call *sys_call_table(,%rax,8) # XXX: rip relative
13926 movq %rax,RAX-ARGOFFSET(%rsp)
13927 /*
13928 @@ -503,6 +790,8 @@ sysret_check:
13929 andl %edi,%edx
13930 jnz sysret_careful
13931 CFI_REMEMBER_STATE
13932 + pax_exit_kernel_user
13933 + pax_erase_kstack
13934 /*
13935 * sysretq will re-enable interrupts:
13936 */
13937 @@ -554,14 +843,18 @@ badsys:
13938 * jump back to the normal fast path.
13939 */
13940 auditsys:
13941 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
13942 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
13943 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
13944 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
13945 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
13946 movq %rax,%rsi /* 2nd arg: syscall number */
13947 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
13948 call audit_syscall_entry
13949 +
13950 + pax_erase_kstack
13951 +
13952 LOAD_ARGS 0 /* reload call-clobbered registers */
13953 + pax_set_fptr_mask
13954 jmp system_call_fastpath
13955
13956 /*
13957 @@ -591,16 +884,20 @@ tracesys:
13958 FIXUP_TOP_OF_STACK %rdi
13959 movq %rsp,%rdi
13960 call syscall_trace_enter
13961 +
13962 + pax_erase_kstack
13963 +
13964 /*
13965 * Reload arg registers from stack in case ptrace changed them.
13966 * We don't reload %rax because syscall_trace_enter() returned
13967 * the value it wants us to use in the table lookup.
13968 */
13969 LOAD_ARGS ARGOFFSET, 1
13970 + pax_set_fptr_mask
13971 RESTORE_REST
13972 cmpq $__NR_syscall_max,%rax
13973 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
13974 - movq %r10,%rcx /* fixup for C */
13975 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
13976 call *sys_call_table(,%rax,8)
13977 movq %rax,RAX-ARGOFFSET(%rsp)
13978 /* Use IRET because user could have changed frame */
13979 @@ -612,7 +909,7 @@ tracesys:
13980 GLOBAL(int_ret_from_sys_call)
13981 DISABLE_INTERRUPTS(CLBR_NONE)
13982 TRACE_IRQS_OFF
13983 - testl $3,CS-ARGOFFSET(%rsp)
13984 + testb $3,CS-ARGOFFSET(%rsp)
13985 je retint_restore_args
13986 movl $_TIF_ALLWORK_MASK,%edi
13987 /* edi: mask to check */
13988 @@ -669,7 +966,7 @@ int_restore_rest:
13989 TRACE_IRQS_OFF
13990 jmp int_with_check
13991 CFI_ENDPROC
13992 -END(system_call)
13993 +ENDPROC(system_call)
13994
13995 /*
13996 * Certain special system calls that need to save a complete full stack frame.
13997 @@ -685,7 +982,7 @@ ENTRY(\label)
13998 call \func
13999 jmp ptregscall_common
14000 CFI_ENDPROC
14001 -END(\label)
14002 +ENDPROC(\label)
14003 .endm
14004
14005 PTREGSCALL stub_clone, sys_clone, %r8
14006 @@ -703,9 +1000,10 @@ ENTRY(ptregscall_common)
14007 movq_cfi_restore R12+8, r12
14008 movq_cfi_restore RBP+8, rbp
14009 movq_cfi_restore RBX+8, rbx
14010 + pax_force_retaddr
14011 ret $REST_SKIP /* pop extended registers */
14012 CFI_ENDPROC
14013 -END(ptregscall_common)
14014 +ENDPROC(ptregscall_common)
14015
14016 ENTRY(stub_execve)
14017 CFI_STARTPROC
14018 @@ -720,7 +1018,7 @@ ENTRY(stub_execve)
14019 RESTORE_REST
14020 jmp int_ret_from_sys_call
14021 CFI_ENDPROC
14022 -END(stub_execve)
14023 +ENDPROC(stub_execve)
14024
14025 /*
14026 * sigreturn is special because it needs to restore all registers on return.
14027 @@ -738,7 +1036,7 @@ ENTRY(stub_rt_sigreturn)
14028 RESTORE_REST
14029 jmp int_ret_from_sys_call
14030 CFI_ENDPROC
14031 -END(stub_rt_sigreturn)
14032 +ENDPROC(stub_rt_sigreturn)
14033
14034 /*
14035 * Build the entry stubs and pointer table with some assembler magic.
14036 @@ -773,7 +1071,7 @@ vector=vector+1
14037 2: jmp common_interrupt
14038 .endr
14039 CFI_ENDPROC
14040 -END(irq_entries_start)
14041 +ENDPROC(irq_entries_start)
14042
14043 .previous
14044 END(interrupt)
14045 @@ -793,6 +1091,16 @@ END(interrupt)
14046 subq $ORIG_RAX-RBP, %rsp
14047 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
14048 SAVE_ARGS_IRQ
14049 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14050 + testb $3, CS(%rdi)
14051 + jnz 1f
14052 + pax_enter_kernel
14053 + jmp 2f
14054 +1: pax_enter_kernel_user
14055 +2:
14056 +#else
14057 + pax_enter_kernel
14058 +#endif
14059 call \func
14060 .endm
14061
14062 @@ -824,7 +1132,7 @@ ret_from_intr:
14063
14064 exit_intr:
14065 GET_THREAD_INFO(%rcx)
14066 - testl $3,CS-ARGOFFSET(%rsp)
14067 + testb $3,CS-ARGOFFSET(%rsp)
14068 je retint_kernel
14069
14070 /* Interrupt came from user space */
14071 @@ -846,12 +1154,16 @@ retint_swapgs: /* return to user-space */
14072 * The iretq could re-enable interrupts:
14073 */
14074 DISABLE_INTERRUPTS(CLBR_ANY)
14075 + pax_exit_kernel_user
14076 + pax_erase_kstack
14077 TRACE_IRQS_IRETQ
14078 SWAPGS
14079 jmp restore_args
14080
14081 retint_restore_args: /* return to kernel space */
14082 DISABLE_INTERRUPTS(CLBR_ANY)
14083 + pax_exit_kernel
14084 + pax_force_retaddr RIP-ARGOFFSET
14085 /*
14086 * The iretq could re-enable interrupts:
14087 */
14088 @@ -940,7 +1252,7 @@ ENTRY(retint_kernel)
14089 #endif
14090
14091 CFI_ENDPROC
14092 -END(common_interrupt)
14093 +ENDPROC(common_interrupt)
14094 /*
14095 * End of kprobes section
14096 */
14097 @@ -956,7 +1268,7 @@ ENTRY(\sym)
14098 interrupt \do_sym
14099 jmp ret_from_intr
14100 CFI_ENDPROC
14101 -END(\sym)
14102 +ENDPROC(\sym)
14103 .endm
14104
14105 #ifdef CONFIG_SMP
14106 @@ -1021,12 +1333,22 @@ ENTRY(\sym)
14107 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14108 call error_entry
14109 DEFAULT_FRAME 0
14110 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14111 + testb $3, CS(%rsp)
14112 + jnz 1f
14113 + pax_enter_kernel
14114 + jmp 2f
14115 +1: pax_enter_kernel_user
14116 +2:
14117 +#else
14118 + pax_enter_kernel
14119 +#endif
14120 movq %rsp,%rdi /* pt_regs pointer */
14121 xorl %esi,%esi /* no error code */
14122 call \do_sym
14123 jmp error_exit /* %ebx: no swapgs flag */
14124 CFI_ENDPROC
14125 -END(\sym)
14126 +ENDPROC(\sym)
14127 .endm
14128
14129 .macro paranoidzeroentry sym do_sym
14130 @@ -1038,15 +1360,25 @@ ENTRY(\sym)
14131 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14132 call save_paranoid
14133 TRACE_IRQS_OFF
14134 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14135 + testb $3, CS(%rsp)
14136 + jnz 1f
14137 + pax_enter_kernel
14138 + jmp 2f
14139 +1: pax_enter_kernel_user
14140 +2:
14141 +#else
14142 + pax_enter_kernel
14143 +#endif
14144 movq %rsp,%rdi /* pt_regs pointer */
14145 xorl %esi,%esi /* no error code */
14146 call \do_sym
14147 jmp paranoid_exit /* %ebx: no swapgs flag */
14148 CFI_ENDPROC
14149 -END(\sym)
14150 +ENDPROC(\sym)
14151 .endm
14152
14153 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
14154 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
14155 .macro paranoidzeroentry_ist sym do_sym ist
14156 ENTRY(\sym)
14157 INTR_FRAME
14158 @@ -1056,14 +1388,30 @@ ENTRY(\sym)
14159 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14160 call save_paranoid
14161 TRACE_IRQS_OFF
14162 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14163 + testb $3, CS(%rsp)
14164 + jnz 1f
14165 + pax_enter_kernel
14166 + jmp 2f
14167 +1: pax_enter_kernel_user
14168 +2:
14169 +#else
14170 + pax_enter_kernel
14171 +#endif
14172 movq %rsp,%rdi /* pt_regs pointer */
14173 xorl %esi,%esi /* no error code */
14174 +#ifdef CONFIG_SMP
14175 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
14176 + lea init_tss(%r12), %r12
14177 +#else
14178 + lea init_tss(%rip), %r12
14179 +#endif
14180 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14181 call \do_sym
14182 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14183 jmp paranoid_exit /* %ebx: no swapgs flag */
14184 CFI_ENDPROC
14185 -END(\sym)
14186 +ENDPROC(\sym)
14187 .endm
14188
14189 .macro errorentry sym do_sym
14190 @@ -1074,13 +1422,23 @@ ENTRY(\sym)
14191 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14192 call error_entry
14193 DEFAULT_FRAME 0
14194 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14195 + testb $3, CS(%rsp)
14196 + jnz 1f
14197 + pax_enter_kernel
14198 + jmp 2f
14199 +1: pax_enter_kernel_user
14200 +2:
14201 +#else
14202 + pax_enter_kernel
14203 +#endif
14204 movq %rsp,%rdi /* pt_regs pointer */
14205 movq ORIG_RAX(%rsp),%rsi /* get error code */
14206 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14207 call \do_sym
14208 jmp error_exit /* %ebx: no swapgs flag */
14209 CFI_ENDPROC
14210 -END(\sym)
14211 +ENDPROC(\sym)
14212 .endm
14213
14214 /* error code is on the stack already */
14215 @@ -1093,13 +1451,23 @@ ENTRY(\sym)
14216 call save_paranoid
14217 DEFAULT_FRAME 0
14218 TRACE_IRQS_OFF
14219 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14220 + testb $3, CS(%rsp)
14221 + jnz 1f
14222 + pax_enter_kernel
14223 + jmp 2f
14224 +1: pax_enter_kernel_user
14225 +2:
14226 +#else
14227 + pax_enter_kernel
14228 +#endif
14229 movq %rsp,%rdi /* pt_regs pointer */
14230 movq ORIG_RAX(%rsp),%rsi /* get error code */
14231 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14232 call \do_sym
14233 jmp paranoid_exit /* %ebx: no swapgs flag */
14234 CFI_ENDPROC
14235 -END(\sym)
14236 +ENDPROC(\sym)
14237 .endm
14238
14239 zeroentry divide_error do_divide_error
14240 @@ -1129,9 +1497,10 @@ gs_change:
14241 2: mfence /* workaround */
14242 SWAPGS
14243 popfq_cfi
14244 + pax_force_retaddr
14245 ret
14246 CFI_ENDPROC
14247 -END(native_load_gs_index)
14248 +ENDPROC(native_load_gs_index)
14249
14250 .section __ex_table,"a"
14251 .align 8
14252 @@ -1153,13 +1522,14 @@ ENTRY(kernel_thread_helper)
14253 * Here we are in the child and the registers are set as they were
14254 * at kernel_thread() invocation in the parent.
14255 */
14256 + pax_force_fptr %rsi
14257 call *%rsi
14258 # exit
14259 mov %eax, %edi
14260 call do_exit
14261 ud2 # padding for call trace
14262 CFI_ENDPROC
14263 -END(kernel_thread_helper)
14264 +ENDPROC(kernel_thread_helper)
14265
14266 /*
14267 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
14268 @@ -1186,11 +1556,11 @@ ENTRY(kernel_execve)
14269 RESTORE_REST
14270 testq %rax,%rax
14271 je int_ret_from_sys_call
14272 - RESTORE_ARGS
14273 UNFAKE_STACK_FRAME
14274 + pax_force_retaddr
14275 ret
14276 CFI_ENDPROC
14277 -END(kernel_execve)
14278 +ENDPROC(kernel_execve)
14279
14280 /* Call softirq on interrupt stack. Interrupts are off. */
14281 ENTRY(call_softirq)
14282 @@ -1208,9 +1578,10 @@ ENTRY(call_softirq)
14283 CFI_DEF_CFA_REGISTER rsp
14284 CFI_ADJUST_CFA_OFFSET -8
14285 decl PER_CPU_VAR(irq_count)
14286 + pax_force_retaddr
14287 ret
14288 CFI_ENDPROC
14289 -END(call_softirq)
14290 +ENDPROC(call_softirq)
14291
14292 #ifdef CONFIG_XEN
14293 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
14294 @@ -1248,7 +1619,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
14295 decl PER_CPU_VAR(irq_count)
14296 jmp error_exit
14297 CFI_ENDPROC
14298 -END(xen_do_hypervisor_callback)
14299 +ENDPROC(xen_do_hypervisor_callback)
14300
14301 /*
14302 * Hypervisor uses this for application faults while it executes.
14303 @@ -1307,7 +1678,7 @@ ENTRY(xen_failsafe_callback)
14304 SAVE_ALL
14305 jmp error_exit
14306 CFI_ENDPROC
14307 -END(xen_failsafe_callback)
14308 +ENDPROC(xen_failsafe_callback)
14309
14310 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
14311 xen_hvm_callback_vector xen_evtchn_do_upcall
14312 @@ -1356,16 +1727,31 @@ ENTRY(paranoid_exit)
14313 TRACE_IRQS_OFF
14314 testl %ebx,%ebx /* swapgs needed? */
14315 jnz paranoid_restore
14316 - testl $3,CS(%rsp)
14317 + testb $3,CS(%rsp)
14318 jnz paranoid_userspace
14319 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14320 + pax_exit_kernel
14321 + TRACE_IRQS_IRETQ 0
14322 + SWAPGS_UNSAFE_STACK
14323 + RESTORE_ALL 8
14324 + pax_force_retaddr_bts
14325 + jmp irq_return
14326 +#endif
14327 paranoid_swapgs:
14328 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14329 + pax_exit_kernel_user
14330 +#else
14331 + pax_exit_kernel
14332 +#endif
14333 TRACE_IRQS_IRETQ 0
14334 SWAPGS_UNSAFE_STACK
14335 RESTORE_ALL 8
14336 jmp irq_return
14337 paranoid_restore:
14338 + pax_exit_kernel
14339 TRACE_IRQS_IRETQ 0
14340 RESTORE_ALL 8
14341 + pax_force_retaddr_bts
14342 jmp irq_return
14343 paranoid_userspace:
14344 GET_THREAD_INFO(%rcx)
14345 @@ -1394,7 +1780,7 @@ paranoid_schedule:
14346 TRACE_IRQS_OFF
14347 jmp paranoid_userspace
14348 CFI_ENDPROC
14349 -END(paranoid_exit)
14350 +ENDPROC(paranoid_exit)
14351
14352 /*
14353 * Exception entry point. This expects an error code/orig_rax on the stack.
14354 @@ -1421,12 +1807,13 @@ ENTRY(error_entry)
14355 movq_cfi r14, R14+8
14356 movq_cfi r15, R15+8
14357 xorl %ebx,%ebx
14358 - testl $3,CS+8(%rsp)
14359 + testb $3,CS+8(%rsp)
14360 je error_kernelspace
14361 error_swapgs:
14362 SWAPGS
14363 error_sti:
14364 TRACE_IRQS_OFF
14365 + pax_force_retaddr_bts
14366 ret
14367
14368 /*
14369 @@ -1453,7 +1840,7 @@ bstep_iret:
14370 movq %rcx,RIP+8(%rsp)
14371 jmp error_swapgs
14372 CFI_ENDPROC
14373 -END(error_entry)
14374 +ENDPROC(error_entry)
14375
14376
14377 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
14378 @@ -1473,7 +1860,7 @@ ENTRY(error_exit)
14379 jnz retint_careful
14380 jmp retint_swapgs
14381 CFI_ENDPROC
14382 -END(error_exit)
14383 +ENDPROC(error_exit)
14384
14385
14386 /* runs on exception stack */
14387 @@ -1485,6 +1872,16 @@ ENTRY(nmi)
14388 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14389 call save_paranoid
14390 DEFAULT_FRAME 0
14391 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14392 + testb $3, CS(%rsp)
14393 + jnz 1f
14394 + pax_enter_kernel
14395 + jmp 2f
14396 +1: pax_enter_kernel_user
14397 +2:
14398 +#else
14399 + pax_enter_kernel
14400 +#endif
14401 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14402 movq %rsp,%rdi
14403 movq $-1,%rsi
14404 @@ -1495,12 +1892,28 @@ ENTRY(nmi)
14405 DISABLE_INTERRUPTS(CLBR_NONE)
14406 testl %ebx,%ebx /* swapgs needed? */
14407 jnz nmi_restore
14408 - testl $3,CS(%rsp)
14409 + testb $3,CS(%rsp)
14410 jnz nmi_userspace
14411 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14412 + pax_exit_kernel
14413 + SWAPGS_UNSAFE_STACK
14414 + RESTORE_ALL 8
14415 + pax_force_retaddr_bts
14416 + jmp irq_return
14417 +#endif
14418 nmi_swapgs:
14419 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14420 + pax_exit_kernel_user
14421 +#else
14422 + pax_exit_kernel
14423 +#endif
14424 SWAPGS_UNSAFE_STACK
14425 + RESTORE_ALL 8
14426 + jmp irq_return
14427 nmi_restore:
14428 + pax_exit_kernel
14429 RESTORE_ALL 8
14430 + pax_force_retaddr_bts
14431 jmp irq_return
14432 nmi_userspace:
14433 GET_THREAD_INFO(%rcx)
14434 @@ -1529,14 +1942,14 @@ nmi_schedule:
14435 jmp paranoid_exit
14436 CFI_ENDPROC
14437 #endif
14438 -END(nmi)
14439 +ENDPROC(nmi)
14440
14441 ENTRY(ignore_sysret)
14442 CFI_STARTPROC
14443 mov $-ENOSYS,%eax
14444 sysret
14445 CFI_ENDPROC
14446 -END(ignore_sysret)
14447 +ENDPROC(ignore_sysret)
14448
14449 /*
14450 * End of kprobes section
14451 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
14452 index c9a281f..ce2f317 100644
14453 --- a/arch/x86/kernel/ftrace.c
14454 +++ b/arch/x86/kernel/ftrace.c
14455 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
14456 static const void *mod_code_newcode; /* holds the text to write to the IP */
14457
14458 static unsigned nmi_wait_count;
14459 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
14460 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14461
14462 int ftrace_arch_read_dyn_info(char *buf, int size)
14463 {
14464 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
14465
14466 r = snprintf(buf, size, "%u %u",
14467 nmi_wait_count,
14468 - atomic_read(&nmi_update_count));
14469 + atomic_read_unchecked(&nmi_update_count));
14470 return r;
14471 }
14472
14473 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
14474
14475 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14476 smp_rmb();
14477 + pax_open_kernel();
14478 ftrace_mod_code();
14479 - atomic_inc(&nmi_update_count);
14480 + pax_close_kernel();
14481 + atomic_inc_unchecked(&nmi_update_count);
14482 }
14483 /* Must have previous changes seen before executions */
14484 smp_mb();
14485 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
14486 {
14487 unsigned char replaced[MCOUNT_INSN_SIZE];
14488
14489 + ip = ktla_ktva(ip);
14490 +
14491 /*
14492 * Note: Due to modules and __init, code can
14493 * disappear and change, we need to protect against faulting
14494 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
14495 unsigned char old[MCOUNT_INSN_SIZE], *new;
14496 int ret;
14497
14498 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14499 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14500 new = ftrace_call_replace(ip, (unsigned long)func);
14501 ret = ftrace_modify_code(ip, old, new);
14502
14503 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
14504 {
14505 unsigned char code[MCOUNT_INSN_SIZE];
14506
14507 + ip = ktla_ktva(ip);
14508 +
14509 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14510 return -EFAULT;
14511
14512 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
14513 index 3bb0850..55a56f4 100644
14514 --- a/arch/x86/kernel/head32.c
14515 +++ b/arch/x86/kernel/head32.c
14516 @@ -19,6 +19,7 @@
14517 #include <asm/io_apic.h>
14518 #include <asm/bios_ebda.h>
14519 #include <asm/tlbflush.h>
14520 +#include <asm/boot.h>
14521
14522 static void __init i386_default_early_setup(void)
14523 {
14524 @@ -33,7 +34,7 @@ void __init i386_start_kernel(void)
14525 {
14526 memblock_init();
14527
14528 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14529 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14530
14531 #ifdef CONFIG_BLK_DEV_INITRD
14532 /* Reserve INITRD */
14533 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
14534 index ce0be7c..c41476e 100644
14535 --- a/arch/x86/kernel/head_32.S
14536 +++ b/arch/x86/kernel/head_32.S
14537 @@ -25,6 +25,12 @@
14538 /* Physical address */
14539 #define pa(X) ((X) - __PAGE_OFFSET)
14540
14541 +#ifdef CONFIG_PAX_KERNEXEC
14542 +#define ta(X) (X)
14543 +#else
14544 +#define ta(X) ((X) - __PAGE_OFFSET)
14545 +#endif
14546 +
14547 /*
14548 * References to members of the new_cpu_data structure.
14549 */
14550 @@ -54,11 +60,7 @@
14551 * and small than max_low_pfn, otherwise will waste some page table entries
14552 */
14553
14554 -#if PTRS_PER_PMD > 1
14555 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14556 -#else
14557 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14558 -#endif
14559 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14560
14561 /* Number of possible pages in the lowmem region */
14562 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
14563 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
14564 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14565
14566 /*
14567 + * Real beginning of normal "text" segment
14568 + */
14569 +ENTRY(stext)
14570 +ENTRY(_stext)
14571 +
14572 +/*
14573 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14574 * %esi points to the real-mode code as a 32-bit pointer.
14575 * CS and DS must be 4 GB flat segments, but we don't depend on
14576 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14577 * can.
14578 */
14579 __HEAD
14580 +
14581 +#ifdef CONFIG_PAX_KERNEXEC
14582 + jmp startup_32
14583 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14584 +.fill PAGE_SIZE-5,1,0xcc
14585 +#endif
14586 +
14587 ENTRY(startup_32)
14588 movl pa(stack_start),%ecx
14589
14590 @@ -105,6 +120,57 @@ ENTRY(startup_32)
14591 2:
14592 leal -__PAGE_OFFSET(%ecx),%esp
14593
14594 +#ifdef CONFIG_SMP
14595 + movl $pa(cpu_gdt_table),%edi
14596 + movl $__per_cpu_load,%eax
14597 + movw %ax,__KERNEL_PERCPU + 2(%edi)
14598 + rorl $16,%eax
14599 + movb %al,__KERNEL_PERCPU + 4(%edi)
14600 + movb %ah,__KERNEL_PERCPU + 7(%edi)
14601 + movl $__per_cpu_end - 1,%eax
14602 + subl $__per_cpu_start,%eax
14603 + movw %ax,__KERNEL_PERCPU + 0(%edi)
14604 +#endif
14605 +
14606 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14607 + movl $NR_CPUS,%ecx
14608 + movl $pa(cpu_gdt_table),%edi
14609 +1:
14610 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14611 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14612 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14613 + addl $PAGE_SIZE_asm,%edi
14614 + loop 1b
14615 +#endif
14616 +
14617 +#ifdef CONFIG_PAX_KERNEXEC
14618 + movl $pa(boot_gdt),%edi
14619 + movl $__LOAD_PHYSICAL_ADDR,%eax
14620 + movw %ax,__BOOT_CS + 2(%edi)
14621 + rorl $16,%eax
14622 + movb %al,__BOOT_CS + 4(%edi)
14623 + movb %ah,__BOOT_CS + 7(%edi)
14624 + rorl $16,%eax
14625 +
14626 + ljmp $(__BOOT_CS),$1f
14627 +1:
14628 +
14629 + movl $NR_CPUS,%ecx
14630 + movl $pa(cpu_gdt_table),%edi
14631 + addl $__PAGE_OFFSET,%eax
14632 +1:
14633 + movw %ax,__KERNEL_CS + 2(%edi)
14634 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14635 + rorl $16,%eax
14636 + movb %al,__KERNEL_CS + 4(%edi)
14637 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14638 + movb %ah,__KERNEL_CS + 7(%edi)
14639 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14640 + rorl $16,%eax
14641 + addl $PAGE_SIZE_asm,%edi
14642 + loop 1b
14643 +#endif
14644 +
14645 /*
14646 * Clear BSS first so that there are no surprises...
14647 */
14648 @@ -195,8 +261,11 @@ ENTRY(startup_32)
14649 movl %eax, pa(max_pfn_mapped)
14650
14651 /* Do early initialization of the fixmap area */
14652 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14653 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
14654 +#ifdef CONFIG_COMPAT_VDSO
14655 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
14656 +#else
14657 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
14658 +#endif
14659 #else /* Not PAE */
14660
14661 page_pde_offset = (__PAGE_OFFSET >> 20);
14662 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14663 movl %eax, pa(max_pfn_mapped)
14664
14665 /* Do early initialization of the fixmap area */
14666 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14667 - movl %eax,pa(initial_page_table+0xffc)
14668 +#ifdef CONFIG_COMPAT_VDSO
14669 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
14670 +#else
14671 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
14672 +#endif
14673 #endif
14674
14675 #ifdef CONFIG_PARAVIRT
14676 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14677 cmpl $num_subarch_entries, %eax
14678 jae bad_subarch
14679
14680 - movl pa(subarch_entries)(,%eax,4), %eax
14681 - subl $__PAGE_OFFSET, %eax
14682 - jmp *%eax
14683 + jmp *pa(subarch_entries)(,%eax,4)
14684
14685 bad_subarch:
14686 WEAK(lguest_entry)
14687 @@ -255,10 +325,10 @@ WEAK(xen_entry)
14688 __INITDATA
14689
14690 subarch_entries:
14691 - .long default_entry /* normal x86/PC */
14692 - .long lguest_entry /* lguest hypervisor */
14693 - .long xen_entry /* Xen hypervisor */
14694 - .long default_entry /* Moorestown MID */
14695 + .long ta(default_entry) /* normal x86/PC */
14696 + .long ta(lguest_entry) /* lguest hypervisor */
14697 + .long ta(xen_entry) /* Xen hypervisor */
14698 + .long ta(default_entry) /* Moorestown MID */
14699 num_subarch_entries = (. - subarch_entries) / 4
14700 .previous
14701 #else
14702 @@ -312,6 +382,7 @@ default_entry:
14703 orl %edx,%eax
14704 movl %eax,%cr4
14705
14706 +#ifdef CONFIG_X86_PAE
14707 testb $X86_CR4_PAE, %al # check if PAE is enabled
14708 jz 6f
14709
14710 @@ -340,6 +411,9 @@ default_entry:
14711 /* Make changes effective */
14712 wrmsr
14713
14714 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
14715 +#endif
14716 +
14717 6:
14718
14719 /*
14720 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
14721 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
14722 movl %eax,%ss # after changing gdt.
14723
14724 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
14725 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
14726 movl %eax,%ds
14727 movl %eax,%es
14728
14729 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
14730 */
14731 cmpb $0,ready
14732 jne 1f
14733 - movl $gdt_page,%eax
14734 + movl $cpu_gdt_table,%eax
14735 movl $stack_canary,%ecx
14736 +#ifdef CONFIG_SMP
14737 + addl $__per_cpu_load,%ecx
14738 +#endif
14739 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
14740 shrl $16, %ecx
14741 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
14742 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
14743 1:
14744 -#endif
14745 movl $(__KERNEL_STACK_CANARY),%eax
14746 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14747 + movl $(__USER_DS),%eax
14748 +#else
14749 + xorl %eax,%eax
14750 +#endif
14751 movl %eax,%gs
14752
14753 xorl %eax,%eax # Clear LDT
14754 @@ -558,22 +639,22 @@ early_page_fault:
14755 jmp early_fault
14756
14757 early_fault:
14758 - cld
14759 #ifdef CONFIG_PRINTK
14760 + cmpl $1,%ss:early_recursion_flag
14761 + je hlt_loop
14762 + incl %ss:early_recursion_flag
14763 + cld
14764 pusha
14765 movl $(__KERNEL_DS),%eax
14766 movl %eax,%ds
14767 movl %eax,%es
14768 - cmpl $2,early_recursion_flag
14769 - je hlt_loop
14770 - incl early_recursion_flag
14771 movl %cr2,%eax
14772 pushl %eax
14773 pushl %edx /* trapno */
14774 pushl $fault_msg
14775 call printk
14776 +; call dump_stack
14777 #endif
14778 - call dump_stack
14779 hlt_loop:
14780 hlt
14781 jmp hlt_loop
14782 @@ -581,8 +662,11 @@ hlt_loop:
14783 /* This is the default interrupt "handler" :-) */
14784 ALIGN
14785 ignore_int:
14786 - cld
14787 #ifdef CONFIG_PRINTK
14788 + cmpl $2,%ss:early_recursion_flag
14789 + je hlt_loop
14790 + incl %ss:early_recursion_flag
14791 + cld
14792 pushl %eax
14793 pushl %ecx
14794 pushl %edx
14795 @@ -591,9 +675,6 @@ ignore_int:
14796 movl $(__KERNEL_DS),%eax
14797 movl %eax,%ds
14798 movl %eax,%es
14799 - cmpl $2,early_recursion_flag
14800 - je hlt_loop
14801 - incl early_recursion_flag
14802 pushl 16(%esp)
14803 pushl 24(%esp)
14804 pushl 32(%esp)
14805 @@ -622,29 +703,43 @@ ENTRY(initial_code)
14806 /*
14807 * BSS section
14808 */
14809 -__PAGE_ALIGNED_BSS
14810 - .align PAGE_SIZE
14811 #ifdef CONFIG_X86_PAE
14812 +.section .initial_pg_pmd,"a",@progbits
14813 initial_pg_pmd:
14814 .fill 1024*KPMDS,4,0
14815 #else
14816 +.section .initial_page_table,"a",@progbits
14817 ENTRY(initial_page_table)
14818 .fill 1024,4,0
14819 #endif
14820 +.section .initial_pg_fixmap,"a",@progbits
14821 initial_pg_fixmap:
14822 .fill 1024,4,0
14823 +.section .empty_zero_page,"a",@progbits
14824 ENTRY(empty_zero_page)
14825 .fill 4096,1,0
14826 +.section .swapper_pg_dir,"a",@progbits
14827 ENTRY(swapper_pg_dir)
14828 +#ifdef CONFIG_X86_PAE
14829 + .fill 4,8,0
14830 +#else
14831 .fill 1024,4,0
14832 +#endif
14833 +
14834 +/*
14835 + * The IDT has to be page-aligned to simplify the Pentium
14836 + * F0 0F bug workaround.. We have a special link segment
14837 + * for this.
14838 + */
14839 +.section .idt,"a",@progbits
14840 +ENTRY(idt_table)
14841 + .fill 256,8,0
14842
14843 /*
14844 * This starts the data section.
14845 */
14846 #ifdef CONFIG_X86_PAE
14847 -__PAGE_ALIGNED_DATA
14848 - /* Page-aligned for the benefit of paravirt? */
14849 - .align PAGE_SIZE
14850 +.section .initial_page_table,"a",@progbits
14851 ENTRY(initial_page_table)
14852 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
14853 # if KPMDS == 3
14854 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
14855 # error "Kernel PMDs should be 1, 2 or 3"
14856 # endif
14857 .align PAGE_SIZE /* needs to be page-sized too */
14858 +
14859 +#ifdef CONFIG_PAX_PER_CPU_PGD
14860 +ENTRY(cpu_pgd)
14861 + .rept NR_CPUS
14862 + .fill 4,8,0
14863 + .endr
14864 +#endif
14865 +
14866 #endif
14867
14868 .data
14869 .balign 4
14870 ENTRY(stack_start)
14871 - .long init_thread_union+THREAD_SIZE
14872 + .long init_thread_union+THREAD_SIZE-8
14873
14874 +ready: .byte 0
14875 +
14876 +.section .rodata,"a",@progbits
14877 early_recursion_flag:
14878 .long 0
14879
14880 -ready: .byte 0
14881 -
14882 int_msg:
14883 .asciz "Unknown interrupt or fault at: %p %p %p\n"
14884
14885 @@ -707,7 +811,7 @@ fault_msg:
14886 .word 0 # 32 bit align gdt_desc.address
14887 boot_gdt_descr:
14888 .word __BOOT_DS+7
14889 - .long boot_gdt - __PAGE_OFFSET
14890 + .long pa(boot_gdt)
14891
14892 .word 0 # 32-bit align idt_desc.address
14893 idt_descr:
14894 @@ -718,7 +822,7 @@ idt_descr:
14895 .word 0 # 32 bit align gdt_desc.address
14896 ENTRY(early_gdt_descr)
14897 .word GDT_ENTRIES*8-1
14898 - .long gdt_page /* Overwritten for secondary CPUs */
14899 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
14900
14901 /*
14902 * The boot_gdt must mirror the equivalent in setup.S and is
14903 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
14904 .align L1_CACHE_BYTES
14905 ENTRY(boot_gdt)
14906 .fill GDT_ENTRY_BOOT_CS,8,0
14907 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
14908 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
14909 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
14910 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
14911 +
14912 + .align PAGE_SIZE_asm
14913 +ENTRY(cpu_gdt_table)
14914 + .rept NR_CPUS
14915 + .quad 0x0000000000000000 /* NULL descriptor */
14916 + .quad 0x0000000000000000 /* 0x0b reserved */
14917 + .quad 0x0000000000000000 /* 0x13 reserved */
14918 + .quad 0x0000000000000000 /* 0x1b reserved */
14919 +
14920 +#ifdef CONFIG_PAX_KERNEXEC
14921 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
14922 +#else
14923 + .quad 0x0000000000000000 /* 0x20 unused */
14924 +#endif
14925 +
14926 + .quad 0x0000000000000000 /* 0x28 unused */
14927 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
14928 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
14929 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
14930 + .quad 0x0000000000000000 /* 0x4b reserved */
14931 + .quad 0x0000000000000000 /* 0x53 reserved */
14932 + .quad 0x0000000000000000 /* 0x5b reserved */
14933 +
14934 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
14935 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
14936 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
14937 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
14938 +
14939 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
14940 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
14941 +
14942 + /*
14943 + * Segments used for calling PnP BIOS have byte granularity.
14944 + * The code segments and data segments have fixed 64k limits,
14945 + * the transfer segment sizes are set at run time.
14946 + */
14947 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
14948 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
14949 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
14950 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
14951 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
14952 +
14953 + /*
14954 + * The APM segments have byte granularity and their bases
14955 + * are set at run time. All have 64k limits.
14956 + */
14957 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
14958 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
14959 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
14960 +
14961 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
14962 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
14963 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
14964 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
14965 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
14966 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
14967 +
14968 + /* Be sure this is zeroed to avoid false validations in Xen */
14969 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
14970 + .endr
14971 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
14972 index e11e394..9aebc5d 100644
14973 --- a/arch/x86/kernel/head_64.S
14974 +++ b/arch/x86/kernel/head_64.S
14975 @@ -19,6 +19,8 @@
14976 #include <asm/cache.h>
14977 #include <asm/processor-flags.h>
14978 #include <asm/percpu.h>
14979 +#include <asm/cpufeature.h>
14980 +#include <asm/alternative-asm.h>
14981
14982 #ifdef CONFIG_PARAVIRT
14983 #include <asm/asm-offsets.h>
14984 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
14985 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
14986 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
14987 L3_START_KERNEL = pud_index(__START_KERNEL_map)
14988 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
14989 +L3_VMALLOC_START = pud_index(VMALLOC_START)
14990 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
14991 +L3_VMALLOC_END = pud_index(VMALLOC_END)
14992 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
14993 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
14994
14995 .text
14996 __HEAD
14997 @@ -85,35 +93,23 @@ startup_64:
14998 */
14999 addq %rbp, init_level4_pgt + 0(%rip)
15000 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
15001 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
15002 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
15003 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
15004 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
15005
15006 addq %rbp, level3_ident_pgt + 0(%rip)
15007 +#ifndef CONFIG_XEN
15008 + addq %rbp, level3_ident_pgt + 8(%rip)
15009 +#endif
15010
15011 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
15012 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
15013 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
15014 +
15015 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
15016 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
15017
15018 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15019 -
15020 - /* Add an Identity mapping if I am above 1G */
15021 - leaq _text(%rip), %rdi
15022 - andq $PMD_PAGE_MASK, %rdi
15023 -
15024 - movq %rdi, %rax
15025 - shrq $PUD_SHIFT, %rax
15026 - andq $(PTRS_PER_PUD - 1), %rax
15027 - jz ident_complete
15028 -
15029 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
15030 - leaq level3_ident_pgt(%rip), %rbx
15031 - movq %rdx, 0(%rbx, %rax, 8)
15032 -
15033 - movq %rdi, %rax
15034 - shrq $PMD_SHIFT, %rax
15035 - andq $(PTRS_PER_PMD - 1), %rax
15036 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15037 - leaq level2_spare_pgt(%rip), %rbx
15038 - movq %rdx, 0(%rbx, %rax, 8)
15039 -ident_complete:
15040 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15041
15042 /*
15043 * Fixup the kernel text+data virtual addresses. Note that
15044 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
15045 * after the boot processor executes this code.
15046 */
15047
15048 - /* Enable PAE mode and PGE */
15049 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15050 + /* Enable PAE mode and PSE/PGE */
15051 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15052 movq %rax, %cr4
15053
15054 /* Setup early boot stage 4 level pagetables. */
15055 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
15056 movl $MSR_EFER, %ecx
15057 rdmsr
15058 btsl $_EFER_SCE, %eax /* Enable System Call */
15059 - btl $20,%edi /* No Execute supported? */
15060 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15061 jnc 1f
15062 btsl $_EFER_NX, %eax
15063 + leaq init_level4_pgt(%rip), %rdi
15064 +#ifndef CONFIG_EFI
15065 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15066 +#endif
15067 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15068 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
15069 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15070 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
15071 1: wrmsr /* Make changes effective */
15072
15073 /* Setup cr0 */
15074 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
15075 * jump. In addition we need to ensure %cs is set so we make this
15076 * a far return.
15077 */
15078 + pax_set_fptr_mask
15079 movq initial_code(%rip),%rax
15080 pushq $0 # fake return address to stop unwinder
15081 pushq $__KERNEL_CS # set correct cs
15082 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
15083 bad_address:
15084 jmp bad_address
15085
15086 - .section ".init.text","ax"
15087 + __INIT
15088 #ifdef CONFIG_EARLY_PRINTK
15089 .globl early_idt_handlers
15090 early_idt_handlers:
15091 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
15092 #endif /* EARLY_PRINTK */
15093 1: hlt
15094 jmp 1b
15095 + .previous
15096
15097 #ifdef CONFIG_EARLY_PRINTK
15098 + __INITDATA
15099 early_recursion_flag:
15100 .long 0
15101 + .previous
15102
15103 + .section .rodata,"a",@progbits
15104 early_idt_msg:
15105 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15106 early_idt_ripmsg:
15107 .asciz "RIP %s\n"
15108 + .previous
15109 #endif /* CONFIG_EARLY_PRINTK */
15110 - .previous
15111
15112 + .section .rodata,"a",@progbits
15113 #define NEXT_PAGE(name) \
15114 .balign PAGE_SIZE; \
15115 ENTRY(name)
15116 @@ -338,7 +348,6 @@ ENTRY(name)
15117 i = i + 1 ; \
15118 .endr
15119
15120 - .data
15121 /*
15122 * This default setting generates an ident mapping at address 0x100000
15123 * and a mapping for the kernel that precisely maps virtual address
15124 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
15125 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15126 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15127 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15128 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
15129 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
15130 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
15131 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
15132 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15133 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15134 .org init_level4_pgt + L4_START_KERNEL*8, 0
15135 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15136 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15137
15138 +#ifdef CONFIG_PAX_PER_CPU_PGD
15139 +NEXT_PAGE(cpu_pgd)
15140 + .rept NR_CPUS
15141 + .fill 512,8,0
15142 + .endr
15143 +#endif
15144 +
15145 NEXT_PAGE(level3_ident_pgt)
15146 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15147 +#ifdef CONFIG_XEN
15148 .fill 511,8,0
15149 +#else
15150 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
15151 + .fill 510,8,0
15152 +#endif
15153 +
15154 +NEXT_PAGE(level3_vmalloc_start_pgt)
15155 + .fill 512,8,0
15156 +
15157 +NEXT_PAGE(level3_vmalloc_end_pgt)
15158 + .fill 512,8,0
15159 +
15160 +NEXT_PAGE(level3_vmemmap_pgt)
15161 + .fill L3_VMEMMAP_START,8,0
15162 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15163
15164 NEXT_PAGE(level3_kernel_pgt)
15165 .fill L3_START_KERNEL,8,0
15166 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
15167 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
15168 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15169
15170 +NEXT_PAGE(level2_vmemmap_pgt)
15171 + .fill 512,8,0
15172 +
15173 NEXT_PAGE(level2_fixmap_pgt)
15174 - .fill 506,8,0
15175 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15176 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
15177 - .fill 5,8,0
15178 + .fill 507,8,0
15179 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
15180 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
15181 + .fill 4,8,0
15182
15183 -NEXT_PAGE(level1_fixmap_pgt)
15184 +NEXT_PAGE(level1_vsyscall_pgt)
15185 .fill 512,8,0
15186
15187 -NEXT_PAGE(level2_ident_pgt)
15188 - /* Since I easily can, map the first 1G.
15189 + /* Since I easily can, map the first 2G.
15190 * Don't set NX because code runs from these pages.
15191 */
15192 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
15193 +NEXT_PAGE(level2_ident_pgt)
15194 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
15195
15196 NEXT_PAGE(level2_kernel_pgt)
15197 /*
15198 @@ -389,33 +429,55 @@ NEXT_PAGE(level2_kernel_pgt)
15199 * If you want to increase this then increase MODULES_VADDR
15200 * too.)
15201 */
15202 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
15203 - KERNEL_IMAGE_SIZE/PMD_SIZE)
15204 -
15205 -NEXT_PAGE(level2_spare_pgt)
15206 - .fill 512, 8, 0
15207 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
15208
15209 #undef PMDS
15210 #undef NEXT_PAGE
15211
15212 - .data
15213 + .align PAGE_SIZE
15214 +ENTRY(cpu_gdt_table)
15215 + .rept NR_CPUS
15216 + .quad 0x0000000000000000 /* NULL descriptor */
15217 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15218 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
15219 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
15220 + .quad 0x00cffb000000ffff /* __USER32_CS */
15221 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15222 + .quad 0x00affb000000ffff /* __USER_CS */
15223 +
15224 +#ifdef CONFIG_PAX_KERNEXEC
15225 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15226 +#else
15227 + .quad 0x0 /* unused */
15228 +#endif
15229 +
15230 + .quad 0,0 /* TSS */
15231 + .quad 0,0 /* LDT */
15232 + .quad 0,0,0 /* three TLS descriptors */
15233 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
15234 + /* asm/segment.h:GDT_ENTRIES must match this */
15235 +
15236 + /* zero the remaining page */
15237 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15238 + .endr
15239 +
15240 .align 16
15241 .globl early_gdt_descr
15242 early_gdt_descr:
15243 .word GDT_ENTRIES*8-1
15244 early_gdt_descr_base:
15245 - .quad INIT_PER_CPU_VAR(gdt_page)
15246 + .quad cpu_gdt_table
15247
15248 ENTRY(phys_base)
15249 /* This must match the first entry in level2_kernel_pgt */
15250 .quad 0x0000000000000000
15251
15252 #include "../../x86/xen/xen-head.S"
15253 -
15254 - .section .bss, "aw", @nobits
15255 +
15256 + .section .rodata,"a",@progbits
15257 .align L1_CACHE_BYTES
15258 ENTRY(idt_table)
15259 - .skip IDT_ENTRIES * 16
15260 + .fill 512,8,0
15261
15262 __PAGE_ALIGNED_BSS
15263 .align PAGE_SIZE
15264 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
15265 index 9c3bd4a..e1d9b35 100644
15266 --- a/arch/x86/kernel/i386_ksyms_32.c
15267 +++ b/arch/x86/kernel/i386_ksyms_32.c
15268 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15269 EXPORT_SYMBOL(cmpxchg8b_emu);
15270 #endif
15271
15272 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
15273 +
15274 /* Networking helper routines. */
15275 EXPORT_SYMBOL(csum_partial_copy_generic);
15276 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15277 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15278
15279 EXPORT_SYMBOL(__get_user_1);
15280 EXPORT_SYMBOL(__get_user_2);
15281 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15282
15283 EXPORT_SYMBOL(csum_partial);
15284 EXPORT_SYMBOL(empty_zero_page);
15285 +
15286 +#ifdef CONFIG_PAX_KERNEXEC
15287 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15288 +#endif
15289 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
15290 index 6104852..6114160 100644
15291 --- a/arch/x86/kernel/i8259.c
15292 +++ b/arch/x86/kernel/i8259.c
15293 @@ -210,7 +210,7 @@ spurious_8259A_irq:
15294 "spurious 8259A interrupt: IRQ%d.\n", irq);
15295 spurious_irq_mask |= irqmask;
15296 }
15297 - atomic_inc(&irq_err_count);
15298 + atomic_inc_unchecked(&irq_err_count);
15299 /*
15300 * Theoretically we do not have to handle this IRQ,
15301 * but in Linux this does not cause problems and is
15302 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
15303 index 43e9ccf..44ccf6f 100644
15304 --- a/arch/x86/kernel/init_task.c
15305 +++ b/arch/x86/kernel/init_task.c
15306 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
15307 * way process stacks are handled. This is done by having a special
15308 * "init_task" linker map entry..
15309 */
15310 -union thread_union init_thread_union __init_task_data =
15311 - { INIT_THREAD_INFO(init_task) };
15312 +union thread_union init_thread_union __init_task_data;
15313
15314 /*
15315 * Initial task structure.
15316 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15317 * section. Since TSS's are completely CPU-local, we want them
15318 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15319 */
15320 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15321 -
15322 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15323 +EXPORT_SYMBOL(init_tss);
15324 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
15325 index 8c96897..be66bfa 100644
15326 --- a/arch/x86/kernel/ioport.c
15327 +++ b/arch/x86/kernel/ioport.c
15328 @@ -6,6 +6,7 @@
15329 #include <linux/sched.h>
15330 #include <linux/kernel.h>
15331 #include <linux/capability.h>
15332 +#include <linux/security.h>
15333 #include <linux/errno.h>
15334 #include <linux/types.h>
15335 #include <linux/ioport.h>
15336 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
15337
15338 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15339 return -EINVAL;
15340 +#ifdef CONFIG_GRKERNSEC_IO
15341 + if (turn_on && grsec_disable_privio) {
15342 + gr_handle_ioperm();
15343 + return -EPERM;
15344 + }
15345 +#endif
15346 if (turn_on && !capable(CAP_SYS_RAWIO))
15347 return -EPERM;
15348
15349 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
15350 * because the ->io_bitmap_max value must match the bitmap
15351 * contents:
15352 */
15353 - tss = &per_cpu(init_tss, get_cpu());
15354 + tss = init_tss + get_cpu();
15355
15356 if (turn_on)
15357 bitmap_clear(t->io_bitmap_ptr, from, num);
15358 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
15359 return -EINVAL;
15360 /* Trying to gain more privileges? */
15361 if (level > old) {
15362 +#ifdef CONFIG_GRKERNSEC_IO
15363 + if (grsec_disable_privio) {
15364 + gr_handle_iopl();
15365 + return -EPERM;
15366 + }
15367 +#endif
15368 if (!capable(CAP_SYS_RAWIO))
15369 return -EPERM;
15370 }
15371 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
15372 index 429e0c9..17b3ece 100644
15373 --- a/arch/x86/kernel/irq.c
15374 +++ b/arch/x86/kernel/irq.c
15375 @@ -18,7 +18,7 @@
15376 #include <asm/mce.h>
15377 #include <asm/hw_irq.h>
15378
15379 -atomic_t irq_err_count;
15380 +atomic_unchecked_t irq_err_count;
15381
15382 /* Function pointer for generic interrupt vector handling */
15383 void (*x86_platform_ipi_callback)(void) = NULL;
15384 @@ -117,9 +117,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
15385 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15386 seq_printf(p, " Machine check polls\n");
15387 #endif
15388 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15389 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15390 #if defined(CONFIG_X86_IO_APIC)
15391 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15392 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15393 #endif
15394 return 0;
15395 }
15396 @@ -159,10 +159,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15397
15398 u64 arch_irq_stat(void)
15399 {
15400 - u64 sum = atomic_read(&irq_err_count);
15401 + u64 sum = atomic_read_unchecked(&irq_err_count);
15402
15403 #ifdef CONFIG_X86_IO_APIC
15404 - sum += atomic_read(&irq_mis_count);
15405 + sum += atomic_read_unchecked(&irq_mis_count);
15406 #endif
15407 return sum;
15408 }
15409 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
15410 index 7209070..cbcd71a 100644
15411 --- a/arch/x86/kernel/irq_32.c
15412 +++ b/arch/x86/kernel/irq_32.c
15413 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
15414 __asm__ __volatile__("andl %%esp,%0" :
15415 "=r" (sp) : "0" (THREAD_SIZE - 1));
15416
15417 - return sp < (sizeof(struct thread_info) + STACK_WARN);
15418 + return sp < STACK_WARN;
15419 }
15420
15421 static void print_stack_overflow(void)
15422 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(void) { }
15423 * per-CPU IRQ handling contexts (thread information and stack)
15424 */
15425 union irq_ctx {
15426 - struct thread_info tinfo;
15427 - u32 stack[THREAD_SIZE/sizeof(u32)];
15428 + unsigned long previous_esp;
15429 + u32 stack[THREAD_SIZE/sizeof(u32)];
15430 } __attribute__((aligned(THREAD_SIZE)));
15431
15432 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15433 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, void *stack)
15434 static inline int
15435 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15436 {
15437 - union irq_ctx *curctx, *irqctx;
15438 + union irq_ctx *irqctx;
15439 u32 *isp, arg1, arg2;
15440
15441 - curctx = (union irq_ctx *) current_thread_info();
15442 irqctx = __this_cpu_read(hardirq_ctx);
15443
15444 /*
15445 @@ -87,21 +86,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15446 * handler) we can't do that and just have to keep using the
15447 * current stack (which is the irq stack already after all)
15448 */
15449 - if (unlikely(curctx == irqctx))
15450 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15451 return 0;
15452
15453 /* build the stack frame on the IRQ stack */
15454 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15455 - irqctx->tinfo.task = curctx->tinfo.task;
15456 - irqctx->tinfo.previous_esp = current_stack_pointer;
15457 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15458 + irqctx->previous_esp = current_stack_pointer;
15459
15460 - /*
15461 - * Copy the softirq bits in preempt_count so that the
15462 - * softirq checks work in the hardirq context.
15463 - */
15464 - irqctx->tinfo.preempt_count =
15465 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15466 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15467 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15468 + __set_fs(MAKE_MM_SEG(0));
15469 +#endif
15470
15471 if (unlikely(overflow))
15472 call_on_stack(print_stack_overflow, isp);
15473 @@ -113,6 +107,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15474 : "0" (irq), "1" (desc), "2" (isp),
15475 "D" (desc->handle_irq)
15476 : "memory", "cc", "ecx");
15477 +
15478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15479 + __set_fs(current_thread_info()->addr_limit);
15480 +#endif
15481 +
15482 return 1;
15483 }
15484
15485 @@ -121,29 +120,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15486 */
15487 void __cpuinit irq_ctx_init(int cpu)
15488 {
15489 - union irq_ctx *irqctx;
15490 -
15491 if (per_cpu(hardirq_ctx, cpu))
15492 return;
15493
15494 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15495 - THREAD_FLAGS,
15496 - THREAD_ORDER));
15497 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15498 - irqctx->tinfo.cpu = cpu;
15499 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15500 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15501 -
15502 - per_cpu(hardirq_ctx, cpu) = irqctx;
15503 -
15504 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15505 - THREAD_FLAGS,
15506 - THREAD_ORDER));
15507 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15508 - irqctx->tinfo.cpu = cpu;
15509 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15510 -
15511 - per_cpu(softirq_ctx, cpu) = irqctx;
15512 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15513 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15514
15515 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15516 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15517 @@ -152,7 +133,6 @@ void __cpuinit irq_ctx_init(int cpu)
15518 asmlinkage void do_softirq(void)
15519 {
15520 unsigned long flags;
15521 - struct thread_info *curctx;
15522 union irq_ctx *irqctx;
15523 u32 *isp;
15524
15525 @@ -162,15 +142,22 @@ asmlinkage void do_softirq(void)
15526 local_irq_save(flags);
15527
15528 if (local_softirq_pending()) {
15529 - curctx = current_thread_info();
15530 irqctx = __this_cpu_read(softirq_ctx);
15531 - irqctx->tinfo.task = curctx->task;
15532 - irqctx->tinfo.previous_esp = current_stack_pointer;
15533 + irqctx->previous_esp = current_stack_pointer;
15534
15535 /* build the stack frame on the softirq stack */
15536 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15537 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15538 +
15539 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15540 + __set_fs(MAKE_MM_SEG(0));
15541 +#endif
15542
15543 call_on_stack(__do_softirq, isp);
15544 +
15545 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15546 + __set_fs(current_thread_info()->addr_limit);
15547 +#endif
15548 +
15549 /*
15550 * Shouldn't happen, we returned above if in_interrupt():
15551 */
15552 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
15553 index 69bca46..0bac999 100644
15554 --- a/arch/x86/kernel/irq_64.c
15555 +++ b/arch/x86/kernel/irq_64.c
15556 @@ -38,7 +38,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
15557 #ifdef CONFIG_DEBUG_STACKOVERFLOW
15558 u64 curbase = (u64)task_stack_page(current);
15559
15560 - if (user_mode_vm(regs))
15561 + if (user_mode(regs))
15562 return;
15563
15564 WARN_ONCE(regs->sp >= curbase &&
15565 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
15566 index faba577..93b9e71 100644
15567 --- a/arch/x86/kernel/kgdb.c
15568 +++ b/arch/x86/kernel/kgdb.c
15569 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
15570 #ifdef CONFIG_X86_32
15571 switch (regno) {
15572 case GDB_SS:
15573 - if (!user_mode_vm(regs))
15574 + if (!user_mode(regs))
15575 *(unsigned long *)mem = __KERNEL_DS;
15576 break;
15577 case GDB_SP:
15578 - if (!user_mode_vm(regs))
15579 + if (!user_mode(regs))
15580 *(unsigned long *)mem = kernel_stack_pointer(regs);
15581 break;
15582 case GDB_GS:
15583 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
15584 case 'k':
15585 /* clear the trace bit */
15586 linux_regs->flags &= ~X86_EFLAGS_TF;
15587 - atomic_set(&kgdb_cpu_doing_single_step, -1);
15588 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15589
15590 /* set the trace bit if we're stepping */
15591 if (remcomInBuffer[0] == 's') {
15592 linux_regs->flags |= X86_EFLAGS_TF;
15593 - atomic_set(&kgdb_cpu_doing_single_step,
15594 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15595 raw_smp_processor_id());
15596 }
15597
15598 @@ -543,7 +543,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
15599
15600 switch (cmd) {
15601 case DIE_DEBUG:
15602 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
15603 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
15604 if (user_mode(regs))
15605 return single_step_cont(regs, args);
15606 break;
15607 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
15608 index 7da647d..5d3c4c1 100644
15609 --- a/arch/x86/kernel/kprobes.c
15610 +++ b/arch/x86/kernel/kprobes.c
15611 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
15612 } __attribute__((packed)) *insn;
15613
15614 insn = (struct __arch_relative_insn *)from;
15615 +
15616 + pax_open_kernel();
15617 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
15618 insn->op = op;
15619 + pax_close_kernel();
15620 }
15621
15622 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
15623 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
15624 kprobe_opcode_t opcode;
15625 kprobe_opcode_t *orig_opcodes = opcodes;
15626
15627 - if (search_exception_tables((unsigned long)opcodes))
15628 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15629 return 0; /* Page fault may occur on this address. */
15630
15631 retry:
15632 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
15633 }
15634 }
15635 insn_get_length(&insn);
15636 + pax_open_kernel();
15637 memcpy(dest, insn.kaddr, insn.length);
15638 + pax_close_kernel();
15639
15640 #ifdef CONFIG_X86_64
15641 if (insn_rip_relative(&insn)) {
15642 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
15643 (u8 *) dest;
15644 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
15645 disp = (u8 *) dest + insn_offset_displacement(&insn);
15646 + pax_open_kernel();
15647 *(s32 *) disp = (s32) newdisp;
15648 + pax_close_kernel();
15649 }
15650 #endif
15651 return insn.length;
15652 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
15653 */
15654 __copy_instruction(p->ainsn.insn, p->addr, 0);
15655
15656 - if (can_boost(p->addr))
15657 + if (can_boost(ktla_ktva(p->addr)))
15658 p->ainsn.boostable = 0;
15659 else
15660 p->ainsn.boostable = -1;
15661
15662 - p->opcode = *p->addr;
15663 + p->opcode = *(ktla_ktva(p->addr));
15664 }
15665
15666 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15667 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
15668 * nor set current_kprobe, because it doesn't use single
15669 * stepping.
15670 */
15671 - regs->ip = (unsigned long)p->ainsn.insn;
15672 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15673 preempt_enable_no_resched();
15674 return;
15675 }
15676 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
15677 if (p->opcode == BREAKPOINT_INSTRUCTION)
15678 regs->ip = (unsigned long)p->addr;
15679 else
15680 - regs->ip = (unsigned long)p->ainsn.insn;
15681 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15682 }
15683
15684 /*
15685 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
15686 setup_singlestep(p, regs, kcb, 0);
15687 return 1;
15688 }
15689 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
15690 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15691 /*
15692 * The breakpoint instruction was removed right
15693 * after we hit it. Another cpu has removed
15694 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
15695 " movq %rax, 152(%rsp)\n"
15696 RESTORE_REGS_STRING
15697 " popfq\n"
15698 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
15699 + " btsq $63,(%rsp)\n"
15700 +#endif
15701 #else
15702 " pushf\n"
15703 SAVE_REGS_STRING
15704 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
15705 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15706 {
15707 unsigned long *tos = stack_addr(regs);
15708 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15709 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15710 unsigned long orig_ip = (unsigned long)p->addr;
15711 kprobe_opcode_t *insn = p->ainsn.insn;
15712
15713 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
15714 struct die_args *args = data;
15715 int ret = NOTIFY_DONE;
15716
15717 - if (args->regs && user_mode_vm(args->regs))
15718 + if (args->regs && user_mode(args->regs))
15719 return ret;
15720
15721 switch (val) {
15722 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
15723 * Verify if the address gap is in 2GB range, because this uses
15724 * a relative jump.
15725 */
15726 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
15727 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
15728 if (abs(rel) > 0x7fffffff)
15729 return -ERANGE;
15730
15731 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
15732 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
15733
15734 /* Set probe function call */
15735 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
15736 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
15737
15738 /* Set returning jmp instruction at the tail of out-of-line buffer */
15739 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
15740 - (u8 *)op->kp.addr + op->optinsn.size);
15741 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
15742
15743 flush_icache_range((unsigned long) buf,
15744 (unsigned long) buf + TMPL_END_IDX +
15745 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
15746 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
15747
15748 /* Backup instructions which will be replaced by jump address */
15749 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
15750 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
15751 RELATIVE_ADDR_SIZE);
15752
15753 insn_buf[0] = RELATIVEJUMP_OPCODE;
15754 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
15755 index a9c2116..a52d4fc 100644
15756 --- a/arch/x86/kernel/kvm.c
15757 +++ b/arch/x86/kernel/kvm.c
15758 @@ -437,6 +437,7 @@ static void __init paravirt_ops_setup(void)
15759 pv_mmu_ops.set_pud = kvm_set_pud;
15760 #if PAGETABLE_LEVELS == 4
15761 pv_mmu_ops.set_pgd = kvm_set_pgd;
15762 + pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
15763 #endif
15764 #endif
15765 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
15766 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
15767 index ea69726..604d066 100644
15768 --- a/arch/x86/kernel/ldt.c
15769 +++ b/arch/x86/kernel/ldt.c
15770 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
15771 if (reload) {
15772 #ifdef CONFIG_SMP
15773 preempt_disable();
15774 - load_LDT(pc);
15775 + load_LDT_nolock(pc);
15776 if (!cpumask_equal(mm_cpumask(current->mm),
15777 cpumask_of(smp_processor_id())))
15778 smp_call_function(flush_ldt, current->mm, 1);
15779 preempt_enable();
15780 #else
15781 - load_LDT(pc);
15782 + load_LDT_nolock(pc);
15783 #endif
15784 }
15785 if (oldsize) {
15786 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
15787 return err;
15788
15789 for (i = 0; i < old->size; i++)
15790 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
15791 + write_ldt_entry(new->ldt, i, old->ldt + i);
15792 return 0;
15793 }
15794
15795 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
15796 retval = copy_ldt(&mm->context, &old_mm->context);
15797 mutex_unlock(&old_mm->context.lock);
15798 }
15799 +
15800 + if (tsk == current) {
15801 + mm->context.vdso = 0;
15802 +
15803 +#ifdef CONFIG_X86_32
15804 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15805 + mm->context.user_cs_base = 0UL;
15806 + mm->context.user_cs_limit = ~0UL;
15807 +
15808 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15809 + cpus_clear(mm->context.cpu_user_cs_mask);
15810 +#endif
15811 +
15812 +#endif
15813 +#endif
15814 +
15815 + }
15816 +
15817 return retval;
15818 }
15819
15820 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
15821 }
15822 }
15823
15824 +#ifdef CONFIG_PAX_SEGMEXEC
15825 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
15826 + error = -EINVAL;
15827 + goto out_unlock;
15828 + }
15829 +#endif
15830 +
15831 fill_ldt(&ldt, &ldt_info);
15832 if (oldmode)
15833 ldt.avl = 0;
15834 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
15835 index a3fa43b..8966f4c 100644
15836 --- a/arch/x86/kernel/machine_kexec_32.c
15837 +++ b/arch/x86/kernel/machine_kexec_32.c
15838 @@ -27,7 +27,7 @@
15839 #include <asm/cacheflush.h>
15840 #include <asm/debugreg.h>
15841
15842 -static void set_idt(void *newidt, __u16 limit)
15843 +static void set_idt(struct desc_struct *newidt, __u16 limit)
15844 {
15845 struct desc_ptr curidt;
15846
15847 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
15848 }
15849
15850
15851 -static void set_gdt(void *newgdt, __u16 limit)
15852 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
15853 {
15854 struct desc_ptr curgdt;
15855
15856 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
15857 }
15858
15859 control_page = page_address(image->control_code_page);
15860 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
15861 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
15862
15863 relocate_kernel_ptr = control_page;
15864 page_list[PA_CONTROL_PAGE] = __pa(control_page);
15865 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
15866 index 3ca42d0..7cff8cc 100644
15867 --- a/arch/x86/kernel/microcode_intel.c
15868 +++ b/arch/x86/kernel/microcode_intel.c
15869 @@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
15870
15871 static int get_ucode_user(void *to, const void *from, size_t n)
15872 {
15873 - return copy_from_user(to, from, n);
15874 + return copy_from_user(to, (const void __force_user *)from, n);
15875 }
15876
15877 static enum ucode_state
15878 request_microcode_user(int cpu, const void __user *buf, size_t size)
15879 {
15880 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
15881 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
15882 }
15883
15884 static void microcode_fini_cpu(int cpu)
15885 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
15886 index 925179f..85bec6c 100644
15887 --- a/arch/x86/kernel/module.c
15888 +++ b/arch/x86/kernel/module.c
15889 @@ -36,15 +36,60 @@
15890 #define DEBUGP(fmt...)
15891 #endif
15892
15893 -void *module_alloc(unsigned long size)
15894 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
15895 {
15896 if (PAGE_ALIGN(size) > MODULES_LEN)
15897 return NULL;
15898 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
15899 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
15900 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
15901 -1, __builtin_return_address(0));
15902 }
15903
15904 +void *module_alloc(unsigned long size)
15905 +{
15906 +
15907 +#ifdef CONFIG_PAX_KERNEXEC
15908 + return __module_alloc(size, PAGE_KERNEL);
15909 +#else
15910 + return __module_alloc(size, PAGE_KERNEL_EXEC);
15911 +#endif
15912 +
15913 +}
15914 +
15915 +#ifdef CONFIG_PAX_KERNEXEC
15916 +#ifdef CONFIG_X86_32
15917 +void *module_alloc_exec(unsigned long size)
15918 +{
15919 + struct vm_struct *area;
15920 +
15921 + if (size == 0)
15922 + return NULL;
15923 +
15924 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
15925 + return area ? area->addr : NULL;
15926 +}
15927 +EXPORT_SYMBOL(module_alloc_exec);
15928 +
15929 +void module_free_exec(struct module *mod, void *module_region)
15930 +{
15931 + vunmap(module_region);
15932 +}
15933 +EXPORT_SYMBOL(module_free_exec);
15934 +#else
15935 +void module_free_exec(struct module *mod, void *module_region)
15936 +{
15937 + module_free(mod, module_region);
15938 +}
15939 +EXPORT_SYMBOL(module_free_exec);
15940 +
15941 +void *module_alloc_exec(unsigned long size)
15942 +{
15943 + return __module_alloc(size, PAGE_KERNEL_RX);
15944 +}
15945 +EXPORT_SYMBOL(module_alloc_exec);
15946 +#endif
15947 +#endif
15948 +
15949 #ifdef CONFIG_X86_32
15950 int apply_relocate(Elf32_Shdr *sechdrs,
15951 const char *strtab,
15952 @@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15953 unsigned int i;
15954 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
15955 Elf32_Sym *sym;
15956 - uint32_t *location;
15957 + uint32_t *plocation, location;
15958
15959 DEBUGP("Applying relocate section %u to %u\n", relsec,
15960 sechdrs[relsec].sh_info);
15961 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
15962 /* This is where to make the change */
15963 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
15964 - + rel[i].r_offset;
15965 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
15966 + location = (uint32_t)plocation;
15967 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
15968 + plocation = ktla_ktva((void *)plocation);
15969 /* This is the symbol it is referring to. Note that all
15970 undefined symbols have been resolved. */
15971 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
15972 @@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15973 switch (ELF32_R_TYPE(rel[i].r_info)) {
15974 case R_386_32:
15975 /* We add the value into the location given */
15976 - *location += sym->st_value;
15977 + pax_open_kernel();
15978 + *plocation += sym->st_value;
15979 + pax_close_kernel();
15980 break;
15981 case R_386_PC32:
15982 /* Add the value, subtract its postition */
15983 - *location += sym->st_value - (uint32_t)location;
15984 + pax_open_kernel();
15985 + *plocation += sym->st_value - location;
15986 + pax_close_kernel();
15987 break;
15988 default:
15989 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
15990 @@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
15991 case R_X86_64_NONE:
15992 break;
15993 case R_X86_64_64:
15994 + pax_open_kernel();
15995 *(u64 *)loc = val;
15996 + pax_close_kernel();
15997 break;
15998 case R_X86_64_32:
15999 + pax_open_kernel();
16000 *(u32 *)loc = val;
16001 + pax_close_kernel();
16002 if (val != *(u32 *)loc)
16003 goto overflow;
16004 break;
16005 case R_X86_64_32S:
16006 + pax_open_kernel();
16007 *(s32 *)loc = val;
16008 + pax_close_kernel();
16009 if ((s64)val != *(s32 *)loc)
16010 goto overflow;
16011 break;
16012 case R_X86_64_PC32:
16013 val -= (u64)loc;
16014 + pax_open_kernel();
16015 *(u32 *)loc = val;
16016 + pax_close_kernel();
16017 +
16018 #if 0
16019 if ((s64)val != *(s32 *)loc)
16020 goto overflow;
16021 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
16022 index e88f37b..1353db6 100644
16023 --- a/arch/x86/kernel/nmi.c
16024 +++ b/arch/x86/kernel/nmi.c
16025 @@ -408,6 +408,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
16026 dotraplinkage notrace __kprobes void
16027 do_nmi(struct pt_regs *regs, long error_code)
16028 {
16029 +
16030 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16031 + if (!user_mode(regs)) {
16032 + unsigned long cs = regs->cs & 0xFFFF;
16033 + unsigned long ip = ktva_ktla(regs->ip);
16034 +
16035 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
16036 + regs->ip = ip;
16037 + }
16038 +#endif
16039 +
16040 nmi_enter();
16041
16042 inc_irq_stat(__nmi_count);
16043 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
16044 index 676b8c7..870ba04 100644
16045 --- a/arch/x86/kernel/paravirt-spinlocks.c
16046 +++ b/arch/x86/kernel/paravirt-spinlocks.c
16047 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
16048 arch_spin_lock(lock);
16049 }
16050
16051 -struct pv_lock_ops pv_lock_ops = {
16052 +struct pv_lock_ops pv_lock_ops __read_only = {
16053 #ifdef CONFIG_SMP
16054 .spin_is_locked = __ticket_spin_is_locked,
16055 .spin_is_contended = __ticket_spin_is_contended,
16056 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
16057 index d90272e..6bb013b 100644
16058 --- a/arch/x86/kernel/paravirt.c
16059 +++ b/arch/x86/kernel/paravirt.c
16060 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
16061 {
16062 return x;
16063 }
16064 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16065 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
16066 +#endif
16067
16068 void __init default_banner(void)
16069 {
16070 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
16071 if (opfunc == NULL)
16072 /* If there's no function, patch it with a ud2a (BUG) */
16073 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16074 - else if (opfunc == _paravirt_nop)
16075 + else if (opfunc == (void *)_paravirt_nop)
16076 /* If the operation is a nop, then nop the callsite */
16077 ret = paravirt_patch_nop();
16078
16079 /* identity functions just return their single argument */
16080 - else if (opfunc == _paravirt_ident_32)
16081 + else if (opfunc == (void *)_paravirt_ident_32)
16082 ret = paravirt_patch_ident_32(insnbuf, len);
16083 - else if (opfunc == _paravirt_ident_64)
16084 + else if (opfunc == (void *)_paravirt_ident_64)
16085 ret = paravirt_patch_ident_64(insnbuf, len);
16086 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16087 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
16088 + ret = paravirt_patch_ident_64(insnbuf, len);
16089 +#endif
16090
16091 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16092 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
16093 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
16094 if (insn_len > len || start == NULL)
16095 insn_len = len;
16096 else
16097 - memcpy(insnbuf, start, insn_len);
16098 + memcpy(insnbuf, ktla_ktva(start), insn_len);
16099
16100 return insn_len;
16101 }
16102 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
16103 preempt_enable();
16104 }
16105
16106 -struct pv_info pv_info = {
16107 +struct pv_info pv_info __read_only = {
16108 .name = "bare hardware",
16109 .paravirt_enabled = 0,
16110 .kernel_rpl = 0,
16111 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
16112 #endif
16113 };
16114
16115 -struct pv_init_ops pv_init_ops = {
16116 +struct pv_init_ops pv_init_ops __read_only = {
16117 .patch = native_patch,
16118 };
16119
16120 -struct pv_time_ops pv_time_ops = {
16121 +struct pv_time_ops pv_time_ops __read_only = {
16122 .sched_clock = native_sched_clock,
16123 .steal_clock = native_steal_clock,
16124 };
16125
16126 -struct pv_irq_ops pv_irq_ops = {
16127 +struct pv_irq_ops pv_irq_ops __read_only = {
16128 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16129 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16130 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16131 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
16132 #endif
16133 };
16134
16135 -struct pv_cpu_ops pv_cpu_ops = {
16136 +struct pv_cpu_ops pv_cpu_ops __read_only = {
16137 .cpuid = native_cpuid,
16138 .get_debugreg = native_get_debugreg,
16139 .set_debugreg = native_set_debugreg,
16140 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
16141 .end_context_switch = paravirt_nop,
16142 };
16143
16144 -struct pv_apic_ops pv_apic_ops = {
16145 +struct pv_apic_ops pv_apic_ops __read_only = {
16146 #ifdef CONFIG_X86_LOCAL_APIC
16147 .startup_ipi_hook = paravirt_nop,
16148 #endif
16149 };
16150
16151 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
16152 +#ifdef CONFIG_X86_32
16153 +#ifdef CONFIG_X86_PAE
16154 +/* 64-bit pagetable entries */
16155 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
16156 +#else
16157 /* 32-bit pagetable entries */
16158 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
16159 +#endif
16160 #else
16161 /* 64-bit pagetable entries */
16162 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16163 #endif
16164
16165 -struct pv_mmu_ops pv_mmu_ops = {
16166 +struct pv_mmu_ops pv_mmu_ops __read_only = {
16167
16168 .read_cr2 = native_read_cr2,
16169 .write_cr2 = native_write_cr2,
16170 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
16171 .make_pud = PTE_IDENT,
16172
16173 .set_pgd = native_set_pgd,
16174 + .set_pgd_batched = native_set_pgd_batched,
16175 #endif
16176 #endif /* PAGETABLE_LEVELS >= 3 */
16177
16178 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
16179 },
16180
16181 .set_fixmap = native_set_fixmap,
16182 +
16183 +#ifdef CONFIG_PAX_KERNEXEC
16184 + .pax_open_kernel = native_pax_open_kernel,
16185 + .pax_close_kernel = native_pax_close_kernel,
16186 +#endif
16187 +
16188 };
16189
16190 EXPORT_SYMBOL_GPL(pv_time_ops);
16191 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
16192 index 35ccf75..7a15747 100644
16193 --- a/arch/x86/kernel/pci-iommu_table.c
16194 +++ b/arch/x86/kernel/pci-iommu_table.c
16195 @@ -2,7 +2,7 @@
16196 #include <asm/iommu_table.h>
16197 #include <linux/string.h>
16198 #include <linux/kallsyms.h>
16199 -
16200 +#include <linux/sched.h>
16201
16202 #define DEBUG 1
16203
16204 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
16205 index ee5d4fb..426649b 100644
16206 --- a/arch/x86/kernel/process.c
16207 +++ b/arch/x86/kernel/process.c
16208 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
16209
16210 void free_thread_info(struct thread_info *ti)
16211 {
16212 - free_thread_xstate(ti->task);
16213 free_pages((unsigned long)ti, THREAD_ORDER);
16214 }
16215
16216 +static struct kmem_cache *task_struct_cachep;
16217 +
16218 void arch_task_cache_init(void)
16219 {
16220 - task_xstate_cachep =
16221 - kmem_cache_create("task_xstate", xstate_size,
16222 + /* create a slab on which task_structs can be allocated */
16223 + task_struct_cachep =
16224 + kmem_cache_create("task_struct", sizeof(struct task_struct),
16225 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16226 +
16227 + task_xstate_cachep =
16228 + kmem_cache_create("task_xstate", xstate_size,
16229 __alignof__(union thread_xstate),
16230 - SLAB_PANIC | SLAB_NOTRACK, NULL);
16231 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16232 +}
16233 +
16234 +struct task_struct *alloc_task_struct_node(int node)
16235 +{
16236 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
16237 +}
16238 +
16239 +void free_task_struct(struct task_struct *task)
16240 +{
16241 + free_thread_xstate(task);
16242 + kmem_cache_free(task_struct_cachep, task);
16243 }
16244
16245 /*
16246 @@ -70,7 +87,7 @@ void exit_thread(void)
16247 unsigned long *bp = t->io_bitmap_ptr;
16248
16249 if (bp) {
16250 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16251 + struct tss_struct *tss = init_tss + get_cpu();
16252
16253 t->io_bitmap_ptr = NULL;
16254 clear_thread_flag(TIF_IO_BITMAP);
16255 @@ -106,7 +123,7 @@ void show_regs_common(void)
16256
16257 printk(KERN_CONT "\n");
16258 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
16259 - current->pid, current->comm, print_tainted(),
16260 + task_pid_nr(current), current->comm, print_tainted(),
16261 init_utsname()->release,
16262 (int)strcspn(init_utsname()->version, " "),
16263 init_utsname()->version);
16264 @@ -120,6 +137,9 @@ void flush_thread(void)
16265 {
16266 struct task_struct *tsk = current;
16267
16268 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16269 + loadsegment(gs, 0);
16270 +#endif
16271 flush_ptrace_hw_breakpoint(tsk);
16272 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
16273 /*
16274 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
16275 regs.di = (unsigned long) arg;
16276
16277 #ifdef CONFIG_X86_32
16278 - regs.ds = __USER_DS;
16279 - regs.es = __USER_DS;
16280 + regs.ds = __KERNEL_DS;
16281 + regs.es = __KERNEL_DS;
16282 regs.fs = __KERNEL_PERCPU;
16283 - regs.gs = __KERNEL_STACK_CANARY;
16284 + savesegment(gs, regs.gs);
16285 #else
16286 regs.ss = __KERNEL_DS;
16287 #endif
16288 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
16289
16290 return ret;
16291 }
16292 -void stop_this_cpu(void *dummy)
16293 +__noreturn void stop_this_cpu(void *dummy)
16294 {
16295 local_irq_disable();
16296 /*
16297 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
16298 }
16299 early_param("idle", idle_setup);
16300
16301 -unsigned long arch_align_stack(unsigned long sp)
16302 +#ifdef CONFIG_PAX_RANDKSTACK
16303 +void pax_randomize_kstack(struct pt_regs *regs)
16304 {
16305 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16306 - sp -= get_random_int() % 8192;
16307 - return sp & ~0xf;
16308 -}
16309 + struct thread_struct *thread = &current->thread;
16310 + unsigned long time;
16311
16312 -unsigned long arch_randomize_brk(struct mm_struct *mm)
16313 -{
16314 - unsigned long range_end = mm->brk + 0x02000000;
16315 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16316 -}
16317 + if (!randomize_va_space)
16318 + return;
16319 +
16320 + if (v8086_mode(regs))
16321 + return;
16322
16323 + rdtscl(time);
16324 +
16325 + /* P4 seems to return a 0 LSB, ignore it */
16326 +#ifdef CONFIG_MPENTIUM4
16327 + time &= 0x3EUL;
16328 + time <<= 2;
16329 +#elif defined(CONFIG_X86_64)
16330 + time &= 0xFUL;
16331 + time <<= 4;
16332 +#else
16333 + time &= 0x1FUL;
16334 + time <<= 3;
16335 +#endif
16336 +
16337 + thread->sp0 ^= time;
16338 + load_sp0(init_tss + smp_processor_id(), thread);
16339 +
16340 +#ifdef CONFIG_X86_64
16341 + percpu_write(kernel_stack, thread->sp0);
16342 +#endif
16343 +}
16344 +#endif
16345 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
16346 index 795b79f..063767a 100644
16347 --- a/arch/x86/kernel/process_32.c
16348 +++ b/arch/x86/kernel/process_32.c
16349 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
16350 unsigned long thread_saved_pc(struct task_struct *tsk)
16351 {
16352 return ((unsigned long *)tsk->thread.sp)[3];
16353 +//XXX return tsk->thread.eip;
16354 }
16355
16356 #ifndef CONFIG_SMP
16357 @@ -130,15 +131,14 @@ void __show_regs(struct pt_regs *regs, int all)
16358 unsigned long sp;
16359 unsigned short ss, gs;
16360
16361 - if (user_mode_vm(regs)) {
16362 + if (user_mode(regs)) {
16363 sp = regs->sp;
16364 ss = regs->ss & 0xffff;
16365 - gs = get_user_gs(regs);
16366 } else {
16367 sp = kernel_stack_pointer(regs);
16368 savesegment(ss, ss);
16369 - savesegment(gs, gs);
16370 }
16371 + gs = get_user_gs(regs);
16372
16373 show_regs_common();
16374
16375 @@ -200,13 +200,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16376 struct task_struct *tsk;
16377 int err;
16378
16379 - childregs = task_pt_regs(p);
16380 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16381 *childregs = *regs;
16382 childregs->ax = 0;
16383 childregs->sp = sp;
16384
16385 p->thread.sp = (unsigned long) childregs;
16386 p->thread.sp0 = (unsigned long) (childregs+1);
16387 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16388
16389 p->thread.ip = (unsigned long) ret_from_fork;
16390
16391 @@ -296,7 +297,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16392 struct thread_struct *prev = &prev_p->thread,
16393 *next = &next_p->thread;
16394 int cpu = smp_processor_id();
16395 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16396 + struct tss_struct *tss = init_tss + cpu;
16397 bool preload_fpu;
16398
16399 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16400 @@ -331,6 +332,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16401 */
16402 lazy_save_gs(prev->gs);
16403
16404 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16405 + __set_fs(task_thread_info(next_p)->addr_limit);
16406 +#endif
16407 +
16408 /*
16409 * Load the per-thread Thread-Local Storage descriptor.
16410 */
16411 @@ -366,6 +371,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16412 */
16413 arch_end_context_switch(next_p);
16414
16415 + percpu_write(current_task, next_p);
16416 + percpu_write(current_tinfo, &next_p->tinfo);
16417 +
16418 if (preload_fpu)
16419 __math_state_restore();
16420
16421 @@ -375,8 +383,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16422 if (prev->gs | next->gs)
16423 lazy_load_gs(next->gs);
16424
16425 - percpu_write(current_task, next_p);
16426 -
16427 return prev_p;
16428 }
16429
16430 @@ -406,4 +412,3 @@ unsigned long get_wchan(struct task_struct *p)
16431 } while (count++ < 16);
16432 return 0;
16433 }
16434 -
16435 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
16436 index 3bd7e6e..90b2bcf 100644
16437 --- a/arch/x86/kernel/process_64.c
16438 +++ b/arch/x86/kernel/process_64.c
16439 @@ -89,7 +89,7 @@ static void __exit_idle(void)
16440 void exit_idle(void)
16441 {
16442 /* idle loop has pid 0 */
16443 - if (current->pid)
16444 + if (task_pid_nr(current))
16445 return;
16446 __exit_idle();
16447 }
16448 @@ -264,8 +264,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16449 struct pt_regs *childregs;
16450 struct task_struct *me = current;
16451
16452 - childregs = ((struct pt_regs *)
16453 - (THREAD_SIZE + task_stack_page(p))) - 1;
16454 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16455 *childregs = *regs;
16456
16457 childregs->ax = 0;
16458 @@ -277,6 +276,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16459 p->thread.sp = (unsigned long) childregs;
16460 p->thread.sp0 = (unsigned long) (childregs+1);
16461 p->thread.usersp = me->thread.usersp;
16462 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16463
16464 set_tsk_thread_flag(p, TIF_FORK);
16465
16466 @@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16467 struct thread_struct *prev = &prev_p->thread;
16468 struct thread_struct *next = &next_p->thread;
16469 int cpu = smp_processor_id();
16470 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16471 + struct tss_struct *tss = init_tss + cpu;
16472 unsigned fsindex, gsindex;
16473 bool preload_fpu;
16474
16475 @@ -475,10 +475,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16476 prev->usersp = percpu_read(old_rsp);
16477 percpu_write(old_rsp, next->usersp);
16478 percpu_write(current_task, next_p);
16479 + percpu_write(current_tinfo, &next_p->tinfo);
16480
16481 - percpu_write(kernel_stack,
16482 - (unsigned long)task_stack_page(next_p) +
16483 - THREAD_SIZE - KERNEL_STACK_OFFSET);
16484 + percpu_write(kernel_stack, next->sp0);
16485
16486 /*
16487 * Now maybe reload the debug registers and handle I/O bitmaps
16488 @@ -540,12 +539,11 @@ unsigned long get_wchan(struct task_struct *p)
16489 if (!p || p == current || p->state == TASK_RUNNING)
16490 return 0;
16491 stack = (unsigned long)task_stack_page(p);
16492 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16493 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16494 return 0;
16495 fp = *(u64 *)(p->thread.sp);
16496 do {
16497 - if (fp < (unsigned long)stack ||
16498 - fp >= (unsigned long)stack+THREAD_SIZE)
16499 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16500 return 0;
16501 ip = *(u64 *)(fp+8);
16502 if (!in_sched_functions(ip))
16503 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
16504 index 8252879..d3219e0 100644
16505 --- a/arch/x86/kernel/ptrace.c
16506 +++ b/arch/x86/kernel/ptrace.c
16507 @@ -822,7 +822,7 @@ long arch_ptrace(struct task_struct *child, long request,
16508 unsigned long addr, unsigned long data)
16509 {
16510 int ret;
16511 - unsigned long __user *datap = (unsigned long __user *)data;
16512 + unsigned long __user *datap = (__force unsigned long __user *)data;
16513
16514 switch (request) {
16515 /* read the word at location addr in the USER area. */
16516 @@ -907,14 +907,14 @@ long arch_ptrace(struct task_struct *child, long request,
16517 if ((int) addr < 0)
16518 return -EIO;
16519 ret = do_get_thread_area(child, addr,
16520 - (struct user_desc __user *)data);
16521 + (__force struct user_desc __user *) data);
16522 break;
16523
16524 case PTRACE_SET_THREAD_AREA:
16525 if ((int) addr < 0)
16526 return -EIO;
16527 ret = do_set_thread_area(child, addr,
16528 - (struct user_desc __user *)data, 0);
16529 + (__force struct user_desc __user *) data, 0);
16530 break;
16531 #endif
16532
16533 @@ -1331,7 +1331,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
16534 memset(info, 0, sizeof(*info));
16535 info->si_signo = SIGTRAP;
16536 info->si_code = si_code;
16537 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
16538 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
16539 }
16540
16541 void user_single_step_siginfo(struct task_struct *tsk,
16542 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
16543 index 42eb330..139955c 100644
16544 --- a/arch/x86/kernel/pvclock.c
16545 +++ b/arch/x86/kernel/pvclock.c
16546 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
16547 return pv_tsc_khz;
16548 }
16549
16550 -static atomic64_t last_value = ATOMIC64_INIT(0);
16551 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
16552
16553 void pvclock_resume(void)
16554 {
16555 - atomic64_set(&last_value, 0);
16556 + atomic64_set_unchecked(&last_value, 0);
16557 }
16558
16559 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16560 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16561 * updating at the same time, and one of them could be slightly behind,
16562 * making the assumption that last_value always go forward fail to hold.
16563 */
16564 - last = atomic64_read(&last_value);
16565 + last = atomic64_read_unchecked(&last_value);
16566 do {
16567 if (ret < last)
16568 return last;
16569 - last = atomic64_cmpxchg(&last_value, last, ret);
16570 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
16571 } while (unlikely(last != ret));
16572
16573 return ret;
16574 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
16575 index 37a458b..e63d183 100644
16576 --- a/arch/x86/kernel/reboot.c
16577 +++ b/arch/x86/kernel/reboot.c
16578 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
16579 EXPORT_SYMBOL(pm_power_off);
16580
16581 static const struct desc_ptr no_idt = {};
16582 -static int reboot_mode;
16583 +static unsigned short reboot_mode;
16584 enum reboot_type reboot_type = BOOT_ACPI;
16585 int reboot_force;
16586
16587 @@ -324,13 +324,17 @@ core_initcall(reboot_init);
16588 extern const unsigned char machine_real_restart_asm[];
16589 extern const u64 machine_real_restart_gdt[3];
16590
16591 -void machine_real_restart(unsigned int type)
16592 +__noreturn void machine_real_restart(unsigned int type)
16593 {
16594 void *restart_va;
16595 unsigned long restart_pa;
16596 - void (*restart_lowmem)(unsigned int);
16597 + void (* __noreturn restart_lowmem)(unsigned int);
16598 u64 *lowmem_gdt;
16599
16600 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16601 + struct desc_struct *gdt;
16602 +#endif
16603 +
16604 local_irq_disable();
16605
16606 /* Write zero to CMOS register number 0x0f, which the BIOS POST
16607 @@ -356,14 +360,14 @@ void machine_real_restart(unsigned int type)
16608 boot)". This seems like a fairly standard thing that gets set by
16609 REBOOT.COM programs, and the previous reset routine did this
16610 too. */
16611 - *((unsigned short *)0x472) = reboot_mode;
16612 + *(unsigned short *)(__va(0x472)) = reboot_mode;
16613
16614 /* Patch the GDT in the low memory trampoline */
16615 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
16616
16617 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
16618 restart_pa = virt_to_phys(restart_va);
16619 - restart_lowmem = (void (*)(unsigned int))restart_pa;
16620 + restart_lowmem = (void *)restart_pa;
16621
16622 /* GDT[0]: GDT self-pointer */
16623 lowmem_gdt[0] =
16624 @@ -374,7 +378,33 @@ void machine_real_restart(unsigned int type)
16625 GDT_ENTRY(0x009b, restart_pa, 0xffff);
16626
16627 /* Jump to the identity-mapped low memory code */
16628 +
16629 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16630 + gdt = get_cpu_gdt_table(smp_processor_id());
16631 + pax_open_kernel();
16632 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16633 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
16634 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
16635 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
16636 +#endif
16637 +#ifdef CONFIG_PAX_KERNEXEC
16638 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
16639 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
16640 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
16641 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
16642 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
16643 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
16644 +#endif
16645 + pax_close_kernel();
16646 +#endif
16647 +
16648 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16649 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
16650 + unreachable();
16651 +#else
16652 restart_lowmem(type);
16653 +#endif
16654 +
16655 }
16656 #ifdef CONFIG_APM_MODULE
16657 EXPORT_SYMBOL(machine_real_restart);
16658 @@ -540,7 +570,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
16659 * try to force a triple fault and then cycle between hitting the keyboard
16660 * controller and doing that
16661 */
16662 -static void native_machine_emergency_restart(void)
16663 +__noreturn static void native_machine_emergency_restart(void)
16664 {
16665 int i;
16666 int attempt = 0;
16667 @@ -664,13 +694,13 @@ void native_machine_shutdown(void)
16668 #endif
16669 }
16670
16671 -static void __machine_emergency_restart(int emergency)
16672 +static __noreturn void __machine_emergency_restart(int emergency)
16673 {
16674 reboot_emergency = emergency;
16675 machine_ops.emergency_restart();
16676 }
16677
16678 -static void native_machine_restart(char *__unused)
16679 +static __noreturn void native_machine_restart(char *__unused)
16680 {
16681 printk("machine restart\n");
16682
16683 @@ -679,7 +709,7 @@ static void native_machine_restart(char *__unused)
16684 __machine_emergency_restart(0);
16685 }
16686
16687 -static void native_machine_halt(void)
16688 +static __noreturn void native_machine_halt(void)
16689 {
16690 /* stop other cpus and apics */
16691 machine_shutdown();
16692 @@ -690,7 +720,7 @@ static void native_machine_halt(void)
16693 stop_this_cpu(NULL);
16694 }
16695
16696 -static void native_machine_power_off(void)
16697 +__noreturn static void native_machine_power_off(void)
16698 {
16699 if (pm_power_off) {
16700 if (!reboot_force)
16701 @@ -699,6 +729,7 @@ static void native_machine_power_off(void)
16702 }
16703 /* a fallback in case there is no PM info available */
16704 tboot_shutdown(TB_SHUTDOWN_HALT);
16705 + unreachable();
16706 }
16707
16708 struct machine_ops machine_ops = {
16709 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
16710 index 7a6f3b3..bed145d7 100644
16711 --- a/arch/x86/kernel/relocate_kernel_64.S
16712 +++ b/arch/x86/kernel/relocate_kernel_64.S
16713 @@ -11,6 +11,7 @@
16714 #include <asm/kexec.h>
16715 #include <asm/processor-flags.h>
16716 #include <asm/pgtable_types.h>
16717 +#include <asm/alternative-asm.h>
16718
16719 /*
16720 * Must be relocatable PIC code callable as a C function
16721 @@ -160,13 +161,14 @@ identity_mapped:
16722 xorq %rbp, %rbp
16723 xorq %r8, %r8
16724 xorq %r9, %r9
16725 - xorq %r10, %r9
16726 + xorq %r10, %r10
16727 xorq %r11, %r11
16728 xorq %r12, %r12
16729 xorq %r13, %r13
16730 xorq %r14, %r14
16731 xorq %r15, %r15
16732
16733 + pax_force_retaddr 0, 1
16734 ret
16735
16736 1:
16737 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
16738 index cf0ef98..e3f780b 100644
16739 --- a/arch/x86/kernel/setup.c
16740 +++ b/arch/x86/kernel/setup.c
16741 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
16742
16743 switch (data->type) {
16744 case SETUP_E820_EXT:
16745 - parse_e820_ext(data);
16746 + parse_e820_ext((struct setup_data __force_kernel *)data);
16747 break;
16748 case SETUP_DTB:
16749 add_dtb(pa_data);
16750 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
16751 * area (640->1Mb) as ram even though it is not.
16752 * take them out.
16753 */
16754 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
16755 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
16756 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
16757 }
16758
16759 @@ -773,14 +773,14 @@ void __init setup_arch(char **cmdline_p)
16760
16761 if (!boot_params.hdr.root_flags)
16762 root_mountflags &= ~MS_RDONLY;
16763 - init_mm.start_code = (unsigned long) _text;
16764 - init_mm.end_code = (unsigned long) _etext;
16765 + init_mm.start_code = ktla_ktva((unsigned long) _text);
16766 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
16767 init_mm.end_data = (unsigned long) _edata;
16768 init_mm.brk = _brk_end;
16769
16770 - code_resource.start = virt_to_phys(_text);
16771 - code_resource.end = virt_to_phys(_etext)-1;
16772 - data_resource.start = virt_to_phys(_etext);
16773 + code_resource.start = virt_to_phys(ktla_ktva(_text));
16774 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
16775 + data_resource.start = virt_to_phys(_sdata);
16776 data_resource.end = virt_to_phys(_edata)-1;
16777 bss_resource.start = virt_to_phys(&__bss_start);
16778 bss_resource.end = virt_to_phys(&__bss_stop)-1;
16779 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
16780 index 71f4727..16dc9f7 100644
16781 --- a/arch/x86/kernel/setup_percpu.c
16782 +++ b/arch/x86/kernel/setup_percpu.c
16783 @@ -21,19 +21,17 @@
16784 #include <asm/cpu.h>
16785 #include <asm/stackprotector.h>
16786
16787 -DEFINE_PER_CPU(int, cpu_number);
16788 +#ifdef CONFIG_SMP
16789 +DEFINE_PER_CPU(unsigned int, cpu_number);
16790 EXPORT_PER_CPU_SYMBOL(cpu_number);
16791 +#endif
16792
16793 -#ifdef CONFIG_X86_64
16794 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
16795 -#else
16796 -#define BOOT_PERCPU_OFFSET 0
16797 -#endif
16798
16799 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
16800 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
16801
16802 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
16803 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
16804 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
16805 };
16806 EXPORT_SYMBOL(__per_cpu_offset);
16807 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
16808 {
16809 #ifdef CONFIG_X86_32
16810 struct desc_struct gdt;
16811 + unsigned long base = per_cpu_offset(cpu);
16812
16813 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
16814 - 0x2 | DESCTYPE_S, 0x8);
16815 - gdt.s = 1;
16816 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
16817 + 0x83 | DESCTYPE_S, 0xC);
16818 write_gdt_entry(get_cpu_gdt_table(cpu),
16819 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
16820 #endif
16821 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
16822 /* alrighty, percpu areas up and running */
16823 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
16824 for_each_possible_cpu(cpu) {
16825 +#ifdef CONFIG_CC_STACKPROTECTOR
16826 +#ifdef CONFIG_X86_32
16827 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
16828 +#endif
16829 +#endif
16830 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
16831 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
16832 per_cpu(cpu_number, cpu) = cpu;
16833 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
16834 */
16835 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
16836 #endif
16837 +#ifdef CONFIG_CC_STACKPROTECTOR
16838 +#ifdef CONFIG_X86_32
16839 + if (!cpu)
16840 + per_cpu(stack_canary.canary, cpu) = canary;
16841 +#endif
16842 +#endif
16843 /*
16844 * Up to this point, the boot CPU has been using .init.data
16845 * area. Reload any changed state for the boot CPU.
16846 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
16847 index 54ddaeb2..22c3bdc 100644
16848 --- a/arch/x86/kernel/signal.c
16849 +++ b/arch/x86/kernel/signal.c
16850 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
16851 * Align the stack pointer according to the i386 ABI,
16852 * i.e. so that on function entry ((sp + 4) & 15) == 0.
16853 */
16854 - sp = ((sp + 4) & -16ul) - 4;
16855 + sp = ((sp - 12) & -16ul) - 4;
16856 #else /* !CONFIG_X86_32 */
16857 sp = round_down(sp, 16) - 8;
16858 #endif
16859 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
16860 * Return an always-bogus address instead so we will die with SIGSEGV.
16861 */
16862 if (onsigstack && !likely(on_sig_stack(sp)))
16863 - return (void __user *)-1L;
16864 + return (__force void __user *)-1L;
16865
16866 /* save i387 state */
16867 if (used_math() && save_i387_xstate(*fpstate) < 0)
16868 - return (void __user *)-1L;
16869 + return (__force void __user *)-1L;
16870
16871 return (void __user *)sp;
16872 }
16873 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
16874 }
16875
16876 if (current->mm->context.vdso)
16877 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
16878 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
16879 else
16880 - restorer = &frame->retcode;
16881 + restorer = (void __user *)&frame->retcode;
16882 if (ka->sa.sa_flags & SA_RESTORER)
16883 restorer = ka->sa.sa_restorer;
16884
16885 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
16886 * reasons and because gdb uses it as a signature to notice
16887 * signal handler stack frames.
16888 */
16889 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
16890 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
16891
16892 if (err)
16893 return -EFAULT;
16894 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
16895 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
16896
16897 /* Set up to return from userspace. */
16898 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
16899 + if (current->mm->context.vdso)
16900 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
16901 + else
16902 + restorer = (void __user *)&frame->retcode;
16903 if (ka->sa.sa_flags & SA_RESTORER)
16904 restorer = ka->sa.sa_restorer;
16905 put_user_ex(restorer, &frame->pretcode);
16906 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
16907 * reasons and because gdb uses it as a signature to notice
16908 * signal handler stack frames.
16909 */
16910 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
16911 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
16912 } put_user_catch(err);
16913
16914 if (err)
16915 @@ -769,7 +772,7 @@ static void do_signal(struct pt_regs *regs)
16916 * X86_32: vm86 regs switched out by assembly code before reaching
16917 * here, so testing against kernel CS suffices.
16918 */
16919 - if (!user_mode(regs))
16920 + if (!user_mode_novm(regs))
16921 return;
16922
16923 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
16924 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
16925 index 9f548cb..caf76f7 100644
16926 --- a/arch/x86/kernel/smpboot.c
16927 +++ b/arch/x86/kernel/smpboot.c
16928 @@ -709,17 +709,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
16929 set_idle_for_cpu(cpu, c_idle.idle);
16930 do_rest:
16931 per_cpu(current_task, cpu) = c_idle.idle;
16932 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
16933 #ifdef CONFIG_X86_32
16934 /* Stack for startup_32 can be just as for start_secondary onwards */
16935 irq_ctx_init(cpu);
16936 #else
16937 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
16938 initial_gs = per_cpu_offset(cpu);
16939 - per_cpu(kernel_stack, cpu) =
16940 - (unsigned long)task_stack_page(c_idle.idle) -
16941 - KERNEL_STACK_OFFSET + THREAD_SIZE;
16942 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
16943 #endif
16944 +
16945 + pax_open_kernel();
16946 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16947 + pax_close_kernel();
16948 +
16949 initial_code = (unsigned long)start_secondary;
16950 stack_start = c_idle.idle->thread.sp;
16951
16952 @@ -861,6 +864,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
16953
16954 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
16955
16956 +#ifdef CONFIG_PAX_PER_CPU_PGD
16957 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
16958 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
16959 + KERNEL_PGD_PTRS);
16960 +#endif
16961 +
16962 err = do_boot_cpu(apicid, cpu);
16963 if (err) {
16964 pr_debug("do_boot_cpu failed %d\n", err);
16965 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
16966 index c346d11..d43b163 100644
16967 --- a/arch/x86/kernel/step.c
16968 +++ b/arch/x86/kernel/step.c
16969 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
16970 struct desc_struct *desc;
16971 unsigned long base;
16972
16973 - seg &= ~7UL;
16974 + seg >>= 3;
16975
16976 mutex_lock(&child->mm->context.lock);
16977 - if (unlikely((seg >> 3) >= child->mm->context.size))
16978 + if (unlikely(seg >= child->mm->context.size))
16979 addr = -1L; /* bogus selector, access would fault */
16980 else {
16981 desc = child->mm->context.ldt + seg;
16982 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
16983 addr += base;
16984 }
16985 mutex_unlock(&child->mm->context.lock);
16986 - }
16987 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
16988 + addr = ktla_ktva(addr);
16989
16990 return addr;
16991 }
16992 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
16993 unsigned char opcode[15];
16994 unsigned long addr = convert_ip_to_linear(child, regs);
16995
16996 + if (addr == -EINVAL)
16997 + return 0;
16998 +
16999 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
17000 for (i = 0; i < copied; i++) {
17001 switch (opcode[i]) {
17002 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
17003 index 0b0cb5f..db6b9ed 100644
17004 --- a/arch/x86/kernel/sys_i386_32.c
17005 +++ b/arch/x86/kernel/sys_i386_32.c
17006 @@ -24,17 +24,224 @@
17007
17008 #include <asm/syscalls.h>
17009
17010 -/*
17011 - * Do a system call from kernel instead of calling sys_execve so we
17012 - * end up with proper pt_regs.
17013 - */
17014 -int kernel_execve(const char *filename,
17015 - const char *const argv[],
17016 - const char *const envp[])
17017 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
17018 {
17019 - long __res;
17020 - asm volatile ("int $0x80"
17021 - : "=a" (__res)
17022 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
17023 - return __res;
17024 + unsigned long pax_task_size = TASK_SIZE;
17025 +
17026 +#ifdef CONFIG_PAX_SEGMEXEC
17027 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
17028 + pax_task_size = SEGMEXEC_TASK_SIZE;
17029 +#endif
17030 +
17031 + if (len > pax_task_size || addr > pax_task_size - len)
17032 + return -EINVAL;
17033 +
17034 + return 0;
17035 +}
17036 +
17037 +unsigned long
17038 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
17039 + unsigned long len, unsigned long pgoff, unsigned long flags)
17040 +{
17041 + struct mm_struct *mm = current->mm;
17042 + struct vm_area_struct *vma;
17043 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17044 +
17045 +#ifdef CONFIG_PAX_SEGMEXEC
17046 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17047 + pax_task_size = SEGMEXEC_TASK_SIZE;
17048 +#endif
17049 +
17050 + pax_task_size -= PAGE_SIZE;
17051 +
17052 + if (len > pax_task_size)
17053 + return -ENOMEM;
17054 +
17055 + if (flags & MAP_FIXED)
17056 + return addr;
17057 +
17058 +#ifdef CONFIG_PAX_RANDMMAP
17059 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17060 +#endif
17061 +
17062 + if (addr) {
17063 + addr = PAGE_ALIGN(addr);
17064 + if (pax_task_size - len >= addr) {
17065 + vma = find_vma(mm, addr);
17066 + if (check_heap_stack_gap(vma, addr, len))
17067 + return addr;
17068 + }
17069 + }
17070 + if (len > mm->cached_hole_size) {
17071 + start_addr = addr = mm->free_area_cache;
17072 + } else {
17073 + start_addr = addr = mm->mmap_base;
17074 + mm->cached_hole_size = 0;
17075 + }
17076 +
17077 +#ifdef CONFIG_PAX_PAGEEXEC
17078 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17079 + start_addr = 0x00110000UL;
17080 +
17081 +#ifdef CONFIG_PAX_RANDMMAP
17082 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17083 + start_addr += mm->delta_mmap & 0x03FFF000UL;
17084 +#endif
17085 +
17086 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17087 + start_addr = addr = mm->mmap_base;
17088 + else
17089 + addr = start_addr;
17090 + }
17091 +#endif
17092 +
17093 +full_search:
17094 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17095 + /* At this point: (!vma || addr < vma->vm_end). */
17096 + if (pax_task_size - len < addr) {
17097 + /*
17098 + * Start a new search - just in case we missed
17099 + * some holes.
17100 + */
17101 + if (start_addr != mm->mmap_base) {
17102 + start_addr = addr = mm->mmap_base;
17103 + mm->cached_hole_size = 0;
17104 + goto full_search;
17105 + }
17106 + return -ENOMEM;
17107 + }
17108 + if (check_heap_stack_gap(vma, addr, len))
17109 + break;
17110 + if (addr + mm->cached_hole_size < vma->vm_start)
17111 + mm->cached_hole_size = vma->vm_start - addr;
17112 + addr = vma->vm_end;
17113 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
17114 + start_addr = addr = mm->mmap_base;
17115 + mm->cached_hole_size = 0;
17116 + goto full_search;
17117 + }
17118 + }
17119 +
17120 + /*
17121 + * Remember the place where we stopped the search:
17122 + */
17123 + mm->free_area_cache = addr + len;
17124 + return addr;
17125 +}
17126 +
17127 +unsigned long
17128 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17129 + const unsigned long len, const unsigned long pgoff,
17130 + const unsigned long flags)
17131 +{
17132 + struct vm_area_struct *vma;
17133 + struct mm_struct *mm = current->mm;
17134 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
17135 +
17136 +#ifdef CONFIG_PAX_SEGMEXEC
17137 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17138 + pax_task_size = SEGMEXEC_TASK_SIZE;
17139 +#endif
17140 +
17141 + pax_task_size -= PAGE_SIZE;
17142 +
17143 + /* requested length too big for entire address space */
17144 + if (len > pax_task_size)
17145 + return -ENOMEM;
17146 +
17147 + if (flags & MAP_FIXED)
17148 + return addr;
17149 +
17150 +#ifdef CONFIG_PAX_PAGEEXEC
17151 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
17152 + goto bottomup;
17153 +#endif
17154 +
17155 +#ifdef CONFIG_PAX_RANDMMAP
17156 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17157 +#endif
17158 +
17159 + /* requesting a specific address */
17160 + if (addr) {
17161 + addr = PAGE_ALIGN(addr);
17162 + if (pax_task_size - len >= addr) {
17163 + vma = find_vma(mm, addr);
17164 + if (check_heap_stack_gap(vma, addr, len))
17165 + return addr;
17166 + }
17167 + }
17168 +
17169 + /* check if free_area_cache is useful for us */
17170 + if (len <= mm->cached_hole_size) {
17171 + mm->cached_hole_size = 0;
17172 + mm->free_area_cache = mm->mmap_base;
17173 + }
17174 +
17175 + /* either no address requested or can't fit in requested address hole */
17176 + addr = mm->free_area_cache;
17177 +
17178 + /* make sure it can fit in the remaining address space */
17179 + if (addr > len) {
17180 + vma = find_vma(mm, addr-len);
17181 + if (check_heap_stack_gap(vma, addr - len, len))
17182 + /* remember the address as a hint for next time */
17183 + return (mm->free_area_cache = addr-len);
17184 + }
17185 +
17186 + if (mm->mmap_base < len)
17187 + goto bottomup;
17188 +
17189 + addr = mm->mmap_base-len;
17190 +
17191 + do {
17192 + /*
17193 + * Lookup failure means no vma is above this address,
17194 + * else if new region fits below vma->vm_start,
17195 + * return with success:
17196 + */
17197 + vma = find_vma(mm, addr);
17198 + if (check_heap_stack_gap(vma, addr, len))
17199 + /* remember the address as a hint for next time */
17200 + return (mm->free_area_cache = addr);
17201 +
17202 + /* remember the largest hole we saw so far */
17203 + if (addr + mm->cached_hole_size < vma->vm_start)
17204 + mm->cached_hole_size = vma->vm_start - addr;
17205 +
17206 + /* try just below the current vma->vm_start */
17207 + addr = skip_heap_stack_gap(vma, len);
17208 + } while (!IS_ERR_VALUE(addr));
17209 +
17210 +bottomup:
17211 + /*
17212 + * A failed mmap() very likely causes application failure,
17213 + * so fall back to the bottom-up function here. This scenario
17214 + * can happen with large stack limits and large mmap()
17215 + * allocations.
17216 + */
17217 +
17218 +#ifdef CONFIG_PAX_SEGMEXEC
17219 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17220 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17221 + else
17222 +#endif
17223 +
17224 + mm->mmap_base = TASK_UNMAPPED_BASE;
17225 +
17226 +#ifdef CONFIG_PAX_RANDMMAP
17227 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17228 + mm->mmap_base += mm->delta_mmap;
17229 +#endif
17230 +
17231 + mm->free_area_cache = mm->mmap_base;
17232 + mm->cached_hole_size = ~0UL;
17233 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17234 + /*
17235 + * Restore the topdown base:
17236 + */
17237 + mm->mmap_base = base;
17238 + mm->free_area_cache = base;
17239 + mm->cached_hole_size = ~0UL;
17240 +
17241 + return addr;
17242 }
17243 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
17244 index 0514890..3dbebce 100644
17245 --- a/arch/x86/kernel/sys_x86_64.c
17246 +++ b/arch/x86/kernel/sys_x86_64.c
17247 @@ -95,8 +95,8 @@ out:
17248 return error;
17249 }
17250
17251 -static void find_start_end(unsigned long flags, unsigned long *begin,
17252 - unsigned long *end)
17253 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
17254 + unsigned long *begin, unsigned long *end)
17255 {
17256 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17257 unsigned long new_begin;
17258 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
17259 *begin = new_begin;
17260 }
17261 } else {
17262 - *begin = TASK_UNMAPPED_BASE;
17263 + *begin = mm->mmap_base;
17264 *end = TASK_SIZE;
17265 }
17266 }
17267 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
17268 if (flags & MAP_FIXED)
17269 return addr;
17270
17271 - find_start_end(flags, &begin, &end);
17272 + find_start_end(mm, flags, &begin, &end);
17273
17274 if (len > end)
17275 return -ENOMEM;
17276
17277 +#ifdef CONFIG_PAX_RANDMMAP
17278 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17279 +#endif
17280 +
17281 if (addr) {
17282 addr = PAGE_ALIGN(addr);
17283 vma = find_vma(mm, addr);
17284 - if (end - len >= addr &&
17285 - (!vma || addr + len <= vma->vm_start))
17286 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17287 return addr;
17288 }
17289 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17290 @@ -172,7 +175,7 @@ full_search:
17291 }
17292 return -ENOMEM;
17293 }
17294 - if (!vma || addr + len <= vma->vm_start) {
17295 + if (check_heap_stack_gap(vma, addr, len)) {
17296 /*
17297 * Remember the place where we stopped the search:
17298 */
17299 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17300 {
17301 struct vm_area_struct *vma;
17302 struct mm_struct *mm = current->mm;
17303 - unsigned long addr = addr0;
17304 + unsigned long base = mm->mmap_base, addr = addr0;
17305
17306 /* requested length too big for entire address space */
17307 if (len > TASK_SIZE)
17308 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17309 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17310 goto bottomup;
17311
17312 +#ifdef CONFIG_PAX_RANDMMAP
17313 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17314 +#endif
17315 +
17316 /* requesting a specific address */
17317 if (addr) {
17318 addr = PAGE_ALIGN(addr);
17319 - vma = find_vma(mm, addr);
17320 - if (TASK_SIZE - len >= addr &&
17321 - (!vma || addr + len <= vma->vm_start))
17322 - return addr;
17323 + if (TASK_SIZE - len >= addr) {
17324 + vma = find_vma(mm, addr);
17325 + if (check_heap_stack_gap(vma, addr, len))
17326 + return addr;
17327 + }
17328 }
17329
17330 /* check if free_area_cache is useful for us */
17331 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17332 ALIGN_TOPDOWN);
17333
17334 vma = find_vma(mm, tmp_addr);
17335 - if (!vma || tmp_addr + len <= vma->vm_start)
17336 + if (check_heap_stack_gap(vma, tmp_addr, len))
17337 /* remember the address as a hint for next time */
17338 return mm->free_area_cache = tmp_addr;
17339 }
17340 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17341 * return with success:
17342 */
17343 vma = find_vma(mm, addr);
17344 - if (!vma || addr+len <= vma->vm_start)
17345 + if (check_heap_stack_gap(vma, addr, len))
17346 /* remember the address as a hint for next time */
17347 return mm->free_area_cache = addr;
17348
17349 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17350 mm->cached_hole_size = vma->vm_start - addr;
17351
17352 /* try just below the current vma->vm_start */
17353 - addr = vma->vm_start-len;
17354 - } while (len < vma->vm_start);
17355 + addr = skip_heap_stack_gap(vma, len);
17356 + } while (!IS_ERR_VALUE(addr));
17357
17358 bottomup:
17359 /*
17360 @@ -270,13 +278,21 @@ bottomup:
17361 * can happen with large stack limits and large mmap()
17362 * allocations.
17363 */
17364 + mm->mmap_base = TASK_UNMAPPED_BASE;
17365 +
17366 +#ifdef CONFIG_PAX_RANDMMAP
17367 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17368 + mm->mmap_base += mm->delta_mmap;
17369 +#endif
17370 +
17371 + mm->free_area_cache = mm->mmap_base;
17372 mm->cached_hole_size = ~0UL;
17373 - mm->free_area_cache = TASK_UNMAPPED_BASE;
17374 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17375 /*
17376 * Restore the topdown base:
17377 */
17378 - mm->free_area_cache = mm->mmap_base;
17379 + mm->mmap_base = base;
17380 + mm->free_area_cache = base;
17381 mm->cached_hole_size = ~0UL;
17382
17383 return addr;
17384 diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
17385 index 9a0e312..e6f66f2 100644
17386 --- a/arch/x86/kernel/syscall_table_32.S
17387 +++ b/arch/x86/kernel/syscall_table_32.S
17388 @@ -1,3 +1,4 @@
17389 +.section .rodata,"a",@progbits
17390 ENTRY(sys_call_table)
17391 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
17392 .long sys_exit
17393 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
17394 index e2410e2..4fe3fbc 100644
17395 --- a/arch/x86/kernel/tboot.c
17396 +++ b/arch/x86/kernel/tboot.c
17397 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
17398
17399 void tboot_shutdown(u32 shutdown_type)
17400 {
17401 - void (*shutdown)(void);
17402 + void (* __noreturn shutdown)(void);
17403
17404 if (!tboot_enabled())
17405 return;
17406 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
17407
17408 switch_to_tboot_pt();
17409
17410 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17411 + shutdown = (void *)tboot->shutdown_entry;
17412 shutdown();
17413
17414 /* should not reach here */
17415 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
17416 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17417 }
17418
17419 -static atomic_t ap_wfs_count;
17420 +static atomic_unchecked_t ap_wfs_count;
17421
17422 static int tboot_wait_for_aps(int num_aps)
17423 {
17424 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
17425 {
17426 switch (action) {
17427 case CPU_DYING:
17428 - atomic_inc(&ap_wfs_count);
17429 + atomic_inc_unchecked(&ap_wfs_count);
17430 if (num_online_cpus() == 1)
17431 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17432 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17433 return NOTIFY_BAD;
17434 break;
17435 }
17436 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
17437
17438 tboot_create_trampoline();
17439
17440 - atomic_set(&ap_wfs_count, 0);
17441 + atomic_set_unchecked(&ap_wfs_count, 0);
17442 register_hotcpu_notifier(&tboot_cpu_notifier);
17443 return 0;
17444 }
17445 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
17446 index dd5fbf4..b7f2232 100644
17447 --- a/arch/x86/kernel/time.c
17448 +++ b/arch/x86/kernel/time.c
17449 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
17450 {
17451 unsigned long pc = instruction_pointer(regs);
17452
17453 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17454 + if (!user_mode(regs) && in_lock_functions(pc)) {
17455 #ifdef CONFIG_FRAME_POINTER
17456 - return *(unsigned long *)(regs->bp + sizeof(long));
17457 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17458 #else
17459 unsigned long *sp =
17460 (unsigned long *)kernel_stack_pointer(regs);
17461 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
17462 * or above a saved flags. Eflags has bits 22-31 zero,
17463 * kernel addresses don't.
17464 */
17465 +
17466 +#ifdef CONFIG_PAX_KERNEXEC
17467 + return ktla_ktva(sp[0]);
17468 +#else
17469 if (sp[0] >> 22)
17470 return sp[0];
17471 if (sp[1] >> 22)
17472 return sp[1];
17473 #endif
17474 +
17475 +#endif
17476 }
17477 return pc;
17478 }
17479 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
17480 index 6bb7b85..dd853e1 100644
17481 --- a/arch/x86/kernel/tls.c
17482 +++ b/arch/x86/kernel/tls.c
17483 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
17484 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17485 return -EINVAL;
17486
17487 +#ifdef CONFIG_PAX_SEGMEXEC
17488 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17489 + return -EINVAL;
17490 +#endif
17491 +
17492 set_tls_desc(p, idx, &info, 1);
17493
17494 return 0;
17495 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
17496 index 451c0a7..e57f551 100644
17497 --- a/arch/x86/kernel/trampoline_32.S
17498 +++ b/arch/x86/kernel/trampoline_32.S
17499 @@ -32,6 +32,12 @@
17500 #include <asm/segment.h>
17501 #include <asm/page_types.h>
17502
17503 +#ifdef CONFIG_PAX_KERNEXEC
17504 +#define ta(X) (X)
17505 +#else
17506 +#define ta(X) ((X) - __PAGE_OFFSET)
17507 +#endif
17508 +
17509 #ifdef CONFIG_SMP
17510
17511 .section ".x86_trampoline","a"
17512 @@ -62,7 +68,7 @@ r_base = .
17513 inc %ax # protected mode (PE) bit
17514 lmsw %ax # into protected mode
17515 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17516 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17517 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
17518
17519 # These need to be in the same 64K segment as the above;
17520 # hence we don't use the boot_gdt_descr defined in head.S
17521 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
17522 index 09ff517..df19fbff 100644
17523 --- a/arch/x86/kernel/trampoline_64.S
17524 +++ b/arch/x86/kernel/trampoline_64.S
17525 @@ -90,7 +90,7 @@ startup_32:
17526 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17527 movl %eax, %ds
17528
17529 - movl $X86_CR4_PAE, %eax
17530 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17531 movl %eax, %cr4 # Enable PAE mode
17532
17533 # Setup trampoline 4 level pagetables
17534 @@ -138,7 +138,7 @@ tidt:
17535 # so the kernel can live anywhere
17536 .balign 4
17537 tgdt:
17538 - .short tgdt_end - tgdt # gdt limit
17539 + .short tgdt_end - tgdt - 1 # gdt limit
17540 .long tgdt - r_base
17541 .short 0
17542 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17543 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
17544 index a8e3eb8..c9dbd7d 100644
17545 --- a/arch/x86/kernel/traps.c
17546 +++ b/arch/x86/kernel/traps.c
17547 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
17548
17549 /* Do we ignore FPU interrupts ? */
17550 char ignore_fpu_irq;
17551 -
17552 -/*
17553 - * The IDT has to be page-aligned to simplify the Pentium
17554 - * F0 0F bug workaround.
17555 - */
17556 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17557 #endif
17558
17559 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17560 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
17561 }
17562
17563 static void __kprobes
17564 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17565 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17566 long error_code, siginfo_t *info)
17567 {
17568 struct task_struct *tsk = current;
17569
17570 #ifdef CONFIG_X86_32
17571 - if (regs->flags & X86_VM_MASK) {
17572 + if (v8086_mode(regs)) {
17573 /*
17574 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17575 * On nmi (interrupt 2), do_trap should not be called.
17576 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17577 }
17578 #endif
17579
17580 - if (!user_mode(regs))
17581 + if (!user_mode_novm(regs))
17582 goto kernel_trap;
17583
17584 #ifdef CONFIG_X86_32
17585 @@ -148,7 +142,7 @@ trap_signal:
17586 printk_ratelimit()) {
17587 printk(KERN_INFO
17588 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17589 - tsk->comm, tsk->pid, str,
17590 + tsk->comm, task_pid_nr(tsk), str,
17591 regs->ip, regs->sp, error_code);
17592 print_vma_addr(" in ", regs->ip);
17593 printk("\n");
17594 @@ -165,8 +159,20 @@ kernel_trap:
17595 if (!fixup_exception(regs)) {
17596 tsk->thread.error_code = error_code;
17597 tsk->thread.trap_no = trapnr;
17598 +
17599 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17600 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17601 + str = "PAX: suspicious stack segment fault";
17602 +#endif
17603 +
17604 die(str, regs, error_code);
17605 }
17606 +
17607 +#ifdef CONFIG_PAX_REFCOUNT
17608 + if (trapnr == 4)
17609 + pax_report_refcount_overflow(regs);
17610 +#endif
17611 +
17612 return;
17613
17614 #ifdef CONFIG_X86_32
17615 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
17616 conditional_sti(regs);
17617
17618 #ifdef CONFIG_X86_32
17619 - if (regs->flags & X86_VM_MASK)
17620 + if (v8086_mode(regs))
17621 goto gp_in_vm86;
17622 #endif
17623
17624 tsk = current;
17625 - if (!user_mode(regs))
17626 + if (!user_mode_novm(regs))
17627 goto gp_in_kernel;
17628
17629 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17630 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17631 + struct mm_struct *mm = tsk->mm;
17632 + unsigned long limit;
17633 +
17634 + down_write(&mm->mmap_sem);
17635 + limit = mm->context.user_cs_limit;
17636 + if (limit < TASK_SIZE) {
17637 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17638 + up_write(&mm->mmap_sem);
17639 + return;
17640 + }
17641 + up_write(&mm->mmap_sem);
17642 + }
17643 +#endif
17644 +
17645 tsk->thread.error_code = error_code;
17646 tsk->thread.trap_no = 13;
17647
17648 @@ -295,6 +317,13 @@ gp_in_kernel:
17649 if (notify_die(DIE_GPF, "general protection fault", regs,
17650 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17651 return;
17652 +
17653 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17654 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
17655 + die("PAX: suspicious general protection fault", regs, error_code);
17656 + else
17657 +#endif
17658 +
17659 die("general protection fault", regs, error_code);
17660 }
17661
17662 @@ -414,7 +443,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
17663 /* It's safe to allow irq's after DR6 has been saved */
17664 preempt_conditional_sti(regs);
17665
17666 - if (regs->flags & X86_VM_MASK) {
17667 + if (v8086_mode(regs)) {
17668 handle_vm86_trap((struct kernel_vm86_regs *) regs,
17669 error_code, 1);
17670 preempt_conditional_cli(regs);
17671 @@ -428,7 +457,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
17672 * We already checked v86 mode above, so we can check for kernel mode
17673 * by just checking the CPL of CS.
17674 */
17675 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
17676 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
17677 tsk->thread.debugreg6 &= ~DR_STEP;
17678 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
17679 regs->flags &= ~X86_EFLAGS_TF;
17680 @@ -457,7 +486,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
17681 return;
17682 conditional_sti(regs);
17683
17684 - if (!user_mode_vm(regs))
17685 + if (!user_mode(regs))
17686 {
17687 if (!fixup_exception(regs)) {
17688 task->thread.error_code = error_code;
17689 @@ -568,7 +597,7 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
17690 void __math_state_restore(void)
17691 {
17692 struct thread_info *thread = current_thread_info();
17693 - struct task_struct *tsk = thread->task;
17694 + struct task_struct *tsk = current;
17695
17696 /*
17697 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
17698 @@ -595,8 +624,7 @@ void __math_state_restore(void)
17699 */
17700 asmlinkage void math_state_restore(void)
17701 {
17702 - struct thread_info *thread = current_thread_info();
17703 - struct task_struct *tsk = thread->task;
17704 + struct task_struct *tsk = current;
17705
17706 if (!tsk_used_math(tsk)) {
17707 local_irq_enable();
17708 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
17709 index b9242ba..50c5edd 100644
17710 --- a/arch/x86/kernel/verify_cpu.S
17711 +++ b/arch/x86/kernel/verify_cpu.S
17712 @@ -20,6 +20,7 @@
17713 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
17714 * arch/x86/kernel/trampoline_64.S: secondary processor verification
17715 * arch/x86/kernel/head_32.S: processor startup
17716 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
17717 *
17718 * verify_cpu, returns the status of longmode and SSE in register %eax.
17719 * 0: Success 1: Failure
17720 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
17721 index 863f875..4307295 100644
17722 --- a/arch/x86/kernel/vm86_32.c
17723 +++ b/arch/x86/kernel/vm86_32.c
17724 @@ -41,6 +41,7 @@
17725 #include <linux/ptrace.h>
17726 #include <linux/audit.h>
17727 #include <linux/stddef.h>
17728 +#include <linux/grsecurity.h>
17729
17730 #include <asm/uaccess.h>
17731 #include <asm/io.h>
17732 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
17733 do_exit(SIGSEGV);
17734 }
17735
17736 - tss = &per_cpu(init_tss, get_cpu());
17737 + tss = init_tss + get_cpu();
17738 current->thread.sp0 = current->thread.saved_sp0;
17739 current->thread.sysenter_cs = __KERNEL_CS;
17740 load_sp0(tss, &current->thread);
17741 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
17742 struct task_struct *tsk;
17743 int tmp, ret = -EPERM;
17744
17745 +#ifdef CONFIG_GRKERNSEC_VM86
17746 + if (!capable(CAP_SYS_RAWIO)) {
17747 + gr_handle_vm86();
17748 + goto out;
17749 + }
17750 +#endif
17751 +
17752 tsk = current;
17753 if (tsk->thread.saved_sp0)
17754 goto out;
17755 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
17756 int tmp, ret;
17757 struct vm86plus_struct __user *v86;
17758
17759 +#ifdef CONFIG_GRKERNSEC_VM86
17760 + if (!capable(CAP_SYS_RAWIO)) {
17761 + gr_handle_vm86();
17762 + ret = -EPERM;
17763 + goto out;
17764 + }
17765 +#endif
17766 +
17767 tsk = current;
17768 switch (cmd) {
17769 case VM86_REQUEST_IRQ:
17770 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
17771 tsk->thread.saved_fs = info->regs32->fs;
17772 tsk->thread.saved_gs = get_user_gs(info->regs32);
17773
17774 - tss = &per_cpu(init_tss, get_cpu());
17775 + tss = init_tss + get_cpu();
17776 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
17777 if (cpu_has_sep)
17778 tsk->thread.sysenter_cs = 0;
17779 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
17780 goto cannot_handle;
17781 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
17782 goto cannot_handle;
17783 - intr_ptr = (unsigned long __user *) (i << 2);
17784 + intr_ptr = (__force unsigned long __user *) (i << 2);
17785 if (get_user(segoffs, intr_ptr))
17786 goto cannot_handle;
17787 if ((segoffs >> 16) == BIOSSEG)
17788 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
17789 index 0f703f1..9e15f64 100644
17790 --- a/arch/x86/kernel/vmlinux.lds.S
17791 +++ b/arch/x86/kernel/vmlinux.lds.S
17792 @@ -26,6 +26,13 @@
17793 #include <asm/page_types.h>
17794 #include <asm/cache.h>
17795 #include <asm/boot.h>
17796 +#include <asm/segment.h>
17797 +
17798 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17799 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
17800 +#else
17801 +#define __KERNEL_TEXT_OFFSET 0
17802 +#endif
17803
17804 #undef i386 /* in case the preprocessor is a 32bit one */
17805
17806 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
17807
17808 PHDRS {
17809 text PT_LOAD FLAGS(5); /* R_E */
17810 +#ifdef CONFIG_X86_32
17811 + module PT_LOAD FLAGS(5); /* R_E */
17812 +#endif
17813 +#ifdef CONFIG_XEN
17814 + rodata PT_LOAD FLAGS(5); /* R_E */
17815 +#else
17816 + rodata PT_LOAD FLAGS(4); /* R__ */
17817 +#endif
17818 data PT_LOAD FLAGS(6); /* RW_ */
17819 -#ifdef CONFIG_X86_64
17820 + init.begin PT_LOAD FLAGS(6); /* RW_ */
17821 #ifdef CONFIG_SMP
17822 percpu PT_LOAD FLAGS(6); /* RW_ */
17823 #endif
17824 + text.init PT_LOAD FLAGS(5); /* R_E */
17825 + text.exit PT_LOAD FLAGS(5); /* R_E */
17826 init PT_LOAD FLAGS(7); /* RWE */
17827 -#endif
17828 note PT_NOTE FLAGS(0); /* ___ */
17829 }
17830
17831 SECTIONS
17832 {
17833 #ifdef CONFIG_X86_32
17834 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
17835 - phys_startup_32 = startup_32 - LOAD_OFFSET;
17836 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
17837 #else
17838 - . = __START_KERNEL;
17839 - phys_startup_64 = startup_64 - LOAD_OFFSET;
17840 + . = __START_KERNEL;
17841 #endif
17842
17843 /* Text and read-only data */
17844 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
17845 - _text = .;
17846 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
17847 /* bootstrapping code */
17848 +#ifdef CONFIG_X86_32
17849 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17850 +#else
17851 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17852 +#endif
17853 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17854 + _text = .;
17855 HEAD_TEXT
17856 #ifdef CONFIG_X86_32
17857 . = ALIGN(PAGE_SIZE);
17858 @@ -108,13 +128,47 @@ SECTIONS
17859 IRQENTRY_TEXT
17860 *(.fixup)
17861 *(.gnu.warning)
17862 - /* End of text section */
17863 - _etext = .;
17864 } :text = 0x9090
17865
17866 - NOTES :text :note
17867 + . += __KERNEL_TEXT_OFFSET;
17868
17869 - EXCEPTION_TABLE(16) :text = 0x9090
17870 +#ifdef CONFIG_X86_32
17871 + . = ALIGN(PAGE_SIZE);
17872 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
17873 +
17874 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
17875 + MODULES_EXEC_VADDR = .;
17876 + BYTE(0)
17877 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
17878 + . = ALIGN(HPAGE_SIZE);
17879 + MODULES_EXEC_END = . - 1;
17880 +#endif
17881 +
17882 + } :module
17883 +#endif
17884 +
17885 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
17886 + /* End of text section */
17887 + _etext = . - __KERNEL_TEXT_OFFSET;
17888 + }
17889 +
17890 +#ifdef CONFIG_X86_32
17891 + . = ALIGN(PAGE_SIZE);
17892 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
17893 + *(.idt)
17894 + . = ALIGN(PAGE_SIZE);
17895 + *(.empty_zero_page)
17896 + *(.initial_pg_fixmap)
17897 + *(.initial_pg_pmd)
17898 + *(.initial_page_table)
17899 + *(.swapper_pg_dir)
17900 + } :rodata
17901 +#endif
17902 +
17903 + . = ALIGN(PAGE_SIZE);
17904 + NOTES :rodata :note
17905 +
17906 + EXCEPTION_TABLE(16) :rodata
17907
17908 #if defined(CONFIG_DEBUG_RODATA)
17909 /* .text should occupy whole number of pages */
17910 @@ -126,16 +180,20 @@ SECTIONS
17911
17912 /* Data */
17913 .data : AT(ADDR(.data) - LOAD_OFFSET) {
17914 +
17915 +#ifdef CONFIG_PAX_KERNEXEC
17916 + . = ALIGN(HPAGE_SIZE);
17917 +#else
17918 + . = ALIGN(PAGE_SIZE);
17919 +#endif
17920 +
17921 /* Start of data section */
17922 _sdata = .;
17923
17924 /* init_task */
17925 INIT_TASK_DATA(THREAD_SIZE)
17926
17927 -#ifdef CONFIG_X86_32
17928 - /* 32 bit has nosave before _edata */
17929 NOSAVE_DATA
17930 -#endif
17931
17932 PAGE_ALIGNED_DATA(PAGE_SIZE)
17933
17934 @@ -176,12 +234,19 @@ SECTIONS
17935 #endif /* CONFIG_X86_64 */
17936
17937 /* Init code and data - will be freed after init */
17938 - . = ALIGN(PAGE_SIZE);
17939 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
17940 + BYTE(0)
17941 +
17942 +#ifdef CONFIG_PAX_KERNEXEC
17943 + . = ALIGN(HPAGE_SIZE);
17944 +#else
17945 + . = ALIGN(PAGE_SIZE);
17946 +#endif
17947 +
17948 __init_begin = .; /* paired with __init_end */
17949 - }
17950 + } :init.begin
17951
17952 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
17953 +#ifdef CONFIG_SMP
17954 /*
17955 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
17956 * output PHDR, so the next output section - .init.text - should
17957 @@ -190,12 +255,27 @@ SECTIONS
17958 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
17959 #endif
17960
17961 - INIT_TEXT_SECTION(PAGE_SIZE)
17962 -#ifdef CONFIG_X86_64
17963 - :init
17964 -#endif
17965 + . = ALIGN(PAGE_SIZE);
17966 + init_begin = .;
17967 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
17968 + VMLINUX_SYMBOL(_sinittext) = .;
17969 + INIT_TEXT
17970 + VMLINUX_SYMBOL(_einittext) = .;
17971 + . = ALIGN(PAGE_SIZE);
17972 + } :text.init
17973
17974 - INIT_DATA_SECTION(16)
17975 + /*
17976 + * .exit.text is discard at runtime, not link time, to deal with
17977 + * references from .altinstructions and .eh_frame
17978 + */
17979 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
17980 + EXIT_TEXT
17981 + . = ALIGN(16);
17982 + } :text.exit
17983 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
17984 +
17985 + . = ALIGN(PAGE_SIZE);
17986 + INIT_DATA_SECTION(16) :init
17987
17988 /*
17989 * Code and data for a variety of lowlevel trampolines, to be
17990 @@ -269,19 +349,12 @@ SECTIONS
17991 }
17992
17993 . = ALIGN(8);
17994 - /*
17995 - * .exit.text is discard at runtime, not link time, to deal with
17996 - * references from .altinstructions and .eh_frame
17997 - */
17998 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
17999 - EXIT_TEXT
18000 - }
18001
18002 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18003 EXIT_DATA
18004 }
18005
18006 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18007 +#ifndef CONFIG_SMP
18008 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
18009 #endif
18010
18011 @@ -300,16 +373,10 @@ SECTIONS
18012 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
18013 __smp_locks = .;
18014 *(.smp_locks)
18015 - . = ALIGN(PAGE_SIZE);
18016 __smp_locks_end = .;
18017 + . = ALIGN(PAGE_SIZE);
18018 }
18019
18020 -#ifdef CONFIG_X86_64
18021 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18022 - NOSAVE_DATA
18023 - }
18024 -#endif
18025 -
18026 /* BSS */
18027 . = ALIGN(PAGE_SIZE);
18028 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18029 @@ -325,6 +392,7 @@ SECTIONS
18030 __brk_base = .;
18031 . += 64 * 1024; /* 64k alignment slop space */
18032 *(.brk_reservation) /* areas brk users have reserved */
18033 + . = ALIGN(HPAGE_SIZE);
18034 __brk_limit = .;
18035 }
18036
18037 @@ -351,13 +419,12 @@ SECTIONS
18038 * for the boot processor.
18039 */
18040 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
18041 -INIT_PER_CPU(gdt_page);
18042 INIT_PER_CPU(irq_stack_union);
18043
18044 /*
18045 * Build-time check on the image size:
18046 */
18047 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18048 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18049 "kernel image bigger than KERNEL_IMAGE_SIZE");
18050
18051 #ifdef CONFIG_SMP
18052 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
18053 index e4d4a22..47ee71f 100644
18054 --- a/arch/x86/kernel/vsyscall_64.c
18055 +++ b/arch/x86/kernel/vsyscall_64.c
18056 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
18057 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
18058 };
18059
18060 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = NATIVE;
18061 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
18062
18063 static int __init vsyscall_setup(char *str)
18064 {
18065 if (str) {
18066 if (!strcmp("emulate", str))
18067 vsyscall_mode = EMULATE;
18068 - else if (!strcmp("native", str))
18069 - vsyscall_mode = NATIVE;
18070 else if (!strcmp("none", str))
18071 vsyscall_mode = NONE;
18072 else
18073 @@ -178,7 +176,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18074
18075 tsk = current;
18076 if (seccomp_mode(&tsk->seccomp))
18077 - do_exit(SIGKILL);
18078 + do_group_exit(SIGKILL);
18079
18080 switch (vsyscall_nr) {
18081 case 0:
18082 @@ -220,8 +218,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18083 return true;
18084
18085 sigsegv:
18086 - force_sig(SIGSEGV, current);
18087 - return true;
18088 + do_group_exit(SIGKILL);
18089 }
18090
18091 /*
18092 @@ -274,10 +271,7 @@ void __init map_vsyscall(void)
18093 extern char __vvar_page;
18094 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
18095
18096 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
18097 - vsyscall_mode == NATIVE
18098 - ? PAGE_KERNEL_VSYSCALL
18099 - : PAGE_KERNEL_VVAR);
18100 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
18101 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
18102 (unsigned long)VSYSCALL_START);
18103
18104 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
18105 index 9796c2f..f686fbf 100644
18106 --- a/arch/x86/kernel/x8664_ksyms_64.c
18107 +++ b/arch/x86/kernel/x8664_ksyms_64.c
18108 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
18109 EXPORT_SYMBOL(copy_user_generic_string);
18110 EXPORT_SYMBOL(copy_user_generic_unrolled);
18111 EXPORT_SYMBOL(__copy_user_nocache);
18112 -EXPORT_SYMBOL(_copy_from_user);
18113 -EXPORT_SYMBOL(_copy_to_user);
18114
18115 EXPORT_SYMBOL(copy_page);
18116 EXPORT_SYMBOL(clear_page);
18117 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
18118 index a391134..d0b63b6e 100644
18119 --- a/arch/x86/kernel/xsave.c
18120 +++ b/arch/x86/kernel/xsave.c
18121 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
18122 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18123 return -EINVAL;
18124
18125 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18126 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18127 fx_sw_user->extended_size -
18128 FP_XSTATE_MAGIC2_SIZE));
18129 if (err)
18130 @@ -267,7 +267,7 @@ fx_only:
18131 * the other extended state.
18132 */
18133 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18134 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18135 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
18136 }
18137
18138 /*
18139 @@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf)
18140 if (use_xsave())
18141 err = restore_user_xstate(buf);
18142 else
18143 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
18144 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
18145 buf);
18146 if (unlikely(err)) {
18147 /*
18148 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
18149 index f1e3be1..588efc8 100644
18150 --- a/arch/x86/kvm/emulate.c
18151 +++ b/arch/x86/kvm/emulate.c
18152 @@ -249,6 +249,7 @@ struct gprefix {
18153
18154 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
18155 do { \
18156 + unsigned long _tmp; \
18157 __asm__ __volatile__ ( \
18158 _PRE_EFLAGS("0", "4", "2") \
18159 _op _suffix " %"_x"3,%1; " \
18160 @@ -263,8 +264,6 @@ struct gprefix {
18161 /* Raw emulation: instruction has two explicit operands. */
18162 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
18163 do { \
18164 - unsigned long _tmp; \
18165 - \
18166 switch ((ctxt)->dst.bytes) { \
18167 case 2: \
18168 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
18169 @@ -280,7 +279,6 @@ struct gprefix {
18170
18171 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18172 do { \
18173 - unsigned long _tmp; \
18174 switch ((ctxt)->dst.bytes) { \
18175 case 1: \
18176 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
18177 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
18178 index 54abb40..a192606 100644
18179 --- a/arch/x86/kvm/lapic.c
18180 +++ b/arch/x86/kvm/lapic.c
18181 @@ -53,7 +53,7 @@
18182 #define APIC_BUS_CYCLE_NS 1
18183
18184 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18185 -#define apic_debug(fmt, arg...)
18186 +#define apic_debug(fmt, arg...) do {} while (0)
18187
18188 #define APIC_LVT_NUM 6
18189 /* 14 is the version for Xeon and Pentium 8.4.8*/
18190 diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
18191 index f1b36cf..af8a124 100644
18192 --- a/arch/x86/kvm/mmu.c
18193 +++ b/arch/x86/kvm/mmu.c
18194 @@ -3555,7 +3555,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
18195
18196 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
18197
18198 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
18199 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
18200
18201 /*
18202 * Assume that the pte write on a page table of the same type
18203 @@ -3587,7 +3587,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
18204 }
18205
18206 spin_lock(&vcpu->kvm->mmu_lock);
18207 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18208 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18209 gentry = 0;
18210 kvm_mmu_free_some_pages(vcpu);
18211 ++vcpu->kvm->stat.mmu_pte_write;
18212 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
18213 index 9299410..ade2f9b 100644
18214 --- a/arch/x86/kvm/paging_tmpl.h
18215 +++ b/arch/x86/kvm/paging_tmpl.h
18216 @@ -197,7 +197,7 @@ retry_walk:
18217 if (unlikely(kvm_is_error_hva(host_addr)))
18218 goto error;
18219
18220 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
18221 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
18222 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
18223 goto error;
18224
18225 @@ -705,7 +705,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
18226 if (need_flush)
18227 kvm_flush_remote_tlbs(vcpu->kvm);
18228
18229 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
18230 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
18231
18232 spin_unlock(&vcpu->kvm->mmu_lock);
18233
18234 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
18235 index e32243e..a6e6172 100644
18236 --- a/arch/x86/kvm/svm.c
18237 +++ b/arch/x86/kvm/svm.c
18238 @@ -3400,7 +3400,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
18239 int cpu = raw_smp_processor_id();
18240
18241 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
18242 +
18243 + pax_open_kernel();
18244 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
18245 + pax_close_kernel();
18246 +
18247 load_TR_desc();
18248 }
18249
18250 @@ -3778,6 +3782,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
18251 #endif
18252 #endif
18253
18254 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18255 + __set_fs(current_thread_info()->addr_limit);
18256 +#endif
18257 +
18258 reload_tss(vcpu);
18259
18260 local_irq_disable();
18261 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
18262 index 579a0b5..ed7bbf9 100644
18263 --- a/arch/x86/kvm/vmx.c
18264 +++ b/arch/x86/kvm/vmx.c
18265 @@ -1305,7 +1305,11 @@ static void reload_tss(void)
18266 struct desc_struct *descs;
18267
18268 descs = (void *)gdt->address;
18269 +
18270 + pax_open_kernel();
18271 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18272 + pax_close_kernel();
18273 +
18274 load_TR_desc();
18275 }
18276
18277 @@ -2633,8 +2637,11 @@ static __init int hardware_setup(void)
18278 if (!cpu_has_vmx_flexpriority())
18279 flexpriority_enabled = 0;
18280
18281 - if (!cpu_has_vmx_tpr_shadow())
18282 - kvm_x86_ops->update_cr8_intercept = NULL;
18283 + if (!cpu_has_vmx_tpr_shadow()) {
18284 + pax_open_kernel();
18285 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18286 + pax_close_kernel();
18287 + }
18288
18289 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18290 kvm_disable_largepages();
18291 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
18292 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
18293
18294 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
18295 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
18296 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
18297
18298 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
18299 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
18300 @@ -6169,6 +6176,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18301 "jmp .Lkvm_vmx_return \n\t"
18302 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18303 ".Lkvm_vmx_return: "
18304 +
18305 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18306 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18307 + ".Lkvm_vmx_return2: "
18308 +#endif
18309 +
18310 /* Save guest registers, load host registers, keep flags */
18311 "mov %0, %c[wordsize](%%"R"sp) \n\t"
18312 "pop %0 \n\t"
18313 @@ -6217,6 +6230,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18314 #endif
18315 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
18316 [wordsize]"i"(sizeof(ulong))
18317 +
18318 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18319 + ,[cs]"i"(__KERNEL_CS)
18320 +#endif
18321 +
18322 : "cc", "memory"
18323 , R"ax", R"bx", R"di", R"si"
18324 #ifdef CONFIG_X86_64
18325 @@ -6245,7 +6263,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18326 }
18327 }
18328
18329 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18330 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18331 +
18332 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18333 + loadsegment(fs, __KERNEL_PERCPU);
18334 +#endif
18335 +
18336 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18337 + __set_fs(current_thread_info()->addr_limit);
18338 +#endif
18339 +
18340 vmx->loaded_vmcs->launched = 1;
18341
18342 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
18343 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
18344 index 4c938da..4ddef65 100644
18345 --- a/arch/x86/kvm/x86.c
18346 +++ b/arch/x86/kvm/x86.c
18347 @@ -1345,8 +1345,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
18348 {
18349 struct kvm *kvm = vcpu->kvm;
18350 int lm = is_long_mode(vcpu);
18351 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
18352 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
18353 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
18354 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
18355 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
18356 : kvm->arch.xen_hvm_config.blob_size_32;
18357 u32 page_num = data & ~PAGE_MASK;
18358 @@ -2165,6 +2165,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
18359 if (n < msr_list.nmsrs)
18360 goto out;
18361 r = -EFAULT;
18362 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
18363 + goto out;
18364 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
18365 num_msrs_to_save * sizeof(u32)))
18366 goto out;
18367 @@ -2340,15 +2342,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
18368 struct kvm_cpuid2 *cpuid,
18369 struct kvm_cpuid_entry2 __user *entries)
18370 {
18371 - int r;
18372 + int r, i;
18373
18374 r = -E2BIG;
18375 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18376 goto out;
18377 r = -EFAULT;
18378 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18379 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18380 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18381 goto out;
18382 + for (i = 0; i < cpuid->nent; ++i) {
18383 + struct kvm_cpuid_entry2 cpuid_entry;
18384 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18385 + goto out;
18386 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
18387 + }
18388 vcpu->arch.cpuid_nent = cpuid->nent;
18389 kvm_apic_set_version(vcpu);
18390 kvm_x86_ops->cpuid_update(vcpu);
18391 @@ -2363,15 +2370,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
18392 struct kvm_cpuid2 *cpuid,
18393 struct kvm_cpuid_entry2 __user *entries)
18394 {
18395 - int r;
18396 + int r, i;
18397
18398 r = -E2BIG;
18399 if (cpuid->nent < vcpu->arch.cpuid_nent)
18400 goto out;
18401 r = -EFAULT;
18402 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18403 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18404 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18405 goto out;
18406 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18407 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18408 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18409 + goto out;
18410 + }
18411 return 0;
18412
18413 out:
18414 @@ -2746,7 +2757,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
18415 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18416 struct kvm_interrupt *irq)
18417 {
18418 - if (irq->irq < 0 || irq->irq >= 256)
18419 + if (irq->irq >= 256)
18420 return -EINVAL;
18421 if (irqchip_in_kernel(vcpu->kvm))
18422 return -ENXIO;
18423 @@ -5162,7 +5173,7 @@ static void kvm_set_mmio_spte_mask(void)
18424 kvm_mmu_set_mmio_spte_mask(mask);
18425 }
18426
18427 -int kvm_arch_init(void *opaque)
18428 +int kvm_arch_init(const void *opaque)
18429 {
18430 int r;
18431 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18432 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
18433 index cf4603b..7cdde38 100644
18434 --- a/arch/x86/lguest/boot.c
18435 +++ b/arch/x86/lguest/boot.c
18436 @@ -1195,9 +1195,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
18437 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
18438 * Launcher to reboot us.
18439 */
18440 -static void lguest_restart(char *reason)
18441 +static __noreturn void lguest_restart(char *reason)
18442 {
18443 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
18444 + BUG();
18445 }
18446
18447 /*G:050
18448 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
18449 index 042f682..c92afb6 100644
18450 --- a/arch/x86/lib/atomic64_32.c
18451 +++ b/arch/x86/lib/atomic64_32.c
18452 @@ -8,18 +8,30 @@
18453
18454 long long atomic64_read_cx8(long long, const atomic64_t *v);
18455 EXPORT_SYMBOL(atomic64_read_cx8);
18456 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18457 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
18458 long long atomic64_set_cx8(long long, const atomic64_t *v);
18459 EXPORT_SYMBOL(atomic64_set_cx8);
18460 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18461 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
18462 long long atomic64_xchg_cx8(long long, unsigned high);
18463 EXPORT_SYMBOL(atomic64_xchg_cx8);
18464 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
18465 EXPORT_SYMBOL(atomic64_add_return_cx8);
18466 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18467 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
18468 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
18469 EXPORT_SYMBOL(atomic64_sub_return_cx8);
18470 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18471 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
18472 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
18473 EXPORT_SYMBOL(atomic64_inc_return_cx8);
18474 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18475 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
18476 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
18477 EXPORT_SYMBOL(atomic64_dec_return_cx8);
18478 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18479 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
18480 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
18481 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
18482 int atomic64_inc_not_zero_cx8(atomic64_t *v);
18483 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
18484 #ifndef CONFIG_X86_CMPXCHG64
18485 long long atomic64_read_386(long long, const atomic64_t *v);
18486 EXPORT_SYMBOL(atomic64_read_386);
18487 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
18488 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
18489 long long atomic64_set_386(long long, const atomic64_t *v);
18490 EXPORT_SYMBOL(atomic64_set_386);
18491 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
18492 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
18493 long long atomic64_xchg_386(long long, unsigned high);
18494 EXPORT_SYMBOL(atomic64_xchg_386);
18495 long long atomic64_add_return_386(long long a, atomic64_t *v);
18496 EXPORT_SYMBOL(atomic64_add_return_386);
18497 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18498 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
18499 long long atomic64_sub_return_386(long long a, atomic64_t *v);
18500 EXPORT_SYMBOL(atomic64_sub_return_386);
18501 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18502 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
18503 long long atomic64_inc_return_386(long long a, atomic64_t *v);
18504 EXPORT_SYMBOL(atomic64_inc_return_386);
18505 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18506 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
18507 long long atomic64_dec_return_386(long long a, atomic64_t *v);
18508 EXPORT_SYMBOL(atomic64_dec_return_386);
18509 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18510 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
18511 long long atomic64_add_386(long long a, atomic64_t *v);
18512 EXPORT_SYMBOL(atomic64_add_386);
18513 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
18514 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
18515 long long atomic64_sub_386(long long a, atomic64_t *v);
18516 EXPORT_SYMBOL(atomic64_sub_386);
18517 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
18518 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
18519 long long atomic64_inc_386(long long a, atomic64_t *v);
18520 EXPORT_SYMBOL(atomic64_inc_386);
18521 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
18522 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
18523 long long atomic64_dec_386(long long a, atomic64_t *v);
18524 EXPORT_SYMBOL(atomic64_dec_386);
18525 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
18526 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
18527 long long atomic64_dec_if_positive_386(atomic64_t *v);
18528 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
18529 int atomic64_inc_not_zero_386(atomic64_t *v);
18530 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
18531 index e8e7e0d..56fd1b0 100644
18532 --- a/arch/x86/lib/atomic64_386_32.S
18533 +++ b/arch/x86/lib/atomic64_386_32.S
18534 @@ -48,6 +48,10 @@ BEGIN(read)
18535 movl (v), %eax
18536 movl 4(v), %edx
18537 RET_ENDP
18538 +BEGIN(read_unchecked)
18539 + movl (v), %eax
18540 + movl 4(v), %edx
18541 +RET_ENDP
18542 #undef v
18543
18544 #define v %esi
18545 @@ -55,6 +59,10 @@ BEGIN(set)
18546 movl %ebx, (v)
18547 movl %ecx, 4(v)
18548 RET_ENDP
18549 +BEGIN(set_unchecked)
18550 + movl %ebx, (v)
18551 + movl %ecx, 4(v)
18552 +RET_ENDP
18553 #undef v
18554
18555 #define v %esi
18556 @@ -70,6 +78,20 @@ RET_ENDP
18557 BEGIN(add)
18558 addl %eax, (v)
18559 adcl %edx, 4(v)
18560 +
18561 +#ifdef CONFIG_PAX_REFCOUNT
18562 + jno 0f
18563 + subl %eax, (v)
18564 + sbbl %edx, 4(v)
18565 + int $4
18566 +0:
18567 + _ASM_EXTABLE(0b, 0b)
18568 +#endif
18569 +
18570 +RET_ENDP
18571 +BEGIN(add_unchecked)
18572 + addl %eax, (v)
18573 + adcl %edx, 4(v)
18574 RET_ENDP
18575 #undef v
18576
18577 @@ -77,6 +99,24 @@ RET_ENDP
18578 BEGIN(add_return)
18579 addl (v), %eax
18580 adcl 4(v), %edx
18581 +
18582 +#ifdef CONFIG_PAX_REFCOUNT
18583 + into
18584 +1234:
18585 + _ASM_EXTABLE(1234b, 2f)
18586 +#endif
18587 +
18588 + movl %eax, (v)
18589 + movl %edx, 4(v)
18590 +
18591 +#ifdef CONFIG_PAX_REFCOUNT
18592 +2:
18593 +#endif
18594 +
18595 +RET_ENDP
18596 +BEGIN(add_return_unchecked)
18597 + addl (v), %eax
18598 + adcl 4(v), %edx
18599 movl %eax, (v)
18600 movl %edx, 4(v)
18601 RET_ENDP
18602 @@ -86,6 +126,20 @@ RET_ENDP
18603 BEGIN(sub)
18604 subl %eax, (v)
18605 sbbl %edx, 4(v)
18606 +
18607 +#ifdef CONFIG_PAX_REFCOUNT
18608 + jno 0f
18609 + addl %eax, (v)
18610 + adcl %edx, 4(v)
18611 + int $4
18612 +0:
18613 + _ASM_EXTABLE(0b, 0b)
18614 +#endif
18615 +
18616 +RET_ENDP
18617 +BEGIN(sub_unchecked)
18618 + subl %eax, (v)
18619 + sbbl %edx, 4(v)
18620 RET_ENDP
18621 #undef v
18622
18623 @@ -96,6 +150,27 @@ BEGIN(sub_return)
18624 sbbl $0, %edx
18625 addl (v), %eax
18626 adcl 4(v), %edx
18627 +
18628 +#ifdef CONFIG_PAX_REFCOUNT
18629 + into
18630 +1234:
18631 + _ASM_EXTABLE(1234b, 2f)
18632 +#endif
18633 +
18634 + movl %eax, (v)
18635 + movl %edx, 4(v)
18636 +
18637 +#ifdef CONFIG_PAX_REFCOUNT
18638 +2:
18639 +#endif
18640 +
18641 +RET_ENDP
18642 +BEGIN(sub_return_unchecked)
18643 + negl %edx
18644 + negl %eax
18645 + sbbl $0, %edx
18646 + addl (v), %eax
18647 + adcl 4(v), %edx
18648 movl %eax, (v)
18649 movl %edx, 4(v)
18650 RET_ENDP
18651 @@ -105,6 +180,20 @@ RET_ENDP
18652 BEGIN(inc)
18653 addl $1, (v)
18654 adcl $0, 4(v)
18655 +
18656 +#ifdef CONFIG_PAX_REFCOUNT
18657 + jno 0f
18658 + subl $1, (v)
18659 + sbbl $0, 4(v)
18660 + int $4
18661 +0:
18662 + _ASM_EXTABLE(0b, 0b)
18663 +#endif
18664 +
18665 +RET_ENDP
18666 +BEGIN(inc_unchecked)
18667 + addl $1, (v)
18668 + adcl $0, 4(v)
18669 RET_ENDP
18670 #undef v
18671
18672 @@ -114,6 +203,26 @@ BEGIN(inc_return)
18673 movl 4(v), %edx
18674 addl $1, %eax
18675 adcl $0, %edx
18676 +
18677 +#ifdef CONFIG_PAX_REFCOUNT
18678 + into
18679 +1234:
18680 + _ASM_EXTABLE(1234b, 2f)
18681 +#endif
18682 +
18683 + movl %eax, (v)
18684 + movl %edx, 4(v)
18685 +
18686 +#ifdef CONFIG_PAX_REFCOUNT
18687 +2:
18688 +#endif
18689 +
18690 +RET_ENDP
18691 +BEGIN(inc_return_unchecked)
18692 + movl (v), %eax
18693 + movl 4(v), %edx
18694 + addl $1, %eax
18695 + adcl $0, %edx
18696 movl %eax, (v)
18697 movl %edx, 4(v)
18698 RET_ENDP
18699 @@ -123,6 +232,20 @@ RET_ENDP
18700 BEGIN(dec)
18701 subl $1, (v)
18702 sbbl $0, 4(v)
18703 +
18704 +#ifdef CONFIG_PAX_REFCOUNT
18705 + jno 0f
18706 + addl $1, (v)
18707 + adcl $0, 4(v)
18708 + int $4
18709 +0:
18710 + _ASM_EXTABLE(0b, 0b)
18711 +#endif
18712 +
18713 +RET_ENDP
18714 +BEGIN(dec_unchecked)
18715 + subl $1, (v)
18716 + sbbl $0, 4(v)
18717 RET_ENDP
18718 #undef v
18719
18720 @@ -132,6 +255,26 @@ BEGIN(dec_return)
18721 movl 4(v), %edx
18722 subl $1, %eax
18723 sbbl $0, %edx
18724 +
18725 +#ifdef CONFIG_PAX_REFCOUNT
18726 + into
18727 +1234:
18728 + _ASM_EXTABLE(1234b, 2f)
18729 +#endif
18730 +
18731 + movl %eax, (v)
18732 + movl %edx, 4(v)
18733 +
18734 +#ifdef CONFIG_PAX_REFCOUNT
18735 +2:
18736 +#endif
18737 +
18738 +RET_ENDP
18739 +BEGIN(dec_return_unchecked)
18740 + movl (v), %eax
18741 + movl 4(v), %edx
18742 + subl $1, %eax
18743 + sbbl $0, %edx
18744 movl %eax, (v)
18745 movl %edx, 4(v)
18746 RET_ENDP
18747 @@ -143,6 +286,13 @@ BEGIN(add_unless)
18748 adcl %edx, %edi
18749 addl (v), %eax
18750 adcl 4(v), %edx
18751 +
18752 +#ifdef CONFIG_PAX_REFCOUNT
18753 + into
18754 +1234:
18755 + _ASM_EXTABLE(1234b, 2f)
18756 +#endif
18757 +
18758 cmpl %eax, %esi
18759 je 3f
18760 1:
18761 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
18762 1:
18763 addl $1, %eax
18764 adcl $0, %edx
18765 +
18766 +#ifdef CONFIG_PAX_REFCOUNT
18767 + into
18768 +1234:
18769 + _ASM_EXTABLE(1234b, 2f)
18770 +#endif
18771 +
18772 movl %eax, (v)
18773 movl %edx, 4(v)
18774 movl $1, %eax
18775 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
18776 movl 4(v), %edx
18777 subl $1, %eax
18778 sbbl $0, %edx
18779 +
18780 +#ifdef CONFIG_PAX_REFCOUNT
18781 + into
18782 +1234:
18783 + _ASM_EXTABLE(1234b, 1f)
18784 +#endif
18785 +
18786 js 1f
18787 movl %eax, (v)
18788 movl %edx, 4(v)
18789 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
18790 index 391a083..d658e9f 100644
18791 --- a/arch/x86/lib/atomic64_cx8_32.S
18792 +++ b/arch/x86/lib/atomic64_cx8_32.S
18793 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
18794 CFI_STARTPROC
18795
18796 read64 %ecx
18797 + pax_force_retaddr
18798 ret
18799 CFI_ENDPROC
18800 ENDPROC(atomic64_read_cx8)
18801
18802 +ENTRY(atomic64_read_unchecked_cx8)
18803 + CFI_STARTPROC
18804 +
18805 + read64 %ecx
18806 + pax_force_retaddr
18807 + ret
18808 + CFI_ENDPROC
18809 +ENDPROC(atomic64_read_unchecked_cx8)
18810 +
18811 ENTRY(atomic64_set_cx8)
18812 CFI_STARTPROC
18813
18814 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
18815 cmpxchg8b (%esi)
18816 jne 1b
18817
18818 + pax_force_retaddr
18819 ret
18820 CFI_ENDPROC
18821 ENDPROC(atomic64_set_cx8)
18822
18823 +ENTRY(atomic64_set_unchecked_cx8)
18824 + CFI_STARTPROC
18825 +
18826 +1:
18827 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
18828 + * are atomic on 586 and newer */
18829 + cmpxchg8b (%esi)
18830 + jne 1b
18831 +
18832 + pax_force_retaddr
18833 + ret
18834 + CFI_ENDPROC
18835 +ENDPROC(atomic64_set_unchecked_cx8)
18836 +
18837 ENTRY(atomic64_xchg_cx8)
18838 CFI_STARTPROC
18839
18840 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
18841 cmpxchg8b (%esi)
18842 jne 1b
18843
18844 + pax_force_retaddr
18845 ret
18846 CFI_ENDPROC
18847 ENDPROC(atomic64_xchg_cx8)
18848
18849 -.macro addsub_return func ins insc
18850 -ENTRY(atomic64_\func\()_return_cx8)
18851 +.macro addsub_return func ins insc unchecked=""
18852 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
18853 CFI_STARTPROC
18854 SAVE ebp
18855 SAVE ebx
18856 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
18857 movl %edx, %ecx
18858 \ins\()l %esi, %ebx
18859 \insc\()l %edi, %ecx
18860 +
18861 +.ifb \unchecked
18862 +#ifdef CONFIG_PAX_REFCOUNT
18863 + into
18864 +2:
18865 + _ASM_EXTABLE(2b, 3f)
18866 +#endif
18867 +.endif
18868 +
18869 LOCK_PREFIX
18870 cmpxchg8b (%ebp)
18871 jne 1b
18872 -
18873 -10:
18874 movl %ebx, %eax
18875 movl %ecx, %edx
18876 +
18877 +.ifb \unchecked
18878 +#ifdef CONFIG_PAX_REFCOUNT
18879 +3:
18880 +#endif
18881 +.endif
18882 +
18883 RESTORE edi
18884 RESTORE esi
18885 RESTORE ebx
18886 RESTORE ebp
18887 + pax_force_retaddr
18888 ret
18889 CFI_ENDPROC
18890 -ENDPROC(atomic64_\func\()_return_cx8)
18891 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
18892 .endm
18893
18894 addsub_return add add adc
18895 addsub_return sub sub sbb
18896 +addsub_return add add adc _unchecked
18897 +addsub_return sub sub sbb _unchecked
18898
18899 -.macro incdec_return func ins insc
18900 -ENTRY(atomic64_\func\()_return_cx8)
18901 +.macro incdec_return func ins insc unchecked
18902 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
18903 CFI_STARTPROC
18904 SAVE ebx
18905
18906 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
18907 movl %edx, %ecx
18908 \ins\()l $1, %ebx
18909 \insc\()l $0, %ecx
18910 +
18911 +.ifb \unchecked
18912 +#ifdef CONFIG_PAX_REFCOUNT
18913 + into
18914 +2:
18915 + _ASM_EXTABLE(2b, 3f)
18916 +#endif
18917 +.endif
18918 +
18919 LOCK_PREFIX
18920 cmpxchg8b (%esi)
18921 jne 1b
18922
18923 -10:
18924 movl %ebx, %eax
18925 movl %ecx, %edx
18926 +
18927 +.ifb \unchecked
18928 +#ifdef CONFIG_PAX_REFCOUNT
18929 +3:
18930 +#endif
18931 +.endif
18932 +
18933 RESTORE ebx
18934 + pax_force_retaddr
18935 ret
18936 CFI_ENDPROC
18937 -ENDPROC(atomic64_\func\()_return_cx8)
18938 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
18939 .endm
18940
18941 incdec_return inc add adc
18942 incdec_return dec sub sbb
18943 +incdec_return inc add adc _unchecked
18944 +incdec_return dec sub sbb _unchecked
18945
18946 ENTRY(atomic64_dec_if_positive_cx8)
18947 CFI_STARTPROC
18948 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
18949 movl %edx, %ecx
18950 subl $1, %ebx
18951 sbb $0, %ecx
18952 +
18953 +#ifdef CONFIG_PAX_REFCOUNT
18954 + into
18955 +1234:
18956 + _ASM_EXTABLE(1234b, 2f)
18957 +#endif
18958 +
18959 js 2f
18960 LOCK_PREFIX
18961 cmpxchg8b (%esi)
18962 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
18963 movl %ebx, %eax
18964 movl %ecx, %edx
18965 RESTORE ebx
18966 + pax_force_retaddr
18967 ret
18968 CFI_ENDPROC
18969 ENDPROC(atomic64_dec_if_positive_cx8)
18970 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
18971 movl %edx, %ecx
18972 addl %esi, %ebx
18973 adcl %edi, %ecx
18974 +
18975 +#ifdef CONFIG_PAX_REFCOUNT
18976 + into
18977 +1234:
18978 + _ASM_EXTABLE(1234b, 3f)
18979 +#endif
18980 +
18981 LOCK_PREFIX
18982 cmpxchg8b (%ebp)
18983 jne 1b
18984 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
18985 CFI_ADJUST_CFA_OFFSET -8
18986 RESTORE ebx
18987 RESTORE ebp
18988 + pax_force_retaddr
18989 ret
18990 4:
18991 cmpl %edx, 4(%esp)
18992 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
18993 movl %edx, %ecx
18994 addl $1, %ebx
18995 adcl $0, %ecx
18996 +
18997 +#ifdef CONFIG_PAX_REFCOUNT
18998 + into
18999 +1234:
19000 + _ASM_EXTABLE(1234b, 3f)
19001 +#endif
19002 +
19003 LOCK_PREFIX
19004 cmpxchg8b (%esi)
19005 jne 1b
19006 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
19007 movl $1, %eax
19008 3:
19009 RESTORE ebx
19010 + pax_force_retaddr
19011 ret
19012 4:
19013 testl %edx, %edx
19014 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
19015 index 78d16a5..fbcf666 100644
19016 --- a/arch/x86/lib/checksum_32.S
19017 +++ b/arch/x86/lib/checksum_32.S
19018 @@ -28,7 +28,8 @@
19019 #include <linux/linkage.h>
19020 #include <asm/dwarf2.h>
19021 #include <asm/errno.h>
19022 -
19023 +#include <asm/segment.h>
19024 +
19025 /*
19026 * computes a partial checksum, e.g. for TCP/UDP fragments
19027 */
19028 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
19029
19030 #define ARGBASE 16
19031 #define FP 12
19032 -
19033 -ENTRY(csum_partial_copy_generic)
19034 +
19035 +ENTRY(csum_partial_copy_generic_to_user)
19036 CFI_STARTPROC
19037 +
19038 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19039 + pushl_cfi %gs
19040 + popl_cfi %es
19041 + jmp csum_partial_copy_generic
19042 +#endif
19043 +
19044 +ENTRY(csum_partial_copy_generic_from_user)
19045 +
19046 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19047 + pushl_cfi %gs
19048 + popl_cfi %ds
19049 +#endif
19050 +
19051 +ENTRY(csum_partial_copy_generic)
19052 subl $4,%esp
19053 CFI_ADJUST_CFA_OFFSET 4
19054 pushl_cfi %edi
19055 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
19056 jmp 4f
19057 SRC(1: movw (%esi), %bx )
19058 addl $2, %esi
19059 -DST( movw %bx, (%edi) )
19060 +DST( movw %bx, %es:(%edi) )
19061 addl $2, %edi
19062 addw %bx, %ax
19063 adcl $0, %eax
19064 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
19065 SRC(1: movl (%esi), %ebx )
19066 SRC( movl 4(%esi), %edx )
19067 adcl %ebx, %eax
19068 -DST( movl %ebx, (%edi) )
19069 +DST( movl %ebx, %es:(%edi) )
19070 adcl %edx, %eax
19071 -DST( movl %edx, 4(%edi) )
19072 +DST( movl %edx, %es:4(%edi) )
19073
19074 SRC( movl 8(%esi), %ebx )
19075 SRC( movl 12(%esi), %edx )
19076 adcl %ebx, %eax
19077 -DST( movl %ebx, 8(%edi) )
19078 +DST( movl %ebx, %es:8(%edi) )
19079 adcl %edx, %eax
19080 -DST( movl %edx, 12(%edi) )
19081 +DST( movl %edx, %es:12(%edi) )
19082
19083 SRC( movl 16(%esi), %ebx )
19084 SRC( movl 20(%esi), %edx )
19085 adcl %ebx, %eax
19086 -DST( movl %ebx, 16(%edi) )
19087 +DST( movl %ebx, %es:16(%edi) )
19088 adcl %edx, %eax
19089 -DST( movl %edx, 20(%edi) )
19090 +DST( movl %edx, %es:20(%edi) )
19091
19092 SRC( movl 24(%esi), %ebx )
19093 SRC( movl 28(%esi), %edx )
19094 adcl %ebx, %eax
19095 -DST( movl %ebx, 24(%edi) )
19096 +DST( movl %ebx, %es:24(%edi) )
19097 adcl %edx, %eax
19098 -DST( movl %edx, 28(%edi) )
19099 +DST( movl %edx, %es:28(%edi) )
19100
19101 lea 32(%esi), %esi
19102 lea 32(%edi), %edi
19103 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
19104 shrl $2, %edx # This clears CF
19105 SRC(3: movl (%esi), %ebx )
19106 adcl %ebx, %eax
19107 -DST( movl %ebx, (%edi) )
19108 +DST( movl %ebx, %es:(%edi) )
19109 lea 4(%esi), %esi
19110 lea 4(%edi), %edi
19111 dec %edx
19112 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
19113 jb 5f
19114 SRC( movw (%esi), %cx )
19115 leal 2(%esi), %esi
19116 -DST( movw %cx, (%edi) )
19117 +DST( movw %cx, %es:(%edi) )
19118 leal 2(%edi), %edi
19119 je 6f
19120 shll $16,%ecx
19121 SRC(5: movb (%esi), %cl )
19122 -DST( movb %cl, (%edi) )
19123 +DST( movb %cl, %es:(%edi) )
19124 6: addl %ecx, %eax
19125 adcl $0, %eax
19126 7:
19127 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
19128
19129 6001:
19130 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19131 - movl $-EFAULT, (%ebx)
19132 + movl $-EFAULT, %ss:(%ebx)
19133
19134 # zero the complete destination - computing the rest
19135 # is too much work
19136 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
19137
19138 6002:
19139 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19140 - movl $-EFAULT,(%ebx)
19141 + movl $-EFAULT,%ss:(%ebx)
19142 jmp 5000b
19143
19144 .previous
19145
19146 + pushl_cfi %ss
19147 + popl_cfi %ds
19148 + pushl_cfi %ss
19149 + popl_cfi %es
19150 popl_cfi %ebx
19151 CFI_RESTORE ebx
19152 popl_cfi %esi
19153 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
19154 popl_cfi %ecx # equivalent to addl $4,%esp
19155 ret
19156 CFI_ENDPROC
19157 -ENDPROC(csum_partial_copy_generic)
19158 +ENDPROC(csum_partial_copy_generic_to_user)
19159
19160 #else
19161
19162 /* Version for PentiumII/PPro */
19163
19164 #define ROUND1(x) \
19165 + nop; nop; nop; \
19166 SRC(movl x(%esi), %ebx ) ; \
19167 addl %ebx, %eax ; \
19168 - DST(movl %ebx, x(%edi) ) ;
19169 + DST(movl %ebx, %es:x(%edi)) ;
19170
19171 #define ROUND(x) \
19172 + nop; nop; nop; \
19173 SRC(movl x(%esi), %ebx ) ; \
19174 adcl %ebx, %eax ; \
19175 - DST(movl %ebx, x(%edi) ) ;
19176 + DST(movl %ebx, %es:x(%edi)) ;
19177
19178 #define ARGBASE 12
19179 -
19180 -ENTRY(csum_partial_copy_generic)
19181 +
19182 +ENTRY(csum_partial_copy_generic_to_user)
19183 CFI_STARTPROC
19184 +
19185 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19186 + pushl_cfi %gs
19187 + popl_cfi %es
19188 + jmp csum_partial_copy_generic
19189 +#endif
19190 +
19191 +ENTRY(csum_partial_copy_generic_from_user)
19192 +
19193 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19194 + pushl_cfi %gs
19195 + popl_cfi %ds
19196 +#endif
19197 +
19198 +ENTRY(csum_partial_copy_generic)
19199 pushl_cfi %ebx
19200 CFI_REL_OFFSET ebx, 0
19201 pushl_cfi %edi
19202 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
19203 subl %ebx, %edi
19204 lea -1(%esi),%edx
19205 andl $-32,%edx
19206 - lea 3f(%ebx,%ebx), %ebx
19207 + lea 3f(%ebx,%ebx,2), %ebx
19208 testl %esi, %esi
19209 jmp *%ebx
19210 1: addl $64,%esi
19211 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
19212 jb 5f
19213 SRC( movw (%esi), %dx )
19214 leal 2(%esi), %esi
19215 -DST( movw %dx, (%edi) )
19216 +DST( movw %dx, %es:(%edi) )
19217 leal 2(%edi), %edi
19218 je 6f
19219 shll $16,%edx
19220 5:
19221 SRC( movb (%esi), %dl )
19222 -DST( movb %dl, (%edi) )
19223 +DST( movb %dl, %es:(%edi) )
19224 6: addl %edx, %eax
19225 adcl $0, %eax
19226 7:
19227 .section .fixup, "ax"
19228 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19229 - movl $-EFAULT, (%ebx)
19230 + movl $-EFAULT, %ss:(%ebx)
19231 # zero the complete destination (computing the rest is too much work)
19232 movl ARGBASE+8(%esp),%edi # dst
19233 movl ARGBASE+12(%esp),%ecx # len
19234 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
19235 rep; stosb
19236 jmp 7b
19237 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19238 - movl $-EFAULT, (%ebx)
19239 + movl $-EFAULT, %ss:(%ebx)
19240 jmp 7b
19241 .previous
19242
19243 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19244 + pushl_cfi %ss
19245 + popl_cfi %ds
19246 + pushl_cfi %ss
19247 + popl_cfi %es
19248 +#endif
19249 +
19250 popl_cfi %esi
19251 CFI_RESTORE esi
19252 popl_cfi %edi
19253 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
19254 CFI_RESTORE ebx
19255 ret
19256 CFI_ENDPROC
19257 -ENDPROC(csum_partial_copy_generic)
19258 +ENDPROC(csum_partial_copy_generic_to_user)
19259
19260 #undef ROUND
19261 #undef ROUND1
19262 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
19263 index f2145cf..cea889d 100644
19264 --- a/arch/x86/lib/clear_page_64.S
19265 +++ b/arch/x86/lib/clear_page_64.S
19266 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
19267 movl $4096/8,%ecx
19268 xorl %eax,%eax
19269 rep stosq
19270 + pax_force_retaddr
19271 ret
19272 CFI_ENDPROC
19273 ENDPROC(clear_page_c)
19274 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
19275 movl $4096,%ecx
19276 xorl %eax,%eax
19277 rep stosb
19278 + pax_force_retaddr
19279 ret
19280 CFI_ENDPROC
19281 ENDPROC(clear_page_c_e)
19282 @@ -43,6 +45,7 @@ ENTRY(clear_page)
19283 leaq 64(%rdi),%rdi
19284 jnz .Lloop
19285 nop
19286 + pax_force_retaddr
19287 ret
19288 CFI_ENDPROC
19289 .Lclear_page_end:
19290 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
19291
19292 #include <asm/cpufeature.h>
19293
19294 - .section .altinstr_replacement,"ax"
19295 + .section .altinstr_replacement,"a"
19296 1: .byte 0xeb /* jmp <disp8> */
19297 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19298 2: .byte 0xeb /* jmp <disp8> */
19299 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
19300 index 1e572c5..2a162cd 100644
19301 --- a/arch/x86/lib/cmpxchg16b_emu.S
19302 +++ b/arch/x86/lib/cmpxchg16b_emu.S
19303 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
19304
19305 popf
19306 mov $1, %al
19307 + pax_force_retaddr
19308 ret
19309
19310 not_same:
19311 popf
19312 xor %al,%al
19313 + pax_force_retaddr
19314 ret
19315
19316 CFI_ENDPROC
19317 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
19318 index 01c805b..dccb07f 100644
19319 --- a/arch/x86/lib/copy_page_64.S
19320 +++ b/arch/x86/lib/copy_page_64.S
19321 @@ -9,6 +9,7 @@ copy_page_c:
19322 CFI_STARTPROC
19323 movl $4096/8,%ecx
19324 rep movsq
19325 + pax_force_retaddr
19326 ret
19327 CFI_ENDPROC
19328 ENDPROC(copy_page_c)
19329 @@ -39,7 +40,7 @@ ENTRY(copy_page)
19330 movq 16 (%rsi), %rdx
19331 movq 24 (%rsi), %r8
19332 movq 32 (%rsi), %r9
19333 - movq 40 (%rsi), %r10
19334 + movq 40 (%rsi), %r13
19335 movq 48 (%rsi), %r11
19336 movq 56 (%rsi), %r12
19337
19338 @@ -50,7 +51,7 @@ ENTRY(copy_page)
19339 movq %rdx, 16 (%rdi)
19340 movq %r8, 24 (%rdi)
19341 movq %r9, 32 (%rdi)
19342 - movq %r10, 40 (%rdi)
19343 + movq %r13, 40 (%rdi)
19344 movq %r11, 48 (%rdi)
19345 movq %r12, 56 (%rdi)
19346
19347 @@ -69,7 +70,7 @@ ENTRY(copy_page)
19348 movq 16 (%rsi), %rdx
19349 movq 24 (%rsi), %r8
19350 movq 32 (%rsi), %r9
19351 - movq 40 (%rsi), %r10
19352 + movq 40 (%rsi), %r13
19353 movq 48 (%rsi), %r11
19354 movq 56 (%rsi), %r12
19355
19356 @@ -78,7 +79,7 @@ ENTRY(copy_page)
19357 movq %rdx, 16 (%rdi)
19358 movq %r8, 24 (%rdi)
19359 movq %r9, 32 (%rdi)
19360 - movq %r10, 40 (%rdi)
19361 + movq %r13, 40 (%rdi)
19362 movq %r11, 48 (%rdi)
19363 movq %r12, 56 (%rdi)
19364
19365 @@ -95,6 +96,7 @@ ENTRY(copy_page)
19366 CFI_RESTORE r13
19367 addq $3*8,%rsp
19368 CFI_ADJUST_CFA_OFFSET -3*8
19369 + pax_force_retaddr
19370 ret
19371 .Lcopy_page_end:
19372 CFI_ENDPROC
19373 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
19374
19375 #include <asm/cpufeature.h>
19376
19377 - .section .altinstr_replacement,"ax"
19378 + .section .altinstr_replacement,"a"
19379 1: .byte 0xeb /* jmp <disp8> */
19380 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19381 2:
19382 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
19383 index 0248402..821c786 100644
19384 --- a/arch/x86/lib/copy_user_64.S
19385 +++ b/arch/x86/lib/copy_user_64.S
19386 @@ -16,6 +16,7 @@
19387 #include <asm/thread_info.h>
19388 #include <asm/cpufeature.h>
19389 #include <asm/alternative-asm.h>
19390 +#include <asm/pgtable.h>
19391
19392 /*
19393 * By placing feature2 after feature1 in altinstructions section, we logically
19394 @@ -29,7 +30,7 @@
19395 .byte 0xe9 /* 32bit jump */
19396 .long \orig-1f /* by default jump to orig */
19397 1:
19398 - .section .altinstr_replacement,"ax"
19399 + .section .altinstr_replacement,"a"
19400 2: .byte 0xe9 /* near jump with 32bit immediate */
19401 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
19402 3: .byte 0xe9 /* near jump with 32bit immediate */
19403 @@ -71,47 +72,20 @@
19404 #endif
19405 .endm
19406
19407 -/* Standard copy_to_user with segment limit checking */
19408 -ENTRY(_copy_to_user)
19409 - CFI_STARTPROC
19410 - GET_THREAD_INFO(%rax)
19411 - movq %rdi,%rcx
19412 - addq %rdx,%rcx
19413 - jc bad_to_user
19414 - cmpq TI_addr_limit(%rax),%rcx
19415 - ja bad_to_user
19416 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
19417 - copy_user_generic_unrolled,copy_user_generic_string, \
19418 - copy_user_enhanced_fast_string
19419 - CFI_ENDPROC
19420 -ENDPROC(_copy_to_user)
19421 -
19422 -/* Standard copy_from_user with segment limit checking */
19423 -ENTRY(_copy_from_user)
19424 - CFI_STARTPROC
19425 - GET_THREAD_INFO(%rax)
19426 - movq %rsi,%rcx
19427 - addq %rdx,%rcx
19428 - jc bad_from_user
19429 - cmpq TI_addr_limit(%rax),%rcx
19430 - ja bad_from_user
19431 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
19432 - copy_user_generic_unrolled,copy_user_generic_string, \
19433 - copy_user_enhanced_fast_string
19434 - CFI_ENDPROC
19435 -ENDPROC(_copy_from_user)
19436 -
19437 .section .fixup,"ax"
19438 /* must zero dest */
19439 ENTRY(bad_from_user)
19440 bad_from_user:
19441 CFI_STARTPROC
19442 + testl %edx,%edx
19443 + js bad_to_user
19444 movl %edx,%ecx
19445 xorl %eax,%eax
19446 rep
19447 stosb
19448 bad_to_user:
19449 movl %edx,%eax
19450 + pax_force_retaddr
19451 ret
19452 CFI_ENDPROC
19453 ENDPROC(bad_from_user)
19454 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
19455 jz 17f
19456 1: movq (%rsi),%r8
19457 2: movq 1*8(%rsi),%r9
19458 -3: movq 2*8(%rsi),%r10
19459 +3: movq 2*8(%rsi),%rax
19460 4: movq 3*8(%rsi),%r11
19461 5: movq %r8,(%rdi)
19462 6: movq %r9,1*8(%rdi)
19463 -7: movq %r10,2*8(%rdi)
19464 +7: movq %rax,2*8(%rdi)
19465 8: movq %r11,3*8(%rdi)
19466 9: movq 4*8(%rsi),%r8
19467 10: movq 5*8(%rsi),%r9
19468 -11: movq 6*8(%rsi),%r10
19469 +11: movq 6*8(%rsi),%rax
19470 12: movq 7*8(%rsi),%r11
19471 13: movq %r8,4*8(%rdi)
19472 14: movq %r9,5*8(%rdi)
19473 -15: movq %r10,6*8(%rdi)
19474 +15: movq %rax,6*8(%rdi)
19475 16: movq %r11,7*8(%rdi)
19476 leaq 64(%rsi),%rsi
19477 leaq 64(%rdi),%rdi
19478 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
19479 decl %ecx
19480 jnz 21b
19481 23: xor %eax,%eax
19482 + pax_force_retaddr
19483 ret
19484
19485 .section .fixup,"ax"
19486 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
19487 3: rep
19488 movsb
19489 4: xorl %eax,%eax
19490 + pax_force_retaddr
19491 ret
19492
19493 .section .fixup,"ax"
19494 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
19495 1: rep
19496 movsb
19497 2: xorl %eax,%eax
19498 + pax_force_retaddr
19499 ret
19500
19501 .section .fixup,"ax"
19502 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
19503 index cb0c112..e3a6895 100644
19504 --- a/arch/x86/lib/copy_user_nocache_64.S
19505 +++ b/arch/x86/lib/copy_user_nocache_64.S
19506 @@ -8,12 +8,14 @@
19507
19508 #include <linux/linkage.h>
19509 #include <asm/dwarf2.h>
19510 +#include <asm/alternative-asm.h>
19511
19512 #define FIX_ALIGNMENT 1
19513
19514 #include <asm/current.h>
19515 #include <asm/asm-offsets.h>
19516 #include <asm/thread_info.h>
19517 +#include <asm/pgtable.h>
19518
19519 .macro ALIGN_DESTINATION
19520 #ifdef FIX_ALIGNMENT
19521 @@ -50,6 +52,15 @@
19522 */
19523 ENTRY(__copy_user_nocache)
19524 CFI_STARTPROC
19525 +
19526 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19527 + mov $PAX_USER_SHADOW_BASE,%rcx
19528 + cmp %rcx,%rsi
19529 + jae 1f
19530 + add %rcx,%rsi
19531 +1:
19532 +#endif
19533 +
19534 cmpl $8,%edx
19535 jb 20f /* less then 8 bytes, go to byte copy loop */
19536 ALIGN_DESTINATION
19537 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
19538 jz 17f
19539 1: movq (%rsi),%r8
19540 2: movq 1*8(%rsi),%r9
19541 -3: movq 2*8(%rsi),%r10
19542 +3: movq 2*8(%rsi),%rax
19543 4: movq 3*8(%rsi),%r11
19544 5: movnti %r8,(%rdi)
19545 6: movnti %r9,1*8(%rdi)
19546 -7: movnti %r10,2*8(%rdi)
19547 +7: movnti %rax,2*8(%rdi)
19548 8: movnti %r11,3*8(%rdi)
19549 9: movq 4*8(%rsi),%r8
19550 10: movq 5*8(%rsi),%r9
19551 -11: movq 6*8(%rsi),%r10
19552 +11: movq 6*8(%rsi),%rax
19553 12: movq 7*8(%rsi),%r11
19554 13: movnti %r8,4*8(%rdi)
19555 14: movnti %r9,5*8(%rdi)
19556 -15: movnti %r10,6*8(%rdi)
19557 +15: movnti %rax,6*8(%rdi)
19558 16: movnti %r11,7*8(%rdi)
19559 leaq 64(%rsi),%rsi
19560 leaq 64(%rdi),%rdi
19561 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
19562 jnz 21b
19563 23: xorl %eax,%eax
19564 sfence
19565 + pax_force_retaddr
19566 ret
19567
19568 .section .fixup,"ax"
19569 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
19570 index fb903b7..c92b7f7 100644
19571 --- a/arch/x86/lib/csum-copy_64.S
19572 +++ b/arch/x86/lib/csum-copy_64.S
19573 @@ -8,6 +8,7 @@
19574 #include <linux/linkage.h>
19575 #include <asm/dwarf2.h>
19576 #include <asm/errno.h>
19577 +#include <asm/alternative-asm.h>
19578
19579 /*
19580 * Checksum copy with exception handling.
19581 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
19582 CFI_RESTORE rbp
19583 addq $7*8, %rsp
19584 CFI_ADJUST_CFA_OFFSET -7*8
19585 + pax_force_retaddr 0, 1
19586 ret
19587 CFI_RESTORE_STATE
19588
19589 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
19590 index 459b58a..9570bc7 100644
19591 --- a/arch/x86/lib/csum-wrappers_64.c
19592 +++ b/arch/x86/lib/csum-wrappers_64.c
19593 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
19594 len -= 2;
19595 }
19596 }
19597 - isum = csum_partial_copy_generic((__force const void *)src,
19598 +
19599 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19600 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19601 + src += PAX_USER_SHADOW_BASE;
19602 +#endif
19603 +
19604 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
19605 dst, len, isum, errp, NULL);
19606 if (unlikely(*errp))
19607 goto out_err;
19608 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
19609 }
19610
19611 *errp = 0;
19612 - return csum_partial_copy_generic(src, (void __force *)dst,
19613 +
19614 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19615 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19616 + dst += PAX_USER_SHADOW_BASE;
19617 +#endif
19618 +
19619 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
19620 len, isum, NULL, errp);
19621 }
19622 EXPORT_SYMBOL(csum_partial_copy_to_user);
19623 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
19624 index 51f1504..ddac4c1 100644
19625 --- a/arch/x86/lib/getuser.S
19626 +++ b/arch/x86/lib/getuser.S
19627 @@ -33,15 +33,38 @@
19628 #include <asm/asm-offsets.h>
19629 #include <asm/thread_info.h>
19630 #include <asm/asm.h>
19631 +#include <asm/segment.h>
19632 +#include <asm/pgtable.h>
19633 +#include <asm/alternative-asm.h>
19634 +
19635 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19636 +#define __copyuser_seg gs;
19637 +#else
19638 +#define __copyuser_seg
19639 +#endif
19640
19641 .text
19642 ENTRY(__get_user_1)
19643 CFI_STARTPROC
19644 +
19645 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19646 GET_THREAD_INFO(%_ASM_DX)
19647 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19648 jae bad_get_user
19649 -1: movzb (%_ASM_AX),%edx
19650 +
19651 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19652 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19653 + cmp %_ASM_DX,%_ASM_AX
19654 + jae 1234f
19655 + add %_ASM_DX,%_ASM_AX
19656 +1234:
19657 +#endif
19658 +
19659 +#endif
19660 +
19661 +1: __copyuser_seg movzb (%_ASM_AX),%edx
19662 xor %eax,%eax
19663 + pax_force_retaddr
19664 ret
19665 CFI_ENDPROC
19666 ENDPROC(__get_user_1)
19667 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
19668 ENTRY(__get_user_2)
19669 CFI_STARTPROC
19670 add $1,%_ASM_AX
19671 +
19672 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19673 jc bad_get_user
19674 GET_THREAD_INFO(%_ASM_DX)
19675 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19676 jae bad_get_user
19677 -2: movzwl -1(%_ASM_AX),%edx
19678 +
19679 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19680 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19681 + cmp %_ASM_DX,%_ASM_AX
19682 + jae 1234f
19683 + add %_ASM_DX,%_ASM_AX
19684 +1234:
19685 +#endif
19686 +
19687 +#endif
19688 +
19689 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19690 xor %eax,%eax
19691 + pax_force_retaddr
19692 ret
19693 CFI_ENDPROC
19694 ENDPROC(__get_user_2)
19695 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
19696 ENTRY(__get_user_4)
19697 CFI_STARTPROC
19698 add $3,%_ASM_AX
19699 +
19700 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19701 jc bad_get_user
19702 GET_THREAD_INFO(%_ASM_DX)
19703 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19704 jae bad_get_user
19705 -3: mov -3(%_ASM_AX),%edx
19706 +
19707 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19708 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19709 + cmp %_ASM_DX,%_ASM_AX
19710 + jae 1234f
19711 + add %_ASM_DX,%_ASM_AX
19712 +1234:
19713 +#endif
19714 +
19715 +#endif
19716 +
19717 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
19718 xor %eax,%eax
19719 + pax_force_retaddr
19720 ret
19721 CFI_ENDPROC
19722 ENDPROC(__get_user_4)
19723 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
19724 GET_THREAD_INFO(%_ASM_DX)
19725 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19726 jae bad_get_user
19727 +
19728 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19729 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19730 + cmp %_ASM_DX,%_ASM_AX
19731 + jae 1234f
19732 + add %_ASM_DX,%_ASM_AX
19733 +1234:
19734 +#endif
19735 +
19736 4: movq -7(%_ASM_AX),%_ASM_DX
19737 xor %eax,%eax
19738 + pax_force_retaddr
19739 ret
19740 CFI_ENDPROC
19741 ENDPROC(__get_user_8)
19742 @@ -91,6 +152,7 @@ bad_get_user:
19743 CFI_STARTPROC
19744 xor %edx,%edx
19745 mov $(-EFAULT),%_ASM_AX
19746 + pax_force_retaddr
19747 ret
19748 CFI_ENDPROC
19749 END(bad_get_user)
19750 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
19751 index 374562e..a75830b 100644
19752 --- a/arch/x86/lib/insn.c
19753 +++ b/arch/x86/lib/insn.c
19754 @@ -21,6 +21,11 @@
19755 #include <linux/string.h>
19756 #include <asm/inat.h>
19757 #include <asm/insn.h>
19758 +#ifdef __KERNEL__
19759 +#include <asm/pgtable_types.h>
19760 +#else
19761 +#define ktla_ktva(addr) addr
19762 +#endif
19763
19764 /* Verify next sizeof(t) bytes can be on the same instruction */
19765 #define validate_next(t, insn, n) \
19766 @@ -49,8 +54,8 @@
19767 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
19768 {
19769 memset(insn, 0, sizeof(*insn));
19770 - insn->kaddr = kaddr;
19771 - insn->next_byte = kaddr;
19772 + insn->kaddr = ktla_ktva(kaddr);
19773 + insn->next_byte = ktla_ktva(kaddr);
19774 insn->x86_64 = x86_64 ? 1 : 0;
19775 insn->opnd_bytes = 4;
19776 if (x86_64)
19777 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
19778 index 05a95e7..326f2fa 100644
19779 --- a/arch/x86/lib/iomap_copy_64.S
19780 +++ b/arch/x86/lib/iomap_copy_64.S
19781 @@ -17,6 +17,7 @@
19782
19783 #include <linux/linkage.h>
19784 #include <asm/dwarf2.h>
19785 +#include <asm/alternative-asm.h>
19786
19787 /*
19788 * override generic version in lib/iomap_copy.c
19789 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
19790 CFI_STARTPROC
19791 movl %edx,%ecx
19792 rep movsd
19793 + pax_force_retaddr
19794 ret
19795 CFI_ENDPROC
19796 ENDPROC(__iowrite32_copy)
19797 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
19798 index efbf2a0..8893637 100644
19799 --- a/arch/x86/lib/memcpy_64.S
19800 +++ b/arch/x86/lib/memcpy_64.S
19801 @@ -34,6 +34,7 @@
19802 rep movsq
19803 movl %edx, %ecx
19804 rep movsb
19805 + pax_force_retaddr
19806 ret
19807 .Lmemcpy_e:
19808 .previous
19809 @@ -51,6 +52,7 @@
19810
19811 movl %edx, %ecx
19812 rep movsb
19813 + pax_force_retaddr
19814 ret
19815 .Lmemcpy_e_e:
19816 .previous
19817 @@ -81,13 +83,13 @@ ENTRY(memcpy)
19818 */
19819 movq 0*8(%rsi), %r8
19820 movq 1*8(%rsi), %r9
19821 - movq 2*8(%rsi), %r10
19822 + movq 2*8(%rsi), %rcx
19823 movq 3*8(%rsi), %r11
19824 leaq 4*8(%rsi), %rsi
19825
19826 movq %r8, 0*8(%rdi)
19827 movq %r9, 1*8(%rdi)
19828 - movq %r10, 2*8(%rdi)
19829 + movq %rcx, 2*8(%rdi)
19830 movq %r11, 3*8(%rdi)
19831 leaq 4*8(%rdi), %rdi
19832 jae .Lcopy_forward_loop
19833 @@ -110,12 +112,12 @@ ENTRY(memcpy)
19834 subq $0x20, %rdx
19835 movq -1*8(%rsi), %r8
19836 movq -2*8(%rsi), %r9
19837 - movq -3*8(%rsi), %r10
19838 + movq -3*8(%rsi), %rcx
19839 movq -4*8(%rsi), %r11
19840 leaq -4*8(%rsi), %rsi
19841 movq %r8, -1*8(%rdi)
19842 movq %r9, -2*8(%rdi)
19843 - movq %r10, -3*8(%rdi)
19844 + movq %rcx, -3*8(%rdi)
19845 movq %r11, -4*8(%rdi)
19846 leaq -4*8(%rdi), %rdi
19847 jae .Lcopy_backward_loop
19848 @@ -135,12 +137,13 @@ ENTRY(memcpy)
19849 */
19850 movq 0*8(%rsi), %r8
19851 movq 1*8(%rsi), %r9
19852 - movq -2*8(%rsi, %rdx), %r10
19853 + movq -2*8(%rsi, %rdx), %rcx
19854 movq -1*8(%rsi, %rdx), %r11
19855 movq %r8, 0*8(%rdi)
19856 movq %r9, 1*8(%rdi)
19857 - movq %r10, -2*8(%rdi, %rdx)
19858 + movq %rcx, -2*8(%rdi, %rdx)
19859 movq %r11, -1*8(%rdi, %rdx)
19860 + pax_force_retaddr
19861 retq
19862 .p2align 4
19863 .Lless_16bytes:
19864 @@ -153,6 +156,7 @@ ENTRY(memcpy)
19865 movq -1*8(%rsi, %rdx), %r9
19866 movq %r8, 0*8(%rdi)
19867 movq %r9, -1*8(%rdi, %rdx)
19868 + pax_force_retaddr
19869 retq
19870 .p2align 4
19871 .Lless_8bytes:
19872 @@ -166,6 +170,7 @@ ENTRY(memcpy)
19873 movl -4(%rsi, %rdx), %r8d
19874 movl %ecx, (%rdi)
19875 movl %r8d, -4(%rdi, %rdx)
19876 + pax_force_retaddr
19877 retq
19878 .p2align 4
19879 .Lless_3bytes:
19880 @@ -183,6 +188,7 @@ ENTRY(memcpy)
19881 jnz .Lloop_1
19882
19883 .Lend:
19884 + pax_force_retaddr
19885 retq
19886 CFI_ENDPROC
19887 ENDPROC(memcpy)
19888 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
19889 index ee16461..c39c199 100644
19890 --- a/arch/x86/lib/memmove_64.S
19891 +++ b/arch/x86/lib/memmove_64.S
19892 @@ -61,13 +61,13 @@ ENTRY(memmove)
19893 5:
19894 sub $0x20, %rdx
19895 movq 0*8(%rsi), %r11
19896 - movq 1*8(%rsi), %r10
19897 + movq 1*8(%rsi), %rcx
19898 movq 2*8(%rsi), %r9
19899 movq 3*8(%rsi), %r8
19900 leaq 4*8(%rsi), %rsi
19901
19902 movq %r11, 0*8(%rdi)
19903 - movq %r10, 1*8(%rdi)
19904 + movq %rcx, 1*8(%rdi)
19905 movq %r9, 2*8(%rdi)
19906 movq %r8, 3*8(%rdi)
19907 leaq 4*8(%rdi), %rdi
19908 @@ -81,10 +81,10 @@ ENTRY(memmove)
19909 4:
19910 movq %rdx, %rcx
19911 movq -8(%rsi, %rdx), %r11
19912 - lea -8(%rdi, %rdx), %r10
19913 + lea -8(%rdi, %rdx), %r9
19914 shrq $3, %rcx
19915 rep movsq
19916 - movq %r11, (%r10)
19917 + movq %r11, (%r9)
19918 jmp 13f
19919 .Lmemmove_end_forward:
19920
19921 @@ -95,14 +95,14 @@ ENTRY(memmove)
19922 7:
19923 movq %rdx, %rcx
19924 movq (%rsi), %r11
19925 - movq %rdi, %r10
19926 + movq %rdi, %r9
19927 leaq -8(%rsi, %rdx), %rsi
19928 leaq -8(%rdi, %rdx), %rdi
19929 shrq $3, %rcx
19930 std
19931 rep movsq
19932 cld
19933 - movq %r11, (%r10)
19934 + movq %r11, (%r9)
19935 jmp 13f
19936
19937 /*
19938 @@ -127,13 +127,13 @@ ENTRY(memmove)
19939 8:
19940 subq $0x20, %rdx
19941 movq -1*8(%rsi), %r11
19942 - movq -2*8(%rsi), %r10
19943 + movq -2*8(%rsi), %rcx
19944 movq -3*8(%rsi), %r9
19945 movq -4*8(%rsi), %r8
19946 leaq -4*8(%rsi), %rsi
19947
19948 movq %r11, -1*8(%rdi)
19949 - movq %r10, -2*8(%rdi)
19950 + movq %rcx, -2*8(%rdi)
19951 movq %r9, -3*8(%rdi)
19952 movq %r8, -4*8(%rdi)
19953 leaq -4*8(%rdi), %rdi
19954 @@ -151,11 +151,11 @@ ENTRY(memmove)
19955 * Move data from 16 bytes to 31 bytes.
19956 */
19957 movq 0*8(%rsi), %r11
19958 - movq 1*8(%rsi), %r10
19959 + movq 1*8(%rsi), %rcx
19960 movq -2*8(%rsi, %rdx), %r9
19961 movq -1*8(%rsi, %rdx), %r8
19962 movq %r11, 0*8(%rdi)
19963 - movq %r10, 1*8(%rdi)
19964 + movq %rcx, 1*8(%rdi)
19965 movq %r9, -2*8(%rdi, %rdx)
19966 movq %r8, -1*8(%rdi, %rdx)
19967 jmp 13f
19968 @@ -167,9 +167,9 @@ ENTRY(memmove)
19969 * Move data from 8 bytes to 15 bytes.
19970 */
19971 movq 0*8(%rsi), %r11
19972 - movq -1*8(%rsi, %rdx), %r10
19973 + movq -1*8(%rsi, %rdx), %r9
19974 movq %r11, 0*8(%rdi)
19975 - movq %r10, -1*8(%rdi, %rdx)
19976 + movq %r9, -1*8(%rdi, %rdx)
19977 jmp 13f
19978 10:
19979 cmpq $4, %rdx
19980 @@ -178,9 +178,9 @@ ENTRY(memmove)
19981 * Move data from 4 bytes to 7 bytes.
19982 */
19983 movl (%rsi), %r11d
19984 - movl -4(%rsi, %rdx), %r10d
19985 + movl -4(%rsi, %rdx), %r9d
19986 movl %r11d, (%rdi)
19987 - movl %r10d, -4(%rdi, %rdx)
19988 + movl %r9d, -4(%rdi, %rdx)
19989 jmp 13f
19990 11:
19991 cmp $2, %rdx
19992 @@ -189,9 +189,9 @@ ENTRY(memmove)
19993 * Move data from 2 bytes to 3 bytes.
19994 */
19995 movw (%rsi), %r11w
19996 - movw -2(%rsi, %rdx), %r10w
19997 + movw -2(%rsi, %rdx), %r9w
19998 movw %r11w, (%rdi)
19999 - movw %r10w, -2(%rdi, %rdx)
20000 + movw %r9w, -2(%rdi, %rdx)
20001 jmp 13f
20002 12:
20003 cmp $1, %rdx
20004 @@ -202,6 +202,7 @@ ENTRY(memmove)
20005 movb (%rsi), %r11b
20006 movb %r11b, (%rdi)
20007 13:
20008 + pax_force_retaddr
20009 retq
20010 CFI_ENDPROC
20011
20012 @@ -210,6 +211,7 @@ ENTRY(memmove)
20013 /* Forward moving data. */
20014 movq %rdx, %rcx
20015 rep movsb
20016 + pax_force_retaddr
20017 retq
20018 .Lmemmove_end_forward_efs:
20019 .previous
20020 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
20021 index 79bd454..dff325a 100644
20022 --- a/arch/x86/lib/memset_64.S
20023 +++ b/arch/x86/lib/memset_64.S
20024 @@ -31,6 +31,7 @@
20025 movl %r8d,%ecx
20026 rep stosb
20027 movq %r9,%rax
20028 + pax_force_retaddr
20029 ret
20030 .Lmemset_e:
20031 .previous
20032 @@ -53,6 +54,7 @@
20033 movl %edx,%ecx
20034 rep stosb
20035 movq %r9,%rax
20036 + pax_force_retaddr
20037 ret
20038 .Lmemset_e_e:
20039 .previous
20040 @@ -60,13 +62,13 @@
20041 ENTRY(memset)
20042 ENTRY(__memset)
20043 CFI_STARTPROC
20044 - movq %rdi,%r10
20045 movq %rdx,%r11
20046
20047 /* expand byte value */
20048 movzbl %sil,%ecx
20049 movabs $0x0101010101010101,%rax
20050 mul %rcx /* with rax, clobbers rdx */
20051 + movq %rdi,%rdx
20052
20053 /* align dst */
20054 movl %edi,%r9d
20055 @@ -120,7 +122,8 @@ ENTRY(__memset)
20056 jnz .Lloop_1
20057
20058 .Lende:
20059 - movq %r10,%rax
20060 + movq %rdx,%rax
20061 + pax_force_retaddr
20062 ret
20063
20064 CFI_RESTORE_STATE
20065 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
20066 index c9f2d9b..e7fd2c0 100644
20067 --- a/arch/x86/lib/mmx_32.c
20068 +++ b/arch/x86/lib/mmx_32.c
20069 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
20070 {
20071 void *p;
20072 int i;
20073 + unsigned long cr0;
20074
20075 if (unlikely(in_interrupt()))
20076 return __memcpy(to, from, len);
20077 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
20078 kernel_fpu_begin();
20079
20080 __asm__ __volatile__ (
20081 - "1: prefetch (%0)\n" /* This set is 28 bytes */
20082 - " prefetch 64(%0)\n"
20083 - " prefetch 128(%0)\n"
20084 - " prefetch 192(%0)\n"
20085 - " prefetch 256(%0)\n"
20086 + "1: prefetch (%1)\n" /* This set is 28 bytes */
20087 + " prefetch 64(%1)\n"
20088 + " prefetch 128(%1)\n"
20089 + " prefetch 192(%1)\n"
20090 + " prefetch 256(%1)\n"
20091 "2: \n"
20092 ".section .fixup, \"ax\"\n"
20093 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20094 + "3: \n"
20095 +
20096 +#ifdef CONFIG_PAX_KERNEXEC
20097 + " movl %%cr0, %0\n"
20098 + " movl %0, %%eax\n"
20099 + " andl $0xFFFEFFFF, %%eax\n"
20100 + " movl %%eax, %%cr0\n"
20101 +#endif
20102 +
20103 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20104 +
20105 +#ifdef CONFIG_PAX_KERNEXEC
20106 + " movl %0, %%cr0\n"
20107 +#endif
20108 +
20109 " jmp 2b\n"
20110 ".previous\n"
20111 _ASM_EXTABLE(1b, 3b)
20112 - : : "r" (from));
20113 + : "=&r" (cr0) : "r" (from) : "ax");
20114
20115 for ( ; i > 5; i--) {
20116 __asm__ __volatile__ (
20117 - "1: prefetch 320(%0)\n"
20118 - "2: movq (%0), %%mm0\n"
20119 - " movq 8(%0), %%mm1\n"
20120 - " movq 16(%0), %%mm2\n"
20121 - " movq 24(%0), %%mm3\n"
20122 - " movq %%mm0, (%1)\n"
20123 - " movq %%mm1, 8(%1)\n"
20124 - " movq %%mm2, 16(%1)\n"
20125 - " movq %%mm3, 24(%1)\n"
20126 - " movq 32(%0), %%mm0\n"
20127 - " movq 40(%0), %%mm1\n"
20128 - " movq 48(%0), %%mm2\n"
20129 - " movq 56(%0), %%mm3\n"
20130 - " movq %%mm0, 32(%1)\n"
20131 - " movq %%mm1, 40(%1)\n"
20132 - " movq %%mm2, 48(%1)\n"
20133 - " movq %%mm3, 56(%1)\n"
20134 + "1: prefetch 320(%1)\n"
20135 + "2: movq (%1), %%mm0\n"
20136 + " movq 8(%1), %%mm1\n"
20137 + " movq 16(%1), %%mm2\n"
20138 + " movq 24(%1), %%mm3\n"
20139 + " movq %%mm0, (%2)\n"
20140 + " movq %%mm1, 8(%2)\n"
20141 + " movq %%mm2, 16(%2)\n"
20142 + " movq %%mm3, 24(%2)\n"
20143 + " movq 32(%1), %%mm0\n"
20144 + " movq 40(%1), %%mm1\n"
20145 + " movq 48(%1), %%mm2\n"
20146 + " movq 56(%1), %%mm3\n"
20147 + " movq %%mm0, 32(%2)\n"
20148 + " movq %%mm1, 40(%2)\n"
20149 + " movq %%mm2, 48(%2)\n"
20150 + " movq %%mm3, 56(%2)\n"
20151 ".section .fixup, \"ax\"\n"
20152 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20153 + "3:\n"
20154 +
20155 +#ifdef CONFIG_PAX_KERNEXEC
20156 + " movl %%cr0, %0\n"
20157 + " movl %0, %%eax\n"
20158 + " andl $0xFFFEFFFF, %%eax\n"
20159 + " movl %%eax, %%cr0\n"
20160 +#endif
20161 +
20162 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20163 +
20164 +#ifdef CONFIG_PAX_KERNEXEC
20165 + " movl %0, %%cr0\n"
20166 +#endif
20167 +
20168 " jmp 2b\n"
20169 ".previous\n"
20170 _ASM_EXTABLE(1b, 3b)
20171 - : : "r" (from), "r" (to) : "memory");
20172 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20173
20174 from += 64;
20175 to += 64;
20176 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
20177 static void fast_copy_page(void *to, void *from)
20178 {
20179 int i;
20180 + unsigned long cr0;
20181
20182 kernel_fpu_begin();
20183
20184 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
20185 * but that is for later. -AV
20186 */
20187 __asm__ __volatile__(
20188 - "1: prefetch (%0)\n"
20189 - " prefetch 64(%0)\n"
20190 - " prefetch 128(%0)\n"
20191 - " prefetch 192(%0)\n"
20192 - " prefetch 256(%0)\n"
20193 + "1: prefetch (%1)\n"
20194 + " prefetch 64(%1)\n"
20195 + " prefetch 128(%1)\n"
20196 + " prefetch 192(%1)\n"
20197 + " prefetch 256(%1)\n"
20198 "2: \n"
20199 ".section .fixup, \"ax\"\n"
20200 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20201 + "3: \n"
20202 +
20203 +#ifdef CONFIG_PAX_KERNEXEC
20204 + " movl %%cr0, %0\n"
20205 + " movl %0, %%eax\n"
20206 + " andl $0xFFFEFFFF, %%eax\n"
20207 + " movl %%eax, %%cr0\n"
20208 +#endif
20209 +
20210 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20211 +
20212 +#ifdef CONFIG_PAX_KERNEXEC
20213 + " movl %0, %%cr0\n"
20214 +#endif
20215 +
20216 " jmp 2b\n"
20217 ".previous\n"
20218 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20219 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20220
20221 for (i = 0; i < (4096-320)/64; i++) {
20222 __asm__ __volatile__ (
20223 - "1: prefetch 320(%0)\n"
20224 - "2: movq (%0), %%mm0\n"
20225 - " movntq %%mm0, (%1)\n"
20226 - " movq 8(%0), %%mm1\n"
20227 - " movntq %%mm1, 8(%1)\n"
20228 - " movq 16(%0), %%mm2\n"
20229 - " movntq %%mm2, 16(%1)\n"
20230 - " movq 24(%0), %%mm3\n"
20231 - " movntq %%mm3, 24(%1)\n"
20232 - " movq 32(%0), %%mm4\n"
20233 - " movntq %%mm4, 32(%1)\n"
20234 - " movq 40(%0), %%mm5\n"
20235 - " movntq %%mm5, 40(%1)\n"
20236 - " movq 48(%0), %%mm6\n"
20237 - " movntq %%mm6, 48(%1)\n"
20238 - " movq 56(%0), %%mm7\n"
20239 - " movntq %%mm7, 56(%1)\n"
20240 + "1: prefetch 320(%1)\n"
20241 + "2: movq (%1), %%mm0\n"
20242 + " movntq %%mm0, (%2)\n"
20243 + " movq 8(%1), %%mm1\n"
20244 + " movntq %%mm1, 8(%2)\n"
20245 + " movq 16(%1), %%mm2\n"
20246 + " movntq %%mm2, 16(%2)\n"
20247 + " movq 24(%1), %%mm3\n"
20248 + " movntq %%mm3, 24(%2)\n"
20249 + " movq 32(%1), %%mm4\n"
20250 + " movntq %%mm4, 32(%2)\n"
20251 + " movq 40(%1), %%mm5\n"
20252 + " movntq %%mm5, 40(%2)\n"
20253 + " movq 48(%1), %%mm6\n"
20254 + " movntq %%mm6, 48(%2)\n"
20255 + " movq 56(%1), %%mm7\n"
20256 + " movntq %%mm7, 56(%2)\n"
20257 ".section .fixup, \"ax\"\n"
20258 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20259 + "3:\n"
20260 +
20261 +#ifdef CONFIG_PAX_KERNEXEC
20262 + " movl %%cr0, %0\n"
20263 + " movl %0, %%eax\n"
20264 + " andl $0xFFFEFFFF, %%eax\n"
20265 + " movl %%eax, %%cr0\n"
20266 +#endif
20267 +
20268 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20269 +
20270 +#ifdef CONFIG_PAX_KERNEXEC
20271 + " movl %0, %%cr0\n"
20272 +#endif
20273 +
20274 " jmp 2b\n"
20275 ".previous\n"
20276 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
20277 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20278
20279 from += 64;
20280 to += 64;
20281 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
20282 static void fast_copy_page(void *to, void *from)
20283 {
20284 int i;
20285 + unsigned long cr0;
20286
20287 kernel_fpu_begin();
20288
20289 __asm__ __volatile__ (
20290 - "1: prefetch (%0)\n"
20291 - " prefetch 64(%0)\n"
20292 - " prefetch 128(%0)\n"
20293 - " prefetch 192(%0)\n"
20294 - " prefetch 256(%0)\n"
20295 + "1: prefetch (%1)\n"
20296 + " prefetch 64(%1)\n"
20297 + " prefetch 128(%1)\n"
20298 + " prefetch 192(%1)\n"
20299 + " prefetch 256(%1)\n"
20300 "2: \n"
20301 ".section .fixup, \"ax\"\n"
20302 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20303 + "3: \n"
20304 +
20305 +#ifdef CONFIG_PAX_KERNEXEC
20306 + " movl %%cr0, %0\n"
20307 + " movl %0, %%eax\n"
20308 + " andl $0xFFFEFFFF, %%eax\n"
20309 + " movl %%eax, %%cr0\n"
20310 +#endif
20311 +
20312 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20313 +
20314 +#ifdef CONFIG_PAX_KERNEXEC
20315 + " movl %0, %%cr0\n"
20316 +#endif
20317 +
20318 " jmp 2b\n"
20319 ".previous\n"
20320 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20321 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20322
20323 for (i = 0; i < 4096/64; i++) {
20324 __asm__ __volatile__ (
20325 - "1: prefetch 320(%0)\n"
20326 - "2: movq (%0), %%mm0\n"
20327 - " movq 8(%0), %%mm1\n"
20328 - " movq 16(%0), %%mm2\n"
20329 - " movq 24(%0), %%mm3\n"
20330 - " movq %%mm0, (%1)\n"
20331 - " movq %%mm1, 8(%1)\n"
20332 - " movq %%mm2, 16(%1)\n"
20333 - " movq %%mm3, 24(%1)\n"
20334 - " movq 32(%0), %%mm0\n"
20335 - " movq 40(%0), %%mm1\n"
20336 - " movq 48(%0), %%mm2\n"
20337 - " movq 56(%0), %%mm3\n"
20338 - " movq %%mm0, 32(%1)\n"
20339 - " movq %%mm1, 40(%1)\n"
20340 - " movq %%mm2, 48(%1)\n"
20341 - " movq %%mm3, 56(%1)\n"
20342 + "1: prefetch 320(%1)\n"
20343 + "2: movq (%1), %%mm0\n"
20344 + " movq 8(%1), %%mm1\n"
20345 + " movq 16(%1), %%mm2\n"
20346 + " movq 24(%1), %%mm3\n"
20347 + " movq %%mm0, (%2)\n"
20348 + " movq %%mm1, 8(%2)\n"
20349 + " movq %%mm2, 16(%2)\n"
20350 + " movq %%mm3, 24(%2)\n"
20351 + " movq 32(%1), %%mm0\n"
20352 + " movq 40(%1), %%mm1\n"
20353 + " movq 48(%1), %%mm2\n"
20354 + " movq 56(%1), %%mm3\n"
20355 + " movq %%mm0, 32(%2)\n"
20356 + " movq %%mm1, 40(%2)\n"
20357 + " movq %%mm2, 48(%2)\n"
20358 + " movq %%mm3, 56(%2)\n"
20359 ".section .fixup, \"ax\"\n"
20360 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20361 + "3:\n"
20362 +
20363 +#ifdef CONFIG_PAX_KERNEXEC
20364 + " movl %%cr0, %0\n"
20365 + " movl %0, %%eax\n"
20366 + " andl $0xFFFEFFFF, %%eax\n"
20367 + " movl %%eax, %%cr0\n"
20368 +#endif
20369 +
20370 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20371 +
20372 +#ifdef CONFIG_PAX_KERNEXEC
20373 + " movl %0, %%cr0\n"
20374 +#endif
20375 +
20376 " jmp 2b\n"
20377 ".previous\n"
20378 _ASM_EXTABLE(1b, 3b)
20379 - : : "r" (from), "r" (to) : "memory");
20380 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20381
20382 from += 64;
20383 to += 64;
20384 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
20385 index 69fa106..adda88b 100644
20386 --- a/arch/x86/lib/msr-reg.S
20387 +++ b/arch/x86/lib/msr-reg.S
20388 @@ -3,6 +3,7 @@
20389 #include <asm/dwarf2.h>
20390 #include <asm/asm.h>
20391 #include <asm/msr.h>
20392 +#include <asm/alternative-asm.h>
20393
20394 #ifdef CONFIG_X86_64
20395 /*
20396 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
20397 CFI_STARTPROC
20398 pushq_cfi %rbx
20399 pushq_cfi %rbp
20400 - movq %rdi, %r10 /* Save pointer */
20401 + movq %rdi, %r9 /* Save pointer */
20402 xorl %r11d, %r11d /* Return value */
20403 movl (%rdi), %eax
20404 movl 4(%rdi), %ecx
20405 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
20406 movl 28(%rdi), %edi
20407 CFI_REMEMBER_STATE
20408 1: \op
20409 -2: movl %eax, (%r10)
20410 +2: movl %eax, (%r9)
20411 movl %r11d, %eax /* Return value */
20412 - movl %ecx, 4(%r10)
20413 - movl %edx, 8(%r10)
20414 - movl %ebx, 12(%r10)
20415 - movl %ebp, 20(%r10)
20416 - movl %esi, 24(%r10)
20417 - movl %edi, 28(%r10)
20418 + movl %ecx, 4(%r9)
20419 + movl %edx, 8(%r9)
20420 + movl %ebx, 12(%r9)
20421 + movl %ebp, 20(%r9)
20422 + movl %esi, 24(%r9)
20423 + movl %edi, 28(%r9)
20424 popq_cfi %rbp
20425 popq_cfi %rbx
20426 + pax_force_retaddr
20427 ret
20428 3:
20429 CFI_RESTORE_STATE
20430 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
20431 index 36b0d15..d381858 100644
20432 --- a/arch/x86/lib/putuser.S
20433 +++ b/arch/x86/lib/putuser.S
20434 @@ -15,7 +15,9 @@
20435 #include <asm/thread_info.h>
20436 #include <asm/errno.h>
20437 #include <asm/asm.h>
20438 -
20439 +#include <asm/segment.h>
20440 +#include <asm/pgtable.h>
20441 +#include <asm/alternative-asm.h>
20442
20443 /*
20444 * __put_user_X
20445 @@ -29,52 +31,119 @@
20446 * as they get called from within inline assembly.
20447 */
20448
20449 -#define ENTER CFI_STARTPROC ; \
20450 - GET_THREAD_INFO(%_ASM_BX)
20451 -#define EXIT ret ; \
20452 +#define ENTER CFI_STARTPROC
20453 +#define EXIT pax_force_retaddr; ret ; \
20454 CFI_ENDPROC
20455
20456 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20457 +#define _DEST %_ASM_CX,%_ASM_BX
20458 +#else
20459 +#define _DEST %_ASM_CX
20460 +#endif
20461 +
20462 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20463 +#define __copyuser_seg gs;
20464 +#else
20465 +#define __copyuser_seg
20466 +#endif
20467 +
20468 .text
20469 ENTRY(__put_user_1)
20470 ENTER
20471 +
20472 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20473 + GET_THREAD_INFO(%_ASM_BX)
20474 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
20475 jae bad_put_user
20476 -1: movb %al,(%_ASM_CX)
20477 +
20478 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20479 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20480 + cmp %_ASM_BX,%_ASM_CX
20481 + jb 1234f
20482 + xor %ebx,%ebx
20483 +1234:
20484 +#endif
20485 +
20486 +#endif
20487 +
20488 +1: __copyuser_seg movb %al,(_DEST)
20489 xor %eax,%eax
20490 EXIT
20491 ENDPROC(__put_user_1)
20492
20493 ENTRY(__put_user_2)
20494 ENTER
20495 +
20496 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20497 + GET_THREAD_INFO(%_ASM_BX)
20498 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20499 sub $1,%_ASM_BX
20500 cmp %_ASM_BX,%_ASM_CX
20501 jae bad_put_user
20502 -2: movw %ax,(%_ASM_CX)
20503 +
20504 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20505 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20506 + cmp %_ASM_BX,%_ASM_CX
20507 + jb 1234f
20508 + xor %ebx,%ebx
20509 +1234:
20510 +#endif
20511 +
20512 +#endif
20513 +
20514 +2: __copyuser_seg movw %ax,(_DEST)
20515 xor %eax,%eax
20516 EXIT
20517 ENDPROC(__put_user_2)
20518
20519 ENTRY(__put_user_4)
20520 ENTER
20521 +
20522 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20523 + GET_THREAD_INFO(%_ASM_BX)
20524 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20525 sub $3,%_ASM_BX
20526 cmp %_ASM_BX,%_ASM_CX
20527 jae bad_put_user
20528 -3: movl %eax,(%_ASM_CX)
20529 +
20530 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20531 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20532 + cmp %_ASM_BX,%_ASM_CX
20533 + jb 1234f
20534 + xor %ebx,%ebx
20535 +1234:
20536 +#endif
20537 +
20538 +#endif
20539 +
20540 +3: __copyuser_seg movl %eax,(_DEST)
20541 xor %eax,%eax
20542 EXIT
20543 ENDPROC(__put_user_4)
20544
20545 ENTRY(__put_user_8)
20546 ENTER
20547 +
20548 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20549 + GET_THREAD_INFO(%_ASM_BX)
20550 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20551 sub $7,%_ASM_BX
20552 cmp %_ASM_BX,%_ASM_CX
20553 jae bad_put_user
20554 -4: mov %_ASM_AX,(%_ASM_CX)
20555 +
20556 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20557 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20558 + cmp %_ASM_BX,%_ASM_CX
20559 + jb 1234f
20560 + xor %ebx,%ebx
20561 +1234:
20562 +#endif
20563 +
20564 +#endif
20565 +
20566 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
20567 #ifdef CONFIG_X86_32
20568 -5: movl %edx,4(%_ASM_CX)
20569 +5: __copyuser_seg movl %edx,4(_DEST)
20570 #endif
20571 xor %eax,%eax
20572 EXIT
20573 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
20574 index 1cad221..de671ee 100644
20575 --- a/arch/x86/lib/rwlock.S
20576 +++ b/arch/x86/lib/rwlock.S
20577 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
20578 FRAME
20579 0: LOCK_PREFIX
20580 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
20581 +
20582 +#ifdef CONFIG_PAX_REFCOUNT
20583 + jno 1234f
20584 + LOCK_PREFIX
20585 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
20586 + int $4
20587 +1234:
20588 + _ASM_EXTABLE(1234b, 1234b)
20589 +#endif
20590 +
20591 1: rep; nop
20592 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
20593 jne 1b
20594 LOCK_PREFIX
20595 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
20596 +
20597 +#ifdef CONFIG_PAX_REFCOUNT
20598 + jno 1234f
20599 + LOCK_PREFIX
20600 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
20601 + int $4
20602 +1234:
20603 + _ASM_EXTABLE(1234b, 1234b)
20604 +#endif
20605 +
20606 jnz 0b
20607 ENDFRAME
20608 + pax_force_retaddr
20609 ret
20610 CFI_ENDPROC
20611 END(__write_lock_failed)
20612 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
20613 FRAME
20614 0: LOCK_PREFIX
20615 READ_LOCK_SIZE(inc) (%__lock_ptr)
20616 +
20617 +#ifdef CONFIG_PAX_REFCOUNT
20618 + jno 1234f
20619 + LOCK_PREFIX
20620 + READ_LOCK_SIZE(dec) (%__lock_ptr)
20621 + int $4
20622 +1234:
20623 + _ASM_EXTABLE(1234b, 1234b)
20624 +#endif
20625 +
20626 1: rep; nop
20627 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
20628 js 1b
20629 LOCK_PREFIX
20630 READ_LOCK_SIZE(dec) (%__lock_ptr)
20631 +
20632 +#ifdef CONFIG_PAX_REFCOUNT
20633 + jno 1234f
20634 + LOCK_PREFIX
20635 + READ_LOCK_SIZE(inc) (%__lock_ptr)
20636 + int $4
20637 +1234:
20638 + _ASM_EXTABLE(1234b, 1234b)
20639 +#endif
20640 +
20641 js 0b
20642 ENDFRAME
20643 + pax_force_retaddr
20644 ret
20645 CFI_ENDPROC
20646 END(__read_lock_failed)
20647 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
20648 index 5dff5f0..cadebf4 100644
20649 --- a/arch/x86/lib/rwsem.S
20650 +++ b/arch/x86/lib/rwsem.S
20651 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
20652 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
20653 CFI_RESTORE __ASM_REG(dx)
20654 restore_common_regs
20655 + pax_force_retaddr
20656 ret
20657 CFI_ENDPROC
20658 ENDPROC(call_rwsem_down_read_failed)
20659 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
20660 movq %rax,%rdi
20661 call rwsem_down_write_failed
20662 restore_common_regs
20663 + pax_force_retaddr
20664 ret
20665 CFI_ENDPROC
20666 ENDPROC(call_rwsem_down_write_failed)
20667 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
20668 movq %rax,%rdi
20669 call rwsem_wake
20670 restore_common_regs
20671 -1: ret
20672 +1: pax_force_retaddr
20673 + ret
20674 CFI_ENDPROC
20675 ENDPROC(call_rwsem_wake)
20676
20677 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
20678 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
20679 CFI_RESTORE __ASM_REG(dx)
20680 restore_common_regs
20681 + pax_force_retaddr
20682 ret
20683 CFI_ENDPROC
20684 ENDPROC(call_rwsem_downgrade_wake)
20685 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
20686 index a63efd6..ccecad8 100644
20687 --- a/arch/x86/lib/thunk_64.S
20688 +++ b/arch/x86/lib/thunk_64.S
20689 @@ -8,6 +8,7 @@
20690 #include <linux/linkage.h>
20691 #include <asm/dwarf2.h>
20692 #include <asm/calling.h>
20693 +#include <asm/alternative-asm.h>
20694
20695 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
20696 .macro THUNK name, func, put_ret_addr_in_rdi=0
20697 @@ -41,5 +42,6 @@
20698 SAVE_ARGS
20699 restore:
20700 RESTORE_ARGS
20701 + pax_force_retaddr
20702 ret
20703 CFI_ENDPROC
20704 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
20705 index e218d5d..35679b4 100644
20706 --- a/arch/x86/lib/usercopy_32.c
20707 +++ b/arch/x86/lib/usercopy_32.c
20708 @@ -43,7 +43,7 @@ do { \
20709 __asm__ __volatile__( \
20710 " testl %1,%1\n" \
20711 " jz 2f\n" \
20712 - "0: lodsb\n" \
20713 + "0: "__copyuser_seg"lodsb\n" \
20714 " stosb\n" \
20715 " testb %%al,%%al\n" \
20716 " jz 1f\n" \
20717 @@ -128,10 +128,12 @@ do { \
20718 int __d0; \
20719 might_fault(); \
20720 __asm__ __volatile__( \
20721 + __COPYUSER_SET_ES \
20722 "0: rep; stosl\n" \
20723 " movl %2,%0\n" \
20724 "1: rep; stosb\n" \
20725 "2:\n" \
20726 + __COPYUSER_RESTORE_ES \
20727 ".section .fixup,\"ax\"\n" \
20728 "3: lea 0(%2,%0,4),%0\n" \
20729 " jmp 2b\n" \
20730 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
20731 might_fault();
20732
20733 __asm__ __volatile__(
20734 + __COPYUSER_SET_ES
20735 " testl %0, %0\n"
20736 " jz 3f\n"
20737 " andl %0,%%ecx\n"
20738 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
20739 " subl %%ecx,%0\n"
20740 " addl %0,%%eax\n"
20741 "1:\n"
20742 + __COPYUSER_RESTORE_ES
20743 ".section .fixup,\"ax\"\n"
20744 "2: xorl %%eax,%%eax\n"
20745 " jmp 1b\n"
20746 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
20747
20748 #ifdef CONFIG_X86_INTEL_USERCOPY
20749 static unsigned long
20750 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
20751 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
20752 {
20753 int d0, d1;
20754 __asm__ __volatile__(
20755 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
20756 " .align 2,0x90\n"
20757 "3: movl 0(%4), %%eax\n"
20758 "4: movl 4(%4), %%edx\n"
20759 - "5: movl %%eax, 0(%3)\n"
20760 - "6: movl %%edx, 4(%3)\n"
20761 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
20762 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
20763 "7: movl 8(%4), %%eax\n"
20764 "8: movl 12(%4),%%edx\n"
20765 - "9: movl %%eax, 8(%3)\n"
20766 - "10: movl %%edx, 12(%3)\n"
20767 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
20768 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
20769 "11: movl 16(%4), %%eax\n"
20770 "12: movl 20(%4), %%edx\n"
20771 - "13: movl %%eax, 16(%3)\n"
20772 - "14: movl %%edx, 20(%3)\n"
20773 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
20774 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
20775 "15: movl 24(%4), %%eax\n"
20776 "16: movl 28(%4), %%edx\n"
20777 - "17: movl %%eax, 24(%3)\n"
20778 - "18: movl %%edx, 28(%3)\n"
20779 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
20780 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
20781 "19: movl 32(%4), %%eax\n"
20782 "20: movl 36(%4), %%edx\n"
20783 - "21: movl %%eax, 32(%3)\n"
20784 - "22: movl %%edx, 36(%3)\n"
20785 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
20786 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
20787 "23: movl 40(%4), %%eax\n"
20788 "24: movl 44(%4), %%edx\n"
20789 - "25: movl %%eax, 40(%3)\n"
20790 - "26: movl %%edx, 44(%3)\n"
20791 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
20792 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
20793 "27: movl 48(%4), %%eax\n"
20794 "28: movl 52(%4), %%edx\n"
20795 - "29: movl %%eax, 48(%3)\n"
20796 - "30: movl %%edx, 52(%3)\n"
20797 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
20798 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
20799 "31: movl 56(%4), %%eax\n"
20800 "32: movl 60(%4), %%edx\n"
20801 - "33: movl %%eax, 56(%3)\n"
20802 - "34: movl %%edx, 60(%3)\n"
20803 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
20804 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
20805 " addl $-64, %0\n"
20806 " addl $64, %4\n"
20807 " addl $64, %3\n"
20808 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
20809 " shrl $2, %0\n"
20810 " andl $3, %%eax\n"
20811 " cld\n"
20812 + __COPYUSER_SET_ES
20813 "99: rep; movsl\n"
20814 "36: movl %%eax, %0\n"
20815 "37: rep; movsb\n"
20816 "100:\n"
20817 + __COPYUSER_RESTORE_ES
20818 + ".section .fixup,\"ax\"\n"
20819 + "101: lea 0(%%eax,%0,4),%0\n"
20820 + " jmp 100b\n"
20821 + ".previous\n"
20822 + ".section __ex_table,\"a\"\n"
20823 + " .align 4\n"
20824 + " .long 1b,100b\n"
20825 + " .long 2b,100b\n"
20826 + " .long 3b,100b\n"
20827 + " .long 4b,100b\n"
20828 + " .long 5b,100b\n"
20829 + " .long 6b,100b\n"
20830 + " .long 7b,100b\n"
20831 + " .long 8b,100b\n"
20832 + " .long 9b,100b\n"
20833 + " .long 10b,100b\n"
20834 + " .long 11b,100b\n"
20835 + " .long 12b,100b\n"
20836 + " .long 13b,100b\n"
20837 + " .long 14b,100b\n"
20838 + " .long 15b,100b\n"
20839 + " .long 16b,100b\n"
20840 + " .long 17b,100b\n"
20841 + " .long 18b,100b\n"
20842 + " .long 19b,100b\n"
20843 + " .long 20b,100b\n"
20844 + " .long 21b,100b\n"
20845 + " .long 22b,100b\n"
20846 + " .long 23b,100b\n"
20847 + " .long 24b,100b\n"
20848 + " .long 25b,100b\n"
20849 + " .long 26b,100b\n"
20850 + " .long 27b,100b\n"
20851 + " .long 28b,100b\n"
20852 + " .long 29b,100b\n"
20853 + " .long 30b,100b\n"
20854 + " .long 31b,100b\n"
20855 + " .long 32b,100b\n"
20856 + " .long 33b,100b\n"
20857 + " .long 34b,100b\n"
20858 + " .long 35b,100b\n"
20859 + " .long 36b,100b\n"
20860 + " .long 37b,100b\n"
20861 + " .long 99b,101b\n"
20862 + ".previous"
20863 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
20864 + : "1"(to), "2"(from), "0"(size)
20865 + : "eax", "edx", "memory");
20866 + return size;
20867 +}
20868 +
20869 +static unsigned long
20870 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
20871 +{
20872 + int d0, d1;
20873 + __asm__ __volatile__(
20874 + " .align 2,0x90\n"
20875 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
20876 + " cmpl $67, %0\n"
20877 + " jbe 3f\n"
20878 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
20879 + " .align 2,0x90\n"
20880 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
20881 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
20882 + "5: movl %%eax, 0(%3)\n"
20883 + "6: movl %%edx, 4(%3)\n"
20884 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
20885 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
20886 + "9: movl %%eax, 8(%3)\n"
20887 + "10: movl %%edx, 12(%3)\n"
20888 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
20889 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
20890 + "13: movl %%eax, 16(%3)\n"
20891 + "14: movl %%edx, 20(%3)\n"
20892 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
20893 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
20894 + "17: movl %%eax, 24(%3)\n"
20895 + "18: movl %%edx, 28(%3)\n"
20896 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
20897 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
20898 + "21: movl %%eax, 32(%3)\n"
20899 + "22: movl %%edx, 36(%3)\n"
20900 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
20901 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
20902 + "25: movl %%eax, 40(%3)\n"
20903 + "26: movl %%edx, 44(%3)\n"
20904 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
20905 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
20906 + "29: movl %%eax, 48(%3)\n"
20907 + "30: movl %%edx, 52(%3)\n"
20908 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
20909 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
20910 + "33: movl %%eax, 56(%3)\n"
20911 + "34: movl %%edx, 60(%3)\n"
20912 + " addl $-64, %0\n"
20913 + " addl $64, %4\n"
20914 + " addl $64, %3\n"
20915 + " cmpl $63, %0\n"
20916 + " ja 1b\n"
20917 + "35: movl %0, %%eax\n"
20918 + " shrl $2, %0\n"
20919 + " andl $3, %%eax\n"
20920 + " cld\n"
20921 + "99: rep; "__copyuser_seg" movsl\n"
20922 + "36: movl %%eax, %0\n"
20923 + "37: rep; "__copyuser_seg" movsb\n"
20924 + "100:\n"
20925 ".section .fixup,\"ax\"\n"
20926 "101: lea 0(%%eax,%0,4),%0\n"
20927 " jmp 100b\n"
20928 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
20929 int d0, d1;
20930 __asm__ __volatile__(
20931 " .align 2,0x90\n"
20932 - "0: movl 32(%4), %%eax\n"
20933 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20934 " cmpl $67, %0\n"
20935 " jbe 2f\n"
20936 - "1: movl 64(%4), %%eax\n"
20937 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20938 " .align 2,0x90\n"
20939 - "2: movl 0(%4), %%eax\n"
20940 - "21: movl 4(%4), %%edx\n"
20941 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20942 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20943 " movl %%eax, 0(%3)\n"
20944 " movl %%edx, 4(%3)\n"
20945 - "3: movl 8(%4), %%eax\n"
20946 - "31: movl 12(%4),%%edx\n"
20947 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20948 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20949 " movl %%eax, 8(%3)\n"
20950 " movl %%edx, 12(%3)\n"
20951 - "4: movl 16(%4), %%eax\n"
20952 - "41: movl 20(%4), %%edx\n"
20953 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20954 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20955 " movl %%eax, 16(%3)\n"
20956 " movl %%edx, 20(%3)\n"
20957 - "10: movl 24(%4), %%eax\n"
20958 - "51: movl 28(%4), %%edx\n"
20959 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20960 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20961 " movl %%eax, 24(%3)\n"
20962 " movl %%edx, 28(%3)\n"
20963 - "11: movl 32(%4), %%eax\n"
20964 - "61: movl 36(%4), %%edx\n"
20965 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20966 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20967 " movl %%eax, 32(%3)\n"
20968 " movl %%edx, 36(%3)\n"
20969 - "12: movl 40(%4), %%eax\n"
20970 - "71: movl 44(%4), %%edx\n"
20971 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20972 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20973 " movl %%eax, 40(%3)\n"
20974 " movl %%edx, 44(%3)\n"
20975 - "13: movl 48(%4), %%eax\n"
20976 - "81: movl 52(%4), %%edx\n"
20977 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20978 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20979 " movl %%eax, 48(%3)\n"
20980 " movl %%edx, 52(%3)\n"
20981 - "14: movl 56(%4), %%eax\n"
20982 - "91: movl 60(%4), %%edx\n"
20983 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20984 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20985 " movl %%eax, 56(%3)\n"
20986 " movl %%edx, 60(%3)\n"
20987 " addl $-64, %0\n"
20988 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
20989 " shrl $2, %0\n"
20990 " andl $3, %%eax\n"
20991 " cld\n"
20992 - "6: rep; movsl\n"
20993 + "6: rep; "__copyuser_seg" movsl\n"
20994 " movl %%eax,%0\n"
20995 - "7: rep; movsb\n"
20996 + "7: rep; "__copyuser_seg" movsb\n"
20997 "8:\n"
20998 ".section .fixup,\"ax\"\n"
20999 "9: lea 0(%%eax,%0,4),%0\n"
21000 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
21001
21002 __asm__ __volatile__(
21003 " .align 2,0x90\n"
21004 - "0: movl 32(%4), %%eax\n"
21005 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21006 " cmpl $67, %0\n"
21007 " jbe 2f\n"
21008 - "1: movl 64(%4), %%eax\n"
21009 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21010 " .align 2,0x90\n"
21011 - "2: movl 0(%4), %%eax\n"
21012 - "21: movl 4(%4), %%edx\n"
21013 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21014 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21015 " movnti %%eax, 0(%3)\n"
21016 " movnti %%edx, 4(%3)\n"
21017 - "3: movl 8(%4), %%eax\n"
21018 - "31: movl 12(%4),%%edx\n"
21019 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21020 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21021 " movnti %%eax, 8(%3)\n"
21022 " movnti %%edx, 12(%3)\n"
21023 - "4: movl 16(%4), %%eax\n"
21024 - "41: movl 20(%4), %%edx\n"
21025 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21026 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21027 " movnti %%eax, 16(%3)\n"
21028 " movnti %%edx, 20(%3)\n"
21029 - "10: movl 24(%4), %%eax\n"
21030 - "51: movl 28(%4), %%edx\n"
21031 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21032 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21033 " movnti %%eax, 24(%3)\n"
21034 " movnti %%edx, 28(%3)\n"
21035 - "11: movl 32(%4), %%eax\n"
21036 - "61: movl 36(%4), %%edx\n"
21037 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21038 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21039 " movnti %%eax, 32(%3)\n"
21040 " movnti %%edx, 36(%3)\n"
21041 - "12: movl 40(%4), %%eax\n"
21042 - "71: movl 44(%4), %%edx\n"
21043 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21044 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21045 " movnti %%eax, 40(%3)\n"
21046 " movnti %%edx, 44(%3)\n"
21047 - "13: movl 48(%4), %%eax\n"
21048 - "81: movl 52(%4), %%edx\n"
21049 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21050 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21051 " movnti %%eax, 48(%3)\n"
21052 " movnti %%edx, 52(%3)\n"
21053 - "14: movl 56(%4), %%eax\n"
21054 - "91: movl 60(%4), %%edx\n"
21055 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21056 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21057 " movnti %%eax, 56(%3)\n"
21058 " movnti %%edx, 60(%3)\n"
21059 " addl $-64, %0\n"
21060 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
21061 " shrl $2, %0\n"
21062 " andl $3, %%eax\n"
21063 " cld\n"
21064 - "6: rep; movsl\n"
21065 + "6: rep; "__copyuser_seg" movsl\n"
21066 " movl %%eax,%0\n"
21067 - "7: rep; movsb\n"
21068 + "7: rep; "__copyuser_seg" movsb\n"
21069 "8:\n"
21070 ".section .fixup,\"ax\"\n"
21071 "9: lea 0(%%eax,%0,4),%0\n"
21072 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
21073
21074 __asm__ __volatile__(
21075 " .align 2,0x90\n"
21076 - "0: movl 32(%4), %%eax\n"
21077 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21078 " cmpl $67, %0\n"
21079 " jbe 2f\n"
21080 - "1: movl 64(%4), %%eax\n"
21081 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21082 " .align 2,0x90\n"
21083 - "2: movl 0(%4), %%eax\n"
21084 - "21: movl 4(%4), %%edx\n"
21085 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21086 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21087 " movnti %%eax, 0(%3)\n"
21088 " movnti %%edx, 4(%3)\n"
21089 - "3: movl 8(%4), %%eax\n"
21090 - "31: movl 12(%4),%%edx\n"
21091 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21092 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21093 " movnti %%eax, 8(%3)\n"
21094 " movnti %%edx, 12(%3)\n"
21095 - "4: movl 16(%4), %%eax\n"
21096 - "41: movl 20(%4), %%edx\n"
21097 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21098 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21099 " movnti %%eax, 16(%3)\n"
21100 " movnti %%edx, 20(%3)\n"
21101 - "10: movl 24(%4), %%eax\n"
21102 - "51: movl 28(%4), %%edx\n"
21103 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21104 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21105 " movnti %%eax, 24(%3)\n"
21106 " movnti %%edx, 28(%3)\n"
21107 - "11: movl 32(%4), %%eax\n"
21108 - "61: movl 36(%4), %%edx\n"
21109 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21110 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21111 " movnti %%eax, 32(%3)\n"
21112 " movnti %%edx, 36(%3)\n"
21113 - "12: movl 40(%4), %%eax\n"
21114 - "71: movl 44(%4), %%edx\n"
21115 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21116 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21117 " movnti %%eax, 40(%3)\n"
21118 " movnti %%edx, 44(%3)\n"
21119 - "13: movl 48(%4), %%eax\n"
21120 - "81: movl 52(%4), %%edx\n"
21121 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21122 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21123 " movnti %%eax, 48(%3)\n"
21124 " movnti %%edx, 52(%3)\n"
21125 - "14: movl 56(%4), %%eax\n"
21126 - "91: movl 60(%4), %%edx\n"
21127 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21128 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21129 " movnti %%eax, 56(%3)\n"
21130 " movnti %%edx, 60(%3)\n"
21131 " addl $-64, %0\n"
21132 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
21133 " shrl $2, %0\n"
21134 " andl $3, %%eax\n"
21135 " cld\n"
21136 - "6: rep; movsl\n"
21137 + "6: rep; "__copyuser_seg" movsl\n"
21138 " movl %%eax,%0\n"
21139 - "7: rep; movsb\n"
21140 + "7: rep; "__copyuser_seg" movsb\n"
21141 "8:\n"
21142 ".section .fixup,\"ax\"\n"
21143 "9: lea 0(%%eax,%0,4),%0\n"
21144 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
21145 */
21146 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
21147 unsigned long size);
21148 -unsigned long __copy_user_intel(void __user *to, const void *from,
21149 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
21150 + unsigned long size);
21151 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
21152 unsigned long size);
21153 unsigned long __copy_user_zeroing_intel_nocache(void *to,
21154 const void __user *from, unsigned long size);
21155 #endif /* CONFIG_X86_INTEL_USERCOPY */
21156
21157 /* Generic arbitrary sized copy. */
21158 -#define __copy_user(to, from, size) \
21159 +#define __copy_user(to, from, size, prefix, set, restore) \
21160 do { \
21161 int __d0, __d1, __d2; \
21162 __asm__ __volatile__( \
21163 + set \
21164 " cmp $7,%0\n" \
21165 " jbe 1f\n" \
21166 " movl %1,%0\n" \
21167 " negl %0\n" \
21168 " andl $7,%0\n" \
21169 " subl %0,%3\n" \
21170 - "4: rep; movsb\n" \
21171 + "4: rep; "prefix"movsb\n" \
21172 " movl %3,%0\n" \
21173 " shrl $2,%0\n" \
21174 " andl $3,%3\n" \
21175 " .align 2,0x90\n" \
21176 - "0: rep; movsl\n" \
21177 + "0: rep; "prefix"movsl\n" \
21178 " movl %3,%0\n" \
21179 - "1: rep; movsb\n" \
21180 + "1: rep; "prefix"movsb\n" \
21181 "2:\n" \
21182 + restore \
21183 ".section .fixup,\"ax\"\n" \
21184 "5: addl %3,%0\n" \
21185 " jmp 2b\n" \
21186 @@ -682,14 +799,14 @@ do { \
21187 " negl %0\n" \
21188 " andl $7,%0\n" \
21189 " subl %0,%3\n" \
21190 - "4: rep; movsb\n" \
21191 + "4: rep; "__copyuser_seg"movsb\n" \
21192 " movl %3,%0\n" \
21193 " shrl $2,%0\n" \
21194 " andl $3,%3\n" \
21195 " .align 2,0x90\n" \
21196 - "0: rep; movsl\n" \
21197 + "0: rep; "__copyuser_seg"movsl\n" \
21198 " movl %3,%0\n" \
21199 - "1: rep; movsb\n" \
21200 + "1: rep; "__copyuser_seg"movsb\n" \
21201 "2:\n" \
21202 ".section .fixup,\"ax\"\n" \
21203 "5: addl %3,%0\n" \
21204 @@ -775,9 +892,9 @@ survive:
21205 }
21206 #endif
21207 if (movsl_is_ok(to, from, n))
21208 - __copy_user(to, from, n);
21209 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
21210 else
21211 - n = __copy_user_intel(to, from, n);
21212 + n = __generic_copy_to_user_intel(to, from, n);
21213 return n;
21214 }
21215 EXPORT_SYMBOL(__copy_to_user_ll);
21216 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
21217 unsigned long n)
21218 {
21219 if (movsl_is_ok(to, from, n))
21220 - __copy_user(to, from, n);
21221 + __copy_user(to, from, n, __copyuser_seg, "", "");
21222 else
21223 - n = __copy_user_intel((void __user *)to,
21224 - (const void *)from, n);
21225 + n = __generic_copy_from_user_intel(to, from, n);
21226 return n;
21227 }
21228 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
21229 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
21230 if (n > 64 && cpu_has_xmm2)
21231 n = __copy_user_intel_nocache(to, from, n);
21232 else
21233 - __copy_user(to, from, n);
21234 + __copy_user(to, from, n, __copyuser_seg, "", "");
21235 #else
21236 - __copy_user(to, from, n);
21237 + __copy_user(to, from, n, __copyuser_seg, "", "");
21238 #endif
21239 return n;
21240 }
21241 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
21242
21243 -/**
21244 - * copy_to_user: - Copy a block of data into user space.
21245 - * @to: Destination address, in user space.
21246 - * @from: Source address, in kernel space.
21247 - * @n: Number of bytes to copy.
21248 - *
21249 - * Context: User context only. This function may sleep.
21250 - *
21251 - * Copy data from kernel space to user space.
21252 - *
21253 - * Returns number of bytes that could not be copied.
21254 - * On success, this will be zero.
21255 - */
21256 -unsigned long
21257 -copy_to_user(void __user *to, const void *from, unsigned long n)
21258 -{
21259 - if (access_ok(VERIFY_WRITE, to, n))
21260 - n = __copy_to_user(to, from, n);
21261 - return n;
21262 -}
21263 -EXPORT_SYMBOL(copy_to_user);
21264 -
21265 -/**
21266 - * copy_from_user: - Copy a block of data from user space.
21267 - * @to: Destination address, in kernel space.
21268 - * @from: Source address, in user space.
21269 - * @n: Number of bytes to copy.
21270 - *
21271 - * Context: User context only. This function may sleep.
21272 - *
21273 - * Copy data from user space to kernel space.
21274 - *
21275 - * Returns number of bytes that could not be copied.
21276 - * On success, this will be zero.
21277 - *
21278 - * If some data could not be copied, this function will pad the copied
21279 - * data to the requested size using zero bytes.
21280 - */
21281 -unsigned long
21282 -_copy_from_user(void *to, const void __user *from, unsigned long n)
21283 -{
21284 - if (access_ok(VERIFY_READ, from, n))
21285 - n = __copy_from_user(to, from, n);
21286 - else
21287 - memset(to, 0, n);
21288 - return n;
21289 -}
21290 -EXPORT_SYMBOL(_copy_from_user);
21291 -
21292 void copy_from_user_overflow(void)
21293 {
21294 WARN(1, "Buffer overflow detected!\n");
21295 }
21296 EXPORT_SYMBOL(copy_from_user_overflow);
21297 +
21298 +void copy_to_user_overflow(void)
21299 +{
21300 + WARN(1, "Buffer overflow detected!\n");
21301 +}
21302 +EXPORT_SYMBOL(copy_to_user_overflow);
21303 +
21304 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21305 +void __set_fs(mm_segment_t x)
21306 +{
21307 + switch (x.seg) {
21308 + case 0:
21309 + loadsegment(gs, 0);
21310 + break;
21311 + case TASK_SIZE_MAX:
21312 + loadsegment(gs, __USER_DS);
21313 + break;
21314 + case -1UL:
21315 + loadsegment(gs, __KERNEL_DS);
21316 + break;
21317 + default:
21318 + BUG();
21319 + }
21320 + return;
21321 +}
21322 +EXPORT_SYMBOL(__set_fs);
21323 +
21324 +void set_fs(mm_segment_t x)
21325 +{
21326 + current_thread_info()->addr_limit = x;
21327 + __set_fs(x);
21328 +}
21329 +EXPORT_SYMBOL(set_fs);
21330 +#endif
21331 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
21332 index b7c2849..8633ad8 100644
21333 --- a/arch/x86/lib/usercopy_64.c
21334 +++ b/arch/x86/lib/usercopy_64.c
21335 @@ -42,6 +42,12 @@ long
21336 __strncpy_from_user(char *dst, const char __user *src, long count)
21337 {
21338 long res;
21339 +
21340 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21341 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21342 + src += PAX_USER_SHADOW_BASE;
21343 +#endif
21344 +
21345 __do_strncpy_from_user(dst, src, count, res);
21346 return res;
21347 }
21348 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
21349 {
21350 long __d0;
21351 might_fault();
21352 +
21353 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21354 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
21355 + addr += PAX_USER_SHADOW_BASE;
21356 +#endif
21357 +
21358 /* no memory constraint because it doesn't change any memory gcc knows
21359 about */
21360 asm volatile(
21361 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
21362 }
21363 EXPORT_SYMBOL(strlen_user);
21364
21365 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
21366 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
21367 {
21368 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21369 - return copy_user_generic((__force void *)to, (__force void *)from, len);
21370 - }
21371 - return len;
21372 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21373 +
21374 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21375 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
21376 + to += PAX_USER_SHADOW_BASE;
21377 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
21378 + from += PAX_USER_SHADOW_BASE;
21379 +#endif
21380 +
21381 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
21382 + }
21383 + return len;
21384 }
21385 EXPORT_SYMBOL(copy_in_user);
21386
21387 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
21388 * it is not necessary to optimize tail handling.
21389 */
21390 unsigned long
21391 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
21392 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
21393 {
21394 char c;
21395 unsigned zero_len;
21396 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
21397 index d0474ad..36e9257 100644
21398 --- a/arch/x86/mm/extable.c
21399 +++ b/arch/x86/mm/extable.c
21400 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
21401 const struct exception_table_entry *fixup;
21402
21403 #ifdef CONFIG_PNPBIOS
21404 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
21405 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
21406 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
21407 extern u32 pnp_bios_is_utter_crap;
21408 pnp_bios_is_utter_crap = 1;
21409 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
21410 index 5db0490..13bd09c 100644
21411 --- a/arch/x86/mm/fault.c
21412 +++ b/arch/x86/mm/fault.c
21413 @@ -13,11 +13,18 @@
21414 #include <linux/perf_event.h> /* perf_sw_event */
21415 #include <linux/hugetlb.h> /* hstate_index_to_shift */
21416 #include <linux/prefetch.h> /* prefetchw */
21417 +#include <linux/unistd.h>
21418 +#include <linux/compiler.h>
21419
21420 #include <asm/traps.h> /* dotraplinkage, ... */
21421 #include <asm/pgalloc.h> /* pgd_*(), ... */
21422 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
21423 #include <asm/fixmap.h> /* VSYSCALL_START */
21424 +#include <asm/tlbflush.h>
21425 +
21426 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21427 +#include <asm/stacktrace.h>
21428 +#endif
21429
21430 /*
21431 * Page fault error code bits:
21432 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
21433 int ret = 0;
21434
21435 /* kprobe_running() needs smp_processor_id() */
21436 - if (kprobes_built_in() && !user_mode_vm(regs)) {
21437 + if (kprobes_built_in() && !user_mode(regs)) {
21438 preempt_disable();
21439 if (kprobe_running() && kprobe_fault_handler(regs, 14))
21440 ret = 1;
21441 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
21442 return !instr_lo || (instr_lo>>1) == 1;
21443 case 0x00:
21444 /* Prefetch instruction is 0x0F0D or 0x0F18 */
21445 - if (probe_kernel_address(instr, opcode))
21446 + if (user_mode(regs)) {
21447 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
21448 + return 0;
21449 + } else if (probe_kernel_address(instr, opcode))
21450 return 0;
21451
21452 *prefetch = (instr_lo == 0xF) &&
21453 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
21454 while (instr < max_instr) {
21455 unsigned char opcode;
21456
21457 - if (probe_kernel_address(instr, opcode))
21458 + if (user_mode(regs)) {
21459 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
21460 + break;
21461 + } else if (probe_kernel_address(instr, opcode))
21462 break;
21463
21464 instr++;
21465 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
21466 force_sig_info(si_signo, &info, tsk);
21467 }
21468
21469 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21470 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
21471 +#endif
21472 +
21473 +#ifdef CONFIG_PAX_EMUTRAMP
21474 +static int pax_handle_fetch_fault(struct pt_regs *regs);
21475 +#endif
21476 +
21477 +#ifdef CONFIG_PAX_PAGEEXEC
21478 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
21479 +{
21480 + pgd_t *pgd;
21481 + pud_t *pud;
21482 + pmd_t *pmd;
21483 +
21484 + pgd = pgd_offset(mm, address);
21485 + if (!pgd_present(*pgd))
21486 + return NULL;
21487 + pud = pud_offset(pgd, address);
21488 + if (!pud_present(*pud))
21489 + return NULL;
21490 + pmd = pmd_offset(pud, address);
21491 + if (!pmd_present(*pmd))
21492 + return NULL;
21493 + return pmd;
21494 +}
21495 +#endif
21496 +
21497 DEFINE_SPINLOCK(pgd_lock);
21498 LIST_HEAD(pgd_list);
21499
21500 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
21501 for (address = VMALLOC_START & PMD_MASK;
21502 address >= TASK_SIZE && address < FIXADDR_TOP;
21503 address += PMD_SIZE) {
21504 +
21505 +#ifdef CONFIG_PAX_PER_CPU_PGD
21506 + unsigned long cpu;
21507 +#else
21508 struct page *page;
21509 +#endif
21510
21511 spin_lock(&pgd_lock);
21512 +
21513 +#ifdef CONFIG_PAX_PER_CPU_PGD
21514 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
21515 + pgd_t *pgd = get_cpu_pgd(cpu);
21516 + pmd_t *ret;
21517 +#else
21518 list_for_each_entry(page, &pgd_list, lru) {
21519 + pgd_t *pgd = page_address(page);
21520 spinlock_t *pgt_lock;
21521 pmd_t *ret;
21522
21523 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
21524 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
21525
21526 spin_lock(pgt_lock);
21527 - ret = vmalloc_sync_one(page_address(page), address);
21528 +#endif
21529 +
21530 + ret = vmalloc_sync_one(pgd, address);
21531 +
21532 +#ifndef CONFIG_PAX_PER_CPU_PGD
21533 spin_unlock(pgt_lock);
21534 +#endif
21535
21536 if (!ret)
21537 break;
21538 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
21539 * an interrupt in the middle of a task switch..
21540 */
21541 pgd_paddr = read_cr3();
21542 +
21543 +#ifdef CONFIG_PAX_PER_CPU_PGD
21544 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
21545 +#endif
21546 +
21547 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
21548 if (!pmd_k)
21549 return -1;
21550 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
21551 * happen within a race in page table update. In the later
21552 * case just flush:
21553 */
21554 +
21555 +#ifdef CONFIG_PAX_PER_CPU_PGD
21556 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
21557 + pgd = pgd_offset_cpu(smp_processor_id(), address);
21558 +#else
21559 pgd = pgd_offset(current->active_mm, address);
21560 +#endif
21561 +
21562 pgd_ref = pgd_offset_k(address);
21563 if (pgd_none(*pgd_ref))
21564 return -1;
21565 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
21566 static int is_errata100(struct pt_regs *regs, unsigned long address)
21567 {
21568 #ifdef CONFIG_X86_64
21569 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
21570 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
21571 return 1;
21572 #endif
21573 return 0;
21574 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
21575 }
21576
21577 static const char nx_warning[] = KERN_CRIT
21578 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
21579 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
21580
21581 static void
21582 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21583 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21584 if (!oops_may_print())
21585 return;
21586
21587 - if (error_code & PF_INSTR) {
21588 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
21589 unsigned int level;
21590
21591 pte_t *pte = lookup_address(address, &level);
21592
21593 if (pte && pte_present(*pte) && !pte_exec(*pte))
21594 - printk(nx_warning, current_uid());
21595 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
21596 }
21597
21598 +#ifdef CONFIG_PAX_KERNEXEC
21599 + if (init_mm.start_code <= address && address < init_mm.end_code) {
21600 + if (current->signal->curr_ip)
21601 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21602 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
21603 + else
21604 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21605 + current->comm, task_pid_nr(current), current_uid(), current_euid());
21606 + }
21607 +#endif
21608 +
21609 printk(KERN_ALERT "BUG: unable to handle kernel ");
21610 if (address < PAGE_SIZE)
21611 printk(KERN_CONT "NULL pointer dereference");
21612 @@ -739,6 +820,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
21613 }
21614 #endif
21615
21616 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21617 + if (pax_is_fetch_fault(regs, error_code, address)) {
21618 +
21619 +#ifdef CONFIG_PAX_EMUTRAMP
21620 + switch (pax_handle_fetch_fault(regs)) {
21621 + case 2:
21622 + return;
21623 + }
21624 +#endif
21625 +
21626 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21627 + do_group_exit(SIGKILL);
21628 + }
21629 +#endif
21630 +
21631 if (unlikely(show_unhandled_signals))
21632 show_signal_msg(regs, error_code, address, tsk);
21633
21634 @@ -835,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
21635 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
21636 printk(KERN_ERR
21637 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
21638 - tsk->comm, tsk->pid, address);
21639 + tsk->comm, task_pid_nr(tsk), address);
21640 code = BUS_MCEERR_AR;
21641 }
21642 #endif
21643 @@ -890,6 +986,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
21644 return 1;
21645 }
21646
21647 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21648 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
21649 +{
21650 + pte_t *pte;
21651 + pmd_t *pmd;
21652 + spinlock_t *ptl;
21653 + unsigned char pte_mask;
21654 +
21655 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
21656 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
21657 + return 0;
21658 +
21659 + /* PaX: it's our fault, let's handle it if we can */
21660 +
21661 + /* PaX: take a look at read faults before acquiring any locks */
21662 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
21663 + /* instruction fetch attempt from a protected page in user mode */
21664 + up_read(&mm->mmap_sem);
21665 +
21666 +#ifdef CONFIG_PAX_EMUTRAMP
21667 + switch (pax_handle_fetch_fault(regs)) {
21668 + case 2:
21669 + return 1;
21670 + }
21671 +#endif
21672 +
21673 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21674 + do_group_exit(SIGKILL);
21675 + }
21676 +
21677 + pmd = pax_get_pmd(mm, address);
21678 + if (unlikely(!pmd))
21679 + return 0;
21680 +
21681 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21682 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21683 + pte_unmap_unlock(pte, ptl);
21684 + return 0;
21685 + }
21686 +
21687 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21688 + /* write attempt to a protected page in user mode */
21689 + pte_unmap_unlock(pte, ptl);
21690 + return 0;
21691 + }
21692 +
21693 +#ifdef CONFIG_SMP
21694 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21695 +#else
21696 + if (likely(address > get_limit(regs->cs)))
21697 +#endif
21698 + {
21699 + set_pte(pte, pte_mkread(*pte));
21700 + __flush_tlb_one(address);
21701 + pte_unmap_unlock(pte, ptl);
21702 + up_read(&mm->mmap_sem);
21703 + return 1;
21704 + }
21705 +
21706 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21707 +
21708 + /*
21709 + * PaX: fill DTLB with user rights and retry
21710 + */
21711 + __asm__ __volatile__ (
21712 + "orb %2,(%1)\n"
21713 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
21714 +/*
21715 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
21716 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
21717 + * page fault when examined during a TLB load attempt. this is true not only
21718 + * for PTEs holding a non-present entry but also present entries that will
21719 + * raise a page fault (such as those set up by PaX, or the copy-on-write
21720 + * mechanism). in effect it means that we do *not* need to flush the TLBs
21721 + * for our target pages since their PTEs are simply not in the TLBs at all.
21722 +
21723 + * the best thing in omitting it is that we gain around 15-20% speed in the
21724 + * fast path of the page fault handler and can get rid of tracing since we
21725 + * can no longer flush unintended entries.
21726 + */
21727 + "invlpg (%0)\n"
21728 +#endif
21729 + __copyuser_seg"testb $0,(%0)\n"
21730 + "xorb %3,(%1)\n"
21731 + :
21732 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21733 + : "memory", "cc");
21734 + pte_unmap_unlock(pte, ptl);
21735 + up_read(&mm->mmap_sem);
21736 + return 1;
21737 +}
21738 +#endif
21739 +
21740 /*
21741 * Handle a spurious fault caused by a stale TLB entry.
21742 *
21743 @@ -962,6 +1151,9 @@ int show_unhandled_signals = 1;
21744 static inline int
21745 access_error(unsigned long error_code, struct vm_area_struct *vma)
21746 {
21747 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21748 + return 1;
21749 +
21750 if (error_code & PF_WRITE) {
21751 /* write, present and write, not present: */
21752 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21753 @@ -995,18 +1187,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
21754 {
21755 struct vm_area_struct *vma;
21756 struct task_struct *tsk;
21757 - unsigned long address;
21758 struct mm_struct *mm;
21759 int fault;
21760 int write = error_code & PF_WRITE;
21761 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
21762 (write ? FAULT_FLAG_WRITE : 0);
21763
21764 - tsk = current;
21765 - mm = tsk->mm;
21766 -
21767 /* Get the faulting address: */
21768 - address = read_cr2();
21769 + unsigned long address = read_cr2();
21770 +
21771 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21772 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21773 + if (!search_exception_tables(regs->ip)) {
21774 + bad_area_nosemaphore(regs, error_code, address);
21775 + return;
21776 + }
21777 + if (address < PAX_USER_SHADOW_BASE) {
21778 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21779 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
21780 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21781 + } else
21782 + address -= PAX_USER_SHADOW_BASE;
21783 + }
21784 +#endif
21785 +
21786 + tsk = current;
21787 + mm = tsk->mm;
21788
21789 /*
21790 * Detect and handle instructions that would cause a page fault for
21791 @@ -1067,7 +1273,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
21792 * User-mode registers count as a user access even for any
21793 * potential system fault or CPU buglet:
21794 */
21795 - if (user_mode_vm(regs)) {
21796 + if (user_mode(regs)) {
21797 local_irq_enable();
21798 error_code |= PF_USER;
21799 } else {
21800 @@ -1122,6 +1328,11 @@ retry:
21801 might_sleep();
21802 }
21803
21804 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21805 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
21806 + return;
21807 +#endif
21808 +
21809 vma = find_vma(mm, address);
21810 if (unlikely(!vma)) {
21811 bad_area(regs, error_code, address);
21812 @@ -1133,18 +1344,24 @@ retry:
21813 bad_area(regs, error_code, address);
21814 return;
21815 }
21816 - if (error_code & PF_USER) {
21817 - /*
21818 - * Accessing the stack below %sp is always a bug.
21819 - * The large cushion allows instructions like enter
21820 - * and pusha to work. ("enter $65535, $31" pushes
21821 - * 32 pointers and then decrements %sp by 65535.)
21822 - */
21823 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
21824 - bad_area(regs, error_code, address);
21825 - return;
21826 - }
21827 + /*
21828 + * Accessing the stack below %sp is always a bug.
21829 + * The large cushion allows instructions like enter
21830 + * and pusha to work. ("enter $65535, $31" pushes
21831 + * 32 pointers and then decrements %sp by 65535.)
21832 + */
21833 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
21834 + bad_area(regs, error_code, address);
21835 + return;
21836 }
21837 +
21838 +#ifdef CONFIG_PAX_SEGMEXEC
21839 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
21840 + bad_area(regs, error_code, address);
21841 + return;
21842 + }
21843 +#endif
21844 +
21845 if (unlikely(expand_stack(vma, address))) {
21846 bad_area(regs, error_code, address);
21847 return;
21848 @@ -1199,3 +1416,292 @@ good_area:
21849
21850 up_read(&mm->mmap_sem);
21851 }
21852 +
21853 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21854 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
21855 +{
21856 + struct mm_struct *mm = current->mm;
21857 + unsigned long ip = regs->ip;
21858 +
21859 + if (v8086_mode(regs))
21860 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
21861 +
21862 +#ifdef CONFIG_PAX_PAGEEXEC
21863 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
21864 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
21865 + return true;
21866 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
21867 + return true;
21868 + return false;
21869 + }
21870 +#endif
21871 +
21872 +#ifdef CONFIG_PAX_SEGMEXEC
21873 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
21874 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
21875 + return true;
21876 + return false;
21877 + }
21878 +#endif
21879 +
21880 + return false;
21881 +}
21882 +#endif
21883 +
21884 +#ifdef CONFIG_PAX_EMUTRAMP
21885 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
21886 +{
21887 + int err;
21888 +
21889 + do { /* PaX: libffi trampoline emulation */
21890 + unsigned char mov, jmp;
21891 + unsigned int addr1, addr2;
21892 +
21893 +#ifdef CONFIG_X86_64
21894 + if ((regs->ip + 9) >> 32)
21895 + break;
21896 +#endif
21897 +
21898 + err = get_user(mov, (unsigned char __user *)regs->ip);
21899 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21900 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21901 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21902 +
21903 + if (err)
21904 + break;
21905 +
21906 + if (mov == 0xB8 && jmp == 0xE9) {
21907 + regs->ax = addr1;
21908 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21909 + return 2;
21910 + }
21911 + } while (0);
21912 +
21913 + do { /* PaX: gcc trampoline emulation #1 */
21914 + unsigned char mov1, mov2;
21915 + unsigned short jmp;
21916 + unsigned int addr1, addr2;
21917 +
21918 +#ifdef CONFIG_X86_64
21919 + if ((regs->ip + 11) >> 32)
21920 + break;
21921 +#endif
21922 +
21923 + err = get_user(mov1, (unsigned char __user *)regs->ip);
21924 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21925 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
21926 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21927 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
21928 +
21929 + if (err)
21930 + break;
21931 +
21932 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
21933 + regs->cx = addr1;
21934 + regs->ax = addr2;
21935 + regs->ip = addr2;
21936 + return 2;
21937 + }
21938 + } while (0);
21939 +
21940 + do { /* PaX: gcc trampoline emulation #2 */
21941 + unsigned char mov, jmp;
21942 + unsigned int addr1, addr2;
21943 +
21944 +#ifdef CONFIG_X86_64
21945 + if ((regs->ip + 9) >> 32)
21946 + break;
21947 +#endif
21948 +
21949 + err = get_user(mov, (unsigned char __user *)regs->ip);
21950 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21951 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21952 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21953 +
21954 + if (err)
21955 + break;
21956 +
21957 + if (mov == 0xB9 && jmp == 0xE9) {
21958 + regs->cx = addr1;
21959 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21960 + return 2;
21961 + }
21962 + } while (0);
21963 +
21964 + return 1; /* PaX in action */
21965 +}
21966 +
21967 +#ifdef CONFIG_X86_64
21968 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
21969 +{
21970 + int err;
21971 +
21972 + do { /* PaX: libffi trampoline emulation */
21973 + unsigned short mov1, mov2, jmp1;
21974 + unsigned char stcclc, jmp2;
21975 + unsigned long addr1, addr2;
21976 +
21977 + err = get_user(mov1, (unsigned short __user *)regs->ip);
21978 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
21979 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
21980 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
21981 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
21982 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
21983 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
21984 +
21985 + if (err)
21986 + break;
21987 +
21988 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21989 + regs->r11 = addr1;
21990 + regs->r10 = addr2;
21991 + if (stcclc == 0xF8)
21992 + regs->flags &= ~X86_EFLAGS_CF;
21993 + else
21994 + regs->flags |= X86_EFLAGS_CF;
21995 + regs->ip = addr1;
21996 + return 2;
21997 + }
21998 + } while (0);
21999 +
22000 + do { /* PaX: gcc trampoline emulation #1 */
22001 + unsigned short mov1, mov2, jmp1;
22002 + unsigned char jmp2;
22003 + unsigned int addr1;
22004 + unsigned long addr2;
22005 +
22006 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22007 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
22008 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
22009 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
22010 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
22011 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
22012 +
22013 + if (err)
22014 + break;
22015 +
22016 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22017 + regs->r11 = addr1;
22018 + regs->r10 = addr2;
22019 + regs->ip = addr1;
22020 + return 2;
22021 + }
22022 + } while (0);
22023 +
22024 + do { /* PaX: gcc trampoline emulation #2 */
22025 + unsigned short mov1, mov2, jmp1;
22026 + unsigned char jmp2;
22027 + unsigned long addr1, addr2;
22028 +
22029 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22030 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
22031 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
22032 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
22033 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
22034 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
22035 +
22036 + if (err)
22037 + break;
22038 +
22039 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22040 + regs->r11 = addr1;
22041 + regs->r10 = addr2;
22042 + regs->ip = addr1;
22043 + return 2;
22044 + }
22045 + } while (0);
22046 +
22047 + return 1; /* PaX in action */
22048 +}
22049 +#endif
22050 +
22051 +/*
22052 + * PaX: decide what to do with offenders (regs->ip = fault address)
22053 + *
22054 + * returns 1 when task should be killed
22055 + * 2 when gcc trampoline was detected
22056 + */
22057 +static int pax_handle_fetch_fault(struct pt_regs *regs)
22058 +{
22059 + if (v8086_mode(regs))
22060 + return 1;
22061 +
22062 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
22063 + return 1;
22064 +
22065 +#ifdef CONFIG_X86_32
22066 + return pax_handle_fetch_fault_32(regs);
22067 +#else
22068 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
22069 + return pax_handle_fetch_fault_32(regs);
22070 + else
22071 + return pax_handle_fetch_fault_64(regs);
22072 +#endif
22073 +}
22074 +#endif
22075 +
22076 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22077 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
22078 +{
22079 + long i;
22080 +
22081 + printk(KERN_ERR "PAX: bytes at PC: ");
22082 + for (i = 0; i < 20; i++) {
22083 + unsigned char c;
22084 + if (get_user(c, (unsigned char __force_user *)pc+i))
22085 + printk(KERN_CONT "?? ");
22086 + else
22087 + printk(KERN_CONT "%02x ", c);
22088 + }
22089 + printk("\n");
22090 +
22091 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
22092 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
22093 + unsigned long c;
22094 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
22095 +#ifdef CONFIG_X86_32
22096 + printk(KERN_CONT "???????? ");
22097 +#else
22098 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
22099 + printk(KERN_CONT "???????? ???????? ");
22100 + else
22101 + printk(KERN_CONT "???????????????? ");
22102 +#endif
22103 + } else {
22104 +#ifdef CONFIG_X86_64
22105 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
22106 + printk(KERN_CONT "%08x ", (unsigned int)c);
22107 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
22108 + } else
22109 +#endif
22110 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
22111 + }
22112 + }
22113 + printk("\n");
22114 +}
22115 +#endif
22116 +
22117 +/**
22118 + * probe_kernel_write(): safely attempt to write to a location
22119 + * @dst: address to write to
22120 + * @src: pointer to the data that shall be written
22121 + * @size: size of the data chunk
22122 + *
22123 + * Safely write to address @dst from the buffer at @src. If a kernel fault
22124 + * happens, handle that and return -EFAULT.
22125 + */
22126 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
22127 +{
22128 + long ret;
22129 + mm_segment_t old_fs = get_fs();
22130 +
22131 + set_fs(KERNEL_DS);
22132 + pagefault_disable();
22133 + pax_open_kernel();
22134 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
22135 + pax_close_kernel();
22136 + pagefault_enable();
22137 + set_fs(old_fs);
22138 +
22139 + return ret ? -EFAULT : 0;
22140 +}
22141 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
22142 index dd74e46..7d26398 100644
22143 --- a/arch/x86/mm/gup.c
22144 +++ b/arch/x86/mm/gup.c
22145 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
22146 addr = start;
22147 len = (unsigned long) nr_pages << PAGE_SHIFT;
22148 end = start + len;
22149 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22150 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22151 (void __user *)start, len)))
22152 return 0;
22153
22154 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
22155 index f4f29b1..5cac4fb 100644
22156 --- a/arch/x86/mm/highmem_32.c
22157 +++ b/arch/x86/mm/highmem_32.c
22158 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
22159 idx = type + KM_TYPE_NR*smp_processor_id();
22160 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22161 BUG_ON(!pte_none(*(kmap_pte-idx)));
22162 +
22163 + pax_open_kernel();
22164 set_pte(kmap_pte-idx, mk_pte(page, prot));
22165 + pax_close_kernel();
22166 +
22167 arch_flush_lazy_mmu_mode();
22168
22169 return (void *)vaddr;
22170 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
22171 index f581a18..29efd37 100644
22172 --- a/arch/x86/mm/hugetlbpage.c
22173 +++ b/arch/x86/mm/hugetlbpage.c
22174 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
22175 struct hstate *h = hstate_file(file);
22176 struct mm_struct *mm = current->mm;
22177 struct vm_area_struct *vma;
22178 - unsigned long start_addr;
22179 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22180 +
22181 +#ifdef CONFIG_PAX_SEGMEXEC
22182 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22183 + pax_task_size = SEGMEXEC_TASK_SIZE;
22184 +#endif
22185 +
22186 + pax_task_size -= PAGE_SIZE;
22187
22188 if (len > mm->cached_hole_size) {
22189 - start_addr = mm->free_area_cache;
22190 + start_addr = mm->free_area_cache;
22191 } else {
22192 - start_addr = TASK_UNMAPPED_BASE;
22193 - mm->cached_hole_size = 0;
22194 + start_addr = mm->mmap_base;
22195 + mm->cached_hole_size = 0;
22196 }
22197
22198 full_search:
22199 @@ -280,26 +287,27 @@ full_search:
22200
22201 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22202 /* At this point: (!vma || addr < vma->vm_end). */
22203 - if (TASK_SIZE - len < addr) {
22204 + if (pax_task_size - len < addr) {
22205 /*
22206 * Start a new search - just in case we missed
22207 * some holes.
22208 */
22209 - if (start_addr != TASK_UNMAPPED_BASE) {
22210 - start_addr = TASK_UNMAPPED_BASE;
22211 + if (start_addr != mm->mmap_base) {
22212 + start_addr = mm->mmap_base;
22213 mm->cached_hole_size = 0;
22214 goto full_search;
22215 }
22216 return -ENOMEM;
22217 }
22218 - if (!vma || addr + len <= vma->vm_start) {
22219 - mm->free_area_cache = addr + len;
22220 - return addr;
22221 - }
22222 + if (check_heap_stack_gap(vma, addr, len))
22223 + break;
22224 if (addr + mm->cached_hole_size < vma->vm_start)
22225 mm->cached_hole_size = vma->vm_start - addr;
22226 addr = ALIGN(vma->vm_end, huge_page_size(h));
22227 }
22228 +
22229 + mm->free_area_cache = addr + len;
22230 + return addr;
22231 }
22232
22233 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22234 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22235 {
22236 struct hstate *h = hstate_file(file);
22237 struct mm_struct *mm = current->mm;
22238 - struct vm_area_struct *vma, *prev_vma;
22239 - unsigned long base = mm->mmap_base, addr = addr0;
22240 + struct vm_area_struct *vma;
22241 + unsigned long base = mm->mmap_base, addr;
22242 unsigned long largest_hole = mm->cached_hole_size;
22243 - int first_time = 1;
22244
22245 /* don't allow allocations above current base */
22246 if (mm->free_area_cache > base)
22247 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22248 largest_hole = 0;
22249 mm->free_area_cache = base;
22250 }
22251 -try_again:
22252 +
22253 /* make sure it can fit in the remaining address space */
22254 if (mm->free_area_cache < len)
22255 goto fail;
22256
22257 /* either no address requested or can't fit in requested address hole */
22258 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
22259 + addr = (mm->free_area_cache - len);
22260 do {
22261 + addr &= huge_page_mask(h);
22262 + vma = find_vma(mm, addr);
22263 /*
22264 * Lookup failure means no vma is above this address,
22265 * i.e. return with success:
22266 - */
22267 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
22268 - return addr;
22269 -
22270 - /*
22271 * new region fits between prev_vma->vm_end and
22272 * vma->vm_start, use it:
22273 */
22274 - if (addr + len <= vma->vm_start &&
22275 - (!prev_vma || (addr >= prev_vma->vm_end))) {
22276 + if (check_heap_stack_gap(vma, addr, len)) {
22277 /* remember the address as a hint for next time */
22278 - mm->cached_hole_size = largest_hole;
22279 - return (mm->free_area_cache = addr);
22280 - } else {
22281 - /* pull free_area_cache down to the first hole */
22282 - if (mm->free_area_cache == vma->vm_end) {
22283 - mm->free_area_cache = vma->vm_start;
22284 - mm->cached_hole_size = largest_hole;
22285 - }
22286 + mm->cached_hole_size = largest_hole;
22287 + return (mm->free_area_cache = addr);
22288 + }
22289 + /* pull free_area_cache down to the first hole */
22290 + if (mm->free_area_cache == vma->vm_end) {
22291 + mm->free_area_cache = vma->vm_start;
22292 + mm->cached_hole_size = largest_hole;
22293 }
22294
22295 /* remember the largest hole we saw so far */
22296 if (addr + largest_hole < vma->vm_start)
22297 - largest_hole = vma->vm_start - addr;
22298 + largest_hole = vma->vm_start - addr;
22299
22300 /* try just below the current vma->vm_start */
22301 - addr = (vma->vm_start - len) & huge_page_mask(h);
22302 - } while (len <= vma->vm_start);
22303 + addr = skip_heap_stack_gap(vma, len);
22304 + } while (!IS_ERR_VALUE(addr));
22305
22306 fail:
22307 /*
22308 - * if hint left us with no space for the requested
22309 - * mapping then try again:
22310 - */
22311 - if (first_time) {
22312 - mm->free_area_cache = base;
22313 - largest_hole = 0;
22314 - first_time = 0;
22315 - goto try_again;
22316 - }
22317 - /*
22318 * A failed mmap() very likely causes application failure,
22319 * so fall back to the bottom-up function here. This scenario
22320 * can happen with large stack limits and large mmap()
22321 * allocations.
22322 */
22323 - mm->free_area_cache = TASK_UNMAPPED_BASE;
22324 +
22325 +#ifdef CONFIG_PAX_SEGMEXEC
22326 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22327 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22328 + else
22329 +#endif
22330 +
22331 + mm->mmap_base = TASK_UNMAPPED_BASE;
22332 +
22333 +#ifdef CONFIG_PAX_RANDMMAP
22334 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22335 + mm->mmap_base += mm->delta_mmap;
22336 +#endif
22337 +
22338 + mm->free_area_cache = mm->mmap_base;
22339 mm->cached_hole_size = ~0UL;
22340 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
22341 len, pgoff, flags);
22342 @@ -386,6 +392,7 @@ fail:
22343 /*
22344 * Restore the topdown base:
22345 */
22346 + mm->mmap_base = base;
22347 mm->free_area_cache = base;
22348 mm->cached_hole_size = ~0UL;
22349
22350 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
22351 struct hstate *h = hstate_file(file);
22352 struct mm_struct *mm = current->mm;
22353 struct vm_area_struct *vma;
22354 + unsigned long pax_task_size = TASK_SIZE;
22355
22356 if (len & ~huge_page_mask(h))
22357 return -EINVAL;
22358 - if (len > TASK_SIZE)
22359 +
22360 +#ifdef CONFIG_PAX_SEGMEXEC
22361 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22362 + pax_task_size = SEGMEXEC_TASK_SIZE;
22363 +#endif
22364 +
22365 + pax_task_size -= PAGE_SIZE;
22366 +
22367 + if (len > pax_task_size)
22368 return -ENOMEM;
22369
22370 if (flags & MAP_FIXED) {
22371 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
22372 if (addr) {
22373 addr = ALIGN(addr, huge_page_size(h));
22374 vma = find_vma(mm, addr);
22375 - if (TASK_SIZE - len >= addr &&
22376 - (!vma || addr + len <= vma->vm_start))
22377 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
22378 return addr;
22379 }
22380 if (mm->get_unmapped_area == arch_get_unmapped_area)
22381 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
22382 index 87488b9..a55509f 100644
22383 --- a/arch/x86/mm/init.c
22384 +++ b/arch/x86/mm/init.c
22385 @@ -15,6 +15,7 @@
22386 #include <asm/tlbflush.h>
22387 #include <asm/tlb.h>
22388 #include <asm/proto.h>
22389 +#include <asm/desc.h>
22390
22391 unsigned long __initdata pgt_buf_start;
22392 unsigned long __meminitdata pgt_buf_end;
22393 @@ -31,7 +32,7 @@ int direct_gbpages
22394 static void __init find_early_table_space(unsigned long end, int use_pse,
22395 int use_gbpages)
22396 {
22397 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
22398 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
22399 phys_addr_t base;
22400
22401 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
22402 @@ -312,8 +313,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
22403 */
22404 int devmem_is_allowed(unsigned long pagenr)
22405 {
22406 +#ifdef CONFIG_GRKERNSEC_KMEM
22407 + /* allow BDA */
22408 + if (!pagenr)
22409 + return 1;
22410 + /* allow EBDA */
22411 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
22412 + return 1;
22413 +#else
22414 + if (!pagenr)
22415 + return 1;
22416 +#ifdef CONFIG_VM86
22417 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22418 + return 1;
22419 +#endif
22420 +#endif
22421 +
22422 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22423 + return 1;
22424 +#ifdef CONFIG_GRKERNSEC_KMEM
22425 + /* throw out everything else below 1MB */
22426 if (pagenr <= 256)
22427 - return 1;
22428 + return 0;
22429 +#endif
22430 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22431 return 0;
22432 if (!page_is_ram(pagenr))
22433 @@ -372,6 +394,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
22434
22435 void free_initmem(void)
22436 {
22437 +
22438 +#ifdef CONFIG_PAX_KERNEXEC
22439 +#ifdef CONFIG_X86_32
22440 + /* PaX: limit KERNEL_CS to actual size */
22441 + unsigned long addr, limit;
22442 + struct desc_struct d;
22443 + int cpu;
22444 +
22445 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22446 + limit = (limit - 1UL) >> PAGE_SHIFT;
22447 +
22448 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22449 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
22450 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22451 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22452 + }
22453 +
22454 + /* PaX: make KERNEL_CS read-only */
22455 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22456 + if (!paravirt_enabled())
22457 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22458 +/*
22459 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22460 + pgd = pgd_offset_k(addr);
22461 + pud = pud_offset(pgd, addr);
22462 + pmd = pmd_offset(pud, addr);
22463 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22464 + }
22465 +*/
22466 +#ifdef CONFIG_X86_PAE
22467 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22468 +/*
22469 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22470 + pgd = pgd_offset_k(addr);
22471 + pud = pud_offset(pgd, addr);
22472 + pmd = pmd_offset(pud, addr);
22473 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22474 + }
22475 +*/
22476 +#endif
22477 +
22478 +#ifdef CONFIG_MODULES
22479 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22480 +#endif
22481 +
22482 +#else
22483 + pgd_t *pgd;
22484 + pud_t *pud;
22485 + pmd_t *pmd;
22486 + unsigned long addr, end;
22487 +
22488 + /* PaX: make kernel code/rodata read-only, rest non-executable */
22489 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22490 + pgd = pgd_offset_k(addr);
22491 + pud = pud_offset(pgd, addr);
22492 + pmd = pmd_offset(pud, addr);
22493 + if (!pmd_present(*pmd))
22494 + continue;
22495 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22496 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22497 + else
22498 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22499 + }
22500 +
22501 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22502 + end = addr + KERNEL_IMAGE_SIZE;
22503 + for (; addr < end; addr += PMD_SIZE) {
22504 + pgd = pgd_offset_k(addr);
22505 + pud = pud_offset(pgd, addr);
22506 + pmd = pmd_offset(pud, addr);
22507 + if (!pmd_present(*pmd))
22508 + continue;
22509 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22510 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22511 + }
22512 +#endif
22513 +
22514 + flush_tlb_all();
22515 +#endif
22516 +
22517 free_init_pages("unused kernel memory",
22518 (unsigned long)(&__init_begin),
22519 (unsigned long)(&__init_end));
22520 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
22521 index 29f7c6d..b46b35b 100644
22522 --- a/arch/x86/mm/init_32.c
22523 +++ b/arch/x86/mm/init_32.c
22524 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
22525 }
22526
22527 /*
22528 - * Creates a middle page table and puts a pointer to it in the
22529 - * given global directory entry. This only returns the gd entry
22530 - * in non-PAE compilation mode, since the middle layer is folded.
22531 - */
22532 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
22533 -{
22534 - pud_t *pud;
22535 - pmd_t *pmd_table;
22536 -
22537 -#ifdef CONFIG_X86_PAE
22538 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
22539 - if (after_bootmem)
22540 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
22541 - else
22542 - pmd_table = (pmd_t *)alloc_low_page();
22543 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
22544 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
22545 - pud = pud_offset(pgd, 0);
22546 - BUG_ON(pmd_table != pmd_offset(pud, 0));
22547 -
22548 - return pmd_table;
22549 - }
22550 -#endif
22551 - pud = pud_offset(pgd, 0);
22552 - pmd_table = pmd_offset(pud, 0);
22553 -
22554 - return pmd_table;
22555 -}
22556 -
22557 -/*
22558 * Create a page table and place a pointer to it in a middle page
22559 * directory entry:
22560 */
22561 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
22562 page_table = (pte_t *)alloc_low_page();
22563
22564 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
22565 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22566 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
22567 +#else
22568 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
22569 +#endif
22570 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
22571 }
22572
22573 return pte_offset_kernel(pmd, 0);
22574 }
22575
22576 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
22577 +{
22578 + pud_t *pud;
22579 + pmd_t *pmd_table;
22580 +
22581 + pud = pud_offset(pgd, 0);
22582 + pmd_table = pmd_offset(pud, 0);
22583 +
22584 + return pmd_table;
22585 +}
22586 +
22587 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
22588 {
22589 int pgd_idx = pgd_index(vaddr);
22590 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22591 int pgd_idx, pmd_idx;
22592 unsigned long vaddr;
22593 pgd_t *pgd;
22594 + pud_t *pud;
22595 pmd_t *pmd;
22596 pte_t *pte = NULL;
22597
22598 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22599 pgd = pgd_base + pgd_idx;
22600
22601 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
22602 - pmd = one_md_table_init(pgd);
22603 - pmd = pmd + pmd_index(vaddr);
22604 + pud = pud_offset(pgd, vaddr);
22605 + pmd = pmd_offset(pud, vaddr);
22606 +
22607 +#ifdef CONFIG_X86_PAE
22608 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22609 +#endif
22610 +
22611 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
22612 pmd++, pmd_idx++) {
22613 pte = page_table_kmap_check(one_page_table_init(pmd),
22614 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22615 }
22616 }
22617
22618 -static inline int is_kernel_text(unsigned long addr)
22619 +static inline int is_kernel_text(unsigned long start, unsigned long end)
22620 {
22621 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
22622 - return 1;
22623 - return 0;
22624 + if ((start > ktla_ktva((unsigned long)_etext) ||
22625 + end <= ktla_ktva((unsigned long)_stext)) &&
22626 + (start > ktla_ktva((unsigned long)_einittext) ||
22627 + end <= ktla_ktva((unsigned long)_sinittext)) &&
22628 +
22629 +#ifdef CONFIG_ACPI_SLEEP
22630 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
22631 +#endif
22632 +
22633 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
22634 + return 0;
22635 + return 1;
22636 }
22637
22638 /*
22639 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
22640 unsigned long last_map_addr = end;
22641 unsigned long start_pfn, end_pfn;
22642 pgd_t *pgd_base = swapper_pg_dir;
22643 - int pgd_idx, pmd_idx, pte_ofs;
22644 + unsigned int pgd_idx, pmd_idx, pte_ofs;
22645 unsigned long pfn;
22646 pgd_t *pgd;
22647 + pud_t *pud;
22648 pmd_t *pmd;
22649 pte_t *pte;
22650 unsigned pages_2m, pages_4k;
22651 @@ -281,8 +282,13 @@ repeat:
22652 pfn = start_pfn;
22653 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22654 pgd = pgd_base + pgd_idx;
22655 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
22656 - pmd = one_md_table_init(pgd);
22657 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
22658 + pud = pud_offset(pgd, 0);
22659 + pmd = pmd_offset(pud, 0);
22660 +
22661 +#ifdef CONFIG_X86_PAE
22662 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22663 +#endif
22664
22665 if (pfn >= end_pfn)
22666 continue;
22667 @@ -294,14 +300,13 @@ repeat:
22668 #endif
22669 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
22670 pmd++, pmd_idx++) {
22671 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
22672 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
22673
22674 /*
22675 * Map with big pages if possible, otherwise
22676 * create normal page tables:
22677 */
22678 if (use_pse) {
22679 - unsigned int addr2;
22680 pgprot_t prot = PAGE_KERNEL_LARGE;
22681 /*
22682 * first pass will use the same initial
22683 @@ -311,11 +316,7 @@ repeat:
22684 __pgprot(PTE_IDENT_ATTR |
22685 _PAGE_PSE);
22686
22687 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
22688 - PAGE_OFFSET + PAGE_SIZE-1;
22689 -
22690 - if (is_kernel_text(addr) ||
22691 - is_kernel_text(addr2))
22692 + if (is_kernel_text(address, address + PMD_SIZE))
22693 prot = PAGE_KERNEL_LARGE_EXEC;
22694
22695 pages_2m++;
22696 @@ -332,7 +333,7 @@ repeat:
22697 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22698 pte += pte_ofs;
22699 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
22700 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
22701 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
22702 pgprot_t prot = PAGE_KERNEL;
22703 /*
22704 * first pass will use the same initial
22705 @@ -340,7 +341,7 @@ repeat:
22706 */
22707 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
22708
22709 - if (is_kernel_text(addr))
22710 + if (is_kernel_text(address, address + PAGE_SIZE))
22711 prot = PAGE_KERNEL_EXEC;
22712
22713 pages_4k++;
22714 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
22715
22716 pud = pud_offset(pgd, va);
22717 pmd = pmd_offset(pud, va);
22718 - if (!pmd_present(*pmd))
22719 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
22720 break;
22721
22722 pte = pte_offset_kernel(pmd, va);
22723 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_range_init(void)
22724
22725 static void __init pagetable_init(void)
22726 {
22727 - pgd_t *pgd_base = swapper_pg_dir;
22728 -
22729 - permanent_kmaps_init(pgd_base);
22730 + permanent_kmaps_init(swapper_pg_dir);
22731 }
22732
22733 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22734 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22735 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22736
22737 /* user-defined highmem size */
22738 @@ -757,6 +756,12 @@ void __init mem_init(void)
22739
22740 pci_iommu_alloc();
22741
22742 +#ifdef CONFIG_PAX_PER_CPU_PGD
22743 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22744 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22745 + KERNEL_PGD_PTRS);
22746 +#endif
22747 +
22748 #ifdef CONFIG_FLATMEM
22749 BUG_ON(!mem_map);
22750 #endif
22751 @@ -774,7 +779,7 @@ void __init mem_init(void)
22752 set_highmem_pages_init();
22753
22754 codesize = (unsigned long) &_etext - (unsigned long) &_text;
22755 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
22756 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
22757 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
22758
22759 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
22760 @@ -815,10 +820,10 @@ void __init mem_init(void)
22761 ((unsigned long)&__init_end -
22762 (unsigned long)&__init_begin) >> 10,
22763
22764 - (unsigned long)&_etext, (unsigned long)&_edata,
22765 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
22766 + (unsigned long)&_sdata, (unsigned long)&_edata,
22767 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
22768
22769 - (unsigned long)&_text, (unsigned long)&_etext,
22770 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
22771 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
22772
22773 /*
22774 @@ -896,6 +901,7 @@ void set_kernel_text_rw(void)
22775 if (!kernel_set_to_readonly)
22776 return;
22777
22778 + start = ktla_ktva(start);
22779 pr_debug("Set kernel text: %lx - %lx for read write\n",
22780 start, start+size);
22781
22782 @@ -910,6 +916,7 @@ void set_kernel_text_ro(void)
22783 if (!kernel_set_to_readonly)
22784 return;
22785
22786 + start = ktla_ktva(start);
22787 pr_debug("Set kernel text: %lx - %lx for read only\n",
22788 start, start+size);
22789
22790 @@ -938,6 +945,7 @@ void mark_rodata_ro(void)
22791 unsigned long start = PFN_ALIGN(_text);
22792 unsigned long size = PFN_ALIGN(_etext) - start;
22793
22794 + start = ktla_ktva(start);
22795 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
22796 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
22797 size >> 10);
22798 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
22799 index bbaaa00..16dffad 100644
22800 --- a/arch/x86/mm/init_64.c
22801 +++ b/arch/x86/mm/init_64.c
22802 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
22803 * around without checking the pgd every time.
22804 */
22805
22806 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
22807 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
22808 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22809
22810 int force_personality32;
22811 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
22812
22813 for (address = start; address <= end; address += PGDIR_SIZE) {
22814 const pgd_t *pgd_ref = pgd_offset_k(address);
22815 +
22816 +#ifdef CONFIG_PAX_PER_CPU_PGD
22817 + unsigned long cpu;
22818 +#else
22819 struct page *page;
22820 +#endif
22821
22822 if (pgd_none(*pgd_ref))
22823 continue;
22824
22825 spin_lock(&pgd_lock);
22826 +
22827 +#ifdef CONFIG_PAX_PER_CPU_PGD
22828 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22829 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
22830 +#else
22831 list_for_each_entry(page, &pgd_list, lru) {
22832 pgd_t *pgd;
22833 spinlock_t *pgt_lock;
22834 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
22835 /* the pgt_lock only for Xen */
22836 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22837 spin_lock(pgt_lock);
22838 +#endif
22839
22840 if (pgd_none(*pgd))
22841 set_pgd(pgd, *pgd_ref);
22842 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
22843 BUG_ON(pgd_page_vaddr(*pgd)
22844 != pgd_page_vaddr(*pgd_ref));
22845
22846 +#ifndef CONFIG_PAX_PER_CPU_PGD
22847 spin_unlock(pgt_lock);
22848 +#endif
22849 +
22850 }
22851 spin_unlock(&pgd_lock);
22852 }
22853 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
22854 pmd = fill_pmd(pud, vaddr);
22855 pte = fill_pte(pmd, vaddr);
22856
22857 + pax_open_kernel();
22858 set_pte(pte, new_pte);
22859 + pax_close_kernel();
22860
22861 /*
22862 * It's enough to flush this one mapping.
22863 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
22864 pgd = pgd_offset_k((unsigned long)__va(phys));
22865 if (pgd_none(*pgd)) {
22866 pud = (pud_t *) spp_getpage();
22867 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
22868 - _PAGE_USER));
22869 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
22870 }
22871 pud = pud_offset(pgd, (unsigned long)__va(phys));
22872 if (pud_none(*pud)) {
22873 pmd = (pmd_t *) spp_getpage();
22874 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
22875 - _PAGE_USER));
22876 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
22877 }
22878 pmd = pmd_offset(pud, phys);
22879 BUG_ON(!pmd_none(*pmd));
22880 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
22881 if (pfn >= pgt_buf_top)
22882 panic("alloc_low_page: ran out of memory");
22883
22884 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
22885 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
22886 clear_page(adr);
22887 *phys = pfn * PAGE_SIZE;
22888 return adr;
22889 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
22890
22891 phys = __pa(virt);
22892 left = phys & (PAGE_SIZE - 1);
22893 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
22894 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
22895 adr = (void *)(((unsigned long)adr) | left);
22896
22897 return adr;
22898 @@ -693,6 +707,12 @@ void __init mem_init(void)
22899
22900 pci_iommu_alloc();
22901
22902 +#ifdef CONFIG_PAX_PER_CPU_PGD
22903 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22904 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22905 + KERNEL_PGD_PTRS);
22906 +#endif
22907 +
22908 /* clear_bss() already clear the empty_zero_page */
22909
22910 reservedpages = 0;
22911 @@ -853,8 +873,8 @@ int kern_addr_valid(unsigned long addr)
22912 static struct vm_area_struct gate_vma = {
22913 .vm_start = VSYSCALL_START,
22914 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
22915 - .vm_page_prot = PAGE_READONLY_EXEC,
22916 - .vm_flags = VM_READ | VM_EXEC
22917 + .vm_page_prot = PAGE_READONLY,
22918 + .vm_flags = VM_READ
22919 };
22920
22921 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
22922 @@ -888,7 +908,7 @@ int in_gate_area_no_mm(unsigned long addr)
22923
22924 const char *arch_vma_name(struct vm_area_struct *vma)
22925 {
22926 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
22927 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
22928 return "[vdso]";
22929 if (vma == &gate_vma)
22930 return "[vsyscall]";
22931 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
22932 index 7b179b4..6bd1777 100644
22933 --- a/arch/x86/mm/iomap_32.c
22934 +++ b/arch/x86/mm/iomap_32.c
22935 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
22936 type = kmap_atomic_idx_push();
22937 idx = type + KM_TYPE_NR * smp_processor_id();
22938 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22939 +
22940 + pax_open_kernel();
22941 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
22942 + pax_close_kernel();
22943 +
22944 arch_flush_lazy_mmu_mode();
22945
22946 return (void *)vaddr;
22947 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
22948 index be1ef57..9680edc 100644
22949 --- a/arch/x86/mm/ioremap.c
22950 +++ b/arch/x86/mm/ioremap.c
22951 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
22952 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
22953 int is_ram = page_is_ram(pfn);
22954
22955 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
22956 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
22957 return NULL;
22958 WARN_ON_ONCE(is_ram);
22959 }
22960 @@ -344,7 +344,7 @@ static int __init early_ioremap_debug_setup(char *str)
22961 early_param("early_ioremap_debug", early_ioremap_debug_setup);
22962
22963 static __initdata int after_paging_init;
22964 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
22965 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
22966
22967 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
22968 {
22969 @@ -381,8 +381,7 @@ void __init early_ioremap_init(void)
22970 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
22971
22972 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
22973 - memset(bm_pte, 0, sizeof(bm_pte));
22974 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
22975 + pmd_populate_user(&init_mm, pmd, bm_pte);
22976
22977 /*
22978 * The boot-ioremap range spans multiple pmds, for which
22979 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
22980 index d87dd6d..bf3fa66 100644
22981 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
22982 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
22983 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
22984 * memory (e.g. tracked pages)? For now, we need this to avoid
22985 * invoking kmemcheck for PnP BIOS calls.
22986 */
22987 - if (regs->flags & X86_VM_MASK)
22988 + if (v8086_mode(regs))
22989 return false;
22990 - if (regs->cs != __KERNEL_CS)
22991 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
22992 return false;
22993
22994 pte = kmemcheck_pte_lookup(address);
22995 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
22996 index 4b5ba85..f166ad2 100644
22997 --- a/arch/x86/mm/mmap.c
22998 +++ b/arch/x86/mm/mmap.c
22999 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
23000 * Leave an at least ~128 MB hole with possible stack randomization.
23001 */
23002 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
23003 -#define MAX_GAP (TASK_SIZE/6*5)
23004 +#define MAX_GAP (pax_task_size/6*5)
23005
23006 static int mmap_is_legacy(void)
23007 {
23008 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
23009 return rnd << PAGE_SHIFT;
23010 }
23011
23012 -static unsigned long mmap_base(void)
23013 +static unsigned long mmap_base(struct mm_struct *mm)
23014 {
23015 unsigned long gap = rlimit(RLIMIT_STACK);
23016 + unsigned long pax_task_size = TASK_SIZE;
23017 +
23018 +#ifdef CONFIG_PAX_SEGMEXEC
23019 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23020 + pax_task_size = SEGMEXEC_TASK_SIZE;
23021 +#endif
23022
23023 if (gap < MIN_GAP)
23024 gap = MIN_GAP;
23025 else if (gap > MAX_GAP)
23026 gap = MAX_GAP;
23027
23028 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
23029 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
23030 }
23031
23032 /*
23033 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
23034 * does, but not when emulating X86_32
23035 */
23036 -static unsigned long mmap_legacy_base(void)
23037 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
23038 {
23039 - if (mmap_is_ia32())
23040 + if (mmap_is_ia32()) {
23041 +
23042 +#ifdef CONFIG_PAX_SEGMEXEC
23043 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23044 + return SEGMEXEC_TASK_UNMAPPED_BASE;
23045 + else
23046 +#endif
23047 +
23048 return TASK_UNMAPPED_BASE;
23049 - else
23050 + } else
23051 return TASK_UNMAPPED_BASE + mmap_rnd();
23052 }
23053
23054 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
23055 void arch_pick_mmap_layout(struct mm_struct *mm)
23056 {
23057 if (mmap_is_legacy()) {
23058 - mm->mmap_base = mmap_legacy_base();
23059 + mm->mmap_base = mmap_legacy_base(mm);
23060 +
23061 +#ifdef CONFIG_PAX_RANDMMAP
23062 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23063 + mm->mmap_base += mm->delta_mmap;
23064 +#endif
23065 +
23066 mm->get_unmapped_area = arch_get_unmapped_area;
23067 mm->unmap_area = arch_unmap_area;
23068 } else {
23069 - mm->mmap_base = mmap_base();
23070 + mm->mmap_base = mmap_base(mm);
23071 +
23072 +#ifdef CONFIG_PAX_RANDMMAP
23073 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23074 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
23075 +#endif
23076 +
23077 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
23078 mm->unmap_area = arch_unmap_area_topdown;
23079 }
23080 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
23081 index de54b9b..799051e 100644
23082 --- a/arch/x86/mm/mmio-mod.c
23083 +++ b/arch/x86/mm/mmio-mod.c
23084 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
23085 break;
23086 default:
23087 {
23088 - unsigned char *ip = (unsigned char *)instptr;
23089 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
23090 my_trace->opcode = MMIO_UNKNOWN_OP;
23091 my_trace->width = 0;
23092 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
23093 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
23094 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23095 void __iomem *addr)
23096 {
23097 - static atomic_t next_id;
23098 + static atomic_unchecked_t next_id;
23099 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
23100 /* These are page-unaligned. */
23101 struct mmiotrace_map map = {
23102 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23103 .private = trace
23104 },
23105 .phys = offset,
23106 - .id = atomic_inc_return(&next_id)
23107 + .id = atomic_inc_return_unchecked(&next_id)
23108 };
23109 map.map_id = trace->id;
23110
23111 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
23112 index b008656..773eac2 100644
23113 --- a/arch/x86/mm/pageattr-test.c
23114 +++ b/arch/x86/mm/pageattr-test.c
23115 @@ -36,7 +36,7 @@ enum {
23116
23117 static int pte_testbit(pte_t pte)
23118 {
23119 - return pte_flags(pte) & _PAGE_UNUSED1;
23120 + return pte_flags(pte) & _PAGE_CPA_TEST;
23121 }
23122
23123 struct split_state {
23124 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
23125 index f9e5267..6f6e27f 100644
23126 --- a/arch/x86/mm/pageattr.c
23127 +++ b/arch/x86/mm/pageattr.c
23128 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23129 */
23130 #ifdef CONFIG_PCI_BIOS
23131 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
23132 - pgprot_val(forbidden) |= _PAGE_NX;
23133 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23134 #endif
23135
23136 /*
23137 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23138 * Does not cover __inittext since that is gone later on. On
23139 * 64bit we do not enforce !NX on the low mapping
23140 */
23141 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
23142 - pgprot_val(forbidden) |= _PAGE_NX;
23143 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
23144 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23145
23146 +#ifdef CONFIG_DEBUG_RODATA
23147 /*
23148 * The .rodata section needs to be read-only. Using the pfn
23149 * catches all aliases.
23150 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23151 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
23152 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
23153 pgprot_val(forbidden) |= _PAGE_RW;
23154 +#endif
23155
23156 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
23157 /*
23158 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23159 }
23160 #endif
23161
23162 +#ifdef CONFIG_PAX_KERNEXEC
23163 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
23164 + pgprot_val(forbidden) |= _PAGE_RW;
23165 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23166 + }
23167 +#endif
23168 +
23169 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
23170
23171 return prot;
23172 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
23173 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
23174 {
23175 /* change init_mm */
23176 + pax_open_kernel();
23177 set_pte_atomic(kpte, pte);
23178 +
23179 #ifdef CONFIG_X86_32
23180 if (!SHARED_KERNEL_PMD) {
23181 +
23182 +#ifdef CONFIG_PAX_PER_CPU_PGD
23183 + unsigned long cpu;
23184 +#else
23185 struct page *page;
23186 +#endif
23187
23188 +#ifdef CONFIG_PAX_PER_CPU_PGD
23189 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
23190 + pgd_t *pgd = get_cpu_pgd(cpu);
23191 +#else
23192 list_for_each_entry(page, &pgd_list, lru) {
23193 - pgd_t *pgd;
23194 + pgd_t *pgd = (pgd_t *)page_address(page);
23195 +#endif
23196 +
23197 pud_t *pud;
23198 pmd_t *pmd;
23199
23200 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
23201 + pgd += pgd_index(address);
23202 pud = pud_offset(pgd, address);
23203 pmd = pmd_offset(pud, address);
23204 set_pte_atomic((pte_t *)pmd, pte);
23205 }
23206 }
23207 #endif
23208 + pax_close_kernel();
23209 }
23210
23211 static int
23212 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
23213 index f6ff57b..481690f 100644
23214 --- a/arch/x86/mm/pat.c
23215 +++ b/arch/x86/mm/pat.c
23216 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
23217
23218 if (!entry) {
23219 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
23220 - current->comm, current->pid, start, end);
23221 + current->comm, task_pid_nr(current), start, end);
23222 return -EINVAL;
23223 }
23224
23225 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
23226 while (cursor < to) {
23227 if (!devmem_is_allowed(pfn)) {
23228 printk(KERN_INFO
23229 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
23230 - current->comm, from, to);
23231 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
23232 + current->comm, from, to, cursor);
23233 return 0;
23234 }
23235 cursor += PAGE_SIZE;
23236 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
23237 printk(KERN_INFO
23238 "%s:%d ioremap_change_attr failed %s "
23239 "for %Lx-%Lx\n",
23240 - current->comm, current->pid,
23241 + current->comm, task_pid_nr(current),
23242 cattr_name(flags),
23243 base, (unsigned long long)(base + size));
23244 return -EINVAL;
23245 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
23246 if (want_flags != flags) {
23247 printk(KERN_WARNING
23248 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
23249 - current->comm, current->pid,
23250 + current->comm, task_pid_nr(current),
23251 cattr_name(want_flags),
23252 (unsigned long long)paddr,
23253 (unsigned long long)(paddr + size),
23254 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
23255 free_memtype(paddr, paddr + size);
23256 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
23257 " for %Lx-%Lx, got %s\n",
23258 - current->comm, current->pid,
23259 + current->comm, task_pid_nr(current),
23260 cattr_name(want_flags),
23261 (unsigned long long)paddr,
23262 (unsigned long long)(paddr + size),
23263 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
23264 index 9f0614d..92ae64a 100644
23265 --- a/arch/x86/mm/pf_in.c
23266 +++ b/arch/x86/mm/pf_in.c
23267 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
23268 int i;
23269 enum reason_type rv = OTHERS;
23270
23271 - p = (unsigned char *)ins_addr;
23272 + p = (unsigned char *)ktla_ktva(ins_addr);
23273 p += skip_prefix(p, &prf);
23274 p += get_opcode(p, &opcode);
23275
23276 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
23277 struct prefix_bits prf;
23278 int i;
23279
23280 - p = (unsigned char *)ins_addr;
23281 + p = (unsigned char *)ktla_ktva(ins_addr);
23282 p += skip_prefix(p, &prf);
23283 p += get_opcode(p, &opcode);
23284
23285 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
23286 struct prefix_bits prf;
23287 int i;
23288
23289 - p = (unsigned char *)ins_addr;
23290 + p = (unsigned char *)ktla_ktva(ins_addr);
23291 p += skip_prefix(p, &prf);
23292 p += get_opcode(p, &opcode);
23293
23294 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
23295 struct prefix_bits prf;
23296 int i;
23297
23298 - p = (unsigned char *)ins_addr;
23299 + p = (unsigned char *)ktla_ktva(ins_addr);
23300 p += skip_prefix(p, &prf);
23301 p += get_opcode(p, &opcode);
23302 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
23303 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
23304 struct prefix_bits prf;
23305 int i;
23306
23307 - p = (unsigned char *)ins_addr;
23308 + p = (unsigned char *)ktla_ktva(ins_addr);
23309 p += skip_prefix(p, &prf);
23310 p += get_opcode(p, &opcode);
23311 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
23312 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
23313 index 8573b83..6372501 100644
23314 --- a/arch/x86/mm/pgtable.c
23315 +++ b/arch/x86/mm/pgtable.c
23316 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *pgd)
23317 list_del(&page->lru);
23318 }
23319
23320 -#define UNSHARED_PTRS_PER_PGD \
23321 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23322 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23323 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
23324
23325 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23326 +{
23327 + while (count--)
23328 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
23329 +}
23330 +#endif
23331
23332 +#ifdef CONFIG_PAX_PER_CPU_PGD
23333 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23334 +{
23335 + while (count--)
23336 +
23337 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23338 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
23339 +#else
23340 + *dst++ = *src++;
23341 +#endif
23342 +
23343 +}
23344 +#endif
23345 +
23346 +#ifdef CONFIG_X86_64
23347 +#define pxd_t pud_t
23348 +#define pyd_t pgd_t
23349 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
23350 +#define pxd_free(mm, pud) pud_free((mm), (pud))
23351 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
23352 +#define pyd_offset(mm ,address) pgd_offset((mm), (address))
23353 +#define PYD_SIZE PGDIR_SIZE
23354 +#else
23355 +#define pxd_t pmd_t
23356 +#define pyd_t pud_t
23357 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
23358 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
23359 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
23360 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
23361 +#define PYD_SIZE PUD_SIZE
23362 +#endif
23363 +
23364 +#ifdef CONFIG_PAX_PER_CPU_PGD
23365 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
23366 +static inline void pgd_dtor(pgd_t *pgd) {}
23367 +#else
23368 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
23369 {
23370 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
23371 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
23372 pgd_list_del(pgd);
23373 spin_unlock(&pgd_lock);
23374 }
23375 +#endif
23376
23377 /*
23378 * List of all pgd's needed for non-PAE so it can invalidate entries
23379 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
23380 * -- wli
23381 */
23382
23383 -#ifdef CONFIG_X86_PAE
23384 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
23385 /*
23386 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
23387 * updating the top-level pagetable entries to guarantee the
23388 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
23389 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
23390 * and initialize the kernel pmds here.
23391 */
23392 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
23393 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23394
23395 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23396 {
23397 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23398 */
23399 flush_tlb_mm(mm);
23400 }
23401 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
23402 +#define PREALLOCATED_PXDS USER_PGD_PTRS
23403 #else /* !CONFIG_X86_PAE */
23404
23405 /* No need to prepopulate any pagetable entries in non-PAE modes. */
23406 -#define PREALLOCATED_PMDS 0
23407 +#define PREALLOCATED_PXDS 0
23408
23409 #endif /* CONFIG_X86_PAE */
23410
23411 -static void free_pmds(pmd_t *pmds[])
23412 +static void free_pxds(pxd_t *pxds[])
23413 {
23414 int i;
23415
23416 - for(i = 0; i < PREALLOCATED_PMDS; i++)
23417 - if (pmds[i])
23418 - free_page((unsigned long)pmds[i]);
23419 + for(i = 0; i < PREALLOCATED_PXDS; i++)
23420 + if (pxds[i])
23421 + free_page((unsigned long)pxds[i]);
23422 }
23423
23424 -static int preallocate_pmds(pmd_t *pmds[])
23425 +static int preallocate_pxds(pxd_t *pxds[])
23426 {
23427 int i;
23428 bool failed = false;
23429
23430 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
23431 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
23432 - if (pmd == NULL)
23433 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
23434 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
23435 + if (pxd == NULL)
23436 failed = true;
23437 - pmds[i] = pmd;
23438 + pxds[i] = pxd;
23439 }
23440
23441 if (failed) {
23442 - free_pmds(pmds);
23443 + free_pxds(pxds);
23444 return -ENOMEM;
23445 }
23446
23447 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[])
23448 * preallocate which never got a corresponding vma will need to be
23449 * freed manually.
23450 */
23451 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
23452 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
23453 {
23454 int i;
23455
23456 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
23457 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
23458 pgd_t pgd = pgdp[i];
23459
23460 if (pgd_val(pgd) != 0) {
23461 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
23462 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
23463
23464 - pgdp[i] = native_make_pgd(0);
23465 + set_pgd(pgdp + i, native_make_pgd(0));
23466
23467 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
23468 - pmd_free(mm, pmd);
23469 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
23470 + pxd_free(mm, pxd);
23471 }
23472 }
23473 }
23474
23475 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
23476 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
23477 {
23478 - pud_t *pud;
23479 + pyd_t *pyd;
23480 unsigned long addr;
23481 int i;
23482
23483 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
23484 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
23485 return;
23486
23487 - pud = pud_offset(pgd, 0);
23488 +#ifdef CONFIG_X86_64
23489 + pyd = pyd_offset(mm, 0L);
23490 +#else
23491 + pyd = pyd_offset(pgd, 0L);
23492 +#endif
23493
23494 - for (addr = i = 0; i < PREALLOCATED_PMDS;
23495 - i++, pud++, addr += PUD_SIZE) {
23496 - pmd_t *pmd = pmds[i];
23497 + for (addr = i = 0; i < PREALLOCATED_PXDS;
23498 + i++, pyd++, addr += PYD_SIZE) {
23499 + pxd_t *pxd = pxds[i];
23500
23501 if (i >= KERNEL_PGD_BOUNDARY)
23502 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23503 - sizeof(pmd_t) * PTRS_PER_PMD);
23504 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23505 + sizeof(pxd_t) * PTRS_PER_PMD);
23506
23507 - pud_populate(mm, pud, pmd);
23508 + pyd_populate(mm, pyd, pxd);
23509 }
23510 }
23511
23512 pgd_t *pgd_alloc(struct mm_struct *mm)
23513 {
23514 pgd_t *pgd;
23515 - pmd_t *pmds[PREALLOCATED_PMDS];
23516 + pxd_t *pxds[PREALLOCATED_PXDS];
23517
23518 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
23519
23520 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23521
23522 mm->pgd = pgd;
23523
23524 - if (preallocate_pmds(pmds) != 0)
23525 + if (preallocate_pxds(pxds) != 0)
23526 goto out_free_pgd;
23527
23528 if (paravirt_pgd_alloc(mm) != 0)
23529 - goto out_free_pmds;
23530 + goto out_free_pxds;
23531
23532 /*
23533 * Make sure that pre-populating the pmds is atomic with
23534 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23535 spin_lock(&pgd_lock);
23536
23537 pgd_ctor(mm, pgd);
23538 - pgd_prepopulate_pmd(mm, pgd, pmds);
23539 + pgd_prepopulate_pxd(mm, pgd, pxds);
23540
23541 spin_unlock(&pgd_lock);
23542
23543 return pgd;
23544
23545 -out_free_pmds:
23546 - free_pmds(pmds);
23547 +out_free_pxds:
23548 + free_pxds(pxds);
23549 out_free_pgd:
23550 free_page((unsigned long)pgd);
23551 out:
23552 @@ -295,7 +344,7 @@ out:
23553
23554 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
23555 {
23556 - pgd_mop_up_pmds(mm, pgd);
23557 + pgd_mop_up_pxds(mm, pgd);
23558 pgd_dtor(pgd);
23559 paravirt_pgd_free(mm, pgd);
23560 free_page((unsigned long)pgd);
23561 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
23562 index cac7184..09a39fa 100644
23563 --- a/arch/x86/mm/pgtable_32.c
23564 +++ b/arch/x86/mm/pgtable_32.c
23565 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
23566 return;
23567 }
23568 pte = pte_offset_kernel(pmd, vaddr);
23569 +
23570 + pax_open_kernel();
23571 if (pte_val(pteval))
23572 set_pte_at(&init_mm, vaddr, pte, pteval);
23573 else
23574 pte_clear(&init_mm, vaddr, pte);
23575 + pax_close_kernel();
23576
23577 /*
23578 * It's enough to flush this one mapping.
23579 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
23580 index 410531d..0f16030 100644
23581 --- a/arch/x86/mm/setup_nx.c
23582 +++ b/arch/x86/mm/setup_nx.c
23583 @@ -5,8 +5,10 @@
23584 #include <asm/pgtable.h>
23585 #include <asm/proto.h>
23586
23587 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23588 static int disable_nx __cpuinitdata;
23589
23590 +#ifndef CONFIG_PAX_PAGEEXEC
23591 /*
23592 * noexec = on|off
23593 *
23594 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
23595 return 0;
23596 }
23597 early_param("noexec", noexec_setup);
23598 +#endif
23599 +
23600 +#endif
23601
23602 void __cpuinit x86_configure_nx(void)
23603 {
23604 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23605 if (cpu_has_nx && !disable_nx)
23606 __supported_pte_mask |= _PAGE_NX;
23607 else
23608 +#endif
23609 __supported_pte_mask &= ~_PAGE_NX;
23610 }
23611
23612 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
23613 index d6c0418..06a0ad5 100644
23614 --- a/arch/x86/mm/tlb.c
23615 +++ b/arch/x86/mm/tlb.c
23616 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
23617 BUG();
23618 cpumask_clear_cpu(cpu,
23619 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
23620 +
23621 +#ifndef CONFIG_PAX_PER_CPU_PGD
23622 load_cr3(swapper_pg_dir);
23623 +#endif
23624 +
23625 }
23626 EXPORT_SYMBOL_GPL(leave_mm);
23627
23628 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
23629 index 6687022..ceabcfa 100644
23630 --- a/arch/x86/net/bpf_jit.S
23631 +++ b/arch/x86/net/bpf_jit.S
23632 @@ -9,6 +9,7 @@
23633 */
23634 #include <linux/linkage.h>
23635 #include <asm/dwarf2.h>
23636 +#include <asm/alternative-asm.h>
23637
23638 /*
23639 * Calling convention :
23640 @@ -35,6 +36,7 @@ sk_load_word:
23641 jle bpf_slow_path_word
23642 mov (SKBDATA,%rsi),%eax
23643 bswap %eax /* ntohl() */
23644 + pax_force_retaddr
23645 ret
23646
23647
23648 @@ -53,6 +55,7 @@ sk_load_half:
23649 jle bpf_slow_path_half
23650 movzwl (SKBDATA,%rsi),%eax
23651 rol $8,%ax # ntohs()
23652 + pax_force_retaddr
23653 ret
23654
23655 sk_load_byte_ind:
23656 @@ -66,6 +69,7 @@ sk_load_byte:
23657 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
23658 jle bpf_slow_path_byte
23659 movzbl (SKBDATA,%rsi),%eax
23660 + pax_force_retaddr
23661 ret
23662
23663 /**
23664 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
23665 movzbl (SKBDATA,%rsi),%ebx
23666 and $15,%bl
23667 shl $2,%bl
23668 + pax_force_retaddr
23669 ret
23670 CFI_ENDPROC
23671 ENDPROC(sk_load_byte_msh)
23672 @@ -91,6 +96,7 @@ bpf_error:
23673 xor %eax,%eax
23674 mov -8(%rbp),%rbx
23675 leaveq
23676 + pax_force_retaddr
23677 ret
23678
23679 /* rsi contains offset and can be scratched */
23680 @@ -113,6 +119,7 @@ bpf_slow_path_word:
23681 js bpf_error
23682 mov -12(%rbp),%eax
23683 bswap %eax
23684 + pax_force_retaddr
23685 ret
23686
23687 bpf_slow_path_half:
23688 @@ -121,12 +128,14 @@ bpf_slow_path_half:
23689 mov -12(%rbp),%ax
23690 rol $8,%ax
23691 movzwl %ax,%eax
23692 + pax_force_retaddr
23693 ret
23694
23695 bpf_slow_path_byte:
23696 bpf_slow_path_common(1)
23697 js bpf_error
23698 movzbl -12(%rbp),%eax
23699 + pax_force_retaddr
23700 ret
23701
23702 bpf_slow_path_byte_msh:
23703 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
23704 and $15,%al
23705 shl $2,%al
23706 xchg %eax,%ebx
23707 + pax_force_retaddr
23708 ret
23709 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
23710 index 7b65f75..63097f6 100644
23711 --- a/arch/x86/net/bpf_jit_comp.c
23712 +++ b/arch/x86/net/bpf_jit_comp.c
23713 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
23714 set_fs(old_fs);
23715 }
23716
23717 +struct bpf_jit_work {
23718 + struct work_struct work;
23719 + void *image;
23720 +};
23721
23722 void bpf_jit_compile(struct sk_filter *fp)
23723 {
23724 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
23725 if (addrs == NULL)
23726 return;
23727
23728 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
23729 + if (!fp->work)
23730 + goto out;
23731 +
23732 /* Before first pass, make a rough estimation of addrs[]
23733 * each bpf instruction is translated to less than 64 bytes
23734 */
23735 @@ -585,11 +593,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23736 if (image) {
23737 if (unlikely(proglen + ilen > oldproglen)) {
23738 pr_err("bpb_jit_compile fatal error\n");
23739 - kfree(addrs);
23740 - module_free(NULL, image);
23741 - return;
23742 + module_free_exec(NULL, image);
23743 + goto out;
23744 }
23745 + pax_open_kernel();
23746 memcpy(image + proglen, temp, ilen);
23747 + pax_close_kernel();
23748 }
23749 proglen += ilen;
23750 addrs[i] = proglen;
23751 @@ -609,7 +618,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23752 break;
23753 }
23754 if (proglen == oldproglen) {
23755 - image = module_alloc(max_t(unsigned int,
23756 + image = module_alloc_exec(max_t(unsigned int,
23757 proglen,
23758 sizeof(struct work_struct)));
23759 if (!image)
23760 @@ -631,24 +640,27 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23761 fp->bpf_func = (void *)image;
23762 }
23763 out:
23764 + kfree(fp->work);
23765 kfree(addrs);
23766 return;
23767 }
23768
23769 static void jit_free_defer(struct work_struct *arg)
23770 {
23771 - module_free(NULL, arg);
23772 + module_free_exec(NULL, ((struct bpf_jit_work*)arg)->image);
23773 + kfree(arg);
23774 }
23775
23776 /* run from softirq, we must use a work_struct to call
23777 - * module_free() from process context
23778 + * module_free_exec() from process context
23779 */
23780 void bpf_jit_free(struct sk_filter *fp)
23781 {
23782 if (fp->bpf_func != sk_run_filter) {
23783 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
23784 + struct work_struct *work = &fp->work->work;
23785
23786 INIT_WORK(work, jit_free_defer);
23787 + fp->work->image = fp->bpf_func;
23788 schedule_work(work);
23789 }
23790 }
23791 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
23792 index bff89df..377758a 100644
23793 --- a/arch/x86/oprofile/backtrace.c
23794 +++ b/arch/x86/oprofile/backtrace.c
23795 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
23796 struct stack_frame_ia32 *fp;
23797 unsigned long bytes;
23798
23799 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
23800 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
23801 if (bytes != sizeof(bufhead))
23802 return NULL;
23803
23804 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
23805 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
23806
23807 oprofile_add_trace(bufhead[0].return_address);
23808
23809 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
23810 struct stack_frame bufhead[2];
23811 unsigned long bytes;
23812
23813 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
23814 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
23815 if (bytes != sizeof(bufhead))
23816 return NULL;
23817
23818 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
23819 {
23820 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
23821
23822 - if (!user_mode_vm(regs)) {
23823 + if (!user_mode(regs)) {
23824 unsigned long stack = kernel_stack_pointer(regs);
23825 if (depth)
23826 dump_trace(NULL, regs, (unsigned long *)stack, 0,
23827 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
23828 index cb29191..036766d 100644
23829 --- a/arch/x86/pci/mrst.c
23830 +++ b/arch/x86/pci/mrst.c
23831 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
23832 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
23833 pci_mmcfg_late_init();
23834 pcibios_enable_irq = mrst_pci_irq_enable;
23835 - pci_root_ops = pci_mrst_ops;
23836 + pax_open_kernel();
23837 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
23838 + pax_close_kernel();
23839 /* Continue with standard init */
23840 return 1;
23841 }
23842 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
23843 index db0e9a5..8844dea 100644
23844 --- a/arch/x86/pci/pcbios.c
23845 +++ b/arch/x86/pci/pcbios.c
23846 @@ -79,50 +79,93 @@ union bios32 {
23847 static struct {
23848 unsigned long address;
23849 unsigned short segment;
23850 -} bios32_indirect = { 0, __KERNEL_CS };
23851 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
23852
23853 /*
23854 * Returns the entry point for the given service, NULL on error
23855 */
23856
23857 -static unsigned long bios32_service(unsigned long service)
23858 +static unsigned long __devinit bios32_service(unsigned long service)
23859 {
23860 unsigned char return_code; /* %al */
23861 unsigned long address; /* %ebx */
23862 unsigned long length; /* %ecx */
23863 unsigned long entry; /* %edx */
23864 unsigned long flags;
23865 + struct desc_struct d, *gdt;
23866
23867 local_irq_save(flags);
23868 - __asm__("lcall *(%%edi); cld"
23869 +
23870 + gdt = get_cpu_gdt_table(smp_processor_id());
23871 +
23872 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
23873 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23874 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
23875 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23876 +
23877 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
23878 : "=a" (return_code),
23879 "=b" (address),
23880 "=c" (length),
23881 "=d" (entry)
23882 : "0" (service),
23883 "1" (0),
23884 - "D" (&bios32_indirect));
23885 + "D" (&bios32_indirect),
23886 + "r"(__PCIBIOS_DS)
23887 + : "memory");
23888 +
23889 + pax_open_kernel();
23890 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
23891 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
23892 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
23893 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
23894 + pax_close_kernel();
23895 +
23896 local_irq_restore(flags);
23897
23898 switch (return_code) {
23899 - case 0:
23900 - return address + entry;
23901 - case 0x80: /* Not present */
23902 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23903 - return 0;
23904 - default: /* Shouldn't happen */
23905 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23906 - service, return_code);
23907 + case 0: {
23908 + int cpu;
23909 + unsigned char flags;
23910 +
23911 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
23912 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
23913 + printk(KERN_WARNING "bios32_service: not valid\n");
23914 return 0;
23915 + }
23916 + address = address + PAGE_OFFSET;
23917 + length += 16UL; /* some BIOSs underreport this... */
23918 + flags = 4;
23919 + if (length >= 64*1024*1024) {
23920 + length >>= PAGE_SHIFT;
23921 + flags |= 8;
23922 + }
23923 +
23924 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
23925 + gdt = get_cpu_gdt_table(cpu);
23926 + pack_descriptor(&d, address, length, 0x9b, flags);
23927 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23928 + pack_descriptor(&d, address, length, 0x93, flags);
23929 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23930 + }
23931 + return entry;
23932 + }
23933 + case 0x80: /* Not present */
23934 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23935 + return 0;
23936 + default: /* Shouldn't happen */
23937 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23938 + service, return_code);
23939 + return 0;
23940 }
23941 }
23942
23943 static struct {
23944 unsigned long address;
23945 unsigned short segment;
23946 -} pci_indirect = { 0, __KERNEL_CS };
23947 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
23948
23949 -static int pci_bios_present;
23950 +static int pci_bios_present __read_only;
23951
23952 static int __devinit check_pcibios(void)
23953 {
23954 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
23955 unsigned long flags, pcibios_entry;
23956
23957 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
23958 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
23959 + pci_indirect.address = pcibios_entry;
23960
23961 local_irq_save(flags);
23962 - __asm__(
23963 - "lcall *(%%edi); cld\n\t"
23964 + __asm__("movw %w6, %%ds\n\t"
23965 + "lcall *%%ss:(%%edi); cld\n\t"
23966 + "push %%ss\n\t"
23967 + "pop %%ds\n\t"
23968 "jc 1f\n\t"
23969 "xor %%ah, %%ah\n"
23970 "1:"
23971 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
23972 "=b" (ebx),
23973 "=c" (ecx)
23974 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
23975 - "D" (&pci_indirect)
23976 + "D" (&pci_indirect),
23977 + "r" (__PCIBIOS_DS)
23978 : "memory");
23979 local_irq_restore(flags);
23980
23981 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
23982
23983 switch (len) {
23984 case 1:
23985 - __asm__("lcall *(%%esi); cld\n\t"
23986 + __asm__("movw %w6, %%ds\n\t"
23987 + "lcall *%%ss:(%%esi); cld\n\t"
23988 + "push %%ss\n\t"
23989 + "pop %%ds\n\t"
23990 "jc 1f\n\t"
23991 "xor %%ah, %%ah\n"
23992 "1:"
23993 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
23994 : "1" (PCIBIOS_READ_CONFIG_BYTE),
23995 "b" (bx),
23996 "D" ((long)reg),
23997 - "S" (&pci_indirect));
23998 + "S" (&pci_indirect),
23999 + "r" (__PCIBIOS_DS));
24000 /*
24001 * Zero-extend the result beyond 8 bits, do not trust the
24002 * BIOS having done it:
24003 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24004 *value &= 0xff;
24005 break;
24006 case 2:
24007 - __asm__("lcall *(%%esi); cld\n\t"
24008 + __asm__("movw %w6, %%ds\n\t"
24009 + "lcall *%%ss:(%%esi); cld\n\t"
24010 + "push %%ss\n\t"
24011 + "pop %%ds\n\t"
24012 "jc 1f\n\t"
24013 "xor %%ah, %%ah\n"
24014 "1:"
24015 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24016 : "1" (PCIBIOS_READ_CONFIG_WORD),
24017 "b" (bx),
24018 "D" ((long)reg),
24019 - "S" (&pci_indirect));
24020 + "S" (&pci_indirect),
24021 + "r" (__PCIBIOS_DS));
24022 /*
24023 * Zero-extend the result beyond 16 bits, do not trust the
24024 * BIOS having done it:
24025 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24026 *value &= 0xffff;
24027 break;
24028 case 4:
24029 - __asm__("lcall *(%%esi); cld\n\t"
24030 + __asm__("movw %w6, %%ds\n\t"
24031 + "lcall *%%ss:(%%esi); cld\n\t"
24032 + "push %%ss\n\t"
24033 + "pop %%ds\n\t"
24034 "jc 1f\n\t"
24035 "xor %%ah, %%ah\n"
24036 "1:"
24037 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24038 : "1" (PCIBIOS_READ_CONFIG_DWORD),
24039 "b" (bx),
24040 "D" ((long)reg),
24041 - "S" (&pci_indirect));
24042 + "S" (&pci_indirect),
24043 + "r" (__PCIBIOS_DS));
24044 break;
24045 }
24046
24047 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24048
24049 switch (len) {
24050 case 1:
24051 - __asm__("lcall *(%%esi); cld\n\t"
24052 + __asm__("movw %w6, %%ds\n\t"
24053 + "lcall *%%ss:(%%esi); cld\n\t"
24054 + "push %%ss\n\t"
24055 + "pop %%ds\n\t"
24056 "jc 1f\n\t"
24057 "xor %%ah, %%ah\n"
24058 "1:"
24059 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24060 "c" (value),
24061 "b" (bx),
24062 "D" ((long)reg),
24063 - "S" (&pci_indirect));
24064 + "S" (&pci_indirect),
24065 + "r" (__PCIBIOS_DS));
24066 break;
24067 case 2:
24068 - __asm__("lcall *(%%esi); cld\n\t"
24069 + __asm__("movw %w6, %%ds\n\t"
24070 + "lcall *%%ss:(%%esi); cld\n\t"
24071 + "push %%ss\n\t"
24072 + "pop %%ds\n\t"
24073 "jc 1f\n\t"
24074 "xor %%ah, %%ah\n"
24075 "1:"
24076 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24077 "c" (value),
24078 "b" (bx),
24079 "D" ((long)reg),
24080 - "S" (&pci_indirect));
24081 + "S" (&pci_indirect),
24082 + "r" (__PCIBIOS_DS));
24083 break;
24084 case 4:
24085 - __asm__("lcall *(%%esi); cld\n\t"
24086 + __asm__("movw %w6, %%ds\n\t"
24087 + "lcall *%%ss:(%%esi); cld\n\t"
24088 + "push %%ss\n\t"
24089 + "pop %%ds\n\t"
24090 "jc 1f\n\t"
24091 "xor %%ah, %%ah\n"
24092 "1:"
24093 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24094 "c" (value),
24095 "b" (bx),
24096 "D" ((long)reg),
24097 - "S" (&pci_indirect));
24098 + "S" (&pci_indirect),
24099 + "r" (__PCIBIOS_DS));
24100 break;
24101 }
24102
24103 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
24104
24105 DBG("PCI: Fetching IRQ routing table... ");
24106 __asm__("push %%es\n\t"
24107 + "movw %w8, %%ds\n\t"
24108 "push %%ds\n\t"
24109 "pop %%es\n\t"
24110 - "lcall *(%%esi); cld\n\t"
24111 + "lcall *%%ss:(%%esi); cld\n\t"
24112 "pop %%es\n\t"
24113 + "push %%ss\n\t"
24114 + "pop %%ds\n"
24115 "jc 1f\n\t"
24116 "xor %%ah, %%ah\n"
24117 "1:"
24118 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
24119 "1" (0),
24120 "D" ((long) &opt),
24121 "S" (&pci_indirect),
24122 - "m" (opt)
24123 + "m" (opt),
24124 + "r" (__PCIBIOS_DS)
24125 : "memory");
24126 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
24127 if (ret & 0xff00)
24128 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
24129 {
24130 int ret;
24131
24132 - __asm__("lcall *(%%esi); cld\n\t"
24133 + __asm__("movw %w5, %%ds\n\t"
24134 + "lcall *%%ss:(%%esi); cld\n\t"
24135 + "push %%ss\n\t"
24136 + "pop %%ds\n"
24137 "jc 1f\n\t"
24138 "xor %%ah, %%ah\n"
24139 "1:"
24140 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
24141 : "0" (PCIBIOS_SET_PCI_HW_INT),
24142 "b" ((dev->bus->number << 8) | dev->devfn),
24143 "c" ((irq << 8) | (pin + 10)),
24144 - "S" (&pci_indirect));
24145 + "S" (&pci_indirect),
24146 + "r" (__PCIBIOS_DS));
24147 return !(ret & 0xff00);
24148 }
24149 EXPORT_SYMBOL(pcibios_set_irq_routing);
24150 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
24151 index 40e4469..1ab536e 100644
24152 --- a/arch/x86/platform/efi/efi_32.c
24153 +++ b/arch/x86/platform/efi/efi_32.c
24154 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
24155 {
24156 struct desc_ptr gdt_descr;
24157
24158 +#ifdef CONFIG_PAX_KERNEXEC
24159 + struct desc_struct d;
24160 +#endif
24161 +
24162 local_irq_save(efi_rt_eflags);
24163
24164 load_cr3(initial_page_table);
24165 __flush_tlb_all();
24166
24167 +#ifdef CONFIG_PAX_KERNEXEC
24168 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
24169 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
24170 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
24171 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
24172 +#endif
24173 +
24174 gdt_descr.address = __pa(get_cpu_gdt_table(0));
24175 gdt_descr.size = GDT_SIZE - 1;
24176 load_gdt(&gdt_descr);
24177 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
24178 {
24179 struct desc_ptr gdt_descr;
24180
24181 +#ifdef CONFIG_PAX_KERNEXEC
24182 + struct desc_struct d;
24183 +
24184 + memset(&d, 0, sizeof d);
24185 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
24186 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
24187 +#endif
24188 +
24189 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
24190 gdt_descr.size = GDT_SIZE - 1;
24191 load_gdt(&gdt_descr);
24192 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
24193 index fbe66e6..c5c0dd2 100644
24194 --- a/arch/x86/platform/efi/efi_stub_32.S
24195 +++ b/arch/x86/platform/efi/efi_stub_32.S
24196 @@ -6,7 +6,9 @@
24197 */
24198
24199 #include <linux/linkage.h>
24200 +#include <linux/init.h>
24201 #include <asm/page_types.h>
24202 +#include <asm/segment.h>
24203
24204 /*
24205 * efi_call_phys(void *, ...) is a function with variable parameters.
24206 @@ -20,7 +22,7 @@
24207 * service functions will comply with gcc calling convention, too.
24208 */
24209
24210 -.text
24211 +__INIT
24212 ENTRY(efi_call_phys)
24213 /*
24214 * 0. The function can only be called in Linux kernel. So CS has been
24215 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
24216 * The mapping of lower virtual memory has been created in prelog and
24217 * epilog.
24218 */
24219 - movl $1f, %edx
24220 - subl $__PAGE_OFFSET, %edx
24221 - jmp *%edx
24222 + movl $(__KERNEXEC_EFI_DS), %edx
24223 + mov %edx, %ds
24224 + mov %edx, %es
24225 + mov %edx, %ss
24226 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
24227 1:
24228
24229 /*
24230 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
24231 * parameter 2, ..., param n. To make things easy, we save the return
24232 * address of efi_call_phys in a global variable.
24233 */
24234 - popl %edx
24235 - movl %edx, saved_return_addr
24236 - /* get the function pointer into ECX*/
24237 - popl %ecx
24238 - movl %ecx, efi_rt_function_ptr
24239 - movl $2f, %edx
24240 - subl $__PAGE_OFFSET, %edx
24241 - pushl %edx
24242 + popl (saved_return_addr)
24243 + popl (efi_rt_function_ptr)
24244
24245 /*
24246 * 3. Clear PG bit in %CR0.
24247 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
24248 /*
24249 * 5. Call the physical function.
24250 */
24251 - jmp *%ecx
24252 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
24253
24254 -2:
24255 /*
24256 * 6. After EFI runtime service returns, control will return to
24257 * following instruction. We'd better readjust stack pointer first.
24258 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
24259 movl %cr0, %edx
24260 orl $0x80000000, %edx
24261 movl %edx, %cr0
24262 - jmp 1f
24263 -1:
24264 +
24265 /*
24266 * 8. Now restore the virtual mode from flat mode by
24267 * adding EIP with PAGE_OFFSET.
24268 */
24269 - movl $1f, %edx
24270 - jmp *%edx
24271 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
24272 1:
24273 + movl $(__KERNEL_DS), %edx
24274 + mov %edx, %ds
24275 + mov %edx, %es
24276 + mov %edx, %ss
24277
24278 /*
24279 * 9. Balance the stack. And because EAX contain the return value,
24280 * we'd better not clobber it.
24281 */
24282 - leal efi_rt_function_ptr, %edx
24283 - movl (%edx), %ecx
24284 - pushl %ecx
24285 + pushl (efi_rt_function_ptr)
24286
24287 /*
24288 - * 10. Push the saved return address onto the stack and return.
24289 + * 10. Return to the saved return address.
24290 */
24291 - leal saved_return_addr, %edx
24292 - movl (%edx), %ecx
24293 - pushl %ecx
24294 - ret
24295 + jmpl *(saved_return_addr)
24296 ENDPROC(efi_call_phys)
24297 .previous
24298
24299 -.data
24300 +__INITDATA
24301 saved_return_addr:
24302 .long 0
24303 efi_rt_function_ptr:
24304 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
24305 index 4c07cca..2c8427d 100644
24306 --- a/arch/x86/platform/efi/efi_stub_64.S
24307 +++ b/arch/x86/platform/efi/efi_stub_64.S
24308 @@ -7,6 +7,7 @@
24309 */
24310
24311 #include <linux/linkage.h>
24312 +#include <asm/alternative-asm.h>
24313
24314 #define SAVE_XMM \
24315 mov %rsp, %rax; \
24316 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
24317 call *%rdi
24318 addq $32, %rsp
24319 RESTORE_XMM
24320 + pax_force_retaddr 0, 1
24321 ret
24322 ENDPROC(efi_call0)
24323
24324 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
24325 call *%rdi
24326 addq $32, %rsp
24327 RESTORE_XMM
24328 + pax_force_retaddr 0, 1
24329 ret
24330 ENDPROC(efi_call1)
24331
24332 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
24333 call *%rdi
24334 addq $32, %rsp
24335 RESTORE_XMM
24336 + pax_force_retaddr 0, 1
24337 ret
24338 ENDPROC(efi_call2)
24339
24340 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
24341 call *%rdi
24342 addq $32, %rsp
24343 RESTORE_XMM
24344 + pax_force_retaddr 0, 1
24345 ret
24346 ENDPROC(efi_call3)
24347
24348 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
24349 call *%rdi
24350 addq $32, %rsp
24351 RESTORE_XMM
24352 + pax_force_retaddr 0, 1
24353 ret
24354 ENDPROC(efi_call4)
24355
24356 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
24357 call *%rdi
24358 addq $48, %rsp
24359 RESTORE_XMM
24360 + pax_force_retaddr 0, 1
24361 ret
24362 ENDPROC(efi_call5)
24363
24364 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
24365 call *%rdi
24366 addq $48, %rsp
24367 RESTORE_XMM
24368 + pax_force_retaddr 0, 1
24369 ret
24370 ENDPROC(efi_call6)
24371 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
24372 index ad4ec1c..686479e 100644
24373 --- a/arch/x86/platform/mrst/mrst.c
24374 +++ b/arch/x86/platform/mrst/mrst.c
24375 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
24376 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
24377 int sfi_mrtc_num;
24378
24379 -static void mrst_power_off(void)
24380 +static __noreturn void mrst_power_off(void)
24381 {
24382 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
24383 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
24384 + BUG();
24385 }
24386
24387 -static void mrst_reboot(void)
24388 +static __noreturn void mrst_reboot(void)
24389 {
24390 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
24391 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
24392 else
24393 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
24394 + BUG();
24395 }
24396
24397 /* parse all the mtimer info to a static mtimer array */
24398 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
24399 index f10c0af..3ec1f95 100644
24400 --- a/arch/x86/power/cpu.c
24401 +++ b/arch/x86/power/cpu.c
24402 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
24403 static void fix_processor_context(void)
24404 {
24405 int cpu = smp_processor_id();
24406 - struct tss_struct *t = &per_cpu(init_tss, cpu);
24407 + struct tss_struct *t = init_tss + cpu;
24408
24409 set_tss_desc(cpu, t); /*
24410 * This just modifies memory; should not be
24411 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
24412 */
24413
24414 #ifdef CONFIG_X86_64
24415 + pax_open_kernel();
24416 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
24417 + pax_close_kernel();
24418
24419 syscall_init(); /* This sets MSR_*STAR and related */
24420 #endif
24421 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
24422 index 5d17950..2253fc9 100644
24423 --- a/arch/x86/vdso/Makefile
24424 +++ b/arch/x86/vdso/Makefile
24425 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
24426 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
24427 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
24428
24429 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24430 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24431 GCOV_PROFILE := n
24432
24433 #
24434 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
24435 index 468d591..8e80a0a 100644
24436 --- a/arch/x86/vdso/vdso32-setup.c
24437 +++ b/arch/x86/vdso/vdso32-setup.c
24438 @@ -25,6 +25,7 @@
24439 #include <asm/tlbflush.h>
24440 #include <asm/vdso.h>
24441 #include <asm/proto.h>
24442 +#include <asm/mman.h>
24443
24444 enum {
24445 VDSO_DISABLED = 0,
24446 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
24447 void enable_sep_cpu(void)
24448 {
24449 int cpu = get_cpu();
24450 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
24451 + struct tss_struct *tss = init_tss + cpu;
24452
24453 if (!boot_cpu_has(X86_FEATURE_SEP)) {
24454 put_cpu();
24455 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
24456 gate_vma.vm_start = FIXADDR_USER_START;
24457 gate_vma.vm_end = FIXADDR_USER_END;
24458 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
24459 - gate_vma.vm_page_prot = __P101;
24460 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
24461 /*
24462 * Make sure the vDSO gets into every core dump.
24463 * Dumping its contents makes post-mortem fully interpretable later
24464 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24465 if (compat)
24466 addr = VDSO_HIGH_BASE;
24467 else {
24468 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
24469 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
24470 if (IS_ERR_VALUE(addr)) {
24471 ret = addr;
24472 goto up_fail;
24473 }
24474 }
24475
24476 - current->mm->context.vdso = (void *)addr;
24477 + current->mm->context.vdso = addr;
24478
24479 if (compat_uses_vma || !compat) {
24480 /*
24481 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24482 }
24483
24484 current_thread_info()->sysenter_return =
24485 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24486 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24487
24488 up_fail:
24489 if (ret)
24490 - current->mm->context.vdso = NULL;
24491 + current->mm->context.vdso = 0;
24492
24493 up_write(&mm->mmap_sem);
24494
24495 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
24496
24497 const char *arch_vma_name(struct vm_area_struct *vma)
24498 {
24499 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24500 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24501 return "[vdso]";
24502 +
24503 +#ifdef CONFIG_PAX_SEGMEXEC
24504 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
24505 + return "[vdso]";
24506 +#endif
24507 +
24508 return NULL;
24509 }
24510
24511 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24512 * Check to see if the corresponding task was created in compat vdso
24513 * mode.
24514 */
24515 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
24516 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
24517 return &gate_vma;
24518 return NULL;
24519 }
24520 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
24521 index 153407c..611cba9 100644
24522 --- a/arch/x86/vdso/vma.c
24523 +++ b/arch/x86/vdso/vma.c
24524 @@ -16,8 +16,6 @@
24525 #include <asm/vdso.h>
24526 #include <asm/page.h>
24527
24528 -unsigned int __read_mostly vdso_enabled = 1;
24529 -
24530 extern char vdso_start[], vdso_end[];
24531 extern unsigned short vdso_sync_cpuid;
24532
24533 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
24534 * unaligned here as a result of stack start randomization.
24535 */
24536 addr = PAGE_ALIGN(addr);
24537 - addr = align_addr(addr, NULL, ALIGN_VDSO);
24538
24539 return addr;
24540 }
24541 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
24542 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24543 {
24544 struct mm_struct *mm = current->mm;
24545 - unsigned long addr;
24546 + unsigned long addr = 0;
24547 int ret;
24548
24549 - if (!vdso_enabled)
24550 - return 0;
24551 -
24552 down_write(&mm->mmap_sem);
24553 +
24554 +#ifdef CONFIG_PAX_RANDMMAP
24555 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
24556 +#endif
24557 +
24558 addr = vdso_addr(mm->start_stack, vdso_size);
24559 + addr = align_addr(addr, NULL, ALIGN_VDSO);
24560 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
24561 if (IS_ERR_VALUE(addr)) {
24562 ret = addr;
24563 goto up_fail;
24564 }
24565
24566 - current->mm->context.vdso = (void *)addr;
24567 + mm->context.vdso = addr;
24568
24569 ret = install_special_mapping(mm, addr, vdso_size,
24570 VM_READ|VM_EXEC|
24571 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
24572 VM_ALWAYSDUMP,
24573 vdso_pages);
24574 - if (ret) {
24575 - current->mm->context.vdso = NULL;
24576 - goto up_fail;
24577 - }
24578 +
24579 + if (ret)
24580 + mm->context.vdso = 0;
24581
24582 up_fail:
24583 up_write(&mm->mmap_sem);
24584 return ret;
24585 }
24586 -
24587 -static __init int vdso_setup(char *s)
24588 -{
24589 - vdso_enabled = simple_strtoul(s, NULL, 0);
24590 - return 0;
24591 -}
24592 -__setup("vdso=", vdso_setup);
24593 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
24594 index 1f92865..c843b20 100644
24595 --- a/arch/x86/xen/enlighten.c
24596 +++ b/arch/x86/xen/enlighten.c
24597 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
24598
24599 struct shared_info xen_dummy_shared_info;
24600
24601 -void *xen_initial_gdt;
24602 -
24603 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
24604 __read_mostly int xen_have_vector_callback;
24605 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
24606 @@ -1029,7 +1027,7 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
24607 #endif
24608 };
24609
24610 -static void xen_reboot(int reason)
24611 +static __noreturn void xen_reboot(int reason)
24612 {
24613 struct sched_shutdown r = { .reason = reason };
24614
24615 @@ -1037,17 +1035,17 @@ static void xen_reboot(int reason)
24616 BUG();
24617 }
24618
24619 -static void xen_restart(char *msg)
24620 +static __noreturn void xen_restart(char *msg)
24621 {
24622 xen_reboot(SHUTDOWN_reboot);
24623 }
24624
24625 -static void xen_emergency_restart(void)
24626 +static __noreturn void xen_emergency_restart(void)
24627 {
24628 xen_reboot(SHUTDOWN_reboot);
24629 }
24630
24631 -static void xen_machine_halt(void)
24632 +static __noreturn void xen_machine_halt(void)
24633 {
24634 xen_reboot(SHUTDOWN_poweroff);
24635 }
24636 @@ -1153,7 +1151,17 @@ asmlinkage void __init xen_start_kernel(void)
24637 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
24638
24639 /* Work out if we support NX */
24640 - x86_configure_nx();
24641 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24642 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
24643 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
24644 + unsigned l, h;
24645 +
24646 + __supported_pte_mask |= _PAGE_NX;
24647 + rdmsr(MSR_EFER, l, h);
24648 + l |= EFER_NX;
24649 + wrmsr(MSR_EFER, l, h);
24650 + }
24651 +#endif
24652
24653 xen_setup_features();
24654
24655 @@ -1184,13 +1192,6 @@ asmlinkage void __init xen_start_kernel(void)
24656
24657 machine_ops = xen_machine_ops;
24658
24659 - /*
24660 - * The only reliable way to retain the initial address of the
24661 - * percpu gdt_page is to remember it here, so we can go and
24662 - * mark it RW later, when the initial percpu area is freed.
24663 - */
24664 - xen_initial_gdt = &per_cpu(gdt_page, 0);
24665 -
24666 xen_smp_init();
24667
24668 #ifdef CONFIG_ACPI_NUMA
24669 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
24670 index 87f6673..e2555a6 100644
24671 --- a/arch/x86/xen/mmu.c
24672 +++ b/arch/x86/xen/mmu.c
24673 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
24674 convert_pfn_mfn(init_level4_pgt);
24675 convert_pfn_mfn(level3_ident_pgt);
24676 convert_pfn_mfn(level3_kernel_pgt);
24677 + convert_pfn_mfn(level3_vmalloc_start_pgt);
24678 + convert_pfn_mfn(level3_vmalloc_end_pgt);
24679 + convert_pfn_mfn(level3_vmemmap_pgt);
24680
24681 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
24682 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
24683 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
24684 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
24685 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
24686 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
24687 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
24688 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
24689 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
24690 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
24691 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
24692 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
24693 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
24694
24695 @@ -1962,6 +1969,7 @@ static void __init xen_post_allocator_init(void)
24696 pv_mmu_ops.set_pud = xen_set_pud;
24697 #if PAGETABLE_LEVELS == 4
24698 pv_mmu_ops.set_pgd = xen_set_pgd;
24699 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
24700 #endif
24701
24702 /* This will work as long as patching hasn't happened yet
24703 @@ -2043,6 +2051,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
24704 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
24705 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
24706 .set_pgd = xen_set_pgd_hyper,
24707 + .set_pgd_batched = xen_set_pgd_hyper,
24708
24709 .alloc_pud = xen_alloc_pmd_init,
24710 .release_pud = xen_release_pmd_init,
24711 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
24712 index 041d4fe..7666b7e 100644
24713 --- a/arch/x86/xen/smp.c
24714 +++ b/arch/x86/xen/smp.c
24715 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
24716 {
24717 BUG_ON(smp_processor_id() != 0);
24718 native_smp_prepare_boot_cpu();
24719 -
24720 - /* We've switched to the "real" per-cpu gdt, so make sure the
24721 - old memory can be recycled */
24722 - make_lowmem_page_readwrite(xen_initial_gdt);
24723 -
24724 xen_filter_cpu_maps();
24725 xen_setup_vcpu_info_placement();
24726 }
24727 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
24728 gdt = get_cpu_gdt_table(cpu);
24729
24730 ctxt->flags = VGCF_IN_KERNEL;
24731 - ctxt->user_regs.ds = __USER_DS;
24732 - ctxt->user_regs.es = __USER_DS;
24733 + ctxt->user_regs.ds = __KERNEL_DS;
24734 + ctxt->user_regs.es = __KERNEL_DS;
24735 ctxt->user_regs.ss = __KERNEL_DS;
24736 #ifdef CONFIG_X86_32
24737 ctxt->user_regs.fs = __KERNEL_PERCPU;
24738 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
24739 + savesegment(gs, ctxt->user_regs.gs);
24740 #else
24741 ctxt->gs_base_kernel = per_cpu_offset(cpu);
24742 #endif
24743 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
24744 int rc;
24745
24746 per_cpu(current_task, cpu) = idle;
24747 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
24748 #ifdef CONFIG_X86_32
24749 irq_ctx_init(cpu);
24750 #else
24751 clear_tsk_thread_flag(idle, TIF_FORK);
24752 - per_cpu(kernel_stack, cpu) =
24753 - (unsigned long)task_stack_page(idle) -
24754 - KERNEL_STACK_OFFSET + THREAD_SIZE;
24755 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
24756 #endif
24757 xen_setup_runstate_info(cpu);
24758 xen_setup_timer(cpu);
24759 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
24760 index b040b0e..8cc4fe0 100644
24761 --- a/arch/x86/xen/xen-asm_32.S
24762 +++ b/arch/x86/xen/xen-asm_32.S
24763 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
24764 ESP_OFFSET=4 # bytes pushed onto stack
24765
24766 /*
24767 - * Store vcpu_info pointer for easy access. Do it this way to
24768 - * avoid having to reload %fs
24769 + * Store vcpu_info pointer for easy access.
24770 */
24771 #ifdef CONFIG_SMP
24772 - GET_THREAD_INFO(%eax)
24773 - movl TI_cpu(%eax), %eax
24774 - movl __per_cpu_offset(,%eax,4), %eax
24775 - mov xen_vcpu(%eax), %eax
24776 + push %fs
24777 + mov $(__KERNEL_PERCPU), %eax
24778 + mov %eax, %fs
24779 + mov PER_CPU_VAR(xen_vcpu), %eax
24780 + pop %fs
24781 #else
24782 movl xen_vcpu, %eax
24783 #endif
24784 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
24785 index aaa7291..3f77960 100644
24786 --- a/arch/x86/xen/xen-head.S
24787 +++ b/arch/x86/xen/xen-head.S
24788 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
24789 #ifdef CONFIG_X86_32
24790 mov %esi,xen_start_info
24791 mov $init_thread_union+THREAD_SIZE,%esp
24792 +#ifdef CONFIG_SMP
24793 + movl $cpu_gdt_table,%edi
24794 + movl $__per_cpu_load,%eax
24795 + movw %ax,__KERNEL_PERCPU + 2(%edi)
24796 + rorl $16,%eax
24797 + movb %al,__KERNEL_PERCPU + 4(%edi)
24798 + movb %ah,__KERNEL_PERCPU + 7(%edi)
24799 + movl $__per_cpu_end - 1,%eax
24800 + subl $__per_cpu_start,%eax
24801 + movw %ax,__KERNEL_PERCPU + 0(%edi)
24802 +#endif
24803 #else
24804 mov %rsi,xen_start_info
24805 mov $init_thread_union+THREAD_SIZE,%rsp
24806 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
24807 index b095739..8c17bcd 100644
24808 --- a/arch/x86/xen/xen-ops.h
24809 +++ b/arch/x86/xen/xen-ops.h
24810 @@ -10,8 +10,6 @@
24811 extern const char xen_hypervisor_callback[];
24812 extern const char xen_failsafe_callback[];
24813
24814 -extern void *xen_initial_gdt;
24815 -
24816 struct trap_info;
24817 void xen_copy_trap_info(struct trap_info *traps);
24818
24819 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
24820 index 58916af..9cb880b 100644
24821 --- a/block/blk-iopoll.c
24822 +++ b/block/blk-iopoll.c
24823 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
24824 }
24825 EXPORT_SYMBOL(blk_iopoll_complete);
24826
24827 -static void blk_iopoll_softirq(struct softirq_action *h)
24828 +static void blk_iopoll_softirq(void)
24829 {
24830 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
24831 int rearm = 0, budget = blk_iopoll_budget;
24832 diff --git a/block/blk-map.c b/block/blk-map.c
24833 index 623e1cd..ca1e109 100644
24834 --- a/block/blk-map.c
24835 +++ b/block/blk-map.c
24836 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
24837 if (!len || !kbuf)
24838 return -EINVAL;
24839
24840 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
24841 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
24842 if (do_copy)
24843 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
24844 else
24845 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
24846 index 1366a89..e17f54b 100644
24847 --- a/block/blk-softirq.c
24848 +++ b/block/blk-softirq.c
24849 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
24850 * Softirq action handler - move entries to local list and loop over them
24851 * while passing them to the queue registered handler.
24852 */
24853 -static void blk_done_softirq(struct softirq_action *h)
24854 +static void blk_done_softirq(void)
24855 {
24856 struct list_head *cpu_list, local_list;
24857
24858 diff --git a/block/bsg.c b/block/bsg.c
24859 index 702f131..37808bf 100644
24860 --- a/block/bsg.c
24861 +++ b/block/bsg.c
24862 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
24863 struct sg_io_v4 *hdr, struct bsg_device *bd,
24864 fmode_t has_write_perm)
24865 {
24866 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24867 + unsigned char *cmdptr;
24868 +
24869 if (hdr->request_len > BLK_MAX_CDB) {
24870 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
24871 if (!rq->cmd)
24872 return -ENOMEM;
24873 - }
24874 + cmdptr = rq->cmd;
24875 + } else
24876 + cmdptr = tmpcmd;
24877
24878 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
24879 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
24880 hdr->request_len))
24881 return -EFAULT;
24882
24883 + if (cmdptr != rq->cmd)
24884 + memcpy(rq->cmd, cmdptr, hdr->request_len);
24885 +
24886 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
24887 if (blk_verify_command(rq->cmd, has_write_perm))
24888 return -EPERM;
24889 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
24890 index 7b72502..646105c 100644
24891 --- a/block/compat_ioctl.c
24892 +++ b/block/compat_ioctl.c
24893 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
24894 err |= __get_user(f->spec1, &uf->spec1);
24895 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
24896 err |= __get_user(name, &uf->name);
24897 - f->name = compat_ptr(name);
24898 + f->name = (void __force_kernel *)compat_ptr(name);
24899 if (err) {
24900 err = -EFAULT;
24901 goto out;
24902 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
24903 index fbdf0d8..e8f3caf 100644
24904 --- a/block/scsi_ioctl.c
24905 +++ b/block/scsi_ioctl.c
24906 @@ -24,6 +24,7 @@
24907 #include <linux/capability.h>
24908 #include <linux/completion.h>
24909 #include <linux/cdrom.h>
24910 +#include <linux/ratelimit.h>
24911 #include <linux/slab.h>
24912 #include <linux/times.h>
24913 #include <asm/uaccess.h>
24914 @@ -222,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
24915 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
24916 struct sg_io_hdr *hdr, fmode_t mode)
24917 {
24918 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
24919 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24920 + unsigned char *cmdptr;
24921 +
24922 + if (rq->cmd != rq->__cmd)
24923 + cmdptr = rq->cmd;
24924 + else
24925 + cmdptr = tmpcmd;
24926 +
24927 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
24928 return -EFAULT;
24929 +
24930 + if (cmdptr != rq->cmd)
24931 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
24932 +
24933 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
24934 return -EPERM;
24935
24936 @@ -432,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
24937 int err;
24938 unsigned int in_len, out_len, bytes, opcode, cmdlen;
24939 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
24940 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24941 + unsigned char *cmdptr;
24942
24943 if (!sic)
24944 return -EINVAL;
24945 @@ -465,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
24946 */
24947 err = -EFAULT;
24948 rq->cmd_len = cmdlen;
24949 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
24950 +
24951 + if (rq->cmd != rq->__cmd)
24952 + cmdptr = rq->cmd;
24953 + else
24954 + cmdptr = tmpcmd;
24955 +
24956 + if (copy_from_user(cmdptr, sic->data, cmdlen))
24957 goto error;
24958
24959 + if (rq->cmd != cmdptr)
24960 + memcpy(rq->cmd, cmdptr, cmdlen);
24961 +
24962 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
24963 goto error;
24964
24965 @@ -690,6 +714,57 @@ int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mod
24966 }
24967 EXPORT_SYMBOL(scsi_cmd_ioctl);
24968
24969 +int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
24970 +{
24971 + if (bd && bd == bd->bd_contains)
24972 + return 0;
24973 +
24974 + /* Actually none of these is particularly useful on a partition,
24975 + * but they are safe.
24976 + */
24977 + switch (cmd) {
24978 + case SCSI_IOCTL_GET_IDLUN:
24979 + case SCSI_IOCTL_GET_BUS_NUMBER:
24980 + case SCSI_IOCTL_GET_PCI:
24981 + case SCSI_IOCTL_PROBE_HOST:
24982 + case SG_GET_VERSION_NUM:
24983 + case SG_SET_TIMEOUT:
24984 + case SG_GET_TIMEOUT:
24985 + case SG_GET_RESERVED_SIZE:
24986 + case SG_SET_RESERVED_SIZE:
24987 + case SG_EMULATED_HOST:
24988 + return 0;
24989 + case CDROM_GET_CAPABILITY:
24990 + /* Keep this until we remove the printk below. udev sends it
24991 + * and we do not want to spam dmesg about it. CD-ROMs do
24992 + * not have partitions, so we get here only for disks.
24993 + */
24994 + return -ENOIOCTLCMD;
24995 + default:
24996 + break;
24997 + }
24998 +
24999 + /* In particular, rule out all resets and host-specific ioctls. */
25000 + printk_ratelimited(KERN_WARNING
25001 + "%s: sending ioctl %x to a partition!\n", current->comm, cmd);
25002 +
25003 + return capable(CAP_SYS_RAWIO) ? 0 : -ENOIOCTLCMD;
25004 +}
25005 +EXPORT_SYMBOL(scsi_verify_blk_ioctl);
25006 +
25007 +int scsi_cmd_blk_ioctl(struct block_device *bd, fmode_t mode,
25008 + unsigned int cmd, void __user *arg)
25009 +{
25010 + int ret;
25011 +
25012 + ret = scsi_verify_blk_ioctl(bd, cmd);
25013 + if (ret < 0)
25014 + return ret;
25015 +
25016 + return scsi_cmd_ioctl(bd->bd_disk->queue, bd->bd_disk, mode, cmd, arg);
25017 +}
25018 +EXPORT_SYMBOL(scsi_cmd_blk_ioctl);
25019 +
25020 static int __init blk_scsi_ioctl_init(void)
25021 {
25022 blk_set_cmd_filter_defaults(&blk_default_cmd_filter);
25023 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
25024 index 671d4d6..5f24030 100644
25025 --- a/crypto/cryptd.c
25026 +++ b/crypto/cryptd.c
25027 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
25028
25029 struct cryptd_blkcipher_request_ctx {
25030 crypto_completion_t complete;
25031 -};
25032 +} __no_const;
25033
25034 struct cryptd_hash_ctx {
25035 struct crypto_shash *child;
25036 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
25037
25038 struct cryptd_aead_request_ctx {
25039 crypto_completion_t complete;
25040 -};
25041 +} __no_const;
25042
25043 static void cryptd_queue_worker(struct work_struct *work);
25044
25045 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
25046 index 5d41894..22021e4 100644
25047 --- a/drivers/acpi/apei/cper.c
25048 +++ b/drivers/acpi/apei/cper.c
25049 @@ -38,12 +38,12 @@
25050 */
25051 u64 cper_next_record_id(void)
25052 {
25053 - static atomic64_t seq;
25054 + static atomic64_unchecked_t seq;
25055
25056 - if (!atomic64_read(&seq))
25057 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
25058 + if (!atomic64_read_unchecked(&seq))
25059 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
25060
25061 - return atomic64_inc_return(&seq);
25062 + return atomic64_inc_return_unchecked(&seq);
25063 }
25064 EXPORT_SYMBOL_GPL(cper_next_record_id);
25065
25066 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
25067 index 6c47ae9..8ab9132 100644
25068 --- a/drivers/acpi/ec_sys.c
25069 +++ b/drivers/acpi/ec_sys.c
25070 @@ -12,6 +12,7 @@
25071 #include <linux/acpi.h>
25072 #include <linux/debugfs.h>
25073 #include <linux/module.h>
25074 +#include <asm/uaccess.h>
25075 #include "internal.h"
25076
25077 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
25078 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25079 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
25080 */
25081 unsigned int size = EC_SPACE_SIZE;
25082 - u8 *data = (u8 *) buf;
25083 + u8 data;
25084 loff_t init_off = *off;
25085 int err = 0;
25086
25087 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25088 size = count;
25089
25090 while (size) {
25091 - err = ec_read(*off, &data[*off - init_off]);
25092 + err = ec_read(*off, &data);
25093 if (err)
25094 return err;
25095 + if (put_user(data, &buf[*off - init_off]))
25096 + return -EFAULT;
25097 *off += 1;
25098 size--;
25099 }
25100 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25101
25102 unsigned int size = count;
25103 loff_t init_off = *off;
25104 - u8 *data = (u8 *) buf;
25105 int err = 0;
25106
25107 if (*off >= EC_SPACE_SIZE)
25108 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25109 }
25110
25111 while (size) {
25112 - u8 byte_write = data[*off - init_off];
25113 + u8 byte_write;
25114 + if (get_user(byte_write, &buf[*off - init_off]))
25115 + return -EFAULT;
25116 err = ec_write(*off, byte_write);
25117 if (err)
25118 return err;
25119 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
25120 index 251c7b62..000462d 100644
25121 --- a/drivers/acpi/proc.c
25122 +++ b/drivers/acpi/proc.c
25123 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
25124 size_t count, loff_t * ppos)
25125 {
25126 struct list_head *node, *next;
25127 - char strbuf[5];
25128 - char str[5] = "";
25129 - unsigned int len = count;
25130 + char strbuf[5] = {0};
25131
25132 - if (len > 4)
25133 - len = 4;
25134 - if (len < 0)
25135 + if (count > 4)
25136 + count = 4;
25137 + if (copy_from_user(strbuf, buffer, count))
25138 return -EFAULT;
25139 -
25140 - if (copy_from_user(strbuf, buffer, len))
25141 - return -EFAULT;
25142 - strbuf[len] = '\0';
25143 - sscanf(strbuf, "%s", str);
25144 + strbuf[count] = '\0';
25145
25146 mutex_lock(&acpi_device_lock);
25147 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
25148 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
25149 if (!dev->wakeup.flags.valid)
25150 continue;
25151
25152 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
25153 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
25154 if (device_can_wakeup(&dev->dev)) {
25155 bool enable = !device_may_wakeup(&dev->dev);
25156 device_set_wakeup_enable(&dev->dev, enable);
25157 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
25158 index 9d7bc9f..a6fc091 100644
25159 --- a/drivers/acpi/processor_driver.c
25160 +++ b/drivers/acpi/processor_driver.c
25161 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
25162 return 0;
25163 #endif
25164
25165 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
25166 + BUG_ON(pr->id >= nr_cpu_ids);
25167
25168 /*
25169 * Buggy BIOS check
25170 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
25171 index c04ad68..0b99473 100644
25172 --- a/drivers/ata/libata-core.c
25173 +++ b/drivers/ata/libata-core.c
25174 @@ -4733,7 +4733,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
25175 struct ata_port *ap;
25176 unsigned int tag;
25177
25178 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25179 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25180 ap = qc->ap;
25181
25182 qc->flags = 0;
25183 @@ -4749,7 +4749,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
25184 struct ata_port *ap;
25185 struct ata_link *link;
25186
25187 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25188 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25189 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
25190 ap = qc->ap;
25191 link = qc->dev->link;
25192 @@ -5754,6 +5754,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25193 return;
25194
25195 spin_lock(&lock);
25196 + pax_open_kernel();
25197
25198 for (cur = ops->inherits; cur; cur = cur->inherits) {
25199 void **inherit = (void **)cur;
25200 @@ -5767,8 +5768,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25201 if (IS_ERR(*pp))
25202 *pp = NULL;
25203
25204 - ops->inherits = NULL;
25205 + *(struct ata_port_operations **)&ops->inherits = NULL;
25206
25207 + pax_close_kernel();
25208 spin_unlock(&lock);
25209 }
25210
25211 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
25212 index e8574bb..f9f6a72 100644
25213 --- a/drivers/ata/pata_arasan_cf.c
25214 +++ b/drivers/ata/pata_arasan_cf.c
25215 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
25216 /* Handle platform specific quirks */
25217 if (pdata->quirk) {
25218 if (pdata->quirk & CF_BROKEN_PIO) {
25219 - ap->ops->set_piomode = NULL;
25220 + pax_open_kernel();
25221 + *(void **)&ap->ops->set_piomode = NULL;
25222 + pax_close_kernel();
25223 ap->pio_mask = 0;
25224 }
25225 if (pdata->quirk & CF_BROKEN_MWDMA)
25226 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
25227 index f9b983a..887b9d8 100644
25228 --- a/drivers/atm/adummy.c
25229 +++ b/drivers/atm/adummy.c
25230 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
25231 vcc->pop(vcc, skb);
25232 else
25233 dev_kfree_skb_any(skb);
25234 - atomic_inc(&vcc->stats->tx);
25235 + atomic_inc_unchecked(&vcc->stats->tx);
25236
25237 return 0;
25238 }
25239 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
25240 index f8f41e0..1f987dd 100644
25241 --- a/drivers/atm/ambassador.c
25242 +++ b/drivers/atm/ambassador.c
25243 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
25244 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
25245
25246 // VC layer stats
25247 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25248 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25249
25250 // free the descriptor
25251 kfree (tx_descr);
25252 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25253 dump_skb ("<<<", vc, skb);
25254
25255 // VC layer stats
25256 - atomic_inc(&atm_vcc->stats->rx);
25257 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25258 __net_timestamp(skb);
25259 // end of our responsibility
25260 atm_vcc->push (atm_vcc, skb);
25261 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25262 } else {
25263 PRINTK (KERN_INFO, "dropped over-size frame");
25264 // should we count this?
25265 - atomic_inc(&atm_vcc->stats->rx_drop);
25266 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25267 }
25268
25269 } else {
25270 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
25271 }
25272
25273 if (check_area (skb->data, skb->len)) {
25274 - atomic_inc(&atm_vcc->stats->tx_err);
25275 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
25276 return -ENOMEM; // ?
25277 }
25278
25279 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
25280 index b22d71c..d6e1049 100644
25281 --- a/drivers/atm/atmtcp.c
25282 +++ b/drivers/atm/atmtcp.c
25283 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25284 if (vcc->pop) vcc->pop(vcc,skb);
25285 else dev_kfree_skb(skb);
25286 if (dev_data) return 0;
25287 - atomic_inc(&vcc->stats->tx_err);
25288 + atomic_inc_unchecked(&vcc->stats->tx_err);
25289 return -ENOLINK;
25290 }
25291 size = skb->len+sizeof(struct atmtcp_hdr);
25292 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25293 if (!new_skb) {
25294 if (vcc->pop) vcc->pop(vcc,skb);
25295 else dev_kfree_skb(skb);
25296 - atomic_inc(&vcc->stats->tx_err);
25297 + atomic_inc_unchecked(&vcc->stats->tx_err);
25298 return -ENOBUFS;
25299 }
25300 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
25301 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25302 if (vcc->pop) vcc->pop(vcc,skb);
25303 else dev_kfree_skb(skb);
25304 out_vcc->push(out_vcc,new_skb);
25305 - atomic_inc(&vcc->stats->tx);
25306 - atomic_inc(&out_vcc->stats->rx);
25307 + atomic_inc_unchecked(&vcc->stats->tx);
25308 + atomic_inc_unchecked(&out_vcc->stats->rx);
25309 return 0;
25310 }
25311
25312 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25313 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
25314 read_unlock(&vcc_sklist_lock);
25315 if (!out_vcc) {
25316 - atomic_inc(&vcc->stats->tx_err);
25317 + atomic_inc_unchecked(&vcc->stats->tx_err);
25318 goto done;
25319 }
25320 skb_pull(skb,sizeof(struct atmtcp_hdr));
25321 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25322 __net_timestamp(new_skb);
25323 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
25324 out_vcc->push(out_vcc,new_skb);
25325 - atomic_inc(&vcc->stats->tx);
25326 - atomic_inc(&out_vcc->stats->rx);
25327 + atomic_inc_unchecked(&vcc->stats->tx);
25328 + atomic_inc_unchecked(&out_vcc->stats->rx);
25329 done:
25330 if (vcc->pop) vcc->pop(vcc,skb);
25331 else dev_kfree_skb(skb);
25332 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
25333 index 956e9ac..133516d 100644
25334 --- a/drivers/atm/eni.c
25335 +++ b/drivers/atm/eni.c
25336 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
25337 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
25338 vcc->dev->number);
25339 length = 0;
25340 - atomic_inc(&vcc->stats->rx_err);
25341 + atomic_inc_unchecked(&vcc->stats->rx_err);
25342 }
25343 else {
25344 length = ATM_CELL_SIZE-1; /* no HEC */
25345 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25346 size);
25347 }
25348 eff = length = 0;
25349 - atomic_inc(&vcc->stats->rx_err);
25350 + atomic_inc_unchecked(&vcc->stats->rx_err);
25351 }
25352 else {
25353 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
25354 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25355 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
25356 vcc->dev->number,vcc->vci,length,size << 2,descr);
25357 length = eff = 0;
25358 - atomic_inc(&vcc->stats->rx_err);
25359 + atomic_inc_unchecked(&vcc->stats->rx_err);
25360 }
25361 }
25362 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
25363 @@ -771,7 +771,7 @@ rx_dequeued++;
25364 vcc->push(vcc,skb);
25365 pushed++;
25366 }
25367 - atomic_inc(&vcc->stats->rx);
25368 + atomic_inc_unchecked(&vcc->stats->rx);
25369 }
25370 wake_up(&eni_dev->rx_wait);
25371 }
25372 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
25373 PCI_DMA_TODEVICE);
25374 if (vcc->pop) vcc->pop(vcc,skb);
25375 else dev_kfree_skb_irq(skb);
25376 - atomic_inc(&vcc->stats->tx);
25377 + atomic_inc_unchecked(&vcc->stats->tx);
25378 wake_up(&eni_dev->tx_wait);
25379 dma_complete++;
25380 }
25381 @@ -1569,7 +1569,7 @@ tx_complete++;
25382 /*--------------------------------- entries ---------------------------------*/
25383
25384
25385 -static const char *media_name[] __devinitdata = {
25386 +static const char *media_name[] __devinitconst = {
25387 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
25388 "UTP", "05?", "06?", "07?", /* 4- 7 */
25389 "TAXI","09?", "10?", "11?", /* 8-11 */
25390 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
25391 index 5072f8a..fa52520d 100644
25392 --- a/drivers/atm/firestream.c
25393 +++ b/drivers/atm/firestream.c
25394 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
25395 }
25396 }
25397
25398 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25399 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25400
25401 fs_dprintk (FS_DEBUG_TXMEM, "i");
25402 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
25403 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25404 #endif
25405 skb_put (skb, qe->p1 & 0xffff);
25406 ATM_SKB(skb)->vcc = atm_vcc;
25407 - atomic_inc(&atm_vcc->stats->rx);
25408 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25409 __net_timestamp(skb);
25410 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
25411 atm_vcc->push (atm_vcc, skb);
25412 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25413 kfree (pe);
25414 }
25415 if (atm_vcc)
25416 - atomic_inc(&atm_vcc->stats->rx_drop);
25417 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25418 break;
25419 case 0x1f: /* Reassembly abort: no buffers. */
25420 /* Silently increment error counter. */
25421 if (atm_vcc)
25422 - atomic_inc(&atm_vcc->stats->rx_drop);
25423 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25424 break;
25425 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
25426 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
25427 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
25428 index 361f5ae..7fc552d 100644
25429 --- a/drivers/atm/fore200e.c
25430 +++ b/drivers/atm/fore200e.c
25431 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
25432 #endif
25433 /* check error condition */
25434 if (*entry->status & STATUS_ERROR)
25435 - atomic_inc(&vcc->stats->tx_err);
25436 + atomic_inc_unchecked(&vcc->stats->tx_err);
25437 else
25438 - atomic_inc(&vcc->stats->tx);
25439 + atomic_inc_unchecked(&vcc->stats->tx);
25440 }
25441 }
25442
25443 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25444 if (skb == NULL) {
25445 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
25446
25447 - atomic_inc(&vcc->stats->rx_drop);
25448 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25449 return -ENOMEM;
25450 }
25451
25452 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25453
25454 dev_kfree_skb_any(skb);
25455
25456 - atomic_inc(&vcc->stats->rx_drop);
25457 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25458 return -ENOMEM;
25459 }
25460
25461 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25462
25463 vcc->push(vcc, skb);
25464 - atomic_inc(&vcc->stats->rx);
25465 + atomic_inc_unchecked(&vcc->stats->rx);
25466
25467 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25468
25469 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
25470 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
25471 fore200e->atm_dev->number,
25472 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
25473 - atomic_inc(&vcc->stats->rx_err);
25474 + atomic_inc_unchecked(&vcc->stats->rx_err);
25475 }
25476 }
25477
25478 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
25479 goto retry_here;
25480 }
25481
25482 - atomic_inc(&vcc->stats->tx_err);
25483 + atomic_inc_unchecked(&vcc->stats->tx_err);
25484
25485 fore200e->tx_sat++;
25486 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
25487 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
25488 index 9a51df4..f3bb5f8 100644
25489 --- a/drivers/atm/he.c
25490 +++ b/drivers/atm/he.c
25491 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25492
25493 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
25494 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
25495 - atomic_inc(&vcc->stats->rx_drop);
25496 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25497 goto return_host_buffers;
25498 }
25499
25500 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25501 RBRQ_LEN_ERR(he_dev->rbrq_head)
25502 ? "LEN_ERR" : "",
25503 vcc->vpi, vcc->vci);
25504 - atomic_inc(&vcc->stats->rx_err);
25505 + atomic_inc_unchecked(&vcc->stats->rx_err);
25506 goto return_host_buffers;
25507 }
25508
25509 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25510 vcc->push(vcc, skb);
25511 spin_lock(&he_dev->global_lock);
25512
25513 - atomic_inc(&vcc->stats->rx);
25514 + atomic_inc_unchecked(&vcc->stats->rx);
25515
25516 return_host_buffers:
25517 ++pdus_assembled;
25518 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
25519 tpd->vcc->pop(tpd->vcc, tpd->skb);
25520 else
25521 dev_kfree_skb_any(tpd->skb);
25522 - atomic_inc(&tpd->vcc->stats->tx_err);
25523 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
25524 }
25525 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
25526 return;
25527 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25528 vcc->pop(vcc, skb);
25529 else
25530 dev_kfree_skb_any(skb);
25531 - atomic_inc(&vcc->stats->tx_err);
25532 + atomic_inc_unchecked(&vcc->stats->tx_err);
25533 return -EINVAL;
25534 }
25535
25536 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25537 vcc->pop(vcc, skb);
25538 else
25539 dev_kfree_skb_any(skb);
25540 - atomic_inc(&vcc->stats->tx_err);
25541 + atomic_inc_unchecked(&vcc->stats->tx_err);
25542 return -EINVAL;
25543 }
25544 #endif
25545 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25546 vcc->pop(vcc, skb);
25547 else
25548 dev_kfree_skb_any(skb);
25549 - atomic_inc(&vcc->stats->tx_err);
25550 + atomic_inc_unchecked(&vcc->stats->tx_err);
25551 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25552 return -ENOMEM;
25553 }
25554 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25555 vcc->pop(vcc, skb);
25556 else
25557 dev_kfree_skb_any(skb);
25558 - atomic_inc(&vcc->stats->tx_err);
25559 + atomic_inc_unchecked(&vcc->stats->tx_err);
25560 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25561 return -ENOMEM;
25562 }
25563 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25564 __enqueue_tpd(he_dev, tpd, cid);
25565 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25566
25567 - atomic_inc(&vcc->stats->tx);
25568 + atomic_inc_unchecked(&vcc->stats->tx);
25569
25570 return 0;
25571 }
25572 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
25573 index b812103..e391a49 100644
25574 --- a/drivers/atm/horizon.c
25575 +++ b/drivers/atm/horizon.c
25576 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
25577 {
25578 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
25579 // VC layer stats
25580 - atomic_inc(&vcc->stats->rx);
25581 + atomic_inc_unchecked(&vcc->stats->rx);
25582 __net_timestamp(skb);
25583 // end of our responsibility
25584 vcc->push (vcc, skb);
25585 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
25586 dev->tx_iovec = NULL;
25587
25588 // VC layer stats
25589 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25590 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25591
25592 // free the skb
25593 hrz_kfree_skb (skb);
25594 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
25595 index 1c05212..c28e200 100644
25596 --- a/drivers/atm/idt77252.c
25597 +++ b/drivers/atm/idt77252.c
25598 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
25599 else
25600 dev_kfree_skb(skb);
25601
25602 - atomic_inc(&vcc->stats->tx);
25603 + atomic_inc_unchecked(&vcc->stats->tx);
25604 }
25605
25606 atomic_dec(&scq->used);
25607 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25608 if ((sb = dev_alloc_skb(64)) == NULL) {
25609 printk("%s: Can't allocate buffers for aal0.\n",
25610 card->name);
25611 - atomic_add(i, &vcc->stats->rx_drop);
25612 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
25613 break;
25614 }
25615 if (!atm_charge(vcc, sb->truesize)) {
25616 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
25617 card->name);
25618 - atomic_add(i - 1, &vcc->stats->rx_drop);
25619 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
25620 dev_kfree_skb(sb);
25621 break;
25622 }
25623 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25624 ATM_SKB(sb)->vcc = vcc;
25625 __net_timestamp(sb);
25626 vcc->push(vcc, sb);
25627 - atomic_inc(&vcc->stats->rx);
25628 + atomic_inc_unchecked(&vcc->stats->rx);
25629
25630 cell += ATM_CELL_PAYLOAD;
25631 }
25632 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25633 "(CDC: %08x)\n",
25634 card->name, len, rpp->len, readl(SAR_REG_CDC));
25635 recycle_rx_pool_skb(card, rpp);
25636 - atomic_inc(&vcc->stats->rx_err);
25637 + atomic_inc_unchecked(&vcc->stats->rx_err);
25638 return;
25639 }
25640 if (stat & SAR_RSQE_CRC) {
25641 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
25642 recycle_rx_pool_skb(card, rpp);
25643 - atomic_inc(&vcc->stats->rx_err);
25644 + atomic_inc_unchecked(&vcc->stats->rx_err);
25645 return;
25646 }
25647 if (skb_queue_len(&rpp->queue) > 1) {
25648 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25649 RXPRINTK("%s: Can't alloc RX skb.\n",
25650 card->name);
25651 recycle_rx_pool_skb(card, rpp);
25652 - atomic_inc(&vcc->stats->rx_err);
25653 + atomic_inc_unchecked(&vcc->stats->rx_err);
25654 return;
25655 }
25656 if (!atm_charge(vcc, skb->truesize)) {
25657 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25658 __net_timestamp(skb);
25659
25660 vcc->push(vcc, skb);
25661 - atomic_inc(&vcc->stats->rx);
25662 + atomic_inc_unchecked(&vcc->stats->rx);
25663
25664 return;
25665 }
25666 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25667 __net_timestamp(skb);
25668
25669 vcc->push(vcc, skb);
25670 - atomic_inc(&vcc->stats->rx);
25671 + atomic_inc_unchecked(&vcc->stats->rx);
25672
25673 if (skb->truesize > SAR_FB_SIZE_3)
25674 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
25675 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
25676 if (vcc->qos.aal != ATM_AAL0) {
25677 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
25678 card->name, vpi, vci);
25679 - atomic_inc(&vcc->stats->rx_drop);
25680 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25681 goto drop;
25682 }
25683
25684 if ((sb = dev_alloc_skb(64)) == NULL) {
25685 printk("%s: Can't allocate buffers for AAL0.\n",
25686 card->name);
25687 - atomic_inc(&vcc->stats->rx_err);
25688 + atomic_inc_unchecked(&vcc->stats->rx_err);
25689 goto drop;
25690 }
25691
25692 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
25693 ATM_SKB(sb)->vcc = vcc;
25694 __net_timestamp(sb);
25695 vcc->push(vcc, sb);
25696 - atomic_inc(&vcc->stats->rx);
25697 + atomic_inc_unchecked(&vcc->stats->rx);
25698
25699 drop:
25700 skb_pull(queue, 64);
25701 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25702
25703 if (vc == NULL) {
25704 printk("%s: NULL connection in send().\n", card->name);
25705 - atomic_inc(&vcc->stats->tx_err);
25706 + atomic_inc_unchecked(&vcc->stats->tx_err);
25707 dev_kfree_skb(skb);
25708 return -EINVAL;
25709 }
25710 if (!test_bit(VCF_TX, &vc->flags)) {
25711 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
25712 - atomic_inc(&vcc->stats->tx_err);
25713 + atomic_inc_unchecked(&vcc->stats->tx_err);
25714 dev_kfree_skb(skb);
25715 return -EINVAL;
25716 }
25717 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25718 break;
25719 default:
25720 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
25721 - atomic_inc(&vcc->stats->tx_err);
25722 + atomic_inc_unchecked(&vcc->stats->tx_err);
25723 dev_kfree_skb(skb);
25724 return -EINVAL;
25725 }
25726
25727 if (skb_shinfo(skb)->nr_frags != 0) {
25728 printk("%s: No scatter-gather yet.\n", card->name);
25729 - atomic_inc(&vcc->stats->tx_err);
25730 + atomic_inc_unchecked(&vcc->stats->tx_err);
25731 dev_kfree_skb(skb);
25732 return -EINVAL;
25733 }
25734 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25735
25736 err = queue_skb(card, vc, skb, oam);
25737 if (err) {
25738 - atomic_inc(&vcc->stats->tx_err);
25739 + atomic_inc_unchecked(&vcc->stats->tx_err);
25740 dev_kfree_skb(skb);
25741 return err;
25742 }
25743 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
25744 skb = dev_alloc_skb(64);
25745 if (!skb) {
25746 printk("%s: Out of memory in send_oam().\n", card->name);
25747 - atomic_inc(&vcc->stats->tx_err);
25748 + atomic_inc_unchecked(&vcc->stats->tx_err);
25749 return -ENOMEM;
25750 }
25751 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
25752 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
25753 index 3d0c2b0..45441fa 100644
25754 --- a/drivers/atm/iphase.c
25755 +++ b/drivers/atm/iphase.c
25756 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
25757 status = (u_short) (buf_desc_ptr->desc_mode);
25758 if (status & (RX_CER | RX_PTE | RX_OFL))
25759 {
25760 - atomic_inc(&vcc->stats->rx_err);
25761 + atomic_inc_unchecked(&vcc->stats->rx_err);
25762 IF_ERR(printk("IA: bad packet, dropping it");)
25763 if (status & RX_CER) {
25764 IF_ERR(printk(" cause: packet CRC error\n");)
25765 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
25766 len = dma_addr - buf_addr;
25767 if (len > iadev->rx_buf_sz) {
25768 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
25769 - atomic_inc(&vcc->stats->rx_err);
25770 + atomic_inc_unchecked(&vcc->stats->rx_err);
25771 goto out_free_desc;
25772 }
25773
25774 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25775 ia_vcc = INPH_IA_VCC(vcc);
25776 if (ia_vcc == NULL)
25777 {
25778 - atomic_inc(&vcc->stats->rx_err);
25779 + atomic_inc_unchecked(&vcc->stats->rx_err);
25780 dev_kfree_skb_any(skb);
25781 atm_return(vcc, atm_guess_pdu2truesize(len));
25782 goto INCR_DLE;
25783 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25784 if ((length > iadev->rx_buf_sz) || (length >
25785 (skb->len - sizeof(struct cpcs_trailer))))
25786 {
25787 - atomic_inc(&vcc->stats->rx_err);
25788 + atomic_inc_unchecked(&vcc->stats->rx_err);
25789 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
25790 length, skb->len);)
25791 dev_kfree_skb_any(skb);
25792 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25793
25794 IF_RX(printk("rx_dle_intr: skb push");)
25795 vcc->push(vcc,skb);
25796 - atomic_inc(&vcc->stats->rx);
25797 + atomic_inc_unchecked(&vcc->stats->rx);
25798 iadev->rx_pkt_cnt++;
25799 }
25800 INCR_DLE:
25801 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
25802 {
25803 struct k_sonet_stats *stats;
25804 stats = &PRIV(_ia_dev[board])->sonet_stats;
25805 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
25806 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
25807 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
25808 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
25809 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
25810 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
25811 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
25812 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
25813 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
25814 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
25815 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
25816 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
25817 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
25818 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
25819 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
25820 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
25821 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
25822 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
25823 }
25824 ia_cmds.status = 0;
25825 break;
25826 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
25827 if ((desc == 0) || (desc > iadev->num_tx_desc))
25828 {
25829 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
25830 - atomic_inc(&vcc->stats->tx);
25831 + atomic_inc_unchecked(&vcc->stats->tx);
25832 if (vcc->pop)
25833 vcc->pop(vcc, skb);
25834 else
25835 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
25836 ATM_DESC(skb) = vcc->vci;
25837 skb_queue_tail(&iadev->tx_dma_q, skb);
25838
25839 - atomic_inc(&vcc->stats->tx);
25840 + atomic_inc_unchecked(&vcc->stats->tx);
25841 iadev->tx_pkt_cnt++;
25842 /* Increment transaction counter */
25843 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
25844
25845 #if 0
25846 /* add flow control logic */
25847 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
25848 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
25849 if (iavcc->vc_desc_cnt > 10) {
25850 vcc->tx_quota = vcc->tx_quota * 3 / 4;
25851 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
25852 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
25853 index f556969..0da15eb 100644
25854 --- a/drivers/atm/lanai.c
25855 +++ b/drivers/atm/lanai.c
25856 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
25857 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
25858 lanai_endtx(lanai, lvcc);
25859 lanai_free_skb(lvcc->tx.atmvcc, skb);
25860 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
25861 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
25862 }
25863
25864 /* Try to fill the buffer - don't call unless there is backlog */
25865 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
25866 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
25867 __net_timestamp(skb);
25868 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
25869 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
25870 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
25871 out:
25872 lvcc->rx.buf.ptr = end;
25873 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
25874 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25875 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
25876 "vcc %d\n", lanai->number, (unsigned int) s, vci);
25877 lanai->stats.service_rxnotaal5++;
25878 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25879 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25880 return 0;
25881 }
25882 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
25883 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25884 int bytes;
25885 read_unlock(&vcc_sklist_lock);
25886 DPRINTK("got trashed rx pdu on vci %d\n", vci);
25887 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25888 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25889 lvcc->stats.x.aal5.service_trash++;
25890 bytes = (SERVICE_GET_END(s) * 16) -
25891 (((unsigned long) lvcc->rx.buf.ptr) -
25892 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25893 }
25894 if (s & SERVICE_STREAM) {
25895 read_unlock(&vcc_sklist_lock);
25896 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25897 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25898 lvcc->stats.x.aal5.service_stream++;
25899 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
25900 "PDU on VCI %d!\n", lanai->number, vci);
25901 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25902 return 0;
25903 }
25904 DPRINTK("got rx crc error on vci %d\n", vci);
25905 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25906 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25907 lvcc->stats.x.aal5.service_rxcrc++;
25908 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
25909 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
25910 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
25911 index 1c70c45..300718d 100644
25912 --- a/drivers/atm/nicstar.c
25913 +++ b/drivers/atm/nicstar.c
25914 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25915 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
25916 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
25917 card->index);
25918 - atomic_inc(&vcc->stats->tx_err);
25919 + atomic_inc_unchecked(&vcc->stats->tx_err);
25920 dev_kfree_skb_any(skb);
25921 return -EINVAL;
25922 }
25923 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25924 if (!vc->tx) {
25925 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
25926 card->index);
25927 - atomic_inc(&vcc->stats->tx_err);
25928 + atomic_inc_unchecked(&vcc->stats->tx_err);
25929 dev_kfree_skb_any(skb);
25930 return -EINVAL;
25931 }
25932 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25933 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
25934 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
25935 card->index);
25936 - atomic_inc(&vcc->stats->tx_err);
25937 + atomic_inc_unchecked(&vcc->stats->tx_err);
25938 dev_kfree_skb_any(skb);
25939 return -EINVAL;
25940 }
25941
25942 if (skb_shinfo(skb)->nr_frags != 0) {
25943 printk("nicstar%d: No scatter-gather yet.\n", card->index);
25944 - atomic_inc(&vcc->stats->tx_err);
25945 + atomic_inc_unchecked(&vcc->stats->tx_err);
25946 dev_kfree_skb_any(skb);
25947 return -EINVAL;
25948 }
25949 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25950 }
25951
25952 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
25953 - atomic_inc(&vcc->stats->tx_err);
25954 + atomic_inc_unchecked(&vcc->stats->tx_err);
25955 dev_kfree_skb_any(skb);
25956 return -EIO;
25957 }
25958 - atomic_inc(&vcc->stats->tx);
25959 + atomic_inc_unchecked(&vcc->stats->tx);
25960
25961 return 0;
25962 }
25963 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25964 printk
25965 ("nicstar%d: Can't allocate buffers for aal0.\n",
25966 card->index);
25967 - atomic_add(i, &vcc->stats->rx_drop);
25968 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
25969 break;
25970 }
25971 if (!atm_charge(vcc, sb->truesize)) {
25972 RXPRINTK
25973 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
25974 card->index);
25975 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
25976 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
25977 dev_kfree_skb_any(sb);
25978 break;
25979 }
25980 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25981 ATM_SKB(sb)->vcc = vcc;
25982 __net_timestamp(sb);
25983 vcc->push(vcc, sb);
25984 - atomic_inc(&vcc->stats->rx);
25985 + atomic_inc_unchecked(&vcc->stats->rx);
25986 cell += ATM_CELL_PAYLOAD;
25987 }
25988
25989 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25990 if (iovb == NULL) {
25991 printk("nicstar%d: Out of iovec buffers.\n",
25992 card->index);
25993 - atomic_inc(&vcc->stats->rx_drop);
25994 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25995 recycle_rx_buf(card, skb);
25996 return;
25997 }
25998 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25999 small or large buffer itself. */
26000 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
26001 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
26002 - atomic_inc(&vcc->stats->rx_err);
26003 + atomic_inc_unchecked(&vcc->stats->rx_err);
26004 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26005 NS_MAX_IOVECS);
26006 NS_PRV_IOVCNT(iovb) = 0;
26007 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26008 ("nicstar%d: Expected a small buffer, and this is not one.\n",
26009 card->index);
26010 which_list(card, skb);
26011 - atomic_inc(&vcc->stats->rx_err);
26012 + atomic_inc_unchecked(&vcc->stats->rx_err);
26013 recycle_rx_buf(card, skb);
26014 vc->rx_iov = NULL;
26015 recycle_iov_buf(card, iovb);
26016 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26017 ("nicstar%d: Expected a large buffer, and this is not one.\n",
26018 card->index);
26019 which_list(card, skb);
26020 - atomic_inc(&vcc->stats->rx_err);
26021 + atomic_inc_unchecked(&vcc->stats->rx_err);
26022 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26023 NS_PRV_IOVCNT(iovb));
26024 vc->rx_iov = NULL;
26025 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26026 printk(" - PDU size mismatch.\n");
26027 else
26028 printk(".\n");
26029 - atomic_inc(&vcc->stats->rx_err);
26030 + atomic_inc_unchecked(&vcc->stats->rx_err);
26031 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26032 NS_PRV_IOVCNT(iovb));
26033 vc->rx_iov = NULL;
26034 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26035 /* skb points to a small buffer */
26036 if (!atm_charge(vcc, skb->truesize)) {
26037 push_rxbufs(card, skb);
26038 - atomic_inc(&vcc->stats->rx_drop);
26039 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26040 } else {
26041 skb_put(skb, len);
26042 dequeue_sm_buf(card, skb);
26043 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26044 ATM_SKB(skb)->vcc = vcc;
26045 __net_timestamp(skb);
26046 vcc->push(vcc, skb);
26047 - atomic_inc(&vcc->stats->rx);
26048 + atomic_inc_unchecked(&vcc->stats->rx);
26049 }
26050 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
26051 struct sk_buff *sb;
26052 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26053 if (len <= NS_SMBUFSIZE) {
26054 if (!atm_charge(vcc, sb->truesize)) {
26055 push_rxbufs(card, sb);
26056 - atomic_inc(&vcc->stats->rx_drop);
26057 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26058 } else {
26059 skb_put(sb, len);
26060 dequeue_sm_buf(card, sb);
26061 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26062 ATM_SKB(sb)->vcc = vcc;
26063 __net_timestamp(sb);
26064 vcc->push(vcc, sb);
26065 - atomic_inc(&vcc->stats->rx);
26066 + atomic_inc_unchecked(&vcc->stats->rx);
26067 }
26068
26069 push_rxbufs(card, skb);
26070 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26071
26072 if (!atm_charge(vcc, skb->truesize)) {
26073 push_rxbufs(card, skb);
26074 - atomic_inc(&vcc->stats->rx_drop);
26075 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26076 } else {
26077 dequeue_lg_buf(card, skb);
26078 #ifdef NS_USE_DESTRUCTORS
26079 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26080 ATM_SKB(skb)->vcc = vcc;
26081 __net_timestamp(skb);
26082 vcc->push(vcc, skb);
26083 - atomic_inc(&vcc->stats->rx);
26084 + atomic_inc_unchecked(&vcc->stats->rx);
26085 }
26086
26087 push_rxbufs(card, sb);
26088 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26089 printk
26090 ("nicstar%d: Out of huge buffers.\n",
26091 card->index);
26092 - atomic_inc(&vcc->stats->rx_drop);
26093 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26094 recycle_iovec_rx_bufs(card,
26095 (struct iovec *)
26096 iovb->data,
26097 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26098 card->hbpool.count++;
26099 } else
26100 dev_kfree_skb_any(hb);
26101 - atomic_inc(&vcc->stats->rx_drop);
26102 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26103 } else {
26104 /* Copy the small buffer to the huge buffer */
26105 sb = (struct sk_buff *)iov->iov_base;
26106 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26107 #endif /* NS_USE_DESTRUCTORS */
26108 __net_timestamp(hb);
26109 vcc->push(vcc, hb);
26110 - atomic_inc(&vcc->stats->rx);
26111 + atomic_inc_unchecked(&vcc->stats->rx);
26112 }
26113 }
26114
26115 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
26116 index 5d1d076..12fbca4 100644
26117 --- a/drivers/atm/solos-pci.c
26118 +++ b/drivers/atm/solos-pci.c
26119 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
26120 }
26121 atm_charge(vcc, skb->truesize);
26122 vcc->push(vcc, skb);
26123 - atomic_inc(&vcc->stats->rx);
26124 + atomic_inc_unchecked(&vcc->stats->rx);
26125 break;
26126
26127 case PKT_STATUS:
26128 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
26129 vcc = SKB_CB(oldskb)->vcc;
26130
26131 if (vcc) {
26132 - atomic_inc(&vcc->stats->tx);
26133 + atomic_inc_unchecked(&vcc->stats->tx);
26134 solos_pop(vcc, oldskb);
26135 } else
26136 dev_kfree_skb_irq(oldskb);
26137 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
26138 index 90f1ccc..04c4a1e 100644
26139 --- a/drivers/atm/suni.c
26140 +++ b/drivers/atm/suni.c
26141 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
26142
26143
26144 #define ADD_LIMITED(s,v) \
26145 - atomic_add((v),&stats->s); \
26146 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
26147 + atomic_add_unchecked((v),&stats->s); \
26148 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
26149
26150
26151 static void suni_hz(unsigned long from_timer)
26152 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
26153 index 5120a96..e2572bd 100644
26154 --- a/drivers/atm/uPD98402.c
26155 +++ b/drivers/atm/uPD98402.c
26156 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
26157 struct sonet_stats tmp;
26158 int error = 0;
26159
26160 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26161 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26162 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
26163 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
26164 if (zero && !error) {
26165 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
26166
26167
26168 #define ADD_LIMITED(s,v) \
26169 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
26170 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
26171 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26172 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
26173 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
26174 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26175
26176
26177 static void stat_event(struct atm_dev *dev)
26178 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
26179 if (reason & uPD98402_INT_PFM) stat_event(dev);
26180 if (reason & uPD98402_INT_PCO) {
26181 (void) GET(PCOCR); /* clear interrupt cause */
26182 - atomic_add(GET(HECCT),
26183 + atomic_add_unchecked(GET(HECCT),
26184 &PRIV(dev)->sonet_stats.uncorr_hcs);
26185 }
26186 if ((reason & uPD98402_INT_RFO) &&
26187 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
26188 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
26189 uPD98402_INT_LOS),PIMR); /* enable them */
26190 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
26191 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26192 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
26193 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
26194 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26195 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
26196 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
26197 return 0;
26198 }
26199
26200 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
26201 index d889f56..17eb71e 100644
26202 --- a/drivers/atm/zatm.c
26203 +++ b/drivers/atm/zatm.c
26204 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26205 }
26206 if (!size) {
26207 dev_kfree_skb_irq(skb);
26208 - if (vcc) atomic_inc(&vcc->stats->rx_err);
26209 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
26210 continue;
26211 }
26212 if (!atm_charge(vcc,skb->truesize)) {
26213 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26214 skb->len = size;
26215 ATM_SKB(skb)->vcc = vcc;
26216 vcc->push(vcc,skb);
26217 - atomic_inc(&vcc->stats->rx);
26218 + atomic_inc_unchecked(&vcc->stats->rx);
26219 }
26220 zout(pos & 0xffff,MTA(mbx));
26221 #if 0 /* probably a stupid idea */
26222 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
26223 skb_queue_head(&zatm_vcc->backlog,skb);
26224 break;
26225 }
26226 - atomic_inc(&vcc->stats->tx);
26227 + atomic_inc_unchecked(&vcc->stats->tx);
26228 wake_up(&zatm_vcc->tx_wait);
26229 }
26230
26231 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
26232 index a4760e0..51283cf 100644
26233 --- a/drivers/base/devtmpfs.c
26234 +++ b/drivers/base/devtmpfs.c
26235 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
26236 if (!thread)
26237 return 0;
26238
26239 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
26240 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
26241 if (err)
26242 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
26243 else
26244 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
26245 index caf995f..6f76697 100644
26246 --- a/drivers/base/power/wakeup.c
26247 +++ b/drivers/base/power/wakeup.c
26248 @@ -30,14 +30,14 @@ bool events_check_enabled;
26249 * They need to be modified together atomically, so it's better to use one
26250 * atomic variable to hold them both.
26251 */
26252 -static atomic_t combined_event_count = ATOMIC_INIT(0);
26253 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
26254
26255 #define IN_PROGRESS_BITS (sizeof(int) * 4)
26256 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
26257
26258 static void split_counters(unsigned int *cnt, unsigned int *inpr)
26259 {
26260 - unsigned int comb = atomic_read(&combined_event_count);
26261 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
26262
26263 *cnt = (comb >> IN_PROGRESS_BITS);
26264 *inpr = comb & MAX_IN_PROGRESS;
26265 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
26266 ws->last_time = ktime_get();
26267
26268 /* Increment the counter of events in progress. */
26269 - atomic_inc(&combined_event_count);
26270 + atomic_inc_unchecked(&combined_event_count);
26271 }
26272
26273 /**
26274 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
26275 * Increment the counter of registered wakeup events and decrement the
26276 * couter of wakeup events in progress simultaneously.
26277 */
26278 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
26279 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
26280 }
26281
26282 /**
26283 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
26284 index 587cce5..77b928b 100644
26285 --- a/drivers/block/cciss.c
26286 +++ b/drivers/block/cciss.c
26287 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
26288 int err;
26289 u32 cp;
26290
26291 + memset(&arg64, 0, sizeof(arg64));
26292 +
26293 err = 0;
26294 err |=
26295 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
26296 @@ -1735,7 +1737,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
26297 case CCISS_BIG_PASSTHRU:
26298 return cciss_bigpassthru(h, argp);
26299
26300 - /* scsi_cmd_ioctl handles these, below, though some are not */
26301 + /* scsi_cmd_blk_ioctl handles these, below, though some are not */
26302 /* very meaningful for cciss. SG_IO is the main one people want. */
26303
26304 case SG_GET_VERSION_NUM:
26305 @@ -1746,9 +1748,9 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
26306 case SG_EMULATED_HOST:
26307 case SG_IO:
26308 case SCSI_IOCTL_SEND_COMMAND:
26309 - return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp);
26310 + return scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);
26311
26312 - /* scsi_cmd_ioctl would normally handle these, below, but */
26313 + /* scsi_cmd_blk_ioctl would normally handle these, below, but */
26314 /* they aren't a good fit for cciss, as CD-ROMs are */
26315 /* not supported, and we don't have any bus/target/lun */
26316 /* which we present to the kernel. */
26317 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
26318 while (!list_empty(&h->reqQ)) {
26319 c = list_entry(h->reqQ.next, CommandList_struct, list);
26320 /* can't do anything if fifo is full */
26321 - if ((h->access.fifo_full(h))) {
26322 + if ((h->access->fifo_full(h))) {
26323 dev_warn(&h->pdev->dev, "fifo full\n");
26324 break;
26325 }
26326 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
26327 h->Qdepth--;
26328
26329 /* Tell the controller execute command */
26330 - h->access.submit_command(h, c);
26331 + h->access->submit_command(h, c);
26332
26333 /* Put job onto the completed Q */
26334 addQ(&h->cmpQ, c);
26335 @@ -3443,17 +3445,17 @@ startio:
26336
26337 static inline unsigned long get_next_completion(ctlr_info_t *h)
26338 {
26339 - return h->access.command_completed(h);
26340 + return h->access->command_completed(h);
26341 }
26342
26343 static inline int interrupt_pending(ctlr_info_t *h)
26344 {
26345 - return h->access.intr_pending(h);
26346 + return h->access->intr_pending(h);
26347 }
26348
26349 static inline long interrupt_not_for_us(ctlr_info_t *h)
26350 {
26351 - return ((h->access.intr_pending(h) == 0) ||
26352 + return ((h->access->intr_pending(h) == 0) ||
26353 (h->interrupts_enabled == 0));
26354 }
26355
26356 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
26357 u32 a;
26358
26359 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
26360 - return h->access.command_completed(h);
26361 + return h->access->command_completed(h);
26362
26363 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
26364 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
26365 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
26366 trans_support & CFGTBL_Trans_use_short_tags);
26367
26368 /* Change the access methods to the performant access methods */
26369 - h->access = SA5_performant_access;
26370 + h->access = &SA5_performant_access;
26371 h->transMethod = CFGTBL_Trans_Performant;
26372
26373 return;
26374 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
26375 if (prod_index < 0)
26376 return -ENODEV;
26377 h->product_name = products[prod_index].product_name;
26378 - h->access = *(products[prod_index].access);
26379 + h->access = products[prod_index].access;
26380
26381 if (cciss_board_disabled(h)) {
26382 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
26383 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
26384 }
26385
26386 /* make sure the board interrupts are off */
26387 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26388 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26389 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
26390 if (rc)
26391 goto clean2;
26392 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
26393 * fake ones to scoop up any residual completions.
26394 */
26395 spin_lock_irqsave(&h->lock, flags);
26396 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26397 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26398 spin_unlock_irqrestore(&h->lock, flags);
26399 free_irq(h->intr[h->intr_mode], h);
26400 rc = cciss_request_irq(h, cciss_msix_discard_completions,
26401 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
26402 dev_info(&h->pdev->dev, "Board READY.\n");
26403 dev_info(&h->pdev->dev,
26404 "Waiting for stale completions to drain.\n");
26405 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26406 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26407 msleep(10000);
26408 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26409 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26410
26411 rc = controller_reset_failed(h->cfgtable);
26412 if (rc)
26413 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
26414 cciss_scsi_setup(h);
26415
26416 /* Turn the interrupts on so we can service requests */
26417 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26418 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26419
26420 /* Get the firmware version */
26421 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
26422 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
26423 kfree(flush_buf);
26424 if (return_code != IO_OK)
26425 dev_warn(&h->pdev->dev, "Error flushing cache\n");
26426 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26427 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26428 free_irq(h->intr[h->intr_mode], h);
26429 }
26430
26431 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
26432 index 7fda30e..eb5dfe0 100644
26433 --- a/drivers/block/cciss.h
26434 +++ b/drivers/block/cciss.h
26435 @@ -101,7 +101,7 @@ struct ctlr_info
26436 /* information about each logical volume */
26437 drive_info_struct *drv[CISS_MAX_LUN];
26438
26439 - struct access_method access;
26440 + struct access_method *access;
26441
26442 /* queue and queue Info */
26443 struct list_head reqQ;
26444 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
26445 index 9125bbe..eede5c8 100644
26446 --- a/drivers/block/cpqarray.c
26447 +++ b/drivers/block/cpqarray.c
26448 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26449 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
26450 goto Enomem4;
26451 }
26452 - hba[i]->access.set_intr_mask(hba[i], 0);
26453 + hba[i]->access->set_intr_mask(hba[i], 0);
26454 if (request_irq(hba[i]->intr, do_ida_intr,
26455 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
26456 {
26457 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26458 add_timer(&hba[i]->timer);
26459
26460 /* Enable IRQ now that spinlock and rate limit timer are set up */
26461 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26462 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26463
26464 for(j=0; j<NWD; j++) {
26465 struct gendisk *disk = ida_gendisk[i][j];
26466 @@ -694,7 +694,7 @@ DBGINFO(
26467 for(i=0; i<NR_PRODUCTS; i++) {
26468 if (board_id == products[i].board_id) {
26469 c->product_name = products[i].product_name;
26470 - c->access = *(products[i].access);
26471 + c->access = products[i].access;
26472 break;
26473 }
26474 }
26475 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
26476 hba[ctlr]->intr = intr;
26477 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
26478 hba[ctlr]->product_name = products[j].product_name;
26479 - hba[ctlr]->access = *(products[j].access);
26480 + hba[ctlr]->access = products[j].access;
26481 hba[ctlr]->ctlr = ctlr;
26482 hba[ctlr]->board_id = board_id;
26483 hba[ctlr]->pci_dev = NULL; /* not PCI */
26484 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
26485
26486 while((c = h->reqQ) != NULL) {
26487 /* Can't do anything if we're busy */
26488 - if (h->access.fifo_full(h) == 0)
26489 + if (h->access->fifo_full(h) == 0)
26490 return;
26491
26492 /* Get the first entry from the request Q */
26493 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
26494 h->Qdepth--;
26495
26496 /* Tell the controller to do our bidding */
26497 - h->access.submit_command(h, c);
26498 + h->access->submit_command(h, c);
26499
26500 /* Get onto the completion Q */
26501 addQ(&h->cmpQ, c);
26502 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26503 unsigned long flags;
26504 __u32 a,a1;
26505
26506 - istat = h->access.intr_pending(h);
26507 + istat = h->access->intr_pending(h);
26508 /* Is this interrupt for us? */
26509 if (istat == 0)
26510 return IRQ_NONE;
26511 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26512 */
26513 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
26514 if (istat & FIFO_NOT_EMPTY) {
26515 - while((a = h->access.command_completed(h))) {
26516 + while((a = h->access->command_completed(h))) {
26517 a1 = a; a &= ~3;
26518 if ((c = h->cmpQ) == NULL)
26519 {
26520 @@ -1449,11 +1449,11 @@ static int sendcmd(
26521 /*
26522 * Disable interrupt
26523 */
26524 - info_p->access.set_intr_mask(info_p, 0);
26525 + info_p->access->set_intr_mask(info_p, 0);
26526 /* Make sure there is room in the command FIFO */
26527 /* Actually it should be completely empty at this time. */
26528 for (i = 200000; i > 0; i--) {
26529 - temp = info_p->access.fifo_full(info_p);
26530 + temp = info_p->access->fifo_full(info_p);
26531 if (temp != 0) {
26532 break;
26533 }
26534 @@ -1466,7 +1466,7 @@ DBG(
26535 /*
26536 * Send the cmd
26537 */
26538 - info_p->access.submit_command(info_p, c);
26539 + info_p->access->submit_command(info_p, c);
26540 complete = pollcomplete(ctlr);
26541
26542 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
26543 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
26544 * we check the new geometry. Then turn interrupts back on when
26545 * we're done.
26546 */
26547 - host->access.set_intr_mask(host, 0);
26548 + host->access->set_intr_mask(host, 0);
26549 getgeometry(ctlr);
26550 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
26551 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
26552
26553 for(i=0; i<NWD; i++) {
26554 struct gendisk *disk = ida_gendisk[ctlr][i];
26555 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
26556 /* Wait (up to 2 seconds) for a command to complete */
26557
26558 for (i = 200000; i > 0; i--) {
26559 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
26560 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
26561 if (done == 0) {
26562 udelay(10); /* a short fixed delay */
26563 } else
26564 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
26565 index be73e9d..7fbf140 100644
26566 --- a/drivers/block/cpqarray.h
26567 +++ b/drivers/block/cpqarray.h
26568 @@ -99,7 +99,7 @@ struct ctlr_info {
26569 drv_info_t drv[NWD];
26570 struct proc_dir_entry *proc;
26571
26572 - struct access_method access;
26573 + struct access_method *access;
26574
26575 cmdlist_t *reqQ;
26576 cmdlist_t *cmpQ;
26577 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
26578 index 9cf2035..bffca95 100644
26579 --- a/drivers/block/drbd/drbd_int.h
26580 +++ b/drivers/block/drbd/drbd_int.h
26581 @@ -736,7 +736,7 @@ struct drbd_request;
26582 struct drbd_epoch {
26583 struct list_head list;
26584 unsigned int barrier_nr;
26585 - atomic_t epoch_size; /* increased on every request added. */
26586 + atomic_unchecked_t epoch_size; /* increased on every request added. */
26587 atomic_t active; /* increased on every req. added, and dec on every finished. */
26588 unsigned long flags;
26589 };
26590 @@ -1108,7 +1108,7 @@ struct drbd_conf {
26591 void *int_dig_in;
26592 void *int_dig_vv;
26593 wait_queue_head_t seq_wait;
26594 - atomic_t packet_seq;
26595 + atomic_unchecked_t packet_seq;
26596 unsigned int peer_seq;
26597 spinlock_t peer_seq_lock;
26598 unsigned int minor;
26599 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
26600
26601 static inline void drbd_tcp_cork(struct socket *sock)
26602 {
26603 - int __user val = 1;
26604 + int val = 1;
26605 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26606 - (char __user *)&val, sizeof(val));
26607 + (char __force_user *)&val, sizeof(val));
26608 }
26609
26610 static inline void drbd_tcp_uncork(struct socket *sock)
26611 {
26612 - int __user val = 0;
26613 + int val = 0;
26614 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26615 - (char __user *)&val, sizeof(val));
26616 + (char __force_user *)&val, sizeof(val));
26617 }
26618
26619 static inline void drbd_tcp_nodelay(struct socket *sock)
26620 {
26621 - int __user val = 1;
26622 + int val = 1;
26623 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
26624 - (char __user *)&val, sizeof(val));
26625 + (char __force_user *)&val, sizeof(val));
26626 }
26627
26628 static inline void drbd_tcp_quickack(struct socket *sock)
26629 {
26630 - int __user val = 2;
26631 + int val = 2;
26632 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
26633 - (char __user *)&val, sizeof(val));
26634 + (char __force_user *)&val, sizeof(val));
26635 }
26636
26637 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
26638 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
26639 index 0358e55..bc33689 100644
26640 --- a/drivers/block/drbd/drbd_main.c
26641 +++ b/drivers/block/drbd/drbd_main.c
26642 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
26643 p.sector = sector;
26644 p.block_id = block_id;
26645 p.blksize = blksize;
26646 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
26647 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
26648
26649 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
26650 return false;
26651 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
26652 p.sector = cpu_to_be64(req->sector);
26653 p.block_id = (unsigned long)req;
26654 p.seq_num = cpu_to_be32(req->seq_num =
26655 - atomic_add_return(1, &mdev->packet_seq));
26656 + atomic_add_return_unchecked(1, &mdev->packet_seq));
26657
26658 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
26659
26660 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
26661 atomic_set(&mdev->unacked_cnt, 0);
26662 atomic_set(&mdev->local_cnt, 0);
26663 atomic_set(&mdev->net_cnt, 0);
26664 - atomic_set(&mdev->packet_seq, 0);
26665 + atomic_set_unchecked(&mdev->packet_seq, 0);
26666 atomic_set(&mdev->pp_in_use, 0);
26667 atomic_set(&mdev->pp_in_use_by_net, 0);
26668 atomic_set(&mdev->rs_sect_in, 0);
26669 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
26670 mdev->receiver.t_state);
26671
26672 /* no need to lock it, I'm the only thread alive */
26673 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
26674 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
26675 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
26676 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
26677 mdev->al_writ_cnt =
26678 mdev->bm_writ_cnt =
26679 mdev->read_cnt =
26680 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
26681 index af2a250..219c74b 100644
26682 --- a/drivers/block/drbd/drbd_nl.c
26683 +++ b/drivers/block/drbd/drbd_nl.c
26684 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
26685 module_put(THIS_MODULE);
26686 }
26687
26688 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26689 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26690
26691 static unsigned short *
26692 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
26693 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
26694 cn_reply->id.idx = CN_IDX_DRBD;
26695 cn_reply->id.val = CN_VAL_DRBD;
26696
26697 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26698 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26699 cn_reply->ack = 0; /* not used here. */
26700 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26701 (int)((char *)tl - (char *)reply->tag_list);
26702 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
26703 cn_reply->id.idx = CN_IDX_DRBD;
26704 cn_reply->id.val = CN_VAL_DRBD;
26705
26706 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26707 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26708 cn_reply->ack = 0; /* not used here. */
26709 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26710 (int)((char *)tl - (char *)reply->tag_list);
26711 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
26712 cn_reply->id.idx = CN_IDX_DRBD;
26713 cn_reply->id.val = CN_VAL_DRBD;
26714
26715 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
26716 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
26717 cn_reply->ack = 0; // not used here.
26718 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26719 (int)((char*)tl - (char*)reply->tag_list);
26720 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
26721 cn_reply->id.idx = CN_IDX_DRBD;
26722 cn_reply->id.val = CN_VAL_DRBD;
26723
26724 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26725 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26726 cn_reply->ack = 0; /* not used here. */
26727 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26728 (int)((char *)tl - (char *)reply->tag_list);
26729 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
26730 index 43beaca..4a5b1dd 100644
26731 --- a/drivers/block/drbd/drbd_receiver.c
26732 +++ b/drivers/block/drbd/drbd_receiver.c
26733 @@ -894,7 +894,7 @@ retry:
26734 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
26735 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
26736
26737 - atomic_set(&mdev->packet_seq, 0);
26738 + atomic_set_unchecked(&mdev->packet_seq, 0);
26739 mdev->peer_seq = 0;
26740
26741 drbd_thread_start(&mdev->asender);
26742 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26743 do {
26744 next_epoch = NULL;
26745
26746 - epoch_size = atomic_read(&epoch->epoch_size);
26747 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
26748
26749 switch (ev & ~EV_CLEANUP) {
26750 case EV_PUT:
26751 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26752 rv = FE_DESTROYED;
26753 } else {
26754 epoch->flags = 0;
26755 - atomic_set(&epoch->epoch_size, 0);
26756 + atomic_set_unchecked(&epoch->epoch_size, 0);
26757 /* atomic_set(&epoch->active, 0); is already zero */
26758 if (rv == FE_STILL_LIVE)
26759 rv = FE_RECYCLED;
26760 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26761 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
26762 drbd_flush(mdev);
26763
26764 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26765 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
26766 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
26767 if (epoch)
26768 break;
26769 }
26770
26771 epoch = mdev->current_epoch;
26772 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
26773 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
26774
26775 D_ASSERT(atomic_read(&epoch->active) == 0);
26776 D_ASSERT(epoch->flags == 0);
26777 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26778 }
26779
26780 epoch->flags = 0;
26781 - atomic_set(&epoch->epoch_size, 0);
26782 + atomic_set_unchecked(&epoch->epoch_size, 0);
26783 atomic_set(&epoch->active, 0);
26784
26785 spin_lock(&mdev->epoch_lock);
26786 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26787 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
26788 list_add(&epoch->list, &mdev->current_epoch->list);
26789 mdev->current_epoch = epoch;
26790 mdev->epochs++;
26791 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
26792 spin_unlock(&mdev->peer_seq_lock);
26793
26794 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
26795 - atomic_inc(&mdev->current_epoch->epoch_size);
26796 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
26797 return drbd_drain_block(mdev, data_size);
26798 }
26799
26800 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
26801
26802 spin_lock(&mdev->epoch_lock);
26803 e->epoch = mdev->current_epoch;
26804 - atomic_inc(&e->epoch->epoch_size);
26805 + atomic_inc_unchecked(&e->epoch->epoch_size);
26806 atomic_inc(&e->epoch->active);
26807 spin_unlock(&mdev->epoch_lock);
26808
26809 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
26810 D_ASSERT(list_empty(&mdev->done_ee));
26811
26812 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
26813 - atomic_set(&mdev->current_epoch->epoch_size, 0);
26814 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
26815 D_ASSERT(list_empty(&mdev->current_epoch->list));
26816 }
26817
26818 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
26819 index 1e888c9..05cf1b0 100644
26820 --- a/drivers/block/loop.c
26821 +++ b/drivers/block/loop.c
26822 @@ -227,7 +227,7 @@ static int __do_lo_send_write(struct file *file,
26823 mm_segment_t old_fs = get_fs();
26824
26825 set_fs(get_ds());
26826 - bw = file->f_op->write(file, buf, len, &pos);
26827 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
26828 set_fs(old_fs);
26829 if (likely(bw == len))
26830 return 0;
26831 diff --git a/drivers/block/ub.c b/drivers/block/ub.c
26832 index 0e376d4..7333b9e 100644
26833 --- a/drivers/block/ub.c
26834 +++ b/drivers/block/ub.c
26835 @@ -1744,12 +1744,11 @@ static int ub_bd_release(struct gendisk *disk, fmode_t mode)
26836 static int ub_bd_ioctl(struct block_device *bdev, fmode_t mode,
26837 unsigned int cmd, unsigned long arg)
26838 {
26839 - struct gendisk *disk = bdev->bd_disk;
26840 void __user *usermem = (void __user *) arg;
26841 int ret;
26842
26843 mutex_lock(&ub_mutex);
26844 - ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem);
26845 + ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, usermem);
26846 mutex_unlock(&ub_mutex);
26847
26848 return ret;
26849 diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
26850 index 4d0b70a..e46f2f7 100644
26851 --- a/drivers/block/virtio_blk.c
26852 +++ b/drivers/block/virtio_blk.c
26853 @@ -243,8 +243,8 @@ static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
26854 if (!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_SCSI))
26855 return -ENOTTY;
26856
26857 - return scsi_cmd_ioctl(disk->queue, disk, mode, cmd,
26858 - (void __user *)data);
26859 + return scsi_cmd_blk_ioctl(bdev, mode, cmd,
26860 + (void __user *)data);
26861 }
26862
26863 /* We provide getgeo only to please some old bootloader/partitioning tools */
26864 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
26865 index f997c27..cedb231 100644
26866 --- a/drivers/cdrom/cdrom.c
26867 +++ b/drivers/cdrom/cdrom.c
26868 @@ -2747,12 +2747,11 @@ int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
26869 {
26870 void __user *argp = (void __user *)arg;
26871 int ret;
26872 - struct gendisk *disk = bdev->bd_disk;
26873
26874 /*
26875 * Try the generic SCSI command ioctl's first.
26876 */
26877 - ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp);
26878 + ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);
26879 if (ret != -ENOTTY)
26880 return ret;
26881
26882 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
26883 index 4364303..9adf4ee 100644
26884 --- a/drivers/char/Kconfig
26885 +++ b/drivers/char/Kconfig
26886 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
26887
26888 config DEVKMEM
26889 bool "/dev/kmem virtual device support"
26890 - default y
26891 + default n
26892 + depends on !GRKERNSEC_KMEM
26893 help
26894 Say Y here if you want to support the /dev/kmem device. The
26895 /dev/kmem device is rarely used, but can be used for certain
26896 @@ -596,6 +597,7 @@ config DEVPORT
26897 bool
26898 depends on !M68K
26899 depends on ISA || PCI
26900 + depends on !GRKERNSEC_KMEM
26901 default y
26902
26903 source "drivers/s390/char/Kconfig"
26904 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
26905 index 2e04433..22afc64 100644
26906 --- a/drivers/char/agp/frontend.c
26907 +++ b/drivers/char/agp/frontend.c
26908 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
26909 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
26910 return -EFAULT;
26911
26912 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
26913 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
26914 return -EFAULT;
26915
26916 client = agp_find_client_by_pid(reserve.pid);
26917 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
26918 index 095ab90..afad0a4 100644
26919 --- a/drivers/char/briq_panel.c
26920 +++ b/drivers/char/briq_panel.c
26921 @@ -9,6 +9,7 @@
26922 #include <linux/types.h>
26923 #include <linux/errno.h>
26924 #include <linux/tty.h>
26925 +#include <linux/mutex.h>
26926 #include <linux/timer.h>
26927 #include <linux/kernel.h>
26928 #include <linux/wait.h>
26929 @@ -34,6 +35,7 @@ static int vfd_is_open;
26930 static unsigned char vfd[40];
26931 static int vfd_cursor;
26932 static unsigned char ledpb, led;
26933 +static DEFINE_MUTEX(vfd_mutex);
26934
26935 static void update_vfd(void)
26936 {
26937 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
26938 if (!vfd_is_open)
26939 return -EBUSY;
26940
26941 + mutex_lock(&vfd_mutex);
26942 for (;;) {
26943 char c;
26944 if (!indx)
26945 break;
26946 - if (get_user(c, buf))
26947 + if (get_user(c, buf)) {
26948 + mutex_unlock(&vfd_mutex);
26949 return -EFAULT;
26950 + }
26951 if (esc) {
26952 set_led(c);
26953 esc = 0;
26954 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
26955 buf++;
26956 }
26957 update_vfd();
26958 + mutex_unlock(&vfd_mutex);
26959
26960 return len;
26961 }
26962 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
26963 index f773a9d..65cd683 100644
26964 --- a/drivers/char/genrtc.c
26965 +++ b/drivers/char/genrtc.c
26966 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
26967 switch (cmd) {
26968
26969 case RTC_PLL_GET:
26970 + memset(&pll, 0, sizeof(pll));
26971 if (get_rtc_pll(&pll))
26972 return -EINVAL;
26973 else
26974 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
26975 index 0833896..cccce52 100644
26976 --- a/drivers/char/hpet.c
26977 +++ b/drivers/char/hpet.c
26978 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
26979 }
26980
26981 static int
26982 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
26983 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
26984 struct hpet_info *info)
26985 {
26986 struct hpet_timer __iomem *timer;
26987 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
26988 index 58c0e63..46c16bf 100644
26989 --- a/drivers/char/ipmi/ipmi_msghandler.c
26990 +++ b/drivers/char/ipmi/ipmi_msghandler.c
26991 @@ -415,7 +415,7 @@ struct ipmi_smi {
26992 struct proc_dir_entry *proc_dir;
26993 char proc_dir_name[10];
26994
26995 - atomic_t stats[IPMI_NUM_STATS];
26996 + atomic_unchecked_t stats[IPMI_NUM_STATS];
26997
26998 /*
26999 * run_to_completion duplicate of smb_info, smi_info
27000 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
27001
27002
27003 #define ipmi_inc_stat(intf, stat) \
27004 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
27005 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
27006 #define ipmi_get_stat(intf, stat) \
27007 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
27008 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
27009
27010 static int is_lan_addr(struct ipmi_addr *addr)
27011 {
27012 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
27013 INIT_LIST_HEAD(&intf->cmd_rcvrs);
27014 init_waitqueue_head(&intf->waitq);
27015 for (i = 0; i < IPMI_NUM_STATS; i++)
27016 - atomic_set(&intf->stats[i], 0);
27017 + atomic_set_unchecked(&intf->stats[i], 0);
27018
27019 intf->proc_dir = NULL;
27020
27021 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
27022 index 9397ab4..d01bee1 100644
27023 --- a/drivers/char/ipmi/ipmi_si_intf.c
27024 +++ b/drivers/char/ipmi/ipmi_si_intf.c
27025 @@ -277,7 +277,7 @@ struct smi_info {
27026 unsigned char slave_addr;
27027
27028 /* Counters and things for the proc filesystem. */
27029 - atomic_t stats[SI_NUM_STATS];
27030 + atomic_unchecked_t stats[SI_NUM_STATS];
27031
27032 struct task_struct *thread;
27033
27034 @@ -286,9 +286,9 @@ struct smi_info {
27035 };
27036
27037 #define smi_inc_stat(smi, stat) \
27038 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
27039 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
27040 #define smi_get_stat(smi, stat) \
27041 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
27042 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
27043
27044 #define SI_MAX_PARMS 4
27045
27046 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
27047 atomic_set(&new_smi->req_events, 0);
27048 new_smi->run_to_completion = 0;
27049 for (i = 0; i < SI_NUM_STATS; i++)
27050 - atomic_set(&new_smi->stats[i], 0);
27051 + atomic_set_unchecked(&new_smi->stats[i], 0);
27052
27053 new_smi->interrupt_disabled = 1;
27054 atomic_set(&new_smi->stop_operation, 0);
27055 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
27056 index 1aeaaba..e018570 100644
27057 --- a/drivers/char/mbcs.c
27058 +++ b/drivers/char/mbcs.c
27059 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
27060 return 0;
27061 }
27062
27063 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
27064 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
27065 {
27066 .part_num = MBCS_PART_NUM,
27067 .mfg_num = MBCS_MFG_NUM,
27068 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
27069 index 1451790..f705c30 100644
27070 --- a/drivers/char/mem.c
27071 +++ b/drivers/char/mem.c
27072 @@ -18,6 +18,7 @@
27073 #include <linux/raw.h>
27074 #include <linux/tty.h>
27075 #include <linux/capability.h>
27076 +#include <linux/security.h>
27077 #include <linux/ptrace.h>
27078 #include <linux/device.h>
27079 #include <linux/highmem.h>
27080 @@ -35,6 +36,10 @@
27081 # include <linux/efi.h>
27082 #endif
27083
27084 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27085 +extern const struct file_operations grsec_fops;
27086 +#endif
27087 +
27088 static inline unsigned long size_inside_page(unsigned long start,
27089 unsigned long size)
27090 {
27091 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27092
27093 while (cursor < to) {
27094 if (!devmem_is_allowed(pfn)) {
27095 +#ifdef CONFIG_GRKERNSEC_KMEM
27096 + gr_handle_mem_readwrite(from, to);
27097 +#else
27098 printk(KERN_INFO
27099 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
27100 current->comm, from, to);
27101 +#endif
27102 return 0;
27103 }
27104 cursor += PAGE_SIZE;
27105 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27106 }
27107 return 1;
27108 }
27109 +#elif defined(CONFIG_GRKERNSEC_KMEM)
27110 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27111 +{
27112 + return 0;
27113 +}
27114 #else
27115 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27116 {
27117 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27118
27119 while (count > 0) {
27120 unsigned long remaining;
27121 + char *temp;
27122
27123 sz = size_inside_page(p, count);
27124
27125 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27126 if (!ptr)
27127 return -EFAULT;
27128
27129 - remaining = copy_to_user(buf, ptr, sz);
27130 +#ifdef CONFIG_PAX_USERCOPY
27131 + temp = kmalloc(sz, GFP_KERNEL);
27132 + if (!temp) {
27133 + unxlate_dev_mem_ptr(p, ptr);
27134 + return -ENOMEM;
27135 + }
27136 + memcpy(temp, ptr, sz);
27137 +#else
27138 + temp = ptr;
27139 +#endif
27140 +
27141 + remaining = copy_to_user(buf, temp, sz);
27142 +
27143 +#ifdef CONFIG_PAX_USERCOPY
27144 + kfree(temp);
27145 +#endif
27146 +
27147 unxlate_dev_mem_ptr(p, ptr);
27148 if (remaining)
27149 return -EFAULT;
27150 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27151 size_t count, loff_t *ppos)
27152 {
27153 unsigned long p = *ppos;
27154 - ssize_t low_count, read, sz;
27155 + ssize_t low_count, read, sz, err = 0;
27156 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
27157 - int err = 0;
27158
27159 read = 0;
27160 if (p < (unsigned long) high_memory) {
27161 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27162 }
27163 #endif
27164 while (low_count > 0) {
27165 + char *temp;
27166 +
27167 sz = size_inside_page(p, low_count);
27168
27169 /*
27170 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27171 */
27172 kbuf = xlate_dev_kmem_ptr((char *)p);
27173
27174 - if (copy_to_user(buf, kbuf, sz))
27175 +#ifdef CONFIG_PAX_USERCOPY
27176 + temp = kmalloc(sz, GFP_KERNEL);
27177 + if (!temp)
27178 + return -ENOMEM;
27179 + memcpy(temp, kbuf, sz);
27180 +#else
27181 + temp = kbuf;
27182 +#endif
27183 +
27184 + err = copy_to_user(buf, temp, sz);
27185 +
27186 +#ifdef CONFIG_PAX_USERCOPY
27187 + kfree(temp);
27188 +#endif
27189 +
27190 + if (err)
27191 return -EFAULT;
27192 buf += sz;
27193 p += sz;
27194 @@ -867,6 +914,9 @@ static const struct memdev {
27195 #ifdef CONFIG_CRASH_DUMP
27196 [12] = { "oldmem", 0, &oldmem_fops, NULL },
27197 #endif
27198 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27199 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
27200 +#endif
27201 };
27202
27203 static int memory_open(struct inode *inode, struct file *filp)
27204 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
27205 index da3cfee..a5a6606 100644
27206 --- a/drivers/char/nvram.c
27207 +++ b/drivers/char/nvram.c
27208 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
27209
27210 spin_unlock_irq(&rtc_lock);
27211
27212 - if (copy_to_user(buf, contents, tmp - contents))
27213 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
27214 return -EFAULT;
27215
27216 *ppos = i;
27217 diff --git a/drivers/char/random.c b/drivers/char/random.c
27218 index 6035ab8..bdfe4fd 100644
27219 --- a/drivers/char/random.c
27220 +++ b/drivers/char/random.c
27221 @@ -261,8 +261,13 @@
27222 /*
27223 * Configuration information
27224 */
27225 +#ifdef CONFIG_GRKERNSEC_RANDNET
27226 +#define INPUT_POOL_WORDS 512
27227 +#define OUTPUT_POOL_WORDS 128
27228 +#else
27229 #define INPUT_POOL_WORDS 128
27230 #define OUTPUT_POOL_WORDS 32
27231 +#endif
27232 #define SEC_XFER_SIZE 512
27233 #define EXTRACT_SIZE 10
27234
27235 @@ -300,10 +305,17 @@ static struct poolinfo {
27236 int poolwords;
27237 int tap1, tap2, tap3, tap4, tap5;
27238 } poolinfo_table[] = {
27239 +#ifdef CONFIG_GRKERNSEC_RANDNET
27240 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
27241 + { 512, 411, 308, 208, 104, 1 },
27242 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
27243 + { 128, 103, 76, 51, 25, 1 },
27244 +#else
27245 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
27246 { 128, 103, 76, 51, 25, 1 },
27247 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
27248 { 32, 26, 20, 14, 7, 1 },
27249 +#endif
27250 #if 0
27251 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
27252 { 2048, 1638, 1231, 819, 411, 1 },
27253 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
27254
27255 extract_buf(r, tmp);
27256 i = min_t(int, nbytes, EXTRACT_SIZE);
27257 - if (copy_to_user(buf, tmp, i)) {
27258 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
27259 ret = -EFAULT;
27260 break;
27261 }
27262 @@ -1228,7 +1240,7 @@ EXPORT_SYMBOL(generate_random_uuid);
27263 #include <linux/sysctl.h>
27264
27265 static int min_read_thresh = 8, min_write_thresh;
27266 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
27267 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
27268 static int max_write_thresh = INPUT_POOL_WORDS * 32;
27269 static char sysctl_bootid[16];
27270
27271 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
27272 index 1ee8ce7..b778bef 100644
27273 --- a/drivers/char/sonypi.c
27274 +++ b/drivers/char/sonypi.c
27275 @@ -55,6 +55,7 @@
27276 #include <asm/uaccess.h>
27277 #include <asm/io.h>
27278 #include <asm/system.h>
27279 +#include <asm/local.h>
27280
27281 #include <linux/sonypi.h>
27282
27283 @@ -491,7 +492,7 @@ static struct sonypi_device {
27284 spinlock_t fifo_lock;
27285 wait_queue_head_t fifo_proc_list;
27286 struct fasync_struct *fifo_async;
27287 - int open_count;
27288 + local_t open_count;
27289 int model;
27290 struct input_dev *input_jog_dev;
27291 struct input_dev *input_key_dev;
27292 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
27293 static int sonypi_misc_release(struct inode *inode, struct file *file)
27294 {
27295 mutex_lock(&sonypi_device.lock);
27296 - sonypi_device.open_count--;
27297 + local_dec(&sonypi_device.open_count);
27298 mutex_unlock(&sonypi_device.lock);
27299 return 0;
27300 }
27301 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
27302 {
27303 mutex_lock(&sonypi_device.lock);
27304 /* Flush input queue on first open */
27305 - if (!sonypi_device.open_count)
27306 + if (!local_read(&sonypi_device.open_count))
27307 kfifo_reset(&sonypi_device.fifo);
27308 - sonypi_device.open_count++;
27309 + local_inc(&sonypi_device.open_count);
27310 mutex_unlock(&sonypi_device.lock);
27311
27312 return 0;
27313 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
27314 index 361a1df..2471eee 100644
27315 --- a/drivers/char/tpm/tpm.c
27316 +++ b/drivers/char/tpm/tpm.c
27317 @@ -414,7 +414,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
27318 chip->vendor.req_complete_val)
27319 goto out_recv;
27320
27321 - if ((status == chip->vendor.req_canceled)) {
27322 + if (status == chip->vendor.req_canceled) {
27323 dev_err(chip->dev, "Operation Canceled\n");
27324 rc = -ECANCELED;
27325 goto out;
27326 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
27327 index 0636520..169c1d0 100644
27328 --- a/drivers/char/tpm/tpm_bios.c
27329 +++ b/drivers/char/tpm/tpm_bios.c
27330 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
27331 event = addr;
27332
27333 if ((event->event_type == 0 && event->event_size == 0) ||
27334 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
27335 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
27336 return NULL;
27337
27338 return addr;
27339 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
27340 return NULL;
27341
27342 if ((event->event_type == 0 && event->event_size == 0) ||
27343 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
27344 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
27345 return NULL;
27346
27347 (*pos)++;
27348 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
27349 int i;
27350
27351 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
27352 - seq_putc(m, data[i]);
27353 + if (!seq_putc(m, data[i]))
27354 + return -EFAULT;
27355
27356 return 0;
27357 }
27358 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
27359 log->bios_event_log_end = log->bios_event_log + len;
27360
27361 virt = acpi_os_map_memory(start, len);
27362 + if (!virt) {
27363 + kfree(log->bios_event_log);
27364 + log->bios_event_log = NULL;
27365 + return -EFAULT;
27366 + }
27367
27368 - memcpy(log->bios_event_log, virt, len);
27369 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
27370
27371 acpi_os_unmap_memory(virt, len);
27372 return 0;
27373 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
27374 index 8e3c46d..c139b99 100644
27375 --- a/drivers/char/virtio_console.c
27376 +++ b/drivers/char/virtio_console.c
27377 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
27378 if (to_user) {
27379 ssize_t ret;
27380
27381 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
27382 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
27383 if (ret)
27384 return -EFAULT;
27385 } else {
27386 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
27387 if (!port_has_data(port) && !port->host_connected)
27388 return 0;
27389
27390 - return fill_readbuf(port, ubuf, count, true);
27391 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
27392 }
27393
27394 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
27395 diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
27396 index eb1d864..39ee5a7 100644
27397 --- a/drivers/dma/dmatest.c
27398 +++ b/drivers/dma/dmatest.c
27399 @@ -591,7 +591,7 @@ static int dmatest_add_channel(struct dma_chan *chan)
27400 }
27401 if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
27402 cnt = dmatest_add_threads(dtc, DMA_PQ);
27403 - thread_count += cnt > 0 ?: 0;
27404 + thread_count += cnt > 0 ? cnt : 0;
27405 }
27406
27407 pr_info("dmatest: Started %u threads using %s\n",
27408 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
27409 index c9eee6d..f9d5280 100644
27410 --- a/drivers/edac/amd64_edac.c
27411 +++ b/drivers/edac/amd64_edac.c
27412 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
27413 * PCI core identifies what devices are on a system during boot, and then
27414 * inquiry this table to see if this driver is for a given device found.
27415 */
27416 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
27417 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
27418 {
27419 .vendor = PCI_VENDOR_ID_AMD,
27420 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
27421 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
27422 index e47e73b..348e0bd 100644
27423 --- a/drivers/edac/amd76x_edac.c
27424 +++ b/drivers/edac/amd76x_edac.c
27425 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
27426 edac_mc_free(mci);
27427 }
27428
27429 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
27430 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
27431 {
27432 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27433 AMD762},
27434 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
27435 index 1af531a..3a8ff27 100644
27436 --- a/drivers/edac/e752x_edac.c
27437 +++ b/drivers/edac/e752x_edac.c
27438 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
27439 edac_mc_free(mci);
27440 }
27441
27442 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
27443 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
27444 {
27445 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27446 E7520},
27447 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
27448 index 6ffb6d2..383d8d7 100644
27449 --- a/drivers/edac/e7xxx_edac.c
27450 +++ b/drivers/edac/e7xxx_edac.c
27451 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
27452 edac_mc_free(mci);
27453 }
27454
27455 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
27456 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
27457 {
27458 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27459 E7205},
27460 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
27461 index 495198a..ac08c85 100644
27462 --- a/drivers/edac/edac_pci_sysfs.c
27463 +++ b/drivers/edac/edac_pci_sysfs.c
27464 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
27465 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
27466 static int edac_pci_poll_msec = 1000; /* one second workq period */
27467
27468 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
27469 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
27470 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
27471 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
27472
27473 static struct kobject *edac_pci_top_main_kobj;
27474 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
27475 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27476 edac_printk(KERN_CRIT, EDAC_PCI,
27477 "Signaled System Error on %s\n",
27478 pci_name(dev));
27479 - atomic_inc(&pci_nonparity_count);
27480 + atomic_inc_unchecked(&pci_nonparity_count);
27481 }
27482
27483 if (status & (PCI_STATUS_PARITY)) {
27484 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27485 "Master Data Parity Error on %s\n",
27486 pci_name(dev));
27487
27488 - atomic_inc(&pci_parity_count);
27489 + atomic_inc_unchecked(&pci_parity_count);
27490 }
27491
27492 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27493 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27494 "Detected Parity Error on %s\n",
27495 pci_name(dev));
27496
27497 - atomic_inc(&pci_parity_count);
27498 + atomic_inc_unchecked(&pci_parity_count);
27499 }
27500 }
27501
27502 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27503 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
27504 "Signaled System Error on %s\n",
27505 pci_name(dev));
27506 - atomic_inc(&pci_nonparity_count);
27507 + atomic_inc_unchecked(&pci_nonparity_count);
27508 }
27509
27510 if (status & (PCI_STATUS_PARITY)) {
27511 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27512 "Master Data Parity Error on "
27513 "%s\n", pci_name(dev));
27514
27515 - atomic_inc(&pci_parity_count);
27516 + atomic_inc_unchecked(&pci_parity_count);
27517 }
27518
27519 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27520 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27521 "Detected Parity Error on %s\n",
27522 pci_name(dev));
27523
27524 - atomic_inc(&pci_parity_count);
27525 + atomic_inc_unchecked(&pci_parity_count);
27526 }
27527 }
27528 }
27529 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
27530 if (!check_pci_errors)
27531 return;
27532
27533 - before_count = atomic_read(&pci_parity_count);
27534 + before_count = atomic_read_unchecked(&pci_parity_count);
27535
27536 /* scan all PCI devices looking for a Parity Error on devices and
27537 * bridges.
27538 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
27539 /* Only if operator has selected panic on PCI Error */
27540 if (edac_pci_get_panic_on_pe()) {
27541 /* If the count is different 'after' from 'before' */
27542 - if (before_count != atomic_read(&pci_parity_count))
27543 + if (before_count != atomic_read_unchecked(&pci_parity_count))
27544 panic("EDAC: PCI Parity Error");
27545 }
27546 }
27547 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
27548 index c0510b3..6e2a954 100644
27549 --- a/drivers/edac/i3000_edac.c
27550 +++ b/drivers/edac/i3000_edac.c
27551 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
27552 edac_mc_free(mci);
27553 }
27554
27555 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
27556 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
27557 {
27558 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27559 I3000},
27560 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
27561 index aa08497..7e6822a 100644
27562 --- a/drivers/edac/i3200_edac.c
27563 +++ b/drivers/edac/i3200_edac.c
27564 @@ -456,7 +456,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
27565 edac_mc_free(mci);
27566 }
27567
27568 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
27569 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
27570 {
27571 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27572 I3200},
27573 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
27574 index 4dc3ac2..67d05a6 100644
27575 --- a/drivers/edac/i5000_edac.c
27576 +++ b/drivers/edac/i5000_edac.c
27577 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
27578 *
27579 * The "E500P" device is the first device supported.
27580 */
27581 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
27582 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
27583 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
27584 .driver_data = I5000P},
27585
27586 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
27587 index bcbdeec..9886d16 100644
27588 --- a/drivers/edac/i5100_edac.c
27589 +++ b/drivers/edac/i5100_edac.c
27590 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
27591 edac_mc_free(mci);
27592 }
27593
27594 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
27595 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
27596 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
27597 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
27598 { 0, }
27599 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
27600 index 74d6ec34..baff517 100644
27601 --- a/drivers/edac/i5400_edac.c
27602 +++ b/drivers/edac/i5400_edac.c
27603 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
27604 *
27605 * The "E500P" device is the first device supported.
27606 */
27607 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
27608 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
27609 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
27610 {0,} /* 0 terminated list. */
27611 };
27612 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
27613 index 6104dba..e7ea8e1 100644
27614 --- a/drivers/edac/i7300_edac.c
27615 +++ b/drivers/edac/i7300_edac.c
27616 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
27617 *
27618 * Has only 8086:360c PCI ID
27619 */
27620 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
27621 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
27622 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
27623 {0,} /* 0 terminated list. */
27624 };
27625 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
27626 index 70ad892..178943c 100644
27627 --- a/drivers/edac/i7core_edac.c
27628 +++ b/drivers/edac/i7core_edac.c
27629 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
27630 /*
27631 * pci_device_id table for which devices we are looking for
27632 */
27633 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
27634 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
27635 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
27636 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
27637 {0,} /* 0 terminated list. */
27638 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
27639 index 4329d39..f3022ef 100644
27640 --- a/drivers/edac/i82443bxgx_edac.c
27641 +++ b/drivers/edac/i82443bxgx_edac.c
27642 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
27643
27644 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
27645
27646 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
27647 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
27648 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
27649 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
27650 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
27651 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
27652 index 931a057..fd28340 100644
27653 --- a/drivers/edac/i82860_edac.c
27654 +++ b/drivers/edac/i82860_edac.c
27655 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
27656 edac_mc_free(mci);
27657 }
27658
27659 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
27660 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
27661 {
27662 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27663 I82860},
27664 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
27665 index 33864c6..01edc61 100644
27666 --- a/drivers/edac/i82875p_edac.c
27667 +++ b/drivers/edac/i82875p_edac.c
27668 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
27669 edac_mc_free(mci);
27670 }
27671
27672 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
27673 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
27674 {
27675 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27676 I82875P},
27677 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
27678 index a5da732..983363b 100644
27679 --- a/drivers/edac/i82975x_edac.c
27680 +++ b/drivers/edac/i82975x_edac.c
27681 @@ -604,7 +604,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
27682 edac_mc_free(mci);
27683 }
27684
27685 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
27686 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
27687 {
27688 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27689 I82975X
27690 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
27691 index 0106747..0b40417 100644
27692 --- a/drivers/edac/mce_amd.h
27693 +++ b/drivers/edac/mce_amd.h
27694 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
27695 bool (*dc_mce)(u16, u8);
27696 bool (*ic_mce)(u16, u8);
27697 bool (*nb_mce)(u16, u8);
27698 -};
27699 +} __no_const;
27700
27701 void amd_report_gart_errors(bool);
27702 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
27703 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
27704 index b153674..ad2ba9b 100644
27705 --- a/drivers/edac/r82600_edac.c
27706 +++ b/drivers/edac/r82600_edac.c
27707 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
27708 edac_mc_free(mci);
27709 }
27710
27711 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
27712 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
27713 {
27714 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
27715 },
27716 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
27717 index b6f47de..c5acf3a 100644
27718 --- a/drivers/edac/x38_edac.c
27719 +++ b/drivers/edac/x38_edac.c
27720 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
27721 edac_mc_free(mci);
27722 }
27723
27724 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
27725 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
27726 {
27727 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27728 X38},
27729 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
27730 index 85661b0..c784559a 100644
27731 --- a/drivers/firewire/core-card.c
27732 +++ b/drivers/firewire/core-card.c
27733 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
27734
27735 void fw_core_remove_card(struct fw_card *card)
27736 {
27737 - struct fw_card_driver dummy_driver = dummy_driver_template;
27738 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
27739
27740 card->driver->update_phy_reg(card, 4,
27741 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
27742 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
27743 index 4799393..37bd3ab 100644
27744 --- a/drivers/firewire/core-cdev.c
27745 +++ b/drivers/firewire/core-cdev.c
27746 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
27747 int ret;
27748
27749 if ((request->channels == 0 && request->bandwidth == 0) ||
27750 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
27751 - request->bandwidth < 0)
27752 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
27753 return -EINVAL;
27754
27755 r = kmalloc(sizeof(*r), GFP_KERNEL);
27756 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
27757 index 855ab3f..11f4bbd 100644
27758 --- a/drivers/firewire/core-transaction.c
27759 +++ b/drivers/firewire/core-transaction.c
27760 @@ -37,6 +37,7 @@
27761 #include <linux/timer.h>
27762 #include <linux/types.h>
27763 #include <linux/workqueue.h>
27764 +#include <linux/sched.h>
27765
27766 #include <asm/byteorder.h>
27767
27768 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
27769 index b45be57..5fad18b 100644
27770 --- a/drivers/firewire/core.h
27771 +++ b/drivers/firewire/core.h
27772 @@ -101,6 +101,7 @@ struct fw_card_driver {
27773
27774 int (*stop_iso)(struct fw_iso_context *ctx);
27775 };
27776 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
27777
27778 void fw_card_initialize(struct fw_card *card,
27779 const struct fw_card_driver *driver, struct device *device);
27780 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
27781 index 153980b..4b4d046 100644
27782 --- a/drivers/firmware/dmi_scan.c
27783 +++ b/drivers/firmware/dmi_scan.c
27784 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
27785 }
27786 }
27787 else {
27788 - /*
27789 - * no iounmap() for that ioremap(); it would be a no-op, but
27790 - * it's so early in setup that sucker gets confused into doing
27791 - * what it shouldn't if we actually call it.
27792 - */
27793 p = dmi_ioremap(0xF0000, 0x10000);
27794 if (p == NULL)
27795 goto error;
27796 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
27797 if (buf == NULL)
27798 return -1;
27799
27800 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
27801 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
27802
27803 iounmap(buf);
27804 return 0;
27805 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
27806 index 98723cb..10ca85b 100644
27807 --- a/drivers/gpio/gpio-vr41xx.c
27808 +++ b/drivers/gpio/gpio-vr41xx.c
27809 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
27810 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
27811 maskl, pendl, maskh, pendh);
27812
27813 - atomic_inc(&irq_err_count);
27814 + atomic_inc_unchecked(&irq_err_count);
27815
27816 return -EINVAL;
27817 }
27818 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
27819 index 8323fc3..5c1d755 100644
27820 --- a/drivers/gpu/drm/drm_crtc.c
27821 +++ b/drivers/gpu/drm/drm_crtc.c
27822 @@ -1379,7 +1379,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27823 */
27824 if ((out_resp->count_modes >= mode_count) && mode_count) {
27825 copied = 0;
27826 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
27827 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
27828 list_for_each_entry(mode, &connector->modes, head) {
27829 drm_crtc_convert_to_umode(&u_mode, mode);
27830 if (copy_to_user(mode_ptr + copied,
27831 @@ -1394,8 +1394,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27832
27833 if ((out_resp->count_props >= props_count) && props_count) {
27834 copied = 0;
27835 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
27836 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
27837 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
27838 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
27839 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
27840 if (connector->property_ids[i] != 0) {
27841 if (put_user(connector->property_ids[i],
27842 @@ -1417,7 +1417,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27843
27844 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
27845 copied = 0;
27846 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
27847 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
27848 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
27849 if (connector->encoder_ids[i] != 0) {
27850 if (put_user(connector->encoder_ids[i],
27851 @@ -1576,7 +1576,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
27852 }
27853
27854 for (i = 0; i < crtc_req->count_connectors; i++) {
27855 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
27856 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
27857 if (get_user(out_id, &set_connectors_ptr[i])) {
27858 ret = -EFAULT;
27859 goto out;
27860 @@ -1857,7 +1857,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
27861 fb = obj_to_fb(obj);
27862
27863 num_clips = r->num_clips;
27864 - clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
27865 + clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
27866
27867 if (!num_clips != !clips_ptr) {
27868 ret = -EINVAL;
27869 @@ -2283,7 +2283,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
27870 out_resp->flags = property->flags;
27871
27872 if ((out_resp->count_values >= value_count) && value_count) {
27873 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
27874 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
27875 for (i = 0; i < value_count; i++) {
27876 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
27877 ret = -EFAULT;
27878 @@ -2296,7 +2296,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
27879 if (property->flags & DRM_MODE_PROP_ENUM) {
27880 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
27881 copied = 0;
27882 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
27883 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
27884 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
27885
27886 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
27887 @@ -2319,7 +2319,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
27888 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
27889 copied = 0;
27890 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
27891 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
27892 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
27893
27894 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
27895 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
27896 @@ -2380,7 +2380,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
27897 struct drm_mode_get_blob *out_resp = data;
27898 struct drm_property_blob *blob;
27899 int ret = 0;
27900 - void *blob_ptr;
27901 + void __user *blob_ptr;
27902
27903 if (!drm_core_check_feature(dev, DRIVER_MODESET))
27904 return -EINVAL;
27905 @@ -2394,7 +2394,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
27906 blob = obj_to_blob(obj);
27907
27908 if (out_resp->length == blob->length) {
27909 - blob_ptr = (void *)(unsigned long)out_resp->data;
27910 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
27911 if (copy_to_user(blob_ptr, blob->data, blob->length)){
27912 ret = -EFAULT;
27913 goto done;
27914 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
27915 index d2619d7..bd6bd00 100644
27916 --- a/drivers/gpu/drm/drm_crtc_helper.c
27917 +++ b/drivers/gpu/drm/drm_crtc_helper.c
27918 @@ -279,7 +279,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
27919 struct drm_crtc *tmp;
27920 int crtc_mask = 1;
27921
27922 - WARN(!crtc, "checking null crtc?\n");
27923 + BUG_ON(!crtc);
27924
27925 dev = crtc->dev;
27926
27927 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
27928 index 40c187c..5746164 100644
27929 --- a/drivers/gpu/drm/drm_drv.c
27930 +++ b/drivers/gpu/drm/drm_drv.c
27931 @@ -308,7 +308,7 @@ module_exit(drm_core_exit);
27932 /**
27933 * Copy and IOCTL return string to user space
27934 */
27935 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
27936 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
27937 {
27938 int len;
27939
27940 @@ -387,7 +387,7 @@ long drm_ioctl(struct file *filp,
27941
27942 dev = file_priv->minor->dev;
27943 atomic_inc(&dev->ioctl_count);
27944 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
27945 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
27946 ++file_priv->ioctl_count;
27947
27948 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
27949 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
27950 index 4911e1d..484c8a3 100644
27951 --- a/drivers/gpu/drm/drm_fops.c
27952 +++ b/drivers/gpu/drm/drm_fops.c
27953 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
27954 }
27955
27956 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
27957 - atomic_set(&dev->counts[i], 0);
27958 + atomic_set_unchecked(&dev->counts[i], 0);
27959
27960 dev->sigdata.lock = NULL;
27961
27962 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
27963
27964 retcode = drm_open_helper(inode, filp, dev);
27965 if (!retcode) {
27966 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
27967 - if (!dev->open_count++)
27968 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
27969 + if (local_inc_return(&dev->open_count) == 1)
27970 retcode = drm_setup(dev);
27971 }
27972 if (!retcode) {
27973 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
27974
27975 mutex_lock(&drm_global_mutex);
27976
27977 - DRM_DEBUG("open_count = %d\n", dev->open_count);
27978 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
27979
27980 if (dev->driver->preclose)
27981 dev->driver->preclose(dev, file_priv);
27982 @@ -485,7 +485,7 @@ int drm_release(struct inode *inode, struct file *filp)
27983 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
27984 task_pid_nr(current),
27985 (long)old_encode_dev(file_priv->minor->device),
27986 - dev->open_count);
27987 + local_read(&dev->open_count));
27988
27989 /* if the master has gone away we can't do anything with the lock */
27990 if (file_priv->minor->master)
27991 @@ -566,8 +566,8 @@ int drm_release(struct inode *inode, struct file *filp)
27992 * End inline drm_release
27993 */
27994
27995 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
27996 - if (!--dev->open_count) {
27997 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
27998 + if (local_dec_and_test(&dev->open_count)) {
27999 if (atomic_read(&dev->ioctl_count)) {
28000 DRM_ERROR("Device busy: %d\n",
28001 atomic_read(&dev->ioctl_count));
28002 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
28003 index c87dc96..326055d 100644
28004 --- a/drivers/gpu/drm/drm_global.c
28005 +++ b/drivers/gpu/drm/drm_global.c
28006 @@ -36,7 +36,7 @@
28007 struct drm_global_item {
28008 struct mutex mutex;
28009 void *object;
28010 - int refcount;
28011 + atomic_t refcount;
28012 };
28013
28014 static struct drm_global_item glob[DRM_GLOBAL_NUM];
28015 @@ -49,7 +49,7 @@ void drm_global_init(void)
28016 struct drm_global_item *item = &glob[i];
28017 mutex_init(&item->mutex);
28018 item->object = NULL;
28019 - item->refcount = 0;
28020 + atomic_set(&item->refcount, 0);
28021 }
28022 }
28023
28024 @@ -59,7 +59,7 @@ void drm_global_release(void)
28025 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
28026 struct drm_global_item *item = &glob[i];
28027 BUG_ON(item->object != NULL);
28028 - BUG_ON(item->refcount != 0);
28029 + BUG_ON(atomic_read(&item->refcount) != 0);
28030 }
28031 }
28032
28033 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
28034 void *object;
28035
28036 mutex_lock(&item->mutex);
28037 - if (item->refcount == 0) {
28038 + if (atomic_read(&item->refcount) == 0) {
28039 item->object = kzalloc(ref->size, GFP_KERNEL);
28040 if (unlikely(item->object == NULL)) {
28041 ret = -ENOMEM;
28042 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
28043 goto out_err;
28044
28045 }
28046 - ++item->refcount;
28047 + atomic_inc(&item->refcount);
28048 ref->object = item->object;
28049 object = item->object;
28050 mutex_unlock(&item->mutex);
28051 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
28052 struct drm_global_item *item = &glob[ref->global_type];
28053
28054 mutex_lock(&item->mutex);
28055 - BUG_ON(item->refcount == 0);
28056 + BUG_ON(atomic_read(&item->refcount) == 0);
28057 BUG_ON(ref->object != item->object);
28058 - if (--item->refcount == 0) {
28059 + if (atomic_dec_and_test(&item->refcount)) {
28060 ref->release(ref);
28061 item->object = NULL;
28062 }
28063 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
28064 index ab1162d..42587b2 100644
28065 --- a/drivers/gpu/drm/drm_info.c
28066 +++ b/drivers/gpu/drm/drm_info.c
28067 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
28068 struct drm_local_map *map;
28069 struct drm_map_list *r_list;
28070
28071 - /* Hardcoded from _DRM_FRAME_BUFFER,
28072 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
28073 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
28074 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
28075 + static const char * const types[] = {
28076 + [_DRM_FRAME_BUFFER] = "FB",
28077 + [_DRM_REGISTERS] = "REG",
28078 + [_DRM_SHM] = "SHM",
28079 + [_DRM_AGP] = "AGP",
28080 + [_DRM_SCATTER_GATHER] = "SG",
28081 + [_DRM_CONSISTENT] = "PCI",
28082 + [_DRM_GEM] = "GEM" };
28083 const char *type;
28084 int i;
28085
28086 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
28087 map = r_list->map;
28088 if (!map)
28089 continue;
28090 - if (map->type < 0 || map->type > 5)
28091 + if (map->type >= ARRAY_SIZE(types))
28092 type = "??";
28093 else
28094 type = types[map->type];
28095 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
28096 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
28097 vma->vm_flags & VM_LOCKED ? 'l' : '-',
28098 vma->vm_flags & VM_IO ? 'i' : '-',
28099 +#ifdef CONFIG_GRKERNSEC_HIDESYM
28100 + 0);
28101 +#else
28102 vma->vm_pgoff);
28103 +#endif
28104
28105 #if defined(__i386__)
28106 pgprot = pgprot_val(vma->vm_page_prot);
28107 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
28108 index ddd70db..40321e6 100644
28109 --- a/drivers/gpu/drm/drm_ioc32.c
28110 +++ b/drivers/gpu/drm/drm_ioc32.c
28111 @@ -456,7 +456,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
28112 request = compat_alloc_user_space(nbytes);
28113 if (!access_ok(VERIFY_WRITE, request, nbytes))
28114 return -EFAULT;
28115 - list = (struct drm_buf_desc *) (request + 1);
28116 + list = (struct drm_buf_desc __user *) (request + 1);
28117
28118 if (__put_user(count, &request->count)
28119 || __put_user(list, &request->list))
28120 @@ -517,7 +517,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
28121 request = compat_alloc_user_space(nbytes);
28122 if (!access_ok(VERIFY_WRITE, request, nbytes))
28123 return -EFAULT;
28124 - list = (struct drm_buf_pub *) (request + 1);
28125 + list = (struct drm_buf_pub __user *) (request + 1);
28126
28127 if (__put_user(count, &request->count)
28128 || __put_user(list, &request->list))
28129 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
28130 index 904d7e9..ab88581 100644
28131 --- a/drivers/gpu/drm/drm_ioctl.c
28132 +++ b/drivers/gpu/drm/drm_ioctl.c
28133 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev, void *data,
28134 stats->data[i].value =
28135 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
28136 else
28137 - stats->data[i].value = atomic_read(&dev->counts[i]);
28138 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
28139 stats->data[i].type = dev->types[i];
28140 }
28141
28142 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
28143 index 632ae24..244cf4a 100644
28144 --- a/drivers/gpu/drm/drm_lock.c
28145 +++ b/drivers/gpu/drm/drm_lock.c
28146 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28147 if (drm_lock_take(&master->lock, lock->context)) {
28148 master->lock.file_priv = file_priv;
28149 master->lock.lock_time = jiffies;
28150 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
28151 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
28152 break; /* Got lock */
28153 }
28154
28155 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28156 return -EINVAL;
28157 }
28158
28159 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
28160 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
28161
28162 if (drm_lock_free(&master->lock, lock->context)) {
28163 /* FIXME: Should really bail out here. */
28164 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
28165 index 8f371e8..9f85d52 100644
28166 --- a/drivers/gpu/drm/i810/i810_dma.c
28167 +++ b/drivers/gpu/drm/i810/i810_dma.c
28168 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
28169 dma->buflist[vertex->idx],
28170 vertex->discard, vertex->used);
28171
28172 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28173 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28174 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28175 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28176 sarea_priv->last_enqueue = dev_priv->counter - 1;
28177 sarea_priv->last_dispatch = (int)hw_status[5];
28178
28179 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
28180 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
28181 mc->last_render);
28182
28183 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28184 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28185 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28186 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28187 sarea_priv->last_enqueue = dev_priv->counter - 1;
28188 sarea_priv->last_dispatch = (int)hw_status[5];
28189
28190 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
28191 index c9339f4..f5e1b9d 100644
28192 --- a/drivers/gpu/drm/i810/i810_drv.h
28193 +++ b/drivers/gpu/drm/i810/i810_drv.h
28194 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
28195 int page_flipping;
28196
28197 wait_queue_head_t irq_queue;
28198 - atomic_t irq_received;
28199 - atomic_t irq_emitted;
28200 + atomic_unchecked_t irq_received;
28201 + atomic_unchecked_t irq_emitted;
28202
28203 int front_offset;
28204 } drm_i810_private_t;
28205 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
28206 index 004b048..7588eba 100644
28207 --- a/drivers/gpu/drm/i915/i915_debugfs.c
28208 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
28209 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
28210 I915_READ(GTIMR));
28211 }
28212 seq_printf(m, "Interrupts received: %d\n",
28213 - atomic_read(&dev_priv->irq_received));
28214 + atomic_read_unchecked(&dev_priv->irq_received));
28215 for (i = 0; i < I915_NUM_RINGS; i++) {
28216 if (IS_GEN6(dev) || IS_GEN7(dev)) {
28217 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
28218 @@ -1232,7 +1232,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
28219 return ret;
28220
28221 if (opregion->header)
28222 - seq_write(m, opregion->header, OPREGION_SIZE);
28223 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
28224
28225 mutex_unlock(&dev->struct_mutex);
28226
28227 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
28228 index a9ae374..43c1e9e 100644
28229 --- a/drivers/gpu/drm/i915/i915_dma.c
28230 +++ b/drivers/gpu/drm/i915/i915_dma.c
28231 @@ -1172,7 +1172,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
28232 bool can_switch;
28233
28234 spin_lock(&dev->count_lock);
28235 - can_switch = (dev->open_count == 0);
28236 + can_switch = (local_read(&dev->open_count) == 0);
28237 spin_unlock(&dev->count_lock);
28238 return can_switch;
28239 }
28240 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
28241 index 554bef7..d24791c 100644
28242 --- a/drivers/gpu/drm/i915/i915_drv.h
28243 +++ b/drivers/gpu/drm/i915/i915_drv.h
28244 @@ -229,7 +229,7 @@ struct drm_i915_display_funcs {
28245 /* render clock increase/decrease */
28246 /* display clock increase/decrease */
28247 /* pll clock increase/decrease */
28248 -};
28249 +} __no_const;
28250
28251 struct intel_device_info {
28252 u8 gen;
28253 @@ -312,7 +312,7 @@ typedef struct drm_i915_private {
28254 int current_page;
28255 int page_flipping;
28256
28257 - atomic_t irq_received;
28258 + atomic_unchecked_t irq_received;
28259
28260 /* protects the irq masks */
28261 spinlock_t irq_lock;
28262 @@ -887,7 +887,7 @@ struct drm_i915_gem_object {
28263 * will be page flipped away on the next vblank. When it
28264 * reaches 0, dev_priv->pending_flip_queue will be woken up.
28265 */
28266 - atomic_t pending_flip;
28267 + atomic_unchecked_t pending_flip;
28268 };
28269
28270 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
28271 @@ -1267,7 +1267,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
28272 extern void intel_teardown_gmbus(struct drm_device *dev);
28273 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
28274 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
28275 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28276 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28277 {
28278 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
28279 }
28280 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28281 index b9da890..cad1d98 100644
28282 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28283 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28284 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
28285 i915_gem_clflush_object(obj);
28286
28287 if (obj->base.pending_write_domain)
28288 - cd->flips |= atomic_read(&obj->pending_flip);
28289 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
28290
28291 /* The actual obj->write_domain will be updated with
28292 * pending_write_domain after we emit the accumulated flush for all
28293 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
28294
28295 static int
28296 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
28297 - int count)
28298 + unsigned int count)
28299 {
28300 - int i;
28301 + unsigned int i;
28302
28303 for (i = 0; i < count; i++) {
28304 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
28305 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
28306 index b40004b..7c53a75 100644
28307 --- a/drivers/gpu/drm/i915/i915_irq.c
28308 +++ b/drivers/gpu/drm/i915/i915_irq.c
28309 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
28310 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
28311 struct drm_i915_master_private *master_priv;
28312
28313 - atomic_inc(&dev_priv->irq_received);
28314 + atomic_inc_unchecked(&dev_priv->irq_received);
28315
28316 /* disable master interrupt before clearing iir */
28317 de_ier = I915_READ(DEIER);
28318 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
28319 struct drm_i915_master_private *master_priv;
28320 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
28321
28322 - atomic_inc(&dev_priv->irq_received);
28323 + atomic_inc_unchecked(&dev_priv->irq_received);
28324
28325 if (IS_GEN6(dev))
28326 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
28327 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
28328 int ret = IRQ_NONE, pipe;
28329 bool blc_event = false;
28330
28331 - atomic_inc(&dev_priv->irq_received);
28332 + atomic_inc_unchecked(&dev_priv->irq_received);
28333
28334 iir = I915_READ(IIR);
28335
28336 @@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
28337 {
28338 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28339
28340 - atomic_set(&dev_priv->irq_received, 0);
28341 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28342
28343 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28344 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28345 @@ -1931,7 +1931,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
28346 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28347 int pipe;
28348
28349 - atomic_set(&dev_priv->irq_received, 0);
28350 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28351
28352 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28353 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28354 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
28355 index daa5743..c0757a9 100644
28356 --- a/drivers/gpu/drm/i915/intel_display.c
28357 +++ b/drivers/gpu/drm/i915/intel_display.c
28358 @@ -2230,7 +2230,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
28359
28360 wait_event(dev_priv->pending_flip_queue,
28361 atomic_read(&dev_priv->mm.wedged) ||
28362 - atomic_read(&obj->pending_flip) == 0);
28363 + atomic_read_unchecked(&obj->pending_flip) == 0);
28364
28365 /* Big Hammer, we also need to ensure that any pending
28366 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
28367 @@ -2851,7 +2851,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
28368 obj = to_intel_framebuffer(crtc->fb)->obj;
28369 dev_priv = crtc->dev->dev_private;
28370 wait_event(dev_priv->pending_flip_queue,
28371 - atomic_read(&obj->pending_flip) == 0);
28372 + atomic_read_unchecked(&obj->pending_flip) == 0);
28373 }
28374
28375 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
28376 @@ -6952,7 +6952,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
28377
28378 atomic_clear_mask(1 << intel_crtc->plane,
28379 &obj->pending_flip.counter);
28380 - if (atomic_read(&obj->pending_flip) == 0)
28381 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
28382 wake_up(&dev_priv->pending_flip_queue);
28383
28384 schedule_work(&work->work);
28385 @@ -7242,7 +7242,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28386 /* Block clients from rendering to the new back buffer until
28387 * the flip occurs and the object is no longer visible.
28388 */
28389 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28390 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28391
28392 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
28393 if (ret)
28394 @@ -7256,7 +7256,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28395 return 0;
28396
28397 cleanup_pending:
28398 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28399 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28400 drm_gem_object_unreference(&work->old_fb_obj->base);
28401 drm_gem_object_unreference(&obj->base);
28402 mutex_unlock(&dev->struct_mutex);
28403 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
28404 index 54558a0..2d97005 100644
28405 --- a/drivers/gpu/drm/mga/mga_drv.h
28406 +++ b/drivers/gpu/drm/mga/mga_drv.h
28407 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
28408 u32 clear_cmd;
28409 u32 maccess;
28410
28411 - atomic_t vbl_received; /**< Number of vblanks received. */
28412 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
28413 wait_queue_head_t fence_queue;
28414 - atomic_t last_fence_retired;
28415 + atomic_unchecked_t last_fence_retired;
28416 u32 next_fence_to_post;
28417
28418 unsigned int fb_cpp;
28419 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
28420 index 2581202..f230a8d9 100644
28421 --- a/drivers/gpu/drm/mga/mga_irq.c
28422 +++ b/drivers/gpu/drm/mga/mga_irq.c
28423 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
28424 if (crtc != 0)
28425 return 0;
28426
28427 - return atomic_read(&dev_priv->vbl_received);
28428 + return atomic_read_unchecked(&dev_priv->vbl_received);
28429 }
28430
28431
28432 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28433 /* VBLANK interrupt */
28434 if (status & MGA_VLINEPEN) {
28435 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
28436 - atomic_inc(&dev_priv->vbl_received);
28437 + atomic_inc_unchecked(&dev_priv->vbl_received);
28438 drm_handle_vblank(dev, 0);
28439 handled = 1;
28440 }
28441 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28442 if ((prim_start & ~0x03) != (prim_end & ~0x03))
28443 MGA_WRITE(MGA_PRIMEND, prim_end);
28444
28445 - atomic_inc(&dev_priv->last_fence_retired);
28446 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
28447 DRM_WAKEUP(&dev_priv->fence_queue);
28448 handled = 1;
28449 }
28450 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
28451 * using fences.
28452 */
28453 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
28454 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
28455 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
28456 - *sequence) <= (1 << 23)));
28457
28458 *sequence = cur_fence;
28459 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
28460 index 5fc201b..7b032b9 100644
28461 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
28462 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
28463 @@ -201,7 +201,7 @@ struct methods {
28464 const char desc[8];
28465 void (*loadbios)(struct drm_device *, uint8_t *);
28466 const bool rw;
28467 -};
28468 +} __do_const;
28469
28470 static struct methods shadow_methods[] = {
28471 { "PRAMIN", load_vbios_pramin, true },
28472 @@ -5474,7 +5474,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
28473 struct bit_table {
28474 const char id;
28475 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
28476 -};
28477 +} __no_const;
28478
28479 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
28480
28481 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
28482 index 4c0be3a..5757582 100644
28483 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
28484 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
28485 @@ -238,7 +238,7 @@ struct nouveau_channel {
28486 struct list_head pending;
28487 uint32_t sequence;
28488 uint32_t sequence_ack;
28489 - atomic_t last_sequence_irq;
28490 + atomic_unchecked_t last_sequence_irq;
28491 struct nouveau_vma vma;
28492 } fence;
28493
28494 @@ -319,7 +319,7 @@ struct nouveau_exec_engine {
28495 u32 handle, u16 class);
28496 void (*set_tile_region)(struct drm_device *dev, int i);
28497 void (*tlb_flush)(struct drm_device *, int engine);
28498 -};
28499 +} __no_const;
28500
28501 struct nouveau_instmem_engine {
28502 void *priv;
28503 @@ -341,13 +341,13 @@ struct nouveau_instmem_engine {
28504 struct nouveau_mc_engine {
28505 int (*init)(struct drm_device *dev);
28506 void (*takedown)(struct drm_device *dev);
28507 -};
28508 +} __no_const;
28509
28510 struct nouveau_timer_engine {
28511 int (*init)(struct drm_device *dev);
28512 void (*takedown)(struct drm_device *dev);
28513 uint64_t (*read)(struct drm_device *dev);
28514 -};
28515 +} __no_const;
28516
28517 struct nouveau_fb_engine {
28518 int num_tiles;
28519 @@ -558,7 +558,7 @@ struct nouveau_vram_engine {
28520 void (*put)(struct drm_device *, struct nouveau_mem **);
28521
28522 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
28523 -};
28524 +} __no_const;
28525
28526 struct nouveau_engine {
28527 struct nouveau_instmem_engine instmem;
28528 @@ -706,7 +706,7 @@ struct drm_nouveau_private {
28529 struct drm_global_reference mem_global_ref;
28530 struct ttm_bo_global_ref bo_global_ref;
28531 struct ttm_bo_device bdev;
28532 - atomic_t validate_sequence;
28533 + atomic_unchecked_t validate_sequence;
28534 } ttm;
28535
28536 struct {
28537 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
28538 index 2f6daae..c9d7b9e 100644
28539 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
28540 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
28541 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
28542 if (USE_REFCNT(dev))
28543 sequence = nvchan_rd32(chan, 0x48);
28544 else
28545 - sequence = atomic_read(&chan->fence.last_sequence_irq);
28546 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
28547
28548 if (chan->fence.sequence_ack == sequence)
28549 goto out;
28550 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
28551 return ret;
28552 }
28553
28554 - atomic_set(&chan->fence.last_sequence_irq, 0);
28555 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
28556 return 0;
28557 }
28558
28559 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
28560 index 5f0bc57..eb9fac8 100644
28561 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
28562 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
28563 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
28564 int trycnt = 0;
28565 int ret, i;
28566
28567 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
28568 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
28569 retry:
28570 if (++trycnt > 100000) {
28571 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
28572 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
28573 index d8831ab..0ba8356 100644
28574 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
28575 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
28576 @@ -542,7 +542,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
28577 bool can_switch;
28578
28579 spin_lock(&dev->count_lock);
28580 - can_switch = (dev->open_count == 0);
28581 + can_switch = (local_read(&dev->open_count) == 0);
28582 spin_unlock(&dev->count_lock);
28583 return can_switch;
28584 }
28585 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
28586 index dbdea8e..cd6eeeb 100644
28587 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
28588 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
28589 @@ -554,7 +554,7 @@ static int
28590 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
28591 u32 class, u32 mthd, u32 data)
28592 {
28593 - atomic_set(&chan->fence.last_sequence_irq, data);
28594 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
28595 return 0;
28596 }
28597
28598 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
28599 index bcac90b..53bfc76 100644
28600 --- a/drivers/gpu/drm/r128/r128_cce.c
28601 +++ b/drivers/gpu/drm/r128/r128_cce.c
28602 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
28603
28604 /* GH: Simple idle check.
28605 */
28606 - atomic_set(&dev_priv->idle_count, 0);
28607 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28608
28609 /* We don't support anything other than bus-mastering ring mode,
28610 * but the ring can be in either AGP or PCI space for the ring
28611 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
28612 index 930c71b..499aded 100644
28613 --- a/drivers/gpu/drm/r128/r128_drv.h
28614 +++ b/drivers/gpu/drm/r128/r128_drv.h
28615 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
28616 int is_pci;
28617 unsigned long cce_buffers_offset;
28618
28619 - atomic_t idle_count;
28620 + atomic_unchecked_t idle_count;
28621
28622 int page_flipping;
28623 int current_page;
28624 u32 crtc_offset;
28625 u32 crtc_offset_cntl;
28626
28627 - atomic_t vbl_received;
28628 + atomic_unchecked_t vbl_received;
28629
28630 u32 color_fmt;
28631 unsigned int front_offset;
28632 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
28633 index 429d5a0..7e899ed 100644
28634 --- a/drivers/gpu/drm/r128/r128_irq.c
28635 +++ b/drivers/gpu/drm/r128/r128_irq.c
28636 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
28637 if (crtc != 0)
28638 return 0;
28639
28640 - return atomic_read(&dev_priv->vbl_received);
28641 + return atomic_read_unchecked(&dev_priv->vbl_received);
28642 }
28643
28644 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28645 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28646 /* VBLANK interrupt */
28647 if (status & R128_CRTC_VBLANK_INT) {
28648 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
28649 - atomic_inc(&dev_priv->vbl_received);
28650 + atomic_inc_unchecked(&dev_priv->vbl_received);
28651 drm_handle_vblank(dev, 0);
28652 return IRQ_HANDLED;
28653 }
28654 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
28655 index a9e33ce..09edd4b 100644
28656 --- a/drivers/gpu/drm/r128/r128_state.c
28657 +++ b/drivers/gpu/drm/r128/r128_state.c
28658 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
28659
28660 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
28661 {
28662 - if (atomic_read(&dev_priv->idle_count) == 0)
28663 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
28664 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
28665 else
28666 - atomic_set(&dev_priv->idle_count, 0);
28667 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28668 }
28669
28670 #endif
28671 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
28672 index 5a82b6b..9e69c73 100644
28673 --- a/drivers/gpu/drm/radeon/mkregtable.c
28674 +++ b/drivers/gpu/drm/radeon/mkregtable.c
28675 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
28676 regex_t mask_rex;
28677 regmatch_t match[4];
28678 char buf[1024];
28679 - size_t end;
28680 + long end;
28681 int len;
28682 int done = 0;
28683 int r;
28684 unsigned o;
28685 struct offset *offset;
28686 char last_reg_s[10];
28687 - int last_reg;
28688 + unsigned long last_reg;
28689
28690 if (regcomp
28691 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
28692 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
28693 index 8227e76..ce0b195 100644
28694 --- a/drivers/gpu/drm/radeon/radeon.h
28695 +++ b/drivers/gpu/drm/radeon/radeon.h
28696 @@ -192,7 +192,7 @@ extern int sumo_get_temp(struct radeon_device *rdev);
28697 */
28698 struct radeon_fence_driver {
28699 uint32_t scratch_reg;
28700 - atomic_t seq;
28701 + atomic_unchecked_t seq;
28702 uint32_t last_seq;
28703 unsigned long last_jiffies;
28704 unsigned long last_timeout;
28705 @@ -530,7 +530,7 @@ struct r600_blit_cp_primitives {
28706 int x2, int y2);
28707 void (*draw_auto)(struct radeon_device *rdev);
28708 void (*set_default_state)(struct radeon_device *rdev);
28709 -};
28710 +} __no_const;
28711
28712 struct r600_blit {
28713 struct mutex mutex;
28714 @@ -954,7 +954,7 @@ struct radeon_asic {
28715 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
28716 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
28717 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
28718 -};
28719 +} __no_const;
28720
28721 /*
28722 * Asic structures
28723 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
28724 index c4d00a1..f0fdc90 100644
28725 --- a/drivers/gpu/drm/radeon/radeon_device.c
28726 +++ b/drivers/gpu/drm/radeon/radeon_device.c
28727 @@ -684,7 +684,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
28728 bool can_switch;
28729
28730 spin_lock(&dev->count_lock);
28731 - can_switch = (dev->open_count == 0);
28732 + can_switch = (local_read(&dev->open_count) == 0);
28733 spin_unlock(&dev->count_lock);
28734 return can_switch;
28735 }
28736 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
28737 index a1b59ca..86f2d44 100644
28738 --- a/drivers/gpu/drm/radeon/radeon_drv.h
28739 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
28740 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
28741
28742 /* SW interrupt */
28743 wait_queue_head_t swi_queue;
28744 - atomic_t swi_emitted;
28745 + atomic_unchecked_t swi_emitted;
28746 int vblank_crtc;
28747 uint32_t irq_enable_reg;
28748 uint32_t r500_disp_irq_reg;
28749 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
28750 index 76ec0e9..6feb1a3 100644
28751 --- a/drivers/gpu/drm/radeon/radeon_fence.c
28752 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
28753 @@ -78,7 +78,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
28754 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
28755 return 0;
28756 }
28757 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
28758 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
28759 if (!rdev->cp.ready)
28760 /* FIXME: cp is not running assume everythings is done right
28761 * away
28762 @@ -373,7 +373,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
28763 return r;
28764 }
28765 radeon_fence_write(rdev, 0);
28766 - atomic_set(&rdev->fence_drv.seq, 0);
28767 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
28768 INIT_LIST_HEAD(&rdev->fence_drv.created);
28769 INIT_LIST_HEAD(&rdev->fence_drv.emited);
28770 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
28771 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
28772 index 48b7cea..342236f 100644
28773 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
28774 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
28775 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
28776 request = compat_alloc_user_space(sizeof(*request));
28777 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
28778 || __put_user(req32.param, &request->param)
28779 - || __put_user((void __user *)(unsigned long)req32.value,
28780 + || __put_user((unsigned long)req32.value,
28781 &request->value))
28782 return -EFAULT;
28783
28784 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
28785 index 00da384..32f972d 100644
28786 --- a/drivers/gpu/drm/radeon/radeon_irq.c
28787 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
28788 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
28789 unsigned int ret;
28790 RING_LOCALS;
28791
28792 - atomic_inc(&dev_priv->swi_emitted);
28793 - ret = atomic_read(&dev_priv->swi_emitted);
28794 + atomic_inc_unchecked(&dev_priv->swi_emitted);
28795 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
28796
28797 BEGIN_RING(4);
28798 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
28799 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
28800 drm_radeon_private_t *dev_priv =
28801 (drm_radeon_private_t *) dev->dev_private;
28802
28803 - atomic_set(&dev_priv->swi_emitted, 0);
28804 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
28805 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
28806
28807 dev->max_vblank_count = 0x001fffff;
28808 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
28809 index e8422ae..d22d4a8 100644
28810 --- a/drivers/gpu/drm/radeon/radeon_state.c
28811 +++ b/drivers/gpu/drm/radeon/radeon_state.c
28812 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
28813 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
28814 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
28815
28816 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
28817 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
28818 sarea_priv->nbox * sizeof(depth_boxes[0])))
28819 return -EFAULT;
28820
28821 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
28822 {
28823 drm_radeon_private_t *dev_priv = dev->dev_private;
28824 drm_radeon_getparam_t *param = data;
28825 - int value;
28826 + int value = 0;
28827
28828 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
28829
28830 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
28831 index 0b5468b..9c4b308 100644
28832 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
28833 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
28834 @@ -672,8 +672,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
28835 }
28836 if (unlikely(ttm_vm_ops == NULL)) {
28837 ttm_vm_ops = vma->vm_ops;
28838 - radeon_ttm_vm_ops = *ttm_vm_ops;
28839 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
28840 + pax_open_kernel();
28841 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
28842 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
28843 + pax_close_kernel();
28844 }
28845 vma->vm_ops = &radeon_ttm_vm_ops;
28846 return 0;
28847 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
28848 index a9049ed..501f284 100644
28849 --- a/drivers/gpu/drm/radeon/rs690.c
28850 +++ b/drivers/gpu/drm/radeon/rs690.c
28851 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
28852 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
28853 rdev->pm.sideport_bandwidth.full)
28854 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
28855 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
28856 + read_delay_latency.full = dfixed_const(800 * 1000);
28857 read_delay_latency.full = dfixed_div(read_delay_latency,
28858 rdev->pm.igp_sideport_mclk);
28859 + a.full = dfixed_const(370);
28860 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
28861 } else {
28862 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
28863 rdev->pm.k8_bandwidth.full)
28864 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
28865 index 727e93d..1565650 100644
28866 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
28867 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
28868 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
28869 static int ttm_pool_mm_shrink(struct shrinker *shrink,
28870 struct shrink_control *sc)
28871 {
28872 - static atomic_t start_pool = ATOMIC_INIT(0);
28873 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
28874 unsigned i;
28875 - unsigned pool_offset = atomic_add_return(1, &start_pool);
28876 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
28877 struct ttm_page_pool *pool;
28878 int shrink_pages = sc->nr_to_scan;
28879
28880 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
28881 index 9cf87d9..2000b7d 100644
28882 --- a/drivers/gpu/drm/via/via_drv.h
28883 +++ b/drivers/gpu/drm/via/via_drv.h
28884 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
28885 typedef uint32_t maskarray_t[5];
28886
28887 typedef struct drm_via_irq {
28888 - atomic_t irq_received;
28889 + atomic_unchecked_t irq_received;
28890 uint32_t pending_mask;
28891 uint32_t enable_mask;
28892 wait_queue_head_t irq_queue;
28893 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
28894 struct timeval last_vblank;
28895 int last_vblank_valid;
28896 unsigned usec_per_vblank;
28897 - atomic_t vbl_received;
28898 + atomic_unchecked_t vbl_received;
28899 drm_via_state_t hc_state;
28900 char pci_buf[VIA_PCI_BUF_SIZE];
28901 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
28902 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
28903 index d391f48..10c8ca3 100644
28904 --- a/drivers/gpu/drm/via/via_irq.c
28905 +++ b/drivers/gpu/drm/via/via_irq.c
28906 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
28907 if (crtc != 0)
28908 return 0;
28909
28910 - return atomic_read(&dev_priv->vbl_received);
28911 + return atomic_read_unchecked(&dev_priv->vbl_received);
28912 }
28913
28914 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28915 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28916
28917 status = VIA_READ(VIA_REG_INTERRUPT);
28918 if (status & VIA_IRQ_VBLANK_PENDING) {
28919 - atomic_inc(&dev_priv->vbl_received);
28920 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
28921 + atomic_inc_unchecked(&dev_priv->vbl_received);
28922 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
28923 do_gettimeofday(&cur_vblank);
28924 if (dev_priv->last_vblank_valid) {
28925 dev_priv->usec_per_vblank =
28926 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28927 dev_priv->last_vblank = cur_vblank;
28928 dev_priv->last_vblank_valid = 1;
28929 }
28930 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
28931 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
28932 DRM_DEBUG("US per vblank is: %u\n",
28933 dev_priv->usec_per_vblank);
28934 }
28935 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28936
28937 for (i = 0; i < dev_priv->num_irqs; ++i) {
28938 if (status & cur_irq->pending_mask) {
28939 - atomic_inc(&cur_irq->irq_received);
28940 + atomic_inc_unchecked(&cur_irq->irq_received);
28941 DRM_WAKEUP(&cur_irq->irq_queue);
28942 handled = 1;
28943 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
28944 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
28945 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
28946 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
28947 masks[irq][4]));
28948 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
28949 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
28950 } else {
28951 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
28952 (((cur_irq_sequence =
28953 - atomic_read(&cur_irq->irq_received)) -
28954 + atomic_read_unchecked(&cur_irq->irq_received)) -
28955 *sequence) <= (1 << 23)));
28956 }
28957 *sequence = cur_irq_sequence;
28958 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
28959 }
28960
28961 for (i = 0; i < dev_priv->num_irqs; ++i) {
28962 - atomic_set(&cur_irq->irq_received, 0);
28963 + atomic_set_unchecked(&cur_irq->irq_received, 0);
28964 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
28965 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
28966 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
28967 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
28968 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
28969 case VIA_IRQ_RELATIVE:
28970 irqwait->request.sequence +=
28971 - atomic_read(&cur_irq->irq_received);
28972 + atomic_read_unchecked(&cur_irq->irq_received);
28973 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
28974 case VIA_IRQ_ABSOLUTE:
28975 break;
28976 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
28977 index dc27970..f18b008 100644
28978 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
28979 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
28980 @@ -260,7 +260,7 @@ struct vmw_private {
28981 * Fencing and IRQs.
28982 */
28983
28984 - atomic_t marker_seq;
28985 + atomic_unchecked_t marker_seq;
28986 wait_queue_head_t fence_queue;
28987 wait_queue_head_t fifo_queue;
28988 int fence_queue_waiters; /* Protected by hw_mutex */
28989 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
28990 index a0c2f12..68ae6cb 100644
28991 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
28992 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
28993 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
28994 (unsigned int) min,
28995 (unsigned int) fifo->capabilities);
28996
28997 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
28998 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
28999 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
29000 vmw_marker_queue_init(&fifo->marker_queue);
29001 return vmw_fifo_send_fence(dev_priv, &dummy);
29002 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
29003 if (reserveable)
29004 iowrite32(bytes, fifo_mem +
29005 SVGA_FIFO_RESERVED);
29006 - return fifo_mem + (next_cmd >> 2);
29007 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
29008 } else {
29009 need_bounce = true;
29010 }
29011 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
29012
29013 fm = vmw_fifo_reserve(dev_priv, bytes);
29014 if (unlikely(fm == NULL)) {
29015 - *seqno = atomic_read(&dev_priv->marker_seq);
29016 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
29017 ret = -ENOMEM;
29018 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
29019 false, 3*HZ);
29020 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
29021 }
29022
29023 do {
29024 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
29025 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
29026 } while (*seqno == 0);
29027
29028 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
29029 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29030 index cabc95f..14b3d77 100644
29031 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29032 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29033 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
29034 * emitted. Then the fence is stale and signaled.
29035 */
29036
29037 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
29038 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
29039 > VMW_FENCE_WRAP);
29040
29041 return ret;
29042 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
29043
29044 if (fifo_idle)
29045 down_read(&fifo_state->rwsem);
29046 - signal_seq = atomic_read(&dev_priv->marker_seq);
29047 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
29048 ret = 0;
29049
29050 for (;;) {
29051 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
29052 index 8a8725c..afed796 100644
29053 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
29054 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
29055 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
29056 while (!vmw_lag_lt(queue, us)) {
29057 spin_lock(&queue->lock);
29058 if (list_empty(&queue->head))
29059 - seqno = atomic_read(&dev_priv->marker_seq);
29060 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
29061 else {
29062 marker = list_first_entry(&queue->head,
29063 struct vmw_marker, head);
29064 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
29065 index af35384..5ab3c36 100644
29066 --- a/drivers/hid/hid-core.c
29067 +++ b/drivers/hid/hid-core.c
29068 @@ -2000,7 +2000,7 @@ static bool hid_ignore(struct hid_device *hdev)
29069
29070 int hid_add_device(struct hid_device *hdev)
29071 {
29072 - static atomic_t id = ATOMIC_INIT(0);
29073 + static atomic_unchecked_t id = ATOMIC_INIT(0);
29074 int ret;
29075
29076 if (WARN_ON(hdev->status & HID_STAT_ADDED))
29077 @@ -2015,7 +2015,7 @@ int hid_add_device(struct hid_device *hdev)
29078 /* XXX hack, any other cleaner solution after the driver core
29079 * is converted to allow more than 20 bytes as the device name? */
29080 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
29081 - hdev->vendor, hdev->product, atomic_inc_return(&id));
29082 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
29083
29084 hid_debug_register(hdev, dev_name(&hdev->dev));
29085 ret = device_add(&hdev->dev);
29086 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
29087 index 4ef02b2..8a96831 100644
29088 --- a/drivers/hid/usbhid/hiddev.c
29089 +++ b/drivers/hid/usbhid/hiddev.c
29090 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29091 break;
29092
29093 case HIDIOCAPPLICATION:
29094 - if (arg < 0 || arg >= hid->maxapplication)
29095 + if (arg >= hid->maxapplication)
29096 break;
29097
29098 for (i = 0; i < hid->maxcollection; i++)
29099 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
29100 index 4065374..10ed7dc 100644
29101 --- a/drivers/hv/channel.c
29102 +++ b/drivers/hv/channel.c
29103 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
29104 int ret = 0;
29105 int t;
29106
29107 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
29108 - atomic_inc(&vmbus_connection.next_gpadl_handle);
29109 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
29110 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
29111
29112 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
29113 if (ret)
29114 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
29115 index 0fb100e..baf87e5 100644
29116 --- a/drivers/hv/hv.c
29117 +++ b/drivers/hv/hv.c
29118 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
29119 u64 output_address = (output) ? virt_to_phys(output) : 0;
29120 u32 output_address_hi = output_address >> 32;
29121 u32 output_address_lo = output_address & 0xFFFFFFFF;
29122 - void *hypercall_page = hv_context.hypercall_page;
29123 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
29124
29125 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
29126 "=a"(hv_status_lo) : "d" (control_hi),
29127 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
29128 index 0aee112..b72d21f 100644
29129 --- a/drivers/hv/hyperv_vmbus.h
29130 +++ b/drivers/hv/hyperv_vmbus.h
29131 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
29132 struct vmbus_connection {
29133 enum vmbus_connect_state conn_state;
29134
29135 - atomic_t next_gpadl_handle;
29136 + atomic_unchecked_t next_gpadl_handle;
29137
29138 /*
29139 * Represents channel interrupts. Each bit position represents a
29140 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
29141 index d2d0a2a..90b8f4d 100644
29142 --- a/drivers/hv/vmbus_drv.c
29143 +++ b/drivers/hv/vmbus_drv.c
29144 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
29145 {
29146 int ret = 0;
29147
29148 - static atomic_t device_num = ATOMIC_INIT(0);
29149 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
29150
29151 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
29152 - atomic_inc_return(&device_num));
29153 + atomic_inc_return_unchecked(&device_num));
29154
29155 child_device_obj->device.bus = &hv_bus;
29156 child_device_obj->device.parent = &hv_acpi_dev->dev;
29157 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
29158 index 66f6729..2d6de0a 100644
29159 --- a/drivers/hwmon/acpi_power_meter.c
29160 +++ b/drivers/hwmon/acpi_power_meter.c
29161 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
29162 return res;
29163
29164 temp /= 1000;
29165 - if (temp < 0)
29166 - return -EINVAL;
29167
29168 mutex_lock(&resource->lock);
29169 resource->trip[attr->index - 7] = temp;
29170 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
29171 index fe4104c..346febb 100644
29172 --- a/drivers/hwmon/sht15.c
29173 +++ b/drivers/hwmon/sht15.c
29174 @@ -166,7 +166,7 @@ struct sht15_data {
29175 int supply_uV;
29176 bool supply_uV_valid;
29177 struct work_struct update_supply_work;
29178 - atomic_t interrupt_handled;
29179 + atomic_unchecked_t interrupt_handled;
29180 };
29181
29182 /**
29183 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
29184 return ret;
29185
29186 gpio_direction_input(data->pdata->gpio_data);
29187 - atomic_set(&data->interrupt_handled, 0);
29188 + atomic_set_unchecked(&data->interrupt_handled, 0);
29189
29190 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29191 if (gpio_get_value(data->pdata->gpio_data) == 0) {
29192 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
29193 /* Only relevant if the interrupt hasn't occurred. */
29194 - if (!atomic_read(&data->interrupt_handled))
29195 + if (!atomic_read_unchecked(&data->interrupt_handled))
29196 schedule_work(&data->read_work);
29197 }
29198 ret = wait_event_timeout(data->wait_queue,
29199 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
29200
29201 /* First disable the interrupt */
29202 disable_irq_nosync(irq);
29203 - atomic_inc(&data->interrupt_handled);
29204 + atomic_inc_unchecked(&data->interrupt_handled);
29205 /* Then schedule a reading work struct */
29206 if (data->state != SHT15_READING_NOTHING)
29207 schedule_work(&data->read_work);
29208 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
29209 * If not, then start the interrupt again - care here as could
29210 * have gone low in meantime so verify it hasn't!
29211 */
29212 - atomic_set(&data->interrupt_handled, 0);
29213 + atomic_set_unchecked(&data->interrupt_handled, 0);
29214 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29215 /* If still not occurred or another handler has been scheduled */
29216 if (gpio_get_value(data->pdata->gpio_data)
29217 - || atomic_read(&data->interrupt_handled))
29218 + || atomic_read_unchecked(&data->interrupt_handled))
29219 return;
29220 }
29221
29222 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
29223 index 378fcb5..5e91fa8 100644
29224 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
29225 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
29226 @@ -43,7 +43,7 @@
29227 extern struct i2c_adapter amd756_smbus;
29228
29229 static struct i2c_adapter *s4882_adapter;
29230 -static struct i2c_algorithm *s4882_algo;
29231 +static i2c_algorithm_no_const *s4882_algo;
29232
29233 /* Wrapper access functions for multiplexed SMBus */
29234 static DEFINE_MUTEX(amd756_lock);
29235 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
29236 index 29015eb..af2d8e9 100644
29237 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
29238 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
29239 @@ -41,7 +41,7 @@
29240 extern struct i2c_adapter *nforce2_smbus;
29241
29242 static struct i2c_adapter *s4985_adapter;
29243 -static struct i2c_algorithm *s4985_algo;
29244 +static i2c_algorithm_no_const *s4985_algo;
29245
29246 /* Wrapper access functions for multiplexed SMBus */
29247 static DEFINE_MUTEX(nforce2_lock);
29248 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
29249 index d7a4833..7fae376 100644
29250 --- a/drivers/i2c/i2c-mux.c
29251 +++ b/drivers/i2c/i2c-mux.c
29252 @@ -28,7 +28,7 @@
29253 /* multiplexer per channel data */
29254 struct i2c_mux_priv {
29255 struct i2c_adapter adap;
29256 - struct i2c_algorithm algo;
29257 + i2c_algorithm_no_const algo;
29258
29259 struct i2c_adapter *parent;
29260 void *mux_dev; /* the mux chip/device */
29261 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
29262 index 57d00ca..0145194 100644
29263 --- a/drivers/ide/aec62xx.c
29264 +++ b/drivers/ide/aec62xx.c
29265 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
29266 .cable_detect = atp86x_cable_detect,
29267 };
29268
29269 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
29270 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
29271 { /* 0: AEC6210 */
29272 .name = DRV_NAME,
29273 .init_chipset = init_chipset_aec62xx,
29274 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
29275 index 2c8016a..911a27c 100644
29276 --- a/drivers/ide/alim15x3.c
29277 +++ b/drivers/ide/alim15x3.c
29278 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
29279 .dma_sff_read_status = ide_dma_sff_read_status,
29280 };
29281
29282 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
29283 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
29284 .name = DRV_NAME,
29285 .init_chipset = init_chipset_ali15x3,
29286 .init_hwif = init_hwif_ali15x3,
29287 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
29288 index 3747b25..56fc995 100644
29289 --- a/drivers/ide/amd74xx.c
29290 +++ b/drivers/ide/amd74xx.c
29291 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
29292 .udma_mask = udma, \
29293 }
29294
29295 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
29296 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
29297 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
29298 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
29299 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
29300 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
29301 index 15f0ead..cb43480 100644
29302 --- a/drivers/ide/atiixp.c
29303 +++ b/drivers/ide/atiixp.c
29304 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
29305 .cable_detect = atiixp_cable_detect,
29306 };
29307
29308 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
29309 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
29310 { /* 0: IXP200/300/400/700 */
29311 .name = DRV_NAME,
29312 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
29313 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
29314 index 5f80312..d1fc438 100644
29315 --- a/drivers/ide/cmd64x.c
29316 +++ b/drivers/ide/cmd64x.c
29317 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
29318 .dma_sff_read_status = ide_dma_sff_read_status,
29319 };
29320
29321 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
29322 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
29323 { /* 0: CMD643 */
29324 .name = DRV_NAME,
29325 .init_chipset = init_chipset_cmd64x,
29326 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
29327 index 2c1e5f7..1444762 100644
29328 --- a/drivers/ide/cs5520.c
29329 +++ b/drivers/ide/cs5520.c
29330 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
29331 .set_dma_mode = cs5520_set_dma_mode,
29332 };
29333
29334 -static const struct ide_port_info cyrix_chipset __devinitdata = {
29335 +static const struct ide_port_info cyrix_chipset __devinitconst = {
29336 .name = DRV_NAME,
29337 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
29338 .port_ops = &cs5520_port_ops,
29339 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
29340 index 4dc4eb9..49b40ad 100644
29341 --- a/drivers/ide/cs5530.c
29342 +++ b/drivers/ide/cs5530.c
29343 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
29344 .udma_filter = cs5530_udma_filter,
29345 };
29346
29347 -static const struct ide_port_info cs5530_chipset __devinitdata = {
29348 +static const struct ide_port_info cs5530_chipset __devinitconst = {
29349 .name = DRV_NAME,
29350 .init_chipset = init_chipset_cs5530,
29351 .init_hwif = init_hwif_cs5530,
29352 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
29353 index 5059faf..18d4c85 100644
29354 --- a/drivers/ide/cs5535.c
29355 +++ b/drivers/ide/cs5535.c
29356 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
29357 .cable_detect = cs5535_cable_detect,
29358 };
29359
29360 -static const struct ide_port_info cs5535_chipset __devinitdata = {
29361 +static const struct ide_port_info cs5535_chipset __devinitconst = {
29362 .name = DRV_NAME,
29363 .port_ops = &cs5535_port_ops,
29364 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
29365 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
29366 index 847553f..3ffb49d 100644
29367 --- a/drivers/ide/cy82c693.c
29368 +++ b/drivers/ide/cy82c693.c
29369 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
29370 .set_dma_mode = cy82c693_set_dma_mode,
29371 };
29372
29373 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
29374 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
29375 .name = DRV_NAME,
29376 .init_iops = init_iops_cy82c693,
29377 .port_ops = &cy82c693_port_ops,
29378 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
29379 index 58c51cd..4aec3b8 100644
29380 --- a/drivers/ide/hpt366.c
29381 +++ b/drivers/ide/hpt366.c
29382 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
29383 }
29384 };
29385
29386 -static const struct hpt_info hpt36x __devinitdata = {
29387 +static const struct hpt_info hpt36x __devinitconst = {
29388 .chip_name = "HPT36x",
29389 .chip_type = HPT36x,
29390 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
29391 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
29392 .timings = &hpt36x_timings
29393 };
29394
29395 -static const struct hpt_info hpt370 __devinitdata = {
29396 +static const struct hpt_info hpt370 __devinitconst = {
29397 .chip_name = "HPT370",
29398 .chip_type = HPT370,
29399 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29400 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
29401 .timings = &hpt37x_timings
29402 };
29403
29404 -static const struct hpt_info hpt370a __devinitdata = {
29405 +static const struct hpt_info hpt370a __devinitconst = {
29406 .chip_name = "HPT370A",
29407 .chip_type = HPT370A,
29408 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29409 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
29410 .timings = &hpt37x_timings
29411 };
29412
29413 -static const struct hpt_info hpt374 __devinitdata = {
29414 +static const struct hpt_info hpt374 __devinitconst = {
29415 .chip_name = "HPT374",
29416 .chip_type = HPT374,
29417 .udma_mask = ATA_UDMA5,
29418 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
29419 .timings = &hpt37x_timings
29420 };
29421
29422 -static const struct hpt_info hpt372 __devinitdata = {
29423 +static const struct hpt_info hpt372 __devinitconst = {
29424 .chip_name = "HPT372",
29425 .chip_type = HPT372,
29426 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29427 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
29428 .timings = &hpt37x_timings
29429 };
29430
29431 -static const struct hpt_info hpt372a __devinitdata = {
29432 +static const struct hpt_info hpt372a __devinitconst = {
29433 .chip_name = "HPT372A",
29434 .chip_type = HPT372A,
29435 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29436 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
29437 .timings = &hpt37x_timings
29438 };
29439
29440 -static const struct hpt_info hpt302 __devinitdata = {
29441 +static const struct hpt_info hpt302 __devinitconst = {
29442 .chip_name = "HPT302",
29443 .chip_type = HPT302,
29444 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29445 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
29446 .timings = &hpt37x_timings
29447 };
29448
29449 -static const struct hpt_info hpt371 __devinitdata = {
29450 +static const struct hpt_info hpt371 __devinitconst = {
29451 .chip_name = "HPT371",
29452 .chip_type = HPT371,
29453 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29454 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
29455 .timings = &hpt37x_timings
29456 };
29457
29458 -static const struct hpt_info hpt372n __devinitdata = {
29459 +static const struct hpt_info hpt372n __devinitconst = {
29460 .chip_name = "HPT372N",
29461 .chip_type = HPT372N,
29462 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29463 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
29464 .timings = &hpt37x_timings
29465 };
29466
29467 -static const struct hpt_info hpt302n __devinitdata = {
29468 +static const struct hpt_info hpt302n __devinitconst = {
29469 .chip_name = "HPT302N",
29470 .chip_type = HPT302N,
29471 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29472 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
29473 .timings = &hpt37x_timings
29474 };
29475
29476 -static const struct hpt_info hpt371n __devinitdata = {
29477 +static const struct hpt_info hpt371n __devinitconst = {
29478 .chip_name = "HPT371N",
29479 .chip_type = HPT371N,
29480 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29481 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
29482 .dma_sff_read_status = ide_dma_sff_read_status,
29483 };
29484
29485 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
29486 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
29487 { /* 0: HPT36x */
29488 .name = DRV_NAME,
29489 .init_chipset = init_chipset_hpt366,
29490 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
29491 index 8126824..55a2798 100644
29492 --- a/drivers/ide/ide-cd.c
29493 +++ b/drivers/ide/ide-cd.c
29494 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
29495 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
29496 if ((unsigned long)buf & alignment
29497 || blk_rq_bytes(rq) & q->dma_pad_mask
29498 - || object_is_on_stack(buf))
29499 + || object_starts_on_stack(buf))
29500 drive->dma = 0;
29501 }
29502 }
29503 diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
29504 index d267b7a..a22ca84 100644
29505 --- a/drivers/ide/ide-floppy_ioctl.c
29506 +++ b/drivers/ide/ide-floppy_ioctl.c
29507 @@ -292,8 +292,7 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
29508 * and CDROM_SEND_PACKET (legacy) ioctls
29509 */
29510 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
29511 - err = scsi_cmd_ioctl(bdev->bd_disk->queue, bdev->bd_disk,
29512 - mode, cmd, argp);
29513 + err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);
29514
29515 if (err == -ENOTTY)
29516 err = generic_ide_ioctl(drive, bdev, cmd, arg);
29517 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
29518 index a743e68..1cfd674 100644
29519 --- a/drivers/ide/ide-pci-generic.c
29520 +++ b/drivers/ide/ide-pci-generic.c
29521 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
29522 .udma_mask = ATA_UDMA6, \
29523 }
29524
29525 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
29526 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
29527 /* 0: Unknown */
29528 DECLARE_GENERIC_PCI_DEV(0),
29529
29530 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
29531 index 560e66d..d5dd180 100644
29532 --- a/drivers/ide/it8172.c
29533 +++ b/drivers/ide/it8172.c
29534 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
29535 .set_dma_mode = it8172_set_dma_mode,
29536 };
29537
29538 -static const struct ide_port_info it8172_port_info __devinitdata = {
29539 +static const struct ide_port_info it8172_port_info __devinitconst = {
29540 .name = DRV_NAME,
29541 .port_ops = &it8172_port_ops,
29542 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
29543 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
29544 index 46816ba..1847aeb 100644
29545 --- a/drivers/ide/it8213.c
29546 +++ b/drivers/ide/it8213.c
29547 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
29548 .cable_detect = it8213_cable_detect,
29549 };
29550
29551 -static const struct ide_port_info it8213_chipset __devinitdata = {
29552 +static const struct ide_port_info it8213_chipset __devinitconst = {
29553 .name = DRV_NAME,
29554 .enablebits = { {0x41, 0x80, 0x80} },
29555 .port_ops = &it8213_port_ops,
29556 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
29557 index 2e3169f..c5611db 100644
29558 --- a/drivers/ide/it821x.c
29559 +++ b/drivers/ide/it821x.c
29560 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
29561 .cable_detect = it821x_cable_detect,
29562 };
29563
29564 -static const struct ide_port_info it821x_chipset __devinitdata = {
29565 +static const struct ide_port_info it821x_chipset __devinitconst = {
29566 .name = DRV_NAME,
29567 .init_chipset = init_chipset_it821x,
29568 .init_hwif = init_hwif_it821x,
29569 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
29570 index 74c2c4a..efddd7d 100644
29571 --- a/drivers/ide/jmicron.c
29572 +++ b/drivers/ide/jmicron.c
29573 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
29574 .cable_detect = jmicron_cable_detect,
29575 };
29576
29577 -static const struct ide_port_info jmicron_chipset __devinitdata = {
29578 +static const struct ide_port_info jmicron_chipset __devinitconst = {
29579 .name = DRV_NAME,
29580 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
29581 .port_ops = &jmicron_port_ops,
29582 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
29583 index 95327a2..73f78d8 100644
29584 --- a/drivers/ide/ns87415.c
29585 +++ b/drivers/ide/ns87415.c
29586 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
29587 .dma_sff_read_status = superio_dma_sff_read_status,
29588 };
29589
29590 -static const struct ide_port_info ns87415_chipset __devinitdata = {
29591 +static const struct ide_port_info ns87415_chipset __devinitconst = {
29592 .name = DRV_NAME,
29593 .init_hwif = init_hwif_ns87415,
29594 .tp_ops = &ns87415_tp_ops,
29595 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
29596 index 1a53a4c..39edc66 100644
29597 --- a/drivers/ide/opti621.c
29598 +++ b/drivers/ide/opti621.c
29599 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
29600 .set_pio_mode = opti621_set_pio_mode,
29601 };
29602
29603 -static const struct ide_port_info opti621_chipset __devinitdata = {
29604 +static const struct ide_port_info opti621_chipset __devinitconst = {
29605 .name = DRV_NAME,
29606 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
29607 .port_ops = &opti621_port_ops,
29608 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
29609 index 9546fe2..2e5ceb6 100644
29610 --- a/drivers/ide/pdc202xx_new.c
29611 +++ b/drivers/ide/pdc202xx_new.c
29612 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
29613 .udma_mask = udma, \
29614 }
29615
29616 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
29617 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
29618 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
29619 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
29620 };
29621 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
29622 index 3a35ec6..5634510 100644
29623 --- a/drivers/ide/pdc202xx_old.c
29624 +++ b/drivers/ide/pdc202xx_old.c
29625 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
29626 .max_sectors = sectors, \
29627 }
29628
29629 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
29630 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
29631 { /* 0: PDC20246 */
29632 .name = DRV_NAME,
29633 .init_chipset = init_chipset_pdc202xx,
29634 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
29635 index 1892e81..fe0fd60 100644
29636 --- a/drivers/ide/piix.c
29637 +++ b/drivers/ide/piix.c
29638 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
29639 .udma_mask = udma, \
29640 }
29641
29642 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
29643 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
29644 /* 0: MPIIX */
29645 { /*
29646 * MPIIX actually has only a single IDE channel mapped to
29647 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
29648 index a6414a8..c04173e 100644
29649 --- a/drivers/ide/rz1000.c
29650 +++ b/drivers/ide/rz1000.c
29651 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
29652 }
29653 }
29654
29655 -static const struct ide_port_info rz1000_chipset __devinitdata = {
29656 +static const struct ide_port_info rz1000_chipset __devinitconst = {
29657 .name = DRV_NAME,
29658 .host_flags = IDE_HFLAG_NO_DMA,
29659 };
29660 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
29661 index 356b9b5..d4758eb 100644
29662 --- a/drivers/ide/sc1200.c
29663 +++ b/drivers/ide/sc1200.c
29664 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
29665 .dma_sff_read_status = ide_dma_sff_read_status,
29666 };
29667
29668 -static const struct ide_port_info sc1200_chipset __devinitdata = {
29669 +static const struct ide_port_info sc1200_chipset __devinitconst = {
29670 .name = DRV_NAME,
29671 .port_ops = &sc1200_port_ops,
29672 .dma_ops = &sc1200_dma_ops,
29673 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
29674 index b7f5b0c..9701038 100644
29675 --- a/drivers/ide/scc_pata.c
29676 +++ b/drivers/ide/scc_pata.c
29677 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
29678 .dma_sff_read_status = scc_dma_sff_read_status,
29679 };
29680
29681 -static const struct ide_port_info scc_chipset __devinitdata = {
29682 +static const struct ide_port_info scc_chipset __devinitconst = {
29683 .name = "sccIDE",
29684 .init_iops = init_iops_scc,
29685 .init_dma = scc_init_dma,
29686 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
29687 index 35fb8da..24d72ef 100644
29688 --- a/drivers/ide/serverworks.c
29689 +++ b/drivers/ide/serverworks.c
29690 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
29691 .cable_detect = svwks_cable_detect,
29692 };
29693
29694 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
29695 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
29696 { /* 0: OSB4 */
29697 .name = DRV_NAME,
29698 .init_chipset = init_chipset_svwks,
29699 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
29700 index ddeda44..46f7e30 100644
29701 --- a/drivers/ide/siimage.c
29702 +++ b/drivers/ide/siimage.c
29703 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
29704 .udma_mask = ATA_UDMA6, \
29705 }
29706
29707 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
29708 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
29709 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
29710 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
29711 };
29712 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
29713 index 4a00225..09e61b4 100644
29714 --- a/drivers/ide/sis5513.c
29715 +++ b/drivers/ide/sis5513.c
29716 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
29717 .cable_detect = sis_cable_detect,
29718 };
29719
29720 -static const struct ide_port_info sis5513_chipset __devinitdata = {
29721 +static const struct ide_port_info sis5513_chipset __devinitconst = {
29722 .name = DRV_NAME,
29723 .init_chipset = init_chipset_sis5513,
29724 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
29725 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
29726 index f21dc2a..d051cd2 100644
29727 --- a/drivers/ide/sl82c105.c
29728 +++ b/drivers/ide/sl82c105.c
29729 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
29730 .dma_sff_read_status = ide_dma_sff_read_status,
29731 };
29732
29733 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
29734 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
29735 .name = DRV_NAME,
29736 .init_chipset = init_chipset_sl82c105,
29737 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
29738 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
29739 index 864ffe0..863a5e9 100644
29740 --- a/drivers/ide/slc90e66.c
29741 +++ b/drivers/ide/slc90e66.c
29742 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
29743 .cable_detect = slc90e66_cable_detect,
29744 };
29745
29746 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
29747 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
29748 .name = DRV_NAME,
29749 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
29750 .port_ops = &slc90e66_port_ops,
29751 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
29752 index 4799d5c..1794678 100644
29753 --- a/drivers/ide/tc86c001.c
29754 +++ b/drivers/ide/tc86c001.c
29755 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
29756 .dma_sff_read_status = ide_dma_sff_read_status,
29757 };
29758
29759 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
29760 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
29761 .name = DRV_NAME,
29762 .init_hwif = init_hwif_tc86c001,
29763 .port_ops = &tc86c001_port_ops,
29764 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
29765 index 281c914..55ce1b8 100644
29766 --- a/drivers/ide/triflex.c
29767 +++ b/drivers/ide/triflex.c
29768 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
29769 .set_dma_mode = triflex_set_mode,
29770 };
29771
29772 -static const struct ide_port_info triflex_device __devinitdata = {
29773 +static const struct ide_port_info triflex_device __devinitconst = {
29774 .name = DRV_NAME,
29775 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
29776 .port_ops = &triflex_port_ops,
29777 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
29778 index 4b42ca0..e494a98 100644
29779 --- a/drivers/ide/trm290.c
29780 +++ b/drivers/ide/trm290.c
29781 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
29782 .dma_check = trm290_dma_check,
29783 };
29784
29785 -static const struct ide_port_info trm290_chipset __devinitdata = {
29786 +static const struct ide_port_info trm290_chipset __devinitconst = {
29787 .name = DRV_NAME,
29788 .init_hwif = init_hwif_trm290,
29789 .tp_ops = &trm290_tp_ops,
29790 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
29791 index f46f49c..eb77678 100644
29792 --- a/drivers/ide/via82cxxx.c
29793 +++ b/drivers/ide/via82cxxx.c
29794 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
29795 .cable_detect = via82cxxx_cable_detect,
29796 };
29797
29798 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
29799 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
29800 .name = DRV_NAME,
29801 .init_chipset = init_chipset_via82cxxx,
29802 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
29803 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
29804 index eb0e2cc..14241c7 100644
29805 --- a/drivers/ieee802154/fakehard.c
29806 +++ b/drivers/ieee802154/fakehard.c
29807 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
29808 phy->transmit_power = 0xbf;
29809
29810 dev->netdev_ops = &fake_ops;
29811 - dev->ml_priv = &fake_mlme;
29812 + dev->ml_priv = (void *)&fake_mlme;
29813
29814 priv = netdev_priv(dev);
29815 priv->phy = phy;
29816 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
29817 index 8b72f39..55df4c8 100644
29818 --- a/drivers/infiniband/core/cm.c
29819 +++ b/drivers/infiniband/core/cm.c
29820 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
29821
29822 struct cm_counter_group {
29823 struct kobject obj;
29824 - atomic_long_t counter[CM_ATTR_COUNT];
29825 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
29826 };
29827
29828 struct cm_counter_attribute {
29829 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
29830 struct ib_mad_send_buf *msg = NULL;
29831 int ret;
29832
29833 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29834 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29835 counter[CM_REQ_COUNTER]);
29836
29837 /* Quick state check to discard duplicate REQs. */
29838 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
29839 if (!cm_id_priv)
29840 return;
29841
29842 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29843 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29844 counter[CM_REP_COUNTER]);
29845 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
29846 if (ret)
29847 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
29848 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
29849 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
29850 spin_unlock_irq(&cm_id_priv->lock);
29851 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29852 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29853 counter[CM_RTU_COUNTER]);
29854 goto out;
29855 }
29856 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
29857 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
29858 dreq_msg->local_comm_id);
29859 if (!cm_id_priv) {
29860 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29861 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29862 counter[CM_DREQ_COUNTER]);
29863 cm_issue_drep(work->port, work->mad_recv_wc);
29864 return -EINVAL;
29865 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
29866 case IB_CM_MRA_REP_RCVD:
29867 break;
29868 case IB_CM_TIMEWAIT:
29869 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29870 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29871 counter[CM_DREQ_COUNTER]);
29872 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
29873 goto unlock;
29874 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
29875 cm_free_msg(msg);
29876 goto deref;
29877 case IB_CM_DREQ_RCVD:
29878 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29879 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29880 counter[CM_DREQ_COUNTER]);
29881 goto unlock;
29882 default:
29883 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
29884 ib_modify_mad(cm_id_priv->av.port->mad_agent,
29885 cm_id_priv->msg, timeout)) {
29886 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
29887 - atomic_long_inc(&work->port->
29888 + atomic_long_inc_unchecked(&work->port->
29889 counter_group[CM_RECV_DUPLICATES].
29890 counter[CM_MRA_COUNTER]);
29891 goto out;
29892 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
29893 break;
29894 case IB_CM_MRA_REQ_RCVD:
29895 case IB_CM_MRA_REP_RCVD:
29896 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29897 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29898 counter[CM_MRA_COUNTER]);
29899 /* fall through */
29900 default:
29901 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
29902 case IB_CM_LAP_IDLE:
29903 break;
29904 case IB_CM_MRA_LAP_SENT:
29905 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29906 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29907 counter[CM_LAP_COUNTER]);
29908 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
29909 goto unlock;
29910 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
29911 cm_free_msg(msg);
29912 goto deref;
29913 case IB_CM_LAP_RCVD:
29914 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29915 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29916 counter[CM_LAP_COUNTER]);
29917 goto unlock;
29918 default:
29919 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
29920 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
29921 if (cur_cm_id_priv) {
29922 spin_unlock_irq(&cm.lock);
29923 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29924 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29925 counter[CM_SIDR_REQ_COUNTER]);
29926 goto out; /* Duplicate message. */
29927 }
29928 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
29929 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
29930 msg->retries = 1;
29931
29932 - atomic_long_add(1 + msg->retries,
29933 + atomic_long_add_unchecked(1 + msg->retries,
29934 &port->counter_group[CM_XMIT].counter[attr_index]);
29935 if (msg->retries)
29936 - atomic_long_add(msg->retries,
29937 + atomic_long_add_unchecked(msg->retries,
29938 &port->counter_group[CM_XMIT_RETRIES].
29939 counter[attr_index]);
29940
29941 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
29942 }
29943
29944 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
29945 - atomic_long_inc(&port->counter_group[CM_RECV].
29946 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
29947 counter[attr_id - CM_ATTR_ID_OFFSET]);
29948
29949 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
29950 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
29951 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
29952
29953 return sprintf(buf, "%ld\n",
29954 - atomic_long_read(&group->counter[cm_attr->index]));
29955 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
29956 }
29957
29958 static const struct sysfs_ops cm_counter_ops = {
29959 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
29960 index 176c8f9..2627b62 100644
29961 --- a/drivers/infiniband/core/fmr_pool.c
29962 +++ b/drivers/infiniband/core/fmr_pool.c
29963 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
29964
29965 struct task_struct *thread;
29966
29967 - atomic_t req_ser;
29968 - atomic_t flush_ser;
29969 + atomic_unchecked_t req_ser;
29970 + atomic_unchecked_t flush_ser;
29971
29972 wait_queue_head_t force_wait;
29973 };
29974 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
29975 struct ib_fmr_pool *pool = pool_ptr;
29976
29977 do {
29978 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
29979 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
29980 ib_fmr_batch_release(pool);
29981
29982 - atomic_inc(&pool->flush_ser);
29983 + atomic_inc_unchecked(&pool->flush_ser);
29984 wake_up_interruptible(&pool->force_wait);
29985
29986 if (pool->flush_function)
29987 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
29988 }
29989
29990 set_current_state(TASK_INTERRUPTIBLE);
29991 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
29992 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
29993 !kthread_should_stop())
29994 schedule();
29995 __set_current_state(TASK_RUNNING);
29996 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
29997 pool->dirty_watermark = params->dirty_watermark;
29998 pool->dirty_len = 0;
29999 spin_lock_init(&pool->pool_lock);
30000 - atomic_set(&pool->req_ser, 0);
30001 - atomic_set(&pool->flush_ser, 0);
30002 + atomic_set_unchecked(&pool->req_ser, 0);
30003 + atomic_set_unchecked(&pool->flush_ser, 0);
30004 init_waitqueue_head(&pool->force_wait);
30005
30006 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30007 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
30008 }
30009 spin_unlock_irq(&pool->pool_lock);
30010
30011 - serial = atomic_inc_return(&pool->req_ser);
30012 + serial = atomic_inc_return_unchecked(&pool->req_ser);
30013 wake_up_process(pool->thread);
30014
30015 if (wait_event_interruptible(pool->force_wait,
30016 - atomic_read(&pool->flush_ser) - serial >= 0))
30017 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30018 return -EINTR;
30019
30020 return 0;
30021 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
30022 } else {
30023 list_add_tail(&fmr->list, &pool->dirty_list);
30024 if (++pool->dirty_len >= pool->dirty_watermark) {
30025 - atomic_inc(&pool->req_ser);
30026 + atomic_inc_unchecked(&pool->req_ser);
30027 wake_up_process(pool->thread);
30028 }
30029 }
30030 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
30031 index 40c8353..946b0e4 100644
30032 --- a/drivers/infiniband/hw/cxgb4/mem.c
30033 +++ b/drivers/infiniband/hw/cxgb4/mem.c
30034 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
30035 int err;
30036 struct fw_ri_tpte tpt;
30037 u32 stag_idx;
30038 - static atomic_t key;
30039 + static atomic_unchecked_t key;
30040
30041 if (c4iw_fatal_error(rdev))
30042 return -EIO;
30043 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
30044 &rdev->resource.tpt_fifo_lock);
30045 if (!stag_idx)
30046 return -ENOMEM;
30047 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
30048 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
30049 }
30050 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
30051 __func__, stag_state, type, pdid, stag_idx);
30052 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
30053 index 79b3dbc..96e5fcc 100644
30054 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
30055 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
30056 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
30057 struct ib_atomic_eth *ateth;
30058 struct ipath_ack_entry *e;
30059 u64 vaddr;
30060 - atomic64_t *maddr;
30061 + atomic64_unchecked_t *maddr;
30062 u64 sdata;
30063 u32 rkey;
30064 u8 next;
30065 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
30066 IB_ACCESS_REMOTE_ATOMIC)))
30067 goto nack_acc_unlck;
30068 /* Perform atomic OP and save result. */
30069 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30070 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30071 sdata = be64_to_cpu(ateth->swap_data);
30072 e = &qp->s_ack_queue[qp->r_head_ack_queue];
30073 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
30074 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30075 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30076 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30077 be64_to_cpu(ateth->compare_data),
30078 sdata);
30079 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
30080 index 1f95bba..9530f87 100644
30081 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
30082 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
30083 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
30084 unsigned long flags;
30085 struct ib_wc wc;
30086 u64 sdata;
30087 - atomic64_t *maddr;
30088 + atomic64_unchecked_t *maddr;
30089 enum ib_wc_status send_status;
30090
30091 /*
30092 @@ -382,11 +382,11 @@ again:
30093 IB_ACCESS_REMOTE_ATOMIC)))
30094 goto acc_err;
30095 /* Perform atomic OP and save result. */
30096 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30097 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30098 sdata = wqe->wr.wr.atomic.compare_add;
30099 *(u64 *) sqp->s_sge.sge.vaddr =
30100 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30101 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30102 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30103 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30104 sdata, wqe->wr.wr.atomic.swap);
30105 goto send_comp;
30106 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
30107 index 5965b3d..16817fb 100644
30108 --- a/drivers/infiniband/hw/nes/nes.c
30109 +++ b/drivers/infiniband/hw/nes/nes.c
30110 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
30111 LIST_HEAD(nes_adapter_list);
30112 static LIST_HEAD(nes_dev_list);
30113
30114 -atomic_t qps_destroyed;
30115 +atomic_unchecked_t qps_destroyed;
30116
30117 static unsigned int ee_flsh_adapter;
30118 static unsigned int sysfs_nonidx_addr;
30119 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
30120 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30121 struct nes_adapter *nesadapter = nesdev->nesadapter;
30122
30123 - atomic_inc(&qps_destroyed);
30124 + atomic_inc_unchecked(&qps_destroyed);
30125
30126 /* Free the control structures */
30127
30128 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
30129 index 568b4f1..5ea3eff 100644
30130 --- a/drivers/infiniband/hw/nes/nes.h
30131 +++ b/drivers/infiniband/hw/nes/nes.h
30132 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
30133 extern unsigned int wqm_quanta;
30134 extern struct list_head nes_adapter_list;
30135
30136 -extern atomic_t cm_connects;
30137 -extern atomic_t cm_accepts;
30138 -extern atomic_t cm_disconnects;
30139 -extern atomic_t cm_closes;
30140 -extern atomic_t cm_connecteds;
30141 -extern atomic_t cm_connect_reqs;
30142 -extern atomic_t cm_rejects;
30143 -extern atomic_t mod_qp_timouts;
30144 -extern atomic_t qps_created;
30145 -extern atomic_t qps_destroyed;
30146 -extern atomic_t sw_qps_destroyed;
30147 +extern atomic_unchecked_t cm_connects;
30148 +extern atomic_unchecked_t cm_accepts;
30149 +extern atomic_unchecked_t cm_disconnects;
30150 +extern atomic_unchecked_t cm_closes;
30151 +extern atomic_unchecked_t cm_connecteds;
30152 +extern atomic_unchecked_t cm_connect_reqs;
30153 +extern atomic_unchecked_t cm_rejects;
30154 +extern atomic_unchecked_t mod_qp_timouts;
30155 +extern atomic_unchecked_t qps_created;
30156 +extern atomic_unchecked_t qps_destroyed;
30157 +extern atomic_unchecked_t sw_qps_destroyed;
30158 extern u32 mh_detected;
30159 extern u32 mh_pauses_sent;
30160 extern u32 cm_packets_sent;
30161 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
30162 extern u32 cm_packets_received;
30163 extern u32 cm_packets_dropped;
30164 extern u32 cm_packets_retrans;
30165 -extern atomic_t cm_listens_created;
30166 -extern atomic_t cm_listens_destroyed;
30167 +extern atomic_unchecked_t cm_listens_created;
30168 +extern atomic_unchecked_t cm_listens_destroyed;
30169 extern u32 cm_backlog_drops;
30170 -extern atomic_t cm_loopbacks;
30171 -extern atomic_t cm_nodes_created;
30172 -extern atomic_t cm_nodes_destroyed;
30173 -extern atomic_t cm_accel_dropped_pkts;
30174 -extern atomic_t cm_resets_recvd;
30175 -extern atomic_t pau_qps_created;
30176 -extern atomic_t pau_qps_destroyed;
30177 +extern atomic_unchecked_t cm_loopbacks;
30178 +extern atomic_unchecked_t cm_nodes_created;
30179 +extern atomic_unchecked_t cm_nodes_destroyed;
30180 +extern atomic_unchecked_t cm_accel_dropped_pkts;
30181 +extern atomic_unchecked_t cm_resets_recvd;
30182 +extern atomic_unchecked_t pau_qps_created;
30183 +extern atomic_unchecked_t pau_qps_destroyed;
30184
30185 extern u32 int_mod_timer_init;
30186 extern u32 int_mod_cq_depth_256;
30187 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
30188 index 0a52d72..0642f36 100644
30189 --- a/drivers/infiniband/hw/nes/nes_cm.c
30190 +++ b/drivers/infiniband/hw/nes/nes_cm.c
30191 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30192 u32 cm_packets_retrans;
30193 u32 cm_packets_created;
30194 u32 cm_packets_received;
30195 -atomic_t cm_listens_created;
30196 -atomic_t cm_listens_destroyed;
30197 +atomic_unchecked_t cm_listens_created;
30198 +atomic_unchecked_t cm_listens_destroyed;
30199 u32 cm_backlog_drops;
30200 -atomic_t cm_loopbacks;
30201 -atomic_t cm_nodes_created;
30202 -atomic_t cm_nodes_destroyed;
30203 -atomic_t cm_accel_dropped_pkts;
30204 -atomic_t cm_resets_recvd;
30205 +atomic_unchecked_t cm_loopbacks;
30206 +atomic_unchecked_t cm_nodes_created;
30207 +atomic_unchecked_t cm_nodes_destroyed;
30208 +atomic_unchecked_t cm_accel_dropped_pkts;
30209 +atomic_unchecked_t cm_resets_recvd;
30210
30211 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
30212 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
30213 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
30214
30215 static struct nes_cm_core *g_cm_core;
30216
30217 -atomic_t cm_connects;
30218 -atomic_t cm_accepts;
30219 -atomic_t cm_disconnects;
30220 -atomic_t cm_closes;
30221 -atomic_t cm_connecteds;
30222 -atomic_t cm_connect_reqs;
30223 -atomic_t cm_rejects;
30224 +atomic_unchecked_t cm_connects;
30225 +atomic_unchecked_t cm_accepts;
30226 +atomic_unchecked_t cm_disconnects;
30227 +atomic_unchecked_t cm_closes;
30228 +atomic_unchecked_t cm_connecteds;
30229 +atomic_unchecked_t cm_connect_reqs;
30230 +atomic_unchecked_t cm_rejects;
30231
30232 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
30233 {
30234 @@ -1271,7 +1271,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
30235 kfree(listener);
30236 listener = NULL;
30237 ret = 0;
30238 - atomic_inc(&cm_listens_destroyed);
30239 + atomic_inc_unchecked(&cm_listens_destroyed);
30240 } else {
30241 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30242 }
30243 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
30244 cm_node->rem_mac);
30245
30246 add_hte_node(cm_core, cm_node);
30247 - atomic_inc(&cm_nodes_created);
30248 + atomic_inc_unchecked(&cm_nodes_created);
30249
30250 return cm_node;
30251 }
30252 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
30253 }
30254
30255 atomic_dec(&cm_core->node_cnt);
30256 - atomic_inc(&cm_nodes_destroyed);
30257 + atomic_inc_unchecked(&cm_nodes_destroyed);
30258 nesqp = cm_node->nesqp;
30259 if (nesqp) {
30260 nesqp->cm_node = NULL;
30261 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
30262
30263 static void drop_packet(struct sk_buff *skb)
30264 {
30265 - atomic_inc(&cm_accel_dropped_pkts);
30266 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30267 dev_kfree_skb_any(skb);
30268 }
30269
30270 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
30271 {
30272
30273 int reset = 0; /* whether to send reset in case of err.. */
30274 - atomic_inc(&cm_resets_recvd);
30275 + atomic_inc_unchecked(&cm_resets_recvd);
30276 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30277 " refcnt=%d\n", cm_node, cm_node->state,
30278 atomic_read(&cm_node->ref_count));
30279 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
30280 rem_ref_cm_node(cm_node->cm_core, cm_node);
30281 return NULL;
30282 }
30283 - atomic_inc(&cm_loopbacks);
30284 + atomic_inc_unchecked(&cm_loopbacks);
30285 loopbackremotenode->loopbackpartner = cm_node;
30286 loopbackremotenode->tcp_cntxt.rcv_wscale =
30287 NES_CM_DEFAULT_RCV_WND_SCALE;
30288 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
30289 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
30290 else {
30291 rem_ref_cm_node(cm_core, cm_node);
30292 - atomic_inc(&cm_accel_dropped_pkts);
30293 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30294 dev_kfree_skb_any(skb);
30295 }
30296 break;
30297 @@ -2880,7 +2880,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30298
30299 if ((cm_id) && (cm_id->event_handler)) {
30300 if (issue_disconn) {
30301 - atomic_inc(&cm_disconnects);
30302 + atomic_inc_unchecked(&cm_disconnects);
30303 cm_event.event = IW_CM_EVENT_DISCONNECT;
30304 cm_event.status = disconn_status;
30305 cm_event.local_addr = cm_id->local_addr;
30306 @@ -2902,7 +2902,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30307 }
30308
30309 if (issue_close) {
30310 - atomic_inc(&cm_closes);
30311 + atomic_inc_unchecked(&cm_closes);
30312 nes_disconnect(nesqp, 1);
30313
30314 cm_id->provider_data = nesqp;
30315 @@ -3038,7 +3038,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30316
30317 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30318 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30319 - atomic_inc(&cm_accepts);
30320 + atomic_inc_unchecked(&cm_accepts);
30321
30322 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30323 netdev_refcnt_read(nesvnic->netdev));
30324 @@ -3240,7 +3240,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
30325 struct nes_cm_core *cm_core;
30326 u8 *start_buff;
30327
30328 - atomic_inc(&cm_rejects);
30329 + atomic_inc_unchecked(&cm_rejects);
30330 cm_node = (struct nes_cm_node *)cm_id->provider_data;
30331 loopback = cm_node->loopbackpartner;
30332 cm_core = cm_node->cm_core;
30333 @@ -3300,7 +3300,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30334 ntohl(cm_id->local_addr.sin_addr.s_addr),
30335 ntohs(cm_id->local_addr.sin_port));
30336
30337 - atomic_inc(&cm_connects);
30338 + atomic_inc_unchecked(&cm_connects);
30339 nesqp->active_conn = 1;
30340
30341 /* cache the cm_id in the qp */
30342 @@ -3406,7 +3406,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
30343 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30344 return err;
30345 }
30346 - atomic_inc(&cm_listens_created);
30347 + atomic_inc_unchecked(&cm_listens_created);
30348 }
30349
30350 cm_id->add_ref(cm_id);
30351 @@ -3507,7 +3507,7 @@ static void cm_event_connected(struct nes_cm_event *event)
30352
30353 if (nesqp->destroyed)
30354 return;
30355 - atomic_inc(&cm_connecteds);
30356 + atomic_inc_unchecked(&cm_connecteds);
30357 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30358 " local port 0x%04X. jiffies = %lu.\n",
30359 nesqp->hwqp.qp_id,
30360 @@ -3694,7 +3694,7 @@ static void cm_event_reset(struct nes_cm_event *event)
30361
30362 cm_id->add_ref(cm_id);
30363 ret = cm_id->event_handler(cm_id, &cm_event);
30364 - atomic_inc(&cm_closes);
30365 + atomic_inc_unchecked(&cm_closes);
30366 cm_event.event = IW_CM_EVENT_CLOSE;
30367 cm_event.status = 0;
30368 cm_event.provider_data = cm_id->provider_data;
30369 @@ -3730,7 +3730,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
30370 return;
30371 cm_id = cm_node->cm_id;
30372
30373 - atomic_inc(&cm_connect_reqs);
30374 + atomic_inc_unchecked(&cm_connect_reqs);
30375 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30376 cm_node, cm_id, jiffies);
30377
30378 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
30379 return;
30380 cm_id = cm_node->cm_id;
30381
30382 - atomic_inc(&cm_connect_reqs);
30383 + atomic_inc_unchecked(&cm_connect_reqs);
30384 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30385 cm_node, cm_id, jiffies);
30386
30387 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
30388 index b3b2a24..7bfaf1e 100644
30389 --- a/drivers/infiniband/hw/nes/nes_mgt.c
30390 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
30391 @@ -40,8 +40,8 @@
30392 #include "nes.h"
30393 #include "nes_mgt.h"
30394
30395 -atomic_t pau_qps_created;
30396 -atomic_t pau_qps_destroyed;
30397 +atomic_unchecked_t pau_qps_created;
30398 +atomic_unchecked_t pau_qps_destroyed;
30399
30400 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
30401 {
30402 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
30403 {
30404 struct sk_buff *skb;
30405 unsigned long flags;
30406 - atomic_inc(&pau_qps_destroyed);
30407 + atomic_inc_unchecked(&pau_qps_destroyed);
30408
30409 /* Free packets that have not yet been forwarded */
30410 /* Lock is acquired by skb_dequeue when removing the skb */
30411 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
30412 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
30413 skb_queue_head_init(&nesqp->pau_list);
30414 spin_lock_init(&nesqp->pau_lock);
30415 - atomic_inc(&pau_qps_created);
30416 + atomic_inc_unchecked(&pau_qps_created);
30417 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
30418 }
30419
30420 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
30421 index c00d2f3..8834298 100644
30422 --- a/drivers/infiniband/hw/nes/nes_nic.c
30423 +++ b/drivers/infiniband/hw/nes/nes_nic.c
30424 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
30425 target_stat_values[++index] = mh_detected;
30426 target_stat_values[++index] = mh_pauses_sent;
30427 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
30428 - target_stat_values[++index] = atomic_read(&cm_connects);
30429 - target_stat_values[++index] = atomic_read(&cm_accepts);
30430 - target_stat_values[++index] = atomic_read(&cm_disconnects);
30431 - target_stat_values[++index] = atomic_read(&cm_connecteds);
30432 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
30433 - target_stat_values[++index] = atomic_read(&cm_rejects);
30434 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
30435 - target_stat_values[++index] = atomic_read(&qps_created);
30436 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
30437 - target_stat_values[++index] = atomic_read(&qps_destroyed);
30438 - target_stat_values[++index] = atomic_read(&cm_closes);
30439 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
30440 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
30441 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
30442 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
30443 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
30444 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
30445 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
30446 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
30447 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
30448 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
30449 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
30450 target_stat_values[++index] = cm_packets_sent;
30451 target_stat_values[++index] = cm_packets_bounced;
30452 target_stat_values[++index] = cm_packets_created;
30453 target_stat_values[++index] = cm_packets_received;
30454 target_stat_values[++index] = cm_packets_dropped;
30455 target_stat_values[++index] = cm_packets_retrans;
30456 - target_stat_values[++index] = atomic_read(&cm_listens_created);
30457 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
30458 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
30459 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
30460 target_stat_values[++index] = cm_backlog_drops;
30461 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
30462 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
30463 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
30464 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
30465 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
30466 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
30467 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
30468 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
30469 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
30470 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
30471 target_stat_values[++index] = nesadapter->free_4kpbl;
30472 target_stat_values[++index] = nesadapter->free_256pbl;
30473 target_stat_values[++index] = int_mod_timer_init;
30474 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
30475 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
30476 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
30477 - target_stat_values[++index] = atomic_read(&pau_qps_created);
30478 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
30479 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
30480 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
30481 }
30482
30483 /**
30484 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
30485 index 5095bc4..41e8fff 100644
30486 --- a/drivers/infiniband/hw/nes/nes_verbs.c
30487 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
30488 @@ -46,9 +46,9 @@
30489
30490 #include <rdma/ib_umem.h>
30491
30492 -atomic_t mod_qp_timouts;
30493 -atomic_t qps_created;
30494 -atomic_t sw_qps_destroyed;
30495 +atomic_unchecked_t mod_qp_timouts;
30496 +atomic_unchecked_t qps_created;
30497 +atomic_unchecked_t sw_qps_destroyed;
30498
30499 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
30500
30501 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
30502 if (init_attr->create_flags)
30503 return ERR_PTR(-EINVAL);
30504
30505 - atomic_inc(&qps_created);
30506 + atomic_inc_unchecked(&qps_created);
30507 switch (init_attr->qp_type) {
30508 case IB_QPT_RC:
30509 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
30510 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
30511 struct iw_cm_event cm_event;
30512 int ret = 0;
30513
30514 - atomic_inc(&sw_qps_destroyed);
30515 + atomic_inc_unchecked(&sw_qps_destroyed);
30516 nesqp->destroyed = 1;
30517
30518 /* Blow away the connection if it exists. */
30519 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
30520 index b881bdc..c2e360c 100644
30521 --- a/drivers/infiniband/hw/qib/qib.h
30522 +++ b/drivers/infiniband/hw/qib/qib.h
30523 @@ -51,6 +51,7 @@
30524 #include <linux/completion.h>
30525 #include <linux/kref.h>
30526 #include <linux/sched.h>
30527 +#include <linux/slab.h>
30528
30529 #include "qib_common.h"
30530 #include "qib_verbs.h"
30531 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
30532 index c351aa4..e6967c2 100644
30533 --- a/drivers/input/gameport/gameport.c
30534 +++ b/drivers/input/gameport/gameport.c
30535 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
30536 */
30537 static void gameport_init_port(struct gameport *gameport)
30538 {
30539 - static atomic_t gameport_no = ATOMIC_INIT(0);
30540 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
30541
30542 __module_get(THIS_MODULE);
30543
30544 mutex_init(&gameport->drv_mutex);
30545 device_initialize(&gameport->dev);
30546 dev_set_name(&gameport->dev, "gameport%lu",
30547 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
30548 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
30549 gameport->dev.bus = &gameport_bus;
30550 gameport->dev.release = gameport_release_port;
30551 if (gameport->parent)
30552 diff --git a/drivers/input/input.c b/drivers/input/input.c
30553 index da38d97..2aa0b79 100644
30554 --- a/drivers/input/input.c
30555 +++ b/drivers/input/input.c
30556 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
30557 */
30558 int input_register_device(struct input_dev *dev)
30559 {
30560 - static atomic_t input_no = ATOMIC_INIT(0);
30561 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
30562 struct input_handler *handler;
30563 const char *path;
30564 int error;
30565 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
30566 dev->setkeycode = input_default_setkeycode;
30567
30568 dev_set_name(&dev->dev, "input%ld",
30569 - (unsigned long) atomic_inc_return(&input_no) - 1);
30570 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
30571
30572 error = device_add(&dev->dev);
30573 if (error)
30574 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
30575 index b8d8611..7a4a04b 100644
30576 --- a/drivers/input/joystick/sidewinder.c
30577 +++ b/drivers/input/joystick/sidewinder.c
30578 @@ -30,6 +30,7 @@
30579 #include <linux/kernel.h>
30580 #include <linux/module.h>
30581 #include <linux/slab.h>
30582 +#include <linux/sched.h>
30583 #include <linux/init.h>
30584 #include <linux/input.h>
30585 #include <linux/gameport.h>
30586 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
30587 index d728875..844c89b 100644
30588 --- a/drivers/input/joystick/xpad.c
30589 +++ b/drivers/input/joystick/xpad.c
30590 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
30591
30592 static int xpad_led_probe(struct usb_xpad *xpad)
30593 {
30594 - static atomic_t led_seq = ATOMIC_INIT(0);
30595 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
30596 long led_no;
30597 struct xpad_led *led;
30598 struct led_classdev *led_cdev;
30599 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
30600 if (!led)
30601 return -ENOMEM;
30602
30603 - led_no = (long)atomic_inc_return(&led_seq) - 1;
30604 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
30605
30606 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
30607 led->xpad = xpad;
30608 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
30609 index 0110b5a..d3ad144 100644
30610 --- a/drivers/input/mousedev.c
30611 +++ b/drivers/input/mousedev.c
30612 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
30613
30614 spin_unlock_irq(&client->packet_lock);
30615
30616 - if (copy_to_user(buffer, data, count))
30617 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
30618 return -EFAULT;
30619
30620 return count;
30621 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
30622 index ba70058..571d25d 100644
30623 --- a/drivers/input/serio/serio.c
30624 +++ b/drivers/input/serio/serio.c
30625 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
30626 */
30627 static void serio_init_port(struct serio *serio)
30628 {
30629 - static atomic_t serio_no = ATOMIC_INIT(0);
30630 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
30631
30632 __module_get(THIS_MODULE);
30633
30634 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
30635 mutex_init(&serio->drv_mutex);
30636 device_initialize(&serio->dev);
30637 dev_set_name(&serio->dev, "serio%ld",
30638 - (long)atomic_inc_return(&serio_no) - 1);
30639 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
30640 serio->dev.bus = &serio_bus;
30641 serio->dev.release = serio_release_port;
30642 serio->dev.groups = serio_device_attr_groups;
30643 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
30644 index e44933d..9ba484a 100644
30645 --- a/drivers/isdn/capi/capi.c
30646 +++ b/drivers/isdn/capi/capi.c
30647 @@ -83,8 +83,8 @@ struct capiminor {
30648
30649 struct capi20_appl *ap;
30650 u32 ncci;
30651 - atomic_t datahandle;
30652 - atomic_t msgid;
30653 + atomic_unchecked_t datahandle;
30654 + atomic_unchecked_t msgid;
30655
30656 struct tty_port port;
30657 int ttyinstop;
30658 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
30659 capimsg_setu16(s, 2, mp->ap->applid);
30660 capimsg_setu8 (s, 4, CAPI_DATA_B3);
30661 capimsg_setu8 (s, 5, CAPI_RESP);
30662 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
30663 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
30664 capimsg_setu32(s, 8, mp->ncci);
30665 capimsg_setu16(s, 12, datahandle);
30666 }
30667 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
30668 mp->outbytes -= len;
30669 spin_unlock_bh(&mp->outlock);
30670
30671 - datahandle = atomic_inc_return(&mp->datahandle);
30672 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
30673 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
30674 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30675 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30676 capimsg_setu16(skb->data, 2, mp->ap->applid);
30677 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
30678 capimsg_setu8 (skb->data, 5, CAPI_REQ);
30679 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
30680 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
30681 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
30682 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
30683 capimsg_setu16(skb->data, 16, len); /* Data length */
30684 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
30685 index db621db..825ea1a 100644
30686 --- a/drivers/isdn/gigaset/common.c
30687 +++ b/drivers/isdn/gigaset/common.c
30688 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
30689 cs->commands_pending = 0;
30690 cs->cur_at_seq = 0;
30691 cs->gotfwver = -1;
30692 - cs->open_count = 0;
30693 + local_set(&cs->open_count, 0);
30694 cs->dev = NULL;
30695 cs->tty = NULL;
30696 cs->tty_dev = NULL;
30697 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
30698 index 212efaf..f187c6b 100644
30699 --- a/drivers/isdn/gigaset/gigaset.h
30700 +++ b/drivers/isdn/gigaset/gigaset.h
30701 @@ -35,6 +35,7 @@
30702 #include <linux/tty_driver.h>
30703 #include <linux/list.h>
30704 #include <linux/atomic.h>
30705 +#include <asm/local.h>
30706
30707 #define GIG_VERSION {0, 5, 0, 0}
30708 #define GIG_COMPAT {0, 4, 0, 0}
30709 @@ -433,7 +434,7 @@ struct cardstate {
30710 spinlock_t cmdlock;
30711 unsigned curlen, cmdbytes;
30712
30713 - unsigned open_count;
30714 + local_t open_count;
30715 struct tty_struct *tty;
30716 struct tasklet_struct if_wake_tasklet;
30717 unsigned control_state;
30718 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
30719 index ee0a549..a7c9798 100644
30720 --- a/drivers/isdn/gigaset/interface.c
30721 +++ b/drivers/isdn/gigaset/interface.c
30722 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
30723 }
30724 tty->driver_data = cs;
30725
30726 - ++cs->open_count;
30727 -
30728 - if (cs->open_count == 1) {
30729 + if (local_inc_return(&cs->open_count) == 1) {
30730 spin_lock_irqsave(&cs->lock, flags);
30731 cs->tty = tty;
30732 spin_unlock_irqrestore(&cs->lock, flags);
30733 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
30734
30735 if (!cs->connected)
30736 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30737 - else if (!cs->open_count)
30738 + else if (!local_read(&cs->open_count))
30739 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30740 else {
30741 - if (!--cs->open_count) {
30742 + if (!local_dec_return(&cs->open_count)) {
30743 spin_lock_irqsave(&cs->lock, flags);
30744 cs->tty = NULL;
30745 spin_unlock_irqrestore(&cs->lock, flags);
30746 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
30747 if (!cs->connected) {
30748 gig_dbg(DEBUG_IF, "not connected");
30749 retval = -ENODEV;
30750 - } else if (!cs->open_count)
30751 + } else if (!local_read(&cs->open_count))
30752 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30753 else {
30754 retval = 0;
30755 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
30756 retval = -ENODEV;
30757 goto done;
30758 }
30759 - if (!cs->open_count) {
30760 + if (!local_read(&cs->open_count)) {
30761 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30762 retval = -ENODEV;
30763 goto done;
30764 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
30765 if (!cs->connected) {
30766 gig_dbg(DEBUG_IF, "not connected");
30767 retval = -ENODEV;
30768 - } else if (!cs->open_count)
30769 + } else if (!local_read(&cs->open_count))
30770 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30771 else if (cs->mstate != MS_LOCKED) {
30772 dev_warn(cs->dev, "can't write to unlocked device\n");
30773 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
30774
30775 if (!cs->connected)
30776 gig_dbg(DEBUG_IF, "not connected");
30777 - else if (!cs->open_count)
30778 + else if (!local_read(&cs->open_count))
30779 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30780 else if (cs->mstate != MS_LOCKED)
30781 dev_warn(cs->dev, "can't write to unlocked device\n");
30782 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
30783
30784 if (!cs->connected)
30785 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30786 - else if (!cs->open_count)
30787 + else if (!local_read(&cs->open_count))
30788 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30789 else
30790 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
30791 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
30792
30793 if (!cs->connected)
30794 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30795 - else if (!cs->open_count)
30796 + else if (!local_read(&cs->open_count))
30797 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30798 else
30799 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
30800 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
30801 goto out;
30802 }
30803
30804 - if (!cs->open_count) {
30805 + if (!local_read(&cs->open_count)) {
30806 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30807 goto out;
30808 }
30809 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
30810 index 2a57da59..e7a12ed 100644
30811 --- a/drivers/isdn/hardware/avm/b1.c
30812 +++ b/drivers/isdn/hardware/avm/b1.c
30813 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
30814 }
30815 if (left) {
30816 if (t4file->user) {
30817 - if (copy_from_user(buf, dp, left))
30818 + if (left > sizeof buf || copy_from_user(buf, dp, left))
30819 return -EFAULT;
30820 } else {
30821 memcpy(buf, dp, left);
30822 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
30823 }
30824 if (left) {
30825 if (config->user) {
30826 - if (copy_from_user(buf, dp, left))
30827 + if (left > sizeof buf || copy_from_user(buf, dp, left))
30828 return -EFAULT;
30829 } else {
30830 memcpy(buf, dp, left);
30831 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
30832 index 85784a7..a19ca98 100644
30833 --- a/drivers/isdn/hardware/eicon/divasync.h
30834 +++ b/drivers/isdn/hardware/eicon/divasync.h
30835 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
30836 } diva_didd_add_adapter_t;
30837 typedef struct _diva_didd_remove_adapter {
30838 IDI_CALL p_request;
30839 -} diva_didd_remove_adapter_t;
30840 +} __no_const diva_didd_remove_adapter_t;
30841 typedef struct _diva_didd_read_adapter_array {
30842 void * buffer;
30843 dword length;
30844 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
30845 index a3bd163..8956575 100644
30846 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
30847 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
30848 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
30849 typedef struct _diva_os_idi_adapter_interface {
30850 diva_init_card_proc_t cleanup_adapter_proc;
30851 diva_cmd_card_proc_t cmd_proc;
30852 -} diva_os_idi_adapter_interface_t;
30853 +} __no_const diva_os_idi_adapter_interface_t;
30854
30855 typedef struct _diva_os_xdi_adapter {
30856 struct list_head link;
30857 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
30858 index 1f355bb..43f1fea 100644
30859 --- a/drivers/isdn/icn/icn.c
30860 +++ b/drivers/isdn/icn/icn.c
30861 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
30862 if (count > len)
30863 count = len;
30864 if (user) {
30865 - if (copy_from_user(msg, buf, count))
30866 + if (count > sizeof msg || copy_from_user(msg, buf, count))
30867 return -EFAULT;
30868 } else
30869 memcpy(msg, buf, count);
30870 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
30871 index b5fdcb7..5b6c59f 100644
30872 --- a/drivers/lguest/core.c
30873 +++ b/drivers/lguest/core.c
30874 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
30875 * it's worked so far. The end address needs +1 because __get_vm_area
30876 * allocates an extra guard page, so we need space for that.
30877 */
30878 +
30879 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30880 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
30881 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
30882 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
30883 +#else
30884 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
30885 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
30886 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
30887 +#endif
30888 +
30889 if (!switcher_vma) {
30890 err = -ENOMEM;
30891 printk("lguest: could not map switcher pages high\n");
30892 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
30893 * Now the Switcher is mapped at the right address, we can't fail!
30894 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
30895 */
30896 - memcpy(switcher_vma->addr, start_switcher_text,
30897 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
30898 end_switcher_text - start_switcher_text);
30899
30900 printk(KERN_INFO "lguest: mapped switcher at %p\n",
30901 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
30902 index 65af42f..530c87a 100644
30903 --- a/drivers/lguest/x86/core.c
30904 +++ b/drivers/lguest/x86/core.c
30905 @@ -59,7 +59,7 @@ static struct {
30906 /* Offset from where switcher.S was compiled to where we've copied it */
30907 static unsigned long switcher_offset(void)
30908 {
30909 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
30910 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
30911 }
30912
30913 /* This cpu's struct lguest_pages. */
30914 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
30915 * These copies are pretty cheap, so we do them unconditionally: */
30916 /* Save the current Host top-level page directory.
30917 */
30918 +
30919 +#ifdef CONFIG_PAX_PER_CPU_PGD
30920 + pages->state.host_cr3 = read_cr3();
30921 +#else
30922 pages->state.host_cr3 = __pa(current->mm->pgd);
30923 +#endif
30924 +
30925 /*
30926 * Set up the Guest's page tables to see this CPU's pages (and no
30927 * other CPU's pages).
30928 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
30929 * compiled-in switcher code and the high-mapped copy we just made.
30930 */
30931 for (i = 0; i < IDT_ENTRIES; i++)
30932 - default_idt_entries[i] += switcher_offset();
30933 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
30934
30935 /*
30936 * Set up the Switcher's per-cpu areas.
30937 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
30938 * it will be undisturbed when we switch. To change %cs and jump we
30939 * need this structure to feed to Intel's "lcall" instruction.
30940 */
30941 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
30942 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
30943 lguest_entry.segment = LGUEST_CS;
30944
30945 /*
30946 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
30947 index 40634b0..4f5855e 100644
30948 --- a/drivers/lguest/x86/switcher_32.S
30949 +++ b/drivers/lguest/x86/switcher_32.S
30950 @@ -87,6 +87,7 @@
30951 #include <asm/page.h>
30952 #include <asm/segment.h>
30953 #include <asm/lguest.h>
30954 +#include <asm/processor-flags.h>
30955
30956 // We mark the start of the code to copy
30957 // It's placed in .text tho it's never run here
30958 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
30959 // Changes type when we load it: damn Intel!
30960 // For after we switch over our page tables
30961 // That entry will be read-only: we'd crash.
30962 +
30963 +#ifdef CONFIG_PAX_KERNEXEC
30964 + mov %cr0, %edx
30965 + xor $X86_CR0_WP, %edx
30966 + mov %edx, %cr0
30967 +#endif
30968 +
30969 movl $(GDT_ENTRY_TSS*8), %edx
30970 ltr %dx
30971
30972 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
30973 // Let's clear it again for our return.
30974 // The GDT descriptor of the Host
30975 // Points to the table after two "size" bytes
30976 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
30977 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
30978 // Clear "used" from type field (byte 5, bit 2)
30979 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
30980 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
30981 +
30982 +#ifdef CONFIG_PAX_KERNEXEC
30983 + mov %cr0, %eax
30984 + xor $X86_CR0_WP, %eax
30985 + mov %eax, %cr0
30986 +#endif
30987
30988 // Once our page table's switched, the Guest is live!
30989 // The Host fades as we run this final step.
30990 @@ -295,13 +309,12 @@ deliver_to_host:
30991 // I consulted gcc, and it gave
30992 // These instructions, which I gladly credit:
30993 leal (%edx,%ebx,8), %eax
30994 - movzwl (%eax),%edx
30995 - movl 4(%eax), %eax
30996 - xorw %ax, %ax
30997 - orl %eax, %edx
30998 + movl 4(%eax), %edx
30999 + movw (%eax), %dx
31000 // Now the address of the handler's in %edx
31001 // We call it now: its "iret" drops us home.
31002 - jmp *%edx
31003 + ljmp $__KERNEL_CS, $1f
31004 +1: jmp *%edx
31005
31006 // Every interrupt can come to us here
31007 // But we must truly tell each apart.
31008 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
31009 index 4daf9e5..b8d1d0f 100644
31010 --- a/drivers/macintosh/macio_asic.c
31011 +++ b/drivers/macintosh/macio_asic.c
31012 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
31013 * MacIO is matched against any Apple ID, it's probe() function
31014 * will then decide wether it applies or not
31015 */
31016 -static const struct pci_device_id __devinitdata pci_ids [] = { {
31017 +static const struct pci_device_id __devinitconst pci_ids [] = { {
31018 .vendor = PCI_VENDOR_ID_APPLE,
31019 .device = PCI_ANY_ID,
31020 .subvendor = PCI_ANY_ID,
31021 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
31022 index 31c2dc2..a2de7a6 100644
31023 --- a/drivers/md/dm-ioctl.c
31024 +++ b/drivers/md/dm-ioctl.c
31025 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
31026 cmd == DM_LIST_VERSIONS_CMD)
31027 return 0;
31028
31029 - if ((cmd == DM_DEV_CREATE_CMD)) {
31030 + if (cmd == DM_DEV_CREATE_CMD) {
31031 if (!*param->name) {
31032 DMWARN("name not supplied when creating device");
31033 return -EINVAL;
31034 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
31035 index 9bfd057..01180bc 100644
31036 --- a/drivers/md/dm-raid1.c
31037 +++ b/drivers/md/dm-raid1.c
31038 @@ -40,7 +40,7 @@ enum dm_raid1_error {
31039
31040 struct mirror {
31041 struct mirror_set *ms;
31042 - atomic_t error_count;
31043 + atomic_unchecked_t error_count;
31044 unsigned long error_type;
31045 struct dm_dev *dev;
31046 sector_t offset;
31047 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
31048 struct mirror *m;
31049
31050 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
31051 - if (!atomic_read(&m->error_count))
31052 + if (!atomic_read_unchecked(&m->error_count))
31053 return m;
31054
31055 return NULL;
31056 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
31057 * simple way to tell if a device has encountered
31058 * errors.
31059 */
31060 - atomic_inc(&m->error_count);
31061 + atomic_inc_unchecked(&m->error_count);
31062
31063 if (test_and_set_bit(error_type, &m->error_type))
31064 return;
31065 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
31066 struct mirror *m = get_default_mirror(ms);
31067
31068 do {
31069 - if (likely(!atomic_read(&m->error_count)))
31070 + if (likely(!atomic_read_unchecked(&m->error_count)))
31071 return m;
31072
31073 if (m-- == ms->mirror)
31074 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
31075 {
31076 struct mirror *default_mirror = get_default_mirror(m->ms);
31077
31078 - return !atomic_read(&default_mirror->error_count);
31079 + return !atomic_read_unchecked(&default_mirror->error_count);
31080 }
31081
31082 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31083 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
31084 */
31085 if (likely(region_in_sync(ms, region, 1)))
31086 m = choose_mirror(ms, bio->bi_sector);
31087 - else if (m && atomic_read(&m->error_count))
31088 + else if (m && atomic_read_unchecked(&m->error_count))
31089 m = NULL;
31090
31091 if (likely(m))
31092 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
31093 }
31094
31095 ms->mirror[mirror].ms = ms;
31096 - atomic_set(&(ms->mirror[mirror].error_count), 0);
31097 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31098 ms->mirror[mirror].error_type = 0;
31099 ms->mirror[mirror].offset = offset;
31100
31101 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
31102 */
31103 static char device_status_char(struct mirror *m)
31104 {
31105 - if (!atomic_read(&(m->error_count)))
31106 + if (!atomic_read_unchecked(&(m->error_count)))
31107 return 'A';
31108
31109 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31110 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
31111 index 3d80cf0..b77cc47 100644
31112 --- a/drivers/md/dm-stripe.c
31113 +++ b/drivers/md/dm-stripe.c
31114 @@ -20,7 +20,7 @@ struct stripe {
31115 struct dm_dev *dev;
31116 sector_t physical_start;
31117
31118 - atomic_t error_count;
31119 + atomic_unchecked_t error_count;
31120 };
31121
31122 struct stripe_c {
31123 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
31124 kfree(sc);
31125 return r;
31126 }
31127 - atomic_set(&(sc->stripe[i].error_count), 0);
31128 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
31129 }
31130
31131 ti->private = sc;
31132 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
31133 DMEMIT("%d ", sc->stripes);
31134 for (i = 0; i < sc->stripes; i++) {
31135 DMEMIT("%s ", sc->stripe[i].dev->name);
31136 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
31137 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
31138 'D' : 'A';
31139 }
31140 buffer[i] = '\0';
31141 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
31142 */
31143 for (i = 0; i < sc->stripes; i++)
31144 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
31145 - atomic_inc(&(sc->stripe[i].error_count));
31146 - if (atomic_read(&(sc->stripe[i].error_count)) <
31147 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
31148 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
31149 DM_IO_ERROR_THRESHOLD)
31150 schedule_work(&sc->trigger_event);
31151 }
31152 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
31153 index 8e91321..fd17aef 100644
31154 --- a/drivers/md/dm-table.c
31155 +++ b/drivers/md/dm-table.c
31156 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
31157 if (!dev_size)
31158 return 0;
31159
31160 - if ((start >= dev_size) || (start + len > dev_size)) {
31161 + if ((start >= dev_size) || (len > dev_size - start)) {
31162 DMWARN("%s: %s too small for target: "
31163 "start=%llu, len=%llu, dev_size=%llu",
31164 dm_device_name(ti->table->md), bdevname(bdev, b),
31165 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
31166 index 59c4f04..4c7b661 100644
31167 --- a/drivers/md/dm-thin-metadata.c
31168 +++ b/drivers/md/dm-thin-metadata.c
31169 @@ -431,7 +431,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
31170
31171 pmd->info.tm = tm;
31172 pmd->info.levels = 2;
31173 - pmd->info.value_type.context = pmd->data_sm;
31174 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
31175 pmd->info.value_type.size = sizeof(__le64);
31176 pmd->info.value_type.inc = data_block_inc;
31177 pmd->info.value_type.dec = data_block_dec;
31178 @@ -450,7 +450,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
31179
31180 pmd->bl_info.tm = tm;
31181 pmd->bl_info.levels = 1;
31182 - pmd->bl_info.value_type.context = pmd->data_sm;
31183 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
31184 pmd->bl_info.value_type.size = sizeof(__le64);
31185 pmd->bl_info.value_type.inc = data_block_inc;
31186 pmd->bl_info.value_type.dec = data_block_dec;
31187 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
31188 index 4720f68..78d1df7 100644
31189 --- a/drivers/md/dm.c
31190 +++ b/drivers/md/dm.c
31191 @@ -177,9 +177,9 @@ struct mapped_device {
31192 /*
31193 * Event handling.
31194 */
31195 - atomic_t event_nr;
31196 + atomic_unchecked_t event_nr;
31197 wait_queue_head_t eventq;
31198 - atomic_t uevent_seq;
31199 + atomic_unchecked_t uevent_seq;
31200 struct list_head uevent_list;
31201 spinlock_t uevent_lock; /* Protect access to uevent_list */
31202
31203 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
31204 rwlock_init(&md->map_lock);
31205 atomic_set(&md->holders, 1);
31206 atomic_set(&md->open_count, 0);
31207 - atomic_set(&md->event_nr, 0);
31208 - atomic_set(&md->uevent_seq, 0);
31209 + atomic_set_unchecked(&md->event_nr, 0);
31210 + atomic_set_unchecked(&md->uevent_seq, 0);
31211 INIT_LIST_HEAD(&md->uevent_list);
31212 spin_lock_init(&md->uevent_lock);
31213
31214 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
31215
31216 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31217
31218 - atomic_inc(&md->event_nr);
31219 + atomic_inc_unchecked(&md->event_nr);
31220 wake_up(&md->eventq);
31221 }
31222
31223 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
31224
31225 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31226 {
31227 - return atomic_add_return(1, &md->uevent_seq);
31228 + return atomic_add_return_unchecked(1, &md->uevent_seq);
31229 }
31230
31231 uint32_t dm_get_event_nr(struct mapped_device *md)
31232 {
31233 - return atomic_read(&md->event_nr);
31234 + return atomic_read_unchecked(&md->event_nr);
31235 }
31236
31237 int dm_wait_event(struct mapped_device *md, int event_nr)
31238 {
31239 return wait_event_interruptible(md->eventq,
31240 - (event_nr != atomic_read(&md->event_nr)));
31241 + (event_nr != atomic_read_unchecked(&md->event_nr)));
31242 }
31243
31244 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31245 diff --git a/drivers/md/md.c b/drivers/md/md.c
31246 index f47f1f8..b7f559e 100644
31247 --- a/drivers/md/md.c
31248 +++ b/drivers/md/md.c
31249 @@ -278,10 +278,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
31250 * start build, activate spare
31251 */
31252 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
31253 -static atomic_t md_event_count;
31254 +static atomic_unchecked_t md_event_count;
31255 void md_new_event(struct mddev *mddev)
31256 {
31257 - atomic_inc(&md_event_count);
31258 + atomic_inc_unchecked(&md_event_count);
31259 wake_up(&md_event_waiters);
31260 }
31261 EXPORT_SYMBOL_GPL(md_new_event);
31262 @@ -291,7 +291,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
31263 */
31264 static void md_new_event_inintr(struct mddev *mddev)
31265 {
31266 - atomic_inc(&md_event_count);
31267 + atomic_inc_unchecked(&md_event_count);
31268 wake_up(&md_event_waiters);
31269 }
31270
31271 @@ -1525,7 +1525,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
31272
31273 rdev->preferred_minor = 0xffff;
31274 rdev->data_offset = le64_to_cpu(sb->data_offset);
31275 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31276 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31277
31278 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
31279 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
31280 @@ -1742,7 +1742,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
31281 else
31282 sb->resync_offset = cpu_to_le64(0);
31283
31284 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
31285 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
31286
31287 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
31288 sb->size = cpu_to_le64(mddev->dev_sectors);
31289 @@ -2639,7 +2639,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
31290 static ssize_t
31291 errors_show(struct md_rdev *rdev, char *page)
31292 {
31293 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
31294 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
31295 }
31296
31297 static ssize_t
31298 @@ -2648,7 +2648,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
31299 char *e;
31300 unsigned long n = simple_strtoul(buf, &e, 10);
31301 if (*buf && (*e == 0 || *e == '\n')) {
31302 - atomic_set(&rdev->corrected_errors, n);
31303 + atomic_set_unchecked(&rdev->corrected_errors, n);
31304 return len;
31305 }
31306 return -EINVAL;
31307 @@ -3039,8 +3039,8 @@ int md_rdev_init(struct md_rdev *rdev)
31308 rdev->sb_loaded = 0;
31309 rdev->bb_page = NULL;
31310 atomic_set(&rdev->nr_pending, 0);
31311 - atomic_set(&rdev->read_errors, 0);
31312 - atomic_set(&rdev->corrected_errors, 0);
31313 + atomic_set_unchecked(&rdev->read_errors, 0);
31314 + atomic_set_unchecked(&rdev->corrected_errors, 0);
31315
31316 INIT_LIST_HEAD(&rdev->same_set);
31317 init_waitqueue_head(&rdev->blocked_wait);
31318 @@ -6683,7 +6683,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31319
31320 spin_unlock(&pers_lock);
31321 seq_printf(seq, "\n");
31322 - seq->poll_event = atomic_read(&md_event_count);
31323 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31324 return 0;
31325 }
31326 if (v == (void*)2) {
31327 @@ -6772,7 +6772,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31328 chunk_kb ? "KB" : "B");
31329 if (bitmap->file) {
31330 seq_printf(seq, ", file: ");
31331 - seq_path(seq, &bitmap->file->f_path, " \t\n");
31332 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
31333 }
31334
31335 seq_printf(seq, "\n");
31336 @@ -6803,7 +6803,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
31337 return error;
31338
31339 seq = file->private_data;
31340 - seq->poll_event = atomic_read(&md_event_count);
31341 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31342 return error;
31343 }
31344
31345 @@ -6817,7 +6817,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
31346 /* always allow read */
31347 mask = POLLIN | POLLRDNORM;
31348
31349 - if (seq->poll_event != atomic_read(&md_event_count))
31350 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
31351 mask |= POLLERR | POLLPRI;
31352 return mask;
31353 }
31354 @@ -6861,7 +6861,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
31355 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
31356 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
31357 (int)part_stat_read(&disk->part0, sectors[1]) -
31358 - atomic_read(&disk->sync_io);
31359 + atomic_read_unchecked(&disk->sync_io);
31360 /* sync IO will cause sync_io to increase before the disk_stats
31361 * as sync_io is counted when a request starts, and
31362 * disk_stats is counted when it completes.
31363 diff --git a/drivers/md/md.h b/drivers/md/md.h
31364 index cf742d9..7c7c745 100644
31365 --- a/drivers/md/md.h
31366 +++ b/drivers/md/md.h
31367 @@ -120,13 +120,13 @@ struct md_rdev {
31368 * only maintained for arrays that
31369 * support hot removal
31370 */
31371 - atomic_t read_errors; /* number of consecutive read errors that
31372 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
31373 * we have tried to ignore.
31374 */
31375 struct timespec last_read_error; /* monotonic time since our
31376 * last read error
31377 */
31378 - atomic_t corrected_errors; /* number of corrected read errors,
31379 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
31380 * for reporting to userspace and storing
31381 * in superblock.
31382 */
31383 @@ -410,7 +410,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
31384
31385 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
31386 {
31387 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31388 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31389 }
31390
31391 struct md_personality
31392 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
31393 index 50ed53b..4f29d7d 100644
31394 --- a/drivers/md/persistent-data/dm-space-map-checker.c
31395 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
31396 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
31397 /*----------------------------------------------------------------*/
31398
31399 struct sm_checker {
31400 - struct dm_space_map sm;
31401 + dm_space_map_no_const sm;
31402
31403 struct count_array old_counts;
31404 struct count_array counts;
31405 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
31406 index fc469ba..2d91555 100644
31407 --- a/drivers/md/persistent-data/dm-space-map-disk.c
31408 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
31409 @@ -23,7 +23,7 @@
31410 * Space map interface.
31411 */
31412 struct sm_disk {
31413 - struct dm_space_map sm;
31414 + dm_space_map_no_const sm;
31415
31416 struct ll_disk ll;
31417 struct ll_disk old_ll;
31418 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
31419 index e89ae5e..062e4c2 100644
31420 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
31421 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
31422 @@ -43,7 +43,7 @@ struct block_op {
31423 };
31424
31425 struct sm_metadata {
31426 - struct dm_space_map sm;
31427 + dm_space_map_no_const sm;
31428
31429 struct ll_disk ll;
31430 struct ll_disk old_ll;
31431 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
31432 index 1cbfc6b..56e1dbb 100644
31433 --- a/drivers/md/persistent-data/dm-space-map.h
31434 +++ b/drivers/md/persistent-data/dm-space-map.h
31435 @@ -60,6 +60,7 @@ struct dm_space_map {
31436 int (*root_size)(struct dm_space_map *sm, size_t *result);
31437 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
31438 };
31439 +typedef struct dm_space_map __no_const dm_space_map_no_const;
31440
31441 /*----------------------------------------------------------------*/
31442
31443 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
31444 index ede2461..9c4c691 100644
31445 --- a/drivers/md/raid1.c
31446 +++ b/drivers/md/raid1.c
31447 @@ -1559,7 +1559,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
31448 if (r1_sync_page_io(rdev, sect, s,
31449 bio->bi_io_vec[idx].bv_page,
31450 READ) != 0)
31451 - atomic_add(s, &rdev->corrected_errors);
31452 + atomic_add_unchecked(s, &rdev->corrected_errors);
31453 }
31454 sectors -= s;
31455 sect += s;
31456 @@ -1772,7 +1772,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
31457 test_bit(In_sync, &rdev->flags)) {
31458 if (r1_sync_page_io(rdev, sect, s,
31459 conf->tmppage, READ)) {
31460 - atomic_add(s, &rdev->corrected_errors);
31461 + atomic_add_unchecked(s, &rdev->corrected_errors);
31462 printk(KERN_INFO
31463 "md/raid1:%s: read error corrected "
31464 "(%d sectors at %llu on %s)\n",
31465 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
31466 index 685ddf3..955b087 100644
31467 --- a/drivers/md/raid10.c
31468 +++ b/drivers/md/raid10.c
31469 @@ -1440,7 +1440,7 @@ static void end_sync_read(struct bio *bio, int error)
31470 /* The write handler will notice the lack of
31471 * R10BIO_Uptodate and record any errors etc
31472 */
31473 - atomic_add(r10_bio->sectors,
31474 + atomic_add_unchecked(r10_bio->sectors,
31475 &conf->mirrors[d].rdev->corrected_errors);
31476
31477 /* for reconstruct, we always reschedule after a read.
31478 @@ -1740,7 +1740,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
31479 {
31480 struct timespec cur_time_mon;
31481 unsigned long hours_since_last;
31482 - unsigned int read_errors = atomic_read(&rdev->read_errors);
31483 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
31484
31485 ktime_get_ts(&cur_time_mon);
31486
31487 @@ -1762,9 +1762,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
31488 * overflowing the shift of read_errors by hours_since_last.
31489 */
31490 if (hours_since_last >= 8 * sizeof(read_errors))
31491 - atomic_set(&rdev->read_errors, 0);
31492 + atomic_set_unchecked(&rdev->read_errors, 0);
31493 else
31494 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
31495 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
31496 }
31497
31498 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
31499 @@ -1814,8 +1814,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31500 return;
31501
31502 check_decay_read_errors(mddev, rdev);
31503 - atomic_inc(&rdev->read_errors);
31504 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
31505 + atomic_inc_unchecked(&rdev->read_errors);
31506 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
31507 char b[BDEVNAME_SIZE];
31508 bdevname(rdev->bdev, b);
31509
31510 @@ -1823,7 +1823,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31511 "md/raid10:%s: %s: Raid device exceeded "
31512 "read_error threshold [cur %d:max %d]\n",
31513 mdname(mddev), b,
31514 - atomic_read(&rdev->read_errors), max_read_errors);
31515 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
31516 printk(KERN_NOTICE
31517 "md/raid10:%s: %s: Failing raid device\n",
31518 mdname(mddev), b);
31519 @@ -1968,7 +1968,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31520 (unsigned long long)(
31521 sect + rdev->data_offset),
31522 bdevname(rdev->bdev, b));
31523 - atomic_add(s, &rdev->corrected_errors);
31524 + atomic_add_unchecked(s, &rdev->corrected_errors);
31525 }
31526
31527 rdev_dec_pending(rdev, mddev);
31528 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
31529 index 858fdbb..b2dac95 100644
31530 --- a/drivers/md/raid5.c
31531 +++ b/drivers/md/raid5.c
31532 @@ -1610,19 +1610,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
31533 (unsigned long long)(sh->sector
31534 + rdev->data_offset),
31535 bdevname(rdev->bdev, b));
31536 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
31537 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
31538 clear_bit(R5_ReadError, &sh->dev[i].flags);
31539 clear_bit(R5_ReWrite, &sh->dev[i].flags);
31540 }
31541 - if (atomic_read(&conf->disks[i].rdev->read_errors))
31542 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
31543 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
31544 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
31545 } else {
31546 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
31547 int retry = 0;
31548 rdev = conf->disks[i].rdev;
31549
31550 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
31551 - atomic_inc(&rdev->read_errors);
31552 + atomic_inc_unchecked(&rdev->read_errors);
31553 if (conf->mddev->degraded >= conf->max_degraded)
31554 printk_ratelimited(
31555 KERN_WARNING
31556 @@ -1642,7 +1642,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
31557 (unsigned long long)(sh->sector
31558 + rdev->data_offset),
31559 bdn);
31560 - else if (atomic_read(&rdev->read_errors)
31561 + else if (atomic_read_unchecked(&rdev->read_errors)
31562 > conf->max_nr_stripes)
31563 printk(KERN_WARNING
31564 "md/raid:%s: Too many read errors, failing device %s.\n",
31565 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
31566 index ba9a643..e474ab5 100644
31567 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
31568 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
31569 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
31570 .subvendor = _subvend, .subdevice = _subdev, \
31571 .driver_data = (unsigned long)&_driverdata }
31572
31573 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
31574 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
31575 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
31576 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
31577 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
31578 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
31579 index a7d876f..8c21b61 100644
31580 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
31581 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
31582 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
31583 union {
31584 dmx_ts_cb ts;
31585 dmx_section_cb sec;
31586 - } cb;
31587 + } __no_const cb;
31588
31589 struct dvb_demux *demux;
31590 void *priv;
31591 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
31592 index f732877..d38c35a 100644
31593 --- a/drivers/media/dvb/dvb-core/dvbdev.c
31594 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
31595 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
31596 const struct dvb_device *template, void *priv, int type)
31597 {
31598 struct dvb_device *dvbdev;
31599 - struct file_operations *dvbdevfops;
31600 + file_operations_no_const *dvbdevfops;
31601 struct device *clsdev;
31602 int minor;
31603 int id;
31604 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
31605 index 9f2a02c..5920f88 100644
31606 --- a/drivers/media/dvb/dvb-usb/cxusb.c
31607 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
31608 @@ -1069,7 +1069,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
31609 struct dib0700_adapter_state {
31610 int (*set_param_save) (struct dvb_frontend *,
31611 struct dvb_frontend_parameters *);
31612 -};
31613 +} __no_const;
31614
31615 static int dib7070_set_param_override(struct dvb_frontend *fe,
31616 struct dvb_frontend_parameters *fep)
31617 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
31618 index f103ec1..5e8968b 100644
31619 --- a/drivers/media/dvb/dvb-usb/dw2102.c
31620 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
31621 @@ -95,7 +95,7 @@ struct su3000_state {
31622
31623 struct s6x0_state {
31624 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
31625 -};
31626 +} __no_const;
31627
31628 /* debug */
31629 static int dvb_usb_dw2102_debug;
31630 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
31631 index 404f63a..4796533 100644
31632 --- a/drivers/media/dvb/frontends/dib3000.h
31633 +++ b/drivers/media/dvb/frontends/dib3000.h
31634 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
31635 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
31636 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
31637 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
31638 -};
31639 +} __no_const;
31640
31641 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
31642 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
31643 diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
31644 index 90bf573..e8463da 100644
31645 --- a/drivers/media/dvb/frontends/ds3000.c
31646 +++ b/drivers/media/dvb/frontends/ds3000.c
31647 @@ -1210,7 +1210,7 @@ static int ds3000_set_frontend(struct dvb_frontend *fe,
31648
31649 for (i = 0; i < 30 ; i++) {
31650 ds3000_read_status(fe, &status);
31651 - if (status && FE_HAS_LOCK)
31652 + if (status & FE_HAS_LOCK)
31653 break;
31654
31655 msleep(10);
31656 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
31657 index 0564192..75b16f5 100644
31658 --- a/drivers/media/dvb/ngene/ngene-cards.c
31659 +++ b/drivers/media/dvb/ngene/ngene-cards.c
31660 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
31661
31662 /****************************************************************************/
31663
31664 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
31665 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
31666 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
31667 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
31668 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
31669 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
31670 index 16a089f..ab1667d 100644
31671 --- a/drivers/media/radio/radio-cadet.c
31672 +++ b/drivers/media/radio/radio-cadet.c
31673 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
31674 unsigned char readbuf[RDS_BUFFER];
31675 int i = 0;
31676
31677 + if (count > RDS_BUFFER)
31678 + return -EFAULT;
31679 mutex_lock(&dev->lock);
31680 if (dev->rdsstat == 0) {
31681 dev->rdsstat = 1;
31682 diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
31683 index 61287fc..8b08712 100644
31684 --- a/drivers/media/rc/redrat3.c
31685 +++ b/drivers/media/rc/redrat3.c
31686 @@ -905,7 +905,7 @@ static int redrat3_set_tx_carrier(struct rc_dev *dev, u32 carrier)
31687 return carrier;
31688 }
31689
31690 -static int redrat3_transmit_ir(struct rc_dev *rcdev, int *txbuf, u32 n)
31691 +static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, u32 n)
31692 {
31693 struct redrat3_dev *rr3 = rcdev->priv;
31694 struct device *dev = rr3->dev;
31695 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
31696 index 9cde353..8c6a1c3 100644
31697 --- a/drivers/media/video/au0828/au0828.h
31698 +++ b/drivers/media/video/au0828/au0828.h
31699 @@ -191,7 +191,7 @@ struct au0828_dev {
31700
31701 /* I2C */
31702 struct i2c_adapter i2c_adap;
31703 - struct i2c_algorithm i2c_algo;
31704 + i2c_algorithm_no_const i2c_algo;
31705 struct i2c_client i2c_client;
31706 u32 i2c_rc;
31707
31708 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
31709 index 68d1240..46b32eb 100644
31710 --- a/drivers/media/video/cx88/cx88-alsa.c
31711 +++ b/drivers/media/video/cx88/cx88-alsa.c
31712 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
31713 * Only boards with eeprom and byte 1 at eeprom=1 have it
31714 */
31715
31716 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
31717 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
31718 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
31719 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
31720 {0, }
31721 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31722 index 305e6aa..0143317 100644
31723 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31724 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31725 @@ -196,7 +196,7 @@ struct pvr2_hdw {
31726
31727 /* I2C stuff */
31728 struct i2c_adapter i2c_adap;
31729 - struct i2c_algorithm i2c_algo;
31730 + i2c_algorithm_no_const i2c_algo;
31731 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
31732 int i2c_cx25840_hack_state;
31733 int i2c_linked;
31734 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
31735 index a0895bf..b7ebb1b 100644
31736 --- a/drivers/media/video/timblogiw.c
31737 +++ b/drivers/media/video/timblogiw.c
31738 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
31739
31740 /* Platform device functions */
31741
31742 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
31743 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
31744 .vidioc_querycap = timblogiw_querycap,
31745 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
31746 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
31747 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
31748 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
31749 };
31750
31751 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
31752 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
31753 .owner = THIS_MODULE,
31754 .open = timblogiw_open,
31755 .release = timblogiw_close,
31756 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
31757 index e9c6a60..daf6a33 100644
31758 --- a/drivers/message/fusion/mptbase.c
31759 +++ b/drivers/message/fusion/mptbase.c
31760 @@ -6753,8 +6753,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
31761 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
31762 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
31763
31764 +#ifdef CONFIG_GRKERNSEC_HIDESYM
31765 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
31766 +#else
31767 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
31768 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
31769 +#endif
31770 +
31771 /*
31772 * Rounding UP to nearest 4-kB boundary here...
31773 */
31774 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
31775 index 9d95042..b808101 100644
31776 --- a/drivers/message/fusion/mptsas.c
31777 +++ b/drivers/message/fusion/mptsas.c
31778 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
31779 return 0;
31780 }
31781
31782 +static inline void
31783 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
31784 +{
31785 + if (phy_info->port_details) {
31786 + phy_info->port_details->rphy = rphy;
31787 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
31788 + ioc->name, rphy));
31789 + }
31790 +
31791 + if (rphy) {
31792 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
31793 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
31794 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
31795 + ioc->name, rphy, rphy->dev.release));
31796 + }
31797 +}
31798 +
31799 /* no mutex */
31800 static void
31801 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
31802 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
31803 return NULL;
31804 }
31805
31806 -static inline void
31807 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
31808 -{
31809 - if (phy_info->port_details) {
31810 - phy_info->port_details->rphy = rphy;
31811 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
31812 - ioc->name, rphy));
31813 - }
31814 -
31815 - if (rphy) {
31816 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
31817 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
31818 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
31819 - ioc->name, rphy, rphy->dev.release));
31820 - }
31821 -}
31822 -
31823 static inline struct sas_port *
31824 mptsas_get_port(struct mptsas_phyinfo *phy_info)
31825 {
31826 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
31827 index 0c3ced7..1fe34ec 100644
31828 --- a/drivers/message/fusion/mptscsih.c
31829 +++ b/drivers/message/fusion/mptscsih.c
31830 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
31831
31832 h = shost_priv(SChost);
31833
31834 - if (h) {
31835 - if (h->info_kbuf == NULL)
31836 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
31837 - return h->info_kbuf;
31838 - h->info_kbuf[0] = '\0';
31839 + if (!h)
31840 + return NULL;
31841
31842 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
31843 - h->info_kbuf[size-1] = '\0';
31844 - }
31845 + if (h->info_kbuf == NULL)
31846 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
31847 + return h->info_kbuf;
31848 + h->info_kbuf[0] = '\0';
31849 +
31850 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
31851 + h->info_kbuf[size-1] = '\0';
31852
31853 return h->info_kbuf;
31854 }
31855 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
31856 index 07dbeaf..5533142 100644
31857 --- a/drivers/message/i2o/i2o_proc.c
31858 +++ b/drivers/message/i2o/i2o_proc.c
31859 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
31860 "Array Controller Device"
31861 };
31862
31863 -static char *chtostr(u8 * chars, int n)
31864 -{
31865 - char tmp[256];
31866 - tmp[0] = 0;
31867 - return strncat(tmp, (char *)chars, n);
31868 -}
31869 -
31870 static int i2o_report_query_status(struct seq_file *seq, int block_status,
31871 char *group)
31872 {
31873 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
31874
31875 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
31876 seq_printf(seq, "%-#8x", ddm_table.module_id);
31877 - seq_printf(seq, "%-29s",
31878 - chtostr(ddm_table.module_name_version, 28));
31879 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
31880 seq_printf(seq, "%9d ", ddm_table.data_size);
31881 seq_printf(seq, "%8d", ddm_table.code_size);
31882
31883 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
31884
31885 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
31886 seq_printf(seq, "%-#8x", dst->module_id);
31887 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
31888 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
31889 + seq_printf(seq, "%-.28s", dst->module_name_version);
31890 + seq_printf(seq, "%-.8s", dst->date);
31891 seq_printf(seq, "%8d ", dst->module_size);
31892 seq_printf(seq, "%8d ", dst->mpb_size);
31893 seq_printf(seq, "0x%04x", dst->module_flags);
31894 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
31895 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
31896 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
31897 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
31898 - seq_printf(seq, "Vendor info : %s\n",
31899 - chtostr((u8 *) (work32 + 2), 16));
31900 - seq_printf(seq, "Product info : %s\n",
31901 - chtostr((u8 *) (work32 + 6), 16));
31902 - seq_printf(seq, "Description : %s\n",
31903 - chtostr((u8 *) (work32 + 10), 16));
31904 - seq_printf(seq, "Product rev. : %s\n",
31905 - chtostr((u8 *) (work32 + 14), 8));
31906 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
31907 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
31908 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
31909 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
31910
31911 seq_printf(seq, "Serial number : ");
31912 print_serial_number(seq, (u8 *) (work32 + 16),
31913 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
31914 }
31915
31916 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
31917 - seq_printf(seq, "Module name : %s\n",
31918 - chtostr(result.module_name, 24));
31919 - seq_printf(seq, "Module revision : %s\n",
31920 - chtostr(result.module_rev, 8));
31921 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
31922 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
31923
31924 seq_printf(seq, "Serial number : ");
31925 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
31926 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
31927 return 0;
31928 }
31929
31930 - seq_printf(seq, "Device name : %s\n",
31931 - chtostr(result.device_name, 64));
31932 - seq_printf(seq, "Service name : %s\n",
31933 - chtostr(result.service_name, 64));
31934 - seq_printf(seq, "Physical name : %s\n",
31935 - chtostr(result.physical_location, 64));
31936 - seq_printf(seq, "Instance number : %s\n",
31937 - chtostr(result.instance_number, 4));
31938 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
31939 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
31940 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
31941 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
31942
31943 return 0;
31944 }
31945 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
31946 index a8c08f3..155fe3d 100644
31947 --- a/drivers/message/i2o/iop.c
31948 +++ b/drivers/message/i2o/iop.c
31949 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
31950
31951 spin_lock_irqsave(&c->context_list_lock, flags);
31952
31953 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
31954 - atomic_inc(&c->context_list_counter);
31955 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
31956 + atomic_inc_unchecked(&c->context_list_counter);
31957
31958 - entry->context = atomic_read(&c->context_list_counter);
31959 + entry->context = atomic_read_unchecked(&c->context_list_counter);
31960
31961 list_add(&entry->list, &c->context_list);
31962
31963 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
31964
31965 #if BITS_PER_LONG == 64
31966 spin_lock_init(&c->context_list_lock);
31967 - atomic_set(&c->context_list_counter, 0);
31968 + atomic_set_unchecked(&c->context_list_counter, 0);
31969 INIT_LIST_HEAD(&c->context_list);
31970 #endif
31971
31972 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
31973 index 7ce65f4..e66e9bc 100644
31974 --- a/drivers/mfd/abx500-core.c
31975 +++ b/drivers/mfd/abx500-core.c
31976 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
31977
31978 struct abx500_device_entry {
31979 struct list_head list;
31980 - struct abx500_ops ops;
31981 + abx500_ops_no_const ops;
31982 struct device *dev;
31983 };
31984
31985 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
31986 index 5c2a06a..8fa077c 100644
31987 --- a/drivers/mfd/janz-cmodio.c
31988 +++ b/drivers/mfd/janz-cmodio.c
31989 @@ -13,6 +13,7 @@
31990
31991 #include <linux/kernel.h>
31992 #include <linux/module.h>
31993 +#include <linux/slab.h>
31994 #include <linux/init.h>
31995 #include <linux/pci.h>
31996 #include <linux/interrupt.h>
31997 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
31998 index 29d12a7..f900ba4 100644
31999 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
32000 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
32001 @@ -464,7 +464,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
32002 * the lid is closed. This leads to interrupts as soon as a little move
32003 * is done.
32004 */
32005 - atomic_inc(&lis3->count);
32006 + atomic_inc_unchecked(&lis3->count);
32007
32008 wake_up_interruptible(&lis3->misc_wait);
32009 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
32010 @@ -550,7 +550,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
32011 if (lis3->pm_dev)
32012 pm_runtime_get_sync(lis3->pm_dev);
32013
32014 - atomic_set(&lis3->count, 0);
32015 + atomic_set_unchecked(&lis3->count, 0);
32016 return 0;
32017 }
32018
32019 @@ -583,7 +583,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
32020 add_wait_queue(&lis3->misc_wait, &wait);
32021 while (true) {
32022 set_current_state(TASK_INTERRUPTIBLE);
32023 - data = atomic_xchg(&lis3->count, 0);
32024 + data = atomic_xchg_unchecked(&lis3->count, 0);
32025 if (data)
32026 break;
32027
32028 @@ -624,7 +624,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
32029 struct lis3lv02d, miscdev);
32030
32031 poll_wait(file, &lis3->misc_wait, wait);
32032 - if (atomic_read(&lis3->count))
32033 + if (atomic_read_unchecked(&lis3->count))
32034 return POLLIN | POLLRDNORM;
32035 return 0;
32036 }
32037 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
32038 index 2b1482a..5d33616 100644
32039 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
32040 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
32041 @@ -266,7 +266,7 @@ struct lis3lv02d {
32042 struct input_polled_dev *idev; /* input device */
32043 struct platform_device *pdev; /* platform device */
32044 struct regulator_bulk_data regulators[2];
32045 - atomic_t count; /* interrupt count after last read */
32046 + atomic_unchecked_t count; /* interrupt count after last read */
32047 union axis_conversion ac; /* hw -> logical axis */
32048 int mapped_btns[3];
32049
32050 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
32051 index 2f30bad..c4c13d0 100644
32052 --- a/drivers/misc/sgi-gru/gruhandles.c
32053 +++ b/drivers/misc/sgi-gru/gruhandles.c
32054 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
32055 unsigned long nsec;
32056
32057 nsec = CLKS2NSEC(clks);
32058 - atomic_long_inc(&mcs_op_statistics[op].count);
32059 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
32060 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
32061 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
32062 if (mcs_op_statistics[op].max < nsec)
32063 mcs_op_statistics[op].max = nsec;
32064 }
32065 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
32066 index 7768b87..f8aac38 100644
32067 --- a/drivers/misc/sgi-gru/gruprocfs.c
32068 +++ b/drivers/misc/sgi-gru/gruprocfs.c
32069 @@ -32,9 +32,9 @@
32070
32071 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
32072
32073 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
32074 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
32075 {
32076 - unsigned long val = atomic_long_read(v);
32077 + unsigned long val = atomic_long_read_unchecked(v);
32078
32079 seq_printf(s, "%16lu %s\n", val, id);
32080 }
32081 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
32082
32083 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
32084 for (op = 0; op < mcsop_last; op++) {
32085 - count = atomic_long_read(&mcs_op_statistics[op].count);
32086 - total = atomic_long_read(&mcs_op_statistics[op].total);
32087 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
32088 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
32089 max = mcs_op_statistics[op].max;
32090 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
32091 count ? total / count : 0, max);
32092 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
32093 index 5c3ce24..4915ccb 100644
32094 --- a/drivers/misc/sgi-gru/grutables.h
32095 +++ b/drivers/misc/sgi-gru/grutables.h
32096 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
32097 * GRU statistics.
32098 */
32099 struct gru_stats_s {
32100 - atomic_long_t vdata_alloc;
32101 - atomic_long_t vdata_free;
32102 - atomic_long_t gts_alloc;
32103 - atomic_long_t gts_free;
32104 - atomic_long_t gms_alloc;
32105 - atomic_long_t gms_free;
32106 - atomic_long_t gts_double_allocate;
32107 - atomic_long_t assign_context;
32108 - atomic_long_t assign_context_failed;
32109 - atomic_long_t free_context;
32110 - atomic_long_t load_user_context;
32111 - atomic_long_t load_kernel_context;
32112 - atomic_long_t lock_kernel_context;
32113 - atomic_long_t unlock_kernel_context;
32114 - atomic_long_t steal_user_context;
32115 - atomic_long_t steal_kernel_context;
32116 - atomic_long_t steal_context_failed;
32117 - atomic_long_t nopfn;
32118 - atomic_long_t asid_new;
32119 - atomic_long_t asid_next;
32120 - atomic_long_t asid_wrap;
32121 - atomic_long_t asid_reuse;
32122 - atomic_long_t intr;
32123 - atomic_long_t intr_cbr;
32124 - atomic_long_t intr_tfh;
32125 - atomic_long_t intr_spurious;
32126 - atomic_long_t intr_mm_lock_failed;
32127 - atomic_long_t call_os;
32128 - atomic_long_t call_os_wait_queue;
32129 - atomic_long_t user_flush_tlb;
32130 - atomic_long_t user_unload_context;
32131 - atomic_long_t user_exception;
32132 - atomic_long_t set_context_option;
32133 - atomic_long_t check_context_retarget_intr;
32134 - atomic_long_t check_context_unload;
32135 - atomic_long_t tlb_dropin;
32136 - atomic_long_t tlb_preload_page;
32137 - atomic_long_t tlb_dropin_fail_no_asid;
32138 - atomic_long_t tlb_dropin_fail_upm;
32139 - atomic_long_t tlb_dropin_fail_invalid;
32140 - atomic_long_t tlb_dropin_fail_range_active;
32141 - atomic_long_t tlb_dropin_fail_idle;
32142 - atomic_long_t tlb_dropin_fail_fmm;
32143 - atomic_long_t tlb_dropin_fail_no_exception;
32144 - atomic_long_t tfh_stale_on_fault;
32145 - atomic_long_t mmu_invalidate_range;
32146 - atomic_long_t mmu_invalidate_page;
32147 - atomic_long_t flush_tlb;
32148 - atomic_long_t flush_tlb_gru;
32149 - atomic_long_t flush_tlb_gru_tgh;
32150 - atomic_long_t flush_tlb_gru_zero_asid;
32151 + atomic_long_unchecked_t vdata_alloc;
32152 + atomic_long_unchecked_t vdata_free;
32153 + atomic_long_unchecked_t gts_alloc;
32154 + atomic_long_unchecked_t gts_free;
32155 + atomic_long_unchecked_t gms_alloc;
32156 + atomic_long_unchecked_t gms_free;
32157 + atomic_long_unchecked_t gts_double_allocate;
32158 + atomic_long_unchecked_t assign_context;
32159 + atomic_long_unchecked_t assign_context_failed;
32160 + atomic_long_unchecked_t free_context;
32161 + atomic_long_unchecked_t load_user_context;
32162 + atomic_long_unchecked_t load_kernel_context;
32163 + atomic_long_unchecked_t lock_kernel_context;
32164 + atomic_long_unchecked_t unlock_kernel_context;
32165 + atomic_long_unchecked_t steal_user_context;
32166 + atomic_long_unchecked_t steal_kernel_context;
32167 + atomic_long_unchecked_t steal_context_failed;
32168 + atomic_long_unchecked_t nopfn;
32169 + atomic_long_unchecked_t asid_new;
32170 + atomic_long_unchecked_t asid_next;
32171 + atomic_long_unchecked_t asid_wrap;
32172 + atomic_long_unchecked_t asid_reuse;
32173 + atomic_long_unchecked_t intr;
32174 + atomic_long_unchecked_t intr_cbr;
32175 + atomic_long_unchecked_t intr_tfh;
32176 + atomic_long_unchecked_t intr_spurious;
32177 + atomic_long_unchecked_t intr_mm_lock_failed;
32178 + atomic_long_unchecked_t call_os;
32179 + atomic_long_unchecked_t call_os_wait_queue;
32180 + atomic_long_unchecked_t user_flush_tlb;
32181 + atomic_long_unchecked_t user_unload_context;
32182 + atomic_long_unchecked_t user_exception;
32183 + atomic_long_unchecked_t set_context_option;
32184 + atomic_long_unchecked_t check_context_retarget_intr;
32185 + atomic_long_unchecked_t check_context_unload;
32186 + atomic_long_unchecked_t tlb_dropin;
32187 + atomic_long_unchecked_t tlb_preload_page;
32188 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
32189 + atomic_long_unchecked_t tlb_dropin_fail_upm;
32190 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
32191 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
32192 + atomic_long_unchecked_t tlb_dropin_fail_idle;
32193 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
32194 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
32195 + atomic_long_unchecked_t tfh_stale_on_fault;
32196 + atomic_long_unchecked_t mmu_invalidate_range;
32197 + atomic_long_unchecked_t mmu_invalidate_page;
32198 + atomic_long_unchecked_t flush_tlb;
32199 + atomic_long_unchecked_t flush_tlb_gru;
32200 + atomic_long_unchecked_t flush_tlb_gru_tgh;
32201 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
32202
32203 - atomic_long_t copy_gpa;
32204 - atomic_long_t read_gpa;
32205 + atomic_long_unchecked_t copy_gpa;
32206 + atomic_long_unchecked_t read_gpa;
32207
32208 - atomic_long_t mesq_receive;
32209 - atomic_long_t mesq_receive_none;
32210 - atomic_long_t mesq_send;
32211 - atomic_long_t mesq_send_failed;
32212 - atomic_long_t mesq_noop;
32213 - atomic_long_t mesq_send_unexpected_error;
32214 - atomic_long_t mesq_send_lb_overflow;
32215 - atomic_long_t mesq_send_qlimit_reached;
32216 - atomic_long_t mesq_send_amo_nacked;
32217 - atomic_long_t mesq_send_put_nacked;
32218 - atomic_long_t mesq_page_overflow;
32219 - atomic_long_t mesq_qf_locked;
32220 - atomic_long_t mesq_qf_noop_not_full;
32221 - atomic_long_t mesq_qf_switch_head_failed;
32222 - atomic_long_t mesq_qf_unexpected_error;
32223 - atomic_long_t mesq_noop_unexpected_error;
32224 - atomic_long_t mesq_noop_lb_overflow;
32225 - atomic_long_t mesq_noop_qlimit_reached;
32226 - atomic_long_t mesq_noop_amo_nacked;
32227 - atomic_long_t mesq_noop_put_nacked;
32228 - atomic_long_t mesq_noop_page_overflow;
32229 + atomic_long_unchecked_t mesq_receive;
32230 + atomic_long_unchecked_t mesq_receive_none;
32231 + atomic_long_unchecked_t mesq_send;
32232 + atomic_long_unchecked_t mesq_send_failed;
32233 + atomic_long_unchecked_t mesq_noop;
32234 + atomic_long_unchecked_t mesq_send_unexpected_error;
32235 + atomic_long_unchecked_t mesq_send_lb_overflow;
32236 + atomic_long_unchecked_t mesq_send_qlimit_reached;
32237 + atomic_long_unchecked_t mesq_send_amo_nacked;
32238 + atomic_long_unchecked_t mesq_send_put_nacked;
32239 + atomic_long_unchecked_t mesq_page_overflow;
32240 + atomic_long_unchecked_t mesq_qf_locked;
32241 + atomic_long_unchecked_t mesq_qf_noop_not_full;
32242 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
32243 + atomic_long_unchecked_t mesq_qf_unexpected_error;
32244 + atomic_long_unchecked_t mesq_noop_unexpected_error;
32245 + atomic_long_unchecked_t mesq_noop_lb_overflow;
32246 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
32247 + atomic_long_unchecked_t mesq_noop_amo_nacked;
32248 + atomic_long_unchecked_t mesq_noop_put_nacked;
32249 + atomic_long_unchecked_t mesq_noop_page_overflow;
32250
32251 };
32252
32253 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
32254 tghop_invalidate, mcsop_last};
32255
32256 struct mcs_op_statistic {
32257 - atomic_long_t count;
32258 - atomic_long_t total;
32259 + atomic_long_unchecked_t count;
32260 + atomic_long_unchecked_t total;
32261 unsigned long max;
32262 };
32263
32264 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
32265
32266 #define STAT(id) do { \
32267 if (gru_options & OPT_STATS) \
32268 - atomic_long_inc(&gru_stats.id); \
32269 + atomic_long_inc_unchecked(&gru_stats.id); \
32270 } while (0)
32271
32272 #ifdef CONFIG_SGI_GRU_DEBUG
32273 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
32274 index 851b2f2..a4ec097 100644
32275 --- a/drivers/misc/sgi-xp/xp.h
32276 +++ b/drivers/misc/sgi-xp/xp.h
32277 @@ -289,7 +289,7 @@ struct xpc_interface {
32278 xpc_notify_func, void *);
32279 void (*received) (short, int, void *);
32280 enum xp_retval (*partid_to_nasids) (short, void *);
32281 -};
32282 +} __no_const;
32283
32284 extern struct xpc_interface xpc_interface;
32285
32286 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
32287 index b94d5f7..7f494c5 100644
32288 --- a/drivers/misc/sgi-xp/xpc.h
32289 +++ b/drivers/misc/sgi-xp/xpc.h
32290 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
32291 void (*received_payload) (struct xpc_channel *, void *);
32292 void (*notify_senders_of_disconnect) (struct xpc_channel *);
32293 };
32294 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
32295
32296 /* struct xpc_partition act_state values (for XPC HB) */
32297
32298 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
32299 /* found in xpc_main.c */
32300 extern struct device *xpc_part;
32301 extern struct device *xpc_chan;
32302 -extern struct xpc_arch_operations xpc_arch_ops;
32303 +extern xpc_arch_operations_no_const xpc_arch_ops;
32304 extern int xpc_disengage_timelimit;
32305 extern int xpc_disengage_timedout;
32306 extern int xpc_activate_IRQ_rcvd;
32307 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
32308 index 8d082b4..aa749ae 100644
32309 --- a/drivers/misc/sgi-xp/xpc_main.c
32310 +++ b/drivers/misc/sgi-xp/xpc_main.c
32311 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
32312 .notifier_call = xpc_system_die,
32313 };
32314
32315 -struct xpc_arch_operations xpc_arch_ops;
32316 +xpc_arch_operations_no_const xpc_arch_ops;
32317
32318 /*
32319 * Timer function to enforce the timelimit on the partition disengage.
32320 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
32321 index 6878a94..fe5c5f1 100644
32322 --- a/drivers/mmc/host/sdhci-pci.c
32323 +++ b/drivers/mmc/host/sdhci-pci.c
32324 @@ -673,7 +673,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
32325 .probe = via_probe,
32326 };
32327
32328 -static const struct pci_device_id pci_ids[] __devinitdata = {
32329 +static const struct pci_device_id pci_ids[] __devinitconst = {
32330 {
32331 .vendor = PCI_VENDOR_ID_RICOH,
32332 .device = PCI_DEVICE_ID_RICOH_R5C822,
32333 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
32334 index e9fad91..0a7a16a 100644
32335 --- a/drivers/mtd/devices/doc2000.c
32336 +++ b/drivers/mtd/devices/doc2000.c
32337 @@ -773,7 +773,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
32338
32339 /* The ECC will not be calculated correctly if less than 512 is written */
32340 /* DBB-
32341 - if (len != 0x200 && eccbuf)
32342 + if (len != 0x200)
32343 printk(KERN_WARNING
32344 "ECC needs a full sector write (adr: %lx size %lx)\n",
32345 (long) to, (long) len);
32346 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
32347 index a3f7a27..234016e 100644
32348 --- a/drivers/mtd/devices/doc2001.c
32349 +++ b/drivers/mtd/devices/doc2001.c
32350 @@ -392,7 +392,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
32351 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
32352
32353 /* Don't allow read past end of device */
32354 - if (from >= this->totlen)
32355 + if (from >= this->totlen || !len)
32356 return -EINVAL;
32357
32358 /* Don't allow a single read to cross a 512-byte block boundary */
32359 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
32360 index 3984d48..28aa897 100644
32361 --- a/drivers/mtd/nand/denali.c
32362 +++ b/drivers/mtd/nand/denali.c
32363 @@ -26,6 +26,7 @@
32364 #include <linux/pci.h>
32365 #include <linux/mtd/mtd.h>
32366 #include <linux/module.h>
32367 +#include <linux/slab.h>
32368
32369 #include "denali.h"
32370
32371 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
32372 index ac40925..483b753 100644
32373 --- a/drivers/mtd/nftlmount.c
32374 +++ b/drivers/mtd/nftlmount.c
32375 @@ -24,6 +24,7 @@
32376 #include <asm/errno.h>
32377 #include <linux/delay.h>
32378 #include <linux/slab.h>
32379 +#include <linux/sched.h>
32380 #include <linux/mtd/mtd.h>
32381 #include <linux/mtd/nand.h>
32382 #include <linux/mtd/nftl.h>
32383 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
32384 index 6c3fb5a..c542a81 100644
32385 --- a/drivers/mtd/ubi/build.c
32386 +++ b/drivers/mtd/ubi/build.c
32387 @@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
32388 static int __init bytes_str_to_int(const char *str)
32389 {
32390 char *endp;
32391 - unsigned long result;
32392 + unsigned long result, scale = 1;
32393
32394 result = simple_strtoul(str, &endp, 0);
32395 if (str == endp || result >= INT_MAX) {
32396 @@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
32397
32398 switch (*endp) {
32399 case 'G':
32400 - result *= 1024;
32401 + scale *= 1024;
32402 case 'M':
32403 - result *= 1024;
32404 + scale *= 1024;
32405 case 'K':
32406 - result *= 1024;
32407 + scale *= 1024;
32408 if (endp[1] == 'i' && endp[2] == 'B')
32409 endp += 2;
32410 case '\0':
32411 @@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
32412 return -EINVAL;
32413 }
32414
32415 - return result;
32416 + if ((intoverflow_t)result*scale >= INT_MAX) {
32417 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
32418 + str);
32419 + return -EINVAL;
32420 + }
32421 +
32422 + return result*scale;
32423 }
32424
32425 /**
32426 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
32427 index 1feae59..c2a61d2 100644
32428 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
32429 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
32430 @@ -2857,7 +2857,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
32431 */
32432
32433 #define ATL2_PARAM(X, desc) \
32434 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
32435 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
32436 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
32437 MODULE_PARM_DESC(X, desc);
32438 #else
32439 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32440 index 9a517c2..a50cfcb 100644
32441 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32442 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32443 @@ -449,7 +449,7 @@ struct bnx2x_rx_mode_obj {
32444
32445 int (*wait_comp)(struct bnx2x *bp,
32446 struct bnx2x_rx_mode_ramrod_params *p);
32447 -};
32448 +} __no_const;
32449
32450 /********************** Set multicast group ***********************************/
32451
32452 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
32453 index 94b4bd0..73c02de 100644
32454 --- a/drivers/net/ethernet/broadcom/tg3.h
32455 +++ b/drivers/net/ethernet/broadcom/tg3.h
32456 @@ -134,6 +134,7 @@
32457 #define CHIPREV_ID_5750_A0 0x4000
32458 #define CHIPREV_ID_5750_A1 0x4001
32459 #define CHIPREV_ID_5750_A3 0x4003
32460 +#define CHIPREV_ID_5750_C1 0x4201
32461 #define CHIPREV_ID_5750_C2 0x4202
32462 #define CHIPREV_ID_5752_A0_HW 0x5000
32463 #define CHIPREV_ID_5752_A0 0x6000
32464 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32465 index c5f5479..2e8c260 100644
32466 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32467 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32468 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
32469 */
32470 struct l2t_skb_cb {
32471 arp_failure_handler_func arp_failure_handler;
32472 -};
32473 +} __no_const;
32474
32475 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
32476
32477 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
32478 index 871bcaa..4043505 100644
32479 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
32480 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
32481 @@ -5397,7 +5397,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
32482 for (i=0; i<ETH_ALEN; i++) {
32483 tmp.addr[i] = dev->dev_addr[i];
32484 }
32485 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
32486 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
32487 break;
32488
32489 case DE4X5_SET_HWADDR: /* Set the hardware address */
32490 @@ -5437,7 +5437,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
32491 spin_lock_irqsave(&lp->lock, flags);
32492 memcpy(&statbuf, &lp->pktStats, ioc->len);
32493 spin_unlock_irqrestore(&lp->lock, flags);
32494 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
32495 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
32496 return -EFAULT;
32497 break;
32498 }
32499 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
32500 index 14d5b61..1398636 100644
32501 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
32502 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
32503 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
32504 {NULL}};
32505
32506
32507 -static const char *block_name[] __devinitdata = {
32508 +static const char *block_name[] __devinitconst = {
32509 "21140 non-MII",
32510 "21140 MII PHY",
32511 "21142 Serial PHY",
32512 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
32513 index 4d01219..b58d26d 100644
32514 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
32515 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
32516 @@ -236,7 +236,7 @@ struct pci_id_info {
32517 int drv_flags; /* Driver use, intended as capability flags. */
32518 };
32519
32520 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
32521 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
32522 { /* Sometime a Level-One switch card. */
32523 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
32524 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
32525 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
32526 index dcd7f7a..ecb7fb3 100644
32527 --- a/drivers/net/ethernet/dlink/sundance.c
32528 +++ b/drivers/net/ethernet/dlink/sundance.c
32529 @@ -218,7 +218,7 @@ enum {
32530 struct pci_id_info {
32531 const char *name;
32532 };
32533 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
32534 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
32535 {"D-Link DFE-550TX FAST Ethernet Adapter"},
32536 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
32537 {"D-Link DFE-580TX 4 port Server Adapter"},
32538 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
32539 index bf266a0..e024af7 100644
32540 --- a/drivers/net/ethernet/emulex/benet/be_main.c
32541 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
32542 @@ -397,7 +397,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
32543
32544 if (wrapped)
32545 newacc += 65536;
32546 - ACCESS_ONCE(*acc) = newacc;
32547 + ACCESS_ONCE_RW(*acc) = newacc;
32548 }
32549
32550 void be_parse_stats(struct be_adapter *adapter)
32551 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
32552 index 61d2bdd..7f1154a 100644
32553 --- a/drivers/net/ethernet/fealnx.c
32554 +++ b/drivers/net/ethernet/fealnx.c
32555 @@ -150,7 +150,7 @@ struct chip_info {
32556 int flags;
32557 };
32558
32559 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
32560 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
32561 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
32562 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
32563 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
32564 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32565 index e1159e5..e18684d 100644
32566 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32567 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32568 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
32569 {
32570 struct e1000_hw *hw = &adapter->hw;
32571 struct e1000_mac_info *mac = &hw->mac;
32572 - struct e1000_mac_operations *func = &mac->ops;
32573 + e1000_mac_operations_no_const *func = &mac->ops;
32574
32575 /* Set media type */
32576 switch (adapter->pdev->device) {
32577 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
32578 index a3e65fd..f451444 100644
32579 --- a/drivers/net/ethernet/intel/e1000e/82571.c
32580 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
32581 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
32582 {
32583 struct e1000_hw *hw = &adapter->hw;
32584 struct e1000_mac_info *mac = &hw->mac;
32585 - struct e1000_mac_operations *func = &mac->ops;
32586 + e1000_mac_operations_no_const *func = &mac->ops;
32587 u32 swsm = 0;
32588 u32 swsm2 = 0;
32589 bool force_clear_smbi = false;
32590 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
32591 index 2967039..ca8c40c 100644
32592 --- a/drivers/net/ethernet/intel/e1000e/hw.h
32593 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
32594 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
32595 void (*write_vfta)(struct e1000_hw *, u32, u32);
32596 s32 (*read_mac_addr)(struct e1000_hw *);
32597 };
32598 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32599
32600 /*
32601 * When to use various PHY register access functions:
32602 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
32603 void (*power_up)(struct e1000_hw *);
32604 void (*power_down)(struct e1000_hw *);
32605 };
32606 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
32607
32608 /* Function pointers for the NVM. */
32609 struct e1000_nvm_operations {
32610 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
32611 s32 (*validate)(struct e1000_hw *);
32612 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
32613 };
32614 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
32615
32616 struct e1000_mac_info {
32617 - struct e1000_mac_operations ops;
32618 + e1000_mac_operations_no_const ops;
32619 u8 addr[ETH_ALEN];
32620 u8 perm_addr[ETH_ALEN];
32621
32622 @@ -872,7 +875,7 @@ struct e1000_mac_info {
32623 };
32624
32625 struct e1000_phy_info {
32626 - struct e1000_phy_operations ops;
32627 + e1000_phy_operations_no_const ops;
32628
32629 enum e1000_phy_type type;
32630
32631 @@ -906,7 +909,7 @@ struct e1000_phy_info {
32632 };
32633
32634 struct e1000_nvm_info {
32635 - struct e1000_nvm_operations ops;
32636 + e1000_nvm_operations_no_const ops;
32637
32638 enum e1000_nvm_type type;
32639 enum e1000_nvm_override override;
32640 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
32641 index 4519a13..f97fcd0 100644
32642 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
32643 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
32644 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
32645 s32 (*read_mac_addr)(struct e1000_hw *);
32646 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
32647 };
32648 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32649
32650 struct e1000_phy_operations {
32651 s32 (*acquire)(struct e1000_hw *);
32652 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
32653 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
32654 s32 (*write_reg)(struct e1000_hw *, u32, u16);
32655 };
32656 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
32657
32658 struct e1000_nvm_operations {
32659 s32 (*acquire)(struct e1000_hw *);
32660 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
32661 s32 (*update)(struct e1000_hw *);
32662 s32 (*validate)(struct e1000_hw *);
32663 };
32664 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
32665
32666 struct e1000_info {
32667 s32 (*get_invariants)(struct e1000_hw *);
32668 @@ -350,7 +353,7 @@ struct e1000_info {
32669 extern const struct e1000_info e1000_82575_info;
32670
32671 struct e1000_mac_info {
32672 - struct e1000_mac_operations ops;
32673 + e1000_mac_operations_no_const ops;
32674
32675 u8 addr[6];
32676 u8 perm_addr[6];
32677 @@ -388,7 +391,7 @@ struct e1000_mac_info {
32678 };
32679
32680 struct e1000_phy_info {
32681 - struct e1000_phy_operations ops;
32682 + e1000_phy_operations_no_const ops;
32683
32684 enum e1000_phy_type type;
32685
32686 @@ -423,7 +426,7 @@ struct e1000_phy_info {
32687 };
32688
32689 struct e1000_nvm_info {
32690 - struct e1000_nvm_operations ops;
32691 + e1000_nvm_operations_no_const ops;
32692 enum e1000_nvm_type type;
32693 enum e1000_nvm_override override;
32694
32695 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
32696 s32 (*check_for_ack)(struct e1000_hw *, u16);
32697 s32 (*check_for_rst)(struct e1000_hw *, u16);
32698 };
32699 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
32700
32701 struct e1000_mbx_stats {
32702 u32 msgs_tx;
32703 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
32704 };
32705
32706 struct e1000_mbx_info {
32707 - struct e1000_mbx_operations ops;
32708 + e1000_mbx_operations_no_const ops;
32709 struct e1000_mbx_stats stats;
32710 u32 timeout;
32711 u32 usec_delay;
32712 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
32713 index d7ed58f..64cde36 100644
32714 --- a/drivers/net/ethernet/intel/igbvf/vf.h
32715 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
32716 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
32717 s32 (*read_mac_addr)(struct e1000_hw *);
32718 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
32719 };
32720 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32721
32722 struct e1000_mac_info {
32723 - struct e1000_mac_operations ops;
32724 + e1000_mac_operations_no_const ops;
32725 u8 addr[6];
32726 u8 perm_addr[6];
32727
32728 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
32729 s32 (*check_for_ack)(struct e1000_hw *);
32730 s32 (*check_for_rst)(struct e1000_hw *);
32731 };
32732 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
32733
32734 struct e1000_mbx_stats {
32735 u32 msgs_tx;
32736 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
32737 };
32738
32739 struct e1000_mbx_info {
32740 - struct e1000_mbx_operations ops;
32741 + e1000_mbx_operations_no_const ops;
32742 struct e1000_mbx_stats stats;
32743 u32 timeout;
32744 u32 usec_delay;
32745 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32746 index 6c5cca8..de8ef63 100644
32747 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32748 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32749 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
32750 s32 (*update_checksum)(struct ixgbe_hw *);
32751 u16 (*calc_checksum)(struct ixgbe_hw *);
32752 };
32753 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
32754
32755 struct ixgbe_mac_operations {
32756 s32 (*init_hw)(struct ixgbe_hw *);
32757 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
32758 /* Manageability interface */
32759 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
32760 };
32761 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
32762
32763 struct ixgbe_phy_operations {
32764 s32 (*identify)(struct ixgbe_hw *);
32765 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
32766 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
32767 s32 (*check_overtemp)(struct ixgbe_hw *);
32768 };
32769 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
32770
32771 struct ixgbe_eeprom_info {
32772 - struct ixgbe_eeprom_operations ops;
32773 + ixgbe_eeprom_operations_no_const ops;
32774 enum ixgbe_eeprom_type type;
32775 u32 semaphore_delay;
32776 u16 word_size;
32777 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
32778
32779 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
32780 struct ixgbe_mac_info {
32781 - struct ixgbe_mac_operations ops;
32782 + ixgbe_mac_operations_no_const ops;
32783 enum ixgbe_mac_type type;
32784 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
32785 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
32786 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
32787 };
32788
32789 struct ixgbe_phy_info {
32790 - struct ixgbe_phy_operations ops;
32791 + ixgbe_phy_operations_no_const ops;
32792 struct mdio_if_info mdio;
32793 enum ixgbe_phy_type type;
32794 u32 id;
32795 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
32796 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
32797 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
32798 };
32799 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
32800
32801 struct ixgbe_mbx_stats {
32802 u32 msgs_tx;
32803 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
32804 };
32805
32806 struct ixgbe_mbx_info {
32807 - struct ixgbe_mbx_operations ops;
32808 + ixgbe_mbx_operations_no_const ops;
32809 struct ixgbe_mbx_stats stats;
32810 u32 timeout;
32811 u32 usec_delay;
32812 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
32813 index 10306b4..28df758 100644
32814 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
32815 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
32816 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
32817 s32 (*clear_vfta)(struct ixgbe_hw *);
32818 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
32819 };
32820 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
32821
32822 enum ixgbe_mac_type {
32823 ixgbe_mac_unknown = 0,
32824 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
32825 };
32826
32827 struct ixgbe_mac_info {
32828 - struct ixgbe_mac_operations ops;
32829 + ixgbe_mac_operations_no_const ops;
32830 u8 addr[6];
32831 u8 perm_addr[6];
32832
32833 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
32834 s32 (*check_for_ack)(struct ixgbe_hw *);
32835 s32 (*check_for_rst)(struct ixgbe_hw *);
32836 };
32837 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
32838
32839 struct ixgbe_mbx_stats {
32840 u32 msgs_tx;
32841 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
32842 };
32843
32844 struct ixgbe_mbx_info {
32845 - struct ixgbe_mbx_operations ops;
32846 + ixgbe_mbx_operations_no_const ops;
32847 struct ixgbe_mbx_stats stats;
32848 u32 timeout;
32849 u32 udelay;
32850 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
32851 index 94bbc85..78c12e6 100644
32852 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
32853 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
32854 @@ -40,6 +40,7 @@
32855 #include <linux/dma-mapping.h>
32856 #include <linux/slab.h>
32857 #include <linux/io-mapping.h>
32858 +#include <linux/sched.h>
32859
32860 #include <linux/mlx4/device.h>
32861 #include <linux/mlx4/doorbell.h>
32862 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
32863 index 5046a64..71ca936 100644
32864 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
32865 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
32866 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
32867 void (*link_down)(struct __vxge_hw_device *devh);
32868 void (*crit_err)(struct __vxge_hw_device *devh,
32869 enum vxge_hw_event type, u64 ext_data);
32870 -};
32871 +} __no_const;
32872
32873 /*
32874 * struct __vxge_hw_blockpool_entry - Block private data structure
32875 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
32876 index 4a518a3..936b334 100644
32877 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
32878 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
32879 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
32880 struct vxge_hw_mempool_dma *dma_object,
32881 u32 index,
32882 u32 is_last);
32883 -};
32884 +} __no_const;
32885
32886 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
32887 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
32888 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
32889 index c8f47f1..5da9840 100644
32890 --- a/drivers/net/ethernet/realtek/r8169.c
32891 +++ b/drivers/net/ethernet/realtek/r8169.c
32892 @@ -698,17 +698,17 @@ struct rtl8169_private {
32893 struct mdio_ops {
32894 void (*write)(void __iomem *, int, int);
32895 int (*read)(void __iomem *, int);
32896 - } mdio_ops;
32897 + } __no_const mdio_ops;
32898
32899 struct pll_power_ops {
32900 void (*down)(struct rtl8169_private *);
32901 void (*up)(struct rtl8169_private *);
32902 - } pll_power_ops;
32903 + } __no_const pll_power_ops;
32904
32905 struct jumbo_ops {
32906 void (*enable)(struct rtl8169_private *);
32907 void (*disable)(struct rtl8169_private *);
32908 - } jumbo_ops;
32909 + } __no_const jumbo_ops;
32910
32911 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
32912 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
32913 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
32914 index 1b4658c..a30dabb 100644
32915 --- a/drivers/net/ethernet/sis/sis190.c
32916 +++ b/drivers/net/ethernet/sis/sis190.c
32917 @@ -1624,7 +1624,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
32918 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
32919 struct net_device *dev)
32920 {
32921 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
32922 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
32923 struct sis190_private *tp = netdev_priv(dev);
32924 struct pci_dev *isa_bridge;
32925 u8 reg, tmp8;
32926 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
32927 index edfa15d..002bfa9 100644
32928 --- a/drivers/net/ppp/ppp_generic.c
32929 +++ b/drivers/net/ppp/ppp_generic.c
32930 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32931 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
32932 struct ppp_stats stats;
32933 struct ppp_comp_stats cstats;
32934 - char *vers;
32935
32936 switch (cmd) {
32937 case SIOCGPPPSTATS:
32938 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32939 break;
32940
32941 case SIOCGPPPVER:
32942 - vers = PPP_VERSION;
32943 - if (copy_to_user(addr, vers, strlen(vers) + 1))
32944 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
32945 break;
32946 err = 0;
32947 break;
32948 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
32949 index 515f122..41dd273 100644
32950 --- a/drivers/net/tokenring/abyss.c
32951 +++ b/drivers/net/tokenring/abyss.c
32952 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
32953
32954 static int __init abyss_init (void)
32955 {
32956 - abyss_netdev_ops = tms380tr_netdev_ops;
32957 + pax_open_kernel();
32958 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
32959
32960 - abyss_netdev_ops.ndo_open = abyss_open;
32961 - abyss_netdev_ops.ndo_stop = abyss_close;
32962 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
32963 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
32964 + pax_close_kernel();
32965
32966 return pci_register_driver(&abyss_driver);
32967 }
32968 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
32969 index 6153cfd..cf69c1c 100644
32970 --- a/drivers/net/tokenring/madgemc.c
32971 +++ b/drivers/net/tokenring/madgemc.c
32972 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
32973
32974 static int __init madgemc_init (void)
32975 {
32976 - madgemc_netdev_ops = tms380tr_netdev_ops;
32977 - madgemc_netdev_ops.ndo_open = madgemc_open;
32978 - madgemc_netdev_ops.ndo_stop = madgemc_close;
32979 + pax_open_kernel();
32980 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
32981 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
32982 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
32983 + pax_close_kernel();
32984
32985 return mca_register_driver (&madgemc_driver);
32986 }
32987 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
32988 index 8d362e6..f91cc52 100644
32989 --- a/drivers/net/tokenring/proteon.c
32990 +++ b/drivers/net/tokenring/proteon.c
32991 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
32992 struct platform_device *pdev;
32993 int i, num = 0, err = 0;
32994
32995 - proteon_netdev_ops = tms380tr_netdev_ops;
32996 - proteon_netdev_ops.ndo_open = proteon_open;
32997 - proteon_netdev_ops.ndo_stop = tms380tr_close;
32998 + pax_open_kernel();
32999 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
33000 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
33001 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
33002 + pax_close_kernel();
33003
33004 err = platform_driver_register(&proteon_driver);
33005 if (err)
33006 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
33007 index 46db5c5..37c1536 100644
33008 --- a/drivers/net/tokenring/skisa.c
33009 +++ b/drivers/net/tokenring/skisa.c
33010 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
33011 struct platform_device *pdev;
33012 int i, num = 0, err = 0;
33013
33014 - sk_isa_netdev_ops = tms380tr_netdev_ops;
33015 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
33016 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
33017 + pax_open_kernel();
33018 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
33019 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
33020 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
33021 + pax_close_kernel();
33022
33023 err = platform_driver_register(&sk_isa_driver);
33024 if (err)
33025 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
33026 index 304fe78..db112fa 100644
33027 --- a/drivers/net/usb/hso.c
33028 +++ b/drivers/net/usb/hso.c
33029 @@ -71,7 +71,7 @@
33030 #include <asm/byteorder.h>
33031 #include <linux/serial_core.h>
33032 #include <linux/serial.h>
33033 -
33034 +#include <asm/local.h>
33035
33036 #define MOD_AUTHOR "Option Wireless"
33037 #define MOD_DESCRIPTION "USB High Speed Option driver"
33038 @@ -257,7 +257,7 @@ struct hso_serial {
33039
33040 /* from usb_serial_port */
33041 struct tty_struct *tty;
33042 - int open_count;
33043 + local_t open_count;
33044 spinlock_t serial_lock;
33045
33046 int (*write_data) (struct hso_serial *serial);
33047 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
33048 struct urb *urb;
33049
33050 urb = serial->rx_urb[0];
33051 - if (serial->open_count > 0) {
33052 + if (local_read(&serial->open_count) > 0) {
33053 count = put_rxbuf_data(urb, serial);
33054 if (count == -1)
33055 return;
33056 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
33057 DUMP1(urb->transfer_buffer, urb->actual_length);
33058
33059 /* Anyone listening? */
33060 - if (serial->open_count == 0)
33061 + if (local_read(&serial->open_count) == 0)
33062 return;
33063
33064 if (status == 0) {
33065 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
33066 spin_unlock_irq(&serial->serial_lock);
33067
33068 /* check for port already opened, if not set the termios */
33069 - serial->open_count++;
33070 - if (serial->open_count == 1) {
33071 + if (local_inc_return(&serial->open_count) == 1) {
33072 serial->rx_state = RX_IDLE;
33073 /* Force default termio settings */
33074 _hso_serial_set_termios(tty, NULL);
33075 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
33076 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
33077 if (result) {
33078 hso_stop_serial_device(serial->parent);
33079 - serial->open_count--;
33080 + local_dec(&serial->open_count);
33081 kref_put(&serial->parent->ref, hso_serial_ref_free);
33082 }
33083 } else {
33084 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
33085
33086 /* reset the rts and dtr */
33087 /* do the actual close */
33088 - serial->open_count--;
33089 + local_dec(&serial->open_count);
33090
33091 - if (serial->open_count <= 0) {
33092 - serial->open_count = 0;
33093 + if (local_read(&serial->open_count) <= 0) {
33094 + local_set(&serial->open_count, 0);
33095 spin_lock_irq(&serial->serial_lock);
33096 if (serial->tty == tty) {
33097 serial->tty->driver_data = NULL;
33098 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
33099
33100 /* the actual setup */
33101 spin_lock_irqsave(&serial->serial_lock, flags);
33102 - if (serial->open_count)
33103 + if (local_read(&serial->open_count))
33104 _hso_serial_set_termios(tty, old);
33105 else
33106 tty->termios = old;
33107 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
33108 D1("Pending read interrupt on port %d\n", i);
33109 spin_lock(&serial->serial_lock);
33110 if (serial->rx_state == RX_IDLE &&
33111 - serial->open_count > 0) {
33112 + local_read(&serial->open_count) > 0) {
33113 /* Setup and send a ctrl req read on
33114 * port i */
33115 if (!serial->rx_urb_filled[0]) {
33116 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
33117 /* Start all serial ports */
33118 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
33119 if (serial_table[i] && (serial_table[i]->interface == iface)) {
33120 - if (dev2ser(serial_table[i])->open_count) {
33121 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
33122 result =
33123 hso_start_serial_device(serial_table[i], GFP_NOIO);
33124 hso_kick_transmit(dev2ser(serial_table[i]));
33125 diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
33126 index e662cbc..8d4a102 100644
33127 --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
33128 +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
33129 @@ -601,8 +601,7 @@ vmxnet3_set_rss_indir(struct net_device *netdev,
33130 * Return with error code if any of the queue indices
33131 * is out of range
33132 */
33133 - if (p->ring_index[i] < 0 ||
33134 - p->ring_index[i] >= adapter->num_rx_queues)
33135 + if (p->ring_index[i] >= adapter->num_rx_queues)
33136 return -EINVAL;
33137 }
33138
33139 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
33140 index 0f9ee46..e2d6e65 100644
33141 --- a/drivers/net/wireless/ath/ath.h
33142 +++ b/drivers/net/wireless/ath/ath.h
33143 @@ -119,6 +119,7 @@ struct ath_ops {
33144 void (*write_flush) (void *);
33145 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
33146 };
33147 +typedef struct ath_ops __no_const ath_ops_no_const;
33148
33149 struct ath_common;
33150 struct ath_bus_ops;
33151 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33152 index b592016..fe47870 100644
33153 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33154 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33155 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33156 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
33157 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
33158
33159 - ACCESS_ONCE(ads->ds_link) = i->link;
33160 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
33161 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
33162 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
33163
33164 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
33165 ctl6 = SM(i->keytype, AR_EncrType);
33166 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33167
33168 if ((i->is_first || i->is_last) &&
33169 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
33170 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
33171 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
33172 | set11nTries(i->rates, 1)
33173 | set11nTries(i->rates, 2)
33174 | set11nTries(i->rates, 3)
33175 | (i->dur_update ? AR_DurUpdateEna : 0)
33176 | SM(0, AR_BurstDur);
33177
33178 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
33179 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
33180 | set11nRate(i->rates, 1)
33181 | set11nRate(i->rates, 2)
33182 | set11nRate(i->rates, 3);
33183 } else {
33184 - ACCESS_ONCE(ads->ds_ctl2) = 0;
33185 - ACCESS_ONCE(ads->ds_ctl3) = 0;
33186 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
33187 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
33188 }
33189
33190 if (!i->is_first) {
33191 - ACCESS_ONCE(ads->ds_ctl0) = 0;
33192 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
33193 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
33194 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
33195 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
33196 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
33197 return;
33198 }
33199
33200 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33201 break;
33202 }
33203
33204 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
33205 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
33206 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
33207 | SM(i->txpower, AR_XmitPower)
33208 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
33209 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33210 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
33211 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
33212
33213 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
33214 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
33215 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
33216 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
33217
33218 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
33219 return;
33220
33221 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
33222 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
33223 | set11nPktDurRTSCTS(i->rates, 1);
33224
33225 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
33226 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
33227 | set11nPktDurRTSCTS(i->rates, 3);
33228
33229 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
33230 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
33231 | set11nRateFlags(i->rates, 1)
33232 | set11nRateFlags(i->rates, 2)
33233 | set11nRateFlags(i->rates, 3)
33234 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33235 index ccde784..db012b3 100644
33236 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33237 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33238 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33239 (i->qcu << AR_TxQcuNum_S) | 0x17;
33240
33241 checksum += val;
33242 - ACCESS_ONCE(ads->info) = val;
33243 + ACCESS_ONCE_RW(ads->info) = val;
33244
33245 checksum += i->link;
33246 - ACCESS_ONCE(ads->link) = i->link;
33247 + ACCESS_ONCE_RW(ads->link) = i->link;
33248
33249 checksum += i->buf_addr[0];
33250 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
33251 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
33252 checksum += i->buf_addr[1];
33253 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
33254 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
33255 checksum += i->buf_addr[2];
33256 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
33257 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
33258 checksum += i->buf_addr[3];
33259 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
33260 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
33261
33262 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
33263 - ACCESS_ONCE(ads->ctl3) = val;
33264 + ACCESS_ONCE_RW(ads->ctl3) = val;
33265 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
33266 - ACCESS_ONCE(ads->ctl5) = val;
33267 + ACCESS_ONCE_RW(ads->ctl5) = val;
33268 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
33269 - ACCESS_ONCE(ads->ctl7) = val;
33270 + ACCESS_ONCE_RW(ads->ctl7) = val;
33271 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
33272 - ACCESS_ONCE(ads->ctl9) = val;
33273 + ACCESS_ONCE_RW(ads->ctl9) = val;
33274
33275 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
33276 - ACCESS_ONCE(ads->ctl10) = checksum;
33277 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
33278
33279 if (i->is_first || i->is_last) {
33280 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
33281 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
33282 | set11nTries(i->rates, 1)
33283 | set11nTries(i->rates, 2)
33284 | set11nTries(i->rates, 3)
33285 | (i->dur_update ? AR_DurUpdateEna : 0)
33286 | SM(0, AR_BurstDur);
33287
33288 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
33289 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
33290 | set11nRate(i->rates, 1)
33291 | set11nRate(i->rates, 2)
33292 | set11nRate(i->rates, 3);
33293 } else {
33294 - ACCESS_ONCE(ads->ctl13) = 0;
33295 - ACCESS_ONCE(ads->ctl14) = 0;
33296 + ACCESS_ONCE_RW(ads->ctl13) = 0;
33297 + ACCESS_ONCE_RW(ads->ctl14) = 0;
33298 }
33299
33300 ads->ctl20 = 0;
33301 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33302
33303 ctl17 = SM(i->keytype, AR_EncrType);
33304 if (!i->is_first) {
33305 - ACCESS_ONCE(ads->ctl11) = 0;
33306 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
33307 - ACCESS_ONCE(ads->ctl15) = 0;
33308 - ACCESS_ONCE(ads->ctl16) = 0;
33309 - ACCESS_ONCE(ads->ctl17) = ctl17;
33310 - ACCESS_ONCE(ads->ctl18) = 0;
33311 - ACCESS_ONCE(ads->ctl19) = 0;
33312 + ACCESS_ONCE_RW(ads->ctl11) = 0;
33313 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
33314 + ACCESS_ONCE_RW(ads->ctl15) = 0;
33315 + ACCESS_ONCE_RW(ads->ctl16) = 0;
33316 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
33317 + ACCESS_ONCE_RW(ads->ctl18) = 0;
33318 + ACCESS_ONCE_RW(ads->ctl19) = 0;
33319 return;
33320 }
33321
33322 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
33323 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
33324 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
33325 | SM(i->txpower, AR_XmitPower)
33326 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
33327 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33328 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
33329 ctl12 |= SM(val, AR_PAPRDChainMask);
33330
33331 - ACCESS_ONCE(ads->ctl12) = ctl12;
33332 - ACCESS_ONCE(ads->ctl17) = ctl17;
33333 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
33334 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
33335
33336 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
33337 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
33338 | set11nPktDurRTSCTS(i->rates, 1);
33339
33340 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
33341 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
33342 | set11nPktDurRTSCTS(i->rates, 3);
33343
33344 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
33345 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
33346 | set11nRateFlags(i->rates, 1)
33347 | set11nRateFlags(i->rates, 2)
33348 | set11nRateFlags(i->rates, 3)
33349 | SM(i->rtscts_rate, AR_RTSCTSRate);
33350
33351 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
33352 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
33353 }
33354
33355 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
33356 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
33357 index f389b3c..7359e18 100644
33358 --- a/drivers/net/wireless/ath/ath9k/hw.h
33359 +++ b/drivers/net/wireless/ath/ath9k/hw.h
33360 @@ -605,7 +605,7 @@ struct ath_hw_private_ops {
33361
33362 /* ANI */
33363 void (*ani_cache_ini_regs)(struct ath_hw *ah);
33364 -};
33365 +} __no_const;
33366
33367 /**
33368 * struct ath_hw_ops - callbacks used by hardware code and driver code
33369 @@ -635,7 +635,7 @@ struct ath_hw_ops {
33370 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
33371 struct ath_hw_antcomb_conf *antconf);
33372
33373 -};
33374 +} __no_const;
33375
33376 struct ath_nf_limits {
33377 s16 max;
33378 @@ -655,7 +655,7 @@ enum ath_cal_list {
33379 #define AH_FASTCC 0x4
33380
33381 struct ath_hw {
33382 - struct ath_ops reg_ops;
33383 + ath_ops_no_const reg_ops;
33384
33385 struct ieee80211_hw *hw;
33386 struct ath_common common;
33387 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33388 index bea8524..c677c06 100644
33389 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33390 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33391 @@ -547,7 +547,7 @@ struct phy_func_ptr {
33392 void (*carrsuppr)(struct brcms_phy *);
33393 s32 (*rxsigpwr)(struct brcms_phy *, s32);
33394 void (*detach)(struct brcms_phy *);
33395 -};
33396 +} __no_const;
33397
33398 struct brcms_phy {
33399 struct brcms_phy_pub pubpi_ro;
33400 diff --git a/drivers/net/wireless/iwlegacy/iwl3945-base.c b/drivers/net/wireless/iwlegacy/iwl3945-base.c
33401 index b282d86..bee832f 100644
33402 --- a/drivers/net/wireless/iwlegacy/iwl3945-base.c
33403 +++ b/drivers/net/wireless/iwlegacy/iwl3945-base.c
33404 @@ -3686,7 +3686,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
33405 */
33406 if (iwl3945_mod_params.disable_hw_scan) {
33407 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
33408 - iwl3945_hw_ops.hw_scan = NULL;
33409 + pax_open_kernel();
33410 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
33411 + pax_close_kernel();
33412 }
33413
33414 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
33415 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
33416 index 69a77e2..552b42c 100644
33417 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
33418 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
33419 @@ -71,8 +71,8 @@ do { \
33420 } while (0)
33421
33422 #else
33423 -#define IWL_DEBUG(m, level, fmt, args...)
33424 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
33425 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
33426 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
33427 #define iwl_print_hex_dump(m, level, p, len)
33428 #endif /* CONFIG_IWLWIFI_DEBUG */
33429
33430 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
33431 index 523ad55..f8c5dc5 100644
33432 --- a/drivers/net/wireless/mac80211_hwsim.c
33433 +++ b/drivers/net/wireless/mac80211_hwsim.c
33434 @@ -1678,9 +1678,11 @@ static int __init init_mac80211_hwsim(void)
33435 return -EINVAL;
33436
33437 if (fake_hw_scan) {
33438 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
33439 - mac80211_hwsim_ops.sw_scan_start = NULL;
33440 - mac80211_hwsim_ops.sw_scan_complete = NULL;
33441 + pax_open_kernel();
33442 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
33443 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
33444 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
33445 + pax_close_kernel();
33446 }
33447
33448 spin_lock_init(&hwsim_radio_lock);
33449 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
33450 index 30f138b..c904585 100644
33451 --- a/drivers/net/wireless/mwifiex/main.h
33452 +++ b/drivers/net/wireless/mwifiex/main.h
33453 @@ -543,7 +543,7 @@ struct mwifiex_if_ops {
33454 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
33455 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
33456 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
33457 -};
33458 +} __no_const;
33459
33460 struct mwifiex_adapter {
33461 u8 iface_type;
33462 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
33463 index 0c13840..a5c3ed6 100644
33464 --- a/drivers/net/wireless/rndis_wlan.c
33465 +++ b/drivers/net/wireless/rndis_wlan.c
33466 @@ -1275,7 +1275,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
33467
33468 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
33469
33470 - if (rts_threshold < 0 || rts_threshold > 2347)
33471 + if (rts_threshold > 2347)
33472 rts_threshold = 2347;
33473
33474 tmp = cpu_to_le32(rts_threshold);
33475 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
33476 index a77f1bb..c608b2b 100644
33477 --- a/drivers/net/wireless/wl1251/wl1251.h
33478 +++ b/drivers/net/wireless/wl1251/wl1251.h
33479 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
33480 void (*reset)(struct wl1251 *wl);
33481 void (*enable_irq)(struct wl1251 *wl);
33482 void (*disable_irq)(struct wl1251 *wl);
33483 -};
33484 +} __no_const;
33485
33486 struct wl1251 {
33487 struct ieee80211_hw *hw;
33488 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
33489 index f34b5b2..b5abb9f 100644
33490 --- a/drivers/oprofile/buffer_sync.c
33491 +++ b/drivers/oprofile/buffer_sync.c
33492 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
33493 if (cookie == NO_COOKIE)
33494 offset = pc;
33495 if (cookie == INVALID_COOKIE) {
33496 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
33497 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
33498 offset = pc;
33499 }
33500 if (cookie != last_cookie) {
33501 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
33502 /* add userspace sample */
33503
33504 if (!mm) {
33505 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
33506 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
33507 return 0;
33508 }
33509
33510 cookie = lookup_dcookie(mm, s->eip, &offset);
33511
33512 if (cookie == INVALID_COOKIE) {
33513 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
33514 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
33515 return 0;
33516 }
33517
33518 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
33519 /* ignore backtraces if failed to add a sample */
33520 if (state == sb_bt_start) {
33521 state = sb_bt_ignore;
33522 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
33523 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
33524 }
33525 }
33526 release_mm(mm);
33527 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
33528 index c0cc4e7..44d4e54 100644
33529 --- a/drivers/oprofile/event_buffer.c
33530 +++ b/drivers/oprofile/event_buffer.c
33531 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
33532 }
33533
33534 if (buffer_pos == buffer_size) {
33535 - atomic_inc(&oprofile_stats.event_lost_overflow);
33536 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
33537 return;
33538 }
33539
33540 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
33541 index f8c752e..28bf4fc 100644
33542 --- a/drivers/oprofile/oprof.c
33543 +++ b/drivers/oprofile/oprof.c
33544 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
33545 if (oprofile_ops.switch_events())
33546 return;
33547
33548 - atomic_inc(&oprofile_stats.multiplex_counter);
33549 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
33550 start_switch_worker();
33551 }
33552
33553 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
33554 index 917d28e..d62d981 100644
33555 --- a/drivers/oprofile/oprofile_stats.c
33556 +++ b/drivers/oprofile/oprofile_stats.c
33557 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
33558 cpu_buf->sample_invalid_eip = 0;
33559 }
33560
33561 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
33562 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
33563 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
33564 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
33565 - atomic_set(&oprofile_stats.multiplex_counter, 0);
33566 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
33567 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
33568 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
33569 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
33570 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
33571 }
33572
33573
33574 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
33575 index 38b6fc0..b5cbfce 100644
33576 --- a/drivers/oprofile/oprofile_stats.h
33577 +++ b/drivers/oprofile/oprofile_stats.h
33578 @@ -13,11 +13,11 @@
33579 #include <linux/atomic.h>
33580
33581 struct oprofile_stat_struct {
33582 - atomic_t sample_lost_no_mm;
33583 - atomic_t sample_lost_no_mapping;
33584 - atomic_t bt_lost_no_mapping;
33585 - atomic_t event_lost_overflow;
33586 - atomic_t multiplex_counter;
33587 + atomic_unchecked_t sample_lost_no_mm;
33588 + atomic_unchecked_t sample_lost_no_mapping;
33589 + atomic_unchecked_t bt_lost_no_mapping;
33590 + atomic_unchecked_t event_lost_overflow;
33591 + atomic_unchecked_t multiplex_counter;
33592 };
33593
33594 extern struct oprofile_stat_struct oprofile_stats;
33595 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
33596 index 2f0aa0f..90fab02 100644
33597 --- a/drivers/oprofile/oprofilefs.c
33598 +++ b/drivers/oprofile/oprofilefs.c
33599 @@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
33600
33601
33602 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
33603 - char const *name, atomic_t *val)
33604 + char const *name, atomic_unchecked_t *val)
33605 {
33606 return __oprofilefs_create_file(sb, root, name,
33607 &atomic_ro_fops, 0444, val);
33608 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
33609 index 3f56bc0..707d642 100644
33610 --- a/drivers/parport/procfs.c
33611 +++ b/drivers/parport/procfs.c
33612 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
33613
33614 *ppos += len;
33615
33616 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
33617 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
33618 }
33619
33620 #ifdef CONFIG_PARPORT_1284
33621 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
33622
33623 *ppos += len;
33624
33625 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
33626 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
33627 }
33628 #endif /* IEEE1284.3 support. */
33629
33630 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
33631 index 9fff878..ad0ad53 100644
33632 --- a/drivers/pci/hotplug/cpci_hotplug.h
33633 +++ b/drivers/pci/hotplug/cpci_hotplug.h
33634 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
33635 int (*hardware_test) (struct slot* slot, u32 value);
33636 u8 (*get_power) (struct slot* slot);
33637 int (*set_power) (struct slot* slot, int value);
33638 -};
33639 +} __no_const;
33640
33641 struct cpci_hp_controller {
33642 unsigned int irq;
33643 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
33644 index 76ba8a1..20ca857 100644
33645 --- a/drivers/pci/hotplug/cpqphp_nvram.c
33646 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
33647 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
33648
33649 void compaq_nvram_init (void __iomem *rom_start)
33650 {
33651 +
33652 +#ifndef CONFIG_PAX_KERNEXEC
33653 if (rom_start) {
33654 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
33655 }
33656 +#endif
33657 +
33658 dbg("int15 entry = %p\n", compaq_int15_entry_point);
33659
33660 /* initialize our int15 lock */
33661 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
33662 index cbfbab1..6a9fced 100644
33663 --- a/drivers/pci/pcie/aspm.c
33664 +++ b/drivers/pci/pcie/aspm.c
33665 @@ -27,9 +27,9 @@
33666 #define MODULE_PARAM_PREFIX "pcie_aspm."
33667
33668 /* Note: those are not register definitions */
33669 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
33670 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
33671 -#define ASPM_STATE_L1 (4) /* L1 state */
33672 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
33673 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
33674 +#define ASPM_STATE_L1 (4U) /* L1 state */
33675 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
33676 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
33677
33678 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
33679 index 04e74f4..a960176 100644
33680 --- a/drivers/pci/probe.c
33681 +++ b/drivers/pci/probe.c
33682 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
33683 u32 l, sz, mask;
33684 u16 orig_cmd;
33685
33686 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
33687 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
33688
33689 if (!dev->mmio_always_on) {
33690 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
33691 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
33692 index 27911b5..5b6db88 100644
33693 --- a/drivers/pci/proc.c
33694 +++ b/drivers/pci/proc.c
33695 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
33696 static int __init pci_proc_init(void)
33697 {
33698 struct pci_dev *dev = NULL;
33699 +
33700 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
33701 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33702 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
33703 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33704 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
33705 +#endif
33706 +#else
33707 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
33708 +#endif
33709 proc_create("devices", 0, proc_bus_pci_dir,
33710 &proc_bus_pci_dev_operations);
33711 proc_initialized = 1;
33712 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
33713 index 7b82868..b9344c9 100644
33714 --- a/drivers/platform/x86/thinkpad_acpi.c
33715 +++ b/drivers/platform/x86/thinkpad_acpi.c
33716 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
33717 return 0;
33718 }
33719
33720 -void static hotkey_mask_warn_incomplete_mask(void)
33721 +static void hotkey_mask_warn_incomplete_mask(void)
33722 {
33723 /* log only what the user can fix... */
33724 const u32 wantedmask = hotkey_driver_mask &
33725 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
33726 }
33727 }
33728
33729 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33730 - struct tp_nvram_state *newn,
33731 - const u32 event_mask)
33732 -{
33733 -
33734 #define TPACPI_COMPARE_KEY(__scancode, __member) \
33735 do { \
33736 if ((event_mask & (1 << __scancode)) && \
33737 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33738 tpacpi_hotkey_send_key(__scancode); \
33739 } while (0)
33740
33741 - void issue_volchange(const unsigned int oldvol,
33742 - const unsigned int newvol)
33743 - {
33744 - unsigned int i = oldvol;
33745 +static void issue_volchange(const unsigned int oldvol,
33746 + const unsigned int newvol,
33747 + const u32 event_mask)
33748 +{
33749 + unsigned int i = oldvol;
33750
33751 - while (i > newvol) {
33752 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
33753 - i--;
33754 - }
33755 - while (i < newvol) {
33756 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33757 - i++;
33758 - }
33759 + while (i > newvol) {
33760 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
33761 + i--;
33762 }
33763 + while (i < newvol) {
33764 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33765 + i++;
33766 + }
33767 +}
33768
33769 - void issue_brightnesschange(const unsigned int oldbrt,
33770 - const unsigned int newbrt)
33771 - {
33772 - unsigned int i = oldbrt;
33773 +static void issue_brightnesschange(const unsigned int oldbrt,
33774 + const unsigned int newbrt,
33775 + const u32 event_mask)
33776 +{
33777 + unsigned int i = oldbrt;
33778
33779 - while (i > newbrt) {
33780 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
33781 - i--;
33782 - }
33783 - while (i < newbrt) {
33784 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
33785 - i++;
33786 - }
33787 + while (i > newbrt) {
33788 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
33789 + i--;
33790 + }
33791 + while (i < newbrt) {
33792 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
33793 + i++;
33794 }
33795 +}
33796
33797 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33798 + struct tp_nvram_state *newn,
33799 + const u32 event_mask)
33800 +{
33801 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
33802 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
33803 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
33804 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33805 oldn->volume_level != newn->volume_level) {
33806 /* recently muted, or repeated mute keypress, or
33807 * multiple presses ending in mute */
33808 - issue_volchange(oldn->volume_level, newn->volume_level);
33809 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
33810 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
33811 }
33812 } else {
33813 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33814 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33815 }
33816 if (oldn->volume_level != newn->volume_level) {
33817 - issue_volchange(oldn->volume_level, newn->volume_level);
33818 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
33819 } else if (oldn->volume_toggle != newn->volume_toggle) {
33820 /* repeated vol up/down keypress at end of scale ? */
33821 if (newn->volume_level == 0)
33822 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33823 /* handle brightness */
33824 if (oldn->brightness_level != newn->brightness_level) {
33825 issue_brightnesschange(oldn->brightness_level,
33826 - newn->brightness_level);
33827 + newn->brightness_level,
33828 + event_mask);
33829 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
33830 /* repeated key presses that didn't change state */
33831 if (newn->brightness_level == 0)
33832 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33833 && !tp_features.bright_unkfw)
33834 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
33835 }
33836 +}
33837
33838 #undef TPACPI_COMPARE_KEY
33839 #undef TPACPI_MAY_SEND_KEY
33840 -}
33841
33842 /*
33843 * Polling driver
33844 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
33845 index b859d16..5cc6b1a 100644
33846 --- a/drivers/pnp/pnpbios/bioscalls.c
33847 +++ b/drivers/pnp/pnpbios/bioscalls.c
33848 @@ -59,7 +59,7 @@ do { \
33849 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
33850 } while(0)
33851
33852 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
33853 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
33854 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
33855
33856 /*
33857 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
33858
33859 cpu = get_cpu();
33860 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
33861 +
33862 + pax_open_kernel();
33863 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
33864 + pax_close_kernel();
33865
33866 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
33867 spin_lock_irqsave(&pnp_bios_lock, flags);
33868 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
33869 :"memory");
33870 spin_unlock_irqrestore(&pnp_bios_lock, flags);
33871
33872 + pax_open_kernel();
33873 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
33874 + pax_close_kernel();
33875 +
33876 put_cpu();
33877
33878 /* If we get here and this is set then the PnP BIOS faulted on us. */
33879 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
33880 return status;
33881 }
33882
33883 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
33884 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
33885 {
33886 int i;
33887
33888 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
33889 pnp_bios_callpoint.offset = header->fields.pm16offset;
33890 pnp_bios_callpoint.segment = PNP_CS16;
33891
33892 + pax_open_kernel();
33893 +
33894 for_each_possible_cpu(i) {
33895 struct desc_struct *gdt = get_cpu_gdt_table(i);
33896 if (!gdt)
33897 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
33898 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
33899 (unsigned long)__va(header->fields.pm16dseg));
33900 }
33901 +
33902 + pax_close_kernel();
33903 }
33904 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
33905 index b0ecacb..7c9da2e 100644
33906 --- a/drivers/pnp/resource.c
33907 +++ b/drivers/pnp/resource.c
33908 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
33909 return 1;
33910
33911 /* check if the resource is valid */
33912 - if (*irq < 0 || *irq > 15)
33913 + if (*irq > 15)
33914 return 0;
33915
33916 /* check if the resource is reserved */
33917 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
33918 return 1;
33919
33920 /* check if the resource is valid */
33921 - if (*dma < 0 || *dma == 4 || *dma > 7)
33922 + if (*dma == 4 || *dma > 7)
33923 return 0;
33924
33925 /* check if the resource is reserved */
33926 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
33927 index bb16f5b..c751eef 100644
33928 --- a/drivers/power/bq27x00_battery.c
33929 +++ b/drivers/power/bq27x00_battery.c
33930 @@ -67,7 +67,7 @@
33931 struct bq27x00_device_info;
33932 struct bq27x00_access_methods {
33933 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
33934 -};
33935 +} __no_const;
33936
33937 enum bq27x00_chip { BQ27000, BQ27500 };
33938
33939 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
33940 index 33f5d9a..d957d3f 100644
33941 --- a/drivers/regulator/max8660.c
33942 +++ b/drivers/regulator/max8660.c
33943 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
33944 max8660->shadow_regs[MAX8660_OVER1] = 5;
33945 } else {
33946 /* Otherwise devices can be toggled via software */
33947 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
33948 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
33949 + pax_open_kernel();
33950 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
33951 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
33952 + pax_close_kernel();
33953 }
33954
33955 /*
33956 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
33957 index 023d17d..74ef35b 100644
33958 --- a/drivers/regulator/mc13892-regulator.c
33959 +++ b/drivers/regulator/mc13892-regulator.c
33960 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
33961 }
33962 mc13xxx_unlock(mc13892);
33963
33964 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
33965 + pax_open_kernel();
33966 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
33967 = mc13892_vcam_set_mode;
33968 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
33969 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
33970 = mc13892_vcam_get_mode;
33971 + pax_close_kernel();
33972 for (i = 0; i < pdata->num_regulators; i++) {
33973 init_data = &pdata->regulators[i];
33974 priv->regulators[i] = regulator_register(
33975 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
33976 index cace6d3..f623fda 100644
33977 --- a/drivers/rtc/rtc-dev.c
33978 +++ b/drivers/rtc/rtc-dev.c
33979 @@ -14,6 +14,7 @@
33980 #include <linux/module.h>
33981 #include <linux/rtc.h>
33982 #include <linux/sched.h>
33983 +#include <linux/grsecurity.h>
33984 #include "rtc-core.h"
33985
33986 static dev_t rtc_devt;
33987 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
33988 if (copy_from_user(&tm, uarg, sizeof(tm)))
33989 return -EFAULT;
33990
33991 + gr_log_timechange();
33992 +
33993 return rtc_set_time(rtc, &tm);
33994
33995 case RTC_PIE_ON:
33996 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
33997 index ffb5878..e6d785c 100644
33998 --- a/drivers/scsi/aacraid/aacraid.h
33999 +++ b/drivers/scsi/aacraid/aacraid.h
34000 @@ -492,7 +492,7 @@ struct adapter_ops
34001 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
34002 /* Administrative operations */
34003 int (*adapter_comm)(struct aac_dev * dev, int comm);
34004 -};
34005 +} __no_const;
34006
34007 /*
34008 * Define which interrupt handler needs to be installed
34009 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
34010 index 705e13e..91c873c 100644
34011 --- a/drivers/scsi/aacraid/linit.c
34012 +++ b/drivers/scsi/aacraid/linit.c
34013 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
34014 #elif defined(__devinitconst)
34015 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
34016 #else
34017 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
34018 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
34019 #endif
34020 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
34021 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
34022 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
34023 index d5ff142..49c0ebb 100644
34024 --- a/drivers/scsi/aic94xx/aic94xx_init.c
34025 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
34026 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
34027 .lldd_control_phy = asd_control_phy,
34028 };
34029
34030 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
34031 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
34032 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
34033 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
34034 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
34035 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
34036 index a796de9..1ef20e1 100644
34037 --- a/drivers/scsi/bfa/bfa.h
34038 +++ b/drivers/scsi/bfa/bfa.h
34039 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
34040 u32 *end);
34041 int cpe_vec_q0;
34042 int rme_vec_q0;
34043 -};
34044 +} __no_const;
34045 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
34046
34047 struct bfa_faa_cbfn_s {
34048 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
34049 index e07bd47..cd1bbbb 100644
34050 --- a/drivers/scsi/bfa/bfa_fcpim.c
34051 +++ b/drivers/scsi/bfa/bfa_fcpim.c
34052 @@ -4121,7 +4121,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
34053
34054 bfa_iotag_attach(fcp);
34055
34056 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
34057 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
34058 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
34059 (fcp->num_itns * sizeof(struct bfa_itn_s));
34060 memset(fcp->itn_arr, 0,
34061 @@ -4179,7 +4179,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
34062 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
34063 {
34064 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
34065 - struct bfa_itn_s *itn;
34066 + bfa_itn_s_no_const *itn;
34067
34068 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
34069 itn->isr = isr;
34070 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
34071 index 1080bcb..a3b39e3 100644
34072 --- a/drivers/scsi/bfa/bfa_fcpim.h
34073 +++ b/drivers/scsi/bfa/bfa_fcpim.h
34074 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
34075 struct bfa_itn_s {
34076 bfa_isr_func_t isr;
34077 };
34078 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
34079
34080 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
34081 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
34082 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
34083 struct list_head iotag_tio_free_q; /* free IO resources */
34084 struct list_head iotag_unused_q; /* unused IO resources*/
34085 struct bfa_iotag_s *iotag_arr;
34086 - struct bfa_itn_s *itn_arr;
34087 + bfa_itn_s_no_const *itn_arr;
34088 int num_ioim_reqs;
34089 int num_fwtio_reqs;
34090 int num_itns;
34091 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
34092 index 546d46b..642fa5b 100644
34093 --- a/drivers/scsi/bfa/bfa_ioc.h
34094 +++ b/drivers/scsi/bfa/bfa_ioc.h
34095 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
34096 bfa_ioc_disable_cbfn_t disable_cbfn;
34097 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
34098 bfa_ioc_reset_cbfn_t reset_cbfn;
34099 -};
34100 +} __no_const;
34101
34102 /*
34103 * IOC event notification mechanism.
34104 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
34105 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
34106 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
34107 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
34108 -};
34109 +} __no_const;
34110
34111 /*
34112 * Queue element to wait for room in request queue. FIFO order is
34113 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
34114 index 351dc0b..951dc32 100644
34115 --- a/drivers/scsi/hosts.c
34116 +++ b/drivers/scsi/hosts.c
34117 @@ -42,7 +42,7 @@
34118 #include "scsi_logging.h"
34119
34120
34121 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
34122 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
34123
34124
34125 static void scsi_host_cls_release(struct device *dev)
34126 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
34127 * subtract one because we increment first then return, but we need to
34128 * know what the next host number was before increment
34129 */
34130 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
34131 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
34132 shost->dma_channel = 0xff;
34133
34134 /* These three are default values which can be overridden */
34135 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
34136 index 865d452..e9b7fa7 100644
34137 --- a/drivers/scsi/hpsa.c
34138 +++ b/drivers/scsi/hpsa.c
34139 @@ -505,7 +505,7 @@ static inline u32 next_command(struct ctlr_info *h)
34140 u32 a;
34141
34142 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
34143 - return h->access.command_completed(h);
34144 + return h->access->command_completed(h);
34145
34146 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
34147 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
34148 @@ -2989,7 +2989,7 @@ static void start_io(struct ctlr_info *h)
34149 while (!list_empty(&h->reqQ)) {
34150 c = list_entry(h->reqQ.next, struct CommandList, list);
34151 /* can't do anything if fifo is full */
34152 - if ((h->access.fifo_full(h))) {
34153 + if ((h->access->fifo_full(h))) {
34154 dev_warn(&h->pdev->dev, "fifo full\n");
34155 break;
34156 }
34157 @@ -2999,7 +2999,7 @@ static void start_io(struct ctlr_info *h)
34158 h->Qdepth--;
34159
34160 /* Tell the controller execute command */
34161 - h->access.submit_command(h, c);
34162 + h->access->submit_command(h, c);
34163
34164 /* Put job onto the completed Q */
34165 addQ(&h->cmpQ, c);
34166 @@ -3008,17 +3008,17 @@ static void start_io(struct ctlr_info *h)
34167
34168 static inline unsigned long get_next_completion(struct ctlr_info *h)
34169 {
34170 - return h->access.command_completed(h);
34171 + return h->access->command_completed(h);
34172 }
34173
34174 static inline bool interrupt_pending(struct ctlr_info *h)
34175 {
34176 - return h->access.intr_pending(h);
34177 + return h->access->intr_pending(h);
34178 }
34179
34180 static inline long interrupt_not_for_us(struct ctlr_info *h)
34181 {
34182 - return (h->access.intr_pending(h) == 0) ||
34183 + return (h->access->intr_pending(h) == 0) ||
34184 (h->interrupts_enabled == 0);
34185 }
34186
34187 @@ -3917,7 +3917,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
34188 if (prod_index < 0)
34189 return -ENODEV;
34190 h->product_name = products[prod_index].product_name;
34191 - h->access = *(products[prod_index].access);
34192 + h->access = products[prod_index].access;
34193
34194 if (hpsa_board_disabled(h->pdev)) {
34195 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
34196 @@ -4162,7 +4162,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
34197
34198 assert_spin_locked(&lockup_detector_lock);
34199 remove_ctlr_from_lockup_detector_list(h);
34200 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34201 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34202 spin_lock_irqsave(&h->lock, flags);
34203 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
34204 spin_unlock_irqrestore(&h->lock, flags);
34205 @@ -4340,7 +4340,7 @@ reinit_after_soft_reset:
34206 }
34207
34208 /* make sure the board interrupts are off */
34209 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34210 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34211
34212 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
34213 goto clean2;
34214 @@ -4374,7 +4374,7 @@ reinit_after_soft_reset:
34215 * fake ones to scoop up any residual completions.
34216 */
34217 spin_lock_irqsave(&h->lock, flags);
34218 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34219 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34220 spin_unlock_irqrestore(&h->lock, flags);
34221 free_irq(h->intr[h->intr_mode], h);
34222 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
34223 @@ -4393,9 +4393,9 @@ reinit_after_soft_reset:
34224 dev_info(&h->pdev->dev, "Board READY.\n");
34225 dev_info(&h->pdev->dev,
34226 "Waiting for stale completions to drain.\n");
34227 - h->access.set_intr_mask(h, HPSA_INTR_ON);
34228 + h->access->set_intr_mask(h, HPSA_INTR_ON);
34229 msleep(10000);
34230 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34231 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34232
34233 rc = controller_reset_failed(h->cfgtable);
34234 if (rc)
34235 @@ -4416,7 +4416,7 @@ reinit_after_soft_reset:
34236 }
34237
34238 /* Turn the interrupts on so we can service requests */
34239 - h->access.set_intr_mask(h, HPSA_INTR_ON);
34240 + h->access->set_intr_mask(h, HPSA_INTR_ON);
34241
34242 hpsa_hba_inquiry(h);
34243 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
34244 @@ -4468,7 +4468,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
34245 * To write all data in the battery backed cache to disks
34246 */
34247 hpsa_flush_cache(h);
34248 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34249 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34250 free_irq(h->intr[h->intr_mode], h);
34251 #ifdef CONFIG_PCI_MSI
34252 if (h->msix_vector)
34253 @@ -4632,7 +4632,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
34254 return;
34255 }
34256 /* Change the access methods to the performant access methods */
34257 - h->access = SA5_performant_access;
34258 + h->access = &SA5_performant_access;
34259 h->transMethod = CFGTBL_Trans_Performant;
34260 }
34261
34262 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
34263 index 91edafb..a9b88ec 100644
34264 --- a/drivers/scsi/hpsa.h
34265 +++ b/drivers/scsi/hpsa.h
34266 @@ -73,7 +73,7 @@ struct ctlr_info {
34267 unsigned int msix_vector;
34268 unsigned int msi_vector;
34269 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
34270 - struct access_method access;
34271 + struct access_method *access;
34272
34273 /* queue and queue Info */
34274 struct list_head reqQ;
34275 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
34276 index f2df059..a3a9930 100644
34277 --- a/drivers/scsi/ips.h
34278 +++ b/drivers/scsi/ips.h
34279 @@ -1027,7 +1027,7 @@ typedef struct {
34280 int (*intr)(struct ips_ha *);
34281 void (*enableint)(struct ips_ha *);
34282 uint32_t (*statupd)(struct ips_ha *);
34283 -} ips_hw_func_t;
34284 +} __no_const ips_hw_func_t;
34285
34286 typedef struct ips_ha {
34287 uint8_t ha_id[IPS_MAX_CHANNELS+1];
34288 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
34289 index 9de9db2..1e09660 100644
34290 --- a/drivers/scsi/libfc/fc_exch.c
34291 +++ b/drivers/scsi/libfc/fc_exch.c
34292 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
34293 * all together if not used XXX
34294 */
34295 struct {
34296 - atomic_t no_free_exch;
34297 - atomic_t no_free_exch_xid;
34298 - atomic_t xid_not_found;
34299 - atomic_t xid_busy;
34300 - atomic_t seq_not_found;
34301 - atomic_t non_bls_resp;
34302 + atomic_unchecked_t no_free_exch;
34303 + atomic_unchecked_t no_free_exch_xid;
34304 + atomic_unchecked_t xid_not_found;
34305 + atomic_unchecked_t xid_busy;
34306 + atomic_unchecked_t seq_not_found;
34307 + atomic_unchecked_t non_bls_resp;
34308 } stats;
34309 };
34310
34311 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
34312 /* allocate memory for exchange */
34313 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
34314 if (!ep) {
34315 - atomic_inc(&mp->stats.no_free_exch);
34316 + atomic_inc_unchecked(&mp->stats.no_free_exch);
34317 goto out;
34318 }
34319 memset(ep, 0, sizeof(*ep));
34320 @@ -780,7 +780,7 @@ out:
34321 return ep;
34322 err:
34323 spin_unlock_bh(&pool->lock);
34324 - atomic_inc(&mp->stats.no_free_exch_xid);
34325 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
34326 mempool_free(ep, mp->ep_pool);
34327 return NULL;
34328 }
34329 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34330 xid = ntohs(fh->fh_ox_id); /* we originated exch */
34331 ep = fc_exch_find(mp, xid);
34332 if (!ep) {
34333 - atomic_inc(&mp->stats.xid_not_found);
34334 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34335 reject = FC_RJT_OX_ID;
34336 goto out;
34337 }
34338 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34339 ep = fc_exch_find(mp, xid);
34340 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
34341 if (ep) {
34342 - atomic_inc(&mp->stats.xid_busy);
34343 + atomic_inc_unchecked(&mp->stats.xid_busy);
34344 reject = FC_RJT_RX_ID;
34345 goto rel;
34346 }
34347 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34348 }
34349 xid = ep->xid; /* get our XID */
34350 } else if (!ep) {
34351 - atomic_inc(&mp->stats.xid_not_found);
34352 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34353 reject = FC_RJT_RX_ID; /* XID not found */
34354 goto out;
34355 }
34356 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34357 } else {
34358 sp = &ep->seq;
34359 if (sp->id != fh->fh_seq_id) {
34360 - atomic_inc(&mp->stats.seq_not_found);
34361 + atomic_inc_unchecked(&mp->stats.seq_not_found);
34362 if (f_ctl & FC_FC_END_SEQ) {
34363 /*
34364 * Update sequence_id based on incoming last
34365 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34366
34367 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
34368 if (!ep) {
34369 - atomic_inc(&mp->stats.xid_not_found);
34370 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34371 goto out;
34372 }
34373 if (ep->esb_stat & ESB_ST_COMPLETE) {
34374 - atomic_inc(&mp->stats.xid_not_found);
34375 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34376 goto rel;
34377 }
34378 if (ep->rxid == FC_XID_UNKNOWN)
34379 ep->rxid = ntohs(fh->fh_rx_id);
34380 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
34381 - atomic_inc(&mp->stats.xid_not_found);
34382 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34383 goto rel;
34384 }
34385 if (ep->did != ntoh24(fh->fh_s_id) &&
34386 ep->did != FC_FID_FLOGI) {
34387 - atomic_inc(&mp->stats.xid_not_found);
34388 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34389 goto rel;
34390 }
34391 sof = fr_sof(fp);
34392 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34393 sp->ssb_stat |= SSB_ST_RESP;
34394 sp->id = fh->fh_seq_id;
34395 } else if (sp->id != fh->fh_seq_id) {
34396 - atomic_inc(&mp->stats.seq_not_found);
34397 + atomic_inc_unchecked(&mp->stats.seq_not_found);
34398 goto rel;
34399 }
34400
34401 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34402 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
34403
34404 if (!sp)
34405 - atomic_inc(&mp->stats.xid_not_found);
34406 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34407 else
34408 - atomic_inc(&mp->stats.non_bls_resp);
34409 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
34410
34411 fc_frame_free(fp);
34412 }
34413 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
34414 index db9238f..4378ed2 100644
34415 --- a/drivers/scsi/libsas/sas_ata.c
34416 +++ b/drivers/scsi/libsas/sas_ata.c
34417 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
34418 .postreset = ata_std_postreset,
34419 .error_handler = ata_std_error_handler,
34420 .post_internal_cmd = sas_ata_post_internal,
34421 - .qc_defer = ata_std_qc_defer,
34422 + .qc_defer = ata_std_qc_defer,
34423 .qc_prep = ata_noop_qc_prep,
34424 .qc_issue = sas_ata_qc_issue,
34425 .qc_fill_rtf = sas_ata_qc_fill_rtf,
34426 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
34427 index bb4c8e0..f33d849 100644
34428 --- a/drivers/scsi/lpfc/lpfc.h
34429 +++ b/drivers/scsi/lpfc/lpfc.h
34430 @@ -425,7 +425,7 @@ struct lpfc_vport {
34431 struct dentry *debug_nodelist;
34432 struct dentry *vport_debugfs_root;
34433 struct lpfc_debugfs_trc *disc_trc;
34434 - atomic_t disc_trc_cnt;
34435 + atomic_unchecked_t disc_trc_cnt;
34436 #endif
34437 uint8_t stat_data_enabled;
34438 uint8_t stat_data_blocked;
34439 @@ -835,8 +835,8 @@ struct lpfc_hba {
34440 struct timer_list fabric_block_timer;
34441 unsigned long bit_flags;
34442 #define FABRIC_COMANDS_BLOCKED 0
34443 - atomic_t num_rsrc_err;
34444 - atomic_t num_cmd_success;
34445 + atomic_unchecked_t num_rsrc_err;
34446 + atomic_unchecked_t num_cmd_success;
34447 unsigned long last_rsrc_error_time;
34448 unsigned long last_ramp_down_time;
34449 unsigned long last_ramp_up_time;
34450 @@ -866,7 +866,7 @@ struct lpfc_hba {
34451
34452 struct dentry *debug_slow_ring_trc;
34453 struct lpfc_debugfs_trc *slow_ring_trc;
34454 - atomic_t slow_ring_trc_cnt;
34455 + atomic_unchecked_t slow_ring_trc_cnt;
34456 /* iDiag debugfs sub-directory */
34457 struct dentry *idiag_root;
34458 struct dentry *idiag_pci_cfg;
34459 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
34460 index 2838259..a07cfb5 100644
34461 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
34462 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
34463 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
34464
34465 #include <linux/debugfs.h>
34466
34467 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
34468 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
34469 static unsigned long lpfc_debugfs_start_time = 0L;
34470
34471 /* iDiag */
34472 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
34473 lpfc_debugfs_enable = 0;
34474
34475 len = 0;
34476 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
34477 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
34478 (lpfc_debugfs_max_disc_trc - 1);
34479 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
34480 dtp = vport->disc_trc + i;
34481 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
34482 lpfc_debugfs_enable = 0;
34483
34484 len = 0;
34485 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
34486 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
34487 (lpfc_debugfs_max_slow_ring_trc - 1);
34488 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
34489 dtp = phba->slow_ring_trc + i;
34490 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
34491 !vport || !vport->disc_trc)
34492 return;
34493
34494 - index = atomic_inc_return(&vport->disc_trc_cnt) &
34495 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
34496 (lpfc_debugfs_max_disc_trc - 1);
34497 dtp = vport->disc_trc + index;
34498 dtp->fmt = fmt;
34499 dtp->data1 = data1;
34500 dtp->data2 = data2;
34501 dtp->data3 = data3;
34502 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
34503 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
34504 dtp->jif = jiffies;
34505 #endif
34506 return;
34507 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
34508 !phba || !phba->slow_ring_trc)
34509 return;
34510
34511 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
34512 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
34513 (lpfc_debugfs_max_slow_ring_trc - 1);
34514 dtp = phba->slow_ring_trc + index;
34515 dtp->fmt = fmt;
34516 dtp->data1 = data1;
34517 dtp->data2 = data2;
34518 dtp->data3 = data3;
34519 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
34520 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
34521 dtp->jif = jiffies;
34522 #endif
34523 return;
34524 @@ -3986,7 +3986,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
34525 "slow_ring buffer\n");
34526 goto debug_failed;
34527 }
34528 - atomic_set(&phba->slow_ring_trc_cnt, 0);
34529 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
34530 memset(phba->slow_ring_trc, 0,
34531 (sizeof(struct lpfc_debugfs_trc) *
34532 lpfc_debugfs_max_slow_ring_trc));
34533 @@ -4032,7 +4032,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
34534 "buffer\n");
34535 goto debug_failed;
34536 }
34537 - atomic_set(&vport->disc_trc_cnt, 0);
34538 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
34539
34540 snprintf(name, sizeof(name), "discovery_trace");
34541 vport->debug_disc_trc =
34542 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
34543 index 55bc4fc..a2a109c 100644
34544 --- a/drivers/scsi/lpfc/lpfc_init.c
34545 +++ b/drivers/scsi/lpfc/lpfc_init.c
34546 @@ -10027,8 +10027,10 @@ lpfc_init(void)
34547 printk(LPFC_COPYRIGHT "\n");
34548
34549 if (lpfc_enable_npiv) {
34550 - lpfc_transport_functions.vport_create = lpfc_vport_create;
34551 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
34552 + pax_open_kernel();
34553 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
34554 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
34555 + pax_close_kernel();
34556 }
34557 lpfc_transport_template =
34558 fc_attach_transport(&lpfc_transport_functions);
34559 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
34560 index 2e1e54e..1af0a0d 100644
34561 --- a/drivers/scsi/lpfc/lpfc_scsi.c
34562 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
34563 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
34564 uint32_t evt_posted;
34565
34566 spin_lock_irqsave(&phba->hbalock, flags);
34567 - atomic_inc(&phba->num_rsrc_err);
34568 + atomic_inc_unchecked(&phba->num_rsrc_err);
34569 phba->last_rsrc_error_time = jiffies;
34570
34571 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
34572 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
34573 unsigned long flags;
34574 struct lpfc_hba *phba = vport->phba;
34575 uint32_t evt_posted;
34576 - atomic_inc(&phba->num_cmd_success);
34577 + atomic_inc_unchecked(&phba->num_cmd_success);
34578
34579 if (vport->cfg_lun_queue_depth <= queue_depth)
34580 return;
34581 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
34582 unsigned long num_rsrc_err, num_cmd_success;
34583 int i;
34584
34585 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
34586 - num_cmd_success = atomic_read(&phba->num_cmd_success);
34587 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
34588 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
34589
34590 vports = lpfc_create_vport_work_array(phba);
34591 if (vports != NULL)
34592 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
34593 }
34594 }
34595 lpfc_destroy_vport_work_array(phba, vports);
34596 - atomic_set(&phba->num_rsrc_err, 0);
34597 - atomic_set(&phba->num_cmd_success, 0);
34598 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
34599 + atomic_set_unchecked(&phba->num_cmd_success, 0);
34600 }
34601
34602 /**
34603 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
34604 }
34605 }
34606 lpfc_destroy_vport_work_array(phba, vports);
34607 - atomic_set(&phba->num_rsrc_err, 0);
34608 - atomic_set(&phba->num_cmd_success, 0);
34609 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
34610 + atomic_set_unchecked(&phba->num_cmd_success, 0);
34611 }
34612
34613 /**
34614 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
34615 index 5163edb..7b142bc 100644
34616 --- a/drivers/scsi/pmcraid.c
34617 +++ b/drivers/scsi/pmcraid.c
34618 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
34619 res->scsi_dev = scsi_dev;
34620 scsi_dev->hostdata = res;
34621 res->change_detected = 0;
34622 - atomic_set(&res->read_failures, 0);
34623 - atomic_set(&res->write_failures, 0);
34624 + atomic_set_unchecked(&res->read_failures, 0);
34625 + atomic_set_unchecked(&res->write_failures, 0);
34626 rc = 0;
34627 }
34628 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
34629 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
34630
34631 /* If this was a SCSI read/write command keep count of errors */
34632 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
34633 - atomic_inc(&res->read_failures);
34634 + atomic_inc_unchecked(&res->read_failures);
34635 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
34636 - atomic_inc(&res->write_failures);
34637 + atomic_inc_unchecked(&res->write_failures);
34638
34639 if (!RES_IS_GSCSI(res->cfg_entry) &&
34640 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
34641 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
34642 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
34643 * hrrq_id assigned here in queuecommand
34644 */
34645 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
34646 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
34647 pinstance->num_hrrq;
34648 cmd->cmd_done = pmcraid_io_done;
34649
34650 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
34651 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
34652 * hrrq_id assigned here in queuecommand
34653 */
34654 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
34655 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
34656 pinstance->num_hrrq;
34657
34658 if (request_size) {
34659 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
34660
34661 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
34662 /* add resources only after host is added into system */
34663 - if (!atomic_read(&pinstance->expose_resources))
34664 + if (!atomic_read_unchecked(&pinstance->expose_resources))
34665 return;
34666
34667 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
34668 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
34669 init_waitqueue_head(&pinstance->reset_wait_q);
34670
34671 atomic_set(&pinstance->outstanding_cmds, 0);
34672 - atomic_set(&pinstance->last_message_id, 0);
34673 - atomic_set(&pinstance->expose_resources, 0);
34674 + atomic_set_unchecked(&pinstance->last_message_id, 0);
34675 + atomic_set_unchecked(&pinstance->expose_resources, 0);
34676
34677 INIT_LIST_HEAD(&pinstance->free_res_q);
34678 INIT_LIST_HEAD(&pinstance->used_res_q);
34679 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
34680 /* Schedule worker thread to handle CCN and take care of adding and
34681 * removing devices to OS
34682 */
34683 - atomic_set(&pinstance->expose_resources, 1);
34684 + atomic_set_unchecked(&pinstance->expose_resources, 1);
34685 schedule_work(&pinstance->worker_q);
34686 return rc;
34687
34688 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
34689 index ca496c7..9c791d5 100644
34690 --- a/drivers/scsi/pmcraid.h
34691 +++ b/drivers/scsi/pmcraid.h
34692 @@ -748,7 +748,7 @@ struct pmcraid_instance {
34693 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
34694
34695 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
34696 - atomic_t last_message_id;
34697 + atomic_unchecked_t last_message_id;
34698
34699 /* configuration table */
34700 struct pmcraid_config_table *cfg_table;
34701 @@ -777,7 +777,7 @@ struct pmcraid_instance {
34702 atomic_t outstanding_cmds;
34703
34704 /* should add/delete resources to mid-layer now ?*/
34705 - atomic_t expose_resources;
34706 + atomic_unchecked_t expose_resources;
34707
34708
34709
34710 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
34711 struct pmcraid_config_table_entry_ext cfg_entry_ext;
34712 };
34713 struct scsi_device *scsi_dev; /* Link scsi_device structure */
34714 - atomic_t read_failures; /* count of failed READ commands */
34715 - atomic_t write_failures; /* count of failed WRITE commands */
34716 + atomic_unchecked_t read_failures; /* count of failed READ commands */
34717 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
34718
34719 /* To indicate add/delete/modify during CCN */
34720 u8 change_detected;
34721 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
34722 index fcf052c..a8025a4 100644
34723 --- a/drivers/scsi/qla2xxx/qla_def.h
34724 +++ b/drivers/scsi/qla2xxx/qla_def.h
34725 @@ -2244,7 +2244,7 @@ struct isp_operations {
34726 int (*get_flash_version) (struct scsi_qla_host *, void *);
34727 int (*start_scsi) (srb_t *);
34728 int (*abort_isp) (struct scsi_qla_host *);
34729 -};
34730 +} __no_const;
34731
34732 /* MSI-X Support *************************************************************/
34733
34734 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
34735 index fd5edc6..4906148 100644
34736 --- a/drivers/scsi/qla4xxx/ql4_def.h
34737 +++ b/drivers/scsi/qla4xxx/ql4_def.h
34738 @@ -258,7 +258,7 @@ struct ddb_entry {
34739 * (4000 only) */
34740 atomic_t relogin_timer; /* Max Time to wait for
34741 * relogin to complete */
34742 - atomic_t relogin_retry_count; /* Num of times relogin has been
34743 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
34744 * retried */
34745 uint32_t default_time2wait; /* Default Min time between
34746 * relogins (+aens) */
34747 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
34748 index 4169c8b..a8b896b 100644
34749 --- a/drivers/scsi/qla4xxx/ql4_os.c
34750 +++ b/drivers/scsi/qla4xxx/ql4_os.c
34751 @@ -2104,12 +2104,12 @@ void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
34752 */
34753 if (!iscsi_is_session_online(cls_sess)) {
34754 /* Reset retry relogin timer */
34755 - atomic_inc(&ddb_entry->relogin_retry_count);
34756 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
34757 DEBUG2(ql4_printk(KERN_INFO, ha,
34758 "%s: index[%d] relogin timed out-retrying"
34759 " relogin (%d), retry (%d)\n", __func__,
34760 ddb_entry->fw_ddb_index,
34761 - atomic_read(&ddb_entry->relogin_retry_count),
34762 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
34763 ddb_entry->default_time2wait + 4));
34764 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
34765 atomic_set(&ddb_entry->retry_relogin_timer,
34766 @@ -3835,7 +3835,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
34767
34768 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
34769 atomic_set(&ddb_entry->relogin_timer, 0);
34770 - atomic_set(&ddb_entry->relogin_retry_count, 0);
34771 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
34772
34773 ddb_entry->default_relogin_timeout =
34774 le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
34775 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
34776 index 2aeb2e9..46e3925 100644
34777 --- a/drivers/scsi/scsi.c
34778 +++ b/drivers/scsi/scsi.c
34779 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
34780 unsigned long timeout;
34781 int rtn = 0;
34782
34783 - atomic_inc(&cmd->device->iorequest_cnt);
34784 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
34785
34786 /* check if the device is still usable */
34787 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
34788 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
34789 index f85cfa6..a57c9e8 100644
34790 --- a/drivers/scsi/scsi_lib.c
34791 +++ b/drivers/scsi/scsi_lib.c
34792 @@ -1416,7 +1416,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
34793 shost = sdev->host;
34794 scsi_init_cmd_errh(cmd);
34795 cmd->result = DID_NO_CONNECT << 16;
34796 - atomic_inc(&cmd->device->iorequest_cnt);
34797 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
34798
34799 /*
34800 * SCSI request completion path will do scsi_device_unbusy(),
34801 @@ -1442,9 +1442,9 @@ static void scsi_softirq_done(struct request *rq)
34802
34803 INIT_LIST_HEAD(&cmd->eh_entry);
34804
34805 - atomic_inc(&cmd->device->iodone_cnt);
34806 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
34807 if (cmd->result)
34808 - atomic_inc(&cmd->device->ioerr_cnt);
34809 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
34810
34811 disposition = scsi_decide_disposition(cmd);
34812 if (disposition != SUCCESS &&
34813 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
34814 index 04c2a27..9d8bd66 100644
34815 --- a/drivers/scsi/scsi_sysfs.c
34816 +++ b/drivers/scsi/scsi_sysfs.c
34817 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
34818 char *buf) \
34819 { \
34820 struct scsi_device *sdev = to_scsi_device(dev); \
34821 - unsigned long long count = atomic_read(&sdev->field); \
34822 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
34823 return snprintf(buf, 20, "0x%llx\n", count); \
34824 } \
34825 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
34826 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
34827 index 84a1fdf..693b0d6 100644
34828 --- a/drivers/scsi/scsi_tgt_lib.c
34829 +++ b/drivers/scsi/scsi_tgt_lib.c
34830 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
34831 int err;
34832
34833 dprintk("%lx %u\n", uaddr, len);
34834 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
34835 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
34836 if (err) {
34837 /*
34838 * TODO: need to fixup sg_tablesize, max_segment_size,
34839 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
34840 index 1b21491..1b7f60e 100644
34841 --- a/drivers/scsi/scsi_transport_fc.c
34842 +++ b/drivers/scsi/scsi_transport_fc.c
34843 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
34844 * Netlink Infrastructure
34845 */
34846
34847 -static atomic_t fc_event_seq;
34848 +static atomic_unchecked_t fc_event_seq;
34849
34850 /**
34851 * fc_get_event_number - Obtain the next sequential FC event number
34852 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
34853 u32
34854 fc_get_event_number(void)
34855 {
34856 - return atomic_add_return(1, &fc_event_seq);
34857 + return atomic_add_return_unchecked(1, &fc_event_seq);
34858 }
34859 EXPORT_SYMBOL(fc_get_event_number);
34860
34861 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
34862 {
34863 int error;
34864
34865 - atomic_set(&fc_event_seq, 0);
34866 + atomic_set_unchecked(&fc_event_seq, 0);
34867
34868 error = transport_class_register(&fc_host_class);
34869 if (error)
34870 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
34871 char *cp;
34872
34873 *val = simple_strtoul(buf, &cp, 0);
34874 - if ((*cp && (*cp != '\n')) || (*val < 0))
34875 + if (*cp && (*cp != '\n'))
34876 return -EINVAL;
34877 /*
34878 * Check for overflow; dev_loss_tmo is u32
34879 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
34880 index 96029e6..4d77fa0 100644
34881 --- a/drivers/scsi/scsi_transport_iscsi.c
34882 +++ b/drivers/scsi/scsi_transport_iscsi.c
34883 @@ -79,7 +79,7 @@ struct iscsi_internal {
34884 struct transport_container session_cont;
34885 };
34886
34887 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
34888 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
34889 static struct workqueue_struct *iscsi_eh_timer_workq;
34890
34891 static DEFINE_IDA(iscsi_sess_ida);
34892 @@ -1062,7 +1062,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
34893 int err;
34894
34895 ihost = shost->shost_data;
34896 - session->sid = atomic_add_return(1, &iscsi_session_nr);
34897 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
34898
34899 if (target_id == ISCSI_MAX_TARGET) {
34900 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
34901 @@ -2663,7 +2663,7 @@ static __init int iscsi_transport_init(void)
34902 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
34903 ISCSI_TRANSPORT_VERSION);
34904
34905 - atomic_set(&iscsi_session_nr, 0);
34906 + atomic_set_unchecked(&iscsi_session_nr, 0);
34907
34908 err = class_register(&iscsi_transport_class);
34909 if (err)
34910 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
34911 index 21a045e..ec89e03 100644
34912 --- a/drivers/scsi/scsi_transport_srp.c
34913 +++ b/drivers/scsi/scsi_transport_srp.c
34914 @@ -33,7 +33,7 @@
34915 #include "scsi_transport_srp_internal.h"
34916
34917 struct srp_host_attrs {
34918 - atomic_t next_port_id;
34919 + atomic_unchecked_t next_port_id;
34920 };
34921 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
34922
34923 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
34924 struct Scsi_Host *shost = dev_to_shost(dev);
34925 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
34926
34927 - atomic_set(&srp_host->next_port_id, 0);
34928 + atomic_set_unchecked(&srp_host->next_port_id, 0);
34929 return 0;
34930 }
34931
34932 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
34933 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
34934 rport->roles = ids->roles;
34935
34936 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
34937 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
34938 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
34939
34940 transport_setup_device(&rport->dev);
34941 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
34942 index fa3a591..fd96409 100644
34943 --- a/drivers/scsi/sd.c
34944 +++ b/drivers/scsi/sd.c
34945 @@ -1074,6 +1074,10 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
34946 SCSI_LOG_IOCTL(1, sd_printk(KERN_INFO, sdkp, "sd_ioctl: disk=%s, "
34947 "cmd=0x%x\n", disk->disk_name, cmd));
34948
34949 + error = scsi_verify_blk_ioctl(bdev, cmd);
34950 + if (error < 0)
34951 + return error;
34952 +
34953 /*
34954 * If we are in the middle of error recovery, don't let anyone
34955 * else try and use this device. Also, if error recovery fails, it
34956 @@ -1096,7 +1100,7 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
34957 error = scsi_ioctl(sdp, cmd, p);
34958 break;
34959 default:
34960 - error = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, p);
34961 + error = scsi_cmd_blk_ioctl(bdev, mode, cmd, p);
34962 if (error != -ENOTTY)
34963 break;
34964 error = scsi_ioctl(sdp, cmd, p);
34965 @@ -1266,6 +1270,11 @@ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
34966 unsigned int cmd, unsigned long arg)
34967 {
34968 struct scsi_device *sdev = scsi_disk(bdev->bd_disk)->device;
34969 + int ret;
34970 +
34971 + ret = scsi_verify_blk_ioctl(bdev, cmd);
34972 + if (ret < 0)
34973 + return ret;
34974
34975 /*
34976 * If we are in the middle of error recovery, don't let anyone
34977 @@ -1277,8 +1286,6 @@ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
34978 return -ENODEV;
34979
34980 if (sdev->host->hostt->compat_ioctl) {
34981 - int ret;
34982 -
34983 ret = sdev->host->hostt->compat_ioctl(sdev, cmd, (void __user *)arg);
34984
34985 return ret;
34986 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
34987 index 441a1c5..07cece7 100644
34988 --- a/drivers/scsi/sg.c
34989 +++ b/drivers/scsi/sg.c
34990 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
34991 sdp->disk->disk_name,
34992 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
34993 NULL,
34994 - (char *)arg);
34995 + (char __user *)arg);
34996 case BLKTRACESTART:
34997 return blk_trace_startstop(sdp->device->request_queue, 1);
34998 case BLKTRACESTOP:
34999 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
35000 const struct file_operations * fops;
35001 };
35002
35003 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
35004 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
35005 {"allow_dio", &adio_fops},
35006 {"debug", &debug_fops},
35007 {"def_reserved_size", &dressz_fops},
35008 @@ -2327,7 +2327,7 @@ sg_proc_init(void)
35009 {
35010 int k, mask;
35011 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
35012 - struct sg_proc_leaf * leaf;
35013 + const struct sg_proc_leaf * leaf;
35014
35015 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
35016 if (!sg_proc_sgp)
35017 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
35018 index f64250e..1ee3049 100644
35019 --- a/drivers/spi/spi-dw-pci.c
35020 +++ b/drivers/spi/spi-dw-pci.c
35021 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
35022 #define spi_resume NULL
35023 #endif
35024
35025 -static const struct pci_device_id pci_ids[] __devinitdata = {
35026 +static const struct pci_device_id pci_ids[] __devinitconst = {
35027 /* Intel MID platform SPI controller 0 */
35028 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
35029 {},
35030 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
35031 index 77eae99..b7cdcc9 100644
35032 --- a/drivers/spi/spi.c
35033 +++ b/drivers/spi/spi.c
35034 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
35035 EXPORT_SYMBOL_GPL(spi_bus_unlock);
35036
35037 /* portable code must never pass more than 32 bytes */
35038 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
35039 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
35040
35041 static u8 *buf;
35042
35043 diff --git a/drivers/staging/gma500/power.c b/drivers/staging/gma500/power.c
35044 index 436fe97..4082570 100644
35045 --- a/drivers/staging/gma500/power.c
35046 +++ b/drivers/staging/gma500/power.c
35047 @@ -266,7 +266,7 @@ bool gma_power_begin(struct drm_device *dev, bool force_on)
35048 ret = gma_resume_pci(dev->pdev);
35049 if (ret == 0) {
35050 /* FIXME: we want to defer this for Medfield/Oaktrail */
35051 - gma_resume_display(dev);
35052 + gma_resume_display(dev->pdev);
35053 psb_irq_preinstall(dev);
35054 psb_irq_postinstall(dev);
35055 pm_runtime_get(&dev->pdev->dev);
35056 diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c
35057 index bafccb3..e3ac78d 100644
35058 --- a/drivers/staging/hv/rndis_filter.c
35059 +++ b/drivers/staging/hv/rndis_filter.c
35060 @@ -42,7 +42,7 @@ struct rndis_device {
35061
35062 enum rndis_device_state state;
35063 bool link_state;
35064 - atomic_t new_req_id;
35065 + atomic_unchecked_t new_req_id;
35066
35067 spinlock_t request_lock;
35068 struct list_head req_list;
35069 @@ -116,7 +116,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35070 * template
35071 */
35072 set = &rndis_msg->msg.set_req;
35073 - set->req_id = atomic_inc_return(&dev->new_req_id);
35074 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35075
35076 /* Add to the request list */
35077 spin_lock_irqsave(&dev->request_lock, flags);
35078 @@ -646,7 +646,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35079
35080 /* Setup the rndis set */
35081 halt = &request->request_msg.msg.halt_req;
35082 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35083 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35084
35085 /* Ignore return since this msg is optional. */
35086 rndis_filter_send_request(dev, request);
35087 diff --git a/drivers/staging/iio/buffer_generic.h b/drivers/staging/iio/buffer_generic.h
35088 index 9e8f010..af9efb5 100644
35089 --- a/drivers/staging/iio/buffer_generic.h
35090 +++ b/drivers/staging/iio/buffer_generic.h
35091 @@ -64,7 +64,7 @@ struct iio_buffer_access_funcs {
35092
35093 int (*is_enabled)(struct iio_buffer *buffer);
35094 int (*enable)(struct iio_buffer *buffer);
35095 -};
35096 +} __no_const;
35097
35098 /**
35099 * struct iio_buffer_setup_ops - buffer setup related callbacks
35100 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
35101 index 8b307b4..a97ac91 100644
35102 --- a/drivers/staging/octeon/ethernet-rx.c
35103 +++ b/drivers/staging/octeon/ethernet-rx.c
35104 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
35105 /* Increment RX stats for virtual ports */
35106 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
35107 #ifdef CONFIG_64BIT
35108 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
35109 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
35110 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
35111 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
35112 #else
35113 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
35114 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
35115 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
35116 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
35117 #endif
35118 }
35119 netif_receive_skb(skb);
35120 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
35121 dev->name);
35122 */
35123 #ifdef CONFIG_64BIT
35124 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
35125 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
35126 #else
35127 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
35128 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
35129 #endif
35130 dev_kfree_skb_irq(skb);
35131 }
35132 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
35133 index 076f866..2308070 100644
35134 --- a/drivers/staging/octeon/ethernet.c
35135 +++ b/drivers/staging/octeon/ethernet.c
35136 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
35137 * since the RX tasklet also increments it.
35138 */
35139 #ifdef CONFIG_64BIT
35140 - atomic64_add(rx_status.dropped_packets,
35141 - (atomic64_t *)&priv->stats.rx_dropped);
35142 + atomic64_add_unchecked(rx_status.dropped_packets,
35143 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
35144 #else
35145 - atomic_add(rx_status.dropped_packets,
35146 - (atomic_t *)&priv->stats.rx_dropped);
35147 + atomic_add_unchecked(rx_status.dropped_packets,
35148 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
35149 #endif
35150 }
35151
35152 diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
35153 index 7a19555..466456d 100644
35154 --- a/drivers/staging/pohmelfs/inode.c
35155 +++ b/drivers/staging/pohmelfs/inode.c
35156 @@ -1861,7 +1861,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
35157 mutex_init(&psb->mcache_lock);
35158 psb->mcache_root = RB_ROOT;
35159 psb->mcache_timeout = msecs_to_jiffies(5000);
35160 - atomic_long_set(&psb->mcache_gen, 0);
35161 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
35162
35163 psb->trans_max_pages = 100;
35164
35165 @@ -1876,7 +1876,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
35166 INIT_LIST_HEAD(&psb->crypto_ready_list);
35167 INIT_LIST_HEAD(&psb->crypto_active_list);
35168
35169 - atomic_set(&psb->trans_gen, 1);
35170 + atomic_set_unchecked(&psb->trans_gen, 1);
35171 atomic_long_set(&psb->total_inodes, 0);
35172
35173 mutex_init(&psb->state_lock);
35174 diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
35175 index e22665c..a2a9390 100644
35176 --- a/drivers/staging/pohmelfs/mcache.c
35177 +++ b/drivers/staging/pohmelfs/mcache.c
35178 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
35179 m->data = data;
35180 m->start = start;
35181 m->size = size;
35182 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
35183 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
35184
35185 mutex_lock(&psb->mcache_lock);
35186 err = pohmelfs_mcache_insert(psb, m);
35187 diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
35188 index 985b6b7..7699e05 100644
35189 --- a/drivers/staging/pohmelfs/netfs.h
35190 +++ b/drivers/staging/pohmelfs/netfs.h
35191 @@ -571,14 +571,14 @@ struct pohmelfs_config;
35192 struct pohmelfs_sb {
35193 struct rb_root mcache_root;
35194 struct mutex mcache_lock;
35195 - atomic_long_t mcache_gen;
35196 + atomic_long_unchecked_t mcache_gen;
35197 unsigned long mcache_timeout;
35198
35199 unsigned int idx;
35200
35201 unsigned int trans_retries;
35202
35203 - atomic_t trans_gen;
35204 + atomic_unchecked_t trans_gen;
35205
35206 unsigned int crypto_attached_size;
35207 unsigned int crypto_align_size;
35208 diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
35209 index 06c1a74..866eebc 100644
35210 --- a/drivers/staging/pohmelfs/trans.c
35211 +++ b/drivers/staging/pohmelfs/trans.c
35212 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
35213 int err;
35214 struct netfs_cmd *cmd = t->iovec.iov_base;
35215
35216 - t->gen = atomic_inc_return(&psb->trans_gen);
35217 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
35218
35219 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
35220 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
35221 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
35222 index 86308a0..feaa925 100644
35223 --- a/drivers/staging/rtl8712/rtl871x_io.h
35224 +++ b/drivers/staging/rtl8712/rtl871x_io.h
35225 @@ -108,7 +108,7 @@ struct _io_ops {
35226 u8 *pmem);
35227 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
35228 u8 *pmem);
35229 -};
35230 +} __no_const;
35231
35232 struct io_req {
35233 struct list_head list;
35234 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
35235 index c7b5e8b..783d6cb 100644
35236 --- a/drivers/staging/sbe-2t3e3/netdev.c
35237 +++ b/drivers/staging/sbe-2t3e3/netdev.c
35238 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35239 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
35240
35241 if (rlen)
35242 - if (copy_to_user(data, &resp, rlen))
35243 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
35244 return -EFAULT;
35245
35246 return 0;
35247 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
35248 index be21617..0954e45 100644
35249 --- a/drivers/staging/usbip/usbip_common.h
35250 +++ b/drivers/staging/usbip/usbip_common.h
35251 @@ -289,7 +289,7 @@ struct usbip_device {
35252 void (*shutdown)(struct usbip_device *);
35253 void (*reset)(struct usbip_device *);
35254 void (*unusable)(struct usbip_device *);
35255 - } eh_ops;
35256 + } __no_const eh_ops;
35257 };
35258
35259 #if 0
35260 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
35261 index 88b3298..3783eee 100644
35262 --- a/drivers/staging/usbip/vhci.h
35263 +++ b/drivers/staging/usbip/vhci.h
35264 @@ -88,7 +88,7 @@ struct vhci_hcd {
35265 unsigned resuming:1;
35266 unsigned long re_timeout;
35267
35268 - atomic_t seqnum;
35269 + atomic_unchecked_t seqnum;
35270
35271 /*
35272 * NOTE:
35273 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
35274 index 2ee97e2..0420b86 100644
35275 --- a/drivers/staging/usbip/vhci_hcd.c
35276 +++ b/drivers/staging/usbip/vhci_hcd.c
35277 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
35278 return;
35279 }
35280
35281 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
35282 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
35283 if (priv->seqnum == 0xffff)
35284 dev_info(&urb->dev->dev, "seqnum max\n");
35285
35286 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
35287 return -ENOMEM;
35288 }
35289
35290 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
35291 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
35292 if (unlink->seqnum == 0xffff)
35293 pr_info("seqnum max\n");
35294
35295 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
35296 vdev->rhport = rhport;
35297 }
35298
35299 - atomic_set(&vhci->seqnum, 0);
35300 + atomic_set_unchecked(&vhci->seqnum, 0);
35301 spin_lock_init(&vhci->lock);
35302
35303 hcd->power_budget = 0; /* no limit */
35304 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
35305 index 3872b8c..fe6d2f4 100644
35306 --- a/drivers/staging/usbip/vhci_rx.c
35307 +++ b/drivers/staging/usbip/vhci_rx.c
35308 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
35309 if (!urb) {
35310 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
35311 pr_info("max seqnum %d\n",
35312 - atomic_read(&the_controller->seqnum));
35313 + atomic_read_unchecked(&the_controller->seqnum));
35314 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
35315 return;
35316 }
35317 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
35318 index 7735027..30eed13 100644
35319 --- a/drivers/staging/vt6655/hostap.c
35320 +++ b/drivers/staging/vt6655/hostap.c
35321 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
35322 *
35323 */
35324
35325 +static net_device_ops_no_const apdev_netdev_ops;
35326 +
35327 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35328 {
35329 PSDevice apdev_priv;
35330 struct net_device *dev = pDevice->dev;
35331 int ret;
35332 - const struct net_device_ops apdev_netdev_ops = {
35333 - .ndo_start_xmit = pDevice->tx_80211,
35334 - };
35335
35336 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
35337
35338 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35339 *apdev_priv = *pDevice;
35340 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
35341
35342 + /* only half broken now */
35343 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
35344 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
35345
35346 pDevice->apdev->type = ARPHRD_IEEE80211;
35347 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
35348 index 51b5adf..098e320 100644
35349 --- a/drivers/staging/vt6656/hostap.c
35350 +++ b/drivers/staging/vt6656/hostap.c
35351 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
35352 *
35353 */
35354
35355 +static net_device_ops_no_const apdev_netdev_ops;
35356 +
35357 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35358 {
35359 PSDevice apdev_priv;
35360 struct net_device *dev = pDevice->dev;
35361 int ret;
35362 - const struct net_device_ops apdev_netdev_ops = {
35363 - .ndo_start_xmit = pDevice->tx_80211,
35364 - };
35365
35366 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
35367
35368 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35369 *apdev_priv = *pDevice;
35370 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
35371
35372 + /* only half broken now */
35373 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
35374 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
35375
35376 pDevice->apdev->type = ARPHRD_IEEE80211;
35377 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
35378 index 7843dfd..3db105f 100644
35379 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
35380 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
35381 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
35382
35383 struct usbctlx_completor {
35384 int (*complete) (struct usbctlx_completor *);
35385 -};
35386 +} __no_const;
35387
35388 static int
35389 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
35390 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
35391 index 1ca66ea..76f1343 100644
35392 --- a/drivers/staging/zcache/tmem.c
35393 +++ b/drivers/staging/zcache/tmem.c
35394 @@ -39,7 +39,7 @@
35395 * A tmem host implementation must use this function to register callbacks
35396 * for memory allocation.
35397 */
35398 -static struct tmem_hostops tmem_hostops;
35399 +static tmem_hostops_no_const tmem_hostops;
35400
35401 static void tmem_objnode_tree_init(void);
35402
35403 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
35404 * A tmem host implementation must use this function to register
35405 * callbacks for a page-accessible memory (PAM) implementation
35406 */
35407 -static struct tmem_pamops tmem_pamops;
35408 +static tmem_pamops_no_const tmem_pamops;
35409
35410 void tmem_register_pamops(struct tmem_pamops *m)
35411 {
35412 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
35413 index ed147c4..94fc3c6 100644
35414 --- a/drivers/staging/zcache/tmem.h
35415 +++ b/drivers/staging/zcache/tmem.h
35416 @@ -180,6 +180,7 @@ struct tmem_pamops {
35417 void (*new_obj)(struct tmem_obj *);
35418 int (*replace_in_obj)(void *, struct tmem_obj *);
35419 };
35420 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
35421 extern void tmem_register_pamops(struct tmem_pamops *m);
35422
35423 /* memory allocation methods provided by the host implementation */
35424 @@ -189,6 +190,7 @@ struct tmem_hostops {
35425 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
35426 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
35427 };
35428 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
35429 extern void tmem_register_hostops(struct tmem_hostops *m);
35430
35431 /* core tmem accessor functions */
35432 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
35433 index 8599545..7761358 100644
35434 --- a/drivers/target/iscsi/iscsi_target.c
35435 +++ b/drivers/target/iscsi/iscsi_target.c
35436 @@ -1364,7 +1364,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
35437 * outstanding_r2ts reaches zero, go ahead and send the delayed
35438 * TASK_ABORTED status.
35439 */
35440 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
35441 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
35442 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
35443 if (--cmd->outstanding_r2ts < 1) {
35444 iscsit_stop_dataout_timer(cmd);
35445 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
35446 index 6845228..df77141 100644
35447 --- a/drivers/target/target_core_tmr.c
35448 +++ b/drivers/target/target_core_tmr.c
35449 @@ -250,7 +250,7 @@ static void core_tmr_drain_task_list(
35450 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
35451 cmd->t_task_list_num,
35452 atomic_read(&cmd->t_task_cdbs_left),
35453 - atomic_read(&cmd->t_task_cdbs_sent),
35454 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
35455 atomic_read(&cmd->t_transport_active),
35456 atomic_read(&cmd->t_transport_stop),
35457 atomic_read(&cmd->t_transport_sent));
35458 @@ -281,7 +281,7 @@ static void core_tmr_drain_task_list(
35459 pr_debug("LUN_RESET: got t_transport_active = 1 for"
35460 " task: %p, t_fe_count: %d dev: %p\n", task,
35461 fe_count, dev);
35462 - atomic_set(&cmd->t_transport_aborted, 1);
35463 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
35464 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35465
35466 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
35467 @@ -289,7 +289,7 @@ static void core_tmr_drain_task_list(
35468 }
35469 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
35470 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
35471 - atomic_set(&cmd->t_transport_aborted, 1);
35472 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
35473 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35474
35475 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
35476 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
35477 index 0257658..09433d5 100644
35478 --- a/drivers/target/target_core_transport.c
35479 +++ b/drivers/target/target_core_transport.c
35480 @@ -1343,7 +1343,7 @@ struct se_device *transport_add_device_to_core_hba(
35481
35482 dev->queue_depth = dev_limits->queue_depth;
35483 atomic_set(&dev->depth_left, dev->queue_depth);
35484 - atomic_set(&dev->dev_ordered_id, 0);
35485 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
35486
35487 se_dev_set_default_attribs(dev, dev_limits);
35488
35489 @@ -1530,7 +1530,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
35490 * Used to determine when ORDERED commands should go from
35491 * Dormant to Active status.
35492 */
35493 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
35494 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
35495 smp_mb__after_atomic_inc();
35496 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
35497 cmd->se_ordered_id, cmd->sam_task_attr,
35498 @@ -1800,7 +1800,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
35499 " t_transport_active: %d t_transport_stop: %d"
35500 " t_transport_sent: %d\n", cmd->t_task_list_num,
35501 atomic_read(&cmd->t_task_cdbs_left),
35502 - atomic_read(&cmd->t_task_cdbs_sent),
35503 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
35504 atomic_read(&cmd->t_task_cdbs_ex_left),
35505 atomic_read(&cmd->t_transport_active),
35506 atomic_read(&cmd->t_transport_stop),
35507 @@ -2089,9 +2089,9 @@ check_depth:
35508
35509 spin_lock_irqsave(&cmd->t_state_lock, flags);
35510 task->task_flags |= (TF_ACTIVE | TF_SENT);
35511 - atomic_inc(&cmd->t_task_cdbs_sent);
35512 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
35513
35514 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
35515 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
35516 cmd->t_task_list_num)
35517 atomic_set(&cmd->t_transport_sent, 1);
35518
35519 @@ -4260,7 +4260,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
35520 atomic_set(&cmd->transport_lun_stop, 0);
35521 }
35522 if (!atomic_read(&cmd->t_transport_active) ||
35523 - atomic_read(&cmd->t_transport_aborted)) {
35524 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
35525 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35526 return false;
35527 }
35528 @@ -4495,7 +4495,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
35529 {
35530 int ret = 0;
35531
35532 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
35533 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
35534 if (!send_status ||
35535 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
35536 return 1;
35537 @@ -4532,7 +4532,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
35538 */
35539 if (cmd->data_direction == DMA_TO_DEVICE) {
35540 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
35541 - atomic_inc(&cmd->t_transport_aborted);
35542 + atomic_inc_unchecked(&cmd->t_transport_aborted);
35543 smp_mb__after_atomic_inc();
35544 }
35545 }
35546 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
35547 index b9040be..e3f5aab 100644
35548 --- a/drivers/tty/hvc/hvcs.c
35549 +++ b/drivers/tty/hvc/hvcs.c
35550 @@ -83,6 +83,7 @@
35551 #include <asm/hvcserver.h>
35552 #include <asm/uaccess.h>
35553 #include <asm/vio.h>
35554 +#include <asm/local.h>
35555
35556 /*
35557 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
35558 @@ -270,7 +271,7 @@ struct hvcs_struct {
35559 unsigned int index;
35560
35561 struct tty_struct *tty;
35562 - int open_count;
35563 + local_t open_count;
35564
35565 /*
35566 * Used to tell the driver kernel_thread what operations need to take
35567 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
35568
35569 spin_lock_irqsave(&hvcsd->lock, flags);
35570
35571 - if (hvcsd->open_count > 0) {
35572 + if (local_read(&hvcsd->open_count) > 0) {
35573 spin_unlock_irqrestore(&hvcsd->lock, flags);
35574 printk(KERN_INFO "HVCS: vterm state unchanged. "
35575 "The hvcs device node is still in use.\n");
35576 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
35577 if ((retval = hvcs_partner_connect(hvcsd)))
35578 goto error_release;
35579
35580 - hvcsd->open_count = 1;
35581 + local_set(&hvcsd->open_count, 1);
35582 hvcsd->tty = tty;
35583 tty->driver_data = hvcsd;
35584
35585 @@ -1179,7 +1180,7 @@ fast_open:
35586
35587 spin_lock_irqsave(&hvcsd->lock, flags);
35588 kref_get(&hvcsd->kref);
35589 - hvcsd->open_count++;
35590 + local_inc(&hvcsd->open_count);
35591 hvcsd->todo_mask |= HVCS_SCHED_READ;
35592 spin_unlock_irqrestore(&hvcsd->lock, flags);
35593
35594 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
35595 hvcsd = tty->driver_data;
35596
35597 spin_lock_irqsave(&hvcsd->lock, flags);
35598 - if (--hvcsd->open_count == 0) {
35599 + if (local_dec_and_test(&hvcsd->open_count)) {
35600
35601 vio_disable_interrupts(hvcsd->vdev);
35602
35603 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
35604 free_irq(irq, hvcsd);
35605 kref_put(&hvcsd->kref, destroy_hvcs_struct);
35606 return;
35607 - } else if (hvcsd->open_count < 0) {
35608 + } else if (local_read(&hvcsd->open_count) < 0) {
35609 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
35610 " is missmanaged.\n",
35611 - hvcsd->vdev->unit_address, hvcsd->open_count);
35612 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
35613 }
35614
35615 spin_unlock_irqrestore(&hvcsd->lock, flags);
35616 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
35617
35618 spin_lock_irqsave(&hvcsd->lock, flags);
35619 /* Preserve this so that we know how many kref refs to put */
35620 - temp_open_count = hvcsd->open_count;
35621 + temp_open_count = local_read(&hvcsd->open_count);
35622
35623 /*
35624 * Don't kref put inside the spinlock because the destruction
35625 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
35626 hvcsd->tty->driver_data = NULL;
35627 hvcsd->tty = NULL;
35628
35629 - hvcsd->open_count = 0;
35630 + local_set(&hvcsd->open_count, 0);
35631
35632 /* This will drop any buffered data on the floor which is OK in a hangup
35633 * scenario. */
35634 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
35635 * the middle of a write operation? This is a crummy place to do this
35636 * but we want to keep it all in the spinlock.
35637 */
35638 - if (hvcsd->open_count <= 0) {
35639 + if (local_read(&hvcsd->open_count) <= 0) {
35640 spin_unlock_irqrestore(&hvcsd->lock, flags);
35641 return -ENODEV;
35642 }
35643 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
35644 {
35645 struct hvcs_struct *hvcsd = tty->driver_data;
35646
35647 - if (!hvcsd || hvcsd->open_count <= 0)
35648 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
35649 return 0;
35650
35651 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
35652 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
35653 index ef92869..f4ebd88 100644
35654 --- a/drivers/tty/ipwireless/tty.c
35655 +++ b/drivers/tty/ipwireless/tty.c
35656 @@ -29,6 +29,7 @@
35657 #include <linux/tty_driver.h>
35658 #include <linux/tty_flip.h>
35659 #include <linux/uaccess.h>
35660 +#include <asm/local.h>
35661
35662 #include "tty.h"
35663 #include "network.h"
35664 @@ -51,7 +52,7 @@ struct ipw_tty {
35665 int tty_type;
35666 struct ipw_network *network;
35667 struct tty_struct *linux_tty;
35668 - int open_count;
35669 + local_t open_count;
35670 unsigned int control_lines;
35671 struct mutex ipw_tty_mutex;
35672 int tx_bytes_queued;
35673 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
35674 mutex_unlock(&tty->ipw_tty_mutex);
35675 return -ENODEV;
35676 }
35677 - if (tty->open_count == 0)
35678 + if (local_read(&tty->open_count) == 0)
35679 tty->tx_bytes_queued = 0;
35680
35681 - tty->open_count++;
35682 + local_inc(&tty->open_count);
35683
35684 tty->linux_tty = linux_tty;
35685 linux_tty->driver_data = tty;
35686 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
35687
35688 static void do_ipw_close(struct ipw_tty *tty)
35689 {
35690 - tty->open_count--;
35691 -
35692 - if (tty->open_count == 0) {
35693 + if (local_dec_return(&tty->open_count) == 0) {
35694 struct tty_struct *linux_tty = tty->linux_tty;
35695
35696 if (linux_tty != NULL) {
35697 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
35698 return;
35699
35700 mutex_lock(&tty->ipw_tty_mutex);
35701 - if (tty->open_count == 0) {
35702 + if (local_read(&tty->open_count) == 0) {
35703 mutex_unlock(&tty->ipw_tty_mutex);
35704 return;
35705 }
35706 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
35707 return;
35708 }
35709
35710 - if (!tty->open_count) {
35711 + if (!local_read(&tty->open_count)) {
35712 mutex_unlock(&tty->ipw_tty_mutex);
35713 return;
35714 }
35715 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
35716 return -ENODEV;
35717
35718 mutex_lock(&tty->ipw_tty_mutex);
35719 - if (!tty->open_count) {
35720 + if (!local_read(&tty->open_count)) {
35721 mutex_unlock(&tty->ipw_tty_mutex);
35722 return -EINVAL;
35723 }
35724 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
35725 if (!tty)
35726 return -ENODEV;
35727
35728 - if (!tty->open_count)
35729 + if (!local_read(&tty->open_count))
35730 return -EINVAL;
35731
35732 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
35733 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
35734 if (!tty)
35735 return 0;
35736
35737 - if (!tty->open_count)
35738 + if (!local_read(&tty->open_count))
35739 return 0;
35740
35741 return tty->tx_bytes_queued;
35742 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
35743 if (!tty)
35744 return -ENODEV;
35745
35746 - if (!tty->open_count)
35747 + if (!local_read(&tty->open_count))
35748 return -EINVAL;
35749
35750 return get_control_lines(tty);
35751 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
35752 if (!tty)
35753 return -ENODEV;
35754
35755 - if (!tty->open_count)
35756 + if (!local_read(&tty->open_count))
35757 return -EINVAL;
35758
35759 return set_control_lines(tty, set, clear);
35760 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
35761 if (!tty)
35762 return -ENODEV;
35763
35764 - if (!tty->open_count)
35765 + if (!local_read(&tty->open_count))
35766 return -EINVAL;
35767
35768 /* FIXME: Exactly how is the tty object locked here .. */
35769 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
35770 against a parallel ioctl etc */
35771 mutex_lock(&ttyj->ipw_tty_mutex);
35772 }
35773 - while (ttyj->open_count)
35774 + while (local_read(&ttyj->open_count))
35775 do_ipw_close(ttyj);
35776 ipwireless_disassociate_network_ttys(network,
35777 ttyj->channel_idx);
35778 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
35779 index fc7bbba..9527e93 100644
35780 --- a/drivers/tty/n_gsm.c
35781 +++ b/drivers/tty/n_gsm.c
35782 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
35783 kref_init(&dlci->ref);
35784 mutex_init(&dlci->mutex);
35785 dlci->fifo = &dlci->_fifo;
35786 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
35787 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
35788 kfree(dlci);
35789 return NULL;
35790 }
35791 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
35792 index 39d6ab6..eb97f41 100644
35793 --- a/drivers/tty/n_tty.c
35794 +++ b/drivers/tty/n_tty.c
35795 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
35796 {
35797 *ops = tty_ldisc_N_TTY;
35798 ops->owner = NULL;
35799 - ops->refcount = ops->flags = 0;
35800 + atomic_set(&ops->refcount, 0);
35801 + ops->flags = 0;
35802 }
35803 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
35804 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
35805 index e18604b..a7d5a11 100644
35806 --- a/drivers/tty/pty.c
35807 +++ b/drivers/tty/pty.c
35808 @@ -773,8 +773,10 @@ static void __init unix98_pty_init(void)
35809 register_sysctl_table(pty_root_table);
35810
35811 /* Now create the /dev/ptmx special device */
35812 + pax_open_kernel();
35813 tty_default_fops(&ptmx_fops);
35814 - ptmx_fops.open = ptmx_open;
35815 + *(void **)&ptmx_fops.open = ptmx_open;
35816 + pax_close_kernel();
35817
35818 cdev_init(&ptmx_cdev, &ptmx_fops);
35819 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
35820 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
35821 index 2b42a01..32a2ed3 100644
35822 --- a/drivers/tty/serial/kgdboc.c
35823 +++ b/drivers/tty/serial/kgdboc.c
35824 @@ -24,8 +24,9 @@
35825 #define MAX_CONFIG_LEN 40
35826
35827 static struct kgdb_io kgdboc_io_ops;
35828 +static struct kgdb_io kgdboc_io_ops_console;
35829
35830 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
35831 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
35832 static int configured = -1;
35833
35834 static char config[MAX_CONFIG_LEN];
35835 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
35836 kgdboc_unregister_kbd();
35837 if (configured == 1)
35838 kgdb_unregister_io_module(&kgdboc_io_ops);
35839 + else if (configured == 2)
35840 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
35841 }
35842
35843 static int configure_kgdboc(void)
35844 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
35845 int err;
35846 char *cptr = config;
35847 struct console *cons;
35848 + int is_console = 0;
35849
35850 err = kgdboc_option_setup(config);
35851 if (err || !strlen(config) || isspace(config[0]))
35852 goto noconfig;
35853
35854 err = -ENODEV;
35855 - kgdboc_io_ops.is_console = 0;
35856 kgdb_tty_driver = NULL;
35857
35858 kgdboc_use_kms = 0;
35859 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
35860 int idx;
35861 if (cons->device && cons->device(cons, &idx) == p &&
35862 idx == tty_line) {
35863 - kgdboc_io_ops.is_console = 1;
35864 + is_console = 1;
35865 break;
35866 }
35867 cons = cons->next;
35868 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
35869 kgdb_tty_line = tty_line;
35870
35871 do_register:
35872 - err = kgdb_register_io_module(&kgdboc_io_ops);
35873 + if (is_console) {
35874 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
35875 + configured = 2;
35876 + } else {
35877 + err = kgdb_register_io_module(&kgdboc_io_ops);
35878 + configured = 1;
35879 + }
35880 if (err)
35881 goto noconfig;
35882
35883 - configured = 1;
35884 -
35885 return 0;
35886
35887 noconfig:
35888 @@ -213,7 +220,7 @@ noconfig:
35889 static int __init init_kgdboc(void)
35890 {
35891 /* Already configured? */
35892 - if (configured == 1)
35893 + if (configured >= 1)
35894 return 0;
35895
35896 return configure_kgdboc();
35897 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
35898 if (config[len - 1] == '\n')
35899 config[len - 1] = '\0';
35900
35901 - if (configured == 1)
35902 + if (configured >= 1)
35903 cleanup_kgdboc();
35904
35905 /* Go and configure with the new params. */
35906 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
35907 .post_exception = kgdboc_post_exp_handler,
35908 };
35909
35910 +static struct kgdb_io kgdboc_io_ops_console = {
35911 + .name = "kgdboc",
35912 + .read_char = kgdboc_get_char,
35913 + .write_char = kgdboc_put_char,
35914 + .pre_exception = kgdboc_pre_exp_handler,
35915 + .post_exception = kgdboc_post_exp_handler,
35916 + .is_console = 1
35917 +};
35918 +
35919 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
35920 /* This is only available if kgdboc is a built in for early debugging */
35921 static int __init kgdboc_early_init(char *opt)
35922 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
35923 index 05085be..67eadb0 100644
35924 --- a/drivers/tty/tty_io.c
35925 +++ b/drivers/tty/tty_io.c
35926 @@ -3240,7 +3240,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
35927
35928 void tty_default_fops(struct file_operations *fops)
35929 {
35930 - *fops = tty_fops;
35931 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
35932 }
35933
35934 /*
35935 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
35936 index 8e0924f..4204eb4 100644
35937 --- a/drivers/tty/tty_ldisc.c
35938 +++ b/drivers/tty/tty_ldisc.c
35939 @@ -75,7 +75,7 @@ static void put_ldisc(struct tty_ldisc *ld)
35940 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
35941 struct tty_ldisc_ops *ldo = ld->ops;
35942
35943 - ldo->refcount--;
35944 + atomic_dec(&ldo->refcount);
35945 module_put(ldo->owner);
35946 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
35947
35948 @@ -110,7 +110,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
35949 spin_lock_irqsave(&tty_ldisc_lock, flags);
35950 tty_ldiscs[disc] = new_ldisc;
35951 new_ldisc->num = disc;
35952 - new_ldisc->refcount = 0;
35953 + atomic_set(&new_ldisc->refcount, 0);
35954 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
35955
35956 return ret;
35957 @@ -138,7 +138,7 @@ int tty_unregister_ldisc(int disc)
35958 return -EINVAL;
35959
35960 spin_lock_irqsave(&tty_ldisc_lock, flags);
35961 - if (tty_ldiscs[disc]->refcount)
35962 + if (atomic_read(&tty_ldiscs[disc]->refcount))
35963 ret = -EBUSY;
35964 else
35965 tty_ldiscs[disc] = NULL;
35966 @@ -159,7 +159,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
35967 if (ldops) {
35968 ret = ERR_PTR(-EAGAIN);
35969 if (try_module_get(ldops->owner)) {
35970 - ldops->refcount++;
35971 + atomic_inc(&ldops->refcount);
35972 ret = ldops;
35973 }
35974 }
35975 @@ -172,7 +172,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
35976 unsigned long flags;
35977
35978 spin_lock_irqsave(&tty_ldisc_lock, flags);
35979 - ldops->refcount--;
35980 + atomic_dec(&ldops->refcount);
35981 module_put(ldops->owner);
35982 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
35983 }
35984 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
35985 index a605549..6bd3c96 100644
35986 --- a/drivers/tty/vt/keyboard.c
35987 +++ b/drivers/tty/vt/keyboard.c
35988 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
35989 kbd->kbdmode == VC_OFF) &&
35990 value != KVAL(K_SAK))
35991 return; /* SAK is allowed even in raw mode */
35992 +
35993 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
35994 + {
35995 + void *func = fn_handler[value];
35996 + if (func == fn_show_state || func == fn_show_ptregs ||
35997 + func == fn_show_mem)
35998 + return;
35999 + }
36000 +#endif
36001 +
36002 fn_handler[value](vc);
36003 }
36004
36005 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
36006 index 5e096f4..0da1363 100644
36007 --- a/drivers/tty/vt/vt_ioctl.c
36008 +++ b/drivers/tty/vt/vt_ioctl.c
36009 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
36010 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
36011 return -EFAULT;
36012
36013 - if (!capable(CAP_SYS_TTY_CONFIG))
36014 - perm = 0;
36015 -
36016 switch (cmd) {
36017 case KDGKBENT:
36018 key_map = key_maps[s];
36019 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
36020 val = (i ? K_HOLE : K_NOSUCHMAP);
36021 return put_user(val, &user_kbe->kb_value);
36022 case KDSKBENT:
36023 + if (!capable(CAP_SYS_TTY_CONFIG))
36024 + perm = 0;
36025 +
36026 if (!perm)
36027 return -EPERM;
36028 if (!i && v == K_NOSUCHMAP) {
36029 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
36030 int i, j, k;
36031 int ret;
36032
36033 - if (!capable(CAP_SYS_TTY_CONFIG))
36034 - perm = 0;
36035 -
36036 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
36037 if (!kbs) {
36038 ret = -ENOMEM;
36039 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
36040 kfree(kbs);
36041 return ((p && *p) ? -EOVERFLOW : 0);
36042 case KDSKBSENT:
36043 + if (!capable(CAP_SYS_TTY_CONFIG))
36044 + perm = 0;
36045 +
36046 if (!perm) {
36047 ret = -EPERM;
36048 goto reterr;
36049 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
36050 index a783d53..cb30d94 100644
36051 --- a/drivers/uio/uio.c
36052 +++ b/drivers/uio/uio.c
36053 @@ -25,6 +25,7 @@
36054 #include <linux/kobject.h>
36055 #include <linux/cdev.h>
36056 #include <linux/uio_driver.h>
36057 +#include <asm/local.h>
36058
36059 #define UIO_MAX_DEVICES (1U << MINORBITS)
36060
36061 @@ -32,10 +33,10 @@ struct uio_device {
36062 struct module *owner;
36063 struct device *dev;
36064 int minor;
36065 - atomic_t event;
36066 + atomic_unchecked_t event;
36067 struct fasync_struct *async_queue;
36068 wait_queue_head_t wait;
36069 - int vma_count;
36070 + local_t vma_count;
36071 struct uio_info *info;
36072 struct kobject *map_dir;
36073 struct kobject *portio_dir;
36074 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
36075 struct device_attribute *attr, char *buf)
36076 {
36077 struct uio_device *idev = dev_get_drvdata(dev);
36078 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
36079 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
36080 }
36081
36082 static struct device_attribute uio_class_attributes[] = {
36083 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
36084 {
36085 struct uio_device *idev = info->uio_dev;
36086
36087 - atomic_inc(&idev->event);
36088 + atomic_inc_unchecked(&idev->event);
36089 wake_up_interruptible(&idev->wait);
36090 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
36091 }
36092 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
36093 }
36094
36095 listener->dev = idev;
36096 - listener->event_count = atomic_read(&idev->event);
36097 + listener->event_count = atomic_read_unchecked(&idev->event);
36098 filep->private_data = listener;
36099
36100 if (idev->info->open) {
36101 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
36102 return -EIO;
36103
36104 poll_wait(filep, &idev->wait, wait);
36105 - if (listener->event_count != atomic_read(&idev->event))
36106 + if (listener->event_count != atomic_read_unchecked(&idev->event))
36107 return POLLIN | POLLRDNORM;
36108 return 0;
36109 }
36110 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
36111 do {
36112 set_current_state(TASK_INTERRUPTIBLE);
36113
36114 - event_count = atomic_read(&idev->event);
36115 + event_count = atomic_read_unchecked(&idev->event);
36116 if (event_count != listener->event_count) {
36117 if (copy_to_user(buf, &event_count, count))
36118 retval = -EFAULT;
36119 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
36120 static void uio_vma_open(struct vm_area_struct *vma)
36121 {
36122 struct uio_device *idev = vma->vm_private_data;
36123 - idev->vma_count++;
36124 + local_inc(&idev->vma_count);
36125 }
36126
36127 static void uio_vma_close(struct vm_area_struct *vma)
36128 {
36129 struct uio_device *idev = vma->vm_private_data;
36130 - idev->vma_count--;
36131 + local_dec(&idev->vma_count);
36132 }
36133
36134 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36135 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
36136 idev->owner = owner;
36137 idev->info = info;
36138 init_waitqueue_head(&idev->wait);
36139 - atomic_set(&idev->event, 0);
36140 + atomic_set_unchecked(&idev->event, 0);
36141
36142 ret = uio_get_minor(idev);
36143 if (ret)
36144 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
36145 index a845f8b..4f54072 100644
36146 --- a/drivers/usb/atm/cxacru.c
36147 +++ b/drivers/usb/atm/cxacru.c
36148 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
36149 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
36150 if (ret < 2)
36151 return -EINVAL;
36152 - if (index < 0 || index > 0x7f)
36153 + if (index > 0x7f)
36154 return -EINVAL;
36155 pos += tmp;
36156
36157 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
36158 index d3448ca..d2864ca 100644
36159 --- a/drivers/usb/atm/usbatm.c
36160 +++ b/drivers/usb/atm/usbatm.c
36161 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36162 if (printk_ratelimit())
36163 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
36164 __func__, vpi, vci);
36165 - atomic_inc(&vcc->stats->rx_err);
36166 + atomic_inc_unchecked(&vcc->stats->rx_err);
36167 return;
36168 }
36169
36170 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36171 if (length > ATM_MAX_AAL5_PDU) {
36172 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
36173 __func__, length, vcc);
36174 - atomic_inc(&vcc->stats->rx_err);
36175 + atomic_inc_unchecked(&vcc->stats->rx_err);
36176 goto out;
36177 }
36178
36179 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36180 if (sarb->len < pdu_length) {
36181 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
36182 __func__, pdu_length, sarb->len, vcc);
36183 - atomic_inc(&vcc->stats->rx_err);
36184 + atomic_inc_unchecked(&vcc->stats->rx_err);
36185 goto out;
36186 }
36187
36188 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
36189 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
36190 __func__, vcc);
36191 - atomic_inc(&vcc->stats->rx_err);
36192 + atomic_inc_unchecked(&vcc->stats->rx_err);
36193 goto out;
36194 }
36195
36196 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36197 if (printk_ratelimit())
36198 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
36199 __func__, length);
36200 - atomic_inc(&vcc->stats->rx_drop);
36201 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36202 goto out;
36203 }
36204
36205 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36206
36207 vcc->push(vcc, skb);
36208
36209 - atomic_inc(&vcc->stats->rx);
36210 + atomic_inc_unchecked(&vcc->stats->rx);
36211 out:
36212 skb_trim(sarb, 0);
36213 }
36214 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
36215 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
36216
36217 usbatm_pop(vcc, skb);
36218 - atomic_inc(&vcc->stats->tx);
36219 + atomic_inc_unchecked(&vcc->stats->tx);
36220
36221 skb = skb_dequeue(&instance->sndqueue);
36222 }
36223 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
36224 if (!left--)
36225 return sprintf(page,
36226 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
36227 - atomic_read(&atm_dev->stats.aal5.tx),
36228 - atomic_read(&atm_dev->stats.aal5.tx_err),
36229 - atomic_read(&atm_dev->stats.aal5.rx),
36230 - atomic_read(&atm_dev->stats.aal5.rx_err),
36231 - atomic_read(&atm_dev->stats.aal5.rx_drop));
36232 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
36233 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
36234 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
36235 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
36236 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
36237
36238 if (!left--) {
36239 if (instance->disconnected)
36240 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
36241 index d956965..4179a77 100644
36242 --- a/drivers/usb/core/devices.c
36243 +++ b/drivers/usb/core/devices.c
36244 @@ -126,7 +126,7 @@ static const char format_endpt[] =
36245 * time it gets called.
36246 */
36247 static struct device_connect_event {
36248 - atomic_t count;
36249 + atomic_unchecked_t count;
36250 wait_queue_head_t wait;
36251 } device_event = {
36252 .count = ATOMIC_INIT(1),
36253 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
36254
36255 void usbfs_conn_disc_event(void)
36256 {
36257 - atomic_add(2, &device_event.count);
36258 + atomic_add_unchecked(2, &device_event.count);
36259 wake_up(&device_event.wait);
36260 }
36261
36262 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
36263
36264 poll_wait(file, &device_event.wait, wait);
36265
36266 - event_count = atomic_read(&device_event.count);
36267 + event_count = atomic_read_unchecked(&device_event.count);
36268 if (file->f_version != event_count) {
36269 file->f_version = event_count;
36270 return POLLIN | POLLRDNORM;
36271 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
36272 index b3bdfed..a9460e0 100644
36273 --- a/drivers/usb/core/message.c
36274 +++ b/drivers/usb/core/message.c
36275 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
36276 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
36277 if (buf) {
36278 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
36279 - if (len > 0) {
36280 - smallbuf = kmalloc(++len, GFP_NOIO);
36281 + if (len++ > 0) {
36282 + smallbuf = kmalloc(len, GFP_NOIO);
36283 if (!smallbuf)
36284 return buf;
36285 memcpy(smallbuf, buf, len);
36286 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
36287 index 1fc8f12..20647c1 100644
36288 --- a/drivers/usb/early/ehci-dbgp.c
36289 +++ b/drivers/usb/early/ehci-dbgp.c
36290 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
36291
36292 #ifdef CONFIG_KGDB
36293 static struct kgdb_io kgdbdbgp_io_ops;
36294 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
36295 +static struct kgdb_io kgdbdbgp_io_ops_console;
36296 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
36297 #else
36298 #define dbgp_kgdb_mode (0)
36299 #endif
36300 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
36301 .write_char = kgdbdbgp_write_char,
36302 };
36303
36304 +static struct kgdb_io kgdbdbgp_io_ops_console = {
36305 + .name = "kgdbdbgp",
36306 + .read_char = kgdbdbgp_read_char,
36307 + .write_char = kgdbdbgp_write_char,
36308 + .is_console = 1
36309 +};
36310 +
36311 static int kgdbdbgp_wait_time;
36312
36313 static int __init kgdbdbgp_parse_config(char *str)
36314 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
36315 ptr++;
36316 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
36317 }
36318 - kgdb_register_io_module(&kgdbdbgp_io_ops);
36319 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
36320 + if (early_dbgp_console.index != -1)
36321 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
36322 + else
36323 + kgdb_register_io_module(&kgdbdbgp_io_ops);
36324
36325 return 0;
36326 }
36327 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
36328 index d6bea3e..60b250e 100644
36329 --- a/drivers/usb/wusbcore/wa-hc.h
36330 +++ b/drivers/usb/wusbcore/wa-hc.h
36331 @@ -192,7 +192,7 @@ struct wahc {
36332 struct list_head xfer_delayed_list;
36333 spinlock_t xfer_list_lock;
36334 struct work_struct xfer_work;
36335 - atomic_t xfer_id_count;
36336 + atomic_unchecked_t xfer_id_count;
36337 };
36338
36339
36340 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
36341 INIT_LIST_HEAD(&wa->xfer_delayed_list);
36342 spin_lock_init(&wa->xfer_list_lock);
36343 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
36344 - atomic_set(&wa->xfer_id_count, 1);
36345 + atomic_set_unchecked(&wa->xfer_id_count, 1);
36346 }
36347
36348 /**
36349 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
36350 index 57c01ab..8a05959 100644
36351 --- a/drivers/usb/wusbcore/wa-xfer.c
36352 +++ b/drivers/usb/wusbcore/wa-xfer.c
36353 @@ -296,7 +296,7 @@ out:
36354 */
36355 static void wa_xfer_id_init(struct wa_xfer *xfer)
36356 {
36357 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
36358 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
36359 }
36360
36361 /*
36362 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
36363 index c14c42b..f955cc2 100644
36364 --- a/drivers/vhost/vhost.c
36365 +++ b/drivers/vhost/vhost.c
36366 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
36367 return 0;
36368 }
36369
36370 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
36371 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
36372 {
36373 struct file *eventfp, *filep = NULL,
36374 *pollstart = NULL, *pollstop = NULL;
36375 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
36376 index b0b2ac3..89a4399 100644
36377 --- a/drivers/video/aty/aty128fb.c
36378 +++ b/drivers/video/aty/aty128fb.c
36379 @@ -148,7 +148,7 @@ enum {
36380 };
36381
36382 /* Must match above enum */
36383 -static const char *r128_family[] __devinitdata = {
36384 +static const char *r128_family[] __devinitconst = {
36385 "AGP",
36386 "PCI",
36387 "PRO AGP",
36388 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
36389 index 5c3960d..15cf8fc 100644
36390 --- a/drivers/video/fbcmap.c
36391 +++ b/drivers/video/fbcmap.c
36392 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
36393 rc = -ENODEV;
36394 goto out;
36395 }
36396 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
36397 - !info->fbops->fb_setcmap)) {
36398 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
36399 rc = -EINVAL;
36400 goto out1;
36401 }
36402 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
36403 index ad93629..e020fc3 100644
36404 --- a/drivers/video/fbmem.c
36405 +++ b/drivers/video/fbmem.c
36406 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
36407 image->dx += image->width + 8;
36408 }
36409 } else if (rotate == FB_ROTATE_UD) {
36410 - for (x = 0; x < num && image->dx >= 0; x++) {
36411 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
36412 info->fbops->fb_imageblit(info, image);
36413 image->dx -= image->width + 8;
36414 }
36415 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
36416 image->dy += image->height + 8;
36417 }
36418 } else if (rotate == FB_ROTATE_CCW) {
36419 - for (x = 0; x < num && image->dy >= 0; x++) {
36420 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
36421 info->fbops->fb_imageblit(info, image);
36422 image->dy -= image->height + 8;
36423 }
36424 @@ -1143,7 +1143,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
36425 return -EFAULT;
36426 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
36427 return -EINVAL;
36428 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
36429 + if (con2fb.framebuffer >= FB_MAX)
36430 return -EINVAL;
36431 if (!registered_fb[con2fb.framebuffer])
36432 request_module("fb%d", con2fb.framebuffer);
36433 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
36434 index 5a5d092..265c5ed 100644
36435 --- a/drivers/video/geode/gx1fb_core.c
36436 +++ b/drivers/video/geode/gx1fb_core.c
36437 @@ -29,7 +29,7 @@ static int crt_option = 1;
36438 static char panel_option[32] = "";
36439
36440 /* Modes relevant to the GX1 (taken from modedb.c) */
36441 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
36442 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
36443 /* 640x480-60 VESA */
36444 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
36445 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
36446 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
36447 index 0fad23f..0e9afa4 100644
36448 --- a/drivers/video/gxt4500.c
36449 +++ b/drivers/video/gxt4500.c
36450 @@ -156,7 +156,7 @@ struct gxt4500_par {
36451 static char *mode_option;
36452
36453 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
36454 -static const struct fb_videomode defaultmode __devinitdata = {
36455 +static const struct fb_videomode defaultmode __devinitconst = {
36456 .refresh = 60,
36457 .xres = 1280,
36458 .yres = 1024,
36459 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
36460 return 0;
36461 }
36462
36463 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
36464 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
36465 .id = "IBM GXT4500P",
36466 .type = FB_TYPE_PACKED_PIXELS,
36467 .visual = FB_VISUAL_PSEUDOCOLOR,
36468 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
36469 index 7672d2e..b56437f 100644
36470 --- a/drivers/video/i810/i810_accel.c
36471 +++ b/drivers/video/i810/i810_accel.c
36472 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
36473 }
36474 }
36475 printk("ringbuffer lockup!!!\n");
36476 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
36477 i810_report_error(mmio);
36478 par->dev_flags |= LOCKUP;
36479 info->pixmap.scan_align = 1;
36480 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
36481 index 318f6fb..9a389c1 100644
36482 --- a/drivers/video/i810/i810_main.c
36483 +++ b/drivers/video/i810/i810_main.c
36484 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
36485 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
36486
36487 /* PCI */
36488 -static const char *i810_pci_list[] __devinitdata = {
36489 +static const char *i810_pci_list[] __devinitconst = {
36490 "Intel(R) 810 Framebuffer Device" ,
36491 "Intel(R) 810-DC100 Framebuffer Device" ,
36492 "Intel(R) 810E Framebuffer Device" ,
36493 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
36494 index de36693..3c63fc2 100644
36495 --- a/drivers/video/jz4740_fb.c
36496 +++ b/drivers/video/jz4740_fb.c
36497 @@ -136,7 +136,7 @@ struct jzfb {
36498 uint32_t pseudo_palette[16];
36499 };
36500
36501 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
36502 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
36503 .id = "JZ4740 FB",
36504 .type = FB_TYPE_PACKED_PIXELS,
36505 .visual = FB_VISUAL_TRUECOLOR,
36506 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
36507 index 3c14e43..eafa544 100644
36508 --- a/drivers/video/logo/logo_linux_clut224.ppm
36509 +++ b/drivers/video/logo/logo_linux_clut224.ppm
36510 @@ -1,1604 +1,1123 @@
36511 P3
36512 -# Standard 224-color Linux logo
36513 80 80
36514 255
36515 - 0 0 0 0 0 0 0 0 0 0 0 0
36516 - 0 0 0 0 0 0 0 0 0 0 0 0
36517 - 0 0 0 0 0 0 0 0 0 0 0 0
36518 - 0 0 0 0 0 0 0 0 0 0 0 0
36519 - 0 0 0 0 0 0 0 0 0 0 0 0
36520 - 0 0 0 0 0 0 0 0 0 0 0 0
36521 - 0 0 0 0 0 0 0 0 0 0 0 0
36522 - 0 0 0 0 0 0 0 0 0 0 0 0
36523 - 0 0 0 0 0 0 0 0 0 0 0 0
36524 - 6 6 6 6 6 6 10 10 10 10 10 10
36525 - 10 10 10 6 6 6 6 6 6 6 6 6
36526 - 0 0 0 0 0 0 0 0 0 0 0 0
36527 - 0 0 0 0 0 0 0 0 0 0 0 0
36528 - 0 0 0 0 0 0 0 0 0 0 0 0
36529 - 0 0 0 0 0 0 0 0 0 0 0 0
36530 - 0 0 0 0 0 0 0 0 0 0 0 0
36531 - 0 0 0 0 0 0 0 0 0 0 0 0
36532 - 0 0 0 0 0 0 0 0 0 0 0 0
36533 - 0 0 0 0 0 0 0 0 0 0 0 0
36534 - 0 0 0 0 0 0 0 0 0 0 0 0
36535 - 0 0 0 0 0 0 0 0 0 0 0 0
36536 - 0 0 0 0 0 0 0 0 0 0 0 0
36537 - 0 0 0 0 0 0 0 0 0 0 0 0
36538 - 0 0 0 0 0 0 0 0 0 0 0 0
36539 - 0 0 0 0 0 0 0 0 0 0 0 0
36540 - 0 0 0 0 0 0 0 0 0 0 0 0
36541 - 0 0 0 0 0 0 0 0 0 0 0 0
36542 - 0 0 0 0 0 0 0 0 0 0 0 0
36543 - 0 0 0 6 6 6 10 10 10 14 14 14
36544 - 22 22 22 26 26 26 30 30 30 34 34 34
36545 - 30 30 30 30 30 30 26 26 26 18 18 18
36546 - 14 14 14 10 10 10 6 6 6 0 0 0
36547 - 0 0 0 0 0 0 0 0 0 0 0 0
36548 - 0 0 0 0 0 0 0 0 0 0 0 0
36549 - 0 0 0 0 0 0 0 0 0 0 0 0
36550 - 0 0 0 0 0 0 0 0 0 0 0 0
36551 - 0 0 0 0 0 0 0 0 0 0 0 0
36552 - 0 0 0 0 0 0 0 0 0 0 0 0
36553 - 0 0 0 0 0 0 0 0 0 0 0 0
36554 - 0 0 0 0 0 0 0 0 0 0 0 0
36555 - 0 0 0 0 0 0 0 0 0 0 0 0
36556 - 0 0 0 0 0 1 0 0 1 0 0 0
36557 - 0 0 0 0 0 0 0 0 0 0 0 0
36558 - 0 0 0 0 0 0 0 0 0 0 0 0
36559 - 0 0 0 0 0 0 0 0 0 0 0 0
36560 - 0 0 0 0 0 0 0 0 0 0 0 0
36561 - 0 0 0 0 0 0 0 0 0 0 0 0
36562 - 0 0 0 0 0 0 0 0 0 0 0 0
36563 - 6 6 6 14 14 14 26 26 26 42 42 42
36564 - 54 54 54 66 66 66 78 78 78 78 78 78
36565 - 78 78 78 74 74 74 66 66 66 54 54 54
36566 - 42 42 42 26 26 26 18 18 18 10 10 10
36567 - 6 6 6 0 0 0 0 0 0 0 0 0
36568 - 0 0 0 0 0 0 0 0 0 0 0 0
36569 - 0 0 0 0 0 0 0 0 0 0 0 0
36570 - 0 0 0 0 0 0 0 0 0 0 0 0
36571 - 0 0 0 0 0 0 0 0 0 0 0 0
36572 - 0 0 0 0 0 0 0 0 0 0 0 0
36573 - 0 0 0 0 0 0 0 0 0 0 0 0
36574 - 0 0 0 0 0 0 0 0 0 0 0 0
36575 - 0 0 0 0 0 0 0 0 0 0 0 0
36576 - 0 0 1 0 0 0 0 0 0 0 0 0
36577 - 0 0 0 0 0 0 0 0 0 0 0 0
36578 - 0 0 0 0 0 0 0 0 0 0 0 0
36579 - 0 0 0 0 0 0 0 0 0 0 0 0
36580 - 0 0 0 0 0 0 0 0 0 0 0 0
36581 - 0 0 0 0 0 0 0 0 0 0 0 0
36582 - 0 0 0 0 0 0 0 0 0 10 10 10
36583 - 22 22 22 42 42 42 66 66 66 86 86 86
36584 - 66 66 66 38 38 38 38 38 38 22 22 22
36585 - 26 26 26 34 34 34 54 54 54 66 66 66
36586 - 86 86 86 70 70 70 46 46 46 26 26 26
36587 - 14 14 14 6 6 6 0 0 0 0 0 0
36588 - 0 0 0 0 0 0 0 0 0 0 0 0
36589 - 0 0 0 0 0 0 0 0 0 0 0 0
36590 - 0 0 0 0 0 0 0 0 0 0 0 0
36591 - 0 0 0 0 0 0 0 0 0 0 0 0
36592 - 0 0 0 0 0 0 0 0 0 0 0 0
36593 - 0 0 0 0 0 0 0 0 0 0 0 0
36594 - 0 0 0 0 0 0 0 0 0 0 0 0
36595 - 0 0 0 0 0 0 0 0 0 0 0 0
36596 - 0 0 1 0 0 1 0 0 1 0 0 0
36597 - 0 0 0 0 0 0 0 0 0 0 0 0
36598 - 0 0 0 0 0 0 0 0 0 0 0 0
36599 - 0 0 0 0 0 0 0 0 0 0 0 0
36600 - 0 0 0 0 0 0 0 0 0 0 0 0
36601 - 0 0 0 0 0 0 0 0 0 0 0 0
36602 - 0 0 0 0 0 0 10 10 10 26 26 26
36603 - 50 50 50 82 82 82 58 58 58 6 6 6
36604 - 2 2 6 2 2 6 2 2 6 2 2 6
36605 - 2 2 6 2 2 6 2 2 6 2 2 6
36606 - 6 6 6 54 54 54 86 86 86 66 66 66
36607 - 38 38 38 18 18 18 6 6 6 0 0 0
36608 - 0 0 0 0 0 0 0 0 0 0 0 0
36609 - 0 0 0 0 0 0 0 0 0 0 0 0
36610 - 0 0 0 0 0 0 0 0 0 0 0 0
36611 - 0 0 0 0 0 0 0 0 0 0 0 0
36612 - 0 0 0 0 0 0 0 0 0 0 0 0
36613 - 0 0 0 0 0 0 0 0 0 0 0 0
36614 - 0 0 0 0 0 0 0 0 0 0 0 0
36615 - 0 0 0 0 0 0 0 0 0 0 0 0
36616 - 0 0 0 0 0 0 0 0 0 0 0 0
36617 - 0 0 0 0 0 0 0 0 0 0 0 0
36618 - 0 0 0 0 0 0 0 0 0 0 0 0
36619 - 0 0 0 0 0 0 0 0 0 0 0 0
36620 - 0 0 0 0 0 0 0 0 0 0 0 0
36621 - 0 0 0 0 0 0 0 0 0 0 0 0
36622 - 0 0 0 6 6 6 22 22 22 50 50 50
36623 - 78 78 78 34 34 34 2 2 6 2 2 6
36624 - 2 2 6 2 2 6 2 2 6 2 2 6
36625 - 2 2 6 2 2 6 2 2 6 2 2 6
36626 - 2 2 6 2 2 6 6 6 6 70 70 70
36627 - 78 78 78 46 46 46 22 22 22 6 6 6
36628 - 0 0 0 0 0 0 0 0 0 0 0 0
36629 - 0 0 0 0 0 0 0 0 0 0 0 0
36630 - 0 0 0 0 0 0 0 0 0 0 0 0
36631 - 0 0 0 0 0 0 0 0 0 0 0 0
36632 - 0 0 0 0 0 0 0 0 0 0 0 0
36633 - 0 0 0 0 0 0 0 0 0 0 0 0
36634 - 0 0 0 0 0 0 0 0 0 0 0 0
36635 - 0 0 0 0 0 0 0 0 0 0 0 0
36636 - 0 0 1 0 0 1 0 0 1 0 0 0
36637 - 0 0 0 0 0 0 0 0 0 0 0 0
36638 - 0 0 0 0 0 0 0 0 0 0 0 0
36639 - 0 0 0 0 0 0 0 0 0 0 0 0
36640 - 0 0 0 0 0 0 0 0 0 0 0 0
36641 - 0 0 0 0 0 0 0 0 0 0 0 0
36642 - 6 6 6 18 18 18 42 42 42 82 82 82
36643 - 26 26 26 2 2 6 2 2 6 2 2 6
36644 - 2 2 6 2 2 6 2 2 6 2 2 6
36645 - 2 2 6 2 2 6 2 2 6 14 14 14
36646 - 46 46 46 34 34 34 6 6 6 2 2 6
36647 - 42 42 42 78 78 78 42 42 42 18 18 18
36648 - 6 6 6 0 0 0 0 0 0 0 0 0
36649 - 0 0 0 0 0 0 0 0 0 0 0 0
36650 - 0 0 0 0 0 0 0 0 0 0 0 0
36651 - 0 0 0 0 0 0 0 0 0 0 0 0
36652 - 0 0 0 0 0 0 0 0 0 0 0 0
36653 - 0 0 0 0 0 0 0 0 0 0 0 0
36654 - 0 0 0 0 0 0 0 0 0 0 0 0
36655 - 0 0 0 0 0 0 0 0 0 0 0 0
36656 - 0 0 1 0 0 0 0 0 1 0 0 0
36657 - 0 0 0 0 0 0 0 0 0 0 0 0
36658 - 0 0 0 0 0 0 0 0 0 0 0 0
36659 - 0 0 0 0 0 0 0 0 0 0 0 0
36660 - 0 0 0 0 0 0 0 0 0 0 0 0
36661 - 0 0 0 0 0 0 0 0 0 0 0 0
36662 - 10 10 10 30 30 30 66 66 66 58 58 58
36663 - 2 2 6 2 2 6 2 2 6 2 2 6
36664 - 2 2 6 2 2 6 2 2 6 2 2 6
36665 - 2 2 6 2 2 6 2 2 6 26 26 26
36666 - 86 86 86 101 101 101 46 46 46 10 10 10
36667 - 2 2 6 58 58 58 70 70 70 34 34 34
36668 - 10 10 10 0 0 0 0 0 0 0 0 0
36669 - 0 0 0 0 0 0 0 0 0 0 0 0
36670 - 0 0 0 0 0 0 0 0 0 0 0 0
36671 - 0 0 0 0 0 0 0 0 0 0 0 0
36672 - 0 0 0 0 0 0 0 0 0 0 0 0
36673 - 0 0 0 0 0 0 0 0 0 0 0 0
36674 - 0 0 0 0 0 0 0 0 0 0 0 0
36675 - 0 0 0 0 0 0 0 0 0 0 0 0
36676 - 0 0 1 0 0 1 0 0 1 0 0 0
36677 - 0 0 0 0 0 0 0 0 0 0 0 0
36678 - 0 0 0 0 0 0 0 0 0 0 0 0
36679 - 0 0 0 0 0 0 0 0 0 0 0 0
36680 - 0 0 0 0 0 0 0 0 0 0 0 0
36681 - 0 0 0 0 0 0 0 0 0 0 0 0
36682 - 14 14 14 42 42 42 86 86 86 10 10 10
36683 - 2 2 6 2 2 6 2 2 6 2 2 6
36684 - 2 2 6 2 2 6 2 2 6 2 2 6
36685 - 2 2 6 2 2 6 2 2 6 30 30 30
36686 - 94 94 94 94 94 94 58 58 58 26 26 26
36687 - 2 2 6 6 6 6 78 78 78 54 54 54
36688 - 22 22 22 6 6 6 0 0 0 0 0 0
36689 - 0 0 0 0 0 0 0 0 0 0 0 0
36690 - 0 0 0 0 0 0 0 0 0 0 0 0
36691 - 0 0 0 0 0 0 0 0 0 0 0 0
36692 - 0 0 0 0 0 0 0 0 0 0 0 0
36693 - 0 0 0 0 0 0 0 0 0 0 0 0
36694 - 0 0 0 0 0 0 0 0 0 0 0 0
36695 - 0 0 0 0 0 0 0 0 0 0 0 0
36696 - 0 0 0 0 0 0 0 0 0 0 0 0
36697 - 0 0 0 0 0 0 0 0 0 0 0 0
36698 - 0 0 0 0 0 0 0 0 0 0 0 0
36699 - 0 0 0 0 0 0 0 0 0 0 0 0
36700 - 0 0 0 0 0 0 0 0 0 0 0 0
36701 - 0 0 0 0 0 0 0 0 0 6 6 6
36702 - 22 22 22 62 62 62 62 62 62 2 2 6
36703 - 2 2 6 2 2 6 2 2 6 2 2 6
36704 - 2 2 6 2 2 6 2 2 6 2 2 6
36705 - 2 2 6 2 2 6 2 2 6 26 26 26
36706 - 54 54 54 38 38 38 18 18 18 10 10 10
36707 - 2 2 6 2 2 6 34 34 34 82 82 82
36708 - 38 38 38 14 14 14 0 0 0 0 0 0
36709 - 0 0 0 0 0 0 0 0 0 0 0 0
36710 - 0 0 0 0 0 0 0 0 0 0 0 0
36711 - 0 0 0 0 0 0 0 0 0 0 0 0
36712 - 0 0 0 0 0 0 0 0 0 0 0 0
36713 - 0 0 0 0 0 0 0 0 0 0 0 0
36714 - 0 0 0 0 0 0 0 0 0 0 0 0
36715 - 0 0 0 0 0 0 0 0 0 0 0 0
36716 - 0 0 0 0 0 1 0 0 1 0 0 0
36717 - 0 0 0 0 0 0 0 0 0 0 0 0
36718 - 0 0 0 0 0 0 0 0 0 0 0 0
36719 - 0 0 0 0 0 0 0 0 0 0 0 0
36720 - 0 0 0 0 0 0 0 0 0 0 0 0
36721 - 0 0 0 0 0 0 0 0 0 6 6 6
36722 - 30 30 30 78 78 78 30 30 30 2 2 6
36723 - 2 2 6 2 2 6 2 2 6 2 2 6
36724 - 2 2 6 2 2 6 2 2 6 2 2 6
36725 - 2 2 6 2 2 6 2 2 6 10 10 10
36726 - 10 10 10 2 2 6 2 2 6 2 2 6
36727 - 2 2 6 2 2 6 2 2 6 78 78 78
36728 - 50 50 50 18 18 18 6 6 6 0 0 0
36729 - 0 0 0 0 0 0 0 0 0 0 0 0
36730 - 0 0 0 0 0 0 0 0 0 0 0 0
36731 - 0 0 0 0 0 0 0 0 0 0 0 0
36732 - 0 0 0 0 0 0 0 0 0 0 0 0
36733 - 0 0 0 0 0 0 0 0 0 0 0 0
36734 - 0 0 0 0 0 0 0 0 0 0 0 0
36735 - 0 0 0 0 0 0 0 0 0 0 0 0
36736 - 0 0 1 0 0 0 0 0 0 0 0 0
36737 - 0 0 0 0 0 0 0 0 0 0 0 0
36738 - 0 0 0 0 0 0 0 0 0 0 0 0
36739 - 0 0 0 0 0 0 0 0 0 0 0 0
36740 - 0 0 0 0 0 0 0 0 0 0 0 0
36741 - 0 0 0 0 0 0 0 0 0 10 10 10
36742 - 38 38 38 86 86 86 14 14 14 2 2 6
36743 - 2 2 6 2 2 6 2 2 6 2 2 6
36744 - 2 2 6 2 2 6 2 2 6 2 2 6
36745 - 2 2 6 2 2 6 2 2 6 2 2 6
36746 - 2 2 6 2 2 6 2 2 6 2 2 6
36747 - 2 2 6 2 2 6 2 2 6 54 54 54
36748 - 66 66 66 26 26 26 6 6 6 0 0 0
36749 - 0 0 0 0 0 0 0 0 0 0 0 0
36750 - 0 0 0 0 0 0 0 0 0 0 0 0
36751 - 0 0 0 0 0 0 0 0 0 0 0 0
36752 - 0 0 0 0 0 0 0 0 0 0 0 0
36753 - 0 0 0 0 0 0 0 0 0 0 0 0
36754 - 0 0 0 0 0 0 0 0 0 0 0 0
36755 - 0 0 0 0 0 0 0 0 0 0 0 0
36756 - 0 0 0 0 0 1 0 0 1 0 0 0
36757 - 0 0 0 0 0 0 0 0 0 0 0 0
36758 - 0 0 0 0 0 0 0 0 0 0 0 0
36759 - 0 0 0 0 0 0 0 0 0 0 0 0
36760 - 0 0 0 0 0 0 0 0 0 0 0 0
36761 - 0 0 0 0 0 0 0 0 0 14 14 14
36762 - 42 42 42 82 82 82 2 2 6 2 2 6
36763 - 2 2 6 6 6 6 10 10 10 2 2 6
36764 - 2 2 6 2 2 6 2 2 6 2 2 6
36765 - 2 2 6 2 2 6 2 2 6 6 6 6
36766 - 14 14 14 10 10 10 2 2 6 2 2 6
36767 - 2 2 6 2 2 6 2 2 6 18 18 18
36768 - 82 82 82 34 34 34 10 10 10 0 0 0
36769 - 0 0 0 0 0 0 0 0 0 0 0 0
36770 - 0 0 0 0 0 0 0 0 0 0 0 0
36771 - 0 0 0 0 0 0 0 0 0 0 0 0
36772 - 0 0 0 0 0 0 0 0 0 0 0 0
36773 - 0 0 0 0 0 0 0 0 0 0 0 0
36774 - 0 0 0 0 0 0 0 0 0 0 0 0
36775 - 0 0 0 0 0 0 0 0 0 0 0 0
36776 - 0 0 1 0 0 0 0 0 0 0 0 0
36777 - 0 0 0 0 0 0 0 0 0 0 0 0
36778 - 0 0 0 0 0 0 0 0 0 0 0 0
36779 - 0 0 0 0 0 0 0 0 0 0 0 0
36780 - 0 0 0 0 0 0 0 0 0 0 0 0
36781 - 0 0 0 0 0 0 0 0 0 14 14 14
36782 - 46 46 46 86 86 86 2 2 6 2 2 6
36783 - 6 6 6 6 6 6 22 22 22 34 34 34
36784 - 6 6 6 2 2 6 2 2 6 2 2 6
36785 - 2 2 6 2 2 6 18 18 18 34 34 34
36786 - 10 10 10 50 50 50 22 22 22 2 2 6
36787 - 2 2 6 2 2 6 2 2 6 10 10 10
36788 - 86 86 86 42 42 42 14 14 14 0 0 0
36789 - 0 0 0 0 0 0 0 0 0 0 0 0
36790 - 0 0 0 0 0 0 0 0 0 0 0 0
36791 - 0 0 0 0 0 0 0 0 0 0 0 0
36792 - 0 0 0 0 0 0 0 0 0 0 0 0
36793 - 0 0 0 0 0 0 0 0 0 0 0 0
36794 - 0 0 0 0 0 0 0 0 0 0 0 0
36795 - 0 0 0 0 0 0 0 0 0 0 0 0
36796 - 0 0 1 0 0 1 0 0 1 0 0 0
36797 - 0 0 0 0 0 0 0 0 0 0 0 0
36798 - 0 0 0 0 0 0 0 0 0 0 0 0
36799 - 0 0 0 0 0 0 0 0 0 0 0 0
36800 - 0 0 0 0 0 0 0 0 0 0 0 0
36801 - 0 0 0 0 0 0 0 0 0 14 14 14
36802 - 46 46 46 86 86 86 2 2 6 2 2 6
36803 - 38 38 38 116 116 116 94 94 94 22 22 22
36804 - 22 22 22 2 2 6 2 2 6 2 2 6
36805 - 14 14 14 86 86 86 138 138 138 162 162 162
36806 -154 154 154 38 38 38 26 26 26 6 6 6
36807 - 2 2 6 2 2 6 2 2 6 2 2 6
36808 - 86 86 86 46 46 46 14 14 14 0 0 0
36809 - 0 0 0 0 0 0 0 0 0 0 0 0
36810 - 0 0 0 0 0 0 0 0 0 0 0 0
36811 - 0 0 0 0 0 0 0 0 0 0 0 0
36812 - 0 0 0 0 0 0 0 0 0 0 0 0
36813 - 0 0 0 0 0 0 0 0 0 0 0 0
36814 - 0 0 0 0 0 0 0 0 0 0 0 0
36815 - 0 0 0 0 0 0 0 0 0 0 0 0
36816 - 0 0 0 0 0 0 0 0 0 0 0 0
36817 - 0 0 0 0 0 0 0 0 0 0 0 0
36818 - 0 0 0 0 0 0 0 0 0 0 0 0
36819 - 0 0 0 0 0 0 0 0 0 0 0 0
36820 - 0 0 0 0 0 0 0 0 0 0 0 0
36821 - 0 0 0 0 0 0 0 0 0 14 14 14
36822 - 46 46 46 86 86 86 2 2 6 14 14 14
36823 -134 134 134 198 198 198 195 195 195 116 116 116
36824 - 10 10 10 2 2 6 2 2 6 6 6 6
36825 -101 98 89 187 187 187 210 210 210 218 218 218
36826 -214 214 214 134 134 134 14 14 14 6 6 6
36827 - 2 2 6 2 2 6 2 2 6 2 2 6
36828 - 86 86 86 50 50 50 18 18 18 6 6 6
36829 - 0 0 0 0 0 0 0 0 0 0 0 0
36830 - 0 0 0 0 0 0 0 0 0 0 0 0
36831 - 0 0 0 0 0 0 0 0 0 0 0 0
36832 - 0 0 0 0 0 0 0 0 0 0 0 0
36833 - 0 0 0 0 0 0 0 0 0 0 0 0
36834 - 0 0 0 0 0 0 0 0 0 0 0 0
36835 - 0 0 0 0 0 0 0 0 1 0 0 0
36836 - 0 0 1 0 0 1 0 0 1 0 0 0
36837 - 0 0 0 0 0 0 0 0 0 0 0 0
36838 - 0 0 0 0 0 0 0 0 0 0 0 0
36839 - 0 0 0 0 0 0 0 0 0 0 0 0
36840 - 0 0 0 0 0 0 0 0 0 0 0 0
36841 - 0 0 0 0 0 0 0 0 0 14 14 14
36842 - 46 46 46 86 86 86 2 2 6 54 54 54
36843 -218 218 218 195 195 195 226 226 226 246 246 246
36844 - 58 58 58 2 2 6 2 2 6 30 30 30
36845 -210 210 210 253 253 253 174 174 174 123 123 123
36846 -221 221 221 234 234 234 74 74 74 2 2 6
36847 - 2 2 6 2 2 6 2 2 6 2 2 6
36848 - 70 70 70 58 58 58 22 22 22 6 6 6
36849 - 0 0 0 0 0 0 0 0 0 0 0 0
36850 - 0 0 0 0 0 0 0 0 0 0 0 0
36851 - 0 0 0 0 0 0 0 0 0 0 0 0
36852 - 0 0 0 0 0 0 0 0 0 0 0 0
36853 - 0 0 0 0 0 0 0 0 0 0 0 0
36854 - 0 0 0 0 0 0 0 0 0 0 0 0
36855 - 0 0 0 0 0 0 0 0 0 0 0 0
36856 - 0 0 0 0 0 0 0 0 0 0 0 0
36857 - 0 0 0 0 0 0 0 0 0 0 0 0
36858 - 0 0 0 0 0 0 0 0 0 0 0 0
36859 - 0 0 0 0 0 0 0 0 0 0 0 0
36860 - 0 0 0 0 0 0 0 0 0 0 0 0
36861 - 0 0 0 0 0 0 0 0 0 14 14 14
36862 - 46 46 46 82 82 82 2 2 6 106 106 106
36863 -170 170 170 26 26 26 86 86 86 226 226 226
36864 -123 123 123 10 10 10 14 14 14 46 46 46
36865 -231 231 231 190 190 190 6 6 6 70 70 70
36866 - 90 90 90 238 238 238 158 158 158 2 2 6
36867 - 2 2 6 2 2 6 2 2 6 2 2 6
36868 - 70 70 70 58 58 58 22 22 22 6 6 6
36869 - 0 0 0 0 0 0 0 0 0 0 0 0
36870 - 0 0 0 0 0 0 0 0 0 0 0 0
36871 - 0 0 0 0 0 0 0 0 0 0 0 0
36872 - 0 0 0 0 0 0 0 0 0 0 0 0
36873 - 0 0 0 0 0 0 0 0 0 0 0 0
36874 - 0 0 0 0 0 0 0 0 0 0 0 0
36875 - 0 0 0 0 0 0 0 0 1 0 0 0
36876 - 0 0 1 0 0 1 0 0 1 0 0 0
36877 - 0 0 0 0 0 0 0 0 0 0 0 0
36878 - 0 0 0 0 0 0 0 0 0 0 0 0
36879 - 0 0 0 0 0 0 0 0 0 0 0 0
36880 - 0 0 0 0 0 0 0 0 0 0 0 0
36881 - 0 0 0 0 0 0 0 0 0 14 14 14
36882 - 42 42 42 86 86 86 6 6 6 116 116 116
36883 -106 106 106 6 6 6 70 70 70 149 149 149
36884 -128 128 128 18 18 18 38 38 38 54 54 54
36885 -221 221 221 106 106 106 2 2 6 14 14 14
36886 - 46 46 46 190 190 190 198 198 198 2 2 6
36887 - 2 2 6 2 2 6 2 2 6 2 2 6
36888 - 74 74 74 62 62 62 22 22 22 6 6 6
36889 - 0 0 0 0 0 0 0 0 0 0 0 0
36890 - 0 0 0 0 0 0 0 0 0 0 0 0
36891 - 0 0 0 0 0 0 0 0 0 0 0 0
36892 - 0 0 0 0 0 0 0 0 0 0 0 0
36893 - 0 0 0 0 0 0 0 0 0 0 0 0
36894 - 0 0 0 0 0 0 0 0 0 0 0 0
36895 - 0 0 0 0 0 0 0 0 1 0 0 0
36896 - 0 0 1 0 0 0 0 0 1 0 0 0
36897 - 0 0 0 0 0 0 0 0 0 0 0 0
36898 - 0 0 0 0 0 0 0 0 0 0 0 0
36899 - 0 0 0 0 0 0 0 0 0 0 0 0
36900 - 0 0 0 0 0 0 0 0 0 0 0 0
36901 - 0 0 0 0 0 0 0 0 0 14 14 14
36902 - 42 42 42 94 94 94 14 14 14 101 101 101
36903 -128 128 128 2 2 6 18 18 18 116 116 116
36904 -118 98 46 121 92 8 121 92 8 98 78 10
36905 -162 162 162 106 106 106 2 2 6 2 2 6
36906 - 2 2 6 195 195 195 195 195 195 6 6 6
36907 - 2 2 6 2 2 6 2 2 6 2 2 6
36908 - 74 74 74 62 62 62 22 22 22 6 6 6
36909 - 0 0 0 0 0 0 0 0 0 0 0 0
36910 - 0 0 0 0 0 0 0 0 0 0 0 0
36911 - 0 0 0 0 0 0 0 0 0 0 0 0
36912 - 0 0 0 0 0 0 0 0 0 0 0 0
36913 - 0 0 0 0 0 0 0 0 0 0 0 0
36914 - 0 0 0 0 0 0 0 0 0 0 0 0
36915 - 0 0 0 0 0 0 0 0 1 0 0 1
36916 - 0 0 1 0 0 0 0 0 1 0 0 0
36917 - 0 0 0 0 0 0 0 0 0 0 0 0
36918 - 0 0 0 0 0 0 0 0 0 0 0 0
36919 - 0 0 0 0 0 0 0 0 0 0 0 0
36920 - 0 0 0 0 0 0 0 0 0 0 0 0
36921 - 0 0 0 0 0 0 0 0 0 10 10 10
36922 - 38 38 38 90 90 90 14 14 14 58 58 58
36923 -210 210 210 26 26 26 54 38 6 154 114 10
36924 -226 170 11 236 186 11 225 175 15 184 144 12
36925 -215 174 15 175 146 61 37 26 9 2 2 6
36926 - 70 70 70 246 246 246 138 138 138 2 2 6
36927 - 2 2 6 2 2 6 2 2 6 2 2 6
36928 - 70 70 70 66 66 66 26 26 26 6 6 6
36929 - 0 0 0 0 0 0 0 0 0 0 0 0
36930 - 0 0 0 0 0 0 0 0 0 0 0 0
36931 - 0 0 0 0 0 0 0 0 0 0 0 0
36932 - 0 0 0 0 0 0 0 0 0 0 0 0
36933 - 0 0 0 0 0 0 0 0 0 0 0 0
36934 - 0 0 0 0 0 0 0 0 0 0 0 0
36935 - 0 0 0 0 0 0 0 0 0 0 0 0
36936 - 0 0 0 0 0 0 0 0 0 0 0 0
36937 - 0 0 0 0 0 0 0 0 0 0 0 0
36938 - 0 0 0 0 0 0 0 0 0 0 0 0
36939 - 0 0 0 0 0 0 0 0 0 0 0 0
36940 - 0 0 0 0 0 0 0 0 0 0 0 0
36941 - 0 0 0 0 0 0 0 0 0 10 10 10
36942 - 38 38 38 86 86 86 14 14 14 10 10 10
36943 -195 195 195 188 164 115 192 133 9 225 175 15
36944 -239 182 13 234 190 10 232 195 16 232 200 30
36945 -245 207 45 241 208 19 232 195 16 184 144 12
36946 -218 194 134 211 206 186 42 42 42 2 2 6
36947 - 2 2 6 2 2 6 2 2 6 2 2 6
36948 - 50 50 50 74 74 74 30 30 30 6 6 6
36949 - 0 0 0 0 0 0 0 0 0 0 0 0
36950 - 0 0 0 0 0 0 0 0 0 0 0 0
36951 - 0 0 0 0 0 0 0 0 0 0 0 0
36952 - 0 0 0 0 0 0 0 0 0 0 0 0
36953 - 0 0 0 0 0 0 0 0 0 0 0 0
36954 - 0 0 0 0 0 0 0 0 0 0 0 0
36955 - 0 0 0 0 0 0 0 0 0 0 0 0
36956 - 0 0 0 0 0 0 0 0 0 0 0 0
36957 - 0 0 0 0 0 0 0 0 0 0 0 0
36958 - 0 0 0 0 0 0 0 0 0 0 0 0
36959 - 0 0 0 0 0 0 0 0 0 0 0 0
36960 - 0 0 0 0 0 0 0 0 0 0 0 0
36961 - 0 0 0 0 0 0 0 0 0 10 10 10
36962 - 34 34 34 86 86 86 14 14 14 2 2 6
36963 -121 87 25 192 133 9 219 162 10 239 182 13
36964 -236 186 11 232 195 16 241 208 19 244 214 54
36965 -246 218 60 246 218 38 246 215 20 241 208 19
36966 -241 208 19 226 184 13 121 87 25 2 2 6
36967 - 2 2 6 2 2 6 2 2 6 2 2 6
36968 - 50 50 50 82 82 82 34 34 34 10 10 10
36969 - 0 0 0 0 0 0 0 0 0 0 0 0
36970 - 0 0 0 0 0 0 0 0 0 0 0 0
36971 - 0 0 0 0 0 0 0 0 0 0 0 0
36972 - 0 0 0 0 0 0 0 0 0 0 0 0
36973 - 0 0 0 0 0 0 0 0 0 0 0 0
36974 - 0 0 0 0 0 0 0 0 0 0 0 0
36975 - 0 0 0 0 0 0 0 0 0 0 0 0
36976 - 0 0 0 0 0 0 0 0 0 0 0 0
36977 - 0 0 0 0 0 0 0 0 0 0 0 0
36978 - 0 0 0 0 0 0 0 0 0 0 0 0
36979 - 0 0 0 0 0 0 0 0 0 0 0 0
36980 - 0 0 0 0 0 0 0 0 0 0 0 0
36981 - 0 0 0 0 0 0 0 0 0 10 10 10
36982 - 34 34 34 82 82 82 30 30 30 61 42 6
36983 -180 123 7 206 145 10 230 174 11 239 182 13
36984 -234 190 10 238 202 15 241 208 19 246 218 74
36985 -246 218 38 246 215 20 246 215 20 246 215 20
36986 -226 184 13 215 174 15 184 144 12 6 6 6
36987 - 2 2 6 2 2 6 2 2 6 2 2 6
36988 - 26 26 26 94 94 94 42 42 42 14 14 14
36989 - 0 0 0 0 0 0 0 0 0 0 0 0
36990 - 0 0 0 0 0 0 0 0 0 0 0 0
36991 - 0 0 0 0 0 0 0 0 0 0 0 0
36992 - 0 0 0 0 0 0 0 0 0 0 0 0
36993 - 0 0 0 0 0 0 0 0 0 0 0 0
36994 - 0 0 0 0 0 0 0 0 0 0 0 0
36995 - 0 0 0 0 0 0 0 0 0 0 0 0
36996 - 0 0 0 0 0 0 0 0 0 0 0 0
36997 - 0 0 0 0 0 0 0 0 0 0 0 0
36998 - 0 0 0 0 0 0 0 0 0 0 0 0
36999 - 0 0 0 0 0 0 0 0 0 0 0 0
37000 - 0 0 0 0 0 0 0 0 0 0 0 0
37001 - 0 0 0 0 0 0 0 0 0 10 10 10
37002 - 30 30 30 78 78 78 50 50 50 104 69 6
37003 -192 133 9 216 158 10 236 178 12 236 186 11
37004 -232 195 16 241 208 19 244 214 54 245 215 43
37005 -246 215 20 246 215 20 241 208 19 198 155 10
37006 -200 144 11 216 158 10 156 118 10 2 2 6
37007 - 2 2 6 2 2 6 2 2 6 2 2 6
37008 - 6 6 6 90 90 90 54 54 54 18 18 18
37009 - 6 6 6 0 0 0 0 0 0 0 0 0
37010 - 0 0 0 0 0 0 0 0 0 0 0 0
37011 - 0 0 0 0 0 0 0 0 0 0 0 0
37012 - 0 0 0 0 0 0 0 0 0 0 0 0
37013 - 0 0 0 0 0 0 0 0 0 0 0 0
37014 - 0 0 0 0 0 0 0 0 0 0 0 0
37015 - 0 0 0 0 0 0 0 0 0 0 0 0
37016 - 0 0 0 0 0 0 0 0 0 0 0 0
37017 - 0 0 0 0 0 0 0 0 0 0 0 0
37018 - 0 0 0 0 0 0 0 0 0 0 0 0
37019 - 0 0 0 0 0 0 0 0 0 0 0 0
37020 - 0 0 0 0 0 0 0 0 0 0 0 0
37021 - 0 0 0 0 0 0 0 0 0 10 10 10
37022 - 30 30 30 78 78 78 46 46 46 22 22 22
37023 -137 92 6 210 162 10 239 182 13 238 190 10
37024 -238 202 15 241 208 19 246 215 20 246 215 20
37025 -241 208 19 203 166 17 185 133 11 210 150 10
37026 -216 158 10 210 150 10 102 78 10 2 2 6
37027 - 6 6 6 54 54 54 14 14 14 2 2 6
37028 - 2 2 6 62 62 62 74 74 74 30 30 30
37029 - 10 10 10 0 0 0 0 0 0 0 0 0
37030 - 0 0 0 0 0 0 0 0 0 0 0 0
37031 - 0 0 0 0 0 0 0 0 0 0 0 0
37032 - 0 0 0 0 0 0 0 0 0 0 0 0
37033 - 0 0 0 0 0 0 0 0 0 0 0 0
37034 - 0 0 0 0 0 0 0 0 0 0 0 0
37035 - 0 0 0 0 0 0 0 0 0 0 0 0
37036 - 0 0 0 0 0 0 0 0 0 0 0 0
37037 - 0 0 0 0 0 0 0 0 0 0 0 0
37038 - 0 0 0 0 0 0 0 0 0 0 0 0
37039 - 0 0 0 0 0 0 0 0 0 0 0 0
37040 - 0 0 0 0 0 0 0 0 0 0 0 0
37041 - 0 0 0 0 0 0 0 0 0 10 10 10
37042 - 34 34 34 78 78 78 50 50 50 6 6 6
37043 - 94 70 30 139 102 15 190 146 13 226 184 13
37044 -232 200 30 232 195 16 215 174 15 190 146 13
37045 -168 122 10 192 133 9 210 150 10 213 154 11
37046 -202 150 34 182 157 106 101 98 89 2 2 6
37047 - 2 2 6 78 78 78 116 116 116 58 58 58
37048 - 2 2 6 22 22 22 90 90 90 46 46 46
37049 - 18 18 18 6 6 6 0 0 0 0 0 0
37050 - 0 0 0 0 0 0 0 0 0 0 0 0
37051 - 0 0 0 0 0 0 0 0 0 0 0 0
37052 - 0 0 0 0 0 0 0 0 0 0 0 0
37053 - 0 0 0 0 0 0 0 0 0 0 0 0
37054 - 0 0 0 0 0 0 0 0 0 0 0 0
37055 - 0 0 0 0 0 0 0 0 0 0 0 0
37056 - 0 0 0 0 0 0 0 0 0 0 0 0
37057 - 0 0 0 0 0 0 0 0 0 0 0 0
37058 - 0 0 0 0 0 0 0 0 0 0 0 0
37059 - 0 0 0 0 0 0 0 0 0 0 0 0
37060 - 0 0 0 0 0 0 0 0 0 0 0 0
37061 - 0 0 0 0 0 0 0 0 0 10 10 10
37062 - 38 38 38 86 86 86 50 50 50 6 6 6
37063 -128 128 128 174 154 114 156 107 11 168 122 10
37064 -198 155 10 184 144 12 197 138 11 200 144 11
37065 -206 145 10 206 145 10 197 138 11 188 164 115
37066 -195 195 195 198 198 198 174 174 174 14 14 14
37067 - 2 2 6 22 22 22 116 116 116 116 116 116
37068 - 22 22 22 2 2 6 74 74 74 70 70 70
37069 - 30 30 30 10 10 10 0 0 0 0 0 0
37070 - 0 0 0 0 0 0 0 0 0 0 0 0
37071 - 0 0 0 0 0 0 0 0 0 0 0 0
37072 - 0 0 0 0 0 0 0 0 0 0 0 0
37073 - 0 0 0 0 0 0 0 0 0 0 0 0
37074 - 0 0 0 0 0 0 0 0 0 0 0 0
37075 - 0 0 0 0 0 0 0 0 0 0 0 0
37076 - 0 0 0 0 0 0 0 0 0 0 0 0
37077 - 0 0 0 0 0 0 0 0 0 0 0 0
37078 - 0 0 0 0 0 0 0 0 0 0 0 0
37079 - 0 0 0 0 0 0 0 0 0 0 0 0
37080 - 0 0 0 0 0 0 0 0 0 0 0 0
37081 - 0 0 0 0 0 0 6 6 6 18 18 18
37082 - 50 50 50 101 101 101 26 26 26 10 10 10
37083 -138 138 138 190 190 190 174 154 114 156 107 11
37084 -197 138 11 200 144 11 197 138 11 192 133 9
37085 -180 123 7 190 142 34 190 178 144 187 187 187
37086 -202 202 202 221 221 221 214 214 214 66 66 66
37087 - 2 2 6 2 2 6 50 50 50 62 62 62
37088 - 6 6 6 2 2 6 10 10 10 90 90 90
37089 - 50 50 50 18 18 18 6 6 6 0 0 0
37090 - 0 0 0 0 0 0 0 0 0 0 0 0
37091 - 0 0 0 0 0 0 0 0 0 0 0 0
37092 - 0 0 0 0 0 0 0 0 0 0 0 0
37093 - 0 0 0 0 0 0 0 0 0 0 0 0
37094 - 0 0 0 0 0 0 0 0 0 0 0 0
37095 - 0 0 0 0 0 0 0 0 0 0 0 0
37096 - 0 0 0 0 0 0 0 0 0 0 0 0
37097 - 0 0 0 0 0 0 0 0 0 0 0 0
37098 - 0 0 0 0 0 0 0 0 0 0 0 0
37099 - 0 0 0 0 0 0 0 0 0 0 0 0
37100 - 0 0 0 0 0 0 0 0 0 0 0 0
37101 - 0 0 0 0 0 0 10 10 10 34 34 34
37102 - 74 74 74 74 74 74 2 2 6 6 6 6
37103 -144 144 144 198 198 198 190 190 190 178 166 146
37104 -154 121 60 156 107 11 156 107 11 168 124 44
37105 -174 154 114 187 187 187 190 190 190 210 210 210
37106 -246 246 246 253 253 253 253 253 253 182 182 182
37107 - 6 6 6 2 2 6 2 2 6 2 2 6
37108 - 2 2 6 2 2 6 2 2 6 62 62 62
37109 - 74 74 74 34 34 34 14 14 14 0 0 0
37110 - 0 0 0 0 0 0 0 0 0 0 0 0
37111 - 0 0 0 0 0 0 0 0 0 0 0 0
37112 - 0 0 0 0 0 0 0 0 0 0 0 0
37113 - 0 0 0 0 0 0 0 0 0 0 0 0
37114 - 0 0 0 0 0 0 0 0 0 0 0 0
37115 - 0 0 0 0 0 0 0 0 0 0 0 0
37116 - 0 0 0 0 0 0 0 0 0 0 0 0
37117 - 0 0 0 0 0 0 0 0 0 0 0 0
37118 - 0 0 0 0 0 0 0 0 0 0 0 0
37119 - 0 0 0 0 0 0 0 0 0 0 0 0
37120 - 0 0 0 0 0 0 0 0 0 0 0 0
37121 - 0 0 0 10 10 10 22 22 22 54 54 54
37122 - 94 94 94 18 18 18 2 2 6 46 46 46
37123 -234 234 234 221 221 221 190 190 190 190 190 190
37124 -190 190 190 187 187 187 187 187 187 190 190 190
37125 -190 190 190 195 195 195 214 214 214 242 242 242
37126 -253 253 253 253 253 253 253 253 253 253 253 253
37127 - 82 82 82 2 2 6 2 2 6 2 2 6
37128 - 2 2 6 2 2 6 2 2 6 14 14 14
37129 - 86 86 86 54 54 54 22 22 22 6 6 6
37130 - 0 0 0 0 0 0 0 0 0 0 0 0
37131 - 0 0 0 0 0 0 0 0 0 0 0 0
37132 - 0 0 0 0 0 0 0 0 0 0 0 0
37133 - 0 0 0 0 0 0 0 0 0 0 0 0
37134 - 0 0 0 0 0 0 0 0 0 0 0 0
37135 - 0 0 0 0 0 0 0 0 0 0 0 0
37136 - 0 0 0 0 0 0 0 0 0 0 0 0
37137 - 0 0 0 0 0 0 0 0 0 0 0 0
37138 - 0 0 0 0 0 0 0 0 0 0 0 0
37139 - 0 0 0 0 0 0 0 0 0 0 0 0
37140 - 0 0 0 0 0 0 0 0 0 0 0 0
37141 - 6 6 6 18 18 18 46 46 46 90 90 90
37142 - 46 46 46 18 18 18 6 6 6 182 182 182
37143 -253 253 253 246 246 246 206 206 206 190 190 190
37144 -190 190 190 190 190 190 190 190 190 190 190 190
37145 -206 206 206 231 231 231 250 250 250 253 253 253
37146 -253 253 253 253 253 253 253 253 253 253 253 253
37147 -202 202 202 14 14 14 2 2 6 2 2 6
37148 - 2 2 6 2 2 6 2 2 6 2 2 6
37149 - 42 42 42 86 86 86 42 42 42 18 18 18
37150 - 6 6 6 0 0 0 0 0 0 0 0 0
37151 - 0 0 0 0 0 0 0 0 0 0 0 0
37152 - 0 0 0 0 0 0 0 0 0 0 0 0
37153 - 0 0 0 0 0 0 0 0 0 0 0 0
37154 - 0 0 0 0 0 0 0 0 0 0 0 0
37155 - 0 0 0 0 0 0 0 0 0 0 0 0
37156 - 0 0 0 0 0 0 0 0 0 0 0 0
37157 - 0 0 0 0 0 0 0 0 0 0 0 0
37158 - 0 0 0 0 0 0 0 0 0 0 0 0
37159 - 0 0 0 0 0 0 0 0 0 0 0 0
37160 - 0 0 0 0 0 0 0 0 0 6 6 6
37161 - 14 14 14 38 38 38 74 74 74 66 66 66
37162 - 2 2 6 6 6 6 90 90 90 250 250 250
37163 -253 253 253 253 253 253 238 238 238 198 198 198
37164 -190 190 190 190 190 190 195 195 195 221 221 221
37165 -246 246 246 253 253 253 253 253 253 253 253 253
37166 -253 253 253 253 253 253 253 253 253 253 253 253
37167 -253 253 253 82 82 82 2 2 6 2 2 6
37168 - 2 2 6 2 2 6 2 2 6 2 2 6
37169 - 2 2 6 78 78 78 70 70 70 34 34 34
37170 - 14 14 14 6 6 6 0 0 0 0 0 0
37171 - 0 0 0 0 0 0 0 0 0 0 0 0
37172 - 0 0 0 0 0 0 0 0 0 0 0 0
37173 - 0 0 0 0 0 0 0 0 0 0 0 0
37174 - 0 0 0 0 0 0 0 0 0 0 0 0
37175 - 0 0 0 0 0 0 0 0 0 0 0 0
37176 - 0 0 0 0 0 0 0 0 0 0 0 0
37177 - 0 0 0 0 0 0 0 0 0 0 0 0
37178 - 0 0 0 0 0 0 0 0 0 0 0 0
37179 - 0 0 0 0 0 0 0 0 0 0 0 0
37180 - 0 0 0 0 0 0 0 0 0 14 14 14
37181 - 34 34 34 66 66 66 78 78 78 6 6 6
37182 - 2 2 6 18 18 18 218 218 218 253 253 253
37183 -253 253 253 253 253 253 253 253 253 246 246 246
37184 -226 226 226 231 231 231 246 246 246 253 253 253
37185 -253 253 253 253 253 253 253 253 253 253 253 253
37186 -253 253 253 253 253 253 253 253 253 253 253 253
37187 -253 253 253 178 178 178 2 2 6 2 2 6
37188 - 2 2 6 2 2 6 2 2 6 2 2 6
37189 - 2 2 6 18 18 18 90 90 90 62 62 62
37190 - 30 30 30 10 10 10 0 0 0 0 0 0
37191 - 0 0 0 0 0 0 0 0 0 0 0 0
37192 - 0 0 0 0 0 0 0 0 0 0 0 0
37193 - 0 0 0 0 0 0 0 0 0 0 0 0
37194 - 0 0 0 0 0 0 0 0 0 0 0 0
37195 - 0 0 0 0 0 0 0 0 0 0 0 0
37196 - 0 0 0 0 0 0 0 0 0 0 0 0
37197 - 0 0 0 0 0 0 0 0 0 0 0 0
37198 - 0 0 0 0 0 0 0 0 0 0 0 0
37199 - 0 0 0 0 0 0 0 0 0 0 0 0
37200 - 0 0 0 0 0 0 10 10 10 26 26 26
37201 - 58 58 58 90 90 90 18 18 18 2 2 6
37202 - 2 2 6 110 110 110 253 253 253 253 253 253
37203 -253 253 253 253 253 253 253 253 253 253 253 253
37204 -250 250 250 253 253 253 253 253 253 253 253 253
37205 -253 253 253 253 253 253 253 253 253 253 253 253
37206 -253 253 253 253 253 253 253 253 253 253 253 253
37207 -253 253 253 231 231 231 18 18 18 2 2 6
37208 - 2 2 6 2 2 6 2 2 6 2 2 6
37209 - 2 2 6 2 2 6 18 18 18 94 94 94
37210 - 54 54 54 26 26 26 10 10 10 0 0 0
37211 - 0 0 0 0 0 0 0 0 0 0 0 0
37212 - 0 0 0 0 0 0 0 0 0 0 0 0
37213 - 0 0 0 0 0 0 0 0 0 0 0 0
37214 - 0 0 0 0 0 0 0 0 0 0 0 0
37215 - 0 0 0 0 0 0 0 0 0 0 0 0
37216 - 0 0 0 0 0 0 0 0 0 0 0 0
37217 - 0 0 0 0 0 0 0 0 0 0 0 0
37218 - 0 0 0 0 0 0 0 0 0 0 0 0
37219 - 0 0 0 0 0 0 0 0 0 0 0 0
37220 - 0 0 0 6 6 6 22 22 22 50 50 50
37221 - 90 90 90 26 26 26 2 2 6 2 2 6
37222 - 14 14 14 195 195 195 250 250 250 253 253 253
37223 -253 253 253 253 253 253 253 253 253 253 253 253
37224 -253 253 253 253 253 253 253 253 253 253 253 253
37225 -253 253 253 253 253 253 253 253 253 253 253 253
37226 -253 253 253 253 253 253 253 253 253 253 253 253
37227 -250 250 250 242 242 242 54 54 54 2 2 6
37228 - 2 2 6 2 2 6 2 2 6 2 2 6
37229 - 2 2 6 2 2 6 2 2 6 38 38 38
37230 - 86 86 86 50 50 50 22 22 22 6 6 6
37231 - 0 0 0 0 0 0 0 0 0 0 0 0
37232 - 0 0 0 0 0 0 0 0 0 0 0 0
37233 - 0 0 0 0 0 0 0 0 0 0 0 0
37234 - 0 0 0 0 0 0 0 0 0 0 0 0
37235 - 0 0 0 0 0 0 0 0 0 0 0 0
37236 - 0 0 0 0 0 0 0 0 0 0 0 0
37237 - 0 0 0 0 0 0 0 0 0 0 0 0
37238 - 0 0 0 0 0 0 0 0 0 0 0 0
37239 - 0 0 0 0 0 0 0 0 0 0 0 0
37240 - 6 6 6 14 14 14 38 38 38 82 82 82
37241 - 34 34 34 2 2 6 2 2 6 2 2 6
37242 - 42 42 42 195 195 195 246 246 246 253 253 253
37243 -253 253 253 253 253 253 253 253 253 250 250 250
37244 -242 242 242 242 242 242 250 250 250 253 253 253
37245 -253 253 253 253 253 253 253 253 253 253 253 253
37246 -253 253 253 250 250 250 246 246 246 238 238 238
37247 -226 226 226 231 231 231 101 101 101 6 6 6
37248 - 2 2 6 2 2 6 2 2 6 2 2 6
37249 - 2 2 6 2 2 6 2 2 6 2 2 6
37250 - 38 38 38 82 82 82 42 42 42 14 14 14
37251 - 6 6 6 0 0 0 0 0 0 0 0 0
37252 - 0 0 0 0 0 0 0 0 0 0 0 0
37253 - 0 0 0 0 0 0 0 0 0 0 0 0
37254 - 0 0 0 0 0 0 0 0 0 0 0 0
37255 - 0 0 0 0 0 0 0 0 0 0 0 0
37256 - 0 0 0 0 0 0 0 0 0 0 0 0
37257 - 0 0 0 0 0 0 0 0 0 0 0 0
37258 - 0 0 0 0 0 0 0 0 0 0 0 0
37259 - 0 0 0 0 0 0 0 0 0 0 0 0
37260 - 10 10 10 26 26 26 62 62 62 66 66 66
37261 - 2 2 6 2 2 6 2 2 6 6 6 6
37262 - 70 70 70 170 170 170 206 206 206 234 234 234
37263 -246 246 246 250 250 250 250 250 250 238 238 238
37264 -226 226 226 231 231 231 238 238 238 250 250 250
37265 -250 250 250 250 250 250 246 246 246 231 231 231
37266 -214 214 214 206 206 206 202 202 202 202 202 202
37267 -198 198 198 202 202 202 182 182 182 18 18 18
37268 - 2 2 6 2 2 6 2 2 6 2 2 6
37269 - 2 2 6 2 2 6 2 2 6 2 2 6
37270 - 2 2 6 62 62 62 66 66 66 30 30 30
37271 - 10 10 10 0 0 0 0 0 0 0 0 0
37272 - 0 0 0 0 0 0 0 0 0 0 0 0
37273 - 0 0 0 0 0 0 0 0 0 0 0 0
37274 - 0 0 0 0 0 0 0 0 0 0 0 0
37275 - 0 0 0 0 0 0 0 0 0 0 0 0
37276 - 0 0 0 0 0 0 0 0 0 0 0 0
37277 - 0 0 0 0 0 0 0 0 0 0 0 0
37278 - 0 0 0 0 0 0 0 0 0 0 0 0
37279 - 0 0 0 0 0 0 0 0 0 0 0 0
37280 - 14 14 14 42 42 42 82 82 82 18 18 18
37281 - 2 2 6 2 2 6 2 2 6 10 10 10
37282 - 94 94 94 182 182 182 218 218 218 242 242 242
37283 -250 250 250 253 253 253 253 253 253 250 250 250
37284 -234 234 234 253 253 253 253 253 253 253 253 253
37285 -253 253 253 253 253 253 253 253 253 246 246 246
37286 -238 238 238 226 226 226 210 210 210 202 202 202
37287 -195 195 195 195 195 195 210 210 210 158 158 158
37288 - 6 6 6 14 14 14 50 50 50 14 14 14
37289 - 2 2 6 2 2 6 2 2 6 2 2 6
37290 - 2 2 6 6 6 6 86 86 86 46 46 46
37291 - 18 18 18 6 6 6 0 0 0 0 0 0
37292 - 0 0 0 0 0 0 0 0 0 0 0 0
37293 - 0 0 0 0 0 0 0 0 0 0 0 0
37294 - 0 0 0 0 0 0 0 0 0 0 0 0
37295 - 0 0 0 0 0 0 0 0 0 0 0 0
37296 - 0 0 0 0 0 0 0 0 0 0 0 0
37297 - 0 0 0 0 0 0 0 0 0 0 0 0
37298 - 0 0 0 0 0 0 0 0 0 0 0 0
37299 - 0 0 0 0 0 0 0 0 0 6 6 6
37300 - 22 22 22 54 54 54 70 70 70 2 2 6
37301 - 2 2 6 10 10 10 2 2 6 22 22 22
37302 -166 166 166 231 231 231 250 250 250 253 253 253
37303 -253 253 253 253 253 253 253 253 253 250 250 250
37304 -242 242 242 253 253 253 253 253 253 253 253 253
37305 -253 253 253 253 253 253 253 253 253 253 253 253
37306 -253 253 253 253 253 253 253 253 253 246 246 246
37307 -231 231 231 206 206 206 198 198 198 226 226 226
37308 - 94 94 94 2 2 6 6 6 6 38 38 38
37309 - 30 30 30 2 2 6 2 2 6 2 2 6
37310 - 2 2 6 2 2 6 62 62 62 66 66 66
37311 - 26 26 26 10 10 10 0 0 0 0 0 0
37312 - 0 0 0 0 0 0 0 0 0 0 0 0
37313 - 0 0 0 0 0 0 0 0 0 0 0 0
37314 - 0 0 0 0 0 0 0 0 0 0 0 0
37315 - 0 0 0 0 0 0 0 0 0 0 0 0
37316 - 0 0 0 0 0 0 0 0 0 0 0 0
37317 - 0 0 0 0 0 0 0 0 0 0 0 0
37318 - 0 0 0 0 0 0 0 0 0 0 0 0
37319 - 0 0 0 0 0 0 0 0 0 10 10 10
37320 - 30 30 30 74 74 74 50 50 50 2 2 6
37321 - 26 26 26 26 26 26 2 2 6 106 106 106
37322 -238 238 238 253 253 253 253 253 253 253 253 253
37323 -253 253 253 253 253 253 253 253 253 253 253 253
37324 -253 253 253 253 253 253 253 253 253 253 253 253
37325 -253 253 253 253 253 253 253 253 253 253 253 253
37326 -253 253 253 253 253 253 253 253 253 253 253 253
37327 -253 253 253 246 246 246 218 218 218 202 202 202
37328 -210 210 210 14 14 14 2 2 6 2 2 6
37329 - 30 30 30 22 22 22 2 2 6 2 2 6
37330 - 2 2 6 2 2 6 18 18 18 86 86 86
37331 - 42 42 42 14 14 14 0 0 0 0 0 0
37332 - 0 0 0 0 0 0 0 0 0 0 0 0
37333 - 0 0 0 0 0 0 0 0 0 0 0 0
37334 - 0 0 0 0 0 0 0 0 0 0 0 0
37335 - 0 0 0 0 0 0 0 0 0 0 0 0
37336 - 0 0 0 0 0 0 0 0 0 0 0 0
37337 - 0 0 0 0 0 0 0 0 0 0 0 0
37338 - 0 0 0 0 0 0 0 0 0 0 0 0
37339 - 0 0 0 0 0 0 0 0 0 14 14 14
37340 - 42 42 42 90 90 90 22 22 22 2 2 6
37341 - 42 42 42 2 2 6 18 18 18 218 218 218
37342 -253 253 253 253 253 253 253 253 253 253 253 253
37343 -253 253 253 253 253 253 253 253 253 253 253 253
37344 -253 253 253 253 253 253 253 253 253 253 253 253
37345 -253 253 253 253 253 253 253 253 253 253 253 253
37346 -253 253 253 253 253 253 253 253 253 253 253 253
37347 -253 253 253 253 253 253 250 250 250 221 221 221
37348 -218 218 218 101 101 101 2 2 6 14 14 14
37349 - 18 18 18 38 38 38 10 10 10 2 2 6
37350 - 2 2 6 2 2 6 2 2 6 78 78 78
37351 - 58 58 58 22 22 22 6 6 6 0 0 0
37352 - 0 0 0 0 0 0 0 0 0 0 0 0
37353 - 0 0 0 0 0 0 0 0 0 0 0 0
37354 - 0 0 0 0 0 0 0 0 0 0 0 0
37355 - 0 0 0 0 0 0 0 0 0 0 0 0
37356 - 0 0 0 0 0 0 0 0 0 0 0 0
37357 - 0 0 0 0 0 0 0 0 0 0 0 0
37358 - 0 0 0 0 0 0 0 0 0 0 0 0
37359 - 0 0 0 0 0 0 6 6 6 18 18 18
37360 - 54 54 54 82 82 82 2 2 6 26 26 26
37361 - 22 22 22 2 2 6 123 123 123 253 253 253
37362 -253 253 253 253 253 253 253 253 253 253 253 253
37363 -253 253 253 253 253 253 253 253 253 253 253 253
37364 -253 253 253 253 253 253 253 253 253 253 253 253
37365 -253 253 253 253 253 253 253 253 253 253 253 253
37366 -253 253 253 253 253 253 253 253 253 253 253 253
37367 -253 253 253 253 253 253 253 253 253 250 250 250
37368 -238 238 238 198 198 198 6 6 6 38 38 38
37369 - 58 58 58 26 26 26 38 38 38 2 2 6
37370 - 2 2 6 2 2 6 2 2 6 46 46 46
37371 - 78 78 78 30 30 30 10 10 10 0 0 0
37372 - 0 0 0 0 0 0 0 0 0 0 0 0
37373 - 0 0 0 0 0 0 0 0 0 0 0 0
37374 - 0 0 0 0 0 0 0 0 0 0 0 0
37375 - 0 0 0 0 0 0 0 0 0 0 0 0
37376 - 0 0 0 0 0 0 0 0 0 0 0 0
37377 - 0 0 0 0 0 0 0 0 0 0 0 0
37378 - 0 0 0 0 0 0 0 0 0 0 0 0
37379 - 0 0 0 0 0 0 10 10 10 30 30 30
37380 - 74 74 74 58 58 58 2 2 6 42 42 42
37381 - 2 2 6 22 22 22 231 231 231 253 253 253
37382 -253 253 253 253 253 253 253 253 253 253 253 253
37383 -253 253 253 253 253 253 253 253 253 250 250 250
37384 -253 253 253 253 253 253 253 253 253 253 253 253
37385 -253 253 253 253 253 253 253 253 253 253 253 253
37386 -253 253 253 253 253 253 253 253 253 253 253 253
37387 -253 253 253 253 253 253 253 253 253 253 253 253
37388 -253 253 253 246 246 246 46 46 46 38 38 38
37389 - 42 42 42 14 14 14 38 38 38 14 14 14
37390 - 2 2 6 2 2 6 2 2 6 6 6 6
37391 - 86 86 86 46 46 46 14 14 14 0 0 0
37392 - 0 0 0 0 0 0 0 0 0 0 0 0
37393 - 0 0 0 0 0 0 0 0 0 0 0 0
37394 - 0 0 0 0 0 0 0 0 0 0 0 0
37395 - 0 0 0 0 0 0 0 0 0 0 0 0
37396 - 0 0 0 0 0 0 0 0 0 0 0 0
37397 - 0 0 0 0 0 0 0 0 0 0 0 0
37398 - 0 0 0 0 0 0 0 0 0 0 0 0
37399 - 0 0 0 6 6 6 14 14 14 42 42 42
37400 - 90 90 90 18 18 18 18 18 18 26 26 26
37401 - 2 2 6 116 116 116 253 253 253 253 253 253
37402 -253 253 253 253 253 253 253 253 253 253 253 253
37403 -253 253 253 253 253 253 250 250 250 238 238 238
37404 -253 253 253 253 253 253 253 253 253 253 253 253
37405 -253 253 253 253 253 253 253 253 253 253 253 253
37406 -253 253 253 253 253 253 253 253 253 253 253 253
37407 -253 253 253 253 253 253 253 253 253 253 253 253
37408 -253 253 253 253 253 253 94 94 94 6 6 6
37409 - 2 2 6 2 2 6 10 10 10 34 34 34
37410 - 2 2 6 2 2 6 2 2 6 2 2 6
37411 - 74 74 74 58 58 58 22 22 22 6 6 6
37412 - 0 0 0 0 0 0 0 0 0 0 0 0
37413 - 0 0 0 0 0 0 0 0 0 0 0 0
37414 - 0 0 0 0 0 0 0 0 0 0 0 0
37415 - 0 0 0 0 0 0 0 0 0 0 0 0
37416 - 0 0 0 0 0 0 0 0 0 0 0 0
37417 - 0 0 0 0 0 0 0 0 0 0 0 0
37418 - 0 0 0 0 0 0 0 0 0 0 0 0
37419 - 0 0 0 10 10 10 26 26 26 66 66 66
37420 - 82 82 82 2 2 6 38 38 38 6 6 6
37421 - 14 14 14 210 210 210 253 253 253 253 253 253
37422 -253 253 253 253 253 253 253 253 253 253 253 253
37423 -253 253 253 253 253 253 246 246 246 242 242 242
37424 -253 253 253 253 253 253 253 253 253 253 253 253
37425 -253 253 253 253 253 253 253 253 253 253 253 253
37426 -253 253 253 253 253 253 253 253 253 253 253 253
37427 -253 253 253 253 253 253 253 253 253 253 253 253
37428 -253 253 253 253 253 253 144 144 144 2 2 6
37429 - 2 2 6 2 2 6 2 2 6 46 46 46
37430 - 2 2 6 2 2 6 2 2 6 2 2 6
37431 - 42 42 42 74 74 74 30 30 30 10 10 10
37432 - 0 0 0 0 0 0 0 0 0 0 0 0
37433 - 0 0 0 0 0 0 0 0 0 0 0 0
37434 - 0 0 0 0 0 0 0 0 0 0 0 0
37435 - 0 0 0 0 0 0 0 0 0 0 0 0
37436 - 0 0 0 0 0 0 0 0 0 0 0 0
37437 - 0 0 0 0 0 0 0 0 0 0 0 0
37438 - 0 0 0 0 0 0 0 0 0 0 0 0
37439 - 6 6 6 14 14 14 42 42 42 90 90 90
37440 - 26 26 26 6 6 6 42 42 42 2 2 6
37441 - 74 74 74 250 250 250 253 253 253 253 253 253
37442 -253 253 253 253 253 253 253 253 253 253 253 253
37443 -253 253 253 253 253 253 242 242 242 242 242 242
37444 -253 253 253 253 253 253 253 253 253 253 253 253
37445 -253 253 253 253 253 253 253 253 253 253 253 253
37446 -253 253 253 253 253 253 253 253 253 253 253 253
37447 -253 253 253 253 253 253 253 253 253 253 253 253
37448 -253 253 253 253 253 253 182 182 182 2 2 6
37449 - 2 2 6 2 2 6 2 2 6 46 46 46
37450 - 2 2 6 2 2 6 2 2 6 2 2 6
37451 - 10 10 10 86 86 86 38 38 38 10 10 10
37452 - 0 0 0 0 0 0 0 0 0 0 0 0
37453 - 0 0 0 0 0 0 0 0 0 0 0 0
37454 - 0 0 0 0 0 0 0 0 0 0 0 0
37455 - 0 0 0 0 0 0 0 0 0 0 0 0
37456 - 0 0 0 0 0 0 0 0 0 0 0 0
37457 - 0 0 0 0 0 0 0 0 0 0 0 0
37458 - 0 0 0 0 0 0 0 0 0 0 0 0
37459 - 10 10 10 26 26 26 66 66 66 82 82 82
37460 - 2 2 6 22 22 22 18 18 18 2 2 6
37461 -149 149 149 253 253 253 253 253 253 253 253 253
37462 -253 253 253 253 253 253 253 253 253 253 253 253
37463 -253 253 253 253 253 253 234 234 234 242 242 242
37464 -253 253 253 253 253 253 253 253 253 253 253 253
37465 -253 253 253 253 253 253 253 253 253 253 253 253
37466 -253 253 253 253 253 253 253 253 253 253 253 253
37467 -253 253 253 253 253 253 253 253 253 253 253 253
37468 -253 253 253 253 253 253 206 206 206 2 2 6
37469 - 2 2 6 2 2 6 2 2 6 38 38 38
37470 - 2 2 6 2 2 6 2 2 6 2 2 6
37471 - 6 6 6 86 86 86 46 46 46 14 14 14
37472 - 0 0 0 0 0 0 0 0 0 0 0 0
37473 - 0 0 0 0 0 0 0 0 0 0 0 0
37474 - 0 0 0 0 0 0 0 0 0 0 0 0
37475 - 0 0 0 0 0 0 0 0 0 0 0 0
37476 - 0 0 0 0 0 0 0 0 0 0 0 0
37477 - 0 0 0 0 0 0 0 0 0 0 0 0
37478 - 0 0 0 0 0 0 0 0 0 6 6 6
37479 - 18 18 18 46 46 46 86 86 86 18 18 18
37480 - 2 2 6 34 34 34 10 10 10 6 6 6
37481 -210 210 210 253 253 253 253 253 253 253 253 253
37482 -253 253 253 253 253 253 253 253 253 253 253 253
37483 -253 253 253 253 253 253 234 234 234 242 242 242
37484 -253 253 253 253 253 253 253 253 253 253 253 253
37485 -253 253 253 253 253 253 253 253 253 253 253 253
37486 -253 253 253 253 253 253 253 253 253 253 253 253
37487 -253 253 253 253 253 253 253 253 253 253 253 253
37488 -253 253 253 253 253 253 221 221 221 6 6 6
37489 - 2 2 6 2 2 6 6 6 6 30 30 30
37490 - 2 2 6 2 2 6 2 2 6 2 2 6
37491 - 2 2 6 82 82 82 54 54 54 18 18 18
37492 - 6 6 6 0 0 0 0 0 0 0 0 0
37493 - 0 0 0 0 0 0 0 0 0 0 0 0
37494 - 0 0 0 0 0 0 0 0 0 0 0 0
37495 - 0 0 0 0 0 0 0 0 0 0 0 0
37496 - 0 0 0 0 0 0 0 0 0 0 0 0
37497 - 0 0 0 0 0 0 0 0 0 0 0 0
37498 - 0 0 0 0 0 0 0 0 0 10 10 10
37499 - 26 26 26 66 66 66 62 62 62 2 2 6
37500 - 2 2 6 38 38 38 10 10 10 26 26 26
37501 -238 238 238 253 253 253 253 253 253 253 253 253
37502 -253 253 253 253 253 253 253 253 253 253 253 253
37503 -253 253 253 253 253 253 231 231 231 238 238 238
37504 -253 253 253 253 253 253 253 253 253 253 253 253
37505 -253 253 253 253 253 253 253 253 253 253 253 253
37506 -253 253 253 253 253 253 253 253 253 253 253 253
37507 -253 253 253 253 253 253 253 253 253 253 253 253
37508 -253 253 253 253 253 253 231 231 231 6 6 6
37509 - 2 2 6 2 2 6 10 10 10 30 30 30
37510 - 2 2 6 2 2 6 2 2 6 2 2 6
37511 - 2 2 6 66 66 66 58 58 58 22 22 22
37512 - 6 6 6 0 0 0 0 0 0 0 0 0
37513 - 0 0 0 0 0 0 0 0 0 0 0 0
37514 - 0 0 0 0 0 0 0 0 0 0 0 0
37515 - 0 0 0 0 0 0 0 0 0 0 0 0
37516 - 0 0 0 0 0 0 0 0 0 0 0 0
37517 - 0 0 0 0 0 0 0 0 0 0 0 0
37518 - 0 0 0 0 0 0 0 0 0 10 10 10
37519 - 38 38 38 78 78 78 6 6 6 2 2 6
37520 - 2 2 6 46 46 46 14 14 14 42 42 42
37521 -246 246 246 253 253 253 253 253 253 253 253 253
37522 -253 253 253 253 253 253 253 253 253 253 253 253
37523 -253 253 253 253 253 253 231 231 231 242 242 242
37524 -253 253 253 253 253 253 253 253 253 253 253 253
37525 -253 253 253 253 253 253 253 253 253 253 253 253
37526 -253 253 253 253 253 253 253 253 253 253 253 253
37527 -253 253 253 253 253 253 253 253 253 253 253 253
37528 -253 253 253 253 253 253 234 234 234 10 10 10
37529 - 2 2 6 2 2 6 22 22 22 14 14 14
37530 - 2 2 6 2 2 6 2 2 6 2 2 6
37531 - 2 2 6 66 66 66 62 62 62 22 22 22
37532 - 6 6 6 0 0 0 0 0 0 0 0 0
37533 - 0 0 0 0 0 0 0 0 0 0 0 0
37534 - 0 0 0 0 0 0 0 0 0 0 0 0
37535 - 0 0 0 0 0 0 0 0 0 0 0 0
37536 - 0 0 0 0 0 0 0 0 0 0 0 0
37537 - 0 0 0 0 0 0 0 0 0 0 0 0
37538 - 0 0 0 0 0 0 6 6 6 18 18 18
37539 - 50 50 50 74 74 74 2 2 6 2 2 6
37540 - 14 14 14 70 70 70 34 34 34 62 62 62
37541 -250 250 250 253 253 253 253 253 253 253 253 253
37542 -253 253 253 253 253 253 253 253 253 253 253 253
37543 -253 253 253 253 253 253 231 231 231 246 246 246
37544 -253 253 253 253 253 253 253 253 253 253 253 253
37545 -253 253 253 253 253 253 253 253 253 253 253 253
37546 -253 253 253 253 253 253 253 253 253 253 253 253
37547 -253 253 253 253 253 253 253 253 253 253 253 253
37548 -253 253 253 253 253 253 234 234 234 14 14 14
37549 - 2 2 6 2 2 6 30 30 30 2 2 6
37550 - 2 2 6 2 2 6 2 2 6 2 2 6
37551 - 2 2 6 66 66 66 62 62 62 22 22 22
37552 - 6 6 6 0 0 0 0 0 0 0 0 0
37553 - 0 0 0 0 0 0 0 0 0 0 0 0
37554 - 0 0 0 0 0 0 0 0 0 0 0 0
37555 - 0 0 0 0 0 0 0 0 0 0 0 0
37556 - 0 0 0 0 0 0 0 0 0 0 0 0
37557 - 0 0 0 0 0 0 0 0 0 0 0 0
37558 - 0 0 0 0 0 0 6 6 6 18 18 18
37559 - 54 54 54 62 62 62 2 2 6 2 2 6
37560 - 2 2 6 30 30 30 46 46 46 70 70 70
37561 -250 250 250 253 253 253 253 253 253 253 253 253
37562 -253 253 253 253 253 253 253 253 253 253 253 253
37563 -253 253 253 253 253 253 231 231 231 246 246 246
37564 -253 253 253 253 253 253 253 253 253 253 253 253
37565 -253 253 253 253 253 253 253 253 253 253 253 253
37566 -253 253 253 253 253 253 253 253 253 253 253 253
37567 -253 253 253 253 253 253 253 253 253 253 253 253
37568 -253 253 253 253 253 253 226 226 226 10 10 10
37569 - 2 2 6 6 6 6 30 30 30 2 2 6
37570 - 2 2 6 2 2 6 2 2 6 2 2 6
37571 - 2 2 6 66 66 66 58 58 58 22 22 22
37572 - 6 6 6 0 0 0 0 0 0 0 0 0
37573 - 0 0 0 0 0 0 0 0 0 0 0 0
37574 - 0 0 0 0 0 0 0 0 0 0 0 0
37575 - 0 0 0 0 0 0 0 0 0 0 0 0
37576 - 0 0 0 0 0 0 0 0 0 0 0 0
37577 - 0 0 0 0 0 0 0 0 0 0 0 0
37578 - 0 0 0 0 0 0 6 6 6 22 22 22
37579 - 58 58 58 62 62 62 2 2 6 2 2 6
37580 - 2 2 6 2 2 6 30 30 30 78 78 78
37581 -250 250 250 253 253 253 253 253 253 253 253 253
37582 -253 253 253 253 253 253 253 253 253 253 253 253
37583 -253 253 253 253 253 253 231 231 231 246 246 246
37584 -253 253 253 253 253 253 253 253 253 253 253 253
37585 -253 253 253 253 253 253 253 253 253 253 253 253
37586 -253 253 253 253 253 253 253 253 253 253 253 253
37587 -253 253 253 253 253 253 253 253 253 253 253 253
37588 -253 253 253 253 253 253 206 206 206 2 2 6
37589 - 22 22 22 34 34 34 18 14 6 22 22 22
37590 - 26 26 26 18 18 18 6 6 6 2 2 6
37591 - 2 2 6 82 82 82 54 54 54 18 18 18
37592 - 6 6 6 0 0 0 0 0 0 0 0 0
37593 - 0 0 0 0 0 0 0 0 0 0 0 0
37594 - 0 0 0 0 0 0 0 0 0 0 0 0
37595 - 0 0 0 0 0 0 0 0 0 0 0 0
37596 - 0 0 0 0 0 0 0 0 0 0 0 0
37597 - 0 0 0 0 0 0 0 0 0 0 0 0
37598 - 0 0 0 0 0 0 6 6 6 26 26 26
37599 - 62 62 62 106 106 106 74 54 14 185 133 11
37600 -210 162 10 121 92 8 6 6 6 62 62 62
37601 -238 238 238 253 253 253 253 253 253 253 253 253
37602 -253 253 253 253 253 253 253 253 253 253 253 253
37603 -253 253 253 253 253 253 231 231 231 246 246 246
37604 -253 253 253 253 253 253 253 253 253 253 253 253
37605 -253 253 253 253 253 253 253 253 253 253 253 253
37606 -253 253 253 253 253 253 253 253 253 253 253 253
37607 -253 253 253 253 253 253 253 253 253 253 253 253
37608 -253 253 253 253 253 253 158 158 158 18 18 18
37609 - 14 14 14 2 2 6 2 2 6 2 2 6
37610 - 6 6 6 18 18 18 66 66 66 38 38 38
37611 - 6 6 6 94 94 94 50 50 50 18 18 18
37612 - 6 6 6 0 0 0 0 0 0 0 0 0
37613 - 0 0 0 0 0 0 0 0 0 0 0 0
37614 - 0 0 0 0 0 0 0 0 0 0 0 0
37615 - 0 0 0 0 0 0 0 0 0 0 0 0
37616 - 0 0 0 0 0 0 0 0 0 0 0 0
37617 - 0 0 0 0 0 0 0 0 0 6 6 6
37618 - 10 10 10 10 10 10 18 18 18 38 38 38
37619 - 78 78 78 142 134 106 216 158 10 242 186 14
37620 -246 190 14 246 190 14 156 118 10 10 10 10
37621 - 90 90 90 238 238 238 253 253 253 253 253 253
37622 -253 253 253 253 253 253 253 253 253 253 253 253
37623 -253 253 253 253 253 253 231 231 231 250 250 250
37624 -253 253 253 253 253 253 253 253 253 253 253 253
37625 -253 253 253 253 253 253 253 253 253 253 253 253
37626 -253 253 253 253 253 253 253 253 253 253 253 253
37627 -253 253 253 253 253 253 253 253 253 246 230 190
37628 -238 204 91 238 204 91 181 142 44 37 26 9
37629 - 2 2 6 2 2 6 2 2 6 2 2 6
37630 - 2 2 6 2 2 6 38 38 38 46 46 46
37631 - 26 26 26 106 106 106 54 54 54 18 18 18
37632 - 6 6 6 0 0 0 0 0 0 0 0 0
37633 - 0 0 0 0 0 0 0 0 0 0 0 0
37634 - 0 0 0 0 0 0 0 0 0 0 0 0
37635 - 0 0 0 0 0 0 0 0 0 0 0 0
37636 - 0 0 0 0 0 0 0 0 0 0 0 0
37637 - 0 0 0 6 6 6 14 14 14 22 22 22
37638 - 30 30 30 38 38 38 50 50 50 70 70 70
37639 -106 106 106 190 142 34 226 170 11 242 186 14
37640 -246 190 14 246 190 14 246 190 14 154 114 10
37641 - 6 6 6 74 74 74 226 226 226 253 253 253
37642 -253 253 253 253 253 253 253 253 253 253 253 253
37643 -253 253 253 253 253 253 231 231 231 250 250 250
37644 -253 253 253 253 253 253 253 253 253 253 253 253
37645 -253 253 253 253 253 253 253 253 253 253 253 253
37646 -253 253 253 253 253 253 253 253 253 253 253 253
37647 -253 253 253 253 253 253 253 253 253 228 184 62
37648 -241 196 14 241 208 19 232 195 16 38 30 10
37649 - 2 2 6 2 2 6 2 2 6 2 2 6
37650 - 2 2 6 6 6 6 30 30 30 26 26 26
37651 -203 166 17 154 142 90 66 66 66 26 26 26
37652 - 6 6 6 0 0 0 0 0 0 0 0 0
37653 - 0 0 0 0 0 0 0 0 0 0 0 0
37654 - 0 0 0 0 0 0 0 0 0 0 0 0
37655 - 0 0 0 0 0 0 0 0 0 0 0 0
37656 - 0 0 0 0 0 0 0 0 0 0 0 0
37657 - 6 6 6 18 18 18 38 38 38 58 58 58
37658 - 78 78 78 86 86 86 101 101 101 123 123 123
37659 -175 146 61 210 150 10 234 174 13 246 186 14
37660 -246 190 14 246 190 14 246 190 14 238 190 10
37661 -102 78 10 2 2 6 46 46 46 198 198 198
37662 -253 253 253 253 253 253 253 253 253 253 253 253
37663 -253 253 253 253 253 253 234 234 234 242 242 242
37664 -253 253 253 253 253 253 253 253 253 253 253 253
37665 -253 253 253 253 253 253 253 253 253 253 253 253
37666 -253 253 253 253 253 253 253 253 253 253 253 253
37667 -253 253 253 253 253 253 253 253 253 224 178 62
37668 -242 186 14 241 196 14 210 166 10 22 18 6
37669 - 2 2 6 2 2 6 2 2 6 2 2 6
37670 - 2 2 6 2 2 6 6 6 6 121 92 8
37671 -238 202 15 232 195 16 82 82 82 34 34 34
37672 - 10 10 10 0 0 0 0 0 0 0 0 0
37673 - 0 0 0 0 0 0 0 0 0 0 0 0
37674 - 0 0 0 0 0 0 0 0 0 0 0 0
37675 - 0 0 0 0 0 0 0 0 0 0 0 0
37676 - 0 0 0 0 0 0 0 0 0 0 0 0
37677 - 14 14 14 38 38 38 70 70 70 154 122 46
37678 -190 142 34 200 144 11 197 138 11 197 138 11
37679 -213 154 11 226 170 11 242 186 14 246 190 14
37680 -246 190 14 246 190 14 246 190 14 246 190 14
37681 -225 175 15 46 32 6 2 2 6 22 22 22
37682 -158 158 158 250 250 250 253 253 253 253 253 253
37683 -253 253 253 253 253 253 253 253 253 253 253 253
37684 -253 253 253 253 253 253 253 253 253 253 253 253
37685 -253 253 253 253 253 253 253 253 253 253 253 253
37686 -253 253 253 253 253 253 253 253 253 253 253 253
37687 -253 253 253 250 250 250 242 242 242 224 178 62
37688 -239 182 13 236 186 11 213 154 11 46 32 6
37689 - 2 2 6 2 2 6 2 2 6 2 2 6
37690 - 2 2 6 2 2 6 61 42 6 225 175 15
37691 -238 190 10 236 186 11 112 100 78 42 42 42
37692 - 14 14 14 0 0 0 0 0 0 0 0 0
37693 - 0 0 0 0 0 0 0 0 0 0 0 0
37694 - 0 0 0 0 0 0 0 0 0 0 0 0
37695 - 0 0 0 0 0 0 0 0 0 0 0 0
37696 - 0 0 0 0 0 0 0 0 0 6 6 6
37697 - 22 22 22 54 54 54 154 122 46 213 154 11
37698 -226 170 11 230 174 11 226 170 11 226 170 11
37699 -236 178 12 242 186 14 246 190 14 246 190 14
37700 -246 190 14 246 190 14 246 190 14 246 190 14
37701 -241 196 14 184 144 12 10 10 10 2 2 6
37702 - 6 6 6 116 116 116 242 242 242 253 253 253
37703 -253 253 253 253 253 253 253 253 253 253 253 253
37704 -253 253 253 253 253 253 253 253 253 253 253 253
37705 -253 253 253 253 253 253 253 253 253 253 253 253
37706 -253 253 253 253 253 253 253 253 253 253 253 253
37707 -253 253 253 231 231 231 198 198 198 214 170 54
37708 -236 178 12 236 178 12 210 150 10 137 92 6
37709 - 18 14 6 2 2 6 2 2 6 2 2 6
37710 - 6 6 6 70 47 6 200 144 11 236 178 12
37711 -239 182 13 239 182 13 124 112 88 58 58 58
37712 - 22 22 22 6 6 6 0 0 0 0 0 0
37713 - 0 0 0 0 0 0 0 0 0 0 0 0
37714 - 0 0 0 0 0 0 0 0 0 0 0 0
37715 - 0 0 0 0 0 0 0 0 0 0 0 0
37716 - 0 0 0 0 0 0 0 0 0 10 10 10
37717 - 30 30 30 70 70 70 180 133 36 226 170 11
37718 -239 182 13 242 186 14 242 186 14 246 186 14
37719 -246 190 14 246 190 14 246 190 14 246 190 14
37720 -246 190 14 246 190 14 246 190 14 246 190 14
37721 -246 190 14 232 195 16 98 70 6 2 2 6
37722 - 2 2 6 2 2 6 66 66 66 221 221 221
37723 -253 253 253 253 253 253 253 253 253 253 253 253
37724 -253 253 253 253 253 253 253 253 253 253 253 253
37725 -253 253 253 253 253 253 253 253 253 253 253 253
37726 -253 253 253 253 253 253 253 253 253 253 253 253
37727 -253 253 253 206 206 206 198 198 198 214 166 58
37728 -230 174 11 230 174 11 216 158 10 192 133 9
37729 -163 110 8 116 81 8 102 78 10 116 81 8
37730 -167 114 7 197 138 11 226 170 11 239 182 13
37731 -242 186 14 242 186 14 162 146 94 78 78 78
37732 - 34 34 34 14 14 14 6 6 6 0 0 0
37733 - 0 0 0 0 0 0 0 0 0 0 0 0
37734 - 0 0 0 0 0 0 0 0 0 0 0 0
37735 - 0 0 0 0 0 0 0 0 0 0 0 0
37736 - 0 0 0 0 0 0 0 0 0 6 6 6
37737 - 30 30 30 78 78 78 190 142 34 226 170 11
37738 -239 182 13 246 190 14 246 190 14 246 190 14
37739 -246 190 14 246 190 14 246 190 14 246 190 14
37740 -246 190 14 246 190 14 246 190 14 246 190 14
37741 -246 190 14 241 196 14 203 166 17 22 18 6
37742 - 2 2 6 2 2 6 2 2 6 38 38 38
37743 -218 218 218 253 253 253 253 253 253 253 253 253
37744 -253 253 253 253 253 253 253 253 253 253 253 253
37745 -253 253 253 253 253 253 253 253 253 253 253 253
37746 -253 253 253 253 253 253 253 253 253 253 253 253
37747 -250 250 250 206 206 206 198 198 198 202 162 69
37748 -226 170 11 236 178 12 224 166 10 210 150 10
37749 -200 144 11 197 138 11 192 133 9 197 138 11
37750 -210 150 10 226 170 11 242 186 14 246 190 14
37751 -246 190 14 246 186 14 225 175 15 124 112 88
37752 - 62 62 62 30 30 30 14 14 14 6 6 6
37753 - 0 0 0 0 0 0 0 0 0 0 0 0
37754 - 0 0 0 0 0 0 0 0 0 0 0 0
37755 - 0 0 0 0 0 0 0 0 0 0 0 0
37756 - 0 0 0 0 0 0 0 0 0 10 10 10
37757 - 30 30 30 78 78 78 174 135 50 224 166 10
37758 -239 182 13 246 190 14 246 190 14 246 190 14
37759 -246 190 14 246 190 14 246 190 14 246 190 14
37760 -246 190 14 246 190 14 246 190 14 246 190 14
37761 -246 190 14 246 190 14 241 196 14 139 102 15
37762 - 2 2 6 2 2 6 2 2 6 2 2 6
37763 - 78 78 78 250 250 250 253 253 253 253 253 253
37764 -253 253 253 253 253 253 253 253 253 253 253 253
37765 -253 253 253 253 253 253 253 253 253 253 253 253
37766 -253 253 253 253 253 253 253 253 253 253 253 253
37767 -250 250 250 214 214 214 198 198 198 190 150 46
37768 -219 162 10 236 178 12 234 174 13 224 166 10
37769 -216 158 10 213 154 11 213 154 11 216 158 10
37770 -226 170 11 239 182 13 246 190 14 246 190 14
37771 -246 190 14 246 190 14 242 186 14 206 162 42
37772 -101 101 101 58 58 58 30 30 30 14 14 14
37773 - 6 6 6 0 0 0 0 0 0 0 0 0
37774 - 0 0 0 0 0 0 0 0 0 0 0 0
37775 - 0 0 0 0 0 0 0 0 0 0 0 0
37776 - 0 0 0 0 0 0 0 0 0 10 10 10
37777 - 30 30 30 74 74 74 174 135 50 216 158 10
37778 -236 178 12 246 190 14 246 190 14 246 190 14
37779 -246 190 14 246 190 14 246 190 14 246 190 14
37780 -246 190 14 246 190 14 246 190 14 246 190 14
37781 -246 190 14 246 190 14 241 196 14 226 184 13
37782 - 61 42 6 2 2 6 2 2 6 2 2 6
37783 - 22 22 22 238 238 238 253 253 253 253 253 253
37784 -253 253 253 253 253 253 253 253 253 253 253 253
37785 -253 253 253 253 253 253 253 253 253 253 253 253
37786 -253 253 253 253 253 253 253 253 253 253 253 253
37787 -253 253 253 226 226 226 187 187 187 180 133 36
37788 -216 158 10 236 178 12 239 182 13 236 178 12
37789 -230 174 11 226 170 11 226 170 11 230 174 11
37790 -236 178 12 242 186 14 246 190 14 246 190 14
37791 -246 190 14 246 190 14 246 186 14 239 182 13
37792 -206 162 42 106 106 106 66 66 66 34 34 34
37793 - 14 14 14 6 6 6 0 0 0 0 0 0
37794 - 0 0 0 0 0 0 0 0 0 0 0 0
37795 - 0 0 0 0 0 0 0 0 0 0 0 0
37796 - 0 0 0 0 0 0 0 0 0 6 6 6
37797 - 26 26 26 70 70 70 163 133 67 213 154 11
37798 -236 178 12 246 190 14 246 190 14 246 190 14
37799 -246 190 14 246 190 14 246 190 14 246 190 14
37800 -246 190 14 246 190 14 246 190 14 246 190 14
37801 -246 190 14 246 190 14 246 190 14 241 196 14
37802 -190 146 13 18 14 6 2 2 6 2 2 6
37803 - 46 46 46 246 246 246 253 253 253 253 253 253
37804 -253 253 253 253 253 253 253 253 253 253 253 253
37805 -253 253 253 253 253 253 253 253 253 253 253 253
37806 -253 253 253 253 253 253 253 253 253 253 253 253
37807 -253 253 253 221 221 221 86 86 86 156 107 11
37808 -216 158 10 236 178 12 242 186 14 246 186 14
37809 -242 186 14 239 182 13 239 182 13 242 186 14
37810 -242 186 14 246 186 14 246 190 14 246 190 14
37811 -246 190 14 246 190 14 246 190 14 246 190 14
37812 -242 186 14 225 175 15 142 122 72 66 66 66
37813 - 30 30 30 10 10 10 0 0 0 0 0 0
37814 - 0 0 0 0 0 0 0 0 0 0 0 0
37815 - 0 0 0 0 0 0 0 0 0 0 0 0
37816 - 0 0 0 0 0 0 0 0 0 6 6 6
37817 - 26 26 26 70 70 70 163 133 67 210 150 10
37818 -236 178 12 246 190 14 246 190 14 246 190 14
37819 -246 190 14 246 190 14 246 190 14 246 190 14
37820 -246 190 14 246 190 14 246 190 14 246 190 14
37821 -246 190 14 246 190 14 246 190 14 246 190 14
37822 -232 195 16 121 92 8 34 34 34 106 106 106
37823 -221 221 221 253 253 253 253 253 253 253 253 253
37824 -253 253 253 253 253 253 253 253 253 253 253 253
37825 -253 253 253 253 253 253 253 253 253 253 253 253
37826 -253 253 253 253 253 253 253 253 253 253 253 253
37827 -242 242 242 82 82 82 18 14 6 163 110 8
37828 -216 158 10 236 178 12 242 186 14 246 190 14
37829 -246 190 14 246 190 14 246 190 14 246 190 14
37830 -246 190 14 246 190 14 246 190 14 246 190 14
37831 -246 190 14 246 190 14 246 190 14 246 190 14
37832 -246 190 14 246 190 14 242 186 14 163 133 67
37833 - 46 46 46 18 18 18 6 6 6 0 0 0
37834 - 0 0 0 0 0 0 0 0 0 0 0 0
37835 - 0 0 0 0 0 0 0 0 0 0 0 0
37836 - 0 0 0 0 0 0 0 0 0 10 10 10
37837 - 30 30 30 78 78 78 163 133 67 210 150 10
37838 -236 178 12 246 186 14 246 190 14 246 190 14
37839 -246 190 14 246 190 14 246 190 14 246 190 14
37840 -246 190 14 246 190 14 246 190 14 246 190 14
37841 -246 190 14 246 190 14 246 190 14 246 190 14
37842 -241 196 14 215 174 15 190 178 144 253 253 253
37843 -253 253 253 253 253 253 253 253 253 253 253 253
37844 -253 253 253 253 253 253 253 253 253 253 253 253
37845 -253 253 253 253 253 253 253 253 253 253 253 253
37846 -253 253 253 253 253 253 253 253 253 218 218 218
37847 - 58 58 58 2 2 6 22 18 6 167 114 7
37848 -216 158 10 236 178 12 246 186 14 246 190 14
37849 -246 190 14 246 190 14 246 190 14 246 190 14
37850 -246 190 14 246 190 14 246 190 14 246 190 14
37851 -246 190 14 246 190 14 246 190 14 246 190 14
37852 -246 190 14 246 186 14 242 186 14 190 150 46
37853 - 54 54 54 22 22 22 6 6 6 0 0 0
37854 - 0 0 0 0 0 0 0 0 0 0 0 0
37855 - 0 0 0 0 0 0 0 0 0 0 0 0
37856 - 0 0 0 0 0 0 0 0 0 14 14 14
37857 - 38 38 38 86 86 86 180 133 36 213 154 11
37858 -236 178 12 246 186 14 246 190 14 246 190 14
37859 -246 190 14 246 190 14 246 190 14 246 190 14
37860 -246 190 14 246 190 14 246 190 14 246 190 14
37861 -246 190 14 246 190 14 246 190 14 246 190 14
37862 -246 190 14 232 195 16 190 146 13 214 214 214
37863 -253 253 253 253 253 253 253 253 253 253 253 253
37864 -253 253 253 253 253 253 253 253 253 253 253 253
37865 -253 253 253 253 253 253 253 253 253 253 253 253
37866 -253 253 253 250 250 250 170 170 170 26 26 26
37867 - 2 2 6 2 2 6 37 26 9 163 110 8
37868 -219 162 10 239 182 13 246 186 14 246 190 14
37869 -246 190 14 246 190 14 246 190 14 246 190 14
37870 -246 190 14 246 190 14 246 190 14 246 190 14
37871 -246 190 14 246 190 14 246 190 14 246 190 14
37872 -246 186 14 236 178 12 224 166 10 142 122 72
37873 - 46 46 46 18 18 18 6 6 6 0 0 0
37874 - 0 0 0 0 0 0 0 0 0 0 0 0
37875 - 0 0 0 0 0 0 0 0 0 0 0 0
37876 - 0 0 0 0 0 0 6 6 6 18 18 18
37877 - 50 50 50 109 106 95 192 133 9 224 166 10
37878 -242 186 14 246 190 14 246 190 14 246 190 14
37879 -246 190 14 246 190 14 246 190 14 246 190 14
37880 -246 190 14 246 190 14 246 190 14 246 190 14
37881 -246 190 14 246 190 14 246 190 14 246 190 14
37882 -242 186 14 226 184 13 210 162 10 142 110 46
37883 -226 226 226 253 253 253 253 253 253 253 253 253
37884 -253 253 253 253 253 253 253 253 253 253 253 253
37885 -253 253 253 253 253 253 253 253 253 253 253 253
37886 -198 198 198 66 66 66 2 2 6 2 2 6
37887 - 2 2 6 2 2 6 50 34 6 156 107 11
37888 -219 162 10 239 182 13 246 186 14 246 190 14
37889 -246 190 14 246 190 14 246 190 14 246 190 14
37890 -246 190 14 246 190 14 246 190 14 246 190 14
37891 -246 190 14 246 190 14 246 190 14 242 186 14
37892 -234 174 13 213 154 11 154 122 46 66 66 66
37893 - 30 30 30 10 10 10 0 0 0 0 0 0
37894 - 0 0 0 0 0 0 0 0 0 0 0 0
37895 - 0 0 0 0 0 0 0 0 0 0 0 0
37896 - 0 0 0 0 0 0 6 6 6 22 22 22
37897 - 58 58 58 154 121 60 206 145 10 234 174 13
37898 -242 186 14 246 186 14 246 190 14 246 190 14
37899 -246 190 14 246 190 14 246 190 14 246 190 14
37900 -246 190 14 246 190 14 246 190 14 246 190 14
37901 -246 190 14 246 190 14 246 190 14 246 190 14
37902 -246 186 14 236 178 12 210 162 10 163 110 8
37903 - 61 42 6 138 138 138 218 218 218 250 250 250
37904 -253 253 253 253 253 253 253 253 253 250 250 250
37905 -242 242 242 210 210 210 144 144 144 66 66 66
37906 - 6 6 6 2 2 6 2 2 6 2 2 6
37907 - 2 2 6 2 2 6 61 42 6 163 110 8
37908 -216 158 10 236 178 12 246 190 14 246 190 14
37909 -246 190 14 246 190 14 246 190 14 246 190 14
37910 -246 190 14 246 190 14 246 190 14 246 190 14
37911 -246 190 14 239 182 13 230 174 11 216 158 10
37912 -190 142 34 124 112 88 70 70 70 38 38 38
37913 - 18 18 18 6 6 6 0 0 0 0 0 0
37914 - 0 0 0 0 0 0 0 0 0 0 0 0
37915 - 0 0 0 0 0 0 0 0 0 0 0 0
37916 - 0 0 0 0 0 0 6 6 6 22 22 22
37917 - 62 62 62 168 124 44 206 145 10 224 166 10
37918 -236 178 12 239 182 13 242 186 14 242 186 14
37919 -246 186 14 246 190 14 246 190 14 246 190 14
37920 -246 190 14 246 190 14 246 190 14 246 190 14
37921 -246 190 14 246 190 14 246 190 14 246 190 14
37922 -246 190 14 236 178 12 216 158 10 175 118 6
37923 - 80 54 7 2 2 6 6 6 6 30 30 30
37924 - 54 54 54 62 62 62 50 50 50 38 38 38
37925 - 14 14 14 2 2 6 2 2 6 2 2 6
37926 - 2 2 6 2 2 6 2 2 6 2 2 6
37927 - 2 2 6 6 6 6 80 54 7 167 114 7
37928 -213 154 11 236 178 12 246 190 14 246 190 14
37929 -246 190 14 246 190 14 246 190 14 246 190 14
37930 -246 190 14 242 186 14 239 182 13 239 182 13
37931 -230 174 11 210 150 10 174 135 50 124 112 88
37932 - 82 82 82 54 54 54 34 34 34 18 18 18
37933 - 6 6 6 0 0 0 0 0 0 0 0 0
37934 - 0 0 0 0 0 0 0 0 0 0 0 0
37935 - 0 0 0 0 0 0 0 0 0 0 0 0
37936 - 0 0 0 0 0 0 6 6 6 18 18 18
37937 - 50 50 50 158 118 36 192 133 9 200 144 11
37938 -216 158 10 219 162 10 224 166 10 226 170 11
37939 -230 174 11 236 178 12 239 182 13 239 182 13
37940 -242 186 14 246 186 14 246 190 14 246 190 14
37941 -246 190 14 246 190 14 246 190 14 246 190 14
37942 -246 186 14 230 174 11 210 150 10 163 110 8
37943 -104 69 6 10 10 10 2 2 6 2 2 6
37944 - 2 2 6 2 2 6 2 2 6 2 2 6
37945 - 2 2 6 2 2 6 2 2 6 2 2 6
37946 - 2 2 6 2 2 6 2 2 6 2 2 6
37947 - 2 2 6 6 6 6 91 60 6 167 114 7
37948 -206 145 10 230 174 11 242 186 14 246 190 14
37949 -246 190 14 246 190 14 246 186 14 242 186 14
37950 -239 182 13 230 174 11 224 166 10 213 154 11
37951 -180 133 36 124 112 88 86 86 86 58 58 58
37952 - 38 38 38 22 22 22 10 10 10 6 6 6
37953 - 0 0 0 0 0 0 0 0 0 0 0 0
37954 - 0 0 0 0 0 0 0 0 0 0 0 0
37955 - 0 0 0 0 0 0 0 0 0 0 0 0
37956 - 0 0 0 0 0 0 0 0 0 14 14 14
37957 - 34 34 34 70 70 70 138 110 50 158 118 36
37958 -167 114 7 180 123 7 192 133 9 197 138 11
37959 -200 144 11 206 145 10 213 154 11 219 162 10
37960 -224 166 10 230 174 11 239 182 13 242 186 14
37961 -246 186 14 246 186 14 246 186 14 246 186 14
37962 -239 182 13 216 158 10 185 133 11 152 99 6
37963 -104 69 6 18 14 6 2 2 6 2 2 6
37964 - 2 2 6 2 2 6 2 2 6 2 2 6
37965 - 2 2 6 2 2 6 2 2 6 2 2 6
37966 - 2 2 6 2 2 6 2 2 6 2 2 6
37967 - 2 2 6 6 6 6 80 54 7 152 99 6
37968 -192 133 9 219 162 10 236 178 12 239 182 13
37969 -246 186 14 242 186 14 239 182 13 236 178 12
37970 -224 166 10 206 145 10 192 133 9 154 121 60
37971 - 94 94 94 62 62 62 42 42 42 22 22 22
37972 - 14 14 14 6 6 6 0 0 0 0 0 0
37973 - 0 0 0 0 0 0 0 0 0 0 0 0
37974 - 0 0 0 0 0 0 0 0 0 0 0 0
37975 - 0 0 0 0 0 0 0 0 0 0 0 0
37976 - 0 0 0 0 0 0 0 0 0 6 6 6
37977 - 18 18 18 34 34 34 58 58 58 78 78 78
37978 -101 98 89 124 112 88 142 110 46 156 107 11
37979 -163 110 8 167 114 7 175 118 6 180 123 7
37980 -185 133 11 197 138 11 210 150 10 219 162 10
37981 -226 170 11 236 178 12 236 178 12 234 174 13
37982 -219 162 10 197 138 11 163 110 8 130 83 6
37983 - 91 60 6 10 10 10 2 2 6 2 2 6
37984 - 18 18 18 38 38 38 38 38 38 38 38 38
37985 - 38 38 38 38 38 38 38 38 38 38 38 38
37986 - 38 38 38 38 38 38 26 26 26 2 2 6
37987 - 2 2 6 6 6 6 70 47 6 137 92 6
37988 -175 118 6 200 144 11 219 162 10 230 174 11
37989 -234 174 13 230 174 11 219 162 10 210 150 10
37990 -192 133 9 163 110 8 124 112 88 82 82 82
37991 - 50 50 50 30 30 30 14 14 14 6 6 6
37992 - 0 0 0 0 0 0 0 0 0 0 0 0
37993 - 0 0 0 0 0 0 0 0 0 0 0 0
37994 - 0 0 0 0 0 0 0 0 0 0 0 0
37995 - 0 0 0 0 0 0 0 0 0 0 0 0
37996 - 0 0 0 0 0 0 0 0 0 0 0 0
37997 - 6 6 6 14 14 14 22 22 22 34 34 34
37998 - 42 42 42 58 58 58 74 74 74 86 86 86
37999 -101 98 89 122 102 70 130 98 46 121 87 25
38000 -137 92 6 152 99 6 163 110 8 180 123 7
38001 -185 133 11 197 138 11 206 145 10 200 144 11
38002 -180 123 7 156 107 11 130 83 6 104 69 6
38003 - 50 34 6 54 54 54 110 110 110 101 98 89
38004 - 86 86 86 82 82 82 78 78 78 78 78 78
38005 - 78 78 78 78 78 78 78 78 78 78 78 78
38006 - 78 78 78 82 82 82 86 86 86 94 94 94
38007 -106 106 106 101 101 101 86 66 34 124 80 6
38008 -156 107 11 180 123 7 192 133 9 200 144 11
38009 -206 145 10 200 144 11 192 133 9 175 118 6
38010 -139 102 15 109 106 95 70 70 70 42 42 42
38011 - 22 22 22 10 10 10 0 0 0 0 0 0
38012 - 0 0 0 0 0 0 0 0 0 0 0 0
38013 - 0 0 0 0 0 0 0 0 0 0 0 0
38014 - 0 0 0 0 0 0 0 0 0 0 0 0
38015 - 0 0 0 0 0 0 0 0 0 0 0 0
38016 - 0 0 0 0 0 0 0 0 0 0 0 0
38017 - 0 0 0 0 0 0 6 6 6 10 10 10
38018 - 14 14 14 22 22 22 30 30 30 38 38 38
38019 - 50 50 50 62 62 62 74 74 74 90 90 90
38020 -101 98 89 112 100 78 121 87 25 124 80 6
38021 -137 92 6 152 99 6 152 99 6 152 99 6
38022 -138 86 6 124 80 6 98 70 6 86 66 30
38023 -101 98 89 82 82 82 58 58 58 46 46 46
38024 - 38 38 38 34 34 34 34 34 34 34 34 34
38025 - 34 34 34 34 34 34 34 34 34 34 34 34
38026 - 34 34 34 34 34 34 38 38 38 42 42 42
38027 - 54 54 54 82 82 82 94 86 76 91 60 6
38028 -134 86 6 156 107 11 167 114 7 175 118 6
38029 -175 118 6 167 114 7 152 99 6 121 87 25
38030 -101 98 89 62 62 62 34 34 34 18 18 18
38031 - 6 6 6 0 0 0 0 0 0 0 0 0
38032 - 0 0 0 0 0 0 0 0 0 0 0 0
38033 - 0 0 0 0 0 0 0 0 0 0 0 0
38034 - 0 0 0 0 0 0 0 0 0 0 0 0
38035 - 0 0 0 0 0 0 0 0 0 0 0 0
38036 - 0 0 0 0 0 0 0 0 0 0 0 0
38037 - 0 0 0 0 0 0 0 0 0 0 0 0
38038 - 0 0 0 6 6 6 6 6 6 10 10 10
38039 - 18 18 18 22 22 22 30 30 30 42 42 42
38040 - 50 50 50 66 66 66 86 86 86 101 98 89
38041 -106 86 58 98 70 6 104 69 6 104 69 6
38042 -104 69 6 91 60 6 82 62 34 90 90 90
38043 - 62 62 62 38 38 38 22 22 22 14 14 14
38044 - 10 10 10 10 10 10 10 10 10 10 10 10
38045 - 10 10 10 10 10 10 6 6 6 10 10 10
38046 - 10 10 10 10 10 10 10 10 10 14 14 14
38047 - 22 22 22 42 42 42 70 70 70 89 81 66
38048 - 80 54 7 104 69 6 124 80 6 137 92 6
38049 -134 86 6 116 81 8 100 82 52 86 86 86
38050 - 58 58 58 30 30 30 14 14 14 6 6 6
38051 - 0 0 0 0 0 0 0 0 0 0 0 0
38052 - 0 0 0 0 0 0 0 0 0 0 0 0
38053 - 0 0 0 0 0 0 0 0 0 0 0 0
38054 - 0 0 0 0 0 0 0 0 0 0 0 0
38055 - 0 0 0 0 0 0 0 0 0 0 0 0
38056 - 0 0 0 0 0 0 0 0 0 0 0 0
38057 - 0 0 0 0 0 0 0 0 0 0 0 0
38058 - 0 0 0 0 0 0 0 0 0 0 0 0
38059 - 0 0 0 6 6 6 10 10 10 14 14 14
38060 - 18 18 18 26 26 26 38 38 38 54 54 54
38061 - 70 70 70 86 86 86 94 86 76 89 81 66
38062 - 89 81 66 86 86 86 74 74 74 50 50 50
38063 - 30 30 30 14 14 14 6 6 6 0 0 0
38064 - 0 0 0 0 0 0 0 0 0 0 0 0
38065 - 0 0 0 0 0 0 0 0 0 0 0 0
38066 - 0 0 0 0 0 0 0 0 0 0 0 0
38067 - 6 6 6 18 18 18 34 34 34 58 58 58
38068 - 82 82 82 89 81 66 89 81 66 89 81 66
38069 - 94 86 66 94 86 76 74 74 74 50 50 50
38070 - 26 26 26 14 14 14 6 6 6 0 0 0
38071 - 0 0 0 0 0 0 0 0 0 0 0 0
38072 - 0 0 0 0 0 0 0 0 0 0 0 0
38073 - 0 0 0 0 0 0 0 0 0 0 0 0
38074 - 0 0 0 0 0 0 0 0 0 0 0 0
38075 - 0 0 0 0 0 0 0 0 0 0 0 0
38076 - 0 0 0 0 0 0 0 0 0 0 0 0
38077 - 0 0 0 0 0 0 0 0 0 0 0 0
38078 - 0 0 0 0 0 0 0 0 0 0 0 0
38079 - 0 0 0 0 0 0 0 0 0 0 0 0
38080 - 6 6 6 6 6 6 14 14 14 18 18 18
38081 - 30 30 30 38 38 38 46 46 46 54 54 54
38082 - 50 50 50 42 42 42 30 30 30 18 18 18
38083 - 10 10 10 0 0 0 0 0 0 0 0 0
38084 - 0 0 0 0 0 0 0 0 0 0 0 0
38085 - 0 0 0 0 0 0 0 0 0 0 0 0
38086 - 0 0 0 0 0 0 0 0 0 0 0 0
38087 - 0 0 0 6 6 6 14 14 14 26 26 26
38088 - 38 38 38 50 50 50 58 58 58 58 58 58
38089 - 54 54 54 42 42 42 30 30 30 18 18 18
38090 - 10 10 10 0 0 0 0 0 0 0 0 0
38091 - 0 0 0 0 0 0 0 0 0 0 0 0
38092 - 0 0 0 0 0 0 0 0 0 0 0 0
38093 - 0 0 0 0 0 0 0 0 0 0 0 0
38094 - 0 0 0 0 0 0 0 0 0 0 0 0
38095 - 0 0 0 0 0 0 0 0 0 0 0 0
38096 - 0 0 0 0 0 0 0 0 0 0 0 0
38097 - 0 0 0 0 0 0 0 0 0 0 0 0
38098 - 0 0 0 0 0 0 0 0 0 0 0 0
38099 - 0 0 0 0 0 0 0 0 0 0 0 0
38100 - 0 0 0 0 0 0 0 0 0 6 6 6
38101 - 6 6 6 10 10 10 14 14 14 18 18 18
38102 - 18 18 18 14 14 14 10 10 10 6 6 6
38103 - 0 0 0 0 0 0 0 0 0 0 0 0
38104 - 0 0 0 0 0 0 0 0 0 0 0 0
38105 - 0 0 0 0 0 0 0 0 0 0 0 0
38106 - 0 0 0 0 0 0 0 0 0 0 0 0
38107 - 0 0 0 0 0 0 0 0 0 6 6 6
38108 - 14 14 14 18 18 18 22 22 22 22 22 22
38109 - 18 18 18 14 14 14 10 10 10 6 6 6
38110 - 0 0 0 0 0 0 0 0 0 0 0 0
38111 - 0 0 0 0 0 0 0 0 0 0 0 0
38112 - 0 0 0 0 0 0 0 0 0 0 0 0
38113 - 0 0 0 0 0 0 0 0 0 0 0 0
38114 - 0 0 0 0 0 0 0 0 0 0 0 0
38115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38128 +4 4 4 4 4 4
38129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38142 +4 4 4 4 4 4
38143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38156 +4 4 4 4 4 4
38157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38170 +4 4 4 4 4 4
38171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38184 +4 4 4 4 4 4
38185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38198 +4 4 4 4 4 4
38199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38203 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
38204 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
38205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38208 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
38209 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38210 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
38211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38212 +4 4 4 4 4 4
38213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38217 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
38218 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
38219 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38222 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
38223 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
38224 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
38225 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38226 +4 4 4 4 4 4
38227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38231 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
38232 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
38233 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38236 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
38237 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
38238 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
38239 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
38240 +4 4 4 4 4 4
38241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38244 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
38245 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
38246 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
38247 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
38248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38249 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
38250 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
38251 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
38252 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
38253 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
38254 +4 4 4 4 4 4
38255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38258 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
38259 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
38260 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
38261 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
38262 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
38263 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
38264 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
38265 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
38266 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
38267 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
38268 +4 4 4 4 4 4
38269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
38272 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
38273 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
38274 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
38275 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
38276 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
38277 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
38278 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
38279 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
38280 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
38281 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
38282 +4 4 4 4 4 4
38283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38285 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
38286 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
38287 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
38288 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
38289 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
38290 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
38291 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
38292 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
38293 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
38294 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
38295 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
38296 +4 4 4 4 4 4
38297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38299 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
38300 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
38301 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
38302 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
38303 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
38304 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
38305 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
38306 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
38307 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
38308 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
38309 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
38310 +4 4 4 4 4 4
38311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38313 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
38314 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
38315 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
38316 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
38317 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
38318 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
38319 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
38320 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
38321 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
38322 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
38323 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38324 +4 4 4 4 4 4
38325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38327 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
38328 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
38329 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
38330 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
38331 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
38332 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
38333 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
38334 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
38335 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
38336 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
38337 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
38338 +4 4 4 4 4 4
38339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38340 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
38341 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
38342 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
38343 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
38344 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
38345 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
38346 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
38347 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
38348 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
38349 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
38350 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
38351 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
38352 +4 4 4 4 4 4
38353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38354 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
38355 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
38356 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
38357 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
38358 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
38359 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
38360 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
38361 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
38362 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
38363 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
38364 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
38365 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
38366 +0 0 0 4 4 4
38367 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
38368 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
38369 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
38370 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
38371 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
38372 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
38373 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
38374 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
38375 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
38376 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
38377 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
38378 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
38379 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
38380 +2 0 0 0 0 0
38381 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
38382 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
38383 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
38384 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
38385 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
38386 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
38387 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
38388 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
38389 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
38390 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
38391 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
38392 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
38393 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
38394 +37 38 37 0 0 0
38395 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
38396 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
38397 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
38398 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
38399 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
38400 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
38401 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
38402 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
38403 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
38404 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
38405 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
38406 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
38407 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
38408 +85 115 134 4 0 0
38409 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
38410 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
38411 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
38412 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
38413 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
38414 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
38415 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
38416 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
38417 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
38418 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
38419 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
38420 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
38421 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
38422 +60 73 81 4 0 0
38423 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
38424 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
38425 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
38426 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
38427 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
38428 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
38429 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
38430 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
38431 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
38432 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
38433 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
38434 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
38435 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
38436 +16 19 21 4 0 0
38437 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
38438 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
38439 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
38440 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
38441 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
38442 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
38443 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
38444 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
38445 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
38446 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
38447 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
38448 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
38449 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
38450 +4 0 0 4 3 3
38451 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
38452 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
38453 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
38454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
38455 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
38456 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
38457 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
38458 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
38459 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
38460 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
38461 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
38462 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
38463 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
38464 +3 2 2 4 4 4
38465 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
38466 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
38467 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
38468 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
38469 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
38470 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
38471 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
38472 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
38473 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
38474 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
38475 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
38476 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
38477 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
38478 +4 4 4 4 4 4
38479 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
38480 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
38481 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
38482 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
38483 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
38484 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
38485 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
38486 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
38487 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
38488 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
38489 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
38490 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
38491 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
38492 +4 4 4 4 4 4
38493 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
38494 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
38495 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
38496 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
38497 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
38498 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
38499 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
38500 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
38501 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
38502 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
38503 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
38504 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
38505 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
38506 +5 5 5 5 5 5
38507 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
38508 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
38509 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
38510 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
38511 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
38512 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38513 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
38514 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
38515 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
38516 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
38517 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
38518 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
38519 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
38520 +5 5 5 4 4 4
38521 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
38522 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
38523 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
38524 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
38525 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38526 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
38527 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
38528 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
38529 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
38530 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
38531 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
38532 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
38533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38534 +4 4 4 4 4 4
38535 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
38536 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
38537 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
38538 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
38539 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
38540 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38541 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38542 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
38543 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
38544 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
38545 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
38546 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
38547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38548 +4 4 4 4 4 4
38549 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
38550 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
38551 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
38552 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
38553 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38554 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
38555 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
38556 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
38557 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
38558 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
38559 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
38560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38562 +4 4 4 4 4 4
38563 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
38564 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
38565 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
38566 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
38567 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38568 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38569 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38570 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
38571 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
38572 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
38573 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
38574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38576 +4 4 4 4 4 4
38577 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
38578 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
38579 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
38580 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
38581 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38582 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
38583 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
38584 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
38585 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
38586 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
38587 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38590 +4 4 4 4 4 4
38591 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
38592 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
38593 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
38594 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
38595 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38596 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
38597 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
38598 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
38599 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
38600 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
38601 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
38602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38604 +4 4 4 4 4 4
38605 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
38606 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
38607 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
38608 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
38609 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38610 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
38611 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
38612 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
38613 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
38614 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
38615 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
38616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38618 +4 4 4 4 4 4
38619 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
38620 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
38621 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
38622 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
38623 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
38624 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
38625 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
38626 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
38627 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
38628 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
38629 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38632 +4 4 4 4 4 4
38633 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
38634 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
38635 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
38636 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
38637 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38638 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
38639 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
38640 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
38641 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
38642 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
38643 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38646 +4 4 4 4 4 4
38647 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
38648 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
38649 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
38650 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
38651 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38652 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
38653 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
38654 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
38655 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
38656 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
38657 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38660 +4 4 4 4 4 4
38661 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
38662 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
38663 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
38664 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
38665 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38666 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
38667 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
38668 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
38669 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
38670 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38671 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38674 +4 4 4 4 4 4
38675 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
38676 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
38677 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
38678 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
38679 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
38680 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
38681 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
38682 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
38683 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38684 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38685 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38688 +4 4 4 4 4 4
38689 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
38690 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
38691 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
38692 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
38693 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38694 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
38695 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
38696 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
38697 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38698 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38699 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38702 +4 4 4 4 4 4
38703 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
38704 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
38705 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
38706 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
38707 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
38708 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
38709 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
38710 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
38711 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38712 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38713 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38716 +4 4 4 4 4 4
38717 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
38718 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
38719 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38720 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
38721 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
38722 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
38723 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
38724 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
38725 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
38726 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38727 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38730 +4 4 4 4 4 4
38731 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
38732 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
38733 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
38734 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
38735 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
38736 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
38737 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
38738 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
38739 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38740 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38741 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38744 +4 4 4 4 4 4
38745 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
38746 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
38747 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38748 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
38749 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
38750 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
38751 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
38752 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
38753 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
38754 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38755 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38758 +4 4 4 4 4 4
38759 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
38760 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
38761 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
38762 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
38763 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
38764 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
38765 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
38766 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
38767 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38768 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38769 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38772 +4 4 4 4 4 4
38773 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38774 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
38775 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38776 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
38777 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
38778 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
38779 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
38780 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
38781 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38782 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38783 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38786 +4 4 4 4 4 4
38787 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
38788 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
38789 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
38790 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
38791 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
38792 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
38793 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38794 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
38795 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38796 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38797 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38800 +4 4 4 4 4 4
38801 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38802 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
38803 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
38804 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
38805 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
38806 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
38807 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38808 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
38809 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38810 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38811 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38814 +4 4 4 4 4 4
38815 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
38816 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
38817 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
38818 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
38819 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
38820 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
38821 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
38822 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
38823 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
38824 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38825 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38828 +4 4 4 4 4 4
38829 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38830 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
38831 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
38832 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
38833 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
38834 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
38835 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
38836 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
38837 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
38838 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38839 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38842 +4 4 4 4 4 4
38843 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
38844 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
38845 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
38846 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
38847 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
38848 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
38849 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
38850 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
38851 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
38852 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38853 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38856 +4 4 4 4 4 4
38857 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38858 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
38859 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
38860 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
38861 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
38862 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
38863 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
38864 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
38865 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
38866 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38867 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38870 +4 4 4 4 4 4
38871 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
38872 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
38873 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
38874 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
38875 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
38876 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
38877 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
38878 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
38879 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
38880 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
38881 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38884 +4 4 4 4 4 4
38885 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
38886 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
38887 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
38888 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
38889 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
38890 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
38891 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
38892 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
38893 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
38894 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
38895 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38898 +4 4 4 4 4 4
38899 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
38900 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
38901 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
38902 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
38903 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
38904 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
38905 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38906 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
38907 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
38908 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
38909 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
38910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38912 +4 4 4 4 4 4
38913 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
38914 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
38915 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
38916 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
38917 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
38918 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
38919 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
38920 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
38921 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
38922 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
38923 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38926 +4 4 4 4 4 4
38927 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
38928 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
38929 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
38930 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
38931 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
38932 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
38933 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
38934 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
38935 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
38936 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
38937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38940 +4 4 4 4 4 4
38941 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
38942 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
38943 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
38944 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
38945 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
38946 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
38947 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
38948 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
38949 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
38950 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
38951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38954 +4 4 4 4 4 4
38955 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
38956 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
38957 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
38958 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
38959 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
38960 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
38961 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
38962 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
38963 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
38964 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
38965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38968 +4 4 4 4 4 4
38969 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
38970 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
38971 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
38972 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
38973 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
38974 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
38975 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
38976 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
38977 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
38978 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
38979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38982 +4 4 4 4 4 4
38983 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
38984 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
38985 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
38986 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
38987 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
38988 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
38989 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
38990 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
38991 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
38992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38996 +4 4 4 4 4 4
38997 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
38998 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
38999 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
39000 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
39001 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
39002 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
39003 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
39004 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
39005 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
39006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39010 +4 4 4 4 4 4
39011 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
39012 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
39013 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
39014 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
39015 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
39016 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
39017 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
39018 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
39019 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39024 +4 4 4 4 4 4
39025 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
39026 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
39027 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
39028 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
39029 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
39030 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
39031 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
39032 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
39033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39038 +4 4 4 4 4 4
39039 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
39040 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
39041 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
39042 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
39043 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
39044 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
39045 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
39046 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
39047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39052 +4 4 4 4 4 4
39053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39054 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
39055 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
39056 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
39057 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
39058 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
39059 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
39060 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
39061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39066 +4 4 4 4 4 4
39067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39068 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
39069 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
39070 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
39071 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
39072 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
39073 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
39074 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
39075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39080 +4 4 4 4 4 4
39081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39082 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
39083 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
39084 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
39085 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
39086 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
39087 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
39088 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
39089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39094 +4 4 4 4 4 4
39095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39097 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
39098 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
39099 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
39100 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
39101 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
39102 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
39103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39108 +4 4 4 4 4 4
39109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39112 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
39113 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
39114 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
39115 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
39116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39122 +4 4 4 4 4 4
39123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39126 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
39127 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
39128 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
39129 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
39130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39136 +4 4 4 4 4 4
39137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39140 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
39141 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
39142 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
39143 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
39144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39150 +4 4 4 4 4 4
39151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39154 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
39155 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
39156 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
39157 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
39158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39164 +4 4 4 4 4 4
39165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39169 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
39170 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
39171 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39178 +4 4 4 4 4 4
39179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39183 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
39184 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
39185 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
39186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39192 +4 4 4 4 4 4
39193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39197 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
39198 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
39199 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39206 +4 4 4 4 4 4
39207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39211 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
39212 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
39213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39220 +4 4 4 4 4 4
39221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39225 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
39226 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
39227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39234 +4 4 4 4 4 4
39235 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
39236 index 3473e75..c930142 100644
39237 --- a/drivers/video/udlfb.c
39238 +++ b/drivers/video/udlfb.c
39239 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
39240 dlfb_urb_completion(urb);
39241
39242 error:
39243 - atomic_add(bytes_sent, &dev->bytes_sent);
39244 - atomic_add(bytes_identical, &dev->bytes_identical);
39245 - atomic_add(width*height*2, &dev->bytes_rendered);
39246 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
39247 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
39248 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
39249 end_cycles = get_cycles();
39250 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
39251 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
39252 >> 10)), /* Kcycles */
39253 &dev->cpu_kcycles_used);
39254
39255 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
39256 dlfb_urb_completion(urb);
39257
39258 error:
39259 - atomic_add(bytes_sent, &dev->bytes_sent);
39260 - atomic_add(bytes_identical, &dev->bytes_identical);
39261 - atomic_add(bytes_rendered, &dev->bytes_rendered);
39262 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
39263 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
39264 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
39265 end_cycles = get_cycles();
39266 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
39267 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
39268 >> 10)), /* Kcycles */
39269 &dev->cpu_kcycles_used);
39270 }
39271 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
39272 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39273 struct dlfb_data *dev = fb_info->par;
39274 return snprintf(buf, PAGE_SIZE, "%u\n",
39275 - atomic_read(&dev->bytes_rendered));
39276 + atomic_read_unchecked(&dev->bytes_rendered));
39277 }
39278
39279 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
39280 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
39281 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39282 struct dlfb_data *dev = fb_info->par;
39283 return snprintf(buf, PAGE_SIZE, "%u\n",
39284 - atomic_read(&dev->bytes_identical));
39285 + atomic_read_unchecked(&dev->bytes_identical));
39286 }
39287
39288 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
39289 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
39290 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39291 struct dlfb_data *dev = fb_info->par;
39292 return snprintf(buf, PAGE_SIZE, "%u\n",
39293 - atomic_read(&dev->bytes_sent));
39294 + atomic_read_unchecked(&dev->bytes_sent));
39295 }
39296
39297 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
39298 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
39299 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39300 struct dlfb_data *dev = fb_info->par;
39301 return snprintf(buf, PAGE_SIZE, "%u\n",
39302 - atomic_read(&dev->cpu_kcycles_used));
39303 + atomic_read_unchecked(&dev->cpu_kcycles_used));
39304 }
39305
39306 static ssize_t edid_show(
39307 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
39308 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39309 struct dlfb_data *dev = fb_info->par;
39310
39311 - atomic_set(&dev->bytes_rendered, 0);
39312 - atomic_set(&dev->bytes_identical, 0);
39313 - atomic_set(&dev->bytes_sent, 0);
39314 - atomic_set(&dev->cpu_kcycles_used, 0);
39315 + atomic_set_unchecked(&dev->bytes_rendered, 0);
39316 + atomic_set_unchecked(&dev->bytes_identical, 0);
39317 + atomic_set_unchecked(&dev->bytes_sent, 0);
39318 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
39319
39320 return count;
39321 }
39322 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
39323 index 7f8472c..9842e87 100644
39324 --- a/drivers/video/uvesafb.c
39325 +++ b/drivers/video/uvesafb.c
39326 @@ -19,6 +19,7 @@
39327 #include <linux/io.h>
39328 #include <linux/mutex.h>
39329 #include <linux/slab.h>
39330 +#include <linux/moduleloader.h>
39331 #include <video/edid.h>
39332 #include <video/uvesafb.h>
39333 #ifdef CONFIG_X86
39334 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
39335 NULL,
39336 };
39337
39338 - return call_usermodehelper(v86d_path, argv, envp, 1);
39339 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
39340 }
39341
39342 /*
39343 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
39344 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
39345 par->pmi_setpal = par->ypan = 0;
39346 } else {
39347 +
39348 +#ifdef CONFIG_PAX_KERNEXEC
39349 +#ifdef CONFIG_MODULES
39350 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
39351 +#endif
39352 + if (!par->pmi_code) {
39353 + par->pmi_setpal = par->ypan = 0;
39354 + return 0;
39355 + }
39356 +#endif
39357 +
39358 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
39359 + task->t.regs.edi);
39360 +
39361 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39362 + pax_open_kernel();
39363 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
39364 + pax_close_kernel();
39365 +
39366 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
39367 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
39368 +#else
39369 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
39370 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
39371 +#endif
39372 +
39373 printk(KERN_INFO "uvesafb: protected mode interface info at "
39374 "%04x:%04x\n",
39375 (u16)task->t.regs.es, (u16)task->t.regs.edi);
39376 @@ -1821,6 +1844,11 @@ out:
39377 if (par->vbe_modes)
39378 kfree(par->vbe_modes);
39379
39380 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39381 + if (par->pmi_code)
39382 + module_free_exec(NULL, par->pmi_code);
39383 +#endif
39384 +
39385 framebuffer_release(info);
39386 return err;
39387 }
39388 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
39389 kfree(par->vbe_state_orig);
39390 if (par->vbe_state_saved)
39391 kfree(par->vbe_state_saved);
39392 +
39393 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39394 + if (par->pmi_code)
39395 + module_free_exec(NULL, par->pmi_code);
39396 +#endif
39397 +
39398 }
39399
39400 framebuffer_release(info);
39401 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
39402 index 501b340..86bd4cf 100644
39403 --- a/drivers/video/vesafb.c
39404 +++ b/drivers/video/vesafb.c
39405 @@ -9,6 +9,7 @@
39406 */
39407
39408 #include <linux/module.h>
39409 +#include <linux/moduleloader.h>
39410 #include <linux/kernel.h>
39411 #include <linux/errno.h>
39412 #include <linux/string.h>
39413 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
39414 static int vram_total __initdata; /* Set total amount of memory */
39415 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
39416 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
39417 -static void (*pmi_start)(void) __read_mostly;
39418 -static void (*pmi_pal) (void) __read_mostly;
39419 +static void (*pmi_start)(void) __read_only;
39420 +static void (*pmi_pal) (void) __read_only;
39421 static int depth __read_mostly;
39422 static int vga_compat __read_mostly;
39423 /* --------------------------------------------------------------------- */
39424 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
39425 unsigned int size_vmode;
39426 unsigned int size_remap;
39427 unsigned int size_total;
39428 + void *pmi_code = NULL;
39429
39430 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
39431 return -ENODEV;
39432 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
39433 size_remap = size_total;
39434 vesafb_fix.smem_len = size_remap;
39435
39436 -#ifndef __i386__
39437 - screen_info.vesapm_seg = 0;
39438 -#endif
39439 -
39440 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
39441 printk(KERN_WARNING
39442 "vesafb: cannot reserve video memory at 0x%lx\n",
39443 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
39444 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
39445 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
39446
39447 +#ifdef __i386__
39448 +
39449 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39450 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
39451 + if (!pmi_code)
39452 +#elif !defined(CONFIG_PAX_KERNEXEC)
39453 + if (0)
39454 +#endif
39455 +
39456 +#endif
39457 + screen_info.vesapm_seg = 0;
39458 +
39459 if (screen_info.vesapm_seg) {
39460 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
39461 - screen_info.vesapm_seg,screen_info.vesapm_off);
39462 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
39463 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
39464 }
39465
39466 if (screen_info.vesapm_seg < 0xc000)
39467 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
39468
39469 if (ypan || pmi_setpal) {
39470 unsigned short *pmi_base;
39471 +
39472 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
39473 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
39474 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
39475 +
39476 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39477 + pax_open_kernel();
39478 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
39479 +#else
39480 + pmi_code = pmi_base;
39481 +#endif
39482 +
39483 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
39484 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
39485 +
39486 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39487 + pmi_start = ktva_ktla(pmi_start);
39488 + pmi_pal = ktva_ktla(pmi_pal);
39489 + pax_close_kernel();
39490 +#endif
39491 +
39492 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
39493 if (pmi_base[3]) {
39494 printk(KERN_INFO "vesafb: pmi: ports = ");
39495 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
39496 info->node, info->fix.id);
39497 return 0;
39498 err:
39499 +
39500 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39501 + module_free_exec(NULL, pmi_code);
39502 +#endif
39503 +
39504 if (info->screen_base)
39505 iounmap(info->screen_base);
39506 framebuffer_release(info);
39507 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
39508 index 88714ae..16c2e11 100644
39509 --- a/drivers/video/via/via_clock.h
39510 +++ b/drivers/video/via/via_clock.h
39511 @@ -56,7 +56,7 @@ struct via_clock {
39512
39513 void (*set_engine_pll_state)(u8 state);
39514 void (*set_engine_pll)(struct via_pll_config config);
39515 -};
39516 +} __no_const;
39517
39518
39519 static inline u32 get_pll_internal_frequency(u32 ref_freq,
39520 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
39521 index e56c934..fc22f4b 100644
39522 --- a/drivers/xen/xen-pciback/conf_space.h
39523 +++ b/drivers/xen/xen-pciback/conf_space.h
39524 @@ -44,15 +44,15 @@ struct config_field {
39525 struct {
39526 conf_dword_write write;
39527 conf_dword_read read;
39528 - } dw;
39529 + } __no_const dw;
39530 struct {
39531 conf_word_write write;
39532 conf_word_read read;
39533 - } w;
39534 + } __no_const w;
39535 struct {
39536 conf_byte_write write;
39537 conf_byte_read read;
39538 - } b;
39539 + } __no_const b;
39540 } u;
39541 struct list_head list;
39542 };
39543 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
39544 index 879ed88..bc03a01 100644
39545 --- a/fs/9p/vfs_inode.c
39546 +++ b/fs/9p/vfs_inode.c
39547 @@ -1286,7 +1286,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
39548 void
39549 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
39550 {
39551 - char *s = nd_get_link(nd);
39552 + const char *s = nd_get_link(nd);
39553
39554 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
39555 IS_ERR(s) ? "<error>" : s);
39556 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
39557 index 79e2ca7..5828ad1 100644
39558 --- a/fs/Kconfig.binfmt
39559 +++ b/fs/Kconfig.binfmt
39560 @@ -86,7 +86,7 @@ config HAVE_AOUT
39561
39562 config BINFMT_AOUT
39563 tristate "Kernel support for a.out and ECOFF binaries"
39564 - depends on HAVE_AOUT
39565 + depends on HAVE_AOUT && BROKEN
39566 ---help---
39567 A.out (Assembler.OUTput) is a set of formats for libraries and
39568 executables used in the earliest versions of UNIX. Linux used
39569 diff --git a/fs/aio.c b/fs/aio.c
39570 index 78c514c..22ac304 100644
39571 --- a/fs/aio.c
39572 +++ b/fs/aio.c
39573 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
39574 size += sizeof(struct io_event) * nr_events;
39575 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
39576
39577 - if (nr_pages < 0)
39578 + if (nr_pages <= 0)
39579 return -EINVAL;
39580
39581 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
39582 @@ -1454,22 +1454,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
39583 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
39584 {
39585 ssize_t ret;
39586 + struct iovec iovstack;
39587
39588 #ifdef CONFIG_COMPAT
39589 if (compat)
39590 ret = compat_rw_copy_check_uvector(type,
39591 (struct compat_iovec __user *)kiocb->ki_buf,
39592 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
39593 + kiocb->ki_nbytes, 1, &iovstack,
39594 &kiocb->ki_iovec, 1);
39595 else
39596 #endif
39597 ret = rw_copy_check_uvector(type,
39598 (struct iovec __user *)kiocb->ki_buf,
39599 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
39600 + kiocb->ki_nbytes, 1, &iovstack,
39601 &kiocb->ki_iovec, 1);
39602 if (ret < 0)
39603 goto out;
39604
39605 + if (kiocb->ki_iovec == &iovstack) {
39606 + kiocb->ki_inline_vec = iovstack;
39607 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
39608 + }
39609 kiocb->ki_nr_segs = kiocb->ki_nbytes;
39610 kiocb->ki_cur_seg = 0;
39611 /* ki_nbytes/left now reflect bytes instead of segs */
39612 diff --git a/fs/attr.c b/fs/attr.c
39613 index 7ee7ba4..0c61a60 100644
39614 --- a/fs/attr.c
39615 +++ b/fs/attr.c
39616 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
39617 unsigned long limit;
39618
39619 limit = rlimit(RLIMIT_FSIZE);
39620 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
39621 if (limit != RLIM_INFINITY && offset > limit)
39622 goto out_sig;
39623 if (offset > inode->i_sb->s_maxbytes)
39624 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
39625 index e1fbdee..cd5ea56 100644
39626 --- a/fs/autofs4/waitq.c
39627 +++ b/fs/autofs4/waitq.c
39628 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
39629 {
39630 unsigned long sigpipe, flags;
39631 mm_segment_t fs;
39632 - const char *data = (const char *)addr;
39633 + const char __user *data = (const char __force_user *)addr;
39634 ssize_t wr = 0;
39635
39636 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
39637 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
39638 index 8342ca6..82fd192 100644
39639 --- a/fs/befs/linuxvfs.c
39640 +++ b/fs/befs/linuxvfs.c
39641 @@ -503,7 +503,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
39642 {
39643 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
39644 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
39645 - char *link = nd_get_link(nd);
39646 + const char *link = nd_get_link(nd);
39647 if (!IS_ERR(link))
39648 kfree(link);
39649 }
39650 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
39651 index a6395bd..a5b24c4 100644
39652 --- a/fs/binfmt_aout.c
39653 +++ b/fs/binfmt_aout.c
39654 @@ -16,6 +16,7 @@
39655 #include <linux/string.h>
39656 #include <linux/fs.h>
39657 #include <linux/file.h>
39658 +#include <linux/security.h>
39659 #include <linux/stat.h>
39660 #include <linux/fcntl.h>
39661 #include <linux/ptrace.h>
39662 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
39663 #endif
39664 # define START_STACK(u) ((void __user *)u.start_stack)
39665
39666 + memset(&dump, 0, sizeof(dump));
39667 +
39668 fs = get_fs();
39669 set_fs(KERNEL_DS);
39670 has_dumped = 1;
39671 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
39672
39673 /* If the size of the dump file exceeds the rlimit, then see what would happen
39674 if we wrote the stack, but not the data area. */
39675 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
39676 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
39677 dump.u_dsize = 0;
39678
39679 /* Make sure we have enough room to write the stack and data areas. */
39680 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
39681 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
39682 dump.u_ssize = 0;
39683
39684 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39685 rlim = rlimit(RLIMIT_DATA);
39686 if (rlim >= RLIM_INFINITY)
39687 rlim = ~0;
39688 +
39689 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
39690 if (ex.a_data + ex.a_bss > rlim)
39691 return -ENOMEM;
39692
39693 @@ -262,6 +269,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39694 install_exec_creds(bprm);
39695 current->flags &= ~PF_FORKNOEXEC;
39696
39697 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
39698 + current->mm->pax_flags = 0UL;
39699 +#endif
39700 +
39701 +#ifdef CONFIG_PAX_PAGEEXEC
39702 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
39703 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
39704 +
39705 +#ifdef CONFIG_PAX_EMUTRAMP
39706 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
39707 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
39708 +#endif
39709 +
39710 +#ifdef CONFIG_PAX_MPROTECT
39711 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
39712 + current->mm->pax_flags |= MF_PAX_MPROTECT;
39713 +#endif
39714 +
39715 + }
39716 +#endif
39717 +
39718 if (N_MAGIC(ex) == OMAGIC) {
39719 unsigned long text_addr, map_size;
39720 loff_t pos;
39721 @@ -334,7 +362,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39722
39723 down_write(&current->mm->mmap_sem);
39724 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
39725 - PROT_READ | PROT_WRITE | PROT_EXEC,
39726 + PROT_READ | PROT_WRITE,
39727 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
39728 fd_offset + ex.a_text);
39729 up_write(&current->mm->mmap_sem);
39730 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
39731 index 21ac5ee..c1090ea 100644
39732 --- a/fs/binfmt_elf.c
39733 +++ b/fs/binfmt_elf.c
39734 @@ -32,6 +32,7 @@
39735 #include <linux/elf.h>
39736 #include <linux/utsname.h>
39737 #include <linux/coredump.h>
39738 +#include <linux/xattr.h>
39739 #include <asm/uaccess.h>
39740 #include <asm/param.h>
39741 #include <asm/page.h>
39742 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
39743 #define elf_core_dump NULL
39744 #endif
39745
39746 +#ifdef CONFIG_PAX_MPROTECT
39747 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
39748 +#endif
39749 +
39750 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
39751 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
39752 #else
39753 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
39754 .load_binary = load_elf_binary,
39755 .load_shlib = load_elf_library,
39756 .core_dump = elf_core_dump,
39757 +
39758 +#ifdef CONFIG_PAX_MPROTECT
39759 + .handle_mprotect= elf_handle_mprotect,
39760 +#endif
39761 +
39762 .min_coredump = ELF_EXEC_PAGESIZE,
39763 };
39764
39765 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
39766
39767 static int set_brk(unsigned long start, unsigned long end)
39768 {
39769 + unsigned long e = end;
39770 +
39771 start = ELF_PAGEALIGN(start);
39772 end = ELF_PAGEALIGN(end);
39773 if (end > start) {
39774 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
39775 if (BAD_ADDR(addr))
39776 return addr;
39777 }
39778 - current->mm->start_brk = current->mm->brk = end;
39779 + current->mm->start_brk = current->mm->brk = e;
39780 return 0;
39781 }
39782
39783 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39784 elf_addr_t __user *u_rand_bytes;
39785 const char *k_platform = ELF_PLATFORM;
39786 const char *k_base_platform = ELF_BASE_PLATFORM;
39787 - unsigned char k_rand_bytes[16];
39788 + u32 k_rand_bytes[4];
39789 int items;
39790 elf_addr_t *elf_info;
39791 int ei_index = 0;
39792 const struct cred *cred = current_cred();
39793 struct vm_area_struct *vma;
39794 + unsigned long saved_auxv[AT_VECTOR_SIZE];
39795
39796 /*
39797 * In some cases (e.g. Hyper-Threading), we want to avoid L1
39798 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39799 * Generate 16 random bytes for userspace PRNG seeding.
39800 */
39801 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
39802 - u_rand_bytes = (elf_addr_t __user *)
39803 - STACK_ALLOC(p, sizeof(k_rand_bytes));
39804 + srandom32(k_rand_bytes[0] ^ random32());
39805 + srandom32(k_rand_bytes[1] ^ random32());
39806 + srandom32(k_rand_bytes[2] ^ random32());
39807 + srandom32(k_rand_bytes[3] ^ random32());
39808 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
39809 + u_rand_bytes = (elf_addr_t __user *) p;
39810 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
39811 return -EFAULT;
39812
39813 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39814 return -EFAULT;
39815 current->mm->env_end = p;
39816
39817 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
39818 +
39819 /* Put the elf_info on the stack in the right place. */
39820 sp = (elf_addr_t __user *)envp + 1;
39821 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
39822 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
39823 return -EFAULT;
39824 return 0;
39825 }
39826 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
39827 {
39828 struct elf_phdr *elf_phdata;
39829 struct elf_phdr *eppnt;
39830 - unsigned long load_addr = 0;
39831 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
39832 int load_addr_set = 0;
39833 unsigned long last_bss = 0, elf_bss = 0;
39834 - unsigned long error = ~0UL;
39835 + unsigned long error = -EINVAL;
39836 unsigned long total_size;
39837 int retval, i, size;
39838
39839 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
39840 goto out_close;
39841 }
39842
39843 +#ifdef CONFIG_PAX_SEGMEXEC
39844 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
39845 + pax_task_size = SEGMEXEC_TASK_SIZE;
39846 +#endif
39847 +
39848 eppnt = elf_phdata;
39849 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
39850 if (eppnt->p_type == PT_LOAD) {
39851 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
39852 k = load_addr + eppnt->p_vaddr;
39853 if (BAD_ADDR(k) ||
39854 eppnt->p_filesz > eppnt->p_memsz ||
39855 - eppnt->p_memsz > TASK_SIZE ||
39856 - TASK_SIZE - eppnt->p_memsz < k) {
39857 + eppnt->p_memsz > pax_task_size ||
39858 + pax_task_size - eppnt->p_memsz < k) {
39859 error = -ENOMEM;
39860 goto out_close;
39861 }
39862 @@ -528,6 +552,348 @@ out:
39863 return error;
39864 }
39865
39866 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
39867 +{
39868 + unsigned long pax_flags = 0UL;
39869 +
39870 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
39871 +
39872 +#ifdef CONFIG_PAX_PAGEEXEC
39873 + if (elf_phdata->p_flags & PF_PAGEEXEC)
39874 + pax_flags |= MF_PAX_PAGEEXEC;
39875 +#endif
39876 +
39877 +#ifdef CONFIG_PAX_SEGMEXEC
39878 + if (elf_phdata->p_flags & PF_SEGMEXEC)
39879 + pax_flags |= MF_PAX_SEGMEXEC;
39880 +#endif
39881 +
39882 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39883 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39884 + if ((__supported_pte_mask & _PAGE_NX))
39885 + pax_flags &= ~MF_PAX_SEGMEXEC;
39886 + else
39887 + pax_flags &= ~MF_PAX_PAGEEXEC;
39888 + }
39889 +#endif
39890 +
39891 +#ifdef CONFIG_PAX_EMUTRAMP
39892 + if (elf_phdata->p_flags & PF_EMUTRAMP)
39893 + pax_flags |= MF_PAX_EMUTRAMP;
39894 +#endif
39895 +
39896 +#ifdef CONFIG_PAX_MPROTECT
39897 + if (elf_phdata->p_flags & PF_MPROTECT)
39898 + pax_flags |= MF_PAX_MPROTECT;
39899 +#endif
39900 +
39901 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
39902 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
39903 + pax_flags |= MF_PAX_RANDMMAP;
39904 +#endif
39905 +
39906 +#endif
39907 +
39908 + return pax_flags;
39909 +}
39910 +
39911 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
39912 +{
39913 + unsigned long pax_flags = 0UL;
39914 +
39915 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
39916 +
39917 +#ifdef CONFIG_PAX_PAGEEXEC
39918 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
39919 + pax_flags |= MF_PAX_PAGEEXEC;
39920 +#endif
39921 +
39922 +#ifdef CONFIG_PAX_SEGMEXEC
39923 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
39924 + pax_flags |= MF_PAX_SEGMEXEC;
39925 +#endif
39926 +
39927 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39928 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39929 + if ((__supported_pte_mask & _PAGE_NX))
39930 + pax_flags &= ~MF_PAX_SEGMEXEC;
39931 + else
39932 + pax_flags &= ~MF_PAX_PAGEEXEC;
39933 + }
39934 +#endif
39935 +
39936 +#ifdef CONFIG_PAX_EMUTRAMP
39937 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
39938 + pax_flags |= MF_PAX_EMUTRAMP;
39939 +#endif
39940 +
39941 +#ifdef CONFIG_PAX_MPROTECT
39942 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
39943 + pax_flags |= MF_PAX_MPROTECT;
39944 +#endif
39945 +
39946 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
39947 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
39948 + pax_flags |= MF_PAX_RANDMMAP;
39949 +#endif
39950 +
39951 +#endif
39952 +
39953 + return pax_flags;
39954 +}
39955 +
39956 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
39957 +{
39958 + unsigned long pax_flags = 0UL;
39959 +
39960 +#ifdef CONFIG_PAX_EI_PAX
39961 +
39962 +#ifdef CONFIG_PAX_PAGEEXEC
39963 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
39964 + pax_flags |= MF_PAX_PAGEEXEC;
39965 +#endif
39966 +
39967 +#ifdef CONFIG_PAX_SEGMEXEC
39968 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
39969 + pax_flags |= MF_PAX_SEGMEXEC;
39970 +#endif
39971 +
39972 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39973 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39974 + if ((__supported_pte_mask & _PAGE_NX))
39975 + pax_flags &= ~MF_PAX_SEGMEXEC;
39976 + else
39977 + pax_flags &= ~MF_PAX_PAGEEXEC;
39978 + }
39979 +#endif
39980 +
39981 +#ifdef CONFIG_PAX_EMUTRAMP
39982 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
39983 + pax_flags |= MF_PAX_EMUTRAMP;
39984 +#endif
39985 +
39986 +#ifdef CONFIG_PAX_MPROTECT
39987 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
39988 + pax_flags |= MF_PAX_MPROTECT;
39989 +#endif
39990 +
39991 +#ifdef CONFIG_PAX_ASLR
39992 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
39993 + pax_flags |= MF_PAX_RANDMMAP;
39994 +#endif
39995 +
39996 +#else
39997 +
39998 +#ifdef CONFIG_PAX_PAGEEXEC
39999 + pax_flags |= MF_PAX_PAGEEXEC;
40000 +#endif
40001 +
40002 +#ifdef CONFIG_PAX_MPROTECT
40003 + pax_flags |= MF_PAX_MPROTECT;
40004 +#endif
40005 +
40006 +#ifdef CONFIG_PAX_RANDMMAP
40007 + pax_flags |= MF_PAX_RANDMMAP;
40008 +#endif
40009 +
40010 +#ifdef CONFIG_PAX_SEGMEXEC
40011 + if (!(__supported_pte_mask & _PAGE_NX)) {
40012 + pax_flags &= ~MF_PAX_PAGEEXEC;
40013 + pax_flags |= MF_PAX_SEGMEXEC;
40014 + }
40015 +#endif
40016 +
40017 +#endif
40018 +
40019 + return pax_flags;
40020 +}
40021 +
40022 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
40023 +{
40024 +
40025 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
40026 + unsigned long i;
40027 +
40028 + for (i = 0UL; i < elf_ex->e_phnum; i++)
40029 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
40030 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
40031 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
40032 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
40033 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
40034 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
40035 + return ~0UL;
40036 +
40037 +#ifdef CONFIG_PAX_SOFTMODE
40038 + if (pax_softmode)
40039 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
40040 + else
40041 +#endif
40042 +
40043 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
40044 + break;
40045 + }
40046 +#endif
40047 +
40048 + return ~0UL;
40049 +}
40050 +
40051 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
40052 +{
40053 + unsigned long pax_flags = 0UL;
40054 +
40055 +#ifdef CONFIG_PAX_PAGEEXEC
40056 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
40057 + pax_flags |= MF_PAX_PAGEEXEC;
40058 +#endif
40059 +
40060 +#ifdef CONFIG_PAX_SEGMEXEC
40061 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
40062 + pax_flags |= MF_PAX_SEGMEXEC;
40063 +#endif
40064 +
40065 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40066 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40067 + if ((__supported_pte_mask & _PAGE_NX))
40068 + pax_flags &= ~MF_PAX_SEGMEXEC;
40069 + else
40070 + pax_flags &= ~MF_PAX_PAGEEXEC;
40071 + }
40072 +#endif
40073 +
40074 +#ifdef CONFIG_PAX_EMUTRAMP
40075 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
40076 + pax_flags |= MF_PAX_EMUTRAMP;
40077 +#endif
40078 +
40079 +#ifdef CONFIG_PAX_MPROTECT
40080 + if (pax_flags_softmode & MF_PAX_MPROTECT)
40081 + pax_flags |= MF_PAX_MPROTECT;
40082 +#endif
40083 +
40084 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
40085 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
40086 + pax_flags |= MF_PAX_RANDMMAP;
40087 +#endif
40088 +
40089 + return pax_flags;
40090 +}
40091 +
40092 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
40093 +{
40094 + unsigned long pax_flags = 0UL;
40095 +
40096 +#ifdef CONFIG_PAX_PAGEEXEC
40097 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
40098 + pax_flags |= MF_PAX_PAGEEXEC;
40099 +#endif
40100 +
40101 +#ifdef CONFIG_PAX_SEGMEXEC
40102 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
40103 + pax_flags |= MF_PAX_SEGMEXEC;
40104 +#endif
40105 +
40106 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40107 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40108 + if ((__supported_pte_mask & _PAGE_NX))
40109 + pax_flags &= ~MF_PAX_SEGMEXEC;
40110 + else
40111 + pax_flags &= ~MF_PAX_PAGEEXEC;
40112 + }
40113 +#endif
40114 +
40115 +#ifdef CONFIG_PAX_EMUTRAMP
40116 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
40117 + pax_flags |= MF_PAX_EMUTRAMP;
40118 +#endif
40119 +
40120 +#ifdef CONFIG_PAX_MPROTECT
40121 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
40122 + pax_flags |= MF_PAX_MPROTECT;
40123 +#endif
40124 +
40125 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
40126 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
40127 + pax_flags |= MF_PAX_RANDMMAP;
40128 +#endif
40129 +
40130 + return pax_flags;
40131 +}
40132 +
40133 +static unsigned long pax_parse_xattr_pax(struct file * const file)
40134 +{
40135 +
40136 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
40137 + ssize_t xattr_size, i;
40138 + unsigned char xattr_value[5];
40139 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
40140 +
40141 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
40142 + if (xattr_size <= 0)
40143 + return ~0UL;
40144 +
40145 + for (i = 0; i < xattr_size; i++)
40146 + switch (xattr_value[i]) {
40147 + default:
40148 + return ~0UL;
40149 +
40150 +#define parse_flag(option1, option2, flag) \
40151 + case option1: \
40152 + pax_flags_hardmode |= MF_PAX_##flag; \
40153 + break; \
40154 + case option2: \
40155 + pax_flags_softmode |= MF_PAX_##flag; \
40156 + break;
40157 +
40158 + parse_flag('p', 'P', PAGEEXEC);
40159 + parse_flag('e', 'E', EMUTRAMP);
40160 + parse_flag('m', 'M', MPROTECT);
40161 + parse_flag('r', 'R', RANDMMAP);
40162 + parse_flag('s', 'S', SEGMEXEC);
40163 +
40164 +#undef parse_flag
40165 + }
40166 +
40167 + if (pax_flags_hardmode & pax_flags_softmode)
40168 + return ~0UL;
40169 +
40170 +#ifdef CONFIG_PAX_SOFTMODE
40171 + if (pax_softmode)
40172 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
40173 + else
40174 +#endif
40175 +
40176 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
40177 +#else
40178 + return ~0UL;
40179 +#endif
40180 +}
40181 +
40182 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
40183 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
40184 +{
40185 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
40186 +
40187 + pax_flags = pax_parse_ei_pax(elf_ex);
40188 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
40189 + xattr_pax_flags = pax_parse_xattr_pax(file);
40190 +
40191 + if (pt_pax_flags == ~0UL)
40192 + pt_pax_flags = xattr_pax_flags;
40193 + else if (xattr_pax_flags == ~0UL)
40194 + xattr_pax_flags = pt_pax_flags;
40195 + if (pt_pax_flags != xattr_pax_flags)
40196 + return -EINVAL;
40197 + if (pt_pax_flags != ~0UL)
40198 + pax_flags = pt_pax_flags;
40199 +
40200 + if (0 > pax_check_flags(&pax_flags))
40201 + return -EINVAL;
40202 +
40203 + current->mm->pax_flags = pax_flags;
40204 + return 0;
40205 +}
40206 +#endif
40207 +
40208 /*
40209 * These are the functions used to load ELF style executables and shared
40210 * libraries. There is no binary dependent code anywhere else.
40211 @@ -544,6 +910,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
40212 {
40213 unsigned int random_variable = 0;
40214
40215 +#ifdef CONFIG_PAX_RANDUSTACK
40216 + if (randomize_va_space)
40217 + return stack_top - current->mm->delta_stack;
40218 +#endif
40219 +
40220 if ((current->flags & PF_RANDOMIZE) &&
40221 !(current->personality & ADDR_NO_RANDOMIZE)) {
40222 random_variable = get_random_int() & STACK_RND_MASK;
40223 @@ -562,7 +933,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40224 unsigned long load_addr = 0, load_bias = 0;
40225 int load_addr_set = 0;
40226 char * elf_interpreter = NULL;
40227 - unsigned long error;
40228 + unsigned long error = 0;
40229 struct elf_phdr *elf_ppnt, *elf_phdata;
40230 unsigned long elf_bss, elf_brk;
40231 int retval, i;
40232 @@ -572,11 +943,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40233 unsigned long start_code, end_code, start_data, end_data;
40234 unsigned long reloc_func_desc __maybe_unused = 0;
40235 int executable_stack = EXSTACK_DEFAULT;
40236 - unsigned long def_flags = 0;
40237 struct {
40238 struct elfhdr elf_ex;
40239 struct elfhdr interp_elf_ex;
40240 } *loc;
40241 + unsigned long pax_task_size = TASK_SIZE;
40242
40243 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
40244 if (!loc) {
40245 @@ -713,11 +1084,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40246
40247 /* OK, This is the point of no return */
40248 current->flags &= ~PF_FORKNOEXEC;
40249 - current->mm->def_flags = def_flags;
40250 +
40251 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
40252 + current->mm->pax_flags = 0UL;
40253 +#endif
40254 +
40255 +#ifdef CONFIG_PAX_DLRESOLVE
40256 + current->mm->call_dl_resolve = 0UL;
40257 +#endif
40258 +
40259 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
40260 + current->mm->call_syscall = 0UL;
40261 +#endif
40262 +
40263 +#ifdef CONFIG_PAX_ASLR
40264 + current->mm->delta_mmap = 0UL;
40265 + current->mm->delta_stack = 0UL;
40266 +#endif
40267 +
40268 + current->mm->def_flags = 0;
40269 +
40270 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
40271 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
40272 + send_sig(SIGKILL, current, 0);
40273 + goto out_free_dentry;
40274 + }
40275 +#endif
40276 +
40277 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
40278 + pax_set_initial_flags(bprm);
40279 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
40280 + if (pax_set_initial_flags_func)
40281 + (pax_set_initial_flags_func)(bprm);
40282 +#endif
40283 +
40284 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
40285 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
40286 + current->mm->context.user_cs_limit = PAGE_SIZE;
40287 + current->mm->def_flags |= VM_PAGEEXEC;
40288 + }
40289 +#endif
40290 +
40291 +#ifdef CONFIG_PAX_SEGMEXEC
40292 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
40293 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
40294 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
40295 + pax_task_size = SEGMEXEC_TASK_SIZE;
40296 + current->mm->def_flags |= VM_NOHUGEPAGE;
40297 + }
40298 +#endif
40299 +
40300 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
40301 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40302 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
40303 + put_cpu();
40304 + }
40305 +#endif
40306
40307 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
40308 may depend on the personality. */
40309 SET_PERSONALITY(loc->elf_ex);
40310 +
40311 +#ifdef CONFIG_PAX_ASLR
40312 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
40313 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
40314 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
40315 + }
40316 +#endif
40317 +
40318 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
40319 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40320 + executable_stack = EXSTACK_DISABLE_X;
40321 + current->personality &= ~READ_IMPLIES_EXEC;
40322 + } else
40323 +#endif
40324 +
40325 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
40326 current->personality |= READ_IMPLIES_EXEC;
40327
40328 @@ -808,6 +1249,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40329 #else
40330 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
40331 #endif
40332 +
40333 +#ifdef CONFIG_PAX_RANDMMAP
40334 + /* PaX: randomize base address at the default exe base if requested */
40335 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
40336 +#ifdef CONFIG_SPARC64
40337 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
40338 +#else
40339 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
40340 +#endif
40341 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
40342 + elf_flags |= MAP_FIXED;
40343 + }
40344 +#endif
40345 +
40346 }
40347
40348 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
40349 @@ -840,9 +1295,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40350 * allowed task size. Note that p_filesz must always be
40351 * <= p_memsz so it is only necessary to check p_memsz.
40352 */
40353 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
40354 - elf_ppnt->p_memsz > TASK_SIZE ||
40355 - TASK_SIZE - elf_ppnt->p_memsz < k) {
40356 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
40357 + elf_ppnt->p_memsz > pax_task_size ||
40358 + pax_task_size - elf_ppnt->p_memsz < k) {
40359 /* set_brk can never work. Avoid overflows. */
40360 send_sig(SIGKILL, current, 0);
40361 retval = -EINVAL;
40362 @@ -870,6 +1325,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40363 start_data += load_bias;
40364 end_data += load_bias;
40365
40366 +#ifdef CONFIG_PAX_RANDMMAP
40367 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
40368 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
40369 +#endif
40370 +
40371 /* Calling set_brk effectively mmaps the pages that we need
40372 * for the bss and break sections. We must do this before
40373 * mapping in the interpreter, to make sure it doesn't wind
40374 @@ -881,9 +1341,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40375 goto out_free_dentry;
40376 }
40377 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
40378 - send_sig(SIGSEGV, current, 0);
40379 - retval = -EFAULT; /* Nobody gets to see this, but.. */
40380 - goto out_free_dentry;
40381 + /*
40382 + * This bss-zeroing can fail if the ELF
40383 + * file specifies odd protections. So
40384 + * we don't check the return value
40385 + */
40386 }
40387
40388 if (elf_interpreter) {
40389 @@ -1098,7 +1560,7 @@ out:
40390 * Decide what to dump of a segment, part, all or none.
40391 */
40392 static unsigned long vma_dump_size(struct vm_area_struct *vma,
40393 - unsigned long mm_flags)
40394 + unsigned long mm_flags, long signr)
40395 {
40396 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
40397
40398 @@ -1132,7 +1594,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
40399 if (vma->vm_file == NULL)
40400 return 0;
40401
40402 - if (FILTER(MAPPED_PRIVATE))
40403 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
40404 goto whole;
40405
40406 /*
40407 @@ -1354,9 +1816,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
40408 {
40409 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
40410 int i = 0;
40411 - do
40412 + do {
40413 i += 2;
40414 - while (auxv[i - 2] != AT_NULL);
40415 + } while (auxv[i - 2] != AT_NULL);
40416 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
40417 }
40418
40419 @@ -1862,14 +2324,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
40420 }
40421
40422 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
40423 - unsigned long mm_flags)
40424 + struct coredump_params *cprm)
40425 {
40426 struct vm_area_struct *vma;
40427 size_t size = 0;
40428
40429 for (vma = first_vma(current, gate_vma); vma != NULL;
40430 vma = next_vma(vma, gate_vma))
40431 - size += vma_dump_size(vma, mm_flags);
40432 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40433 return size;
40434 }
40435
40436 @@ -1963,7 +2425,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40437
40438 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
40439
40440 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
40441 + offset += elf_core_vma_data_size(gate_vma, cprm);
40442 offset += elf_core_extra_data_size();
40443 e_shoff = offset;
40444
40445 @@ -1977,10 +2439,12 @@ static int elf_core_dump(struct coredump_params *cprm)
40446 offset = dataoff;
40447
40448 size += sizeof(*elf);
40449 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40450 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
40451 goto end_coredump;
40452
40453 size += sizeof(*phdr4note);
40454 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40455 if (size > cprm->limit
40456 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
40457 goto end_coredump;
40458 @@ -1994,7 +2458,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40459 phdr.p_offset = offset;
40460 phdr.p_vaddr = vma->vm_start;
40461 phdr.p_paddr = 0;
40462 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
40463 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40464 phdr.p_memsz = vma->vm_end - vma->vm_start;
40465 offset += phdr.p_filesz;
40466 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
40467 @@ -2005,6 +2469,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40468 phdr.p_align = ELF_EXEC_PAGESIZE;
40469
40470 size += sizeof(phdr);
40471 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40472 if (size > cprm->limit
40473 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
40474 goto end_coredump;
40475 @@ -2029,7 +2494,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40476 unsigned long addr;
40477 unsigned long end;
40478
40479 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
40480 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40481
40482 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
40483 struct page *page;
40484 @@ -2038,6 +2503,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40485 page = get_dump_page(addr);
40486 if (page) {
40487 void *kaddr = kmap(page);
40488 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
40489 stop = ((size += PAGE_SIZE) > cprm->limit) ||
40490 !dump_write(cprm->file, kaddr,
40491 PAGE_SIZE);
40492 @@ -2055,6 +2521,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40493
40494 if (e_phnum == PN_XNUM) {
40495 size += sizeof(*shdr4extnum);
40496 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40497 if (size > cprm->limit
40498 || !dump_write(cprm->file, shdr4extnum,
40499 sizeof(*shdr4extnum)))
40500 @@ -2075,6 +2542,97 @@ out:
40501
40502 #endif /* CONFIG_ELF_CORE */
40503
40504 +#ifdef CONFIG_PAX_MPROTECT
40505 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
40506 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
40507 + * we'll remove VM_MAYWRITE for good on RELRO segments.
40508 + *
40509 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
40510 + * basis because we want to allow the common case and not the special ones.
40511 + */
40512 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
40513 +{
40514 + struct elfhdr elf_h;
40515 + struct elf_phdr elf_p;
40516 + unsigned long i;
40517 + unsigned long oldflags;
40518 + bool is_textrel_rw, is_textrel_rx, is_relro;
40519 +
40520 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
40521 + return;
40522 +
40523 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
40524 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
40525 +
40526 +#ifdef CONFIG_PAX_ELFRELOCS
40527 + /* possible TEXTREL */
40528 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
40529 + is_textrel_rx = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
40530 +#else
40531 + is_textrel_rw = false;
40532 + is_textrel_rx = false;
40533 +#endif
40534 +
40535 + /* possible RELRO */
40536 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
40537 +
40538 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
40539 + return;
40540 +
40541 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
40542 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
40543 +
40544 +#ifdef CONFIG_PAX_ETEXECRELOCS
40545 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
40546 +#else
40547 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
40548 +#endif
40549 +
40550 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
40551 + !elf_check_arch(&elf_h) ||
40552 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
40553 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
40554 + return;
40555 +
40556 + for (i = 0UL; i < elf_h.e_phnum; i++) {
40557 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
40558 + return;
40559 + switch (elf_p.p_type) {
40560 + case PT_DYNAMIC:
40561 + if (!is_textrel_rw && !is_textrel_rx)
40562 + continue;
40563 + i = 0UL;
40564 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
40565 + elf_dyn dyn;
40566 +
40567 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
40568 + return;
40569 + if (dyn.d_tag == DT_NULL)
40570 + return;
40571 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
40572 + gr_log_textrel(vma);
40573 + if (is_textrel_rw)
40574 + vma->vm_flags |= VM_MAYWRITE;
40575 + else
40576 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
40577 + vma->vm_flags &= ~VM_MAYWRITE;
40578 + return;
40579 + }
40580 + i++;
40581 + }
40582 + return;
40583 +
40584 + case PT_GNU_RELRO:
40585 + if (!is_relro)
40586 + continue;
40587 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
40588 + vma->vm_flags &= ~VM_MAYWRITE;
40589 + return;
40590 + }
40591 + }
40592 +}
40593 +#endif
40594 +
40595 static int __init init_elf_binfmt(void)
40596 {
40597 return register_binfmt(&elf_format);
40598 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
40599 index 1bffbe0..c8c283e 100644
40600 --- a/fs/binfmt_flat.c
40601 +++ b/fs/binfmt_flat.c
40602 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
40603 realdatastart = (unsigned long) -ENOMEM;
40604 printk("Unable to allocate RAM for process data, errno %d\n",
40605 (int)-realdatastart);
40606 + down_write(&current->mm->mmap_sem);
40607 do_munmap(current->mm, textpos, text_len);
40608 + up_write(&current->mm->mmap_sem);
40609 ret = realdatastart;
40610 goto err;
40611 }
40612 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
40613 }
40614 if (IS_ERR_VALUE(result)) {
40615 printk("Unable to read data+bss, errno %d\n", (int)-result);
40616 + down_write(&current->mm->mmap_sem);
40617 do_munmap(current->mm, textpos, text_len);
40618 do_munmap(current->mm, realdatastart, len);
40619 + up_write(&current->mm->mmap_sem);
40620 ret = result;
40621 goto err;
40622 }
40623 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
40624 }
40625 if (IS_ERR_VALUE(result)) {
40626 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
40627 + down_write(&current->mm->mmap_sem);
40628 do_munmap(current->mm, textpos, text_len + data_len + extra +
40629 MAX_SHARED_LIBS * sizeof(unsigned long));
40630 + up_write(&current->mm->mmap_sem);
40631 ret = result;
40632 goto err;
40633 }
40634 diff --git a/fs/bio.c b/fs/bio.c
40635 index b1fe82c..84da0a9 100644
40636 --- a/fs/bio.c
40637 +++ b/fs/bio.c
40638 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
40639 const int read = bio_data_dir(bio) == READ;
40640 struct bio_map_data *bmd = bio->bi_private;
40641 int i;
40642 - char *p = bmd->sgvecs[0].iov_base;
40643 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
40644
40645 __bio_for_each_segment(bvec, bio, i, 0) {
40646 char *addr = page_address(bvec->bv_page);
40647 diff --git a/fs/block_dev.c b/fs/block_dev.c
40648 index b07f1da..9efcb92 100644
40649 --- a/fs/block_dev.c
40650 +++ b/fs/block_dev.c
40651 @@ -681,7 +681,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
40652 else if (bdev->bd_contains == bdev)
40653 return true; /* is a whole device which isn't held */
40654
40655 - else if (whole->bd_holder == bd_may_claim)
40656 + else if (whole->bd_holder == (void *)bd_may_claim)
40657 return true; /* is a partition of a device that is being partitioned */
40658 else if (whole->bd_holder != NULL)
40659 return false; /* is a partition of a held device */
40660 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
40661 index dede441..f2a2507 100644
40662 --- a/fs/btrfs/ctree.c
40663 +++ b/fs/btrfs/ctree.c
40664 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
40665 free_extent_buffer(buf);
40666 add_root_to_dirty_list(root);
40667 } else {
40668 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
40669 - parent_start = parent->start;
40670 - else
40671 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
40672 + if (parent)
40673 + parent_start = parent->start;
40674 + else
40675 + parent_start = 0;
40676 + } else
40677 parent_start = 0;
40678
40679 WARN_ON(trans->transid != btrfs_header_generation(parent));
40680 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
40681 index fd1a06d..6e9033d 100644
40682 --- a/fs/btrfs/inode.c
40683 +++ b/fs/btrfs/inode.c
40684 @@ -6895,7 +6895,7 @@ fail:
40685 return -ENOMEM;
40686 }
40687
40688 -static int btrfs_getattr(struct vfsmount *mnt,
40689 +int btrfs_getattr(struct vfsmount *mnt,
40690 struct dentry *dentry, struct kstat *stat)
40691 {
40692 struct inode *inode = dentry->d_inode;
40693 @@ -6909,6 +6909,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
40694 return 0;
40695 }
40696
40697 +EXPORT_SYMBOL(btrfs_getattr);
40698 +
40699 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
40700 +{
40701 + return BTRFS_I(inode)->root->anon_dev;
40702 +}
40703 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
40704 +
40705 /*
40706 * If a file is moved, it will inherit the cow and compression flags of the new
40707 * directory.
40708 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
40709 index c04f02c..f5c9e2e 100644
40710 --- a/fs/btrfs/ioctl.c
40711 +++ b/fs/btrfs/ioctl.c
40712 @@ -2733,9 +2733,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
40713 for (i = 0; i < num_types; i++) {
40714 struct btrfs_space_info *tmp;
40715
40716 + /* Don't copy in more than we allocated */
40717 if (!slot_count)
40718 break;
40719
40720 + slot_count--;
40721 +
40722 info = NULL;
40723 rcu_read_lock();
40724 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
40725 @@ -2757,15 +2760,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
40726 memcpy(dest, &space, sizeof(space));
40727 dest++;
40728 space_args.total_spaces++;
40729 - slot_count--;
40730 }
40731 - if (!slot_count)
40732 - break;
40733 }
40734 up_read(&info->groups_sem);
40735 }
40736
40737 - user_dest = (struct btrfs_ioctl_space_info *)
40738 + user_dest = (struct btrfs_ioctl_space_info __user *)
40739 (arg + sizeof(struct btrfs_ioctl_space_args));
40740
40741 if (copy_to_user(user_dest, dest_orig, alloc_size))
40742 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
40743 index cfb5543..1ae7347 100644
40744 --- a/fs/btrfs/relocation.c
40745 +++ b/fs/btrfs/relocation.c
40746 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
40747 }
40748 spin_unlock(&rc->reloc_root_tree.lock);
40749
40750 - BUG_ON((struct btrfs_root *)node->data != root);
40751 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
40752
40753 if (!del) {
40754 spin_lock(&rc->reloc_root_tree.lock);
40755 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
40756 index 622f469..e8d2d55 100644
40757 --- a/fs/cachefiles/bind.c
40758 +++ b/fs/cachefiles/bind.c
40759 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
40760 args);
40761
40762 /* start by checking things over */
40763 - ASSERT(cache->fstop_percent >= 0 &&
40764 - cache->fstop_percent < cache->fcull_percent &&
40765 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
40766 cache->fcull_percent < cache->frun_percent &&
40767 cache->frun_percent < 100);
40768
40769 - ASSERT(cache->bstop_percent >= 0 &&
40770 - cache->bstop_percent < cache->bcull_percent &&
40771 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
40772 cache->bcull_percent < cache->brun_percent &&
40773 cache->brun_percent < 100);
40774
40775 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
40776 index 0a1467b..6a53245 100644
40777 --- a/fs/cachefiles/daemon.c
40778 +++ b/fs/cachefiles/daemon.c
40779 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
40780 if (n > buflen)
40781 return -EMSGSIZE;
40782
40783 - if (copy_to_user(_buffer, buffer, n) != 0)
40784 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
40785 return -EFAULT;
40786
40787 return n;
40788 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
40789 if (test_bit(CACHEFILES_DEAD, &cache->flags))
40790 return -EIO;
40791
40792 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
40793 + if (datalen > PAGE_SIZE - 1)
40794 return -EOPNOTSUPP;
40795
40796 /* drag the command string into the kernel so we can parse it */
40797 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
40798 if (args[0] != '%' || args[1] != '\0')
40799 return -EINVAL;
40800
40801 - if (fstop < 0 || fstop >= cache->fcull_percent)
40802 + if (fstop >= cache->fcull_percent)
40803 return cachefiles_daemon_range_error(cache, args);
40804
40805 cache->fstop_percent = fstop;
40806 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
40807 if (args[0] != '%' || args[1] != '\0')
40808 return -EINVAL;
40809
40810 - if (bstop < 0 || bstop >= cache->bcull_percent)
40811 + if (bstop >= cache->bcull_percent)
40812 return cachefiles_daemon_range_error(cache, args);
40813
40814 cache->bstop_percent = bstop;
40815 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
40816 index bd6bc1b..b627b53 100644
40817 --- a/fs/cachefiles/internal.h
40818 +++ b/fs/cachefiles/internal.h
40819 @@ -57,7 +57,7 @@ struct cachefiles_cache {
40820 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
40821 struct rb_root active_nodes; /* active nodes (can't be culled) */
40822 rwlock_t active_lock; /* lock for active_nodes */
40823 - atomic_t gravecounter; /* graveyard uniquifier */
40824 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
40825 unsigned frun_percent; /* when to stop culling (% files) */
40826 unsigned fcull_percent; /* when to start culling (% files) */
40827 unsigned fstop_percent; /* when to stop allocating (% files) */
40828 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
40829 * proc.c
40830 */
40831 #ifdef CONFIG_CACHEFILES_HISTOGRAM
40832 -extern atomic_t cachefiles_lookup_histogram[HZ];
40833 -extern atomic_t cachefiles_mkdir_histogram[HZ];
40834 -extern atomic_t cachefiles_create_histogram[HZ];
40835 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
40836 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
40837 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
40838
40839 extern int __init cachefiles_proc_init(void);
40840 extern void cachefiles_proc_cleanup(void);
40841 static inline
40842 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
40843 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
40844 {
40845 unsigned long jif = jiffies - start_jif;
40846 if (jif >= HZ)
40847 jif = HZ - 1;
40848 - atomic_inc(&histogram[jif]);
40849 + atomic_inc_unchecked(&histogram[jif]);
40850 }
40851
40852 #else
40853 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
40854 index a0358c2..d6137f2 100644
40855 --- a/fs/cachefiles/namei.c
40856 +++ b/fs/cachefiles/namei.c
40857 @@ -318,7 +318,7 @@ try_again:
40858 /* first step is to make up a grave dentry in the graveyard */
40859 sprintf(nbuffer, "%08x%08x",
40860 (uint32_t) get_seconds(),
40861 - (uint32_t) atomic_inc_return(&cache->gravecounter));
40862 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
40863
40864 /* do the multiway lock magic */
40865 trap = lock_rename(cache->graveyard, dir);
40866 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
40867 index eccd339..4c1d995 100644
40868 --- a/fs/cachefiles/proc.c
40869 +++ b/fs/cachefiles/proc.c
40870 @@ -14,9 +14,9 @@
40871 #include <linux/seq_file.h>
40872 #include "internal.h"
40873
40874 -atomic_t cachefiles_lookup_histogram[HZ];
40875 -atomic_t cachefiles_mkdir_histogram[HZ];
40876 -atomic_t cachefiles_create_histogram[HZ];
40877 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
40878 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
40879 +atomic_unchecked_t cachefiles_create_histogram[HZ];
40880
40881 /*
40882 * display the latency histogram
40883 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
40884 return 0;
40885 default:
40886 index = (unsigned long) v - 3;
40887 - x = atomic_read(&cachefiles_lookup_histogram[index]);
40888 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
40889 - z = atomic_read(&cachefiles_create_histogram[index]);
40890 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
40891 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
40892 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
40893 if (x == 0 && y == 0 && z == 0)
40894 return 0;
40895
40896 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
40897 index 0e3c092..818480e 100644
40898 --- a/fs/cachefiles/rdwr.c
40899 +++ b/fs/cachefiles/rdwr.c
40900 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
40901 old_fs = get_fs();
40902 set_fs(KERNEL_DS);
40903 ret = file->f_op->write(
40904 - file, (const void __user *) data, len, &pos);
40905 + file, (const void __force_user *) data, len, &pos);
40906 set_fs(old_fs);
40907 kunmap(page);
40908 if (ret != len)
40909 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
40910 index 9895400..fa40a7d 100644
40911 --- a/fs/ceph/dir.c
40912 +++ b/fs/ceph/dir.c
40913 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
40914 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
40915 struct ceph_mds_client *mdsc = fsc->mdsc;
40916 unsigned frag = fpos_frag(filp->f_pos);
40917 - int off = fpos_off(filp->f_pos);
40918 + unsigned int off = fpos_off(filp->f_pos);
40919 int err;
40920 u32 ftype;
40921 struct ceph_mds_reply_info_parsed *rinfo;
40922 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
40923 index 84e8c07..6170d31 100644
40924 --- a/fs/cifs/cifs_debug.c
40925 +++ b/fs/cifs/cifs_debug.c
40926 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
40927
40928 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
40929 #ifdef CONFIG_CIFS_STATS2
40930 - atomic_set(&totBufAllocCount, 0);
40931 - atomic_set(&totSmBufAllocCount, 0);
40932 + atomic_set_unchecked(&totBufAllocCount, 0);
40933 + atomic_set_unchecked(&totSmBufAllocCount, 0);
40934 #endif /* CONFIG_CIFS_STATS2 */
40935 spin_lock(&cifs_tcp_ses_lock);
40936 list_for_each(tmp1, &cifs_tcp_ses_list) {
40937 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
40938 tcon = list_entry(tmp3,
40939 struct cifs_tcon,
40940 tcon_list);
40941 - atomic_set(&tcon->num_smbs_sent, 0);
40942 - atomic_set(&tcon->num_writes, 0);
40943 - atomic_set(&tcon->num_reads, 0);
40944 - atomic_set(&tcon->num_oplock_brks, 0);
40945 - atomic_set(&tcon->num_opens, 0);
40946 - atomic_set(&tcon->num_posixopens, 0);
40947 - atomic_set(&tcon->num_posixmkdirs, 0);
40948 - atomic_set(&tcon->num_closes, 0);
40949 - atomic_set(&tcon->num_deletes, 0);
40950 - atomic_set(&tcon->num_mkdirs, 0);
40951 - atomic_set(&tcon->num_rmdirs, 0);
40952 - atomic_set(&tcon->num_renames, 0);
40953 - atomic_set(&tcon->num_t2renames, 0);
40954 - atomic_set(&tcon->num_ffirst, 0);
40955 - atomic_set(&tcon->num_fnext, 0);
40956 - atomic_set(&tcon->num_fclose, 0);
40957 - atomic_set(&tcon->num_hardlinks, 0);
40958 - atomic_set(&tcon->num_symlinks, 0);
40959 - atomic_set(&tcon->num_locks, 0);
40960 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
40961 + atomic_set_unchecked(&tcon->num_writes, 0);
40962 + atomic_set_unchecked(&tcon->num_reads, 0);
40963 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
40964 + atomic_set_unchecked(&tcon->num_opens, 0);
40965 + atomic_set_unchecked(&tcon->num_posixopens, 0);
40966 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
40967 + atomic_set_unchecked(&tcon->num_closes, 0);
40968 + atomic_set_unchecked(&tcon->num_deletes, 0);
40969 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
40970 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
40971 + atomic_set_unchecked(&tcon->num_renames, 0);
40972 + atomic_set_unchecked(&tcon->num_t2renames, 0);
40973 + atomic_set_unchecked(&tcon->num_ffirst, 0);
40974 + atomic_set_unchecked(&tcon->num_fnext, 0);
40975 + atomic_set_unchecked(&tcon->num_fclose, 0);
40976 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
40977 + atomic_set_unchecked(&tcon->num_symlinks, 0);
40978 + atomic_set_unchecked(&tcon->num_locks, 0);
40979 }
40980 }
40981 }
40982 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
40983 smBufAllocCount.counter, cifs_min_small);
40984 #ifdef CONFIG_CIFS_STATS2
40985 seq_printf(m, "Total Large %d Small %d Allocations\n",
40986 - atomic_read(&totBufAllocCount),
40987 - atomic_read(&totSmBufAllocCount));
40988 + atomic_read_unchecked(&totBufAllocCount),
40989 + atomic_read_unchecked(&totSmBufAllocCount));
40990 #endif /* CONFIG_CIFS_STATS2 */
40991
40992 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
40993 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
40994 if (tcon->need_reconnect)
40995 seq_puts(m, "\tDISCONNECTED ");
40996 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
40997 - atomic_read(&tcon->num_smbs_sent),
40998 - atomic_read(&tcon->num_oplock_brks));
40999 + atomic_read_unchecked(&tcon->num_smbs_sent),
41000 + atomic_read_unchecked(&tcon->num_oplock_brks));
41001 seq_printf(m, "\nReads: %d Bytes: %lld",
41002 - atomic_read(&tcon->num_reads),
41003 + atomic_read_unchecked(&tcon->num_reads),
41004 (long long)(tcon->bytes_read));
41005 seq_printf(m, "\nWrites: %d Bytes: %lld",
41006 - atomic_read(&tcon->num_writes),
41007 + atomic_read_unchecked(&tcon->num_writes),
41008 (long long)(tcon->bytes_written));
41009 seq_printf(m, "\nFlushes: %d",
41010 - atomic_read(&tcon->num_flushes));
41011 + atomic_read_unchecked(&tcon->num_flushes));
41012 seq_printf(m, "\nLocks: %d HardLinks: %d "
41013 "Symlinks: %d",
41014 - atomic_read(&tcon->num_locks),
41015 - atomic_read(&tcon->num_hardlinks),
41016 - atomic_read(&tcon->num_symlinks));
41017 + atomic_read_unchecked(&tcon->num_locks),
41018 + atomic_read_unchecked(&tcon->num_hardlinks),
41019 + atomic_read_unchecked(&tcon->num_symlinks));
41020 seq_printf(m, "\nOpens: %d Closes: %d "
41021 "Deletes: %d",
41022 - atomic_read(&tcon->num_opens),
41023 - atomic_read(&tcon->num_closes),
41024 - atomic_read(&tcon->num_deletes));
41025 + atomic_read_unchecked(&tcon->num_opens),
41026 + atomic_read_unchecked(&tcon->num_closes),
41027 + atomic_read_unchecked(&tcon->num_deletes));
41028 seq_printf(m, "\nPosix Opens: %d "
41029 "Posix Mkdirs: %d",
41030 - atomic_read(&tcon->num_posixopens),
41031 - atomic_read(&tcon->num_posixmkdirs));
41032 + atomic_read_unchecked(&tcon->num_posixopens),
41033 + atomic_read_unchecked(&tcon->num_posixmkdirs));
41034 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
41035 - atomic_read(&tcon->num_mkdirs),
41036 - atomic_read(&tcon->num_rmdirs));
41037 + atomic_read_unchecked(&tcon->num_mkdirs),
41038 + atomic_read_unchecked(&tcon->num_rmdirs));
41039 seq_printf(m, "\nRenames: %d T2 Renames %d",
41040 - atomic_read(&tcon->num_renames),
41041 - atomic_read(&tcon->num_t2renames));
41042 + atomic_read_unchecked(&tcon->num_renames),
41043 + atomic_read_unchecked(&tcon->num_t2renames));
41044 seq_printf(m, "\nFindFirst: %d FNext %d "
41045 "FClose %d",
41046 - atomic_read(&tcon->num_ffirst),
41047 - atomic_read(&tcon->num_fnext),
41048 - atomic_read(&tcon->num_fclose));
41049 + atomic_read_unchecked(&tcon->num_ffirst),
41050 + atomic_read_unchecked(&tcon->num_fnext),
41051 + atomic_read_unchecked(&tcon->num_fclose));
41052 }
41053 }
41054 }
41055 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
41056 index 8f1fe32..38f9e27 100644
41057 --- a/fs/cifs/cifsfs.c
41058 +++ b/fs/cifs/cifsfs.c
41059 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
41060 cifs_req_cachep = kmem_cache_create("cifs_request",
41061 CIFSMaxBufSize +
41062 MAX_CIFS_HDR_SIZE, 0,
41063 - SLAB_HWCACHE_ALIGN, NULL);
41064 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
41065 if (cifs_req_cachep == NULL)
41066 return -ENOMEM;
41067
41068 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
41069 efficient to alloc 1 per page off the slab compared to 17K (5page)
41070 alloc of large cifs buffers even when page debugging is on */
41071 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
41072 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
41073 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
41074 NULL);
41075 if (cifs_sm_req_cachep == NULL) {
41076 mempool_destroy(cifs_req_poolp);
41077 @@ -1101,8 +1101,8 @@ init_cifs(void)
41078 atomic_set(&bufAllocCount, 0);
41079 atomic_set(&smBufAllocCount, 0);
41080 #ifdef CONFIG_CIFS_STATS2
41081 - atomic_set(&totBufAllocCount, 0);
41082 - atomic_set(&totSmBufAllocCount, 0);
41083 + atomic_set_unchecked(&totBufAllocCount, 0);
41084 + atomic_set_unchecked(&totSmBufAllocCount, 0);
41085 #endif /* CONFIG_CIFS_STATS2 */
41086
41087 atomic_set(&midCount, 0);
41088 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
41089 index 8238aa1..0347196 100644
41090 --- a/fs/cifs/cifsglob.h
41091 +++ b/fs/cifs/cifsglob.h
41092 @@ -392,28 +392,28 @@ struct cifs_tcon {
41093 __u16 Flags; /* optional support bits */
41094 enum statusEnum tidStatus;
41095 #ifdef CONFIG_CIFS_STATS
41096 - atomic_t num_smbs_sent;
41097 - atomic_t num_writes;
41098 - atomic_t num_reads;
41099 - atomic_t num_flushes;
41100 - atomic_t num_oplock_brks;
41101 - atomic_t num_opens;
41102 - atomic_t num_closes;
41103 - atomic_t num_deletes;
41104 - atomic_t num_mkdirs;
41105 - atomic_t num_posixopens;
41106 - atomic_t num_posixmkdirs;
41107 - atomic_t num_rmdirs;
41108 - atomic_t num_renames;
41109 - atomic_t num_t2renames;
41110 - atomic_t num_ffirst;
41111 - atomic_t num_fnext;
41112 - atomic_t num_fclose;
41113 - atomic_t num_hardlinks;
41114 - atomic_t num_symlinks;
41115 - atomic_t num_locks;
41116 - atomic_t num_acl_get;
41117 - atomic_t num_acl_set;
41118 + atomic_unchecked_t num_smbs_sent;
41119 + atomic_unchecked_t num_writes;
41120 + atomic_unchecked_t num_reads;
41121 + atomic_unchecked_t num_flushes;
41122 + atomic_unchecked_t num_oplock_brks;
41123 + atomic_unchecked_t num_opens;
41124 + atomic_unchecked_t num_closes;
41125 + atomic_unchecked_t num_deletes;
41126 + atomic_unchecked_t num_mkdirs;
41127 + atomic_unchecked_t num_posixopens;
41128 + atomic_unchecked_t num_posixmkdirs;
41129 + atomic_unchecked_t num_rmdirs;
41130 + atomic_unchecked_t num_renames;
41131 + atomic_unchecked_t num_t2renames;
41132 + atomic_unchecked_t num_ffirst;
41133 + atomic_unchecked_t num_fnext;
41134 + atomic_unchecked_t num_fclose;
41135 + atomic_unchecked_t num_hardlinks;
41136 + atomic_unchecked_t num_symlinks;
41137 + atomic_unchecked_t num_locks;
41138 + atomic_unchecked_t num_acl_get;
41139 + atomic_unchecked_t num_acl_set;
41140 #ifdef CONFIG_CIFS_STATS2
41141 unsigned long long time_writes;
41142 unsigned long long time_reads;
41143 @@ -628,7 +628,7 @@ convert_delimiter(char *path, char delim)
41144 }
41145
41146 #ifdef CONFIG_CIFS_STATS
41147 -#define cifs_stats_inc atomic_inc
41148 +#define cifs_stats_inc atomic_inc_unchecked
41149
41150 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
41151 unsigned int bytes)
41152 @@ -985,8 +985,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
41153 /* Various Debug counters */
41154 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
41155 #ifdef CONFIG_CIFS_STATS2
41156 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
41157 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
41158 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
41159 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
41160 #endif
41161 GLOBAL_EXTERN atomic_t smBufAllocCount;
41162 GLOBAL_EXTERN atomic_t midCount;
41163 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
41164 index 6b0e064..94e6c3c 100644
41165 --- a/fs/cifs/link.c
41166 +++ b/fs/cifs/link.c
41167 @@ -600,7 +600,7 @@ symlink_exit:
41168
41169 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
41170 {
41171 - char *p = nd_get_link(nd);
41172 + const char *p = nd_get_link(nd);
41173 if (!IS_ERR(p))
41174 kfree(p);
41175 }
41176 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
41177 index 703ef5c..2a44ed5 100644
41178 --- a/fs/cifs/misc.c
41179 +++ b/fs/cifs/misc.c
41180 @@ -156,7 +156,7 @@ cifs_buf_get(void)
41181 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
41182 atomic_inc(&bufAllocCount);
41183 #ifdef CONFIG_CIFS_STATS2
41184 - atomic_inc(&totBufAllocCount);
41185 + atomic_inc_unchecked(&totBufAllocCount);
41186 #endif /* CONFIG_CIFS_STATS2 */
41187 }
41188
41189 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
41190 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
41191 atomic_inc(&smBufAllocCount);
41192 #ifdef CONFIG_CIFS_STATS2
41193 - atomic_inc(&totSmBufAllocCount);
41194 + atomic_inc_unchecked(&totSmBufAllocCount);
41195 #endif /* CONFIG_CIFS_STATS2 */
41196
41197 }
41198 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
41199 index 6901578..d402eb5 100644
41200 --- a/fs/coda/cache.c
41201 +++ b/fs/coda/cache.c
41202 @@ -24,7 +24,7 @@
41203 #include "coda_linux.h"
41204 #include "coda_cache.h"
41205
41206 -static atomic_t permission_epoch = ATOMIC_INIT(0);
41207 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
41208
41209 /* replace or extend an acl cache hit */
41210 void coda_cache_enter(struct inode *inode, int mask)
41211 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
41212 struct coda_inode_info *cii = ITOC(inode);
41213
41214 spin_lock(&cii->c_lock);
41215 - cii->c_cached_epoch = atomic_read(&permission_epoch);
41216 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
41217 if (cii->c_uid != current_fsuid()) {
41218 cii->c_uid = current_fsuid();
41219 cii->c_cached_perm = mask;
41220 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
41221 {
41222 struct coda_inode_info *cii = ITOC(inode);
41223 spin_lock(&cii->c_lock);
41224 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
41225 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
41226 spin_unlock(&cii->c_lock);
41227 }
41228
41229 /* remove all acl caches */
41230 void coda_cache_clear_all(struct super_block *sb)
41231 {
41232 - atomic_inc(&permission_epoch);
41233 + atomic_inc_unchecked(&permission_epoch);
41234 }
41235
41236
41237 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
41238 spin_lock(&cii->c_lock);
41239 hit = (mask & cii->c_cached_perm) == mask &&
41240 cii->c_uid == current_fsuid() &&
41241 - cii->c_cached_epoch == atomic_read(&permission_epoch);
41242 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
41243 spin_unlock(&cii->c_lock);
41244
41245 return hit;
41246 diff --git a/fs/compat.c b/fs/compat.c
41247 index c987875..08771ca 100644
41248 --- a/fs/compat.c
41249 +++ b/fs/compat.c
41250 @@ -132,8 +132,8 @@ asmlinkage long compat_sys_utimes(const char __user *filename, struct compat_tim
41251 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
41252 {
41253 compat_ino_t ino = stat->ino;
41254 - typeof(ubuf->st_uid) uid = 0;
41255 - typeof(ubuf->st_gid) gid = 0;
41256 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
41257 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
41258 int err;
41259
41260 SET_UID(uid, stat->uid);
41261 @@ -504,7 +504,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
41262
41263 set_fs(KERNEL_DS);
41264 /* The __user pointer cast is valid because of the set_fs() */
41265 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
41266 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
41267 set_fs(oldfs);
41268 /* truncating is ok because it's a user address */
41269 if (!ret)
41270 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
41271 goto out;
41272
41273 ret = -EINVAL;
41274 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
41275 + if (nr_segs > UIO_MAXIOV)
41276 goto out;
41277 if (nr_segs > fast_segs) {
41278 ret = -ENOMEM;
41279 @@ -845,6 +845,7 @@ struct compat_old_linux_dirent {
41280
41281 struct compat_readdir_callback {
41282 struct compat_old_linux_dirent __user *dirent;
41283 + struct file * file;
41284 int result;
41285 };
41286
41287 @@ -862,6 +863,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
41288 buf->result = -EOVERFLOW;
41289 return -EOVERFLOW;
41290 }
41291 +
41292 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41293 + return 0;
41294 +
41295 buf->result++;
41296 dirent = buf->dirent;
41297 if (!access_ok(VERIFY_WRITE, dirent,
41298 @@ -894,6 +899,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
41299
41300 buf.result = 0;
41301 buf.dirent = dirent;
41302 + buf.file = file;
41303
41304 error = vfs_readdir(file, compat_fillonedir, &buf);
41305 if (buf.result)
41306 @@ -914,6 +920,7 @@ struct compat_linux_dirent {
41307 struct compat_getdents_callback {
41308 struct compat_linux_dirent __user *current_dir;
41309 struct compat_linux_dirent __user *previous;
41310 + struct file * file;
41311 int count;
41312 int error;
41313 };
41314 @@ -935,6 +942,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
41315 buf->error = -EOVERFLOW;
41316 return -EOVERFLOW;
41317 }
41318 +
41319 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41320 + return 0;
41321 +
41322 dirent = buf->previous;
41323 if (dirent) {
41324 if (__put_user(offset, &dirent->d_off))
41325 @@ -982,6 +993,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
41326 buf.previous = NULL;
41327 buf.count = count;
41328 buf.error = 0;
41329 + buf.file = file;
41330
41331 error = vfs_readdir(file, compat_filldir, &buf);
41332 if (error >= 0)
41333 @@ -1003,6 +1015,7 @@ out:
41334 struct compat_getdents_callback64 {
41335 struct linux_dirent64 __user *current_dir;
41336 struct linux_dirent64 __user *previous;
41337 + struct file * file;
41338 int count;
41339 int error;
41340 };
41341 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
41342 buf->error = -EINVAL; /* only used if we fail.. */
41343 if (reclen > buf->count)
41344 return -EINVAL;
41345 +
41346 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41347 + return 0;
41348 +
41349 dirent = buf->previous;
41350
41351 if (dirent) {
41352 @@ -1070,13 +1087,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
41353 buf.previous = NULL;
41354 buf.count = count;
41355 buf.error = 0;
41356 + buf.file = file;
41357
41358 error = vfs_readdir(file, compat_filldir64, &buf);
41359 if (error >= 0)
41360 error = buf.error;
41361 lastdirent = buf.previous;
41362 if (lastdirent) {
41363 - typeof(lastdirent->d_off) d_off = file->f_pos;
41364 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
41365 if (__put_user_unaligned(d_off, &lastdirent->d_off))
41366 error = -EFAULT;
41367 else
41368 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
41369 index 112e45a..b59845b 100644
41370 --- a/fs/compat_binfmt_elf.c
41371 +++ b/fs/compat_binfmt_elf.c
41372 @@ -30,11 +30,13 @@
41373 #undef elf_phdr
41374 #undef elf_shdr
41375 #undef elf_note
41376 +#undef elf_dyn
41377 #undef elf_addr_t
41378 #define elfhdr elf32_hdr
41379 #define elf_phdr elf32_phdr
41380 #define elf_shdr elf32_shdr
41381 #define elf_note elf32_note
41382 +#define elf_dyn Elf32_Dyn
41383 #define elf_addr_t Elf32_Addr
41384
41385 /*
41386 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
41387 index 51352de..93292ff 100644
41388 --- a/fs/compat_ioctl.c
41389 +++ b/fs/compat_ioctl.c
41390 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
41391
41392 err = get_user(palp, &up->palette);
41393 err |= get_user(length, &up->length);
41394 + if (err)
41395 + return -EFAULT;
41396
41397 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
41398 err = put_user(compat_ptr(palp), &up_native->palette);
41399 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
41400 return -EFAULT;
41401 if (__get_user(udata, &ss32->iomem_base))
41402 return -EFAULT;
41403 - ss.iomem_base = compat_ptr(udata);
41404 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
41405 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
41406 __get_user(ss.port_high, &ss32->port_high))
41407 return -EFAULT;
41408 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
41409 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
41410 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
41411 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
41412 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
41413 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
41414 return -EFAULT;
41415
41416 return ioctl_preallocate(file, p);
41417 @@ -1644,8 +1646,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
41418 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
41419 {
41420 unsigned int a, b;
41421 - a = *(unsigned int *)p;
41422 - b = *(unsigned int *)q;
41423 + a = *(const unsigned int *)p;
41424 + b = *(const unsigned int *)q;
41425 if (a > b)
41426 return 1;
41427 if (a < b)
41428 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
41429 index 9a37a9b..35792b6 100644
41430 --- a/fs/configfs/dir.c
41431 +++ b/fs/configfs/dir.c
41432 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
41433 }
41434 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
41435 struct configfs_dirent *next;
41436 - const char * name;
41437 + const unsigned char * name;
41438 + char d_name[sizeof(next->s_dentry->d_iname)];
41439 int len;
41440 struct inode *inode = NULL;
41441
41442 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
41443 continue;
41444
41445 name = configfs_get_name(next);
41446 - len = strlen(name);
41447 + if (next->s_dentry && name == next->s_dentry->d_iname) {
41448 + len = next->s_dentry->d_name.len;
41449 + memcpy(d_name, name, len);
41450 + name = d_name;
41451 + } else
41452 + len = strlen(name);
41453
41454 /*
41455 * We'll have a dentry and an inode for
41456 diff --git a/fs/dcache.c b/fs/dcache.c
41457 index 89509b5..d33331b 100644
41458 --- a/fs/dcache.c
41459 +++ b/fs/dcache.c
41460 @@ -3056,7 +3056,7 @@ void __init vfs_caches_init(unsigned long mempages)
41461 mempages -= reserve;
41462
41463 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
41464 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
41465 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
41466
41467 dcache_init();
41468 inode_init();
41469 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
41470 index 32f90a3..0be89e0 100644
41471 --- a/fs/ecryptfs/inode.c
41472 +++ b/fs/ecryptfs/inode.c
41473 @@ -691,7 +691,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
41474 old_fs = get_fs();
41475 set_fs(get_ds());
41476 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
41477 - (char __user *)lower_buf,
41478 + (char __force_user *)lower_buf,
41479 lower_bufsiz);
41480 set_fs(old_fs);
41481 if (rc < 0)
41482 @@ -737,7 +737,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41483 }
41484 old_fs = get_fs();
41485 set_fs(get_ds());
41486 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
41487 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
41488 set_fs(old_fs);
41489 if (rc < 0) {
41490 kfree(buf);
41491 @@ -752,7 +752,7 @@ out:
41492 static void
41493 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
41494 {
41495 - char *buf = nd_get_link(nd);
41496 + const char *buf = nd_get_link(nd);
41497 if (!IS_ERR(buf)) {
41498 /* Free the char* */
41499 kfree(buf);
41500 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
41501 index 940a82e..63af89e 100644
41502 --- a/fs/ecryptfs/miscdev.c
41503 +++ b/fs/ecryptfs/miscdev.c
41504 @@ -328,7 +328,7 @@ check_list:
41505 goto out_unlock_msg_ctx;
41506 i = 5;
41507 if (msg_ctx->msg) {
41508 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
41509 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
41510 goto out_unlock_msg_ctx;
41511 i += packet_length_size;
41512 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
41513 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
41514 index 3745f7c..89cc7a3 100644
41515 --- a/fs/ecryptfs/read_write.c
41516 +++ b/fs/ecryptfs/read_write.c
41517 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
41518 return -EIO;
41519 fs_save = get_fs();
41520 set_fs(get_ds());
41521 - rc = vfs_write(lower_file, data, size, &offset);
41522 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
41523 set_fs(fs_save);
41524 mark_inode_dirty_sync(ecryptfs_inode);
41525 return rc;
41526 @@ -235,7 +235,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
41527 return -EIO;
41528 fs_save = get_fs();
41529 set_fs(get_ds());
41530 - rc = vfs_read(lower_file, data, size, &offset);
41531 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
41532 set_fs(fs_save);
41533 return rc;
41534 }
41535 diff --git a/fs/exec.c b/fs/exec.c
41536 index 3625464..d08b205 100644
41537 --- a/fs/exec.c
41538 +++ b/fs/exec.c
41539 @@ -55,12 +55,28 @@
41540 #include <linux/pipe_fs_i.h>
41541 #include <linux/oom.h>
41542 #include <linux/compat.h>
41543 +#include <linux/random.h>
41544 +#include <linux/seq_file.h>
41545 +
41546 +#ifdef CONFIG_PAX_REFCOUNT
41547 +#include <linux/kallsyms.h>
41548 +#include <linux/kdebug.h>
41549 +#endif
41550
41551 #include <asm/uaccess.h>
41552 #include <asm/mmu_context.h>
41553 #include <asm/tlb.h>
41554 #include "internal.h"
41555
41556 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
41557 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
41558 +#endif
41559 +
41560 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
41561 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
41562 +EXPORT_SYMBOL(pax_set_initial_flags_func);
41563 +#endif
41564 +
41565 int core_uses_pid;
41566 char core_pattern[CORENAME_MAX_SIZE] = "core";
41567 unsigned int core_pipe_limit;
41568 @@ -70,7 +86,7 @@ struct core_name {
41569 char *corename;
41570 int used, size;
41571 };
41572 -static atomic_t call_count = ATOMIC_INIT(1);
41573 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
41574
41575 /* The maximal length of core_pattern is also specified in sysctl.c */
41576
41577 @@ -188,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
41578 int write)
41579 {
41580 struct page *page;
41581 - int ret;
41582
41583 -#ifdef CONFIG_STACK_GROWSUP
41584 - if (write) {
41585 - ret = expand_downwards(bprm->vma, pos);
41586 - if (ret < 0)
41587 - return NULL;
41588 - }
41589 -#endif
41590 - ret = get_user_pages(current, bprm->mm, pos,
41591 - 1, write, 1, &page, NULL);
41592 - if (ret <= 0)
41593 + if (0 > expand_downwards(bprm->vma, pos))
41594 + return NULL;
41595 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
41596 return NULL;
41597
41598 if (write) {
41599 @@ -274,6 +282,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
41600 vma->vm_end = STACK_TOP_MAX;
41601 vma->vm_start = vma->vm_end - PAGE_SIZE;
41602 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
41603 +
41604 +#ifdef CONFIG_PAX_SEGMEXEC
41605 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
41606 +#endif
41607 +
41608 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
41609 INIT_LIST_HEAD(&vma->anon_vma_chain);
41610
41611 @@ -288,6 +301,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
41612 mm->stack_vm = mm->total_vm = 1;
41613 up_write(&mm->mmap_sem);
41614 bprm->p = vma->vm_end - sizeof(void *);
41615 +
41616 +#ifdef CONFIG_PAX_RANDUSTACK
41617 + if (randomize_va_space)
41618 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
41619 +#endif
41620 +
41621 return 0;
41622 err:
41623 up_write(&mm->mmap_sem);
41624 @@ -396,19 +415,7 @@ err:
41625 return err;
41626 }
41627
41628 -struct user_arg_ptr {
41629 -#ifdef CONFIG_COMPAT
41630 - bool is_compat;
41631 -#endif
41632 - union {
41633 - const char __user *const __user *native;
41634 -#ifdef CONFIG_COMPAT
41635 - compat_uptr_t __user *compat;
41636 -#endif
41637 - } ptr;
41638 -};
41639 -
41640 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41641 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41642 {
41643 const char __user *native;
41644
41645 @@ -417,14 +424,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41646 compat_uptr_t compat;
41647
41648 if (get_user(compat, argv.ptr.compat + nr))
41649 - return ERR_PTR(-EFAULT);
41650 + return (const char __force_user *)ERR_PTR(-EFAULT);
41651
41652 return compat_ptr(compat);
41653 }
41654 #endif
41655
41656 if (get_user(native, argv.ptr.native + nr))
41657 - return ERR_PTR(-EFAULT);
41658 + return (const char __force_user *)ERR_PTR(-EFAULT);
41659
41660 return native;
41661 }
41662 @@ -443,7 +450,7 @@ static int count(struct user_arg_ptr argv, int max)
41663 if (!p)
41664 break;
41665
41666 - if (IS_ERR(p))
41667 + if (IS_ERR((const char __force_kernel *)p))
41668 return -EFAULT;
41669
41670 if (i++ >= max)
41671 @@ -477,7 +484,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
41672
41673 ret = -EFAULT;
41674 str = get_user_arg_ptr(argv, argc);
41675 - if (IS_ERR(str))
41676 + if (IS_ERR((const char __force_kernel *)str))
41677 goto out;
41678
41679 len = strnlen_user(str, MAX_ARG_STRLEN);
41680 @@ -559,7 +566,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
41681 int r;
41682 mm_segment_t oldfs = get_fs();
41683 struct user_arg_ptr argv = {
41684 - .ptr.native = (const char __user *const __user *)__argv,
41685 + .ptr.native = (const char __force_user *const __force_user *)__argv,
41686 };
41687
41688 set_fs(KERNEL_DS);
41689 @@ -594,7 +601,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
41690 unsigned long new_end = old_end - shift;
41691 struct mmu_gather tlb;
41692
41693 - BUG_ON(new_start > new_end);
41694 + if (new_start >= new_end || new_start < mmap_min_addr)
41695 + return -ENOMEM;
41696
41697 /*
41698 * ensure there are no vmas between where we want to go
41699 @@ -603,6 +611,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
41700 if (vma != find_vma(mm, new_start))
41701 return -EFAULT;
41702
41703 +#ifdef CONFIG_PAX_SEGMEXEC
41704 + BUG_ON(pax_find_mirror_vma(vma));
41705 +#endif
41706 +
41707 /*
41708 * cover the whole range: [new_start, old_end)
41709 */
41710 @@ -683,10 +695,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
41711 stack_top = arch_align_stack(stack_top);
41712 stack_top = PAGE_ALIGN(stack_top);
41713
41714 - if (unlikely(stack_top < mmap_min_addr) ||
41715 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
41716 - return -ENOMEM;
41717 -
41718 stack_shift = vma->vm_end - stack_top;
41719
41720 bprm->p -= stack_shift;
41721 @@ -698,8 +706,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
41722 bprm->exec -= stack_shift;
41723
41724 down_write(&mm->mmap_sem);
41725 +
41726 + /* Move stack pages down in memory. */
41727 + if (stack_shift) {
41728 + ret = shift_arg_pages(vma, stack_shift);
41729 + if (ret)
41730 + goto out_unlock;
41731 + }
41732 +
41733 vm_flags = VM_STACK_FLAGS;
41734
41735 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41736 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41737 + vm_flags &= ~VM_EXEC;
41738 +
41739 +#ifdef CONFIG_PAX_MPROTECT
41740 + if (mm->pax_flags & MF_PAX_MPROTECT)
41741 + vm_flags &= ~VM_MAYEXEC;
41742 +#endif
41743 +
41744 + }
41745 +#endif
41746 +
41747 /*
41748 * Adjust stack execute permissions; explicitly enable for
41749 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
41750 @@ -718,13 +746,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
41751 goto out_unlock;
41752 BUG_ON(prev != vma);
41753
41754 - /* Move stack pages down in memory. */
41755 - if (stack_shift) {
41756 - ret = shift_arg_pages(vma, stack_shift);
41757 - if (ret)
41758 - goto out_unlock;
41759 - }
41760 -
41761 /* mprotect_fixup is overkill to remove the temporary stack flags */
41762 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
41763
41764 @@ -805,7 +826,7 @@ int kernel_read(struct file *file, loff_t offset,
41765 old_fs = get_fs();
41766 set_fs(get_ds());
41767 /* The cast to a user pointer is valid due to the set_fs() */
41768 - result = vfs_read(file, (void __user *)addr, count, &pos);
41769 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
41770 set_fs(old_fs);
41771 return result;
41772 }
41773 @@ -1247,7 +1268,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
41774 }
41775 rcu_read_unlock();
41776
41777 - if (p->fs->users > n_fs) {
41778 + if (atomic_read(&p->fs->users) > n_fs) {
41779 bprm->unsafe |= LSM_UNSAFE_SHARE;
41780 } else {
41781 res = -EAGAIN;
41782 @@ -1450,6 +1471,11 @@ static int do_execve_common(const char *filename,
41783 struct user_arg_ptr envp,
41784 struct pt_regs *regs)
41785 {
41786 +#ifdef CONFIG_GRKERNSEC
41787 + struct file *old_exec_file;
41788 + struct acl_subject_label *old_acl;
41789 + struct rlimit old_rlim[RLIM_NLIMITS];
41790 +#endif
41791 struct linux_binprm *bprm;
41792 struct file *file;
41793 struct files_struct *displaced;
41794 @@ -1457,6 +1483,8 @@ static int do_execve_common(const char *filename,
41795 int retval;
41796 const struct cred *cred = current_cred();
41797
41798 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
41799 +
41800 /*
41801 * We move the actual failure in case of RLIMIT_NPROC excess from
41802 * set*uid() to execve() because too many poorly written programs
41803 @@ -1497,12 +1525,27 @@ static int do_execve_common(const char *filename,
41804 if (IS_ERR(file))
41805 goto out_unmark;
41806
41807 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
41808 + retval = -EPERM;
41809 + goto out_file;
41810 + }
41811 +
41812 sched_exec();
41813
41814 bprm->file = file;
41815 bprm->filename = filename;
41816 bprm->interp = filename;
41817
41818 + if (gr_process_user_ban()) {
41819 + retval = -EPERM;
41820 + goto out_file;
41821 + }
41822 +
41823 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
41824 + retval = -EACCES;
41825 + goto out_file;
41826 + }
41827 +
41828 retval = bprm_mm_init(bprm);
41829 if (retval)
41830 goto out_file;
41831 @@ -1532,9 +1575,40 @@ static int do_execve_common(const char *filename,
41832 if (retval < 0)
41833 goto out;
41834
41835 + if (!gr_tpe_allow(file)) {
41836 + retval = -EACCES;
41837 + goto out;
41838 + }
41839 +
41840 + if (gr_check_crash_exec(file)) {
41841 + retval = -EACCES;
41842 + goto out;
41843 + }
41844 +
41845 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
41846 +
41847 + gr_handle_exec_args(bprm, argv);
41848 +
41849 +#ifdef CONFIG_GRKERNSEC
41850 + old_acl = current->acl;
41851 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
41852 + old_exec_file = current->exec_file;
41853 + get_file(file);
41854 + current->exec_file = file;
41855 +#endif
41856 +
41857 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
41858 + bprm->unsafe & LSM_UNSAFE_SHARE);
41859 + if (retval < 0)
41860 + goto out_fail;
41861 +
41862 retval = search_binary_handler(bprm,regs);
41863 if (retval < 0)
41864 - goto out;
41865 + goto out_fail;
41866 +#ifdef CONFIG_GRKERNSEC
41867 + if (old_exec_file)
41868 + fput(old_exec_file);
41869 +#endif
41870
41871 /* execve succeeded */
41872 current->fs->in_exec = 0;
41873 @@ -1545,6 +1619,14 @@ static int do_execve_common(const char *filename,
41874 put_files_struct(displaced);
41875 return retval;
41876
41877 +out_fail:
41878 +#ifdef CONFIG_GRKERNSEC
41879 + current->acl = old_acl;
41880 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
41881 + fput(current->exec_file);
41882 + current->exec_file = old_exec_file;
41883 +#endif
41884 +
41885 out:
41886 if (bprm->mm) {
41887 acct_arg_size(bprm, 0);
41888 @@ -1618,7 +1700,7 @@ static int expand_corename(struct core_name *cn)
41889 {
41890 char *old_corename = cn->corename;
41891
41892 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
41893 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
41894 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
41895
41896 if (!cn->corename) {
41897 @@ -1715,7 +1797,7 @@ static int format_corename(struct core_name *cn, long signr)
41898 int pid_in_pattern = 0;
41899 int err = 0;
41900
41901 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
41902 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
41903 cn->corename = kmalloc(cn->size, GFP_KERNEL);
41904 cn->used = 0;
41905
41906 @@ -1812,6 +1894,218 @@ out:
41907 return ispipe;
41908 }
41909
41910 +int pax_check_flags(unsigned long *flags)
41911 +{
41912 + int retval = 0;
41913 +
41914 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
41915 + if (*flags & MF_PAX_SEGMEXEC)
41916 + {
41917 + *flags &= ~MF_PAX_SEGMEXEC;
41918 + retval = -EINVAL;
41919 + }
41920 +#endif
41921 +
41922 + if ((*flags & MF_PAX_PAGEEXEC)
41923 +
41924 +#ifdef CONFIG_PAX_PAGEEXEC
41925 + && (*flags & MF_PAX_SEGMEXEC)
41926 +#endif
41927 +
41928 + )
41929 + {
41930 + *flags &= ~MF_PAX_PAGEEXEC;
41931 + retval = -EINVAL;
41932 + }
41933 +
41934 + if ((*flags & MF_PAX_MPROTECT)
41935 +
41936 +#ifdef CONFIG_PAX_MPROTECT
41937 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
41938 +#endif
41939 +
41940 + )
41941 + {
41942 + *flags &= ~MF_PAX_MPROTECT;
41943 + retval = -EINVAL;
41944 + }
41945 +
41946 + if ((*flags & MF_PAX_EMUTRAMP)
41947 +
41948 +#ifdef CONFIG_PAX_EMUTRAMP
41949 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
41950 +#endif
41951 +
41952 + )
41953 + {
41954 + *flags &= ~MF_PAX_EMUTRAMP;
41955 + retval = -EINVAL;
41956 + }
41957 +
41958 + return retval;
41959 +}
41960 +
41961 +EXPORT_SYMBOL(pax_check_flags);
41962 +
41963 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41964 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
41965 +{
41966 + struct task_struct *tsk = current;
41967 + struct mm_struct *mm = current->mm;
41968 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
41969 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
41970 + char *path_exec = NULL;
41971 + char *path_fault = NULL;
41972 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
41973 +
41974 + if (buffer_exec && buffer_fault) {
41975 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
41976 +
41977 + down_read(&mm->mmap_sem);
41978 + vma = mm->mmap;
41979 + while (vma && (!vma_exec || !vma_fault)) {
41980 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
41981 + vma_exec = vma;
41982 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
41983 + vma_fault = vma;
41984 + vma = vma->vm_next;
41985 + }
41986 + if (vma_exec) {
41987 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
41988 + if (IS_ERR(path_exec))
41989 + path_exec = "<path too long>";
41990 + else {
41991 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
41992 + if (path_exec) {
41993 + *path_exec = 0;
41994 + path_exec = buffer_exec;
41995 + } else
41996 + path_exec = "<path too long>";
41997 + }
41998 + }
41999 + if (vma_fault) {
42000 + start = vma_fault->vm_start;
42001 + end = vma_fault->vm_end;
42002 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
42003 + if (vma_fault->vm_file) {
42004 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
42005 + if (IS_ERR(path_fault))
42006 + path_fault = "<path too long>";
42007 + else {
42008 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
42009 + if (path_fault) {
42010 + *path_fault = 0;
42011 + path_fault = buffer_fault;
42012 + } else
42013 + path_fault = "<path too long>";
42014 + }
42015 + } else
42016 + path_fault = "<anonymous mapping>";
42017 + }
42018 + up_read(&mm->mmap_sem);
42019 + }
42020 + if (tsk->signal->curr_ip)
42021 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
42022 + else
42023 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
42024 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
42025 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
42026 + task_uid(tsk), task_euid(tsk), pc, sp);
42027 + free_page((unsigned long)buffer_exec);
42028 + free_page((unsigned long)buffer_fault);
42029 + pax_report_insns(regs, pc, sp);
42030 + do_coredump(SIGKILL, SIGKILL, regs);
42031 +}
42032 +#endif
42033 +
42034 +#ifdef CONFIG_PAX_REFCOUNT
42035 +void pax_report_refcount_overflow(struct pt_regs *regs)
42036 +{
42037 + if (current->signal->curr_ip)
42038 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
42039 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
42040 + else
42041 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
42042 + current->comm, task_pid_nr(current), current_uid(), current_euid());
42043 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
42044 + show_regs(regs);
42045 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
42046 +}
42047 +#endif
42048 +
42049 +#ifdef CONFIG_PAX_USERCOPY
42050 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
42051 +int object_is_on_stack(const void *obj, unsigned long len)
42052 +{
42053 + const void * const stack = task_stack_page(current);
42054 + const void * const stackend = stack + THREAD_SIZE;
42055 +
42056 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
42057 + const void *frame = NULL;
42058 + const void *oldframe;
42059 +#endif
42060 +
42061 + if (obj + len < obj)
42062 + return -1;
42063 +
42064 + if (obj + len <= stack || stackend <= obj)
42065 + return 0;
42066 +
42067 + if (obj < stack || stackend < obj + len)
42068 + return -1;
42069 +
42070 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
42071 + oldframe = __builtin_frame_address(1);
42072 + if (oldframe)
42073 + frame = __builtin_frame_address(2);
42074 + /*
42075 + low ----------------------------------------------> high
42076 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
42077 + ^----------------^
42078 + allow copies only within here
42079 + */
42080 + while (stack <= frame && frame < stackend) {
42081 + /* if obj + len extends past the last frame, this
42082 + check won't pass and the next frame will be 0,
42083 + causing us to bail out and correctly report
42084 + the copy as invalid
42085 + */
42086 + if (obj + len <= frame)
42087 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
42088 + oldframe = frame;
42089 + frame = *(const void * const *)frame;
42090 + }
42091 + return -1;
42092 +#else
42093 + return 1;
42094 +#endif
42095 +}
42096 +
42097 +NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
42098 +{
42099 + if (current->signal->curr_ip)
42100 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
42101 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
42102 + else
42103 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
42104 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
42105 + dump_stack();
42106 + gr_handle_kernel_exploit();
42107 + do_group_exit(SIGKILL);
42108 +}
42109 +#endif
42110 +
42111 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
42112 +void pax_track_stack(void)
42113 +{
42114 + unsigned long sp = (unsigned long)&sp;
42115 + if (sp < current_thread_info()->lowest_stack &&
42116 + sp > (unsigned long)task_stack_page(current))
42117 + current_thread_info()->lowest_stack = sp;
42118 +}
42119 +EXPORT_SYMBOL(pax_track_stack);
42120 +#endif
42121 +
42122 static int zap_process(struct task_struct *start, int exit_code)
42123 {
42124 struct task_struct *t;
42125 @@ -2023,17 +2317,17 @@ static void wait_for_dump_helpers(struct file *file)
42126 pipe = file->f_path.dentry->d_inode->i_pipe;
42127
42128 pipe_lock(pipe);
42129 - pipe->readers++;
42130 - pipe->writers--;
42131 + atomic_inc(&pipe->readers);
42132 + atomic_dec(&pipe->writers);
42133
42134 - while ((pipe->readers > 1) && (!signal_pending(current))) {
42135 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
42136 wake_up_interruptible_sync(&pipe->wait);
42137 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
42138 pipe_wait(pipe);
42139 }
42140
42141 - pipe->readers--;
42142 - pipe->writers++;
42143 + atomic_dec(&pipe->readers);
42144 + atomic_inc(&pipe->writers);
42145 pipe_unlock(pipe);
42146
42147 }
42148 @@ -2094,7 +2388,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42149 int retval = 0;
42150 int flag = 0;
42151 int ispipe;
42152 - static atomic_t core_dump_count = ATOMIC_INIT(0);
42153 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
42154 struct coredump_params cprm = {
42155 .signr = signr,
42156 .regs = regs,
42157 @@ -2109,6 +2403,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42158
42159 audit_core_dumps(signr);
42160
42161 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
42162 + gr_handle_brute_attach(current, cprm.mm_flags);
42163 +
42164 binfmt = mm->binfmt;
42165 if (!binfmt || !binfmt->core_dump)
42166 goto fail;
42167 @@ -2176,7 +2473,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42168 }
42169 cprm.limit = RLIM_INFINITY;
42170
42171 - dump_count = atomic_inc_return(&core_dump_count);
42172 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
42173 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
42174 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
42175 task_tgid_vnr(current), current->comm);
42176 @@ -2203,6 +2500,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42177 } else {
42178 struct inode *inode;
42179
42180 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
42181 +
42182 if (cprm.limit < binfmt->min_coredump)
42183 goto fail_unlock;
42184
42185 @@ -2246,7 +2545,7 @@ close_fail:
42186 filp_close(cprm.file, NULL);
42187 fail_dropcount:
42188 if (ispipe)
42189 - atomic_dec(&core_dump_count);
42190 + atomic_dec_unchecked(&core_dump_count);
42191 fail_unlock:
42192 kfree(cn.corename);
42193 fail_corename:
42194 @@ -2265,7 +2564,7 @@ fail:
42195 */
42196 int dump_write(struct file *file, const void *addr, int nr)
42197 {
42198 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
42199 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
42200 }
42201 EXPORT_SYMBOL(dump_write);
42202
42203 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
42204 index a8cbe1b..fed04cb 100644
42205 --- a/fs/ext2/balloc.c
42206 +++ b/fs/ext2/balloc.c
42207 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
42208
42209 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
42210 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
42211 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
42212 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
42213 sbi->s_resuid != current_fsuid() &&
42214 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
42215 return 0;
42216 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
42217 index a203892..4e64db5 100644
42218 --- a/fs/ext3/balloc.c
42219 +++ b/fs/ext3/balloc.c
42220 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
42221
42222 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
42223 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
42224 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
42225 + if (free_blocks < root_blocks + 1 &&
42226 !use_reservation && sbi->s_resuid != current_fsuid() &&
42227 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
42228 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
42229 + !capable_nolog(CAP_SYS_RESOURCE)) {
42230 return 0;
42231 }
42232 return 1;
42233 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
42234 index 12ccacd..a6035fce0 100644
42235 --- a/fs/ext4/balloc.c
42236 +++ b/fs/ext4/balloc.c
42237 @@ -436,8 +436,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
42238 /* Hm, nope. Are (enough) root reserved clusters available? */
42239 if (sbi->s_resuid == current_fsuid() ||
42240 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
42241 - capable(CAP_SYS_RESOURCE) ||
42242 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
42243 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
42244 + capable_nolog(CAP_SYS_RESOURCE)) {
42245
42246 if (free_clusters >= (nclusters + dirty_clusters))
42247 return 1;
42248 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
42249 index 5b0e26a..0aa002d 100644
42250 --- a/fs/ext4/ext4.h
42251 +++ b/fs/ext4/ext4.h
42252 @@ -1208,19 +1208,19 @@ struct ext4_sb_info {
42253 unsigned long s_mb_last_start;
42254
42255 /* stats for buddy allocator */
42256 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
42257 - atomic_t s_bal_success; /* we found long enough chunks */
42258 - atomic_t s_bal_allocated; /* in blocks */
42259 - atomic_t s_bal_ex_scanned; /* total extents scanned */
42260 - atomic_t s_bal_goals; /* goal hits */
42261 - atomic_t s_bal_breaks; /* too long searches */
42262 - atomic_t s_bal_2orders; /* 2^order hits */
42263 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
42264 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
42265 + atomic_unchecked_t s_bal_allocated; /* in blocks */
42266 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
42267 + atomic_unchecked_t s_bal_goals; /* goal hits */
42268 + atomic_unchecked_t s_bal_breaks; /* too long searches */
42269 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
42270 spinlock_t s_bal_lock;
42271 unsigned long s_mb_buddies_generated;
42272 unsigned long long s_mb_generation_time;
42273 - atomic_t s_mb_lost_chunks;
42274 - atomic_t s_mb_preallocated;
42275 - atomic_t s_mb_discarded;
42276 + atomic_unchecked_t s_mb_lost_chunks;
42277 + atomic_unchecked_t s_mb_preallocated;
42278 + atomic_unchecked_t s_mb_discarded;
42279 atomic_t s_lock_busy;
42280
42281 /* locality groups */
42282 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
42283 index e2d8be8..c7f0ce9 100644
42284 --- a/fs/ext4/mballoc.c
42285 +++ b/fs/ext4/mballoc.c
42286 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
42287 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
42288
42289 if (EXT4_SB(sb)->s_mb_stats)
42290 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
42291 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
42292
42293 break;
42294 }
42295 @@ -2088,7 +2088,7 @@ repeat:
42296 ac->ac_status = AC_STATUS_CONTINUE;
42297 ac->ac_flags |= EXT4_MB_HINT_FIRST;
42298 cr = 3;
42299 - atomic_inc(&sbi->s_mb_lost_chunks);
42300 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
42301 goto repeat;
42302 }
42303 }
42304 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
42305 if (sbi->s_mb_stats) {
42306 ext4_msg(sb, KERN_INFO,
42307 "mballoc: %u blocks %u reqs (%u success)",
42308 - atomic_read(&sbi->s_bal_allocated),
42309 - atomic_read(&sbi->s_bal_reqs),
42310 - atomic_read(&sbi->s_bal_success));
42311 + atomic_read_unchecked(&sbi->s_bal_allocated),
42312 + atomic_read_unchecked(&sbi->s_bal_reqs),
42313 + atomic_read_unchecked(&sbi->s_bal_success));
42314 ext4_msg(sb, KERN_INFO,
42315 "mballoc: %u extents scanned, %u goal hits, "
42316 "%u 2^N hits, %u breaks, %u lost",
42317 - atomic_read(&sbi->s_bal_ex_scanned),
42318 - atomic_read(&sbi->s_bal_goals),
42319 - atomic_read(&sbi->s_bal_2orders),
42320 - atomic_read(&sbi->s_bal_breaks),
42321 - atomic_read(&sbi->s_mb_lost_chunks));
42322 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
42323 + atomic_read_unchecked(&sbi->s_bal_goals),
42324 + atomic_read_unchecked(&sbi->s_bal_2orders),
42325 + atomic_read_unchecked(&sbi->s_bal_breaks),
42326 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
42327 ext4_msg(sb, KERN_INFO,
42328 "mballoc: %lu generated and it took %Lu",
42329 sbi->s_mb_buddies_generated,
42330 sbi->s_mb_generation_time);
42331 ext4_msg(sb, KERN_INFO,
42332 "mballoc: %u preallocated, %u discarded",
42333 - atomic_read(&sbi->s_mb_preallocated),
42334 - atomic_read(&sbi->s_mb_discarded));
42335 + atomic_read_unchecked(&sbi->s_mb_preallocated),
42336 + atomic_read_unchecked(&sbi->s_mb_discarded));
42337 }
42338
42339 free_percpu(sbi->s_locality_groups);
42340 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
42341 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
42342
42343 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
42344 - atomic_inc(&sbi->s_bal_reqs);
42345 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
42346 + atomic_inc_unchecked(&sbi->s_bal_reqs);
42347 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
42348 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
42349 - atomic_inc(&sbi->s_bal_success);
42350 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
42351 + atomic_inc_unchecked(&sbi->s_bal_success);
42352 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
42353 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
42354 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
42355 - atomic_inc(&sbi->s_bal_goals);
42356 + atomic_inc_unchecked(&sbi->s_bal_goals);
42357 if (ac->ac_found > sbi->s_mb_max_to_scan)
42358 - atomic_inc(&sbi->s_bal_breaks);
42359 + atomic_inc_unchecked(&sbi->s_bal_breaks);
42360 }
42361
42362 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
42363 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
42364 trace_ext4_mb_new_inode_pa(ac, pa);
42365
42366 ext4_mb_use_inode_pa(ac, pa);
42367 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
42368 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
42369
42370 ei = EXT4_I(ac->ac_inode);
42371 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
42372 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
42373 trace_ext4_mb_new_group_pa(ac, pa);
42374
42375 ext4_mb_use_group_pa(ac, pa);
42376 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42377 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42378
42379 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
42380 lg = ac->ac_lg;
42381 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
42382 * from the bitmap and continue.
42383 */
42384 }
42385 - atomic_add(free, &sbi->s_mb_discarded);
42386 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
42387
42388 return err;
42389 }
42390 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
42391 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
42392 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
42393 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
42394 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
42395 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
42396 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
42397
42398 return 0;
42399 diff --git a/fs/fcntl.c b/fs/fcntl.c
42400 index 22764c7..86372c9 100644
42401 --- a/fs/fcntl.c
42402 +++ b/fs/fcntl.c
42403 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
42404 if (err)
42405 return err;
42406
42407 + if (gr_handle_chroot_fowner(pid, type))
42408 + return -ENOENT;
42409 + if (gr_check_protected_task_fowner(pid, type))
42410 + return -EACCES;
42411 +
42412 f_modown(filp, pid, type, force);
42413 return 0;
42414 }
42415 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
42416
42417 static int f_setown_ex(struct file *filp, unsigned long arg)
42418 {
42419 - struct f_owner_ex * __user owner_p = (void * __user)arg;
42420 + struct f_owner_ex __user *owner_p = (void __user *)arg;
42421 struct f_owner_ex owner;
42422 struct pid *pid;
42423 int type;
42424 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
42425
42426 static int f_getown_ex(struct file *filp, unsigned long arg)
42427 {
42428 - struct f_owner_ex * __user owner_p = (void * __user)arg;
42429 + struct f_owner_ex __user *owner_p = (void __user *)arg;
42430 struct f_owner_ex owner;
42431 int ret = 0;
42432
42433 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
42434 switch (cmd) {
42435 case F_DUPFD:
42436 case F_DUPFD_CLOEXEC:
42437 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
42438 if (arg >= rlimit(RLIMIT_NOFILE))
42439 break;
42440 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
42441 diff --git a/fs/fifo.c b/fs/fifo.c
42442 index b1a524d..4ee270e 100644
42443 --- a/fs/fifo.c
42444 +++ b/fs/fifo.c
42445 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
42446 */
42447 filp->f_op = &read_pipefifo_fops;
42448 pipe->r_counter++;
42449 - if (pipe->readers++ == 0)
42450 + if (atomic_inc_return(&pipe->readers) == 1)
42451 wake_up_partner(inode);
42452
42453 - if (!pipe->writers) {
42454 + if (!atomic_read(&pipe->writers)) {
42455 if ((filp->f_flags & O_NONBLOCK)) {
42456 /* suppress POLLHUP until we have
42457 * seen a writer */
42458 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
42459 * errno=ENXIO when there is no process reading the FIFO.
42460 */
42461 ret = -ENXIO;
42462 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
42463 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
42464 goto err;
42465
42466 filp->f_op = &write_pipefifo_fops;
42467 pipe->w_counter++;
42468 - if (!pipe->writers++)
42469 + if (atomic_inc_return(&pipe->writers) == 1)
42470 wake_up_partner(inode);
42471
42472 - if (!pipe->readers) {
42473 + if (!atomic_read(&pipe->readers)) {
42474 wait_for_partner(inode, &pipe->r_counter);
42475 if (signal_pending(current))
42476 goto err_wr;
42477 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
42478 */
42479 filp->f_op = &rdwr_pipefifo_fops;
42480
42481 - pipe->readers++;
42482 - pipe->writers++;
42483 + atomic_inc(&pipe->readers);
42484 + atomic_inc(&pipe->writers);
42485 pipe->r_counter++;
42486 pipe->w_counter++;
42487 - if (pipe->readers == 1 || pipe->writers == 1)
42488 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
42489 wake_up_partner(inode);
42490 break;
42491
42492 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
42493 return 0;
42494
42495 err_rd:
42496 - if (!--pipe->readers)
42497 + if (atomic_dec_and_test(&pipe->readers))
42498 wake_up_interruptible(&pipe->wait);
42499 ret = -ERESTARTSYS;
42500 goto err;
42501
42502 err_wr:
42503 - if (!--pipe->writers)
42504 + if (atomic_dec_and_test(&pipe->writers))
42505 wake_up_interruptible(&pipe->wait);
42506 ret = -ERESTARTSYS;
42507 goto err;
42508
42509 err:
42510 - if (!pipe->readers && !pipe->writers)
42511 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
42512 free_pipe_info(inode);
42513
42514 err_nocleanup:
42515 diff --git a/fs/file.c b/fs/file.c
42516 index 4c6992d..104cdea 100644
42517 --- a/fs/file.c
42518 +++ b/fs/file.c
42519 @@ -15,6 +15,7 @@
42520 #include <linux/slab.h>
42521 #include <linux/vmalloc.h>
42522 #include <linux/file.h>
42523 +#include <linux/security.h>
42524 #include <linux/fdtable.h>
42525 #include <linux/bitops.h>
42526 #include <linux/interrupt.h>
42527 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
42528 * N.B. For clone tasks sharing a files structure, this test
42529 * will limit the total number of files that can be opened.
42530 */
42531 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
42532 if (nr >= rlimit(RLIMIT_NOFILE))
42533 return -EMFILE;
42534
42535 diff --git a/fs/filesystems.c b/fs/filesystems.c
42536 index 0845f84..7b4ebef 100644
42537 --- a/fs/filesystems.c
42538 +++ b/fs/filesystems.c
42539 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(const char *name)
42540 int len = dot ? dot - name : strlen(name);
42541
42542 fs = __get_fs_type(name, len);
42543 +
42544 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
42545 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
42546 +#else
42547 if (!fs && (request_module("%.*s", len, name) == 0))
42548 +#endif
42549 fs = __get_fs_type(name, len);
42550
42551 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
42552 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
42553 index 78b519c..212c0d0 100644
42554 --- a/fs/fs_struct.c
42555 +++ b/fs/fs_struct.c
42556 @@ -4,6 +4,7 @@
42557 #include <linux/path.h>
42558 #include <linux/slab.h>
42559 #include <linux/fs_struct.h>
42560 +#include <linux/grsecurity.h>
42561 #include "internal.h"
42562
42563 static inline void path_get_longterm(struct path *path)
42564 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
42565 old_root = fs->root;
42566 fs->root = *path;
42567 path_get_longterm(path);
42568 + gr_set_chroot_entries(current, path);
42569 write_seqcount_end(&fs->seq);
42570 spin_unlock(&fs->lock);
42571 if (old_root.dentry)
42572 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
42573 && fs->root.mnt == old_root->mnt) {
42574 path_get_longterm(new_root);
42575 fs->root = *new_root;
42576 + gr_set_chroot_entries(p, new_root);
42577 count++;
42578 }
42579 if (fs->pwd.dentry == old_root->dentry
42580 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
42581 spin_lock(&fs->lock);
42582 write_seqcount_begin(&fs->seq);
42583 tsk->fs = NULL;
42584 - kill = !--fs->users;
42585 + gr_clear_chroot_entries(tsk);
42586 + kill = !atomic_dec_return(&fs->users);
42587 write_seqcount_end(&fs->seq);
42588 spin_unlock(&fs->lock);
42589 task_unlock(tsk);
42590 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
42591 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
42592 /* We don't need to lock fs - think why ;-) */
42593 if (fs) {
42594 - fs->users = 1;
42595 + atomic_set(&fs->users, 1);
42596 fs->in_exec = 0;
42597 spin_lock_init(&fs->lock);
42598 seqcount_init(&fs->seq);
42599 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
42600 spin_lock(&old->lock);
42601 fs->root = old->root;
42602 path_get_longterm(&fs->root);
42603 + /* instead of calling gr_set_chroot_entries here,
42604 + we call it from every caller of this function
42605 + */
42606 fs->pwd = old->pwd;
42607 path_get_longterm(&fs->pwd);
42608 spin_unlock(&old->lock);
42609 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
42610
42611 task_lock(current);
42612 spin_lock(&fs->lock);
42613 - kill = !--fs->users;
42614 + kill = !atomic_dec_return(&fs->users);
42615 current->fs = new_fs;
42616 + gr_set_chroot_entries(current, &new_fs->root);
42617 spin_unlock(&fs->lock);
42618 task_unlock(current);
42619
42620 @@ -170,7 +178,7 @@ EXPORT_SYMBOL(current_umask);
42621
42622 /* to be mentioned only in INIT_TASK */
42623 struct fs_struct init_fs = {
42624 - .users = 1,
42625 + .users = ATOMIC_INIT(1),
42626 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
42627 .seq = SEQCNT_ZERO,
42628 .umask = 0022,
42629 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
42630 task_lock(current);
42631
42632 spin_lock(&init_fs.lock);
42633 - init_fs.users++;
42634 + atomic_inc(&init_fs.users);
42635 spin_unlock(&init_fs.lock);
42636
42637 spin_lock(&fs->lock);
42638 current->fs = &init_fs;
42639 - kill = !--fs->users;
42640 + gr_set_chroot_entries(current, &current->fs->root);
42641 + kill = !atomic_dec_return(&fs->users);
42642 spin_unlock(&fs->lock);
42643
42644 task_unlock(current);
42645 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
42646 index 9905350..02eaec4 100644
42647 --- a/fs/fscache/cookie.c
42648 +++ b/fs/fscache/cookie.c
42649 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
42650 parent ? (char *) parent->def->name : "<no-parent>",
42651 def->name, netfs_data);
42652
42653 - fscache_stat(&fscache_n_acquires);
42654 + fscache_stat_unchecked(&fscache_n_acquires);
42655
42656 /* if there's no parent cookie, then we don't create one here either */
42657 if (!parent) {
42658 - fscache_stat(&fscache_n_acquires_null);
42659 + fscache_stat_unchecked(&fscache_n_acquires_null);
42660 _leave(" [no parent]");
42661 return NULL;
42662 }
42663 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
42664 /* allocate and initialise a cookie */
42665 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
42666 if (!cookie) {
42667 - fscache_stat(&fscache_n_acquires_oom);
42668 + fscache_stat_unchecked(&fscache_n_acquires_oom);
42669 _leave(" [ENOMEM]");
42670 return NULL;
42671 }
42672 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
42673
42674 switch (cookie->def->type) {
42675 case FSCACHE_COOKIE_TYPE_INDEX:
42676 - fscache_stat(&fscache_n_cookie_index);
42677 + fscache_stat_unchecked(&fscache_n_cookie_index);
42678 break;
42679 case FSCACHE_COOKIE_TYPE_DATAFILE:
42680 - fscache_stat(&fscache_n_cookie_data);
42681 + fscache_stat_unchecked(&fscache_n_cookie_data);
42682 break;
42683 default:
42684 - fscache_stat(&fscache_n_cookie_special);
42685 + fscache_stat_unchecked(&fscache_n_cookie_special);
42686 break;
42687 }
42688
42689 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
42690 if (fscache_acquire_non_index_cookie(cookie) < 0) {
42691 atomic_dec(&parent->n_children);
42692 __fscache_cookie_put(cookie);
42693 - fscache_stat(&fscache_n_acquires_nobufs);
42694 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
42695 _leave(" = NULL");
42696 return NULL;
42697 }
42698 }
42699
42700 - fscache_stat(&fscache_n_acquires_ok);
42701 + fscache_stat_unchecked(&fscache_n_acquires_ok);
42702 _leave(" = %p", cookie);
42703 return cookie;
42704 }
42705 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
42706 cache = fscache_select_cache_for_object(cookie->parent);
42707 if (!cache) {
42708 up_read(&fscache_addremove_sem);
42709 - fscache_stat(&fscache_n_acquires_no_cache);
42710 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
42711 _leave(" = -ENOMEDIUM [no cache]");
42712 return -ENOMEDIUM;
42713 }
42714 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
42715 object = cache->ops->alloc_object(cache, cookie);
42716 fscache_stat_d(&fscache_n_cop_alloc_object);
42717 if (IS_ERR(object)) {
42718 - fscache_stat(&fscache_n_object_no_alloc);
42719 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
42720 ret = PTR_ERR(object);
42721 goto error;
42722 }
42723
42724 - fscache_stat(&fscache_n_object_alloc);
42725 + fscache_stat_unchecked(&fscache_n_object_alloc);
42726
42727 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
42728
42729 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
42730 struct fscache_object *object;
42731 struct hlist_node *_p;
42732
42733 - fscache_stat(&fscache_n_updates);
42734 + fscache_stat_unchecked(&fscache_n_updates);
42735
42736 if (!cookie) {
42737 - fscache_stat(&fscache_n_updates_null);
42738 + fscache_stat_unchecked(&fscache_n_updates_null);
42739 _leave(" [no cookie]");
42740 return;
42741 }
42742 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
42743 struct fscache_object *object;
42744 unsigned long event;
42745
42746 - fscache_stat(&fscache_n_relinquishes);
42747 + fscache_stat_unchecked(&fscache_n_relinquishes);
42748 if (retire)
42749 - fscache_stat(&fscache_n_relinquishes_retire);
42750 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
42751
42752 if (!cookie) {
42753 - fscache_stat(&fscache_n_relinquishes_null);
42754 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
42755 _leave(" [no cookie]");
42756 return;
42757 }
42758 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
42759
42760 /* wait for the cookie to finish being instantiated (or to fail) */
42761 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
42762 - fscache_stat(&fscache_n_relinquishes_waitcrt);
42763 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
42764 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
42765 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
42766 }
42767 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
42768 index f6aad48..88dcf26 100644
42769 --- a/fs/fscache/internal.h
42770 +++ b/fs/fscache/internal.h
42771 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
42772 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
42773 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
42774
42775 -extern atomic_t fscache_n_op_pend;
42776 -extern atomic_t fscache_n_op_run;
42777 -extern atomic_t fscache_n_op_enqueue;
42778 -extern atomic_t fscache_n_op_deferred_release;
42779 -extern atomic_t fscache_n_op_release;
42780 -extern atomic_t fscache_n_op_gc;
42781 -extern atomic_t fscache_n_op_cancelled;
42782 -extern atomic_t fscache_n_op_rejected;
42783 +extern atomic_unchecked_t fscache_n_op_pend;
42784 +extern atomic_unchecked_t fscache_n_op_run;
42785 +extern atomic_unchecked_t fscache_n_op_enqueue;
42786 +extern atomic_unchecked_t fscache_n_op_deferred_release;
42787 +extern atomic_unchecked_t fscache_n_op_release;
42788 +extern atomic_unchecked_t fscache_n_op_gc;
42789 +extern atomic_unchecked_t fscache_n_op_cancelled;
42790 +extern atomic_unchecked_t fscache_n_op_rejected;
42791
42792 -extern atomic_t fscache_n_attr_changed;
42793 -extern atomic_t fscache_n_attr_changed_ok;
42794 -extern atomic_t fscache_n_attr_changed_nobufs;
42795 -extern atomic_t fscache_n_attr_changed_nomem;
42796 -extern atomic_t fscache_n_attr_changed_calls;
42797 +extern atomic_unchecked_t fscache_n_attr_changed;
42798 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
42799 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
42800 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
42801 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
42802
42803 -extern atomic_t fscache_n_allocs;
42804 -extern atomic_t fscache_n_allocs_ok;
42805 -extern atomic_t fscache_n_allocs_wait;
42806 -extern atomic_t fscache_n_allocs_nobufs;
42807 -extern atomic_t fscache_n_allocs_intr;
42808 -extern atomic_t fscache_n_allocs_object_dead;
42809 -extern atomic_t fscache_n_alloc_ops;
42810 -extern atomic_t fscache_n_alloc_op_waits;
42811 +extern atomic_unchecked_t fscache_n_allocs;
42812 +extern atomic_unchecked_t fscache_n_allocs_ok;
42813 +extern atomic_unchecked_t fscache_n_allocs_wait;
42814 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
42815 +extern atomic_unchecked_t fscache_n_allocs_intr;
42816 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
42817 +extern atomic_unchecked_t fscache_n_alloc_ops;
42818 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
42819
42820 -extern atomic_t fscache_n_retrievals;
42821 -extern atomic_t fscache_n_retrievals_ok;
42822 -extern atomic_t fscache_n_retrievals_wait;
42823 -extern atomic_t fscache_n_retrievals_nodata;
42824 -extern atomic_t fscache_n_retrievals_nobufs;
42825 -extern atomic_t fscache_n_retrievals_intr;
42826 -extern atomic_t fscache_n_retrievals_nomem;
42827 -extern atomic_t fscache_n_retrievals_object_dead;
42828 -extern atomic_t fscache_n_retrieval_ops;
42829 -extern atomic_t fscache_n_retrieval_op_waits;
42830 +extern atomic_unchecked_t fscache_n_retrievals;
42831 +extern atomic_unchecked_t fscache_n_retrievals_ok;
42832 +extern atomic_unchecked_t fscache_n_retrievals_wait;
42833 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
42834 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
42835 +extern atomic_unchecked_t fscache_n_retrievals_intr;
42836 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
42837 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
42838 +extern atomic_unchecked_t fscache_n_retrieval_ops;
42839 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
42840
42841 -extern atomic_t fscache_n_stores;
42842 -extern atomic_t fscache_n_stores_ok;
42843 -extern atomic_t fscache_n_stores_again;
42844 -extern atomic_t fscache_n_stores_nobufs;
42845 -extern atomic_t fscache_n_stores_oom;
42846 -extern atomic_t fscache_n_store_ops;
42847 -extern atomic_t fscache_n_store_calls;
42848 -extern atomic_t fscache_n_store_pages;
42849 -extern atomic_t fscache_n_store_radix_deletes;
42850 -extern atomic_t fscache_n_store_pages_over_limit;
42851 +extern atomic_unchecked_t fscache_n_stores;
42852 +extern atomic_unchecked_t fscache_n_stores_ok;
42853 +extern atomic_unchecked_t fscache_n_stores_again;
42854 +extern atomic_unchecked_t fscache_n_stores_nobufs;
42855 +extern atomic_unchecked_t fscache_n_stores_oom;
42856 +extern atomic_unchecked_t fscache_n_store_ops;
42857 +extern atomic_unchecked_t fscache_n_store_calls;
42858 +extern atomic_unchecked_t fscache_n_store_pages;
42859 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
42860 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
42861
42862 -extern atomic_t fscache_n_store_vmscan_not_storing;
42863 -extern atomic_t fscache_n_store_vmscan_gone;
42864 -extern atomic_t fscache_n_store_vmscan_busy;
42865 -extern atomic_t fscache_n_store_vmscan_cancelled;
42866 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
42867 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
42868 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
42869 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
42870
42871 -extern atomic_t fscache_n_marks;
42872 -extern atomic_t fscache_n_uncaches;
42873 +extern atomic_unchecked_t fscache_n_marks;
42874 +extern atomic_unchecked_t fscache_n_uncaches;
42875
42876 -extern atomic_t fscache_n_acquires;
42877 -extern atomic_t fscache_n_acquires_null;
42878 -extern atomic_t fscache_n_acquires_no_cache;
42879 -extern atomic_t fscache_n_acquires_ok;
42880 -extern atomic_t fscache_n_acquires_nobufs;
42881 -extern atomic_t fscache_n_acquires_oom;
42882 +extern atomic_unchecked_t fscache_n_acquires;
42883 +extern atomic_unchecked_t fscache_n_acquires_null;
42884 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
42885 +extern atomic_unchecked_t fscache_n_acquires_ok;
42886 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
42887 +extern atomic_unchecked_t fscache_n_acquires_oom;
42888
42889 -extern atomic_t fscache_n_updates;
42890 -extern atomic_t fscache_n_updates_null;
42891 -extern atomic_t fscache_n_updates_run;
42892 +extern atomic_unchecked_t fscache_n_updates;
42893 +extern atomic_unchecked_t fscache_n_updates_null;
42894 +extern atomic_unchecked_t fscache_n_updates_run;
42895
42896 -extern atomic_t fscache_n_relinquishes;
42897 -extern atomic_t fscache_n_relinquishes_null;
42898 -extern atomic_t fscache_n_relinquishes_waitcrt;
42899 -extern atomic_t fscache_n_relinquishes_retire;
42900 +extern atomic_unchecked_t fscache_n_relinquishes;
42901 +extern atomic_unchecked_t fscache_n_relinquishes_null;
42902 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
42903 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
42904
42905 -extern atomic_t fscache_n_cookie_index;
42906 -extern atomic_t fscache_n_cookie_data;
42907 -extern atomic_t fscache_n_cookie_special;
42908 +extern atomic_unchecked_t fscache_n_cookie_index;
42909 +extern atomic_unchecked_t fscache_n_cookie_data;
42910 +extern atomic_unchecked_t fscache_n_cookie_special;
42911
42912 -extern atomic_t fscache_n_object_alloc;
42913 -extern atomic_t fscache_n_object_no_alloc;
42914 -extern atomic_t fscache_n_object_lookups;
42915 -extern atomic_t fscache_n_object_lookups_negative;
42916 -extern atomic_t fscache_n_object_lookups_positive;
42917 -extern atomic_t fscache_n_object_lookups_timed_out;
42918 -extern atomic_t fscache_n_object_created;
42919 -extern atomic_t fscache_n_object_avail;
42920 -extern atomic_t fscache_n_object_dead;
42921 +extern atomic_unchecked_t fscache_n_object_alloc;
42922 +extern atomic_unchecked_t fscache_n_object_no_alloc;
42923 +extern atomic_unchecked_t fscache_n_object_lookups;
42924 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
42925 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
42926 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
42927 +extern atomic_unchecked_t fscache_n_object_created;
42928 +extern atomic_unchecked_t fscache_n_object_avail;
42929 +extern atomic_unchecked_t fscache_n_object_dead;
42930
42931 -extern atomic_t fscache_n_checkaux_none;
42932 -extern atomic_t fscache_n_checkaux_okay;
42933 -extern atomic_t fscache_n_checkaux_update;
42934 -extern atomic_t fscache_n_checkaux_obsolete;
42935 +extern atomic_unchecked_t fscache_n_checkaux_none;
42936 +extern atomic_unchecked_t fscache_n_checkaux_okay;
42937 +extern atomic_unchecked_t fscache_n_checkaux_update;
42938 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
42939
42940 extern atomic_t fscache_n_cop_alloc_object;
42941 extern atomic_t fscache_n_cop_lookup_object;
42942 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
42943 atomic_inc(stat);
42944 }
42945
42946 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
42947 +{
42948 + atomic_inc_unchecked(stat);
42949 +}
42950 +
42951 static inline void fscache_stat_d(atomic_t *stat)
42952 {
42953 atomic_dec(stat);
42954 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
42955
42956 #define __fscache_stat(stat) (NULL)
42957 #define fscache_stat(stat) do {} while (0)
42958 +#define fscache_stat_unchecked(stat) do {} while (0)
42959 #define fscache_stat_d(stat) do {} while (0)
42960 #endif
42961
42962 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
42963 index b6b897c..0ffff9c 100644
42964 --- a/fs/fscache/object.c
42965 +++ b/fs/fscache/object.c
42966 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
42967 /* update the object metadata on disk */
42968 case FSCACHE_OBJECT_UPDATING:
42969 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
42970 - fscache_stat(&fscache_n_updates_run);
42971 + fscache_stat_unchecked(&fscache_n_updates_run);
42972 fscache_stat(&fscache_n_cop_update_object);
42973 object->cache->ops->update_object(object);
42974 fscache_stat_d(&fscache_n_cop_update_object);
42975 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
42976 spin_lock(&object->lock);
42977 object->state = FSCACHE_OBJECT_DEAD;
42978 spin_unlock(&object->lock);
42979 - fscache_stat(&fscache_n_object_dead);
42980 + fscache_stat_unchecked(&fscache_n_object_dead);
42981 goto terminal_transit;
42982
42983 /* handle the parent cache of this object being withdrawn from
42984 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
42985 spin_lock(&object->lock);
42986 object->state = FSCACHE_OBJECT_DEAD;
42987 spin_unlock(&object->lock);
42988 - fscache_stat(&fscache_n_object_dead);
42989 + fscache_stat_unchecked(&fscache_n_object_dead);
42990 goto terminal_transit;
42991
42992 /* complain about the object being woken up once it is
42993 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
42994 parent->cookie->def->name, cookie->def->name,
42995 object->cache->tag->name);
42996
42997 - fscache_stat(&fscache_n_object_lookups);
42998 + fscache_stat_unchecked(&fscache_n_object_lookups);
42999 fscache_stat(&fscache_n_cop_lookup_object);
43000 ret = object->cache->ops->lookup_object(object);
43001 fscache_stat_d(&fscache_n_cop_lookup_object);
43002 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
43003 if (ret == -ETIMEDOUT) {
43004 /* probably stuck behind another object, so move this one to
43005 * the back of the queue */
43006 - fscache_stat(&fscache_n_object_lookups_timed_out);
43007 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
43008 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
43009 }
43010
43011 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
43012
43013 spin_lock(&object->lock);
43014 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
43015 - fscache_stat(&fscache_n_object_lookups_negative);
43016 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
43017
43018 /* transit here to allow write requests to begin stacking up
43019 * and read requests to begin returning ENODATA */
43020 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
43021 * result, in which case there may be data available */
43022 spin_lock(&object->lock);
43023 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
43024 - fscache_stat(&fscache_n_object_lookups_positive);
43025 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
43026
43027 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
43028
43029 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
43030 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
43031 } else {
43032 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
43033 - fscache_stat(&fscache_n_object_created);
43034 + fscache_stat_unchecked(&fscache_n_object_created);
43035
43036 object->state = FSCACHE_OBJECT_AVAILABLE;
43037 spin_unlock(&object->lock);
43038 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
43039 fscache_enqueue_dependents(object);
43040
43041 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
43042 - fscache_stat(&fscache_n_object_avail);
43043 + fscache_stat_unchecked(&fscache_n_object_avail);
43044
43045 _leave("");
43046 }
43047 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
43048 enum fscache_checkaux result;
43049
43050 if (!object->cookie->def->check_aux) {
43051 - fscache_stat(&fscache_n_checkaux_none);
43052 + fscache_stat_unchecked(&fscache_n_checkaux_none);
43053 return FSCACHE_CHECKAUX_OKAY;
43054 }
43055
43056 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
43057 switch (result) {
43058 /* entry okay as is */
43059 case FSCACHE_CHECKAUX_OKAY:
43060 - fscache_stat(&fscache_n_checkaux_okay);
43061 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
43062 break;
43063
43064 /* entry requires update */
43065 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
43066 - fscache_stat(&fscache_n_checkaux_update);
43067 + fscache_stat_unchecked(&fscache_n_checkaux_update);
43068 break;
43069
43070 /* entry requires deletion */
43071 case FSCACHE_CHECKAUX_OBSOLETE:
43072 - fscache_stat(&fscache_n_checkaux_obsolete);
43073 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
43074 break;
43075
43076 default:
43077 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
43078 index 30afdfa..2256596 100644
43079 --- a/fs/fscache/operation.c
43080 +++ b/fs/fscache/operation.c
43081 @@ -17,7 +17,7 @@
43082 #include <linux/slab.h>
43083 #include "internal.h"
43084
43085 -atomic_t fscache_op_debug_id;
43086 +atomic_unchecked_t fscache_op_debug_id;
43087 EXPORT_SYMBOL(fscache_op_debug_id);
43088
43089 /**
43090 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
43091 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
43092 ASSERTCMP(atomic_read(&op->usage), >, 0);
43093
43094 - fscache_stat(&fscache_n_op_enqueue);
43095 + fscache_stat_unchecked(&fscache_n_op_enqueue);
43096 switch (op->flags & FSCACHE_OP_TYPE) {
43097 case FSCACHE_OP_ASYNC:
43098 _debug("queue async");
43099 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
43100 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
43101 if (op->processor)
43102 fscache_enqueue_operation(op);
43103 - fscache_stat(&fscache_n_op_run);
43104 + fscache_stat_unchecked(&fscache_n_op_run);
43105 }
43106
43107 /*
43108 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
43109 if (object->n_ops > 1) {
43110 atomic_inc(&op->usage);
43111 list_add_tail(&op->pend_link, &object->pending_ops);
43112 - fscache_stat(&fscache_n_op_pend);
43113 + fscache_stat_unchecked(&fscache_n_op_pend);
43114 } else if (!list_empty(&object->pending_ops)) {
43115 atomic_inc(&op->usage);
43116 list_add_tail(&op->pend_link, &object->pending_ops);
43117 - fscache_stat(&fscache_n_op_pend);
43118 + fscache_stat_unchecked(&fscache_n_op_pend);
43119 fscache_start_operations(object);
43120 } else {
43121 ASSERTCMP(object->n_in_progress, ==, 0);
43122 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
43123 object->n_exclusive++; /* reads and writes must wait */
43124 atomic_inc(&op->usage);
43125 list_add_tail(&op->pend_link, &object->pending_ops);
43126 - fscache_stat(&fscache_n_op_pend);
43127 + fscache_stat_unchecked(&fscache_n_op_pend);
43128 ret = 0;
43129 } else {
43130 /* not allowed to submit ops in any other state */
43131 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
43132 if (object->n_exclusive > 0) {
43133 atomic_inc(&op->usage);
43134 list_add_tail(&op->pend_link, &object->pending_ops);
43135 - fscache_stat(&fscache_n_op_pend);
43136 + fscache_stat_unchecked(&fscache_n_op_pend);
43137 } else if (!list_empty(&object->pending_ops)) {
43138 atomic_inc(&op->usage);
43139 list_add_tail(&op->pend_link, &object->pending_ops);
43140 - fscache_stat(&fscache_n_op_pend);
43141 + fscache_stat_unchecked(&fscache_n_op_pend);
43142 fscache_start_operations(object);
43143 } else {
43144 ASSERTCMP(object->n_exclusive, ==, 0);
43145 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
43146 object->n_ops++;
43147 atomic_inc(&op->usage);
43148 list_add_tail(&op->pend_link, &object->pending_ops);
43149 - fscache_stat(&fscache_n_op_pend);
43150 + fscache_stat_unchecked(&fscache_n_op_pend);
43151 ret = 0;
43152 } else if (object->state == FSCACHE_OBJECT_DYING ||
43153 object->state == FSCACHE_OBJECT_LC_DYING ||
43154 object->state == FSCACHE_OBJECT_WITHDRAWING) {
43155 - fscache_stat(&fscache_n_op_rejected);
43156 + fscache_stat_unchecked(&fscache_n_op_rejected);
43157 ret = -ENOBUFS;
43158 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
43159 fscache_report_unexpected_submission(object, op, ostate);
43160 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
43161
43162 ret = -EBUSY;
43163 if (!list_empty(&op->pend_link)) {
43164 - fscache_stat(&fscache_n_op_cancelled);
43165 + fscache_stat_unchecked(&fscache_n_op_cancelled);
43166 list_del_init(&op->pend_link);
43167 object->n_ops--;
43168 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
43169 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
43170 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
43171 BUG();
43172
43173 - fscache_stat(&fscache_n_op_release);
43174 + fscache_stat_unchecked(&fscache_n_op_release);
43175
43176 if (op->release) {
43177 op->release(op);
43178 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
43179 * lock, and defer it otherwise */
43180 if (!spin_trylock(&object->lock)) {
43181 _debug("defer put");
43182 - fscache_stat(&fscache_n_op_deferred_release);
43183 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
43184
43185 cache = object->cache;
43186 spin_lock(&cache->op_gc_list_lock);
43187 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
43188
43189 _debug("GC DEFERRED REL OBJ%x OP%x",
43190 object->debug_id, op->debug_id);
43191 - fscache_stat(&fscache_n_op_gc);
43192 + fscache_stat_unchecked(&fscache_n_op_gc);
43193
43194 ASSERTCMP(atomic_read(&op->usage), ==, 0);
43195
43196 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
43197 index 3f7a59b..cf196cc 100644
43198 --- a/fs/fscache/page.c
43199 +++ b/fs/fscache/page.c
43200 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
43201 val = radix_tree_lookup(&cookie->stores, page->index);
43202 if (!val) {
43203 rcu_read_unlock();
43204 - fscache_stat(&fscache_n_store_vmscan_not_storing);
43205 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
43206 __fscache_uncache_page(cookie, page);
43207 return true;
43208 }
43209 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
43210 spin_unlock(&cookie->stores_lock);
43211
43212 if (xpage) {
43213 - fscache_stat(&fscache_n_store_vmscan_cancelled);
43214 - fscache_stat(&fscache_n_store_radix_deletes);
43215 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
43216 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
43217 ASSERTCMP(xpage, ==, page);
43218 } else {
43219 - fscache_stat(&fscache_n_store_vmscan_gone);
43220 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
43221 }
43222
43223 wake_up_bit(&cookie->flags, 0);
43224 @@ -107,7 +107,7 @@ page_busy:
43225 /* we might want to wait here, but that could deadlock the allocator as
43226 * the work threads writing to the cache may all end up sleeping
43227 * on memory allocation */
43228 - fscache_stat(&fscache_n_store_vmscan_busy);
43229 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
43230 return false;
43231 }
43232 EXPORT_SYMBOL(__fscache_maybe_release_page);
43233 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
43234 FSCACHE_COOKIE_STORING_TAG);
43235 if (!radix_tree_tag_get(&cookie->stores, page->index,
43236 FSCACHE_COOKIE_PENDING_TAG)) {
43237 - fscache_stat(&fscache_n_store_radix_deletes);
43238 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
43239 xpage = radix_tree_delete(&cookie->stores, page->index);
43240 }
43241 spin_unlock(&cookie->stores_lock);
43242 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
43243
43244 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
43245
43246 - fscache_stat(&fscache_n_attr_changed_calls);
43247 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
43248
43249 if (fscache_object_is_active(object)) {
43250 fscache_stat(&fscache_n_cop_attr_changed);
43251 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43252
43253 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43254
43255 - fscache_stat(&fscache_n_attr_changed);
43256 + fscache_stat_unchecked(&fscache_n_attr_changed);
43257
43258 op = kzalloc(sizeof(*op), GFP_KERNEL);
43259 if (!op) {
43260 - fscache_stat(&fscache_n_attr_changed_nomem);
43261 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
43262 _leave(" = -ENOMEM");
43263 return -ENOMEM;
43264 }
43265 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43266 if (fscache_submit_exclusive_op(object, op) < 0)
43267 goto nobufs;
43268 spin_unlock(&cookie->lock);
43269 - fscache_stat(&fscache_n_attr_changed_ok);
43270 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
43271 fscache_put_operation(op);
43272 _leave(" = 0");
43273 return 0;
43274 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43275 nobufs:
43276 spin_unlock(&cookie->lock);
43277 kfree(op);
43278 - fscache_stat(&fscache_n_attr_changed_nobufs);
43279 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
43280 _leave(" = %d", -ENOBUFS);
43281 return -ENOBUFS;
43282 }
43283 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
43284 /* allocate a retrieval operation and attempt to submit it */
43285 op = kzalloc(sizeof(*op), GFP_NOIO);
43286 if (!op) {
43287 - fscache_stat(&fscache_n_retrievals_nomem);
43288 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43289 return NULL;
43290 }
43291
43292 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
43293 return 0;
43294 }
43295
43296 - fscache_stat(&fscache_n_retrievals_wait);
43297 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
43298
43299 jif = jiffies;
43300 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
43301 fscache_wait_bit_interruptible,
43302 TASK_INTERRUPTIBLE) != 0) {
43303 - fscache_stat(&fscache_n_retrievals_intr);
43304 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43305 _leave(" = -ERESTARTSYS");
43306 return -ERESTARTSYS;
43307 }
43308 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
43309 */
43310 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43311 struct fscache_retrieval *op,
43312 - atomic_t *stat_op_waits,
43313 - atomic_t *stat_object_dead)
43314 + atomic_unchecked_t *stat_op_waits,
43315 + atomic_unchecked_t *stat_object_dead)
43316 {
43317 int ret;
43318
43319 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43320 goto check_if_dead;
43321
43322 _debug(">>> WT");
43323 - fscache_stat(stat_op_waits);
43324 + fscache_stat_unchecked(stat_op_waits);
43325 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
43326 fscache_wait_bit_interruptible,
43327 TASK_INTERRUPTIBLE) < 0) {
43328 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43329
43330 check_if_dead:
43331 if (unlikely(fscache_object_is_dead(object))) {
43332 - fscache_stat(stat_object_dead);
43333 + fscache_stat_unchecked(stat_object_dead);
43334 return -ENOBUFS;
43335 }
43336 return 0;
43337 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43338
43339 _enter("%p,%p,,,", cookie, page);
43340
43341 - fscache_stat(&fscache_n_retrievals);
43342 + fscache_stat_unchecked(&fscache_n_retrievals);
43343
43344 if (hlist_empty(&cookie->backing_objects))
43345 goto nobufs;
43346 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43347 goto nobufs_unlock;
43348 spin_unlock(&cookie->lock);
43349
43350 - fscache_stat(&fscache_n_retrieval_ops);
43351 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
43352
43353 /* pin the netfs read context in case we need to do the actual netfs
43354 * read because we've encountered a cache read failure */
43355 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43356
43357 error:
43358 if (ret == -ENOMEM)
43359 - fscache_stat(&fscache_n_retrievals_nomem);
43360 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43361 else if (ret == -ERESTARTSYS)
43362 - fscache_stat(&fscache_n_retrievals_intr);
43363 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43364 else if (ret == -ENODATA)
43365 - fscache_stat(&fscache_n_retrievals_nodata);
43366 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
43367 else if (ret < 0)
43368 - fscache_stat(&fscache_n_retrievals_nobufs);
43369 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43370 else
43371 - fscache_stat(&fscache_n_retrievals_ok);
43372 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
43373
43374 fscache_put_retrieval(op);
43375 _leave(" = %d", ret);
43376 @@ -429,7 +429,7 @@ nobufs_unlock:
43377 spin_unlock(&cookie->lock);
43378 kfree(op);
43379 nobufs:
43380 - fscache_stat(&fscache_n_retrievals_nobufs);
43381 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43382 _leave(" = -ENOBUFS");
43383 return -ENOBUFS;
43384 }
43385 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43386
43387 _enter("%p,,%d,,,", cookie, *nr_pages);
43388
43389 - fscache_stat(&fscache_n_retrievals);
43390 + fscache_stat_unchecked(&fscache_n_retrievals);
43391
43392 if (hlist_empty(&cookie->backing_objects))
43393 goto nobufs;
43394 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43395 goto nobufs_unlock;
43396 spin_unlock(&cookie->lock);
43397
43398 - fscache_stat(&fscache_n_retrieval_ops);
43399 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
43400
43401 /* pin the netfs read context in case we need to do the actual netfs
43402 * read because we've encountered a cache read failure */
43403 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43404
43405 error:
43406 if (ret == -ENOMEM)
43407 - fscache_stat(&fscache_n_retrievals_nomem);
43408 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43409 else if (ret == -ERESTARTSYS)
43410 - fscache_stat(&fscache_n_retrievals_intr);
43411 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43412 else if (ret == -ENODATA)
43413 - fscache_stat(&fscache_n_retrievals_nodata);
43414 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
43415 else if (ret < 0)
43416 - fscache_stat(&fscache_n_retrievals_nobufs);
43417 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43418 else
43419 - fscache_stat(&fscache_n_retrievals_ok);
43420 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
43421
43422 fscache_put_retrieval(op);
43423 _leave(" = %d", ret);
43424 @@ -545,7 +545,7 @@ nobufs_unlock:
43425 spin_unlock(&cookie->lock);
43426 kfree(op);
43427 nobufs:
43428 - fscache_stat(&fscache_n_retrievals_nobufs);
43429 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43430 _leave(" = -ENOBUFS");
43431 return -ENOBUFS;
43432 }
43433 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43434
43435 _enter("%p,%p,,,", cookie, page);
43436
43437 - fscache_stat(&fscache_n_allocs);
43438 + fscache_stat_unchecked(&fscache_n_allocs);
43439
43440 if (hlist_empty(&cookie->backing_objects))
43441 goto nobufs;
43442 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43443 goto nobufs_unlock;
43444 spin_unlock(&cookie->lock);
43445
43446 - fscache_stat(&fscache_n_alloc_ops);
43447 + fscache_stat_unchecked(&fscache_n_alloc_ops);
43448
43449 ret = fscache_wait_for_retrieval_activation(
43450 object, op,
43451 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43452
43453 error:
43454 if (ret == -ERESTARTSYS)
43455 - fscache_stat(&fscache_n_allocs_intr);
43456 + fscache_stat_unchecked(&fscache_n_allocs_intr);
43457 else if (ret < 0)
43458 - fscache_stat(&fscache_n_allocs_nobufs);
43459 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
43460 else
43461 - fscache_stat(&fscache_n_allocs_ok);
43462 + fscache_stat_unchecked(&fscache_n_allocs_ok);
43463
43464 fscache_put_retrieval(op);
43465 _leave(" = %d", ret);
43466 @@ -625,7 +625,7 @@ nobufs_unlock:
43467 spin_unlock(&cookie->lock);
43468 kfree(op);
43469 nobufs:
43470 - fscache_stat(&fscache_n_allocs_nobufs);
43471 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
43472 _leave(" = -ENOBUFS");
43473 return -ENOBUFS;
43474 }
43475 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43476
43477 spin_lock(&cookie->stores_lock);
43478
43479 - fscache_stat(&fscache_n_store_calls);
43480 + fscache_stat_unchecked(&fscache_n_store_calls);
43481
43482 /* find a page to store */
43483 page = NULL;
43484 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43485 page = results[0];
43486 _debug("gang %d [%lx]", n, page->index);
43487 if (page->index > op->store_limit) {
43488 - fscache_stat(&fscache_n_store_pages_over_limit);
43489 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
43490 goto superseded;
43491 }
43492
43493 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43494 spin_unlock(&cookie->stores_lock);
43495 spin_unlock(&object->lock);
43496
43497 - fscache_stat(&fscache_n_store_pages);
43498 + fscache_stat_unchecked(&fscache_n_store_pages);
43499 fscache_stat(&fscache_n_cop_write_page);
43500 ret = object->cache->ops->write_page(op, page);
43501 fscache_stat_d(&fscache_n_cop_write_page);
43502 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43503 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43504 ASSERT(PageFsCache(page));
43505
43506 - fscache_stat(&fscache_n_stores);
43507 + fscache_stat_unchecked(&fscache_n_stores);
43508
43509 op = kzalloc(sizeof(*op), GFP_NOIO);
43510 if (!op)
43511 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43512 spin_unlock(&cookie->stores_lock);
43513 spin_unlock(&object->lock);
43514
43515 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
43516 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
43517 op->store_limit = object->store_limit;
43518
43519 if (fscache_submit_op(object, &op->op) < 0)
43520 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43521
43522 spin_unlock(&cookie->lock);
43523 radix_tree_preload_end();
43524 - fscache_stat(&fscache_n_store_ops);
43525 - fscache_stat(&fscache_n_stores_ok);
43526 + fscache_stat_unchecked(&fscache_n_store_ops);
43527 + fscache_stat_unchecked(&fscache_n_stores_ok);
43528
43529 /* the work queue now carries its own ref on the object */
43530 fscache_put_operation(&op->op);
43531 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43532 return 0;
43533
43534 already_queued:
43535 - fscache_stat(&fscache_n_stores_again);
43536 + fscache_stat_unchecked(&fscache_n_stores_again);
43537 already_pending:
43538 spin_unlock(&cookie->stores_lock);
43539 spin_unlock(&object->lock);
43540 spin_unlock(&cookie->lock);
43541 radix_tree_preload_end();
43542 kfree(op);
43543 - fscache_stat(&fscache_n_stores_ok);
43544 + fscache_stat_unchecked(&fscache_n_stores_ok);
43545 _leave(" = 0");
43546 return 0;
43547
43548 @@ -851,14 +851,14 @@ nobufs:
43549 spin_unlock(&cookie->lock);
43550 radix_tree_preload_end();
43551 kfree(op);
43552 - fscache_stat(&fscache_n_stores_nobufs);
43553 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
43554 _leave(" = -ENOBUFS");
43555 return -ENOBUFS;
43556
43557 nomem_free:
43558 kfree(op);
43559 nomem:
43560 - fscache_stat(&fscache_n_stores_oom);
43561 + fscache_stat_unchecked(&fscache_n_stores_oom);
43562 _leave(" = -ENOMEM");
43563 return -ENOMEM;
43564 }
43565 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
43566 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43567 ASSERTCMP(page, !=, NULL);
43568
43569 - fscache_stat(&fscache_n_uncaches);
43570 + fscache_stat_unchecked(&fscache_n_uncaches);
43571
43572 /* cache withdrawal may beat us to it */
43573 if (!PageFsCache(page))
43574 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
43575 unsigned long loop;
43576
43577 #ifdef CONFIG_FSCACHE_STATS
43578 - atomic_add(pagevec->nr, &fscache_n_marks);
43579 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
43580 #endif
43581
43582 for (loop = 0; loop < pagevec->nr; loop++) {
43583 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
43584 index 4765190..2a067f2 100644
43585 --- a/fs/fscache/stats.c
43586 +++ b/fs/fscache/stats.c
43587 @@ -18,95 +18,95 @@
43588 /*
43589 * operation counters
43590 */
43591 -atomic_t fscache_n_op_pend;
43592 -atomic_t fscache_n_op_run;
43593 -atomic_t fscache_n_op_enqueue;
43594 -atomic_t fscache_n_op_requeue;
43595 -atomic_t fscache_n_op_deferred_release;
43596 -atomic_t fscache_n_op_release;
43597 -atomic_t fscache_n_op_gc;
43598 -atomic_t fscache_n_op_cancelled;
43599 -atomic_t fscache_n_op_rejected;
43600 +atomic_unchecked_t fscache_n_op_pend;
43601 +atomic_unchecked_t fscache_n_op_run;
43602 +atomic_unchecked_t fscache_n_op_enqueue;
43603 +atomic_unchecked_t fscache_n_op_requeue;
43604 +atomic_unchecked_t fscache_n_op_deferred_release;
43605 +atomic_unchecked_t fscache_n_op_release;
43606 +atomic_unchecked_t fscache_n_op_gc;
43607 +atomic_unchecked_t fscache_n_op_cancelled;
43608 +atomic_unchecked_t fscache_n_op_rejected;
43609
43610 -atomic_t fscache_n_attr_changed;
43611 -atomic_t fscache_n_attr_changed_ok;
43612 -atomic_t fscache_n_attr_changed_nobufs;
43613 -atomic_t fscache_n_attr_changed_nomem;
43614 -atomic_t fscache_n_attr_changed_calls;
43615 +atomic_unchecked_t fscache_n_attr_changed;
43616 +atomic_unchecked_t fscache_n_attr_changed_ok;
43617 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
43618 +atomic_unchecked_t fscache_n_attr_changed_nomem;
43619 +atomic_unchecked_t fscache_n_attr_changed_calls;
43620
43621 -atomic_t fscache_n_allocs;
43622 -atomic_t fscache_n_allocs_ok;
43623 -atomic_t fscache_n_allocs_wait;
43624 -atomic_t fscache_n_allocs_nobufs;
43625 -atomic_t fscache_n_allocs_intr;
43626 -atomic_t fscache_n_allocs_object_dead;
43627 -atomic_t fscache_n_alloc_ops;
43628 -atomic_t fscache_n_alloc_op_waits;
43629 +atomic_unchecked_t fscache_n_allocs;
43630 +atomic_unchecked_t fscache_n_allocs_ok;
43631 +atomic_unchecked_t fscache_n_allocs_wait;
43632 +atomic_unchecked_t fscache_n_allocs_nobufs;
43633 +atomic_unchecked_t fscache_n_allocs_intr;
43634 +atomic_unchecked_t fscache_n_allocs_object_dead;
43635 +atomic_unchecked_t fscache_n_alloc_ops;
43636 +atomic_unchecked_t fscache_n_alloc_op_waits;
43637
43638 -atomic_t fscache_n_retrievals;
43639 -atomic_t fscache_n_retrievals_ok;
43640 -atomic_t fscache_n_retrievals_wait;
43641 -atomic_t fscache_n_retrievals_nodata;
43642 -atomic_t fscache_n_retrievals_nobufs;
43643 -atomic_t fscache_n_retrievals_intr;
43644 -atomic_t fscache_n_retrievals_nomem;
43645 -atomic_t fscache_n_retrievals_object_dead;
43646 -atomic_t fscache_n_retrieval_ops;
43647 -atomic_t fscache_n_retrieval_op_waits;
43648 +atomic_unchecked_t fscache_n_retrievals;
43649 +atomic_unchecked_t fscache_n_retrievals_ok;
43650 +atomic_unchecked_t fscache_n_retrievals_wait;
43651 +atomic_unchecked_t fscache_n_retrievals_nodata;
43652 +atomic_unchecked_t fscache_n_retrievals_nobufs;
43653 +atomic_unchecked_t fscache_n_retrievals_intr;
43654 +atomic_unchecked_t fscache_n_retrievals_nomem;
43655 +atomic_unchecked_t fscache_n_retrievals_object_dead;
43656 +atomic_unchecked_t fscache_n_retrieval_ops;
43657 +atomic_unchecked_t fscache_n_retrieval_op_waits;
43658
43659 -atomic_t fscache_n_stores;
43660 -atomic_t fscache_n_stores_ok;
43661 -atomic_t fscache_n_stores_again;
43662 -atomic_t fscache_n_stores_nobufs;
43663 -atomic_t fscache_n_stores_oom;
43664 -atomic_t fscache_n_store_ops;
43665 -atomic_t fscache_n_store_calls;
43666 -atomic_t fscache_n_store_pages;
43667 -atomic_t fscache_n_store_radix_deletes;
43668 -atomic_t fscache_n_store_pages_over_limit;
43669 +atomic_unchecked_t fscache_n_stores;
43670 +atomic_unchecked_t fscache_n_stores_ok;
43671 +atomic_unchecked_t fscache_n_stores_again;
43672 +atomic_unchecked_t fscache_n_stores_nobufs;
43673 +atomic_unchecked_t fscache_n_stores_oom;
43674 +atomic_unchecked_t fscache_n_store_ops;
43675 +atomic_unchecked_t fscache_n_store_calls;
43676 +atomic_unchecked_t fscache_n_store_pages;
43677 +atomic_unchecked_t fscache_n_store_radix_deletes;
43678 +atomic_unchecked_t fscache_n_store_pages_over_limit;
43679
43680 -atomic_t fscache_n_store_vmscan_not_storing;
43681 -atomic_t fscache_n_store_vmscan_gone;
43682 -atomic_t fscache_n_store_vmscan_busy;
43683 -atomic_t fscache_n_store_vmscan_cancelled;
43684 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
43685 +atomic_unchecked_t fscache_n_store_vmscan_gone;
43686 +atomic_unchecked_t fscache_n_store_vmscan_busy;
43687 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
43688
43689 -atomic_t fscache_n_marks;
43690 -atomic_t fscache_n_uncaches;
43691 +atomic_unchecked_t fscache_n_marks;
43692 +atomic_unchecked_t fscache_n_uncaches;
43693
43694 -atomic_t fscache_n_acquires;
43695 -atomic_t fscache_n_acquires_null;
43696 -atomic_t fscache_n_acquires_no_cache;
43697 -atomic_t fscache_n_acquires_ok;
43698 -atomic_t fscache_n_acquires_nobufs;
43699 -atomic_t fscache_n_acquires_oom;
43700 +atomic_unchecked_t fscache_n_acquires;
43701 +atomic_unchecked_t fscache_n_acquires_null;
43702 +atomic_unchecked_t fscache_n_acquires_no_cache;
43703 +atomic_unchecked_t fscache_n_acquires_ok;
43704 +atomic_unchecked_t fscache_n_acquires_nobufs;
43705 +atomic_unchecked_t fscache_n_acquires_oom;
43706
43707 -atomic_t fscache_n_updates;
43708 -atomic_t fscache_n_updates_null;
43709 -atomic_t fscache_n_updates_run;
43710 +atomic_unchecked_t fscache_n_updates;
43711 +atomic_unchecked_t fscache_n_updates_null;
43712 +atomic_unchecked_t fscache_n_updates_run;
43713
43714 -atomic_t fscache_n_relinquishes;
43715 -atomic_t fscache_n_relinquishes_null;
43716 -atomic_t fscache_n_relinquishes_waitcrt;
43717 -atomic_t fscache_n_relinquishes_retire;
43718 +atomic_unchecked_t fscache_n_relinquishes;
43719 +atomic_unchecked_t fscache_n_relinquishes_null;
43720 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
43721 +atomic_unchecked_t fscache_n_relinquishes_retire;
43722
43723 -atomic_t fscache_n_cookie_index;
43724 -atomic_t fscache_n_cookie_data;
43725 -atomic_t fscache_n_cookie_special;
43726 +atomic_unchecked_t fscache_n_cookie_index;
43727 +atomic_unchecked_t fscache_n_cookie_data;
43728 +atomic_unchecked_t fscache_n_cookie_special;
43729
43730 -atomic_t fscache_n_object_alloc;
43731 -atomic_t fscache_n_object_no_alloc;
43732 -atomic_t fscache_n_object_lookups;
43733 -atomic_t fscache_n_object_lookups_negative;
43734 -atomic_t fscache_n_object_lookups_positive;
43735 -atomic_t fscache_n_object_lookups_timed_out;
43736 -atomic_t fscache_n_object_created;
43737 -atomic_t fscache_n_object_avail;
43738 -atomic_t fscache_n_object_dead;
43739 +atomic_unchecked_t fscache_n_object_alloc;
43740 +atomic_unchecked_t fscache_n_object_no_alloc;
43741 +atomic_unchecked_t fscache_n_object_lookups;
43742 +atomic_unchecked_t fscache_n_object_lookups_negative;
43743 +atomic_unchecked_t fscache_n_object_lookups_positive;
43744 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
43745 +atomic_unchecked_t fscache_n_object_created;
43746 +atomic_unchecked_t fscache_n_object_avail;
43747 +atomic_unchecked_t fscache_n_object_dead;
43748
43749 -atomic_t fscache_n_checkaux_none;
43750 -atomic_t fscache_n_checkaux_okay;
43751 -atomic_t fscache_n_checkaux_update;
43752 -atomic_t fscache_n_checkaux_obsolete;
43753 +atomic_unchecked_t fscache_n_checkaux_none;
43754 +atomic_unchecked_t fscache_n_checkaux_okay;
43755 +atomic_unchecked_t fscache_n_checkaux_update;
43756 +atomic_unchecked_t fscache_n_checkaux_obsolete;
43757
43758 atomic_t fscache_n_cop_alloc_object;
43759 atomic_t fscache_n_cop_lookup_object;
43760 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
43761 seq_puts(m, "FS-Cache statistics\n");
43762
43763 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
43764 - atomic_read(&fscache_n_cookie_index),
43765 - atomic_read(&fscache_n_cookie_data),
43766 - atomic_read(&fscache_n_cookie_special));
43767 + atomic_read_unchecked(&fscache_n_cookie_index),
43768 + atomic_read_unchecked(&fscache_n_cookie_data),
43769 + atomic_read_unchecked(&fscache_n_cookie_special));
43770
43771 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
43772 - atomic_read(&fscache_n_object_alloc),
43773 - atomic_read(&fscache_n_object_no_alloc),
43774 - atomic_read(&fscache_n_object_avail),
43775 - atomic_read(&fscache_n_object_dead));
43776 + atomic_read_unchecked(&fscache_n_object_alloc),
43777 + atomic_read_unchecked(&fscache_n_object_no_alloc),
43778 + atomic_read_unchecked(&fscache_n_object_avail),
43779 + atomic_read_unchecked(&fscache_n_object_dead));
43780 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
43781 - atomic_read(&fscache_n_checkaux_none),
43782 - atomic_read(&fscache_n_checkaux_okay),
43783 - atomic_read(&fscache_n_checkaux_update),
43784 - atomic_read(&fscache_n_checkaux_obsolete));
43785 + atomic_read_unchecked(&fscache_n_checkaux_none),
43786 + atomic_read_unchecked(&fscache_n_checkaux_okay),
43787 + atomic_read_unchecked(&fscache_n_checkaux_update),
43788 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
43789
43790 seq_printf(m, "Pages : mrk=%u unc=%u\n",
43791 - atomic_read(&fscache_n_marks),
43792 - atomic_read(&fscache_n_uncaches));
43793 + atomic_read_unchecked(&fscache_n_marks),
43794 + atomic_read_unchecked(&fscache_n_uncaches));
43795
43796 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
43797 " oom=%u\n",
43798 - atomic_read(&fscache_n_acquires),
43799 - atomic_read(&fscache_n_acquires_null),
43800 - atomic_read(&fscache_n_acquires_no_cache),
43801 - atomic_read(&fscache_n_acquires_ok),
43802 - atomic_read(&fscache_n_acquires_nobufs),
43803 - atomic_read(&fscache_n_acquires_oom));
43804 + atomic_read_unchecked(&fscache_n_acquires),
43805 + atomic_read_unchecked(&fscache_n_acquires_null),
43806 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
43807 + atomic_read_unchecked(&fscache_n_acquires_ok),
43808 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
43809 + atomic_read_unchecked(&fscache_n_acquires_oom));
43810
43811 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
43812 - atomic_read(&fscache_n_object_lookups),
43813 - atomic_read(&fscache_n_object_lookups_negative),
43814 - atomic_read(&fscache_n_object_lookups_positive),
43815 - atomic_read(&fscache_n_object_created),
43816 - atomic_read(&fscache_n_object_lookups_timed_out));
43817 + atomic_read_unchecked(&fscache_n_object_lookups),
43818 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
43819 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
43820 + atomic_read_unchecked(&fscache_n_object_created),
43821 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
43822
43823 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
43824 - atomic_read(&fscache_n_updates),
43825 - atomic_read(&fscache_n_updates_null),
43826 - atomic_read(&fscache_n_updates_run));
43827 + atomic_read_unchecked(&fscache_n_updates),
43828 + atomic_read_unchecked(&fscache_n_updates_null),
43829 + atomic_read_unchecked(&fscache_n_updates_run));
43830
43831 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
43832 - atomic_read(&fscache_n_relinquishes),
43833 - atomic_read(&fscache_n_relinquishes_null),
43834 - atomic_read(&fscache_n_relinquishes_waitcrt),
43835 - atomic_read(&fscache_n_relinquishes_retire));
43836 + atomic_read_unchecked(&fscache_n_relinquishes),
43837 + atomic_read_unchecked(&fscache_n_relinquishes_null),
43838 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
43839 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
43840
43841 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
43842 - atomic_read(&fscache_n_attr_changed),
43843 - atomic_read(&fscache_n_attr_changed_ok),
43844 - atomic_read(&fscache_n_attr_changed_nobufs),
43845 - atomic_read(&fscache_n_attr_changed_nomem),
43846 - atomic_read(&fscache_n_attr_changed_calls));
43847 + atomic_read_unchecked(&fscache_n_attr_changed),
43848 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
43849 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
43850 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
43851 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
43852
43853 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
43854 - atomic_read(&fscache_n_allocs),
43855 - atomic_read(&fscache_n_allocs_ok),
43856 - atomic_read(&fscache_n_allocs_wait),
43857 - atomic_read(&fscache_n_allocs_nobufs),
43858 - atomic_read(&fscache_n_allocs_intr));
43859 + atomic_read_unchecked(&fscache_n_allocs),
43860 + atomic_read_unchecked(&fscache_n_allocs_ok),
43861 + atomic_read_unchecked(&fscache_n_allocs_wait),
43862 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
43863 + atomic_read_unchecked(&fscache_n_allocs_intr));
43864 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
43865 - atomic_read(&fscache_n_alloc_ops),
43866 - atomic_read(&fscache_n_alloc_op_waits),
43867 - atomic_read(&fscache_n_allocs_object_dead));
43868 + atomic_read_unchecked(&fscache_n_alloc_ops),
43869 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
43870 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
43871
43872 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
43873 " int=%u oom=%u\n",
43874 - atomic_read(&fscache_n_retrievals),
43875 - atomic_read(&fscache_n_retrievals_ok),
43876 - atomic_read(&fscache_n_retrievals_wait),
43877 - atomic_read(&fscache_n_retrievals_nodata),
43878 - atomic_read(&fscache_n_retrievals_nobufs),
43879 - atomic_read(&fscache_n_retrievals_intr),
43880 - atomic_read(&fscache_n_retrievals_nomem));
43881 + atomic_read_unchecked(&fscache_n_retrievals),
43882 + atomic_read_unchecked(&fscache_n_retrievals_ok),
43883 + atomic_read_unchecked(&fscache_n_retrievals_wait),
43884 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
43885 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
43886 + atomic_read_unchecked(&fscache_n_retrievals_intr),
43887 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
43888 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
43889 - atomic_read(&fscache_n_retrieval_ops),
43890 - atomic_read(&fscache_n_retrieval_op_waits),
43891 - atomic_read(&fscache_n_retrievals_object_dead));
43892 + atomic_read_unchecked(&fscache_n_retrieval_ops),
43893 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
43894 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
43895
43896 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
43897 - atomic_read(&fscache_n_stores),
43898 - atomic_read(&fscache_n_stores_ok),
43899 - atomic_read(&fscache_n_stores_again),
43900 - atomic_read(&fscache_n_stores_nobufs),
43901 - atomic_read(&fscache_n_stores_oom));
43902 + atomic_read_unchecked(&fscache_n_stores),
43903 + atomic_read_unchecked(&fscache_n_stores_ok),
43904 + atomic_read_unchecked(&fscache_n_stores_again),
43905 + atomic_read_unchecked(&fscache_n_stores_nobufs),
43906 + atomic_read_unchecked(&fscache_n_stores_oom));
43907 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
43908 - atomic_read(&fscache_n_store_ops),
43909 - atomic_read(&fscache_n_store_calls),
43910 - atomic_read(&fscache_n_store_pages),
43911 - atomic_read(&fscache_n_store_radix_deletes),
43912 - atomic_read(&fscache_n_store_pages_over_limit));
43913 + atomic_read_unchecked(&fscache_n_store_ops),
43914 + atomic_read_unchecked(&fscache_n_store_calls),
43915 + atomic_read_unchecked(&fscache_n_store_pages),
43916 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
43917 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
43918
43919 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
43920 - atomic_read(&fscache_n_store_vmscan_not_storing),
43921 - atomic_read(&fscache_n_store_vmscan_gone),
43922 - atomic_read(&fscache_n_store_vmscan_busy),
43923 - atomic_read(&fscache_n_store_vmscan_cancelled));
43924 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
43925 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
43926 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
43927 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
43928
43929 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
43930 - atomic_read(&fscache_n_op_pend),
43931 - atomic_read(&fscache_n_op_run),
43932 - atomic_read(&fscache_n_op_enqueue),
43933 - atomic_read(&fscache_n_op_cancelled),
43934 - atomic_read(&fscache_n_op_rejected));
43935 + atomic_read_unchecked(&fscache_n_op_pend),
43936 + atomic_read_unchecked(&fscache_n_op_run),
43937 + atomic_read_unchecked(&fscache_n_op_enqueue),
43938 + atomic_read_unchecked(&fscache_n_op_cancelled),
43939 + atomic_read_unchecked(&fscache_n_op_rejected));
43940 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
43941 - atomic_read(&fscache_n_op_deferred_release),
43942 - atomic_read(&fscache_n_op_release),
43943 - atomic_read(&fscache_n_op_gc));
43944 + atomic_read_unchecked(&fscache_n_op_deferred_release),
43945 + atomic_read_unchecked(&fscache_n_op_release),
43946 + atomic_read_unchecked(&fscache_n_op_gc));
43947
43948 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
43949 atomic_read(&fscache_n_cop_alloc_object),
43950 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
43951 index 3426521..3b75162 100644
43952 --- a/fs/fuse/cuse.c
43953 +++ b/fs/fuse/cuse.c
43954 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
43955 INIT_LIST_HEAD(&cuse_conntbl[i]);
43956
43957 /* inherit and extend fuse_dev_operations */
43958 - cuse_channel_fops = fuse_dev_operations;
43959 - cuse_channel_fops.owner = THIS_MODULE;
43960 - cuse_channel_fops.open = cuse_channel_open;
43961 - cuse_channel_fops.release = cuse_channel_release;
43962 + pax_open_kernel();
43963 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
43964 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
43965 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
43966 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
43967 + pax_close_kernel();
43968
43969 cuse_class = class_create(THIS_MODULE, "cuse");
43970 if (IS_ERR(cuse_class))
43971 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
43972 index 2aaf3ea..8e50863 100644
43973 --- a/fs/fuse/dev.c
43974 +++ b/fs/fuse/dev.c
43975 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
43976 ret = 0;
43977 pipe_lock(pipe);
43978
43979 - if (!pipe->readers) {
43980 + if (!atomic_read(&pipe->readers)) {
43981 send_sig(SIGPIPE, current, 0);
43982 if (!ret)
43983 ret = -EPIPE;
43984 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
43985 index 9f63e49..d8a64c0 100644
43986 --- a/fs/fuse/dir.c
43987 +++ b/fs/fuse/dir.c
43988 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *dentry)
43989 return link;
43990 }
43991
43992 -static void free_link(char *link)
43993 +static void free_link(const char *link)
43994 {
43995 if (!IS_ERR(link))
43996 free_page((unsigned long) link);
43997 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
43998 index cfd4959..a780959 100644
43999 --- a/fs/gfs2/inode.c
44000 +++ b/fs/gfs2/inode.c
44001 @@ -1490,7 +1490,7 @@ out:
44002
44003 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44004 {
44005 - char *s = nd_get_link(nd);
44006 + const char *s = nd_get_link(nd);
44007 if (!IS_ERR(s))
44008 kfree(s);
44009 }
44010 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
44011 index 0be5a78..9cfb853 100644
44012 --- a/fs/hugetlbfs/inode.c
44013 +++ b/fs/hugetlbfs/inode.c
44014 @@ -915,7 +915,7 @@ static struct file_system_type hugetlbfs_fs_type = {
44015 .kill_sb = kill_litter_super,
44016 };
44017
44018 -static struct vfsmount *hugetlbfs_vfsmount;
44019 +struct vfsmount *hugetlbfs_vfsmount;
44020
44021 static int can_do_hugetlb_shm(void)
44022 {
44023 diff --git a/fs/inode.c b/fs/inode.c
44024 index ee4e66b..0451521 100644
44025 --- a/fs/inode.c
44026 +++ b/fs/inode.c
44027 @@ -787,8 +787,8 @@ unsigned int get_next_ino(void)
44028
44029 #ifdef CONFIG_SMP
44030 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
44031 - static atomic_t shared_last_ino;
44032 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
44033 + static atomic_unchecked_t shared_last_ino;
44034 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
44035
44036 res = next - LAST_INO_BATCH;
44037 }
44038 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
44039 index e513f19..2ab1351 100644
44040 --- a/fs/jffs2/erase.c
44041 +++ b/fs/jffs2/erase.c
44042 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
44043 struct jffs2_unknown_node marker = {
44044 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
44045 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
44046 - .totlen = cpu_to_je32(c->cleanmarker_size)
44047 + .totlen = cpu_to_je32(c->cleanmarker_size),
44048 + .hdr_crc = cpu_to_je32(0)
44049 };
44050
44051 jffs2_prealloc_raw_node_refs(c, jeb, 1);
44052 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
44053 index b09e51d..e482afa 100644
44054 --- a/fs/jffs2/wbuf.c
44055 +++ b/fs/jffs2/wbuf.c
44056 @@ -1011,7 +1011,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
44057 {
44058 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
44059 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
44060 - .totlen = constant_cpu_to_je32(8)
44061 + .totlen = constant_cpu_to_je32(8),
44062 + .hdr_crc = constant_cpu_to_je32(0)
44063 };
44064
44065 /*
44066 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
44067 index a44eff0..462e07d 100644
44068 --- a/fs/jfs/super.c
44069 +++ b/fs/jfs/super.c
44070 @@ -802,7 +802,7 @@ static int __init init_jfs_fs(void)
44071
44072 jfs_inode_cachep =
44073 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
44074 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
44075 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
44076 init_once);
44077 if (jfs_inode_cachep == NULL)
44078 return -ENOMEM;
44079 diff --git a/fs/libfs.c b/fs/libfs.c
44080 index f6d411e..e82a08d 100644
44081 --- a/fs/libfs.c
44082 +++ b/fs/libfs.c
44083 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
44084
44085 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
44086 struct dentry *next;
44087 + char d_name[sizeof(next->d_iname)];
44088 + const unsigned char *name;
44089 +
44090 next = list_entry(p, struct dentry, d_u.d_child);
44091 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
44092 if (!simple_positive(next)) {
44093 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
44094
44095 spin_unlock(&next->d_lock);
44096 spin_unlock(&dentry->d_lock);
44097 - if (filldir(dirent, next->d_name.name,
44098 + name = next->d_name.name;
44099 + if (name == next->d_iname) {
44100 + memcpy(d_name, name, next->d_name.len);
44101 + name = d_name;
44102 + }
44103 + if (filldir(dirent, name,
44104 next->d_name.len, filp->f_pos,
44105 next->d_inode->i_ino,
44106 dt_type(next->d_inode)) < 0)
44107 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
44108 index 8392cb8..80d6193 100644
44109 --- a/fs/lockd/clntproc.c
44110 +++ b/fs/lockd/clntproc.c
44111 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
44112 /*
44113 * Cookie counter for NLM requests
44114 */
44115 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
44116 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
44117
44118 void nlmclnt_next_cookie(struct nlm_cookie *c)
44119 {
44120 - u32 cookie = atomic_inc_return(&nlm_cookie);
44121 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
44122
44123 memcpy(c->data, &cookie, 4);
44124 c->len=4;
44125 diff --git a/fs/locks.c b/fs/locks.c
44126 index 637694b..f84a121 100644
44127 --- a/fs/locks.c
44128 +++ b/fs/locks.c
44129 @@ -2074,16 +2074,16 @@ void locks_remove_flock(struct file *filp)
44130 return;
44131
44132 if (filp->f_op && filp->f_op->flock) {
44133 - struct file_lock fl = {
44134 + struct file_lock flock = {
44135 .fl_pid = current->tgid,
44136 .fl_file = filp,
44137 .fl_flags = FL_FLOCK,
44138 .fl_type = F_UNLCK,
44139 .fl_end = OFFSET_MAX,
44140 };
44141 - filp->f_op->flock(filp, F_SETLKW, &fl);
44142 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
44143 - fl.fl_ops->fl_release_private(&fl);
44144 + filp->f_op->flock(filp, F_SETLKW, &flock);
44145 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
44146 + flock.fl_ops->fl_release_private(&flock);
44147 }
44148
44149 lock_flocks();
44150 diff --git a/fs/namei.c b/fs/namei.c
44151 index 5008f01..90328a7 100644
44152 --- a/fs/namei.c
44153 +++ b/fs/namei.c
44154 @@ -279,16 +279,32 @@ int generic_permission(struct inode *inode, int mask)
44155 if (ret != -EACCES)
44156 return ret;
44157
44158 +#ifdef CONFIG_GRKERNSEC
44159 + /* we'll block if we have to log due to a denied capability use */
44160 + if (mask & MAY_NOT_BLOCK)
44161 + return -ECHILD;
44162 +#endif
44163 +
44164 if (S_ISDIR(inode->i_mode)) {
44165 /* DACs are overridable for directories */
44166 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44167 - return 0;
44168 if (!(mask & MAY_WRITE))
44169 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44170 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
44171 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44172 return 0;
44173 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44174 + return 0;
44175 return -EACCES;
44176 }
44177 /*
44178 + * Searching includes executable on directories, else just read.
44179 + */
44180 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
44181 + if (mask == MAY_READ)
44182 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
44183 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44184 + return 0;
44185 +
44186 + /*
44187 * Read/write DACs are always overridable.
44188 * Executable DACs are overridable when there is
44189 * at least one exec bit set.
44190 @@ -297,14 +313,6 @@ int generic_permission(struct inode *inode, int mask)
44191 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44192 return 0;
44193
44194 - /*
44195 - * Searching includes executable on directories, else just read.
44196 - */
44197 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
44198 - if (mask == MAY_READ)
44199 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44200 - return 0;
44201 -
44202 return -EACCES;
44203 }
44204
44205 @@ -653,11 +661,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
44206 return error;
44207 }
44208
44209 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
44210 + dentry->d_inode, dentry, nd->path.mnt)) {
44211 + error = -EACCES;
44212 + *p = ERR_PTR(error); /* no ->put_link(), please */
44213 + path_put(&nd->path);
44214 + return error;
44215 + }
44216 +
44217 nd->last_type = LAST_BIND;
44218 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
44219 error = PTR_ERR(*p);
44220 if (!IS_ERR(*p)) {
44221 - char *s = nd_get_link(nd);
44222 + const char *s = nd_get_link(nd);
44223 error = 0;
44224 if (s)
44225 error = __vfs_follow_link(nd, s);
44226 @@ -1622,6 +1638,21 @@ static int path_lookupat(int dfd, const char *name,
44227 if (!err)
44228 err = complete_walk(nd);
44229
44230 + if (!(nd->flags & LOOKUP_PARENT)) {
44231 +#ifdef CONFIG_GRKERNSEC
44232 + if (flags & LOOKUP_RCU) {
44233 + if (!err)
44234 + path_put(&nd->path);
44235 + err = -ECHILD;
44236 + } else
44237 +#endif
44238 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44239 + if (!err)
44240 + path_put(&nd->path);
44241 + err = -ENOENT;
44242 + }
44243 + }
44244 +
44245 if (!err && nd->flags & LOOKUP_DIRECTORY) {
44246 if (!nd->inode->i_op->lookup) {
44247 path_put(&nd->path);
44248 @@ -1649,6 +1680,15 @@ static int do_path_lookup(int dfd, const char *name,
44249 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
44250
44251 if (likely(!retval)) {
44252 + if (*name != '/' && nd->path.dentry && nd->inode) {
44253 +#ifdef CONFIG_GRKERNSEC
44254 + if (flags & LOOKUP_RCU)
44255 + return -ECHILD;
44256 +#endif
44257 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
44258 + return -ENOENT;
44259 + }
44260 +
44261 if (unlikely(!audit_dummy_context())) {
44262 if (nd->path.dentry && nd->inode)
44263 audit_inode(name, nd->path.dentry);
44264 @@ -2046,6 +2086,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
44265 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
44266 return -EPERM;
44267
44268 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
44269 + return -EPERM;
44270 + if (gr_handle_rawio(inode))
44271 + return -EPERM;
44272 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
44273 + return -EACCES;
44274 +
44275 return 0;
44276 }
44277
44278 @@ -2107,6 +2154,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44279 error = complete_walk(nd);
44280 if (error)
44281 return ERR_PTR(error);
44282 +#ifdef CONFIG_GRKERNSEC
44283 + if (nd->flags & LOOKUP_RCU) {
44284 + error = -ECHILD;
44285 + goto exit;
44286 + }
44287 +#endif
44288 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44289 + error = -ENOENT;
44290 + goto exit;
44291 + }
44292 audit_inode(pathname, nd->path.dentry);
44293 if (open_flag & O_CREAT) {
44294 error = -EISDIR;
44295 @@ -2117,6 +2174,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44296 error = complete_walk(nd);
44297 if (error)
44298 return ERR_PTR(error);
44299 +#ifdef CONFIG_GRKERNSEC
44300 + if (nd->flags & LOOKUP_RCU) {
44301 + error = -ECHILD;
44302 + goto exit;
44303 + }
44304 +#endif
44305 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
44306 + error = -ENOENT;
44307 + goto exit;
44308 + }
44309 audit_inode(pathname, dir);
44310 goto ok;
44311 }
44312 @@ -2138,6 +2205,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44313 error = complete_walk(nd);
44314 if (error)
44315 return ERR_PTR(-ECHILD);
44316 +#ifdef CONFIG_GRKERNSEC
44317 + if (nd->flags & LOOKUP_RCU) {
44318 + error = -ECHILD;
44319 + goto exit;
44320 + }
44321 +#endif
44322 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44323 + error = -ENOENT;
44324 + goto exit;
44325 + }
44326
44327 error = -ENOTDIR;
44328 if (nd->flags & LOOKUP_DIRECTORY) {
44329 @@ -2178,6 +2255,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44330 /* Negative dentry, just create the file */
44331 if (!dentry->d_inode) {
44332 int mode = op->mode;
44333 +
44334 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
44335 + error = -EACCES;
44336 + goto exit_mutex_unlock;
44337 + }
44338 +
44339 if (!IS_POSIXACL(dir->d_inode))
44340 mode &= ~current_umask();
44341 /*
44342 @@ -2201,6 +2284,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44343 error = vfs_create(dir->d_inode, dentry, mode, nd);
44344 if (error)
44345 goto exit_mutex_unlock;
44346 + else
44347 + gr_handle_create(path->dentry, path->mnt);
44348 mutex_unlock(&dir->d_inode->i_mutex);
44349 dput(nd->path.dentry);
44350 nd->path.dentry = dentry;
44351 @@ -2210,6 +2295,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44352 /*
44353 * It already exists.
44354 */
44355 +
44356 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
44357 + error = -ENOENT;
44358 + goto exit_mutex_unlock;
44359 + }
44360 +
44361 + /* only check if O_CREAT is specified, all other checks need to go
44362 + into may_open */
44363 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
44364 + error = -EACCES;
44365 + goto exit_mutex_unlock;
44366 + }
44367 +
44368 mutex_unlock(&dir->d_inode->i_mutex);
44369 audit_inode(pathname, path->dentry);
44370
44371 @@ -2422,6 +2520,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
44372 *path = nd.path;
44373 return dentry;
44374 eexist:
44375 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
44376 + dput(dentry);
44377 + dentry = ERR_PTR(-ENOENT);
44378 + goto fail;
44379 + }
44380 dput(dentry);
44381 dentry = ERR_PTR(-EEXIST);
44382 fail:
44383 @@ -2444,6 +2547,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
44384 }
44385 EXPORT_SYMBOL(user_path_create);
44386
44387 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
44388 +{
44389 + char *tmp = getname(pathname);
44390 + struct dentry *res;
44391 + if (IS_ERR(tmp))
44392 + return ERR_CAST(tmp);
44393 + res = kern_path_create(dfd, tmp, path, is_dir);
44394 + if (IS_ERR(res))
44395 + putname(tmp);
44396 + else
44397 + *to = tmp;
44398 + return res;
44399 +}
44400 +
44401 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
44402 {
44403 int error = may_create(dir, dentry);
44404 @@ -2511,6 +2628,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
44405 error = mnt_want_write(path.mnt);
44406 if (error)
44407 goto out_dput;
44408 +
44409 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
44410 + error = -EPERM;
44411 + goto out_drop_write;
44412 + }
44413 +
44414 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
44415 + error = -EACCES;
44416 + goto out_drop_write;
44417 + }
44418 +
44419 error = security_path_mknod(&path, dentry, mode, dev);
44420 if (error)
44421 goto out_drop_write;
44422 @@ -2528,6 +2656,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
44423 }
44424 out_drop_write:
44425 mnt_drop_write(path.mnt);
44426 +
44427 + if (!error)
44428 + gr_handle_create(dentry, path.mnt);
44429 out_dput:
44430 dput(dentry);
44431 mutex_unlock(&path.dentry->d_inode->i_mutex);
44432 @@ -2577,12 +2708,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
44433 error = mnt_want_write(path.mnt);
44434 if (error)
44435 goto out_dput;
44436 +
44437 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
44438 + error = -EACCES;
44439 + goto out_drop_write;
44440 + }
44441 +
44442 error = security_path_mkdir(&path, dentry, mode);
44443 if (error)
44444 goto out_drop_write;
44445 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
44446 out_drop_write:
44447 mnt_drop_write(path.mnt);
44448 +
44449 + if (!error)
44450 + gr_handle_create(dentry, path.mnt);
44451 out_dput:
44452 dput(dentry);
44453 mutex_unlock(&path.dentry->d_inode->i_mutex);
44454 @@ -2662,6 +2802,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
44455 char * name;
44456 struct dentry *dentry;
44457 struct nameidata nd;
44458 + ino_t saved_ino = 0;
44459 + dev_t saved_dev = 0;
44460
44461 error = user_path_parent(dfd, pathname, &nd, &name);
44462 if (error)
44463 @@ -2690,6 +2832,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
44464 error = -ENOENT;
44465 goto exit3;
44466 }
44467 +
44468 + saved_ino = dentry->d_inode->i_ino;
44469 + saved_dev = gr_get_dev_from_dentry(dentry);
44470 +
44471 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
44472 + error = -EACCES;
44473 + goto exit3;
44474 + }
44475 +
44476 error = mnt_want_write(nd.path.mnt);
44477 if (error)
44478 goto exit3;
44479 @@ -2697,6 +2848,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
44480 if (error)
44481 goto exit4;
44482 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
44483 + if (!error && (saved_dev || saved_ino))
44484 + gr_handle_delete(saved_ino, saved_dev);
44485 exit4:
44486 mnt_drop_write(nd.path.mnt);
44487 exit3:
44488 @@ -2759,6 +2912,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44489 struct dentry *dentry;
44490 struct nameidata nd;
44491 struct inode *inode = NULL;
44492 + ino_t saved_ino = 0;
44493 + dev_t saved_dev = 0;
44494
44495 error = user_path_parent(dfd, pathname, &nd, &name);
44496 if (error)
44497 @@ -2781,6 +2936,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44498 if (!inode)
44499 goto slashes;
44500 ihold(inode);
44501 +
44502 + if (inode->i_nlink <= 1) {
44503 + saved_ino = inode->i_ino;
44504 + saved_dev = gr_get_dev_from_dentry(dentry);
44505 + }
44506 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
44507 + error = -EACCES;
44508 + goto exit2;
44509 + }
44510 +
44511 error = mnt_want_write(nd.path.mnt);
44512 if (error)
44513 goto exit2;
44514 @@ -2788,6 +2953,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44515 if (error)
44516 goto exit3;
44517 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
44518 + if (!error && (saved_ino || saved_dev))
44519 + gr_handle_delete(saved_ino, saved_dev);
44520 exit3:
44521 mnt_drop_write(nd.path.mnt);
44522 exit2:
44523 @@ -2863,10 +3030,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
44524 error = mnt_want_write(path.mnt);
44525 if (error)
44526 goto out_dput;
44527 +
44528 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
44529 + error = -EACCES;
44530 + goto out_drop_write;
44531 + }
44532 +
44533 error = security_path_symlink(&path, dentry, from);
44534 if (error)
44535 goto out_drop_write;
44536 error = vfs_symlink(path.dentry->d_inode, dentry, from);
44537 + if (!error)
44538 + gr_handle_create(dentry, path.mnt);
44539 out_drop_write:
44540 mnt_drop_write(path.mnt);
44541 out_dput:
44542 @@ -2938,6 +3113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44543 {
44544 struct dentry *new_dentry;
44545 struct path old_path, new_path;
44546 + char *to = NULL;
44547 int how = 0;
44548 int error;
44549
44550 @@ -2961,7 +3137,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44551 if (error)
44552 return error;
44553
44554 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
44555 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
44556 error = PTR_ERR(new_dentry);
44557 if (IS_ERR(new_dentry))
44558 goto out;
44559 @@ -2972,13 +3148,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44560 error = mnt_want_write(new_path.mnt);
44561 if (error)
44562 goto out_dput;
44563 +
44564 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
44565 + old_path.dentry->d_inode,
44566 + old_path.dentry->d_inode->i_mode, to)) {
44567 + error = -EACCES;
44568 + goto out_drop_write;
44569 + }
44570 +
44571 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
44572 + old_path.dentry, old_path.mnt, to)) {
44573 + error = -EACCES;
44574 + goto out_drop_write;
44575 + }
44576 +
44577 error = security_path_link(old_path.dentry, &new_path, new_dentry);
44578 if (error)
44579 goto out_drop_write;
44580 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
44581 + if (!error)
44582 + gr_handle_create(new_dentry, new_path.mnt);
44583 out_drop_write:
44584 mnt_drop_write(new_path.mnt);
44585 out_dput:
44586 + putname(to);
44587 dput(new_dentry);
44588 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
44589 path_put(&new_path);
44590 @@ -3206,6 +3399,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
44591 if (new_dentry == trap)
44592 goto exit5;
44593
44594 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
44595 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
44596 + to);
44597 + if (error)
44598 + goto exit5;
44599 +
44600 error = mnt_want_write(oldnd.path.mnt);
44601 if (error)
44602 goto exit5;
44603 @@ -3215,6 +3414,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
44604 goto exit6;
44605 error = vfs_rename(old_dir->d_inode, old_dentry,
44606 new_dir->d_inode, new_dentry);
44607 + if (!error)
44608 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
44609 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
44610 exit6:
44611 mnt_drop_write(oldnd.path.mnt);
44612 exit5:
44613 @@ -3240,6 +3442,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
44614
44615 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
44616 {
44617 + char tmpbuf[64];
44618 + const char *newlink;
44619 int len;
44620
44621 len = PTR_ERR(link);
44622 @@ -3249,7 +3453,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
44623 len = strlen(link);
44624 if (len > (unsigned) buflen)
44625 len = buflen;
44626 - if (copy_to_user(buffer, link, len))
44627 +
44628 + if (len < sizeof(tmpbuf)) {
44629 + memcpy(tmpbuf, link, len);
44630 + newlink = tmpbuf;
44631 + } else
44632 + newlink = link;
44633 +
44634 + if (copy_to_user(buffer, newlink, len))
44635 len = -EFAULT;
44636 out:
44637 return len;
44638 diff --git a/fs/namespace.c b/fs/namespace.c
44639 index cfc6d44..b4632a5 100644
44640 --- a/fs/namespace.c
44641 +++ b/fs/namespace.c
44642 @@ -1326,6 +1326,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
44643 if (!(sb->s_flags & MS_RDONLY))
44644 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
44645 up_write(&sb->s_umount);
44646 +
44647 + gr_log_remount(mnt->mnt_devname, retval);
44648 +
44649 return retval;
44650 }
44651
44652 @@ -1345,6 +1348,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
44653 br_write_unlock(vfsmount_lock);
44654 up_write(&namespace_sem);
44655 release_mounts(&umount_list);
44656 +
44657 + gr_log_unmount(mnt->mnt_devname, retval);
44658 +
44659 return retval;
44660 }
44661
44662 @@ -2336,6 +2342,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
44663 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
44664 MS_STRICTATIME);
44665
44666 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
44667 + retval = -EPERM;
44668 + goto dput_out;
44669 + }
44670 +
44671 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
44672 + retval = -EPERM;
44673 + goto dput_out;
44674 + }
44675 +
44676 if (flags & MS_REMOUNT)
44677 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
44678 data_page);
44679 @@ -2350,6 +2366,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
44680 dev_name, data_page);
44681 dput_out:
44682 path_put(&path);
44683 +
44684 + gr_log_mount(dev_name, dir_name, retval);
44685 +
44686 return retval;
44687 }
44688
44689 @@ -2605,6 +2624,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
44690 if (error)
44691 goto out2;
44692
44693 + if (gr_handle_chroot_pivot()) {
44694 + error = -EPERM;
44695 + goto out2;
44696 + }
44697 +
44698 get_fs_root(current->fs, &root);
44699 error = lock_mount(&old);
44700 if (error)
44701 diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
44702 index 281ae95..dd895b9 100644
44703 --- a/fs/nfs/blocklayout/blocklayout.c
44704 +++ b/fs/nfs/blocklayout/blocklayout.c
44705 @@ -90,7 +90,7 @@ static int is_writable(struct pnfs_block_extent *be, sector_t isect)
44706 */
44707 struct parallel_io {
44708 struct kref refcnt;
44709 - struct rpc_call_ops call_ops;
44710 + rpc_call_ops_no_const call_ops;
44711 void (*pnfs_callback) (void *data);
44712 void *data;
44713 };
44714 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
44715 index 50a15fa..ca113f9 100644
44716 --- a/fs/nfs/inode.c
44717 +++ b/fs/nfs/inode.c
44718 @@ -150,7 +150,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
44719 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
44720 nfsi->attrtimeo_timestamp = jiffies;
44721
44722 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
44723 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
44724 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
44725 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
44726 else
44727 @@ -1002,16 +1002,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
44728 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
44729 }
44730
44731 -static atomic_long_t nfs_attr_generation_counter;
44732 +static atomic_long_unchecked_t nfs_attr_generation_counter;
44733
44734 static unsigned long nfs_read_attr_generation_counter(void)
44735 {
44736 - return atomic_long_read(&nfs_attr_generation_counter);
44737 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
44738 }
44739
44740 unsigned long nfs_inc_attr_generation_counter(void)
44741 {
44742 - return atomic_long_inc_return(&nfs_attr_generation_counter);
44743 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
44744 }
44745
44746 void nfs_fattr_init(struct nfs_fattr *fattr)
44747 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
44748 index 7a2e442..8e544cc 100644
44749 --- a/fs/nfsd/vfs.c
44750 +++ b/fs/nfsd/vfs.c
44751 @@ -914,7 +914,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
44752 } else {
44753 oldfs = get_fs();
44754 set_fs(KERNEL_DS);
44755 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
44756 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
44757 set_fs(oldfs);
44758 }
44759
44760 @@ -1018,7 +1018,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
44761
44762 /* Write the data. */
44763 oldfs = get_fs(); set_fs(KERNEL_DS);
44764 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
44765 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
44766 set_fs(oldfs);
44767 if (host_err < 0)
44768 goto out_nfserr;
44769 @@ -1553,7 +1553,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
44770 */
44771
44772 oldfs = get_fs(); set_fs(KERNEL_DS);
44773 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
44774 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
44775 set_fs(oldfs);
44776
44777 if (host_err < 0)
44778 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
44779 index 9fde1c0..14e8827 100644
44780 --- a/fs/notify/fanotify/fanotify_user.c
44781 +++ b/fs/notify/fanotify/fanotify_user.c
44782 @@ -276,7 +276,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
44783 goto out_close_fd;
44784
44785 ret = -EFAULT;
44786 - if (copy_to_user(buf, &fanotify_event_metadata,
44787 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
44788 + copy_to_user(buf, &fanotify_event_metadata,
44789 fanotify_event_metadata.event_len))
44790 goto out_kill_access_response;
44791
44792 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
44793 index e14587d..f104d56 100644
44794 --- a/fs/notify/mark.c
44795 +++ b/fs/notify/mark.c
44796 @@ -135,9 +135,6 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark)
44797
44798 mark->flags &= ~FSNOTIFY_MARK_FLAG_ALIVE;
44799
44800 - /* 1 from caller and 1 for being on i_list/g_list */
44801 - BUG_ON(atomic_read(&mark->refcnt) < 2);
44802 -
44803 spin_lock(&group->mark_lock);
44804
44805 if (mark->flags & FSNOTIFY_MARK_FLAG_INODE) {
44806 @@ -182,6 +179,11 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark)
44807 iput(inode);
44808
44809 /*
44810 + * We don't necessarily have a ref on mark from caller so the above iput
44811 + * may have already destroyed it. Don't touch from now on.
44812 + */
44813 +
44814 + /*
44815 * it's possible that this group tried to destroy itself, but this
44816 * this mark was simultaneously being freed by inode. If that's the
44817 * case, we finish freeing the group here.
44818 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
44819 index ee18815..7aa5d01 100644
44820 --- a/fs/notify/notification.c
44821 +++ b/fs/notify/notification.c
44822 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
44823 * get set to 0 so it will never get 'freed'
44824 */
44825 static struct fsnotify_event *q_overflow_event;
44826 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
44827 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
44828
44829 /**
44830 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
44831 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
44832 */
44833 u32 fsnotify_get_cookie(void)
44834 {
44835 - return atomic_inc_return(&fsnotify_sync_cookie);
44836 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
44837 }
44838 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
44839
44840 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
44841 index 99e3610..02c1068 100644
44842 --- a/fs/ntfs/dir.c
44843 +++ b/fs/ntfs/dir.c
44844 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
44845 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
44846 ~(s64)(ndir->itype.index.block_size - 1)));
44847 /* Bounds checks. */
44848 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
44849 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
44850 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
44851 "inode 0x%lx or driver bug.", vdir->i_ino);
44852 goto err_out;
44853 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
44854 index c587e2d..3641eaa 100644
44855 --- a/fs/ntfs/file.c
44856 +++ b/fs/ntfs/file.c
44857 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
44858 #endif /* NTFS_RW */
44859 };
44860
44861 -const struct file_operations ntfs_empty_file_ops = {};
44862 +const struct file_operations ntfs_empty_file_ops __read_only;
44863
44864 -const struct inode_operations ntfs_empty_inode_ops = {};
44865 +const struct inode_operations ntfs_empty_inode_ops __read_only;
44866 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
44867 index 210c352..a174f83 100644
44868 --- a/fs/ocfs2/localalloc.c
44869 +++ b/fs/ocfs2/localalloc.c
44870 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
44871 goto bail;
44872 }
44873
44874 - atomic_inc(&osb->alloc_stats.moves);
44875 + atomic_inc_unchecked(&osb->alloc_stats.moves);
44876
44877 bail:
44878 if (handle)
44879 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
44880 index d355e6e..578d905 100644
44881 --- a/fs/ocfs2/ocfs2.h
44882 +++ b/fs/ocfs2/ocfs2.h
44883 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
44884
44885 struct ocfs2_alloc_stats
44886 {
44887 - atomic_t moves;
44888 - atomic_t local_data;
44889 - atomic_t bitmap_data;
44890 - atomic_t bg_allocs;
44891 - atomic_t bg_extends;
44892 + atomic_unchecked_t moves;
44893 + atomic_unchecked_t local_data;
44894 + atomic_unchecked_t bitmap_data;
44895 + atomic_unchecked_t bg_allocs;
44896 + atomic_unchecked_t bg_extends;
44897 };
44898
44899 enum ocfs2_local_alloc_state
44900 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
44901 index ba5d97e..c77db25 100644
44902 --- a/fs/ocfs2/suballoc.c
44903 +++ b/fs/ocfs2/suballoc.c
44904 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
44905 mlog_errno(status);
44906 goto bail;
44907 }
44908 - atomic_inc(&osb->alloc_stats.bg_extends);
44909 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
44910
44911 /* You should never ask for this much metadata */
44912 BUG_ON(bits_wanted >
44913 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
44914 mlog_errno(status);
44915 goto bail;
44916 }
44917 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44918 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44919
44920 *suballoc_loc = res.sr_bg_blkno;
44921 *suballoc_bit_start = res.sr_bit_offset;
44922 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
44923 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
44924 res->sr_bits);
44925
44926 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44927 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44928
44929 BUG_ON(res->sr_bits != 1);
44930
44931 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
44932 mlog_errno(status);
44933 goto bail;
44934 }
44935 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44936 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44937
44938 BUG_ON(res.sr_bits != 1);
44939
44940 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
44941 cluster_start,
44942 num_clusters);
44943 if (!status)
44944 - atomic_inc(&osb->alloc_stats.local_data);
44945 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
44946 } else {
44947 if (min_clusters > (osb->bitmap_cpg - 1)) {
44948 /* The only paths asking for contiguousness
44949 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
44950 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
44951 res.sr_bg_blkno,
44952 res.sr_bit_offset);
44953 - atomic_inc(&osb->alloc_stats.bitmap_data);
44954 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
44955 *num_clusters = res.sr_bits;
44956 }
44957 }
44958 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
44959 index 4994f8b..eaab8eb 100644
44960 --- a/fs/ocfs2/super.c
44961 +++ b/fs/ocfs2/super.c
44962 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
44963 "%10s => GlobalAllocs: %d LocalAllocs: %d "
44964 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
44965 "Stats",
44966 - atomic_read(&osb->alloc_stats.bitmap_data),
44967 - atomic_read(&osb->alloc_stats.local_data),
44968 - atomic_read(&osb->alloc_stats.bg_allocs),
44969 - atomic_read(&osb->alloc_stats.moves),
44970 - atomic_read(&osb->alloc_stats.bg_extends));
44971 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
44972 + atomic_read_unchecked(&osb->alloc_stats.local_data),
44973 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
44974 + atomic_read_unchecked(&osb->alloc_stats.moves),
44975 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
44976
44977 out += snprintf(buf + out, len - out,
44978 "%10s => State: %u Descriptor: %llu Size: %u bits "
44979 @@ -2119,11 +2119,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
44980 spin_lock_init(&osb->osb_xattr_lock);
44981 ocfs2_init_steal_slots(osb);
44982
44983 - atomic_set(&osb->alloc_stats.moves, 0);
44984 - atomic_set(&osb->alloc_stats.local_data, 0);
44985 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
44986 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
44987 - atomic_set(&osb->alloc_stats.bg_extends, 0);
44988 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
44989 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
44990 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
44991 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
44992 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
44993
44994 /* Copy the blockcheck stats from the superblock probe */
44995 osb->osb_ecc_stats = *stats;
44996 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
44997 index 5d22872..523db20 100644
44998 --- a/fs/ocfs2/symlink.c
44999 +++ b/fs/ocfs2/symlink.c
45000 @@ -142,7 +142,7 @@ bail:
45001
45002 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
45003 {
45004 - char *link = nd_get_link(nd);
45005 + const char *link = nd_get_link(nd);
45006 if (!IS_ERR(link))
45007 kfree(link);
45008 }
45009 diff --git a/fs/open.c b/fs/open.c
45010 index 22c41b5..695cb17 100644
45011 --- a/fs/open.c
45012 +++ b/fs/open.c
45013 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
45014 error = locks_verify_truncate(inode, NULL, length);
45015 if (!error)
45016 error = security_path_truncate(&path);
45017 +
45018 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
45019 + error = -EACCES;
45020 +
45021 if (!error)
45022 error = do_truncate(path.dentry, length, 0, NULL);
45023
45024 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
45025 if (__mnt_is_readonly(path.mnt))
45026 res = -EROFS;
45027
45028 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
45029 + res = -EACCES;
45030 +
45031 out_path_release:
45032 path_put(&path);
45033 out:
45034 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
45035 if (error)
45036 goto dput_and_out;
45037
45038 + gr_log_chdir(path.dentry, path.mnt);
45039 +
45040 set_fs_pwd(current->fs, &path);
45041
45042 dput_and_out:
45043 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
45044 goto out_putf;
45045
45046 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
45047 +
45048 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
45049 + error = -EPERM;
45050 +
45051 + if (!error)
45052 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
45053 +
45054 if (!error)
45055 set_fs_pwd(current->fs, &file->f_path);
45056 out_putf:
45057 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
45058 if (error)
45059 goto dput_and_out;
45060
45061 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
45062 + goto dput_and_out;
45063 +
45064 set_fs_root(current->fs, &path);
45065 +
45066 + gr_handle_chroot_chdir(&path);
45067 +
45068 error = 0;
45069 dput_and_out:
45070 path_put(&path);
45071 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
45072 if (error)
45073 return error;
45074 mutex_lock(&inode->i_mutex);
45075 +
45076 + if (!gr_acl_handle_fchmod(path->dentry, path->mnt, mode)) {
45077 + error = -EACCES;
45078 + goto out_unlock;
45079 + }
45080 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
45081 + error = -EACCES;
45082 + goto out_unlock;
45083 + }
45084 +
45085 error = security_path_chmod(path->dentry, path->mnt, mode);
45086 if (error)
45087 goto out_unlock;
45088 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
45089 int error;
45090 struct iattr newattrs;
45091
45092 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
45093 + return -EACCES;
45094 +
45095 newattrs.ia_valid = ATTR_CTIME;
45096 if (user != (uid_t) -1) {
45097 newattrs.ia_valid |= ATTR_UID;
45098 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
45099 index 6296b40..417c00f 100644
45100 --- a/fs/partitions/efi.c
45101 +++ b/fs/partitions/efi.c
45102 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
45103 if (!gpt)
45104 return NULL;
45105
45106 + if (!le32_to_cpu(gpt->num_partition_entries))
45107 + return NULL;
45108 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
45109 + if (!pte)
45110 + return NULL;
45111 +
45112 count = le32_to_cpu(gpt->num_partition_entries) *
45113 le32_to_cpu(gpt->sizeof_partition_entry);
45114 - if (!count)
45115 - return NULL;
45116 - pte = kzalloc(count, GFP_KERNEL);
45117 - if (!pte)
45118 - return NULL;
45119 -
45120 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
45121 (u8 *) pte,
45122 count) < count) {
45123 diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
45124 index bd8ae78..539d250 100644
45125 --- a/fs/partitions/ldm.c
45126 +++ b/fs/partitions/ldm.c
45127 @@ -1324,7 +1324,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
45128 goto found;
45129 }
45130
45131 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
45132 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
45133 if (!f) {
45134 ldm_crit ("Out of memory.");
45135 return false;
45136 diff --git a/fs/pipe.c b/fs/pipe.c
45137 index 4065f07..68c0706 100644
45138 --- a/fs/pipe.c
45139 +++ b/fs/pipe.c
45140 @@ -420,9 +420,9 @@ redo:
45141 }
45142 if (bufs) /* More to do? */
45143 continue;
45144 - if (!pipe->writers)
45145 + if (!atomic_read(&pipe->writers))
45146 break;
45147 - if (!pipe->waiting_writers) {
45148 + if (!atomic_read(&pipe->waiting_writers)) {
45149 /* syscall merging: Usually we must not sleep
45150 * if O_NONBLOCK is set, or if we got some data.
45151 * But if a writer sleeps in kernel space, then
45152 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
45153 mutex_lock(&inode->i_mutex);
45154 pipe = inode->i_pipe;
45155
45156 - if (!pipe->readers) {
45157 + if (!atomic_read(&pipe->readers)) {
45158 send_sig(SIGPIPE, current, 0);
45159 ret = -EPIPE;
45160 goto out;
45161 @@ -530,7 +530,7 @@ redo1:
45162 for (;;) {
45163 int bufs;
45164
45165 - if (!pipe->readers) {
45166 + if (!atomic_read(&pipe->readers)) {
45167 send_sig(SIGPIPE, current, 0);
45168 if (!ret)
45169 ret = -EPIPE;
45170 @@ -616,9 +616,9 @@ redo2:
45171 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45172 do_wakeup = 0;
45173 }
45174 - pipe->waiting_writers++;
45175 + atomic_inc(&pipe->waiting_writers);
45176 pipe_wait(pipe);
45177 - pipe->waiting_writers--;
45178 + atomic_dec(&pipe->waiting_writers);
45179 }
45180 out:
45181 mutex_unlock(&inode->i_mutex);
45182 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
45183 mask = 0;
45184 if (filp->f_mode & FMODE_READ) {
45185 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
45186 - if (!pipe->writers && filp->f_version != pipe->w_counter)
45187 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
45188 mask |= POLLHUP;
45189 }
45190
45191 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
45192 * Most Unices do not set POLLERR for FIFOs but on Linux they
45193 * behave exactly like pipes for poll().
45194 */
45195 - if (!pipe->readers)
45196 + if (!atomic_read(&pipe->readers))
45197 mask |= POLLERR;
45198 }
45199
45200 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
45201
45202 mutex_lock(&inode->i_mutex);
45203 pipe = inode->i_pipe;
45204 - pipe->readers -= decr;
45205 - pipe->writers -= decw;
45206 + atomic_sub(decr, &pipe->readers);
45207 + atomic_sub(decw, &pipe->writers);
45208
45209 - if (!pipe->readers && !pipe->writers) {
45210 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
45211 free_pipe_info(inode);
45212 } else {
45213 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
45214 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
45215
45216 if (inode->i_pipe) {
45217 ret = 0;
45218 - inode->i_pipe->readers++;
45219 + atomic_inc(&inode->i_pipe->readers);
45220 }
45221
45222 mutex_unlock(&inode->i_mutex);
45223 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
45224
45225 if (inode->i_pipe) {
45226 ret = 0;
45227 - inode->i_pipe->writers++;
45228 + atomic_inc(&inode->i_pipe->writers);
45229 }
45230
45231 mutex_unlock(&inode->i_mutex);
45232 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
45233 if (inode->i_pipe) {
45234 ret = 0;
45235 if (filp->f_mode & FMODE_READ)
45236 - inode->i_pipe->readers++;
45237 + atomic_inc(&inode->i_pipe->readers);
45238 if (filp->f_mode & FMODE_WRITE)
45239 - inode->i_pipe->writers++;
45240 + atomic_inc(&inode->i_pipe->writers);
45241 }
45242
45243 mutex_unlock(&inode->i_mutex);
45244 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
45245 inode->i_pipe = NULL;
45246 }
45247
45248 -static struct vfsmount *pipe_mnt __read_mostly;
45249 +struct vfsmount *pipe_mnt __read_mostly;
45250
45251 /*
45252 * pipefs_dname() is called from d_path().
45253 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
45254 goto fail_iput;
45255 inode->i_pipe = pipe;
45256
45257 - pipe->readers = pipe->writers = 1;
45258 + atomic_set(&pipe->readers, 1);
45259 + atomic_set(&pipe->writers, 1);
45260 inode->i_fop = &rdwr_pipefifo_fops;
45261
45262 /*
45263 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
45264 index 15af622..0e9f4467 100644
45265 --- a/fs/proc/Kconfig
45266 +++ b/fs/proc/Kconfig
45267 @@ -30,12 +30,12 @@ config PROC_FS
45268
45269 config PROC_KCORE
45270 bool "/proc/kcore support" if !ARM
45271 - depends on PROC_FS && MMU
45272 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
45273
45274 config PROC_VMCORE
45275 bool "/proc/vmcore support"
45276 - depends on PROC_FS && CRASH_DUMP
45277 - default y
45278 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
45279 + default n
45280 help
45281 Exports the dump image of crashed kernel in ELF format.
45282
45283 @@ -59,8 +59,8 @@ config PROC_SYSCTL
45284 limited in memory.
45285
45286 config PROC_PAGE_MONITOR
45287 - default y
45288 - depends on PROC_FS && MMU
45289 + default n
45290 + depends on PROC_FS && MMU && !GRKERNSEC
45291 bool "Enable /proc page monitoring" if EXPERT
45292 help
45293 Various /proc files exist to monitor process memory utilization:
45294 diff --git a/fs/proc/array.c b/fs/proc/array.c
45295 index 3a1dafd..d41fc37 100644
45296 --- a/fs/proc/array.c
45297 +++ b/fs/proc/array.c
45298 @@ -60,6 +60,7 @@
45299 #include <linux/tty.h>
45300 #include <linux/string.h>
45301 #include <linux/mman.h>
45302 +#include <linux/grsecurity.h>
45303 #include <linux/proc_fs.h>
45304 #include <linux/ioport.h>
45305 #include <linux/uaccess.h>
45306 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
45307 seq_putc(m, '\n');
45308 }
45309
45310 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45311 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
45312 +{
45313 + if (p->mm)
45314 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
45315 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
45316 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
45317 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
45318 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
45319 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
45320 + else
45321 + seq_printf(m, "PaX:\t-----\n");
45322 +}
45323 +#endif
45324 +
45325 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
45326 struct pid *pid, struct task_struct *task)
45327 {
45328 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
45329 task_cpus_allowed(m, task);
45330 cpuset_task_status_allowed(m, task);
45331 task_context_switch_counts(m, task);
45332 +
45333 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45334 + task_pax(m, task);
45335 +#endif
45336 +
45337 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
45338 + task_grsec_rbac(m, task);
45339 +#endif
45340 +
45341 return 0;
45342 }
45343
45344 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45345 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45346 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
45347 + _mm->pax_flags & MF_PAX_SEGMEXEC))
45348 +#endif
45349 +
45350 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45351 struct pid *pid, struct task_struct *task, int whole)
45352 {
45353 @@ -449,6 +480,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45354 gtime = task->gtime;
45355 }
45356
45357 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45358 + if (PAX_RAND_FLAGS(mm)) {
45359 + eip = 0;
45360 + esp = 0;
45361 + wchan = 0;
45362 + }
45363 +#endif
45364 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45365 + wchan = 0;
45366 + eip =0;
45367 + esp =0;
45368 +#endif
45369 +
45370 /* scale priority and nice values from timeslices to -20..20 */
45371 /* to make it look like a "normal" Unix priority/nice value */
45372 priority = task_prio(task);
45373 @@ -489,9 +533,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45374 vsize,
45375 mm ? get_mm_rss(mm) : 0,
45376 rsslim,
45377 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45378 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
45379 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
45380 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
45381 +#else
45382 mm ? (permitted ? mm->start_code : 1) : 0,
45383 mm ? (permitted ? mm->end_code : 1) : 0,
45384 (permitted && mm) ? mm->start_stack : 0,
45385 +#endif
45386 esp,
45387 eip,
45388 /* The signal information here is obsolete.
45389 @@ -544,3 +594,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
45390
45391 return 0;
45392 }
45393 +
45394 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45395 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
45396 +{
45397 + u32 curr_ip = 0;
45398 + unsigned long flags;
45399 +
45400 + if (lock_task_sighand(task, &flags)) {
45401 + curr_ip = task->signal->curr_ip;
45402 + unlock_task_sighand(task, &flags);
45403 + }
45404 +
45405 + return sprintf(buffer, "%pI4\n", &curr_ip);
45406 +}
45407 +#endif
45408 diff --git a/fs/proc/base.c b/fs/proc/base.c
45409 index 851ba3d..813fd0b 100644
45410 --- a/fs/proc/base.c
45411 +++ b/fs/proc/base.c
45412 @@ -107,6 +107,22 @@ struct pid_entry {
45413 union proc_op op;
45414 };
45415
45416 +struct getdents_callback {
45417 + struct linux_dirent __user * current_dir;
45418 + struct linux_dirent __user * previous;
45419 + struct file * file;
45420 + int count;
45421 + int error;
45422 +};
45423 +
45424 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
45425 + loff_t offset, u64 ino, unsigned int d_type)
45426 +{
45427 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
45428 + buf->error = -EINVAL;
45429 + return 0;
45430 +}
45431 +
45432 #define NOD(NAME, MODE, IOP, FOP, OP) { \
45433 .name = (NAME), \
45434 .len = sizeof(NAME) - 1, \
45435 @@ -194,65 +210,7 @@ static int proc_root_link(struct inode *inode, struct path *path)
45436 return result;
45437 }
45438
45439 -static struct mm_struct *__check_mem_permission(struct task_struct *task)
45440 -{
45441 - struct mm_struct *mm;
45442 -
45443 - mm = get_task_mm(task);
45444 - if (!mm)
45445 - return ERR_PTR(-EINVAL);
45446 -
45447 - /*
45448 - * A task can always look at itself, in case it chooses
45449 - * to use system calls instead of load instructions.
45450 - */
45451 - if (task == current)
45452 - return mm;
45453 -
45454 - /*
45455 - * If current is actively ptrace'ing, and would also be
45456 - * permitted to freshly attach with ptrace now, permit it.
45457 - */
45458 - if (task_is_stopped_or_traced(task)) {
45459 - int match;
45460 - rcu_read_lock();
45461 - match = (ptrace_parent(task) == current);
45462 - rcu_read_unlock();
45463 - if (match && ptrace_may_access(task, PTRACE_MODE_ATTACH))
45464 - return mm;
45465 - }
45466 -
45467 - /*
45468 - * No one else is allowed.
45469 - */
45470 - mmput(mm);
45471 - return ERR_PTR(-EPERM);
45472 -}
45473 -
45474 -/*
45475 - * If current may access user memory in @task return a reference to the
45476 - * corresponding mm, otherwise ERR_PTR.
45477 - */
45478 -static struct mm_struct *check_mem_permission(struct task_struct *task)
45479 -{
45480 - struct mm_struct *mm;
45481 - int err;
45482 -
45483 - /*
45484 - * Avoid racing if task exec's as we might get a new mm but validate
45485 - * against old credentials.
45486 - */
45487 - err = mutex_lock_killable(&task->signal->cred_guard_mutex);
45488 - if (err)
45489 - return ERR_PTR(err);
45490 -
45491 - mm = __check_mem_permission(task);
45492 - mutex_unlock(&task->signal->cred_guard_mutex);
45493 -
45494 - return mm;
45495 -}
45496 -
45497 -struct mm_struct *mm_for_maps(struct task_struct *task)
45498 +static struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
45499 {
45500 struct mm_struct *mm;
45501 int err;
45502 @@ -262,16 +220,23 @@ struct mm_struct *mm_for_maps(struct task_struct *task)
45503 return ERR_PTR(err);
45504
45505 mm = get_task_mm(task);
45506 - if (mm && mm != current->mm &&
45507 - !ptrace_may_access(task, PTRACE_MODE_READ)) {
45508 - mmput(mm);
45509 - mm = ERR_PTR(-EACCES);
45510 + if (mm) {
45511 + if ((mm != current->mm && !ptrace_may_access(task, mode)) ||
45512 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task)))) {
45513 + mmput(mm);
45514 + mm = ERR_PTR(-EACCES);
45515 + }
45516 }
45517 mutex_unlock(&task->signal->cred_guard_mutex);
45518
45519 return mm;
45520 }
45521
45522 +struct mm_struct *mm_for_maps(struct task_struct *task)
45523 +{
45524 + return mm_access(task, PTRACE_MODE_READ);
45525 +}
45526 +
45527 static int proc_pid_cmdline(struct task_struct *task, char * buffer)
45528 {
45529 int res = 0;
45530 @@ -282,6 +247,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
45531 if (!mm->arg_end)
45532 goto out_mm; /* Shh! No looking before we're done */
45533
45534 + if (gr_acl_handle_procpidmem(task))
45535 + goto out_mm;
45536 +
45537 len = mm->arg_end - mm->arg_start;
45538
45539 if (len > PAGE_SIZE)
45540 @@ -309,12 +277,28 @@ out:
45541 return res;
45542 }
45543
45544 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45545 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45546 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
45547 + _mm->pax_flags & MF_PAX_SEGMEXEC))
45548 +#endif
45549 +
45550 static int proc_pid_auxv(struct task_struct *task, char *buffer)
45551 {
45552 struct mm_struct *mm = mm_for_maps(task);
45553 int res = PTR_ERR(mm);
45554 if (mm && !IS_ERR(mm)) {
45555 unsigned int nwords = 0;
45556 +
45557 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45558 + /* allow if we're currently ptracing this task */
45559 + if (PAX_RAND_FLAGS(mm) &&
45560 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
45561 + mmput(mm);
45562 + return 0;
45563 + }
45564 +#endif
45565 +
45566 do {
45567 nwords += 2;
45568 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
45569 @@ -328,7 +312,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
45570 }
45571
45572
45573 -#ifdef CONFIG_KALLSYMS
45574 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45575 /*
45576 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
45577 * Returns the resolved symbol. If that fails, simply return the address.
45578 @@ -367,7 +351,7 @@ static void unlock_trace(struct task_struct *task)
45579 mutex_unlock(&task->signal->cred_guard_mutex);
45580 }
45581
45582 -#ifdef CONFIG_STACKTRACE
45583 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45584
45585 #define MAX_STACK_TRACE_DEPTH 64
45586
45587 @@ -558,7 +542,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
45588 return count;
45589 }
45590
45591 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45592 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45593 static int proc_pid_syscall(struct task_struct *task, char *buffer)
45594 {
45595 long nr;
45596 @@ -587,7 +571,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
45597 /************************************************************************/
45598
45599 /* permission checks */
45600 -static int proc_fd_access_allowed(struct inode *inode)
45601 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
45602 {
45603 struct task_struct *task;
45604 int allowed = 0;
45605 @@ -597,7 +581,10 @@ static int proc_fd_access_allowed(struct inode *inode)
45606 */
45607 task = get_proc_task(inode);
45608 if (task) {
45609 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45610 + if (log)
45611 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
45612 + else
45613 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45614 put_task_struct(task);
45615 }
45616 return allowed;
45617 @@ -816,38 +803,39 @@ static const struct file_operations proc_single_file_operations = {
45618
45619 static int mem_open(struct inode* inode, struct file* file)
45620 {
45621 - file->private_data = (void*)((long)current->self_exec_id);
45622 + struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
45623 + struct mm_struct *mm;
45624 +
45625 + if (!task)
45626 + return -ESRCH;
45627 +
45628 + mm = mm_access(task, PTRACE_MODE_ATTACH);
45629 + put_task_struct(task);
45630 +
45631 + if (IS_ERR(mm))
45632 + return PTR_ERR(mm);
45633 +
45634 /* OK to pass negative loff_t, we can catch out-of-range */
45635 file->f_mode |= FMODE_UNSIGNED_OFFSET;
45636 + file->private_data = mm;
45637 +
45638 return 0;
45639 }
45640
45641 static ssize_t mem_read(struct file * file, char __user * buf,
45642 size_t count, loff_t *ppos)
45643 {
45644 - struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
45645 + int ret;
45646 char *page;
45647 unsigned long src = *ppos;
45648 - int ret = -ESRCH;
45649 - struct mm_struct *mm;
45650 + struct mm_struct *mm = file->private_data;
45651
45652 - if (!task)
45653 - goto out_no_task;
45654 + if (!mm)
45655 + return 0;
45656
45657 - ret = -ENOMEM;
45658 page = (char *)__get_free_page(GFP_TEMPORARY);
45659 if (!page)
45660 - goto out;
45661 -
45662 - mm = check_mem_permission(task);
45663 - ret = PTR_ERR(mm);
45664 - if (IS_ERR(mm))
45665 - goto out_free;
45666 -
45667 - ret = -EIO;
45668 -
45669 - if (file->private_data != (void*)((long)current->self_exec_id))
45670 - goto out_put;
45671 + return -ENOMEM;
45672
45673 ret = 0;
45674
45675 @@ -874,42 +862,28 @@ static ssize_t mem_read(struct file * file, char __user * buf,
45676 }
45677 *ppos = src;
45678
45679 -out_put:
45680 - mmput(mm);
45681 -out_free:
45682 free_page((unsigned long) page);
45683 -out:
45684 - put_task_struct(task);
45685 -out_no_task:
45686 return ret;
45687 }
45688
45689 +#define mem_write NULL
45690 +
45691 +#ifndef mem_write
45692 +/* They were right the first time */
45693 static ssize_t mem_write(struct file * file, const char __user *buf,
45694 size_t count, loff_t *ppos)
45695 {
45696 int copied;
45697 char *page;
45698 - struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
45699 unsigned long dst = *ppos;
45700 - struct mm_struct *mm;
45701 + struct mm_struct *mm = file->private_data;
45702
45703 - copied = -ESRCH;
45704 - if (!task)
45705 - goto out_no_task;
45706 + if (!mm)
45707 + return 0;
45708
45709 - copied = -ENOMEM;
45710 page = (char *)__get_free_page(GFP_TEMPORARY);
45711 if (!page)
45712 - goto out_task;
45713 -
45714 - mm = check_mem_permission(task);
45715 - copied = PTR_ERR(mm);
45716 - if (IS_ERR(mm))
45717 - goto out_free;
45718 -
45719 - copied = -EIO;
45720 - if (file->private_data != (void *)((long)current->self_exec_id))
45721 - goto out_mm;
45722 + return -ENOMEM;
45723
45724 copied = 0;
45725 while (count > 0) {
45726 @@ -933,15 +907,10 @@ static ssize_t mem_write(struct file * file, const char __user *buf,
45727 }
45728 *ppos = dst;
45729
45730 -out_mm:
45731 - mmput(mm);
45732 -out_free:
45733 free_page((unsigned long) page);
45734 -out_task:
45735 - put_task_struct(task);
45736 -out_no_task:
45737 return copied;
45738 }
45739 +#endif
45740
45741 loff_t mem_lseek(struct file *file, loff_t offset, int orig)
45742 {
45743 @@ -959,11 +928,20 @@ loff_t mem_lseek(struct file *file, loff_t offset, int orig)
45744 return file->f_pos;
45745 }
45746
45747 +static int mem_release(struct inode *inode, struct file *file)
45748 +{
45749 + struct mm_struct *mm = file->private_data;
45750 +
45751 + mmput(mm);
45752 + return 0;
45753 +}
45754 +
45755 static const struct file_operations proc_mem_operations = {
45756 .llseek = mem_lseek,
45757 .read = mem_read,
45758 .write = mem_write,
45759 .open = mem_open,
45760 + .release = mem_release,
45761 };
45762
45763 static ssize_t environ_read(struct file *file, char __user *buf,
45764 @@ -978,6 +956,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
45765 if (!task)
45766 goto out_no_task;
45767
45768 + if (gr_acl_handle_procpidmem(task))
45769 + goto out;
45770 +
45771 ret = -ENOMEM;
45772 page = (char *)__get_free_page(GFP_TEMPORARY);
45773 if (!page)
45774 @@ -1600,7 +1581,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
45775 path_put(&nd->path);
45776
45777 /* Are we allowed to snoop on the tasks file descriptors? */
45778 - if (!proc_fd_access_allowed(inode))
45779 + if (!proc_fd_access_allowed(inode,0))
45780 goto out;
45781
45782 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
45783 @@ -1639,8 +1620,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
45784 struct path path;
45785
45786 /* Are we allowed to snoop on the tasks file descriptors? */
45787 - if (!proc_fd_access_allowed(inode))
45788 - goto out;
45789 + /* logging this is needed for learning on chromium to work properly,
45790 + but we don't want to flood the logs from 'ps' which does a readlink
45791 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
45792 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
45793 + */
45794 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
45795 + if (!proc_fd_access_allowed(inode,0))
45796 + goto out;
45797 + } else {
45798 + if (!proc_fd_access_allowed(inode,1))
45799 + goto out;
45800 + }
45801
45802 error = PROC_I(inode)->op.proc_get_link(inode, &path);
45803 if (error)
45804 @@ -1705,7 +1696,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
45805 rcu_read_lock();
45806 cred = __task_cred(task);
45807 inode->i_uid = cred->euid;
45808 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45809 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45810 +#else
45811 inode->i_gid = cred->egid;
45812 +#endif
45813 rcu_read_unlock();
45814 }
45815 security_task_to_inode(task, inode);
45816 @@ -1723,6 +1718,9 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
45817 struct inode *inode = dentry->d_inode;
45818 struct task_struct *task;
45819 const struct cred *cred;
45820 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45821 + const struct cred *tmpcred = current_cred();
45822 +#endif
45823
45824 generic_fillattr(inode, stat);
45825
45826 @@ -1730,13 +1728,41 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
45827 stat->uid = 0;
45828 stat->gid = 0;
45829 task = pid_task(proc_pid(inode), PIDTYPE_PID);
45830 +
45831 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
45832 + rcu_read_unlock();
45833 + return -ENOENT;
45834 + }
45835 +
45836 if (task) {
45837 + cred = __task_cred(task);
45838 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45839 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
45840 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45841 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
45842 +#endif
45843 + ) {
45844 +#endif
45845 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45846 +#ifdef CONFIG_GRKERNSEC_PROC_USER
45847 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45848 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45849 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45850 +#endif
45851 task_dumpable(task)) {
45852 - cred = __task_cred(task);
45853 stat->uid = cred->euid;
45854 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45855 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
45856 +#else
45857 stat->gid = cred->egid;
45858 +#endif
45859 }
45860 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45861 + } else {
45862 + rcu_read_unlock();
45863 + return -ENOENT;
45864 + }
45865 +#endif
45866 }
45867 rcu_read_unlock();
45868 return 0;
45869 @@ -1773,11 +1799,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
45870
45871 if (task) {
45872 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45873 +#ifdef CONFIG_GRKERNSEC_PROC_USER
45874 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45875 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45876 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45877 +#endif
45878 task_dumpable(task)) {
45879 rcu_read_lock();
45880 cred = __task_cred(task);
45881 inode->i_uid = cred->euid;
45882 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45883 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45884 +#else
45885 inode->i_gid = cred->egid;
45886 +#endif
45887 rcu_read_unlock();
45888 } else {
45889 inode->i_uid = 0;
45890 @@ -1895,7 +1930,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
45891 int fd = proc_fd(inode);
45892
45893 if (task) {
45894 - files = get_files_struct(task);
45895 + if (!gr_acl_handle_procpidmem(task))
45896 + files = get_files_struct(task);
45897 put_task_struct(task);
45898 }
45899 if (files) {
45900 @@ -2163,11 +2199,21 @@ static const struct file_operations proc_fd_operations = {
45901 */
45902 static int proc_fd_permission(struct inode *inode, int mask)
45903 {
45904 + struct task_struct *task;
45905 int rv = generic_permission(inode, mask);
45906 - if (rv == 0)
45907 - return 0;
45908 +
45909 if (task_pid(current) == proc_pid(inode))
45910 rv = 0;
45911 +
45912 + task = get_proc_task(inode);
45913 + if (task == NULL)
45914 + return rv;
45915 +
45916 + if (gr_acl_handle_procpidmem(task))
45917 + rv = -EACCES;
45918 +
45919 + put_task_struct(task);
45920 +
45921 return rv;
45922 }
45923
45924 @@ -2277,6 +2323,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
45925 if (!task)
45926 goto out_no_task;
45927
45928 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45929 + goto out;
45930 +
45931 /*
45932 * Yes, it does not scale. And it should not. Don't add
45933 * new entries into /proc/<tgid>/ without very good reasons.
45934 @@ -2321,6 +2370,9 @@ static int proc_pident_readdir(struct file *filp,
45935 if (!task)
45936 goto out_no_task;
45937
45938 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45939 + goto out;
45940 +
45941 ret = 0;
45942 i = filp->f_pos;
45943 switch (i) {
45944 @@ -2591,7 +2643,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
45945 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
45946 void *cookie)
45947 {
45948 - char *s = nd_get_link(nd);
45949 + const char *s = nd_get_link(nd);
45950 if (!IS_ERR(s))
45951 __putname(s);
45952 }
45953 @@ -2789,7 +2841,7 @@ static const struct pid_entry tgid_base_stuff[] = {
45954 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
45955 #endif
45956 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
45957 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45958 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45959 INF("syscall", S_IRUGO, proc_pid_syscall),
45960 #endif
45961 INF("cmdline", S_IRUGO, proc_pid_cmdline),
45962 @@ -2814,10 +2866,10 @@ static const struct pid_entry tgid_base_stuff[] = {
45963 #ifdef CONFIG_SECURITY
45964 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
45965 #endif
45966 -#ifdef CONFIG_KALLSYMS
45967 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45968 INF("wchan", S_IRUGO, proc_pid_wchan),
45969 #endif
45970 -#ifdef CONFIG_STACKTRACE
45971 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45972 ONE("stack", S_IRUGO, proc_pid_stack),
45973 #endif
45974 #ifdef CONFIG_SCHEDSTATS
45975 @@ -2851,6 +2903,9 @@ static const struct pid_entry tgid_base_stuff[] = {
45976 #ifdef CONFIG_HARDWALL
45977 INF("hardwall", S_IRUGO, proc_pid_hardwall),
45978 #endif
45979 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45980 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
45981 +#endif
45982 };
45983
45984 static int proc_tgid_base_readdir(struct file * filp,
45985 @@ -2976,7 +3031,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
45986 if (!inode)
45987 goto out;
45988
45989 +#ifdef CONFIG_GRKERNSEC_PROC_USER
45990 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
45991 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45992 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45993 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
45994 +#else
45995 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
45996 +#endif
45997 inode->i_op = &proc_tgid_base_inode_operations;
45998 inode->i_fop = &proc_tgid_base_operations;
45999 inode->i_flags|=S_IMMUTABLE;
46000 @@ -3018,7 +3080,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
46001 if (!task)
46002 goto out;
46003
46004 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
46005 + goto out_put_task;
46006 +
46007 result = proc_pid_instantiate(dir, dentry, task, NULL);
46008 +out_put_task:
46009 put_task_struct(task);
46010 out:
46011 return result;
46012 @@ -3083,6 +3149,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
46013 {
46014 unsigned int nr;
46015 struct task_struct *reaper;
46016 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46017 + const struct cred *tmpcred = current_cred();
46018 + const struct cred *itercred;
46019 +#endif
46020 + filldir_t __filldir = filldir;
46021 struct tgid_iter iter;
46022 struct pid_namespace *ns;
46023
46024 @@ -3106,8 +3177,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
46025 for (iter = next_tgid(ns, iter);
46026 iter.task;
46027 iter.tgid += 1, iter = next_tgid(ns, iter)) {
46028 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46029 + rcu_read_lock();
46030 + itercred = __task_cred(iter.task);
46031 +#endif
46032 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
46033 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46034 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
46035 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
46036 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
46037 +#endif
46038 + )
46039 +#endif
46040 + )
46041 + __filldir = &gr_fake_filldir;
46042 + else
46043 + __filldir = filldir;
46044 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46045 + rcu_read_unlock();
46046 +#endif
46047 filp->f_pos = iter.tgid + TGID_OFFSET;
46048 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
46049 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
46050 put_task_struct(iter.task);
46051 goto out;
46052 }
46053 @@ -3135,7 +3225,7 @@ static const struct pid_entry tid_base_stuff[] = {
46054 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
46055 #endif
46056 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
46057 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
46058 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
46059 INF("syscall", S_IRUGO, proc_pid_syscall),
46060 #endif
46061 INF("cmdline", S_IRUGO, proc_pid_cmdline),
46062 @@ -3159,10 +3249,10 @@ static const struct pid_entry tid_base_stuff[] = {
46063 #ifdef CONFIG_SECURITY
46064 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
46065 #endif
46066 -#ifdef CONFIG_KALLSYMS
46067 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46068 INF("wchan", S_IRUGO, proc_pid_wchan),
46069 #endif
46070 -#ifdef CONFIG_STACKTRACE
46071 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46072 ONE("stack", S_IRUGO, proc_pid_stack),
46073 #endif
46074 #ifdef CONFIG_SCHEDSTATS
46075 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
46076 index 82676e3..5f8518a 100644
46077 --- a/fs/proc/cmdline.c
46078 +++ b/fs/proc/cmdline.c
46079 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
46080
46081 static int __init proc_cmdline_init(void)
46082 {
46083 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46084 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
46085 +#else
46086 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
46087 +#endif
46088 return 0;
46089 }
46090 module_init(proc_cmdline_init);
46091 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
46092 index b143471..bb105e5 100644
46093 --- a/fs/proc/devices.c
46094 +++ b/fs/proc/devices.c
46095 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
46096
46097 static int __init proc_devices_init(void)
46098 {
46099 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46100 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
46101 +#else
46102 proc_create("devices", 0, NULL, &proc_devinfo_operations);
46103 +#endif
46104 return 0;
46105 }
46106 module_init(proc_devices_init);
46107 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
46108 index 7737c54..7172574 100644
46109 --- a/fs/proc/inode.c
46110 +++ b/fs/proc/inode.c
46111 @@ -18,12 +18,18 @@
46112 #include <linux/module.h>
46113 #include <linux/sysctl.h>
46114 #include <linux/slab.h>
46115 +#include <linux/grsecurity.h>
46116
46117 #include <asm/system.h>
46118 #include <asm/uaccess.h>
46119
46120 #include "internal.h"
46121
46122 +#ifdef CONFIG_PROC_SYSCTL
46123 +extern const struct inode_operations proc_sys_inode_operations;
46124 +extern const struct inode_operations proc_sys_dir_operations;
46125 +#endif
46126 +
46127 static void proc_evict_inode(struct inode *inode)
46128 {
46129 struct proc_dir_entry *de;
46130 @@ -49,6 +55,13 @@ static void proc_evict_inode(struct inode *inode)
46131 ns_ops = PROC_I(inode)->ns_ops;
46132 if (ns_ops && ns_ops->put)
46133 ns_ops->put(PROC_I(inode)->ns);
46134 +
46135 +#ifdef CONFIG_PROC_SYSCTL
46136 + if (inode->i_op == &proc_sys_inode_operations ||
46137 + inode->i_op == &proc_sys_dir_operations)
46138 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
46139 +#endif
46140 +
46141 }
46142
46143 static struct kmem_cache * proc_inode_cachep;
46144 @@ -440,7 +453,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
46145 if (de->mode) {
46146 inode->i_mode = de->mode;
46147 inode->i_uid = de->uid;
46148 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
46149 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
46150 +#else
46151 inode->i_gid = de->gid;
46152 +#endif
46153 }
46154 if (de->size)
46155 inode->i_size = de->size;
46156 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
46157 index 7838e5c..ff92cbc 100644
46158 --- a/fs/proc/internal.h
46159 +++ b/fs/proc/internal.h
46160 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
46161 struct pid *pid, struct task_struct *task);
46162 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
46163 struct pid *pid, struct task_struct *task);
46164 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
46165 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
46166 +#endif
46167 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
46168
46169 extern const struct file_operations proc_maps_operations;
46170 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
46171 index d245cb2..f4e8498 100644
46172 --- a/fs/proc/kcore.c
46173 +++ b/fs/proc/kcore.c
46174 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46175 * the addresses in the elf_phdr on our list.
46176 */
46177 start = kc_offset_to_vaddr(*fpos - elf_buflen);
46178 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
46179 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
46180 + if (tsz > buflen)
46181 tsz = buflen;
46182 -
46183 +
46184 while (buflen) {
46185 struct kcore_list *m;
46186
46187 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46188 kfree(elf_buf);
46189 } else {
46190 if (kern_addr_valid(start)) {
46191 - unsigned long n;
46192 + char *elf_buf;
46193 + mm_segment_t oldfs;
46194
46195 - n = copy_to_user(buffer, (char *)start, tsz);
46196 - /*
46197 - * We cannot distingush between fault on source
46198 - * and fault on destination. When this happens
46199 - * we clear too and hope it will trigger the
46200 - * EFAULT again.
46201 - */
46202 - if (n) {
46203 - if (clear_user(buffer + tsz - n,
46204 - n))
46205 + elf_buf = kmalloc(tsz, GFP_KERNEL);
46206 + if (!elf_buf)
46207 + return -ENOMEM;
46208 + oldfs = get_fs();
46209 + set_fs(KERNEL_DS);
46210 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
46211 + set_fs(oldfs);
46212 + if (copy_to_user(buffer, elf_buf, tsz)) {
46213 + kfree(elf_buf);
46214 return -EFAULT;
46215 + }
46216 }
46217 + set_fs(oldfs);
46218 + kfree(elf_buf);
46219 } else {
46220 if (clear_user(buffer, tsz))
46221 return -EFAULT;
46222 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46223
46224 static int open_kcore(struct inode *inode, struct file *filp)
46225 {
46226 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
46227 + return -EPERM;
46228 +#endif
46229 if (!capable(CAP_SYS_RAWIO))
46230 return -EPERM;
46231 if (kcore_need_update)
46232 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
46233 index 80e4645..53e5fcf 100644
46234 --- a/fs/proc/meminfo.c
46235 +++ b/fs/proc/meminfo.c
46236 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
46237 vmi.used >> 10,
46238 vmi.largest_chunk >> 10
46239 #ifdef CONFIG_MEMORY_FAILURE
46240 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
46241 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
46242 #endif
46243 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
46244 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
46245 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
46246 index b1822dd..df622cb 100644
46247 --- a/fs/proc/nommu.c
46248 +++ b/fs/proc/nommu.c
46249 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
46250 if (len < 1)
46251 len = 1;
46252 seq_printf(m, "%*c", len, ' ');
46253 - seq_path(m, &file->f_path, "");
46254 + seq_path(m, &file->f_path, "\n\\");
46255 }
46256
46257 seq_putc(m, '\n');
46258 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
46259 index f738024..876984a 100644
46260 --- a/fs/proc/proc_net.c
46261 +++ b/fs/proc/proc_net.c
46262 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
46263 struct task_struct *task;
46264 struct nsproxy *ns;
46265 struct net *net = NULL;
46266 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46267 + const struct cred *cred = current_cred();
46268 +#endif
46269 +
46270 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46271 + if (cred->fsuid)
46272 + return net;
46273 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46274 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
46275 + return net;
46276 +#endif
46277
46278 rcu_read_lock();
46279 task = pid_task(proc_pid(dir), PIDTYPE_PID);
46280 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
46281 index a6b6217..1e0579d 100644
46282 --- a/fs/proc/proc_sysctl.c
46283 +++ b/fs/proc/proc_sysctl.c
46284 @@ -9,11 +9,13 @@
46285 #include <linux/namei.h>
46286 #include "internal.h"
46287
46288 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
46289 +
46290 static const struct dentry_operations proc_sys_dentry_operations;
46291 static const struct file_operations proc_sys_file_operations;
46292 -static const struct inode_operations proc_sys_inode_operations;
46293 +const struct inode_operations proc_sys_inode_operations;
46294 static const struct file_operations proc_sys_dir_file_operations;
46295 -static const struct inode_operations proc_sys_dir_operations;
46296 +const struct inode_operations proc_sys_dir_operations;
46297
46298 void proc_sys_poll_notify(struct ctl_table_poll *poll)
46299 {
46300 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
46301
46302 err = NULL;
46303 d_set_d_op(dentry, &proc_sys_dentry_operations);
46304 +
46305 + gr_handle_proc_create(dentry, inode);
46306 +
46307 d_add(dentry, inode);
46308
46309 + if (gr_handle_sysctl(p, MAY_EXEC))
46310 + err = ERR_PTR(-ENOENT);
46311 +
46312 out:
46313 sysctl_head_finish(head);
46314 return err;
46315 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
46316 if (!table->proc_handler)
46317 goto out;
46318
46319 +#ifdef CONFIG_GRKERNSEC
46320 + error = -EPERM;
46321 + if (write && !capable(CAP_SYS_ADMIN))
46322 + goto out;
46323 +#endif
46324 +
46325 /* careful: calling conventions are nasty here */
46326 res = count;
46327 error = table->proc_handler(table, write, buf, &res, ppos);
46328 @@ -245,6 +259,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
46329 return -ENOMEM;
46330 } else {
46331 d_set_d_op(child, &proc_sys_dentry_operations);
46332 +
46333 + gr_handle_proc_create(child, inode);
46334 +
46335 d_add(child, inode);
46336 }
46337 } else {
46338 @@ -273,6 +290,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
46339 if (*pos < file->f_pos)
46340 continue;
46341
46342 + if (gr_handle_sysctl(table, 0))
46343 + continue;
46344 +
46345 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
46346 if (res)
46347 return res;
46348 @@ -398,6 +418,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
46349 if (IS_ERR(head))
46350 return PTR_ERR(head);
46351
46352 + if (table && gr_handle_sysctl(table, MAY_EXEC))
46353 + return -ENOENT;
46354 +
46355 generic_fillattr(inode, stat);
46356 if (table)
46357 stat->mode = (stat->mode & S_IFMT) | table->mode;
46358 @@ -420,13 +443,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
46359 .llseek = generic_file_llseek,
46360 };
46361
46362 -static const struct inode_operations proc_sys_inode_operations = {
46363 +const struct inode_operations proc_sys_inode_operations = {
46364 .permission = proc_sys_permission,
46365 .setattr = proc_sys_setattr,
46366 .getattr = proc_sys_getattr,
46367 };
46368
46369 -static const struct inode_operations proc_sys_dir_operations = {
46370 +const struct inode_operations proc_sys_dir_operations = {
46371 .lookup = proc_sys_lookup,
46372 .permission = proc_sys_permission,
46373 .setattr = proc_sys_setattr,
46374 diff --git a/fs/proc/root.c b/fs/proc/root.c
46375 index 03102d9..4ae347e 100644
46376 --- a/fs/proc/root.c
46377 +++ b/fs/proc/root.c
46378 @@ -121,7 +121,15 @@ void __init proc_root_init(void)
46379 #ifdef CONFIG_PROC_DEVICETREE
46380 proc_device_tree_init();
46381 #endif
46382 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46383 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46384 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
46385 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46386 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
46387 +#endif
46388 +#else
46389 proc_mkdir("bus", NULL);
46390 +#endif
46391 proc_sys_init();
46392 }
46393
46394 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
46395 index e418c5a..e66a99c 100644
46396 --- a/fs/proc/task_mmu.c
46397 +++ b/fs/proc/task_mmu.c
46398 @@ -52,8 +52,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46399 "VmExe:\t%8lu kB\n"
46400 "VmLib:\t%8lu kB\n"
46401 "VmPTE:\t%8lu kB\n"
46402 - "VmSwap:\t%8lu kB\n",
46403 - hiwater_vm << (PAGE_SHIFT-10),
46404 + "VmSwap:\t%8lu kB\n"
46405 +
46406 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46407 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
46408 +#endif
46409 +
46410 + ,hiwater_vm << (PAGE_SHIFT-10),
46411 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
46412 mm->locked_vm << (PAGE_SHIFT-10),
46413 mm->pinned_vm << (PAGE_SHIFT-10),
46414 @@ -62,7 +67,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46415 data << (PAGE_SHIFT-10),
46416 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
46417 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
46418 - swap << (PAGE_SHIFT-10));
46419 + swap << (PAGE_SHIFT-10)
46420 +
46421 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46422 + , mm->context.user_cs_base, mm->context.user_cs_limit
46423 +#endif
46424 +
46425 + );
46426 }
46427
46428 unsigned long task_vsize(struct mm_struct *mm)
46429 @@ -209,6 +220,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
46430 return ret;
46431 }
46432
46433 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46434 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46435 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
46436 + _mm->pax_flags & MF_PAX_SEGMEXEC))
46437 +#endif
46438 +
46439 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46440 {
46441 struct mm_struct *mm = vma->vm_mm;
46442 @@ -227,13 +244,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46443 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
46444 }
46445
46446 - /* We don't show the stack guard page in /proc/maps */
46447 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46448 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
46449 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
46450 +#else
46451 start = vma->vm_start;
46452 - if (stack_guard_page_start(vma, start))
46453 - start += PAGE_SIZE;
46454 end = vma->vm_end;
46455 - if (stack_guard_page_end(vma, end))
46456 - end -= PAGE_SIZE;
46457 +#endif
46458
46459 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
46460 start,
46461 @@ -242,7 +259,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46462 flags & VM_WRITE ? 'w' : '-',
46463 flags & VM_EXEC ? 'x' : '-',
46464 flags & VM_MAYSHARE ? 's' : 'p',
46465 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46466 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
46467 +#else
46468 pgoff,
46469 +#endif
46470 MAJOR(dev), MINOR(dev), ino, &len);
46471
46472 /*
46473 @@ -251,7 +272,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46474 */
46475 if (file) {
46476 pad_len_spaces(m, len);
46477 - seq_path(m, &file->f_path, "\n");
46478 + seq_path(m, &file->f_path, "\n\\");
46479 } else {
46480 const char *name = arch_vma_name(vma);
46481 if (!name) {
46482 @@ -259,8 +280,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46483 if (vma->vm_start <= mm->brk &&
46484 vma->vm_end >= mm->start_brk) {
46485 name = "[heap]";
46486 - } else if (vma->vm_start <= mm->start_stack &&
46487 - vma->vm_end >= mm->start_stack) {
46488 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
46489 + (vma->vm_start <= mm->start_stack &&
46490 + vma->vm_end >= mm->start_stack)) {
46491 name = "[stack]";
46492 }
46493 } else {
46494 @@ -435,11 +457,16 @@ static int show_smap(struct seq_file *m, void *v)
46495 };
46496
46497 memset(&mss, 0, sizeof mss);
46498 - mss.vma = vma;
46499 - /* mmap_sem is held in m_start */
46500 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
46501 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
46502 -
46503 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46504 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
46505 +#endif
46506 + mss.vma = vma;
46507 + /* mmap_sem is held in m_start */
46508 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
46509 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
46510 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46511 + }
46512 +#endif
46513 show_map_vma(m, vma);
46514
46515 seq_printf(m,
46516 @@ -457,7 +484,11 @@ static int show_smap(struct seq_file *m, void *v)
46517 "KernelPageSize: %8lu kB\n"
46518 "MMUPageSize: %8lu kB\n"
46519 "Locked: %8lu kB\n",
46520 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46521 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
46522 +#else
46523 (vma->vm_end - vma->vm_start) >> 10,
46524 +#endif
46525 mss.resident >> 10,
46526 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
46527 mss.shared_clean >> 10,
46528 @@ -1033,7 +1064,7 @@ static int show_numa_map(struct seq_file *m, void *v)
46529
46530 if (file) {
46531 seq_printf(m, " file=");
46532 - seq_path(m, &file->f_path, "\n\t= ");
46533 + seq_path(m, &file->f_path, "\n\t\\= ");
46534 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
46535 seq_printf(m, " heap");
46536 } else if (vma->vm_start <= mm->start_stack &&
46537 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
46538 index 980de54..2a4db5f 100644
46539 --- a/fs/proc/task_nommu.c
46540 +++ b/fs/proc/task_nommu.c
46541 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46542 else
46543 bytes += kobjsize(mm);
46544
46545 - if (current->fs && current->fs->users > 1)
46546 + if (current->fs && atomic_read(&current->fs->users) > 1)
46547 sbytes += kobjsize(current->fs);
46548 else
46549 bytes += kobjsize(current->fs);
46550 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
46551
46552 if (file) {
46553 pad_len_spaces(m, len);
46554 - seq_path(m, &file->f_path, "");
46555 + seq_path(m, &file->f_path, "\n\\");
46556 } else if (mm) {
46557 if (vma->vm_start <= mm->start_stack &&
46558 vma->vm_end >= mm->start_stack) {
46559 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
46560 index d67908b..d13f6a6 100644
46561 --- a/fs/quota/netlink.c
46562 +++ b/fs/quota/netlink.c
46563 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
46564 void quota_send_warning(short type, unsigned int id, dev_t dev,
46565 const char warntype)
46566 {
46567 - static atomic_t seq;
46568 + static atomic_unchecked_t seq;
46569 struct sk_buff *skb;
46570 void *msg_head;
46571 int ret;
46572 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
46573 "VFS: Not enough memory to send quota warning.\n");
46574 return;
46575 }
46576 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
46577 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
46578 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
46579 if (!msg_head) {
46580 printk(KERN_ERR
46581 diff --git a/fs/readdir.c b/fs/readdir.c
46582 index 356f715..c918d38 100644
46583 --- a/fs/readdir.c
46584 +++ b/fs/readdir.c
46585 @@ -17,6 +17,7 @@
46586 #include <linux/security.h>
46587 #include <linux/syscalls.h>
46588 #include <linux/unistd.h>
46589 +#include <linux/namei.h>
46590
46591 #include <asm/uaccess.h>
46592
46593 @@ -67,6 +68,7 @@ struct old_linux_dirent {
46594
46595 struct readdir_callback {
46596 struct old_linux_dirent __user * dirent;
46597 + struct file * file;
46598 int result;
46599 };
46600
46601 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
46602 buf->result = -EOVERFLOW;
46603 return -EOVERFLOW;
46604 }
46605 +
46606 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46607 + return 0;
46608 +
46609 buf->result++;
46610 dirent = buf->dirent;
46611 if (!access_ok(VERIFY_WRITE, dirent,
46612 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
46613
46614 buf.result = 0;
46615 buf.dirent = dirent;
46616 + buf.file = file;
46617
46618 error = vfs_readdir(file, fillonedir, &buf);
46619 if (buf.result)
46620 @@ -142,6 +149,7 @@ struct linux_dirent {
46621 struct getdents_callback {
46622 struct linux_dirent __user * current_dir;
46623 struct linux_dirent __user * previous;
46624 + struct file * file;
46625 int count;
46626 int error;
46627 };
46628 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
46629 buf->error = -EOVERFLOW;
46630 return -EOVERFLOW;
46631 }
46632 +
46633 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46634 + return 0;
46635 +
46636 dirent = buf->previous;
46637 if (dirent) {
46638 if (__put_user(offset, &dirent->d_off))
46639 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
46640 buf.previous = NULL;
46641 buf.count = count;
46642 buf.error = 0;
46643 + buf.file = file;
46644
46645 error = vfs_readdir(file, filldir, &buf);
46646 if (error >= 0)
46647 @@ -229,6 +242,7 @@ out:
46648 struct getdents_callback64 {
46649 struct linux_dirent64 __user * current_dir;
46650 struct linux_dirent64 __user * previous;
46651 + struct file *file;
46652 int count;
46653 int error;
46654 };
46655 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
46656 buf->error = -EINVAL; /* only used if we fail.. */
46657 if (reclen > buf->count)
46658 return -EINVAL;
46659 +
46660 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46661 + return 0;
46662 +
46663 dirent = buf->previous;
46664 if (dirent) {
46665 if (__put_user(offset, &dirent->d_off))
46666 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
46667
46668 buf.current_dir = dirent;
46669 buf.previous = NULL;
46670 + buf.file = file;
46671 buf.count = count;
46672 buf.error = 0;
46673
46674 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
46675 error = buf.error;
46676 lastdirent = buf.previous;
46677 if (lastdirent) {
46678 - typeof(lastdirent->d_off) d_off = file->f_pos;
46679 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
46680 if (__put_user(d_off, &lastdirent->d_off))
46681 error = -EFAULT;
46682 else
46683 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
46684 index 60c0804..d814f98 100644
46685 --- a/fs/reiserfs/do_balan.c
46686 +++ b/fs/reiserfs/do_balan.c
46687 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
46688 return;
46689 }
46690
46691 - atomic_inc(&(fs_generation(tb->tb_sb)));
46692 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
46693 do_balance_starts(tb);
46694
46695 /* balance leaf returns 0 except if combining L R and S into
46696 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
46697 index 7a99811..a7c96c4 100644
46698 --- a/fs/reiserfs/procfs.c
46699 +++ b/fs/reiserfs/procfs.c
46700 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
46701 "SMALL_TAILS " : "NO_TAILS ",
46702 replay_only(sb) ? "REPLAY_ONLY " : "",
46703 convert_reiserfs(sb) ? "CONV " : "",
46704 - atomic_read(&r->s_generation_counter),
46705 + atomic_read_unchecked(&r->s_generation_counter),
46706 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
46707 SF(s_do_balance), SF(s_unneeded_left_neighbor),
46708 SF(s_good_search_by_key_reada), SF(s_bmaps),
46709 diff --git a/fs/select.c b/fs/select.c
46710 index d33418f..2a5345e 100644
46711 --- a/fs/select.c
46712 +++ b/fs/select.c
46713 @@ -20,6 +20,7 @@
46714 #include <linux/module.h>
46715 #include <linux/slab.h>
46716 #include <linux/poll.h>
46717 +#include <linux/security.h>
46718 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
46719 #include <linux/file.h>
46720 #include <linux/fdtable.h>
46721 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
46722 struct poll_list *walk = head;
46723 unsigned long todo = nfds;
46724
46725 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
46726 if (nfds > rlimit(RLIMIT_NOFILE))
46727 return -EINVAL;
46728
46729 diff --git a/fs/seq_file.c b/fs/seq_file.c
46730 index dba43c3..a99fb63 100644
46731 --- a/fs/seq_file.c
46732 +++ b/fs/seq_file.c
46733 @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m, loff_t offset)
46734 return 0;
46735 }
46736 if (!m->buf) {
46737 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46738 + m->size = PAGE_SIZE;
46739 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46740 if (!m->buf)
46741 return -ENOMEM;
46742 }
46743 @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m, loff_t offset)
46744 Eoverflow:
46745 m->op->stop(m, p);
46746 kfree(m->buf);
46747 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46748 + m->size <<= 1;
46749 + m->buf = kmalloc(m->size, GFP_KERNEL);
46750 return !m->buf ? -ENOMEM : -EAGAIN;
46751 }
46752
46753 @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
46754 m->version = file->f_version;
46755 /* grab buffer if we didn't have one */
46756 if (!m->buf) {
46757 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46758 + m->size = PAGE_SIZE;
46759 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46760 if (!m->buf)
46761 goto Enomem;
46762 }
46763 @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
46764 goto Fill;
46765 m->op->stop(m, p);
46766 kfree(m->buf);
46767 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46768 + m->size <<= 1;
46769 + m->buf = kmalloc(m->size, GFP_KERNEL);
46770 if (!m->buf)
46771 goto Enomem;
46772 m->count = 0;
46773 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
46774 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
46775 void *data)
46776 {
46777 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
46778 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
46779 int res = -ENOMEM;
46780
46781 if (op) {
46782 diff --git a/fs/splice.c b/fs/splice.c
46783 index fa2defa..8601650 100644
46784 --- a/fs/splice.c
46785 +++ b/fs/splice.c
46786 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
46787 pipe_lock(pipe);
46788
46789 for (;;) {
46790 - if (!pipe->readers) {
46791 + if (!atomic_read(&pipe->readers)) {
46792 send_sig(SIGPIPE, current, 0);
46793 if (!ret)
46794 ret = -EPIPE;
46795 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
46796 do_wakeup = 0;
46797 }
46798
46799 - pipe->waiting_writers++;
46800 + atomic_inc(&pipe->waiting_writers);
46801 pipe_wait(pipe);
46802 - pipe->waiting_writers--;
46803 + atomic_dec(&pipe->waiting_writers);
46804 }
46805
46806 pipe_unlock(pipe);
46807 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
46808 old_fs = get_fs();
46809 set_fs(get_ds());
46810 /* The cast to a user pointer is valid due to the set_fs() */
46811 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
46812 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
46813 set_fs(old_fs);
46814
46815 return res;
46816 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
46817 old_fs = get_fs();
46818 set_fs(get_ds());
46819 /* The cast to a user pointer is valid due to the set_fs() */
46820 - res = vfs_write(file, (const char __user *)buf, count, &pos);
46821 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
46822 set_fs(old_fs);
46823
46824 return res;
46825 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
46826 goto err;
46827
46828 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
46829 - vec[i].iov_base = (void __user *) page_address(page);
46830 + vec[i].iov_base = (void __force_user *) page_address(page);
46831 vec[i].iov_len = this_len;
46832 spd.pages[i] = page;
46833 spd.nr_pages++;
46834 @@ -846,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
46835 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
46836 {
46837 while (!pipe->nrbufs) {
46838 - if (!pipe->writers)
46839 + if (!atomic_read(&pipe->writers))
46840 return 0;
46841
46842 - if (!pipe->waiting_writers && sd->num_spliced)
46843 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
46844 return 0;
46845
46846 if (sd->flags & SPLICE_F_NONBLOCK)
46847 @@ -1182,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
46848 * out of the pipe right after the splice_to_pipe(). So set
46849 * PIPE_READERS appropriately.
46850 */
46851 - pipe->readers = 1;
46852 + atomic_set(&pipe->readers, 1);
46853
46854 current->splice_pipe = pipe;
46855 }
46856 @@ -1734,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
46857 ret = -ERESTARTSYS;
46858 break;
46859 }
46860 - if (!pipe->writers)
46861 + if (!atomic_read(&pipe->writers))
46862 break;
46863 - if (!pipe->waiting_writers) {
46864 + if (!atomic_read(&pipe->waiting_writers)) {
46865 if (flags & SPLICE_F_NONBLOCK) {
46866 ret = -EAGAIN;
46867 break;
46868 @@ -1768,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
46869 pipe_lock(pipe);
46870
46871 while (pipe->nrbufs >= pipe->buffers) {
46872 - if (!pipe->readers) {
46873 + if (!atomic_read(&pipe->readers)) {
46874 send_sig(SIGPIPE, current, 0);
46875 ret = -EPIPE;
46876 break;
46877 @@ -1781,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
46878 ret = -ERESTARTSYS;
46879 break;
46880 }
46881 - pipe->waiting_writers++;
46882 + atomic_inc(&pipe->waiting_writers);
46883 pipe_wait(pipe);
46884 - pipe->waiting_writers--;
46885 + atomic_dec(&pipe->waiting_writers);
46886 }
46887
46888 pipe_unlock(pipe);
46889 @@ -1819,14 +1819,14 @@ retry:
46890 pipe_double_lock(ipipe, opipe);
46891
46892 do {
46893 - if (!opipe->readers) {
46894 + if (!atomic_read(&opipe->readers)) {
46895 send_sig(SIGPIPE, current, 0);
46896 if (!ret)
46897 ret = -EPIPE;
46898 break;
46899 }
46900
46901 - if (!ipipe->nrbufs && !ipipe->writers)
46902 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
46903 break;
46904
46905 /*
46906 @@ -1923,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
46907 pipe_double_lock(ipipe, opipe);
46908
46909 do {
46910 - if (!opipe->readers) {
46911 + if (!atomic_read(&opipe->readers)) {
46912 send_sig(SIGPIPE, current, 0);
46913 if (!ret)
46914 ret = -EPIPE;
46915 @@ -1968,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
46916 * return EAGAIN if we have the potential of some data in the
46917 * future, otherwise just return 0
46918 */
46919 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
46920 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
46921 ret = -EAGAIN;
46922
46923 pipe_unlock(ipipe);
46924 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
46925 index d4e6080b..0e58b99 100644
46926 --- a/fs/sysfs/file.c
46927 +++ b/fs/sysfs/file.c
46928 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
46929
46930 struct sysfs_open_dirent {
46931 atomic_t refcnt;
46932 - atomic_t event;
46933 + atomic_unchecked_t event;
46934 wait_queue_head_t poll;
46935 struct list_head buffers; /* goes through sysfs_buffer.list */
46936 };
46937 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
46938 if (!sysfs_get_active(attr_sd))
46939 return -ENODEV;
46940
46941 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
46942 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
46943 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
46944
46945 sysfs_put_active(attr_sd);
46946 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
46947 return -ENOMEM;
46948
46949 atomic_set(&new_od->refcnt, 0);
46950 - atomic_set(&new_od->event, 1);
46951 + atomic_set_unchecked(&new_od->event, 1);
46952 init_waitqueue_head(&new_od->poll);
46953 INIT_LIST_HEAD(&new_od->buffers);
46954 goto retry;
46955 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
46956
46957 sysfs_put_active(attr_sd);
46958
46959 - if (buffer->event != atomic_read(&od->event))
46960 + if (buffer->event != atomic_read_unchecked(&od->event))
46961 goto trigger;
46962
46963 return DEFAULT_POLLMASK;
46964 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
46965
46966 od = sd->s_attr.open;
46967 if (od) {
46968 - atomic_inc(&od->event);
46969 + atomic_inc_unchecked(&od->event);
46970 wake_up_interruptible(&od->poll);
46971 }
46972
46973 diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
46974 index e34f0d9..740ea7b 100644
46975 --- a/fs/sysfs/mount.c
46976 +++ b/fs/sysfs/mount.c
46977 @@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
46978 .s_name = "",
46979 .s_count = ATOMIC_INIT(1),
46980 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
46981 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46982 + .s_mode = S_IFDIR | S_IRWXU,
46983 +#else
46984 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46985 +#endif
46986 .s_ino = 1,
46987 };
46988
46989 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
46990 index a7ac78f..02158e1 100644
46991 --- a/fs/sysfs/symlink.c
46992 +++ b/fs/sysfs/symlink.c
46993 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
46994
46995 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
46996 {
46997 - char *page = nd_get_link(nd);
46998 + const char *page = nd_get_link(nd);
46999 if (!IS_ERR(page))
47000 free_page((unsigned long)page);
47001 }
47002 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
47003 index c175b4d..8f36a16 100644
47004 --- a/fs/udf/misc.c
47005 +++ b/fs/udf/misc.c
47006 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
47007
47008 u8 udf_tag_checksum(const struct tag *t)
47009 {
47010 - u8 *data = (u8 *)t;
47011 + const u8 *data = (const u8 *)t;
47012 u8 checksum = 0;
47013 int i;
47014 for (i = 0; i < sizeof(struct tag); ++i)
47015 diff --git a/fs/utimes.c b/fs/utimes.c
47016 index ba653f3..06ea4b1 100644
47017 --- a/fs/utimes.c
47018 +++ b/fs/utimes.c
47019 @@ -1,6 +1,7 @@
47020 #include <linux/compiler.h>
47021 #include <linux/file.h>
47022 #include <linux/fs.h>
47023 +#include <linux/security.h>
47024 #include <linux/linkage.h>
47025 #include <linux/mount.h>
47026 #include <linux/namei.h>
47027 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
47028 goto mnt_drop_write_and_out;
47029 }
47030 }
47031 +
47032 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
47033 + error = -EACCES;
47034 + goto mnt_drop_write_and_out;
47035 + }
47036 +
47037 mutex_lock(&inode->i_mutex);
47038 error = notify_change(path->dentry, &newattrs);
47039 mutex_unlock(&inode->i_mutex);
47040 diff --git a/fs/xattr.c b/fs/xattr.c
47041 index 67583de..c5aad14 100644
47042 --- a/fs/xattr.c
47043 +++ b/fs/xattr.c
47044 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
47045 * Extended attribute SET operations
47046 */
47047 static long
47048 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
47049 +setxattr(struct path *path, const char __user *name, const void __user *value,
47050 size_t size, int flags)
47051 {
47052 int error;
47053 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
47054 return PTR_ERR(kvalue);
47055 }
47056
47057 - error = vfs_setxattr(d, kname, kvalue, size, flags);
47058 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
47059 + error = -EACCES;
47060 + goto out;
47061 + }
47062 +
47063 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
47064 +out:
47065 kfree(kvalue);
47066 return error;
47067 }
47068 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
47069 return error;
47070 error = mnt_want_write(path.mnt);
47071 if (!error) {
47072 - error = setxattr(path.dentry, name, value, size, flags);
47073 + error = setxattr(&path, name, value, size, flags);
47074 mnt_drop_write(path.mnt);
47075 }
47076 path_put(&path);
47077 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
47078 return error;
47079 error = mnt_want_write(path.mnt);
47080 if (!error) {
47081 - error = setxattr(path.dentry, name, value, size, flags);
47082 + error = setxattr(&path, name, value, size, flags);
47083 mnt_drop_write(path.mnt);
47084 }
47085 path_put(&path);
47086 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
47087 const void __user *,value, size_t, size, int, flags)
47088 {
47089 struct file *f;
47090 - struct dentry *dentry;
47091 int error = -EBADF;
47092
47093 f = fget(fd);
47094 if (!f)
47095 return error;
47096 - dentry = f->f_path.dentry;
47097 - audit_inode(NULL, dentry);
47098 + audit_inode(NULL, f->f_path.dentry);
47099 error = mnt_want_write_file(f);
47100 if (!error) {
47101 - error = setxattr(dentry, name, value, size, flags);
47102 + error = setxattr(&f->f_path, name, value, size, flags);
47103 mnt_drop_write(f->f_path.mnt);
47104 }
47105 fput(f);
47106 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
47107 index 8d5a506..7f62712 100644
47108 --- a/fs/xattr_acl.c
47109 +++ b/fs/xattr_acl.c
47110 @@ -17,8 +17,8 @@
47111 struct posix_acl *
47112 posix_acl_from_xattr(const void *value, size_t size)
47113 {
47114 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
47115 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
47116 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
47117 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
47118 int count;
47119 struct posix_acl *acl;
47120 struct posix_acl_entry *acl_e;
47121 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
47122 index d0ab788..827999b 100644
47123 --- a/fs/xfs/xfs_bmap.c
47124 +++ b/fs/xfs/xfs_bmap.c
47125 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
47126 int nmap,
47127 int ret_nmap);
47128 #else
47129 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
47130 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
47131 #endif /* DEBUG */
47132
47133 STATIC int
47134 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
47135 index 79d05e8..e3e5861 100644
47136 --- a/fs/xfs/xfs_dir2_sf.c
47137 +++ b/fs/xfs/xfs_dir2_sf.c
47138 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
47139 }
47140
47141 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
47142 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
47143 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
47144 + char name[sfep->namelen];
47145 + memcpy(name, sfep->name, sfep->namelen);
47146 + if (filldir(dirent, name, sfep->namelen,
47147 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
47148 + *offset = off & 0x7fffffff;
47149 + return 0;
47150 + }
47151 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
47152 off & 0x7fffffff, ino, DT_UNKNOWN)) {
47153 *offset = off & 0x7fffffff;
47154 return 0;
47155 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
47156 index d99a905..9f88202 100644
47157 --- a/fs/xfs/xfs_ioctl.c
47158 +++ b/fs/xfs/xfs_ioctl.c
47159 @@ -128,7 +128,7 @@ xfs_find_handle(
47160 }
47161
47162 error = -EFAULT;
47163 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
47164 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
47165 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
47166 goto out_put;
47167
47168 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
47169 index 23ce927..e274cc1 100644
47170 --- a/fs/xfs/xfs_iops.c
47171 +++ b/fs/xfs/xfs_iops.c
47172 @@ -447,7 +447,7 @@ xfs_vn_put_link(
47173 struct nameidata *nd,
47174 void *p)
47175 {
47176 - char *s = nd_get_link(nd);
47177 + const char *s = nd_get_link(nd);
47178
47179 if (!IS_ERR(s))
47180 kfree(s);
47181 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
47182 new file mode 100644
47183 index 0000000..fbe6950d9
47184 --- /dev/null
47185 +++ b/grsecurity/Kconfig
47186 @@ -0,0 +1,1067 @@
47187 +#
47188 +# grecurity configuration
47189 +#
47190 +
47191 +menu "Grsecurity"
47192 +
47193 +config GRKERNSEC
47194 + bool "Grsecurity"
47195 + select CRYPTO
47196 + select CRYPTO_SHA256
47197 + help
47198 + If you say Y here, you will be able to configure many features
47199 + that will enhance the security of your system. It is highly
47200 + recommended that you say Y here and read through the help
47201 + for each option so that you fully understand the features and
47202 + can evaluate their usefulness for your machine.
47203 +
47204 +choice
47205 + prompt "Security Level"
47206 + depends on GRKERNSEC
47207 + default GRKERNSEC_CUSTOM
47208 +
47209 +config GRKERNSEC_LOW
47210 + bool "Low"
47211 + select GRKERNSEC_LINK
47212 + select GRKERNSEC_FIFO
47213 + select GRKERNSEC_RANDNET
47214 + select GRKERNSEC_DMESG
47215 + select GRKERNSEC_CHROOT
47216 + select GRKERNSEC_CHROOT_CHDIR
47217 +
47218 + help
47219 + If you choose this option, several of the grsecurity options will
47220 + be enabled that will give you greater protection against a number
47221 + of attacks, while assuring that none of your software will have any
47222 + conflicts with the additional security measures. If you run a lot
47223 + of unusual software, or you are having problems with the higher
47224 + security levels, you should say Y here. With this option, the
47225 + following features are enabled:
47226 +
47227 + - Linking restrictions
47228 + - FIFO restrictions
47229 + - Restricted dmesg
47230 + - Enforced chdir("/") on chroot
47231 + - Runtime module disabling
47232 +
47233 +config GRKERNSEC_MEDIUM
47234 + bool "Medium"
47235 + select PAX
47236 + select PAX_EI_PAX
47237 + select PAX_PT_PAX_FLAGS
47238 + select PAX_HAVE_ACL_FLAGS
47239 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
47240 + select GRKERNSEC_CHROOT
47241 + select GRKERNSEC_CHROOT_SYSCTL
47242 + select GRKERNSEC_LINK
47243 + select GRKERNSEC_FIFO
47244 + select GRKERNSEC_DMESG
47245 + select GRKERNSEC_RANDNET
47246 + select GRKERNSEC_FORKFAIL
47247 + select GRKERNSEC_TIME
47248 + select GRKERNSEC_SIGNAL
47249 + select GRKERNSEC_CHROOT
47250 + select GRKERNSEC_CHROOT_UNIX
47251 + select GRKERNSEC_CHROOT_MOUNT
47252 + select GRKERNSEC_CHROOT_PIVOT
47253 + select GRKERNSEC_CHROOT_DOUBLE
47254 + select GRKERNSEC_CHROOT_CHDIR
47255 + select GRKERNSEC_CHROOT_MKNOD
47256 + select GRKERNSEC_PROC
47257 + select GRKERNSEC_PROC_USERGROUP
47258 + select PAX_RANDUSTACK
47259 + select PAX_ASLR
47260 + select PAX_RANDMMAP
47261 + select PAX_REFCOUNT if (X86 || SPARC64)
47262 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
47263 +
47264 + help
47265 + If you say Y here, several features in addition to those included
47266 + in the low additional security level will be enabled. These
47267 + features provide even more security to your system, though in rare
47268 + cases they may be incompatible with very old or poorly written
47269 + software. If you enable this option, make sure that your auth
47270 + service (identd) is running as gid 1001. With this option,
47271 + the following features (in addition to those provided in the
47272 + low additional security level) will be enabled:
47273 +
47274 + - Failed fork logging
47275 + - Time change logging
47276 + - Signal logging
47277 + - Deny mounts in chroot
47278 + - Deny double chrooting
47279 + - Deny sysctl writes in chroot
47280 + - Deny mknod in chroot
47281 + - Deny access to abstract AF_UNIX sockets out of chroot
47282 + - Deny pivot_root in chroot
47283 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
47284 + - /proc restrictions with special GID set to 10 (usually wheel)
47285 + - Address Space Layout Randomization (ASLR)
47286 + - Prevent exploitation of most refcount overflows
47287 + - Bounds checking of copying between the kernel and userland
47288 +
47289 +config GRKERNSEC_HIGH
47290 + bool "High"
47291 + select GRKERNSEC_LINK
47292 + select GRKERNSEC_FIFO
47293 + select GRKERNSEC_DMESG
47294 + select GRKERNSEC_FORKFAIL
47295 + select GRKERNSEC_TIME
47296 + select GRKERNSEC_SIGNAL
47297 + select GRKERNSEC_CHROOT
47298 + select GRKERNSEC_CHROOT_SHMAT
47299 + select GRKERNSEC_CHROOT_UNIX
47300 + select GRKERNSEC_CHROOT_MOUNT
47301 + select GRKERNSEC_CHROOT_FCHDIR
47302 + select GRKERNSEC_CHROOT_PIVOT
47303 + select GRKERNSEC_CHROOT_DOUBLE
47304 + select GRKERNSEC_CHROOT_CHDIR
47305 + select GRKERNSEC_CHROOT_MKNOD
47306 + select GRKERNSEC_CHROOT_CAPS
47307 + select GRKERNSEC_CHROOT_SYSCTL
47308 + select GRKERNSEC_CHROOT_FINDTASK
47309 + select GRKERNSEC_SYSFS_RESTRICT
47310 + select GRKERNSEC_PROC
47311 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
47312 + select GRKERNSEC_HIDESYM
47313 + select GRKERNSEC_BRUTE
47314 + select GRKERNSEC_PROC_USERGROUP
47315 + select GRKERNSEC_KMEM
47316 + select GRKERNSEC_RESLOG
47317 + select GRKERNSEC_RANDNET
47318 + select GRKERNSEC_PROC_ADD
47319 + select GRKERNSEC_CHROOT_CHMOD
47320 + select GRKERNSEC_CHROOT_NICE
47321 + select GRKERNSEC_SETXID
47322 + select GRKERNSEC_AUDIT_MOUNT
47323 + select GRKERNSEC_MODHARDEN if (MODULES)
47324 + select GRKERNSEC_HARDEN_PTRACE
47325 + select GRKERNSEC_PTRACE_READEXEC
47326 + select GRKERNSEC_VM86 if (X86_32)
47327 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
47328 + select PAX
47329 + select PAX_RANDUSTACK
47330 + select PAX_ASLR
47331 + select PAX_RANDMMAP
47332 + select PAX_NOEXEC
47333 + select PAX_MPROTECT
47334 + select PAX_EI_PAX
47335 + select PAX_PT_PAX_FLAGS
47336 + select PAX_HAVE_ACL_FLAGS
47337 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
47338 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
47339 + select PAX_RANDKSTACK if (X86_TSC && X86)
47340 + select PAX_SEGMEXEC if (X86_32)
47341 + select PAX_PAGEEXEC
47342 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
47343 + select PAX_EMUTRAMP if (PARISC)
47344 + select PAX_EMUSIGRT if (PARISC)
47345 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
47346 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
47347 + select PAX_REFCOUNT if (X86 || SPARC64)
47348 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
47349 + help
47350 + If you say Y here, many of the features of grsecurity will be
47351 + enabled, which will protect you against many kinds of attacks
47352 + against your system. The heightened security comes at a cost
47353 + of an increased chance of incompatibilities with rare software
47354 + on your machine. Since this security level enables PaX, you should
47355 + view <http://pax.grsecurity.net> and read about the PaX
47356 + project. While you are there, download chpax and run it on
47357 + binaries that cause problems with PaX. Also remember that
47358 + since the /proc restrictions are enabled, you must run your
47359 + identd as gid 1001. This security level enables the following
47360 + features in addition to those listed in the low and medium
47361 + security levels:
47362 +
47363 + - Additional /proc restrictions
47364 + - Chmod restrictions in chroot
47365 + - No signals, ptrace, or viewing of processes outside of chroot
47366 + - Capability restrictions in chroot
47367 + - Deny fchdir out of chroot
47368 + - Priority restrictions in chroot
47369 + - Segmentation-based implementation of PaX
47370 + - Mprotect restrictions
47371 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
47372 + - Kernel stack randomization
47373 + - Mount/unmount/remount logging
47374 + - Kernel symbol hiding
47375 + - Hardening of module auto-loading
47376 + - Ptrace restrictions
47377 + - Restricted vm86 mode
47378 + - Restricted sysfs/debugfs
47379 + - Active kernel exploit response
47380 +
47381 +config GRKERNSEC_CUSTOM
47382 + bool "Custom"
47383 + help
47384 + If you say Y here, you will be able to configure every grsecurity
47385 + option, which allows you to enable many more features that aren't
47386 + covered in the basic security levels. These additional features
47387 + include TPE, socket restrictions, and the sysctl system for
47388 + grsecurity. It is advised that you read through the help for
47389 + each option to determine its usefulness in your situation.
47390 +
47391 +endchoice
47392 +
47393 +menu "Address Space Protection"
47394 +depends on GRKERNSEC
47395 +
47396 +config GRKERNSEC_KMEM
47397 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
47398 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
47399 + help
47400 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
47401 + be written to or read from to modify or leak the contents of the running
47402 + kernel. /dev/port will also not be allowed to be opened. If you have module
47403 + support disabled, enabling this will close up four ways that are
47404 + currently used to insert malicious code into the running kernel.
47405 + Even with all these features enabled, we still highly recommend that
47406 + you use the RBAC system, as it is still possible for an attacker to
47407 + modify the running kernel through privileged I/O granted by ioperm/iopl.
47408 + If you are not using XFree86, you may be able to stop this additional
47409 + case by enabling the 'Disable privileged I/O' option. Though nothing
47410 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
47411 + but only to video memory, which is the only writing we allow in this
47412 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
47413 + not be allowed to mprotect it with PROT_WRITE later.
47414 + It is highly recommended that you say Y here if you meet all the
47415 + conditions above.
47416 +
47417 +config GRKERNSEC_VM86
47418 + bool "Restrict VM86 mode"
47419 + depends on X86_32
47420 +
47421 + help
47422 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
47423 + make use of a special execution mode on 32bit x86 processors called
47424 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
47425 + video cards and will still work with this option enabled. The purpose
47426 + of the option is to prevent exploitation of emulation errors in
47427 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
47428 + Nearly all users should be able to enable this option.
47429 +
47430 +config GRKERNSEC_IO
47431 + bool "Disable privileged I/O"
47432 + depends on X86
47433 + select RTC_CLASS
47434 + select RTC_INTF_DEV
47435 + select RTC_DRV_CMOS
47436 +
47437 + help
47438 + If you say Y here, all ioperm and iopl calls will return an error.
47439 + Ioperm and iopl can be used to modify the running kernel.
47440 + Unfortunately, some programs need this access to operate properly,
47441 + the most notable of which are XFree86 and hwclock. hwclock can be
47442 + remedied by having RTC support in the kernel, so real-time
47443 + clock support is enabled if this option is enabled, to ensure
47444 + that hwclock operates correctly. XFree86 still will not
47445 + operate correctly with this option enabled, so DO NOT CHOOSE Y
47446 + IF YOU USE XFree86. If you use XFree86 and you still want to
47447 + protect your kernel against modification, use the RBAC system.
47448 +
47449 +config GRKERNSEC_PROC_MEMMAP
47450 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
47451 + default y if (PAX_NOEXEC || PAX_ASLR)
47452 + depends on PAX_NOEXEC || PAX_ASLR
47453 + help
47454 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
47455 + give no information about the addresses of its mappings if
47456 + PaX features that rely on random addresses are enabled on the task.
47457 + If you use PaX it is greatly recommended that you say Y here as it
47458 + closes up a hole that makes the full ASLR useless for suid
47459 + binaries.
47460 +
47461 +config GRKERNSEC_BRUTE
47462 + bool "Deter exploit bruteforcing"
47463 + help
47464 + If you say Y here, attempts to bruteforce exploits against forking
47465 + daemons such as apache or sshd, as well as against suid/sgid binaries
47466 + will be deterred. When a child of a forking daemon is killed by PaX
47467 + or crashes due to an illegal instruction or other suspicious signal,
47468 + the parent process will be delayed 30 seconds upon every subsequent
47469 + fork until the administrator is able to assess the situation and
47470 + restart the daemon.
47471 + In the suid/sgid case, the attempt is logged, the user has all their
47472 + processes terminated, and they are prevented from executing any further
47473 + processes for 15 minutes.
47474 + It is recommended that you also enable signal logging in the auditing
47475 + section so that logs are generated when a process triggers a suspicious
47476 + signal.
47477 + If the sysctl option is enabled, a sysctl option with name
47478 + "deter_bruteforce" is created.
47479 +
47480 +
47481 +config GRKERNSEC_MODHARDEN
47482 + bool "Harden module auto-loading"
47483 + depends on MODULES
47484 + help
47485 + If you say Y here, module auto-loading in response to use of some
47486 + feature implemented by an unloaded module will be restricted to
47487 + root users. Enabling this option helps defend against attacks
47488 + by unprivileged users who abuse the auto-loading behavior to
47489 + cause a vulnerable module to load that is then exploited.
47490 +
47491 + If this option prevents a legitimate use of auto-loading for a
47492 + non-root user, the administrator can execute modprobe manually
47493 + with the exact name of the module mentioned in the alert log.
47494 + Alternatively, the administrator can add the module to the list
47495 + of modules loaded at boot by modifying init scripts.
47496 +
47497 + Modification of init scripts will most likely be needed on
47498 + Ubuntu servers with encrypted home directory support enabled,
47499 + as the first non-root user logging in will cause the ecb(aes),
47500 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
47501 +
47502 +config GRKERNSEC_HIDESYM
47503 + bool "Hide kernel symbols"
47504 + help
47505 + If you say Y here, getting information on loaded modules, and
47506 + displaying all kernel symbols through a syscall will be restricted
47507 + to users with CAP_SYS_MODULE. For software compatibility reasons,
47508 + /proc/kallsyms will be restricted to the root user. The RBAC
47509 + system can hide that entry even from root.
47510 +
47511 + This option also prevents leaking of kernel addresses through
47512 + several /proc entries.
47513 +
47514 + Note that this option is only effective provided the following
47515 + conditions are met:
47516 + 1) The kernel using grsecurity is not precompiled by some distribution
47517 + 2) You have also enabled GRKERNSEC_DMESG
47518 + 3) You are using the RBAC system and hiding other files such as your
47519 + kernel image and System.map. Alternatively, enabling this option
47520 + causes the permissions on /boot, /lib/modules, and the kernel
47521 + source directory to change at compile time to prevent
47522 + reading by non-root users.
47523 + If the above conditions are met, this option will aid in providing a
47524 + useful protection against local kernel exploitation of overflows
47525 + and arbitrary read/write vulnerabilities.
47526 +
47527 +config GRKERNSEC_KERN_LOCKOUT
47528 + bool "Active kernel exploit response"
47529 + depends on X86 || ARM || PPC || SPARC
47530 + help
47531 + If you say Y here, when a PaX alert is triggered due to suspicious
47532 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
47533 + or an OOPs occurs due to bad memory accesses, instead of just
47534 + terminating the offending process (and potentially allowing
47535 + a subsequent exploit from the same user), we will take one of two
47536 + actions:
47537 + If the user was root, we will panic the system
47538 + If the user was non-root, we will log the attempt, terminate
47539 + all processes owned by the user, then prevent them from creating
47540 + any new processes until the system is restarted
47541 + This deters repeated kernel exploitation/bruteforcing attempts
47542 + and is useful for later forensics.
47543 +
47544 +endmenu
47545 +menu "Role Based Access Control Options"
47546 +depends on GRKERNSEC
47547 +
47548 +config GRKERNSEC_RBAC_DEBUG
47549 + bool
47550 +
47551 +config GRKERNSEC_NO_RBAC
47552 + bool "Disable RBAC system"
47553 + help
47554 + If you say Y here, the /dev/grsec device will be removed from the kernel,
47555 + preventing the RBAC system from being enabled. You should only say Y
47556 + here if you have no intention of using the RBAC system, so as to prevent
47557 + an attacker with root access from misusing the RBAC system to hide files
47558 + and processes when loadable module support and /dev/[k]mem have been
47559 + locked down.
47560 +
47561 +config GRKERNSEC_ACL_HIDEKERN
47562 + bool "Hide kernel processes"
47563 + help
47564 + If you say Y here, all kernel threads will be hidden to all
47565 + processes but those whose subject has the "view hidden processes"
47566 + flag.
47567 +
47568 +config GRKERNSEC_ACL_MAXTRIES
47569 + int "Maximum tries before password lockout"
47570 + default 3
47571 + help
47572 + This option enforces the maximum number of times a user can attempt
47573 + to authorize themselves with the grsecurity RBAC system before being
47574 + denied the ability to attempt authorization again for a specified time.
47575 + The lower the number, the harder it will be to brute-force a password.
47576 +
47577 +config GRKERNSEC_ACL_TIMEOUT
47578 + int "Time to wait after max password tries, in seconds"
47579 + default 30
47580 + help
47581 + This option specifies the time the user must wait after attempting to
47582 + authorize to the RBAC system with the maximum number of invalid
47583 + passwords. The higher the number, the harder it will be to brute-force
47584 + a password.
47585 +
47586 +endmenu
47587 +menu "Filesystem Protections"
47588 +depends on GRKERNSEC
47589 +
47590 +config GRKERNSEC_PROC
47591 + bool "Proc restrictions"
47592 + help
47593 + If you say Y here, the permissions of the /proc filesystem
47594 + will be altered to enhance system security and privacy. You MUST
47595 + choose either a user only restriction or a user and group restriction.
47596 + Depending upon the option you choose, you can either restrict users to
47597 + see only the processes they themselves run, or choose a group that can
47598 + view all processes and files normally restricted to root if you choose
47599 + the "restrict to user only" option. NOTE: If you're running identd as
47600 + a non-root user, you will have to run it as the group you specify here.
47601 +
47602 +config GRKERNSEC_PROC_USER
47603 + bool "Restrict /proc to user only"
47604 + depends on GRKERNSEC_PROC
47605 + help
47606 + If you say Y here, non-root users will only be able to view their own
47607 + processes, and restricts them from viewing network-related information,
47608 + and viewing kernel symbol and module information.
47609 +
47610 +config GRKERNSEC_PROC_USERGROUP
47611 + bool "Allow special group"
47612 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
47613 + help
47614 + If you say Y here, you will be able to select a group that will be
47615 + able to view all processes and network-related information. If you've
47616 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
47617 + remain hidden. This option is useful if you want to run identd as
47618 + a non-root user.
47619 +
47620 +config GRKERNSEC_PROC_GID
47621 + int "GID for special group"
47622 + depends on GRKERNSEC_PROC_USERGROUP
47623 + default 1001
47624 +
47625 +config GRKERNSEC_PROC_ADD
47626 + bool "Additional restrictions"
47627 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
47628 + help
47629 + If you say Y here, additional restrictions will be placed on
47630 + /proc that keep normal users from viewing device information and
47631 + slabinfo information that could be useful for exploits.
47632 +
47633 +config GRKERNSEC_LINK
47634 + bool "Linking restrictions"
47635 + help
47636 + If you say Y here, /tmp race exploits will be prevented, since users
47637 + will no longer be able to follow symlinks owned by other users in
47638 + world-writable +t directories (e.g. /tmp), unless the owner of the
47639 + symlink is the owner of the directory. users will also not be
47640 + able to hardlink to files they do not own. If the sysctl option is
47641 + enabled, a sysctl option with name "linking_restrictions" is created.
47642 +
47643 +config GRKERNSEC_FIFO
47644 + bool "FIFO restrictions"
47645 + help
47646 + If you say Y here, users will not be able to write to FIFOs they don't
47647 + own in world-writable +t directories (e.g. /tmp), unless the owner of
47648 + the FIFO is the same owner of the directory it's held in. If the sysctl
47649 + option is enabled, a sysctl option with name "fifo_restrictions" is
47650 + created.
47651 +
47652 +config GRKERNSEC_SYSFS_RESTRICT
47653 + bool "Sysfs/debugfs restriction"
47654 + depends on SYSFS
47655 + help
47656 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
47657 + any filesystem normally mounted under it (e.g. debugfs) will only
47658 + be accessible by root. These filesystems generally provide access
47659 + to hardware and debug information that isn't appropriate for unprivileged
47660 + users of the system. Sysfs and debugfs have also become a large source
47661 + of new vulnerabilities, ranging from infoleaks to local compromise.
47662 + There has been very little oversight with an eye toward security involved
47663 + in adding new exporters of information to these filesystems, so their
47664 + use is discouraged.
47665 + This option is equivalent to a chmod 0700 of the mount paths.
47666 +
47667 +config GRKERNSEC_ROFS
47668 + bool "Runtime read-only mount protection"
47669 + help
47670 + If you say Y here, a sysctl option with name "romount_protect" will
47671 + be created. By setting this option to 1 at runtime, filesystems
47672 + will be protected in the following ways:
47673 + * No new writable mounts will be allowed
47674 + * Existing read-only mounts won't be able to be remounted read/write
47675 + * Write operations will be denied on all block devices
47676 + This option acts independently of grsec_lock: once it is set to 1,
47677 + it cannot be turned off. Therefore, please be mindful of the resulting
47678 + behavior if this option is enabled in an init script on a read-only
47679 + filesystem. This feature is mainly intended for secure embedded systems.
47680 +
47681 +config GRKERNSEC_CHROOT
47682 + bool "Chroot jail restrictions"
47683 + help
47684 + If you say Y here, you will be able to choose several options that will
47685 + make breaking out of a chrooted jail much more difficult. If you
47686 + encounter no software incompatibilities with the following options, it
47687 + is recommended that you enable each one.
47688 +
47689 +config GRKERNSEC_CHROOT_MOUNT
47690 + bool "Deny mounts"
47691 + depends on GRKERNSEC_CHROOT
47692 + help
47693 + If you say Y here, processes inside a chroot will not be able to
47694 + mount or remount filesystems. If the sysctl option is enabled, a
47695 + sysctl option with name "chroot_deny_mount" is created.
47696 +
47697 +config GRKERNSEC_CHROOT_DOUBLE
47698 + bool "Deny double-chroots"
47699 + depends on GRKERNSEC_CHROOT
47700 + help
47701 + If you say Y here, processes inside a chroot will not be able to chroot
47702 + again outside the chroot. This is a widely used method of breaking
47703 + out of a chroot jail and should not be allowed. If the sysctl
47704 + option is enabled, a sysctl option with name
47705 + "chroot_deny_chroot" is created.
47706 +
47707 +config GRKERNSEC_CHROOT_PIVOT
47708 + bool "Deny pivot_root in chroot"
47709 + depends on GRKERNSEC_CHROOT
47710 + help
47711 + If you say Y here, processes inside a chroot will not be able to use
47712 + a function called pivot_root() that was introduced in Linux 2.3.41. It
47713 + works similar to chroot in that it changes the root filesystem. This
47714 + function could be misused in a chrooted process to attempt to break out
47715 + of the chroot, and therefore should not be allowed. If the sysctl
47716 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
47717 + created.
47718 +
47719 +config GRKERNSEC_CHROOT_CHDIR
47720 + bool "Enforce chdir(\"/\") on all chroots"
47721 + depends on GRKERNSEC_CHROOT
47722 + help
47723 + If you say Y here, the current working directory of all newly-chrooted
47724 + applications will be set to the the root directory of the chroot.
47725 + The man page on chroot(2) states:
47726 + Note that this call does not change the current working
47727 + directory, so that `.' can be outside the tree rooted at
47728 + `/'. In particular, the super-user can escape from a
47729 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
47730 +
47731 + It is recommended that you say Y here, since it's not known to break
47732 + any software. If the sysctl option is enabled, a sysctl option with
47733 + name "chroot_enforce_chdir" is created.
47734 +
47735 +config GRKERNSEC_CHROOT_CHMOD
47736 + bool "Deny (f)chmod +s"
47737 + depends on GRKERNSEC_CHROOT
47738 + help
47739 + If you say Y here, processes inside a chroot will not be able to chmod
47740 + or fchmod files to make them have suid or sgid bits. This protects
47741 + against another published method of breaking a chroot. If the sysctl
47742 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
47743 + created.
47744 +
47745 +config GRKERNSEC_CHROOT_FCHDIR
47746 + bool "Deny fchdir out of chroot"
47747 + depends on GRKERNSEC_CHROOT
47748 + help
47749 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
47750 + to a file descriptor of the chrooting process that points to a directory
47751 + outside the filesystem will be stopped. If the sysctl option
47752 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
47753 +
47754 +config GRKERNSEC_CHROOT_MKNOD
47755 + bool "Deny mknod"
47756 + depends on GRKERNSEC_CHROOT
47757 + help
47758 + If you say Y here, processes inside a chroot will not be allowed to
47759 + mknod. The problem with using mknod inside a chroot is that it
47760 + would allow an attacker to create a device entry that is the same
47761 + as one on the physical root of your system, which could range from
47762 + anything from the console device to a device for your harddrive (which
47763 + they could then use to wipe the drive or steal data). It is recommended
47764 + that you say Y here, unless you run into software incompatibilities.
47765 + If the sysctl option is enabled, a sysctl option with name
47766 + "chroot_deny_mknod" is created.
47767 +
47768 +config GRKERNSEC_CHROOT_SHMAT
47769 + bool "Deny shmat() out of chroot"
47770 + depends on GRKERNSEC_CHROOT
47771 + help
47772 + If you say Y here, processes inside a chroot will not be able to attach
47773 + to shared memory segments that were created outside of the chroot jail.
47774 + It is recommended that you say Y here. If the sysctl option is enabled,
47775 + a sysctl option with name "chroot_deny_shmat" is created.
47776 +
47777 +config GRKERNSEC_CHROOT_UNIX
47778 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
47779 + depends on GRKERNSEC_CHROOT
47780 + help
47781 + If you say Y here, processes inside a chroot will not be able to
47782 + connect to abstract (meaning not belonging to a filesystem) Unix
47783 + domain sockets that were bound outside of a chroot. It is recommended
47784 + that you say Y here. If the sysctl option is enabled, a sysctl option
47785 + with name "chroot_deny_unix" is created.
47786 +
47787 +config GRKERNSEC_CHROOT_FINDTASK
47788 + bool "Protect outside processes"
47789 + depends on GRKERNSEC_CHROOT
47790 + help
47791 + If you say Y here, processes inside a chroot will not be able to
47792 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
47793 + getsid, or view any process outside of the chroot. If the sysctl
47794 + option is enabled, a sysctl option with name "chroot_findtask" is
47795 + created.
47796 +
47797 +config GRKERNSEC_CHROOT_NICE
47798 + bool "Restrict priority changes"
47799 + depends on GRKERNSEC_CHROOT
47800 + help
47801 + If you say Y here, processes inside a chroot will not be able to raise
47802 + the priority of processes in the chroot, or alter the priority of
47803 + processes outside the chroot. This provides more security than simply
47804 + removing CAP_SYS_NICE from the process' capability set. If the
47805 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
47806 + is created.
47807 +
47808 +config GRKERNSEC_CHROOT_SYSCTL
47809 + bool "Deny sysctl writes"
47810 + depends on GRKERNSEC_CHROOT
47811 + help
47812 + If you say Y here, an attacker in a chroot will not be able to
47813 + write to sysctl entries, either by sysctl(2) or through a /proc
47814 + interface. It is strongly recommended that you say Y here. If the
47815 + sysctl option is enabled, a sysctl option with name
47816 + "chroot_deny_sysctl" is created.
47817 +
47818 +config GRKERNSEC_CHROOT_CAPS
47819 + bool "Capability restrictions"
47820 + depends on GRKERNSEC_CHROOT
47821 + help
47822 + If you say Y here, the capabilities on all processes within a
47823 + chroot jail will be lowered to stop module insertion, raw i/o,
47824 + system and net admin tasks, rebooting the system, modifying immutable
47825 + files, modifying IPC owned by another, and changing the system time.
47826 + This is left an option because it can break some apps. Disable this
47827 + if your chrooted apps are having problems performing those kinds of
47828 + tasks. If the sysctl option is enabled, a sysctl option with
47829 + name "chroot_caps" is created.
47830 +
47831 +endmenu
47832 +menu "Kernel Auditing"
47833 +depends on GRKERNSEC
47834 +
47835 +config GRKERNSEC_AUDIT_GROUP
47836 + bool "Single group for auditing"
47837 + help
47838 + If you say Y here, the exec, chdir, and (un)mount logging features
47839 + will only operate on a group you specify. This option is recommended
47840 + if you only want to watch certain users instead of having a large
47841 + amount of logs from the entire system. If the sysctl option is enabled,
47842 + a sysctl option with name "audit_group" is created.
47843 +
47844 +config GRKERNSEC_AUDIT_GID
47845 + int "GID for auditing"
47846 + depends on GRKERNSEC_AUDIT_GROUP
47847 + default 1007
47848 +
47849 +config GRKERNSEC_EXECLOG
47850 + bool "Exec logging"
47851 + help
47852 + If you say Y here, all execve() calls will be logged (since the
47853 + other exec*() calls are frontends to execve(), all execution
47854 + will be logged). Useful for shell-servers that like to keep track
47855 + of their users. If the sysctl option is enabled, a sysctl option with
47856 + name "exec_logging" is created.
47857 + WARNING: This option when enabled will produce a LOT of logs, especially
47858 + on an active system.
47859 +
47860 +config GRKERNSEC_RESLOG
47861 + bool "Resource logging"
47862 + help
47863 + If you say Y here, all attempts to overstep resource limits will
47864 + be logged with the resource name, the requested size, and the current
47865 + limit. It is highly recommended that you say Y here. If the sysctl
47866 + option is enabled, a sysctl option with name "resource_logging" is
47867 + created. If the RBAC system is enabled, the sysctl value is ignored.
47868 +
47869 +config GRKERNSEC_CHROOT_EXECLOG
47870 + bool "Log execs within chroot"
47871 + help
47872 + If you say Y here, all executions inside a chroot jail will be logged
47873 + to syslog. This can cause a large amount of logs if certain
47874 + applications (eg. djb's daemontools) are installed on the system, and
47875 + is therefore left as an option. If the sysctl option is enabled, a
47876 + sysctl option with name "chroot_execlog" is created.
47877 +
47878 +config GRKERNSEC_AUDIT_PTRACE
47879 + bool "Ptrace logging"
47880 + help
47881 + If you say Y here, all attempts to attach to a process via ptrace
47882 + will be logged. If the sysctl option is enabled, a sysctl option
47883 + with name "audit_ptrace" is created.
47884 +
47885 +config GRKERNSEC_AUDIT_CHDIR
47886 + bool "Chdir logging"
47887 + help
47888 + If you say Y here, all chdir() calls will be logged. If the sysctl
47889 + option is enabled, a sysctl option with name "audit_chdir" is created.
47890 +
47891 +config GRKERNSEC_AUDIT_MOUNT
47892 + bool "(Un)Mount logging"
47893 + help
47894 + If you say Y here, all mounts and unmounts will be logged. If the
47895 + sysctl option is enabled, a sysctl option with name "audit_mount" is
47896 + created.
47897 +
47898 +config GRKERNSEC_SIGNAL
47899 + bool "Signal logging"
47900 + help
47901 + If you say Y here, certain important signals will be logged, such as
47902 + SIGSEGV, which will as a result inform you of when a error in a program
47903 + occurred, which in some cases could mean a possible exploit attempt.
47904 + If the sysctl option is enabled, a sysctl option with name
47905 + "signal_logging" is created.
47906 +
47907 +config GRKERNSEC_FORKFAIL
47908 + bool "Fork failure logging"
47909 + help
47910 + If you say Y here, all failed fork() attempts will be logged.
47911 + This could suggest a fork bomb, or someone attempting to overstep
47912 + their process limit. If the sysctl option is enabled, a sysctl option
47913 + with name "forkfail_logging" is created.
47914 +
47915 +config GRKERNSEC_TIME
47916 + bool "Time change logging"
47917 + help
47918 + If you say Y here, any changes of the system clock will be logged.
47919 + If the sysctl option is enabled, a sysctl option with name
47920 + "timechange_logging" is created.
47921 +
47922 +config GRKERNSEC_PROC_IPADDR
47923 + bool "/proc/<pid>/ipaddr support"
47924 + help
47925 + If you say Y here, a new entry will be added to each /proc/<pid>
47926 + directory that contains the IP address of the person using the task.
47927 + The IP is carried across local TCP and AF_UNIX stream sockets.
47928 + This information can be useful for IDS/IPSes to perform remote response
47929 + to a local attack. The entry is readable by only the owner of the
47930 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
47931 + the RBAC system), and thus does not create privacy concerns.
47932 +
47933 +config GRKERNSEC_RWXMAP_LOG
47934 + bool 'Denied RWX mmap/mprotect logging'
47935 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
47936 + help
47937 + If you say Y here, calls to mmap() and mprotect() with explicit
47938 + usage of PROT_WRITE and PROT_EXEC together will be logged when
47939 + denied by the PAX_MPROTECT feature. If the sysctl option is
47940 + enabled, a sysctl option with name "rwxmap_logging" is created.
47941 +
47942 +config GRKERNSEC_AUDIT_TEXTREL
47943 + bool 'ELF text relocations logging (READ HELP)'
47944 + depends on PAX_MPROTECT
47945 + help
47946 + If you say Y here, text relocations will be logged with the filename
47947 + of the offending library or binary. The purpose of the feature is
47948 + to help Linux distribution developers get rid of libraries and
47949 + binaries that need text relocations which hinder the future progress
47950 + of PaX. Only Linux distribution developers should say Y here, and
47951 + never on a production machine, as this option creates an information
47952 + leak that could aid an attacker in defeating the randomization of
47953 + a single memory region. If the sysctl option is enabled, a sysctl
47954 + option with name "audit_textrel" is created.
47955 +
47956 +endmenu
47957 +
47958 +menu "Executable Protections"
47959 +depends on GRKERNSEC
47960 +
47961 +config GRKERNSEC_DMESG
47962 + bool "Dmesg(8) restriction"
47963 + help
47964 + If you say Y here, non-root users will not be able to use dmesg(8)
47965 + to view up to the last 4kb of messages in the kernel's log buffer.
47966 + The kernel's log buffer often contains kernel addresses and other
47967 + identifying information useful to an attacker in fingerprinting a
47968 + system for a targeted exploit.
47969 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
47970 + created.
47971 +
47972 +config GRKERNSEC_HARDEN_PTRACE
47973 + bool "Deter ptrace-based process snooping"
47974 + help
47975 + If you say Y here, TTY sniffers and other malicious monitoring
47976 + programs implemented through ptrace will be defeated. If you
47977 + have been using the RBAC system, this option has already been
47978 + enabled for several years for all users, with the ability to make
47979 + fine-grained exceptions.
47980 +
47981 + This option only affects the ability of non-root users to ptrace
47982 + processes that are not a descendent of the ptracing process.
47983 + This means that strace ./binary and gdb ./binary will still work,
47984 + but attaching to arbitrary processes will not. If the sysctl
47985 + option is enabled, a sysctl option with name "harden_ptrace" is
47986 + created.
47987 +
47988 +config GRKERNSEC_PTRACE_READEXEC
47989 + bool "Require read access to ptrace sensitive binaries"
47990 + help
47991 + If you say Y here, read permission will be required by any unprivileged
47992 + process to ptrace suid/sgid binaries. Note that the ability to
47993 + ptrace privileged binaries and retain that binary's privilege is
47994 + already not possible. This option is useful in environments that
47995 + remove the read bits (e.g. file mode 4711) from suid binaries to
47996 + prevent infoleaking of their contents. What this option adds
47997 + is consistency to the use of that file mode, as the binary could normally
47998 + be read out when run without privileges while ptracing.
47999 +
48000 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
48001 + is created.
48002 +
48003 +config GRKERNSEC_SETXID
48004 + bool "Enforce consistent multithreaded privileges"
48005 + help
48006 + If you say Y here, a change from a root uid to a non-root uid
48007 + in a multithreaded application will cause the resulting uids,
48008 + gids, supplementary groups, and capabilities in that thread
48009 + to be propagated to the other threads of the process. In most
48010 + cases this is unnecessary, as glibc will emulate this behavior
48011 + on behalf of the application. Other libcs do not act in the
48012 + same way, allowing the other threads of the process to continue
48013 + running with root privileges. If the sysctl option is enabled,
48014 + a sysctl option with name "consistent_setxid" is created.
48015 +
48016 +config GRKERNSEC_TPE
48017 + bool "Trusted Path Execution (TPE)"
48018 + help
48019 + If you say Y here, you will be able to choose a gid to add to the
48020 + supplementary groups of users you want to mark as "untrusted."
48021 + These users will not be able to execute any files that are not in
48022 + root-owned directories writable only by root. If the sysctl option
48023 + is enabled, a sysctl option with name "tpe" is created.
48024 +
48025 +config GRKERNSEC_TPE_ALL
48026 + bool "Partially restrict all non-root users"
48027 + depends on GRKERNSEC_TPE
48028 + help
48029 + If you say Y here, all non-root users will be covered under
48030 + a weaker TPE restriction. This is separate from, and in addition to,
48031 + the main TPE options that you have selected elsewhere. Thus, if a
48032 + "trusted" GID is chosen, this restriction applies to even that GID.
48033 + Under this restriction, all non-root users will only be allowed to
48034 + execute files in directories they own that are not group or
48035 + world-writable, or in directories owned by root and writable only by
48036 + root. If the sysctl option is enabled, a sysctl option with name
48037 + "tpe_restrict_all" is created.
48038 +
48039 +config GRKERNSEC_TPE_INVERT
48040 + bool "Invert GID option"
48041 + depends on GRKERNSEC_TPE
48042 + help
48043 + If you say Y here, the group you specify in the TPE configuration will
48044 + decide what group TPE restrictions will be *disabled* for. This
48045 + option is useful if you want TPE restrictions to be applied to most
48046 + users on the system. If the sysctl option is enabled, a sysctl option
48047 + with name "tpe_invert" is created. Unlike other sysctl options, this
48048 + entry will default to on for backward-compatibility.
48049 +
48050 +config GRKERNSEC_TPE_GID
48051 + int "GID for untrusted users"
48052 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
48053 + default 1005
48054 + help
48055 + Setting this GID determines what group TPE restrictions will be
48056 + *enabled* for. If the sysctl option is enabled, a sysctl option
48057 + with name "tpe_gid" is created.
48058 +
48059 +config GRKERNSEC_TPE_GID
48060 + int "GID for trusted users"
48061 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
48062 + default 1005
48063 + help
48064 + Setting this GID determines what group TPE restrictions will be
48065 + *disabled* for. If the sysctl option is enabled, a sysctl option
48066 + with name "tpe_gid" is created.
48067 +
48068 +endmenu
48069 +menu "Network Protections"
48070 +depends on GRKERNSEC
48071 +
48072 +config GRKERNSEC_RANDNET
48073 + bool "Larger entropy pools"
48074 + help
48075 + If you say Y here, the entropy pools used for many features of Linux
48076 + and grsecurity will be doubled in size. Since several grsecurity
48077 + features use additional randomness, it is recommended that you say Y
48078 + here. Saying Y here has a similar effect as modifying
48079 + /proc/sys/kernel/random/poolsize.
48080 +
48081 +config GRKERNSEC_BLACKHOLE
48082 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
48083 + depends on NET
48084 + help
48085 + If you say Y here, neither TCP resets nor ICMP
48086 + destination-unreachable packets will be sent in response to packets
48087 + sent to ports for which no associated listening process exists.
48088 + This feature supports both IPV4 and IPV6 and exempts the
48089 + loopback interface from blackholing. Enabling this feature
48090 + makes a host more resilient to DoS attacks and reduces network
48091 + visibility against scanners.
48092 +
48093 + The blackhole feature as-implemented is equivalent to the FreeBSD
48094 + blackhole feature, as it prevents RST responses to all packets, not
48095 + just SYNs. Under most application behavior this causes no
48096 + problems, but applications (like haproxy) may not close certain
48097 + connections in a way that cleanly terminates them on the remote
48098 + end, leaving the remote host in LAST_ACK state. Because of this
48099 + side-effect and to prevent intentional LAST_ACK DoSes, this
48100 + feature also adds automatic mitigation against such attacks.
48101 + The mitigation drastically reduces the amount of time a socket
48102 + can spend in LAST_ACK state. If you're using haproxy and not
48103 + all servers it connects to have this option enabled, consider
48104 + disabling this feature on the haproxy host.
48105 +
48106 + If the sysctl option is enabled, two sysctl options with names
48107 + "ip_blackhole" and "lastack_retries" will be created.
48108 + While "ip_blackhole" takes the standard zero/non-zero on/off
48109 + toggle, "lastack_retries" uses the same kinds of values as
48110 + "tcp_retries1" and "tcp_retries2". The default value of 4
48111 + prevents a socket from lasting more than 45 seconds in LAST_ACK
48112 + state.
48113 +
48114 +config GRKERNSEC_SOCKET
48115 + bool "Socket restrictions"
48116 + depends on NET
48117 + help
48118 + If you say Y here, you will be able to choose from several options.
48119 + If you assign a GID on your system and add it to the supplementary
48120 + groups of users you want to restrict socket access to, this patch
48121 + will perform up to three things, based on the option(s) you choose.
48122 +
48123 +config GRKERNSEC_SOCKET_ALL
48124 + bool "Deny any sockets to group"
48125 + depends on GRKERNSEC_SOCKET
48126 + help
48127 + If you say Y here, you will be able to choose a GID of whose users will
48128 + be unable to connect to other hosts from your machine or run server
48129 + applications from your machine. If the sysctl option is enabled, a
48130 + sysctl option with name "socket_all" is created.
48131 +
48132 +config GRKERNSEC_SOCKET_ALL_GID
48133 + int "GID to deny all sockets for"
48134 + depends on GRKERNSEC_SOCKET_ALL
48135 + default 1004
48136 + help
48137 + Here you can choose the GID to disable socket access for. Remember to
48138 + add the users you want socket access disabled for to the GID
48139 + specified here. If the sysctl option is enabled, a sysctl option
48140 + with name "socket_all_gid" is created.
48141 +
48142 +config GRKERNSEC_SOCKET_CLIENT
48143 + bool "Deny client sockets to group"
48144 + depends on GRKERNSEC_SOCKET
48145 + help
48146 + If you say Y here, you will be able to choose a GID of whose users will
48147 + be unable to connect to other hosts from your machine, but will be
48148 + able to run servers. If this option is enabled, all users in the group
48149 + you specify will have to use passive mode when initiating ftp transfers
48150 + from the shell on your machine. If the sysctl option is enabled, a
48151 + sysctl option with name "socket_client" is created.
48152 +
48153 +config GRKERNSEC_SOCKET_CLIENT_GID
48154 + int "GID to deny client sockets for"
48155 + depends on GRKERNSEC_SOCKET_CLIENT
48156 + default 1003
48157 + help
48158 + Here you can choose the GID to disable client socket access for.
48159 + Remember to add the users you want client socket access disabled for to
48160 + the GID specified here. If the sysctl option is enabled, a sysctl
48161 + option with name "socket_client_gid" is created.
48162 +
48163 +config GRKERNSEC_SOCKET_SERVER
48164 + bool "Deny server sockets to group"
48165 + depends on GRKERNSEC_SOCKET
48166 + help
48167 + If you say Y here, you will be able to choose a GID of whose users will
48168 + be unable to run server applications from your machine. If the sysctl
48169 + option is enabled, a sysctl option with name "socket_server" is created.
48170 +
48171 +config GRKERNSEC_SOCKET_SERVER_GID
48172 + int "GID to deny server sockets for"
48173 + depends on GRKERNSEC_SOCKET_SERVER
48174 + default 1002
48175 + help
48176 + Here you can choose the GID to disable server socket access for.
48177 + Remember to add the users you want server socket access disabled for to
48178 + the GID specified here. If the sysctl option is enabled, a sysctl
48179 + option with name "socket_server_gid" is created.
48180 +
48181 +endmenu
48182 +menu "Sysctl support"
48183 +depends on GRKERNSEC && SYSCTL
48184 +
48185 +config GRKERNSEC_SYSCTL
48186 + bool "Sysctl support"
48187 + help
48188 + If you say Y here, you will be able to change the options that
48189 + grsecurity runs with at bootup, without having to recompile your
48190 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
48191 + to enable (1) or disable (0) various features. All the sysctl entries
48192 + are mutable until the "grsec_lock" entry is set to a non-zero value.
48193 + All features enabled in the kernel configuration are disabled at boot
48194 + if you do not say Y to the "Turn on features by default" option.
48195 + All options should be set at startup, and the grsec_lock entry should
48196 + be set to a non-zero value after all the options are set.
48197 + *THIS IS EXTREMELY IMPORTANT*
48198 +
48199 +config GRKERNSEC_SYSCTL_DISTRO
48200 + bool "Extra sysctl support for distro makers (READ HELP)"
48201 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
48202 + help
48203 + If you say Y here, additional sysctl options will be created
48204 + for features that affect processes running as root. Therefore,
48205 + it is critical when using this option that the grsec_lock entry be
48206 + enabled after boot. Only distros with prebuilt kernel packages
48207 + with this option enabled that can ensure grsec_lock is enabled
48208 + after boot should use this option.
48209 + *Failure to set grsec_lock after boot makes all grsec features
48210 + this option covers useless*
48211 +
48212 + Currently this option creates the following sysctl entries:
48213 + "Disable Privileged I/O": "disable_priv_io"
48214 +
48215 +config GRKERNSEC_SYSCTL_ON
48216 + bool "Turn on features by default"
48217 + depends on GRKERNSEC_SYSCTL
48218 + help
48219 + If you say Y here, instead of having all features enabled in the
48220 + kernel configuration disabled at boot time, the features will be
48221 + enabled at boot time. It is recommended you say Y here unless
48222 + there is some reason you would want all sysctl-tunable features to
48223 + be disabled by default. As mentioned elsewhere, it is important
48224 + to enable the grsec_lock entry once you have finished modifying
48225 + the sysctl entries.
48226 +
48227 +endmenu
48228 +menu "Logging Options"
48229 +depends on GRKERNSEC
48230 +
48231 +config GRKERNSEC_FLOODTIME
48232 + int "Seconds in between log messages (minimum)"
48233 + default 10
48234 + help
48235 + This option allows you to enforce the number of seconds between
48236 + grsecurity log messages. The default should be suitable for most
48237 + people, however, if you choose to change it, choose a value small enough
48238 + to allow informative logs to be produced, but large enough to
48239 + prevent flooding.
48240 +
48241 +config GRKERNSEC_FLOODBURST
48242 + int "Number of messages in a burst (maximum)"
48243 + default 6
48244 + help
48245 + This option allows you to choose the maximum number of messages allowed
48246 + within the flood time interval you chose in a separate option. The
48247 + default should be suitable for most people, however if you find that
48248 + many of your logs are being interpreted as flooding, you may want to
48249 + raise this value.
48250 +
48251 +endmenu
48252 +
48253 +endmenu
48254 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
48255 new file mode 100644
48256 index 0000000..be9ae3a
48257 --- /dev/null
48258 +++ b/grsecurity/Makefile
48259 @@ -0,0 +1,36 @@
48260 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
48261 +# during 2001-2009 it has been completely redesigned by Brad Spengler
48262 +# into an RBAC system
48263 +#
48264 +# All code in this directory and various hooks inserted throughout the kernel
48265 +# are copyright Brad Spengler - Open Source Security, Inc., and released
48266 +# under the GPL v2 or higher
48267 +
48268 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
48269 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
48270 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
48271 +
48272 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
48273 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
48274 + gracl_learn.o grsec_log.o
48275 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
48276 +
48277 +ifdef CONFIG_NET
48278 +obj-y += grsec_sock.o
48279 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
48280 +endif
48281 +
48282 +ifndef CONFIG_GRKERNSEC
48283 +obj-y += grsec_disabled.o
48284 +endif
48285 +
48286 +ifdef CONFIG_GRKERNSEC_HIDESYM
48287 +extra-y := grsec_hidesym.o
48288 +$(obj)/grsec_hidesym.o:
48289 + @-chmod -f 500 /boot
48290 + @-chmod -f 500 /lib/modules
48291 + @-chmod -f 500 /lib64/modules
48292 + @-chmod -f 500 /lib32/modules
48293 + @-chmod -f 700 .
48294 + @echo ' grsec: protected kernel image paths'
48295 +endif
48296 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
48297 new file mode 100644
48298 index 0000000..09258e0
48299 --- /dev/null
48300 +++ b/grsecurity/gracl.c
48301 @@ -0,0 +1,4156 @@
48302 +#include <linux/kernel.h>
48303 +#include <linux/module.h>
48304 +#include <linux/sched.h>
48305 +#include <linux/mm.h>
48306 +#include <linux/file.h>
48307 +#include <linux/fs.h>
48308 +#include <linux/namei.h>
48309 +#include <linux/mount.h>
48310 +#include <linux/tty.h>
48311 +#include <linux/proc_fs.h>
48312 +#include <linux/lglock.h>
48313 +#include <linux/slab.h>
48314 +#include <linux/vmalloc.h>
48315 +#include <linux/types.h>
48316 +#include <linux/sysctl.h>
48317 +#include <linux/netdevice.h>
48318 +#include <linux/ptrace.h>
48319 +#include <linux/gracl.h>
48320 +#include <linux/gralloc.h>
48321 +#include <linux/grsecurity.h>
48322 +#include <linux/grinternal.h>
48323 +#include <linux/pid_namespace.h>
48324 +#include <linux/fdtable.h>
48325 +#include <linux/percpu.h>
48326 +
48327 +#include <asm/uaccess.h>
48328 +#include <asm/errno.h>
48329 +#include <asm/mman.h>
48330 +
48331 +static struct acl_role_db acl_role_set;
48332 +static struct name_db name_set;
48333 +static struct inodev_db inodev_set;
48334 +
48335 +/* for keeping track of userspace pointers used for subjects, so we
48336 + can share references in the kernel as well
48337 +*/
48338 +
48339 +static struct path real_root;
48340 +
48341 +static struct acl_subj_map_db subj_map_set;
48342 +
48343 +static struct acl_role_label *default_role;
48344 +
48345 +static struct acl_role_label *role_list;
48346 +
48347 +static u16 acl_sp_role_value;
48348 +
48349 +extern char *gr_shared_page[4];
48350 +static DEFINE_MUTEX(gr_dev_mutex);
48351 +DEFINE_RWLOCK(gr_inode_lock);
48352 +
48353 +struct gr_arg *gr_usermode;
48354 +
48355 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
48356 +
48357 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
48358 +extern void gr_clear_learn_entries(void);
48359 +
48360 +#ifdef CONFIG_GRKERNSEC_RESLOG
48361 +extern void gr_log_resource(const struct task_struct *task,
48362 + const int res, const unsigned long wanted, const int gt);
48363 +#endif
48364 +
48365 +unsigned char *gr_system_salt;
48366 +unsigned char *gr_system_sum;
48367 +
48368 +static struct sprole_pw **acl_special_roles = NULL;
48369 +static __u16 num_sprole_pws = 0;
48370 +
48371 +static struct acl_role_label *kernel_role = NULL;
48372 +
48373 +static unsigned int gr_auth_attempts = 0;
48374 +static unsigned long gr_auth_expires = 0UL;
48375 +
48376 +#ifdef CONFIG_NET
48377 +extern struct vfsmount *sock_mnt;
48378 +#endif
48379 +
48380 +extern struct vfsmount *pipe_mnt;
48381 +extern struct vfsmount *shm_mnt;
48382 +#ifdef CONFIG_HUGETLBFS
48383 +extern struct vfsmount *hugetlbfs_vfsmount;
48384 +#endif
48385 +
48386 +static struct acl_object_label *fakefs_obj_rw;
48387 +static struct acl_object_label *fakefs_obj_rwx;
48388 +
48389 +extern int gr_init_uidset(void);
48390 +extern void gr_free_uidset(void);
48391 +extern void gr_remove_uid(uid_t uid);
48392 +extern int gr_find_uid(uid_t uid);
48393 +
48394 +DECLARE_BRLOCK(vfsmount_lock);
48395 +
48396 +__inline__ int
48397 +gr_acl_is_enabled(void)
48398 +{
48399 + return (gr_status & GR_READY);
48400 +}
48401 +
48402 +#ifdef CONFIG_BTRFS_FS
48403 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
48404 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
48405 +#endif
48406 +
48407 +static inline dev_t __get_dev(const struct dentry *dentry)
48408 +{
48409 +#ifdef CONFIG_BTRFS_FS
48410 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
48411 + return get_btrfs_dev_from_inode(dentry->d_inode);
48412 + else
48413 +#endif
48414 + return dentry->d_inode->i_sb->s_dev;
48415 +}
48416 +
48417 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
48418 +{
48419 + return __get_dev(dentry);
48420 +}
48421 +
48422 +static char gr_task_roletype_to_char(struct task_struct *task)
48423 +{
48424 + switch (task->role->roletype &
48425 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
48426 + GR_ROLE_SPECIAL)) {
48427 + case GR_ROLE_DEFAULT:
48428 + return 'D';
48429 + case GR_ROLE_USER:
48430 + return 'U';
48431 + case GR_ROLE_GROUP:
48432 + return 'G';
48433 + case GR_ROLE_SPECIAL:
48434 + return 'S';
48435 + }
48436 +
48437 + return 'X';
48438 +}
48439 +
48440 +char gr_roletype_to_char(void)
48441 +{
48442 + return gr_task_roletype_to_char(current);
48443 +}
48444 +
48445 +__inline__ int
48446 +gr_acl_tpe_check(void)
48447 +{
48448 + if (unlikely(!(gr_status & GR_READY)))
48449 + return 0;
48450 + if (current->role->roletype & GR_ROLE_TPE)
48451 + return 1;
48452 + else
48453 + return 0;
48454 +}
48455 +
48456 +int
48457 +gr_handle_rawio(const struct inode *inode)
48458 +{
48459 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
48460 + if (inode && S_ISBLK(inode->i_mode) &&
48461 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
48462 + !capable(CAP_SYS_RAWIO))
48463 + return 1;
48464 +#endif
48465 + return 0;
48466 +}
48467 +
48468 +static int
48469 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
48470 +{
48471 + if (likely(lena != lenb))
48472 + return 0;
48473 +
48474 + return !memcmp(a, b, lena);
48475 +}
48476 +
48477 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
48478 +{
48479 + *buflen -= namelen;
48480 + if (*buflen < 0)
48481 + return -ENAMETOOLONG;
48482 + *buffer -= namelen;
48483 + memcpy(*buffer, str, namelen);
48484 + return 0;
48485 +}
48486 +
48487 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
48488 +{
48489 + return prepend(buffer, buflen, name->name, name->len);
48490 +}
48491 +
48492 +static int prepend_path(const struct path *path, struct path *root,
48493 + char **buffer, int *buflen)
48494 +{
48495 + struct dentry *dentry = path->dentry;
48496 + struct vfsmount *vfsmnt = path->mnt;
48497 + bool slash = false;
48498 + int error = 0;
48499 +
48500 + while (dentry != root->dentry || vfsmnt != root->mnt) {
48501 + struct dentry * parent;
48502 +
48503 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
48504 + /* Global root? */
48505 + if (vfsmnt->mnt_parent == vfsmnt) {
48506 + goto out;
48507 + }
48508 + dentry = vfsmnt->mnt_mountpoint;
48509 + vfsmnt = vfsmnt->mnt_parent;
48510 + continue;
48511 + }
48512 + parent = dentry->d_parent;
48513 + prefetch(parent);
48514 + spin_lock(&dentry->d_lock);
48515 + error = prepend_name(buffer, buflen, &dentry->d_name);
48516 + spin_unlock(&dentry->d_lock);
48517 + if (!error)
48518 + error = prepend(buffer, buflen, "/", 1);
48519 + if (error)
48520 + break;
48521 +
48522 + slash = true;
48523 + dentry = parent;
48524 + }
48525 +
48526 +out:
48527 + if (!error && !slash)
48528 + error = prepend(buffer, buflen, "/", 1);
48529 +
48530 + return error;
48531 +}
48532 +
48533 +/* this must be called with vfsmount_lock and rename_lock held */
48534 +
48535 +static char *__our_d_path(const struct path *path, struct path *root,
48536 + char *buf, int buflen)
48537 +{
48538 + char *res = buf + buflen;
48539 + int error;
48540 +
48541 + prepend(&res, &buflen, "\0", 1);
48542 + error = prepend_path(path, root, &res, &buflen);
48543 + if (error)
48544 + return ERR_PTR(error);
48545 +
48546 + return res;
48547 +}
48548 +
48549 +static char *
48550 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
48551 +{
48552 + char *retval;
48553 +
48554 + retval = __our_d_path(path, root, buf, buflen);
48555 + if (unlikely(IS_ERR(retval)))
48556 + retval = strcpy(buf, "<path too long>");
48557 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
48558 + retval[1] = '\0';
48559 +
48560 + return retval;
48561 +}
48562 +
48563 +static char *
48564 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
48565 + char *buf, int buflen)
48566 +{
48567 + struct path path;
48568 + char *res;
48569 +
48570 + path.dentry = (struct dentry *)dentry;
48571 + path.mnt = (struct vfsmount *)vfsmnt;
48572 +
48573 + /* we can use real_root.dentry, real_root.mnt, because this is only called
48574 + by the RBAC system */
48575 + res = gen_full_path(&path, &real_root, buf, buflen);
48576 +
48577 + return res;
48578 +}
48579 +
48580 +static char *
48581 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
48582 + char *buf, int buflen)
48583 +{
48584 + char *res;
48585 + struct path path;
48586 + struct path root;
48587 + struct task_struct *reaper = &init_task;
48588 +
48589 + path.dentry = (struct dentry *)dentry;
48590 + path.mnt = (struct vfsmount *)vfsmnt;
48591 +
48592 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
48593 + get_fs_root(reaper->fs, &root);
48594 +
48595 + write_seqlock(&rename_lock);
48596 + br_read_lock(vfsmount_lock);
48597 + res = gen_full_path(&path, &root, buf, buflen);
48598 + br_read_unlock(vfsmount_lock);
48599 + write_sequnlock(&rename_lock);
48600 +
48601 + path_put(&root);
48602 + return res;
48603 +}
48604 +
48605 +static char *
48606 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
48607 +{
48608 + char *ret;
48609 + write_seqlock(&rename_lock);
48610 + br_read_lock(vfsmount_lock);
48611 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
48612 + PAGE_SIZE);
48613 + br_read_unlock(vfsmount_lock);
48614 + write_sequnlock(&rename_lock);
48615 + return ret;
48616 +}
48617 +
48618 +static char *
48619 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
48620 +{
48621 + char *ret;
48622 + char *buf;
48623 + int buflen;
48624 +
48625 + write_seqlock(&rename_lock);
48626 + br_read_lock(vfsmount_lock);
48627 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
48628 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
48629 + buflen = (int)(ret - buf);
48630 + if (buflen >= 5)
48631 + prepend(&ret, &buflen, "/proc", 5);
48632 + else
48633 + ret = strcpy(buf, "<path too long>");
48634 + br_read_unlock(vfsmount_lock);
48635 + write_sequnlock(&rename_lock);
48636 + return ret;
48637 +}
48638 +
48639 +char *
48640 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
48641 +{
48642 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
48643 + PAGE_SIZE);
48644 +}
48645 +
48646 +char *
48647 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
48648 +{
48649 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
48650 + PAGE_SIZE);
48651 +}
48652 +
48653 +char *
48654 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
48655 +{
48656 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
48657 + PAGE_SIZE);
48658 +}
48659 +
48660 +char *
48661 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
48662 +{
48663 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
48664 + PAGE_SIZE);
48665 +}
48666 +
48667 +char *
48668 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
48669 +{
48670 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
48671 + PAGE_SIZE);
48672 +}
48673 +
48674 +__inline__ __u32
48675 +to_gr_audit(const __u32 reqmode)
48676 +{
48677 + /* masks off auditable permission flags, then shifts them to create
48678 + auditing flags, and adds the special case of append auditing if
48679 + we're requesting write */
48680 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
48681 +}
48682 +
48683 +struct acl_subject_label *
48684 +lookup_subject_map(const struct acl_subject_label *userp)
48685 +{
48686 + unsigned int index = shash(userp, subj_map_set.s_size);
48687 + struct subject_map *match;
48688 +
48689 + match = subj_map_set.s_hash[index];
48690 +
48691 + while (match && match->user != userp)
48692 + match = match->next;
48693 +
48694 + if (match != NULL)
48695 + return match->kernel;
48696 + else
48697 + return NULL;
48698 +}
48699 +
48700 +static void
48701 +insert_subj_map_entry(struct subject_map *subjmap)
48702 +{
48703 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
48704 + struct subject_map **curr;
48705 +
48706 + subjmap->prev = NULL;
48707 +
48708 + curr = &subj_map_set.s_hash[index];
48709 + if (*curr != NULL)
48710 + (*curr)->prev = subjmap;
48711 +
48712 + subjmap->next = *curr;
48713 + *curr = subjmap;
48714 +
48715 + return;
48716 +}
48717 +
48718 +static struct acl_role_label *
48719 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
48720 + const gid_t gid)
48721 +{
48722 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
48723 + struct acl_role_label *match;
48724 + struct role_allowed_ip *ipp;
48725 + unsigned int x;
48726 + u32 curr_ip = task->signal->curr_ip;
48727 +
48728 + task->signal->saved_ip = curr_ip;
48729 +
48730 + match = acl_role_set.r_hash[index];
48731 +
48732 + while (match) {
48733 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
48734 + for (x = 0; x < match->domain_child_num; x++) {
48735 + if (match->domain_children[x] == uid)
48736 + goto found;
48737 + }
48738 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
48739 + break;
48740 + match = match->next;
48741 + }
48742 +found:
48743 + if (match == NULL) {
48744 + try_group:
48745 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
48746 + match = acl_role_set.r_hash[index];
48747 +
48748 + while (match) {
48749 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
48750 + for (x = 0; x < match->domain_child_num; x++) {
48751 + if (match->domain_children[x] == gid)
48752 + goto found2;
48753 + }
48754 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
48755 + break;
48756 + match = match->next;
48757 + }
48758 +found2:
48759 + if (match == NULL)
48760 + match = default_role;
48761 + if (match->allowed_ips == NULL)
48762 + return match;
48763 + else {
48764 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
48765 + if (likely
48766 + ((ntohl(curr_ip) & ipp->netmask) ==
48767 + (ntohl(ipp->addr) & ipp->netmask)))
48768 + return match;
48769 + }
48770 + match = default_role;
48771 + }
48772 + } else if (match->allowed_ips == NULL) {
48773 + return match;
48774 + } else {
48775 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
48776 + if (likely
48777 + ((ntohl(curr_ip) & ipp->netmask) ==
48778 + (ntohl(ipp->addr) & ipp->netmask)))
48779 + return match;
48780 + }
48781 + goto try_group;
48782 + }
48783 +
48784 + return match;
48785 +}
48786 +
48787 +struct acl_subject_label *
48788 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
48789 + const struct acl_role_label *role)
48790 +{
48791 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
48792 + struct acl_subject_label *match;
48793 +
48794 + match = role->subj_hash[index];
48795 +
48796 + while (match && (match->inode != ino || match->device != dev ||
48797 + (match->mode & GR_DELETED))) {
48798 + match = match->next;
48799 + }
48800 +
48801 + if (match && !(match->mode & GR_DELETED))
48802 + return match;
48803 + else
48804 + return NULL;
48805 +}
48806 +
48807 +struct acl_subject_label *
48808 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
48809 + const struct acl_role_label *role)
48810 +{
48811 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
48812 + struct acl_subject_label *match;
48813 +
48814 + match = role->subj_hash[index];
48815 +
48816 + while (match && (match->inode != ino || match->device != dev ||
48817 + !(match->mode & GR_DELETED))) {
48818 + match = match->next;
48819 + }
48820 +
48821 + if (match && (match->mode & GR_DELETED))
48822 + return match;
48823 + else
48824 + return NULL;
48825 +}
48826 +
48827 +static struct acl_object_label *
48828 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
48829 + const struct acl_subject_label *subj)
48830 +{
48831 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
48832 + struct acl_object_label *match;
48833 +
48834 + match = subj->obj_hash[index];
48835 +
48836 + while (match && (match->inode != ino || match->device != dev ||
48837 + (match->mode & GR_DELETED))) {
48838 + match = match->next;
48839 + }
48840 +
48841 + if (match && !(match->mode & GR_DELETED))
48842 + return match;
48843 + else
48844 + return NULL;
48845 +}
48846 +
48847 +static struct acl_object_label *
48848 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
48849 + const struct acl_subject_label *subj)
48850 +{
48851 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
48852 + struct acl_object_label *match;
48853 +
48854 + match = subj->obj_hash[index];
48855 +
48856 + while (match && (match->inode != ino || match->device != dev ||
48857 + !(match->mode & GR_DELETED))) {
48858 + match = match->next;
48859 + }
48860 +
48861 + if (match && (match->mode & GR_DELETED))
48862 + return match;
48863 +
48864 + match = subj->obj_hash[index];
48865 +
48866 + while (match && (match->inode != ino || match->device != dev ||
48867 + (match->mode & GR_DELETED))) {
48868 + match = match->next;
48869 + }
48870 +
48871 + if (match && !(match->mode & GR_DELETED))
48872 + return match;
48873 + else
48874 + return NULL;
48875 +}
48876 +
48877 +static struct name_entry *
48878 +lookup_name_entry(const char *name)
48879 +{
48880 + unsigned int len = strlen(name);
48881 + unsigned int key = full_name_hash(name, len);
48882 + unsigned int index = key % name_set.n_size;
48883 + struct name_entry *match;
48884 +
48885 + match = name_set.n_hash[index];
48886 +
48887 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
48888 + match = match->next;
48889 +
48890 + return match;
48891 +}
48892 +
48893 +static struct name_entry *
48894 +lookup_name_entry_create(const char *name)
48895 +{
48896 + unsigned int len = strlen(name);
48897 + unsigned int key = full_name_hash(name, len);
48898 + unsigned int index = key % name_set.n_size;
48899 + struct name_entry *match;
48900 +
48901 + match = name_set.n_hash[index];
48902 +
48903 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
48904 + !match->deleted))
48905 + match = match->next;
48906 +
48907 + if (match && match->deleted)
48908 + return match;
48909 +
48910 + match = name_set.n_hash[index];
48911 +
48912 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
48913 + match->deleted))
48914 + match = match->next;
48915 +
48916 + if (match && !match->deleted)
48917 + return match;
48918 + else
48919 + return NULL;
48920 +}
48921 +
48922 +static struct inodev_entry *
48923 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
48924 +{
48925 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
48926 + struct inodev_entry *match;
48927 +
48928 + match = inodev_set.i_hash[index];
48929 +
48930 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
48931 + match = match->next;
48932 +
48933 + return match;
48934 +}
48935 +
48936 +static void
48937 +insert_inodev_entry(struct inodev_entry *entry)
48938 +{
48939 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
48940 + inodev_set.i_size);
48941 + struct inodev_entry **curr;
48942 +
48943 + entry->prev = NULL;
48944 +
48945 + curr = &inodev_set.i_hash[index];
48946 + if (*curr != NULL)
48947 + (*curr)->prev = entry;
48948 +
48949 + entry->next = *curr;
48950 + *curr = entry;
48951 +
48952 + return;
48953 +}
48954 +
48955 +static void
48956 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
48957 +{
48958 + unsigned int index =
48959 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
48960 + struct acl_role_label **curr;
48961 + struct acl_role_label *tmp;
48962 +
48963 + curr = &acl_role_set.r_hash[index];
48964 +
48965 + /* if role was already inserted due to domains and already has
48966 + a role in the same bucket as it attached, then we need to
48967 + combine these two buckets
48968 + */
48969 + if (role->next) {
48970 + tmp = role->next;
48971 + while (tmp->next)
48972 + tmp = tmp->next;
48973 + tmp->next = *curr;
48974 + } else
48975 + role->next = *curr;
48976 + *curr = role;
48977 +
48978 + return;
48979 +}
48980 +
48981 +static void
48982 +insert_acl_role_label(struct acl_role_label *role)
48983 +{
48984 + int i;
48985 +
48986 + if (role_list == NULL) {
48987 + role_list = role;
48988 + role->prev = NULL;
48989 + } else {
48990 + role->prev = role_list;
48991 + role_list = role;
48992 + }
48993 +
48994 + /* used for hash chains */
48995 + role->next = NULL;
48996 +
48997 + if (role->roletype & GR_ROLE_DOMAIN) {
48998 + for (i = 0; i < role->domain_child_num; i++)
48999 + __insert_acl_role_label(role, role->domain_children[i]);
49000 + } else
49001 + __insert_acl_role_label(role, role->uidgid);
49002 +}
49003 +
49004 +static int
49005 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
49006 +{
49007 + struct name_entry **curr, *nentry;
49008 + struct inodev_entry *ientry;
49009 + unsigned int len = strlen(name);
49010 + unsigned int key = full_name_hash(name, len);
49011 + unsigned int index = key % name_set.n_size;
49012 +
49013 + curr = &name_set.n_hash[index];
49014 +
49015 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
49016 + curr = &((*curr)->next);
49017 +
49018 + if (*curr != NULL)
49019 + return 1;
49020 +
49021 + nentry = acl_alloc(sizeof (struct name_entry));
49022 + if (nentry == NULL)
49023 + return 0;
49024 + ientry = acl_alloc(sizeof (struct inodev_entry));
49025 + if (ientry == NULL)
49026 + return 0;
49027 + ientry->nentry = nentry;
49028 +
49029 + nentry->key = key;
49030 + nentry->name = name;
49031 + nentry->inode = inode;
49032 + nentry->device = device;
49033 + nentry->len = len;
49034 + nentry->deleted = deleted;
49035 +
49036 + nentry->prev = NULL;
49037 + curr = &name_set.n_hash[index];
49038 + if (*curr != NULL)
49039 + (*curr)->prev = nentry;
49040 + nentry->next = *curr;
49041 + *curr = nentry;
49042 +
49043 + /* insert us into the table searchable by inode/dev */
49044 + insert_inodev_entry(ientry);
49045 +
49046 + return 1;
49047 +}
49048 +
49049 +static void
49050 +insert_acl_obj_label(struct acl_object_label *obj,
49051 + struct acl_subject_label *subj)
49052 +{
49053 + unsigned int index =
49054 + fhash(obj->inode, obj->device, subj->obj_hash_size);
49055 + struct acl_object_label **curr;
49056 +
49057 +
49058 + obj->prev = NULL;
49059 +
49060 + curr = &subj->obj_hash[index];
49061 + if (*curr != NULL)
49062 + (*curr)->prev = obj;
49063 +
49064 + obj->next = *curr;
49065 + *curr = obj;
49066 +
49067 + return;
49068 +}
49069 +
49070 +static void
49071 +insert_acl_subj_label(struct acl_subject_label *obj,
49072 + struct acl_role_label *role)
49073 +{
49074 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
49075 + struct acl_subject_label **curr;
49076 +
49077 + obj->prev = NULL;
49078 +
49079 + curr = &role->subj_hash[index];
49080 + if (*curr != NULL)
49081 + (*curr)->prev = obj;
49082 +
49083 + obj->next = *curr;
49084 + *curr = obj;
49085 +
49086 + return;
49087 +}
49088 +
49089 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
49090 +
49091 +static void *
49092 +create_table(__u32 * len, int elementsize)
49093 +{
49094 + unsigned int table_sizes[] = {
49095 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
49096 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
49097 + 4194301, 8388593, 16777213, 33554393, 67108859
49098 + };
49099 + void *newtable = NULL;
49100 + unsigned int pwr = 0;
49101 +
49102 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
49103 + table_sizes[pwr] <= *len)
49104 + pwr++;
49105 +
49106 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
49107 + return newtable;
49108 +
49109 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
49110 + newtable =
49111 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
49112 + else
49113 + newtable = vmalloc(table_sizes[pwr] * elementsize);
49114 +
49115 + *len = table_sizes[pwr];
49116 +
49117 + return newtable;
49118 +}
49119 +
49120 +static int
49121 +init_variables(const struct gr_arg *arg)
49122 +{
49123 + struct task_struct *reaper = &init_task;
49124 + unsigned int stacksize;
49125 +
49126 + subj_map_set.s_size = arg->role_db.num_subjects;
49127 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
49128 + name_set.n_size = arg->role_db.num_objects;
49129 + inodev_set.i_size = arg->role_db.num_objects;
49130 +
49131 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
49132 + !name_set.n_size || !inodev_set.i_size)
49133 + return 1;
49134 +
49135 + if (!gr_init_uidset())
49136 + return 1;
49137 +
49138 + /* set up the stack that holds allocation info */
49139 +
49140 + stacksize = arg->role_db.num_pointers + 5;
49141 +
49142 + if (!acl_alloc_stack_init(stacksize))
49143 + return 1;
49144 +
49145 + /* grab reference for the real root dentry and vfsmount */
49146 + get_fs_root(reaper->fs, &real_root);
49147 +
49148 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49149 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
49150 +#endif
49151 +
49152 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
49153 + if (fakefs_obj_rw == NULL)
49154 + return 1;
49155 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
49156 +
49157 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
49158 + if (fakefs_obj_rwx == NULL)
49159 + return 1;
49160 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
49161 +
49162 + subj_map_set.s_hash =
49163 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
49164 + acl_role_set.r_hash =
49165 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
49166 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
49167 + inodev_set.i_hash =
49168 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
49169 +
49170 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
49171 + !name_set.n_hash || !inodev_set.i_hash)
49172 + return 1;
49173 +
49174 + memset(subj_map_set.s_hash, 0,
49175 + sizeof(struct subject_map *) * subj_map_set.s_size);
49176 + memset(acl_role_set.r_hash, 0,
49177 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
49178 + memset(name_set.n_hash, 0,
49179 + sizeof (struct name_entry *) * name_set.n_size);
49180 + memset(inodev_set.i_hash, 0,
49181 + sizeof (struct inodev_entry *) * inodev_set.i_size);
49182 +
49183 + return 0;
49184 +}
49185 +
49186 +/* free information not needed after startup
49187 + currently contains user->kernel pointer mappings for subjects
49188 +*/
49189 +
49190 +static void
49191 +free_init_variables(void)
49192 +{
49193 + __u32 i;
49194 +
49195 + if (subj_map_set.s_hash) {
49196 + for (i = 0; i < subj_map_set.s_size; i++) {
49197 + if (subj_map_set.s_hash[i]) {
49198 + kfree(subj_map_set.s_hash[i]);
49199 + subj_map_set.s_hash[i] = NULL;
49200 + }
49201 + }
49202 +
49203 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
49204 + PAGE_SIZE)
49205 + kfree(subj_map_set.s_hash);
49206 + else
49207 + vfree(subj_map_set.s_hash);
49208 + }
49209 +
49210 + return;
49211 +}
49212 +
49213 +static void
49214 +free_variables(void)
49215 +{
49216 + struct acl_subject_label *s;
49217 + struct acl_role_label *r;
49218 + struct task_struct *task, *task2;
49219 + unsigned int x;
49220 +
49221 + gr_clear_learn_entries();
49222 +
49223 + read_lock(&tasklist_lock);
49224 + do_each_thread(task2, task) {
49225 + task->acl_sp_role = 0;
49226 + task->acl_role_id = 0;
49227 + task->acl = NULL;
49228 + task->role = NULL;
49229 + } while_each_thread(task2, task);
49230 + read_unlock(&tasklist_lock);
49231 +
49232 + /* release the reference to the real root dentry and vfsmount */
49233 + path_put(&real_root);
49234 +
49235 + /* free all object hash tables */
49236 +
49237 + FOR_EACH_ROLE_START(r)
49238 + if (r->subj_hash == NULL)
49239 + goto next_role;
49240 + FOR_EACH_SUBJECT_START(r, s, x)
49241 + if (s->obj_hash == NULL)
49242 + break;
49243 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
49244 + kfree(s->obj_hash);
49245 + else
49246 + vfree(s->obj_hash);
49247 + FOR_EACH_SUBJECT_END(s, x)
49248 + FOR_EACH_NESTED_SUBJECT_START(r, s)
49249 + if (s->obj_hash == NULL)
49250 + break;
49251 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
49252 + kfree(s->obj_hash);
49253 + else
49254 + vfree(s->obj_hash);
49255 + FOR_EACH_NESTED_SUBJECT_END(s)
49256 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
49257 + kfree(r->subj_hash);
49258 + else
49259 + vfree(r->subj_hash);
49260 + r->subj_hash = NULL;
49261 +next_role:
49262 + FOR_EACH_ROLE_END(r)
49263 +
49264 + acl_free_all();
49265 +
49266 + if (acl_role_set.r_hash) {
49267 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
49268 + PAGE_SIZE)
49269 + kfree(acl_role_set.r_hash);
49270 + else
49271 + vfree(acl_role_set.r_hash);
49272 + }
49273 + if (name_set.n_hash) {
49274 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
49275 + PAGE_SIZE)
49276 + kfree(name_set.n_hash);
49277 + else
49278 + vfree(name_set.n_hash);
49279 + }
49280 +
49281 + if (inodev_set.i_hash) {
49282 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
49283 + PAGE_SIZE)
49284 + kfree(inodev_set.i_hash);
49285 + else
49286 + vfree(inodev_set.i_hash);
49287 + }
49288 +
49289 + gr_free_uidset();
49290 +
49291 + memset(&name_set, 0, sizeof (struct name_db));
49292 + memset(&inodev_set, 0, sizeof (struct inodev_db));
49293 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
49294 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
49295 +
49296 + default_role = NULL;
49297 + role_list = NULL;
49298 +
49299 + return;
49300 +}
49301 +
49302 +static __u32
49303 +count_user_objs(struct acl_object_label *userp)
49304 +{
49305 + struct acl_object_label o_tmp;
49306 + __u32 num = 0;
49307 +
49308 + while (userp) {
49309 + if (copy_from_user(&o_tmp, userp,
49310 + sizeof (struct acl_object_label)))
49311 + break;
49312 +
49313 + userp = o_tmp.prev;
49314 + num++;
49315 + }
49316 +
49317 + return num;
49318 +}
49319 +
49320 +static struct acl_subject_label *
49321 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
49322 +
49323 +static int
49324 +copy_user_glob(struct acl_object_label *obj)
49325 +{
49326 + struct acl_object_label *g_tmp, **guser;
49327 + unsigned int len;
49328 + char *tmp;
49329 +
49330 + if (obj->globbed == NULL)
49331 + return 0;
49332 +
49333 + guser = &obj->globbed;
49334 + while (*guser) {
49335 + g_tmp = (struct acl_object_label *)
49336 + acl_alloc(sizeof (struct acl_object_label));
49337 + if (g_tmp == NULL)
49338 + return -ENOMEM;
49339 +
49340 + if (copy_from_user(g_tmp, *guser,
49341 + sizeof (struct acl_object_label)))
49342 + return -EFAULT;
49343 +
49344 + len = strnlen_user(g_tmp->filename, PATH_MAX);
49345 +
49346 + if (!len || len >= PATH_MAX)
49347 + return -EINVAL;
49348 +
49349 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49350 + return -ENOMEM;
49351 +
49352 + if (copy_from_user(tmp, g_tmp->filename, len))
49353 + return -EFAULT;
49354 + tmp[len-1] = '\0';
49355 + g_tmp->filename = tmp;
49356 +
49357 + *guser = g_tmp;
49358 + guser = &(g_tmp->next);
49359 + }
49360 +
49361 + return 0;
49362 +}
49363 +
49364 +static int
49365 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
49366 + struct acl_role_label *role)
49367 +{
49368 + struct acl_object_label *o_tmp;
49369 + unsigned int len;
49370 + int ret;
49371 + char *tmp;
49372 +
49373 + while (userp) {
49374 + if ((o_tmp = (struct acl_object_label *)
49375 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
49376 + return -ENOMEM;
49377 +
49378 + if (copy_from_user(o_tmp, userp,
49379 + sizeof (struct acl_object_label)))
49380 + return -EFAULT;
49381 +
49382 + userp = o_tmp->prev;
49383 +
49384 + len = strnlen_user(o_tmp->filename, PATH_MAX);
49385 +
49386 + if (!len || len >= PATH_MAX)
49387 + return -EINVAL;
49388 +
49389 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49390 + return -ENOMEM;
49391 +
49392 + if (copy_from_user(tmp, o_tmp->filename, len))
49393 + return -EFAULT;
49394 + tmp[len-1] = '\0';
49395 + o_tmp->filename = tmp;
49396 +
49397 + insert_acl_obj_label(o_tmp, subj);
49398 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
49399 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
49400 + return -ENOMEM;
49401 +
49402 + ret = copy_user_glob(o_tmp);
49403 + if (ret)
49404 + return ret;
49405 +
49406 + if (o_tmp->nested) {
49407 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
49408 + if (IS_ERR(o_tmp->nested))
49409 + return PTR_ERR(o_tmp->nested);
49410 +
49411 + /* insert into nested subject list */
49412 + o_tmp->nested->next = role->hash->first;
49413 + role->hash->first = o_tmp->nested;
49414 + }
49415 + }
49416 +
49417 + return 0;
49418 +}
49419 +
49420 +static __u32
49421 +count_user_subjs(struct acl_subject_label *userp)
49422 +{
49423 + struct acl_subject_label s_tmp;
49424 + __u32 num = 0;
49425 +
49426 + while (userp) {
49427 + if (copy_from_user(&s_tmp, userp,
49428 + sizeof (struct acl_subject_label)))
49429 + break;
49430 +
49431 + userp = s_tmp.prev;
49432 + /* do not count nested subjects against this count, since
49433 + they are not included in the hash table, but are
49434 + attached to objects. We have already counted
49435 + the subjects in userspace for the allocation
49436 + stack
49437 + */
49438 + if (!(s_tmp.mode & GR_NESTED))
49439 + num++;
49440 + }
49441 +
49442 + return num;
49443 +}
49444 +
49445 +static int
49446 +copy_user_allowedips(struct acl_role_label *rolep)
49447 +{
49448 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
49449 +
49450 + ruserip = rolep->allowed_ips;
49451 +
49452 + while (ruserip) {
49453 + rlast = rtmp;
49454 +
49455 + if ((rtmp = (struct role_allowed_ip *)
49456 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
49457 + return -ENOMEM;
49458 +
49459 + if (copy_from_user(rtmp, ruserip,
49460 + sizeof (struct role_allowed_ip)))
49461 + return -EFAULT;
49462 +
49463 + ruserip = rtmp->prev;
49464 +
49465 + if (!rlast) {
49466 + rtmp->prev = NULL;
49467 + rolep->allowed_ips = rtmp;
49468 + } else {
49469 + rlast->next = rtmp;
49470 + rtmp->prev = rlast;
49471 + }
49472 +
49473 + if (!ruserip)
49474 + rtmp->next = NULL;
49475 + }
49476 +
49477 + return 0;
49478 +}
49479 +
49480 +static int
49481 +copy_user_transitions(struct acl_role_label *rolep)
49482 +{
49483 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
49484 +
49485 + unsigned int len;
49486 + char *tmp;
49487 +
49488 + rusertp = rolep->transitions;
49489 +
49490 + while (rusertp) {
49491 + rlast = rtmp;
49492 +
49493 + if ((rtmp = (struct role_transition *)
49494 + acl_alloc(sizeof (struct role_transition))) == NULL)
49495 + return -ENOMEM;
49496 +
49497 + if (copy_from_user(rtmp, rusertp,
49498 + sizeof (struct role_transition)))
49499 + return -EFAULT;
49500 +
49501 + rusertp = rtmp->prev;
49502 +
49503 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
49504 +
49505 + if (!len || len >= GR_SPROLE_LEN)
49506 + return -EINVAL;
49507 +
49508 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49509 + return -ENOMEM;
49510 +
49511 + if (copy_from_user(tmp, rtmp->rolename, len))
49512 + return -EFAULT;
49513 + tmp[len-1] = '\0';
49514 + rtmp->rolename = tmp;
49515 +
49516 + if (!rlast) {
49517 + rtmp->prev = NULL;
49518 + rolep->transitions = rtmp;
49519 + } else {
49520 + rlast->next = rtmp;
49521 + rtmp->prev = rlast;
49522 + }
49523 +
49524 + if (!rusertp)
49525 + rtmp->next = NULL;
49526 + }
49527 +
49528 + return 0;
49529 +}
49530 +
49531 +static struct acl_subject_label *
49532 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
49533 +{
49534 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
49535 + unsigned int len;
49536 + char *tmp;
49537 + __u32 num_objs;
49538 + struct acl_ip_label **i_tmp, *i_utmp2;
49539 + struct gr_hash_struct ghash;
49540 + struct subject_map *subjmap;
49541 + unsigned int i_num;
49542 + int err;
49543 +
49544 + s_tmp = lookup_subject_map(userp);
49545 +
49546 + /* we've already copied this subject into the kernel, just return
49547 + the reference to it, and don't copy it over again
49548 + */
49549 + if (s_tmp)
49550 + return(s_tmp);
49551 +
49552 + if ((s_tmp = (struct acl_subject_label *)
49553 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
49554 + return ERR_PTR(-ENOMEM);
49555 +
49556 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
49557 + if (subjmap == NULL)
49558 + return ERR_PTR(-ENOMEM);
49559 +
49560 + subjmap->user = userp;
49561 + subjmap->kernel = s_tmp;
49562 + insert_subj_map_entry(subjmap);
49563 +
49564 + if (copy_from_user(s_tmp, userp,
49565 + sizeof (struct acl_subject_label)))
49566 + return ERR_PTR(-EFAULT);
49567 +
49568 + len = strnlen_user(s_tmp->filename, PATH_MAX);
49569 +
49570 + if (!len || len >= PATH_MAX)
49571 + return ERR_PTR(-EINVAL);
49572 +
49573 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49574 + return ERR_PTR(-ENOMEM);
49575 +
49576 + if (copy_from_user(tmp, s_tmp->filename, len))
49577 + return ERR_PTR(-EFAULT);
49578 + tmp[len-1] = '\0';
49579 + s_tmp->filename = tmp;
49580 +
49581 + if (!strcmp(s_tmp->filename, "/"))
49582 + role->root_label = s_tmp;
49583 +
49584 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
49585 + return ERR_PTR(-EFAULT);
49586 +
49587 + /* copy user and group transition tables */
49588 +
49589 + if (s_tmp->user_trans_num) {
49590 + uid_t *uidlist;
49591 +
49592 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
49593 + if (uidlist == NULL)
49594 + return ERR_PTR(-ENOMEM);
49595 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
49596 + return ERR_PTR(-EFAULT);
49597 +
49598 + s_tmp->user_transitions = uidlist;
49599 + }
49600 +
49601 + if (s_tmp->group_trans_num) {
49602 + gid_t *gidlist;
49603 +
49604 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
49605 + if (gidlist == NULL)
49606 + return ERR_PTR(-ENOMEM);
49607 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
49608 + return ERR_PTR(-EFAULT);
49609 +
49610 + s_tmp->group_transitions = gidlist;
49611 + }
49612 +
49613 + /* set up object hash table */
49614 + num_objs = count_user_objs(ghash.first);
49615 +
49616 + s_tmp->obj_hash_size = num_objs;
49617 + s_tmp->obj_hash =
49618 + (struct acl_object_label **)
49619 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
49620 +
49621 + if (!s_tmp->obj_hash)
49622 + return ERR_PTR(-ENOMEM);
49623 +
49624 + memset(s_tmp->obj_hash, 0,
49625 + s_tmp->obj_hash_size *
49626 + sizeof (struct acl_object_label *));
49627 +
49628 + /* add in objects */
49629 + err = copy_user_objs(ghash.first, s_tmp, role);
49630 +
49631 + if (err)
49632 + return ERR_PTR(err);
49633 +
49634 + /* set pointer for parent subject */
49635 + if (s_tmp->parent_subject) {
49636 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
49637 +
49638 + if (IS_ERR(s_tmp2))
49639 + return s_tmp2;
49640 +
49641 + s_tmp->parent_subject = s_tmp2;
49642 + }
49643 +
49644 + /* add in ip acls */
49645 +
49646 + if (!s_tmp->ip_num) {
49647 + s_tmp->ips = NULL;
49648 + goto insert;
49649 + }
49650 +
49651 + i_tmp =
49652 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
49653 + sizeof (struct acl_ip_label *));
49654 +
49655 + if (!i_tmp)
49656 + return ERR_PTR(-ENOMEM);
49657 +
49658 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
49659 + *(i_tmp + i_num) =
49660 + (struct acl_ip_label *)
49661 + acl_alloc(sizeof (struct acl_ip_label));
49662 + if (!*(i_tmp + i_num))
49663 + return ERR_PTR(-ENOMEM);
49664 +
49665 + if (copy_from_user
49666 + (&i_utmp2, s_tmp->ips + i_num,
49667 + sizeof (struct acl_ip_label *)))
49668 + return ERR_PTR(-EFAULT);
49669 +
49670 + if (copy_from_user
49671 + (*(i_tmp + i_num), i_utmp2,
49672 + sizeof (struct acl_ip_label)))
49673 + return ERR_PTR(-EFAULT);
49674 +
49675 + if ((*(i_tmp + i_num))->iface == NULL)
49676 + continue;
49677 +
49678 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
49679 + if (!len || len >= IFNAMSIZ)
49680 + return ERR_PTR(-EINVAL);
49681 + tmp = acl_alloc(len);
49682 + if (tmp == NULL)
49683 + return ERR_PTR(-ENOMEM);
49684 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
49685 + return ERR_PTR(-EFAULT);
49686 + (*(i_tmp + i_num))->iface = tmp;
49687 + }
49688 +
49689 + s_tmp->ips = i_tmp;
49690 +
49691 +insert:
49692 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
49693 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
49694 + return ERR_PTR(-ENOMEM);
49695 +
49696 + return s_tmp;
49697 +}
49698 +
49699 +static int
49700 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
49701 +{
49702 + struct acl_subject_label s_pre;
49703 + struct acl_subject_label * ret;
49704 + int err;
49705 +
49706 + while (userp) {
49707 + if (copy_from_user(&s_pre, userp,
49708 + sizeof (struct acl_subject_label)))
49709 + return -EFAULT;
49710 +
49711 + /* do not add nested subjects here, add
49712 + while parsing objects
49713 + */
49714 +
49715 + if (s_pre.mode & GR_NESTED) {
49716 + userp = s_pre.prev;
49717 + continue;
49718 + }
49719 +
49720 + ret = do_copy_user_subj(userp, role);
49721 +
49722 + err = PTR_ERR(ret);
49723 + if (IS_ERR(ret))
49724 + return err;
49725 +
49726 + insert_acl_subj_label(ret, role);
49727 +
49728 + userp = s_pre.prev;
49729 + }
49730 +
49731 + return 0;
49732 +}
49733 +
49734 +static int
49735 +copy_user_acl(struct gr_arg *arg)
49736 +{
49737 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
49738 + struct sprole_pw *sptmp;
49739 + struct gr_hash_struct *ghash;
49740 + uid_t *domainlist;
49741 + unsigned int r_num;
49742 + unsigned int len;
49743 + char *tmp;
49744 + int err = 0;
49745 + __u16 i;
49746 + __u32 num_subjs;
49747 +
49748 + /* we need a default and kernel role */
49749 + if (arg->role_db.num_roles < 2)
49750 + return -EINVAL;
49751 +
49752 + /* copy special role authentication info from userspace */
49753 +
49754 + num_sprole_pws = arg->num_sprole_pws;
49755 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
49756 +
49757 + if (!acl_special_roles) {
49758 + err = -ENOMEM;
49759 + goto cleanup;
49760 + }
49761 +
49762 + for (i = 0; i < num_sprole_pws; i++) {
49763 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
49764 + if (!sptmp) {
49765 + err = -ENOMEM;
49766 + goto cleanup;
49767 + }
49768 + if (copy_from_user(sptmp, arg->sprole_pws + i,
49769 + sizeof (struct sprole_pw))) {
49770 + err = -EFAULT;
49771 + goto cleanup;
49772 + }
49773 +
49774 + len =
49775 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
49776 +
49777 + if (!len || len >= GR_SPROLE_LEN) {
49778 + err = -EINVAL;
49779 + goto cleanup;
49780 + }
49781 +
49782 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
49783 + err = -ENOMEM;
49784 + goto cleanup;
49785 + }
49786 +
49787 + if (copy_from_user(tmp, sptmp->rolename, len)) {
49788 + err = -EFAULT;
49789 + goto cleanup;
49790 + }
49791 + tmp[len-1] = '\0';
49792 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49793 + printk(KERN_ALERT "Copying special role %s\n", tmp);
49794 +#endif
49795 + sptmp->rolename = tmp;
49796 + acl_special_roles[i] = sptmp;
49797 + }
49798 +
49799 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
49800 +
49801 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
49802 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
49803 +
49804 + if (!r_tmp) {
49805 + err = -ENOMEM;
49806 + goto cleanup;
49807 + }
49808 +
49809 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
49810 + sizeof (struct acl_role_label *))) {
49811 + err = -EFAULT;
49812 + goto cleanup;
49813 + }
49814 +
49815 + if (copy_from_user(r_tmp, r_utmp2,
49816 + sizeof (struct acl_role_label))) {
49817 + err = -EFAULT;
49818 + goto cleanup;
49819 + }
49820 +
49821 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
49822 +
49823 + if (!len || len >= PATH_MAX) {
49824 + err = -EINVAL;
49825 + goto cleanup;
49826 + }
49827 +
49828 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
49829 + err = -ENOMEM;
49830 + goto cleanup;
49831 + }
49832 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
49833 + err = -EFAULT;
49834 + goto cleanup;
49835 + }
49836 + tmp[len-1] = '\0';
49837 + r_tmp->rolename = tmp;
49838 +
49839 + if (!strcmp(r_tmp->rolename, "default")
49840 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
49841 + default_role = r_tmp;
49842 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
49843 + kernel_role = r_tmp;
49844 + }
49845 +
49846 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
49847 + err = -ENOMEM;
49848 + goto cleanup;
49849 + }
49850 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
49851 + err = -EFAULT;
49852 + goto cleanup;
49853 + }
49854 +
49855 + r_tmp->hash = ghash;
49856 +
49857 + num_subjs = count_user_subjs(r_tmp->hash->first);
49858 +
49859 + r_tmp->subj_hash_size = num_subjs;
49860 + r_tmp->subj_hash =
49861 + (struct acl_subject_label **)
49862 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
49863 +
49864 + if (!r_tmp->subj_hash) {
49865 + err = -ENOMEM;
49866 + goto cleanup;
49867 + }
49868 +
49869 + err = copy_user_allowedips(r_tmp);
49870 + if (err)
49871 + goto cleanup;
49872 +
49873 + /* copy domain info */
49874 + if (r_tmp->domain_children != NULL) {
49875 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
49876 + if (domainlist == NULL) {
49877 + err = -ENOMEM;
49878 + goto cleanup;
49879 + }
49880 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
49881 + err = -EFAULT;
49882 + goto cleanup;
49883 + }
49884 + r_tmp->domain_children = domainlist;
49885 + }
49886 +
49887 + err = copy_user_transitions(r_tmp);
49888 + if (err)
49889 + goto cleanup;
49890 +
49891 + memset(r_tmp->subj_hash, 0,
49892 + r_tmp->subj_hash_size *
49893 + sizeof (struct acl_subject_label *));
49894 +
49895 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
49896 +
49897 + if (err)
49898 + goto cleanup;
49899 +
49900 + /* set nested subject list to null */
49901 + r_tmp->hash->first = NULL;
49902 +
49903 + insert_acl_role_label(r_tmp);
49904 + }
49905 +
49906 + goto return_err;
49907 + cleanup:
49908 + free_variables();
49909 + return_err:
49910 + return err;
49911 +
49912 +}
49913 +
49914 +static int
49915 +gracl_init(struct gr_arg *args)
49916 +{
49917 + int error = 0;
49918 +
49919 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
49920 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
49921 +
49922 + if (init_variables(args)) {
49923 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
49924 + error = -ENOMEM;
49925 + free_variables();
49926 + goto out;
49927 + }
49928 +
49929 + error = copy_user_acl(args);
49930 + free_init_variables();
49931 + if (error) {
49932 + free_variables();
49933 + goto out;
49934 + }
49935 +
49936 + if ((error = gr_set_acls(0))) {
49937 + free_variables();
49938 + goto out;
49939 + }
49940 +
49941 + pax_open_kernel();
49942 + gr_status |= GR_READY;
49943 + pax_close_kernel();
49944 +
49945 + out:
49946 + return error;
49947 +}
49948 +
49949 +/* derived from glibc fnmatch() 0: match, 1: no match*/
49950 +
49951 +static int
49952 +glob_match(const char *p, const char *n)
49953 +{
49954 + char c;
49955 +
49956 + while ((c = *p++) != '\0') {
49957 + switch (c) {
49958 + case '?':
49959 + if (*n == '\0')
49960 + return 1;
49961 + else if (*n == '/')
49962 + return 1;
49963 + break;
49964 + case '\\':
49965 + if (*n != c)
49966 + return 1;
49967 + break;
49968 + case '*':
49969 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
49970 + if (*n == '/')
49971 + return 1;
49972 + else if (c == '?') {
49973 + if (*n == '\0')
49974 + return 1;
49975 + else
49976 + ++n;
49977 + }
49978 + }
49979 + if (c == '\0') {
49980 + return 0;
49981 + } else {
49982 + const char *endp;
49983 +
49984 + if ((endp = strchr(n, '/')) == NULL)
49985 + endp = n + strlen(n);
49986 +
49987 + if (c == '[') {
49988 + for (--p; n < endp; ++n)
49989 + if (!glob_match(p, n))
49990 + return 0;
49991 + } else if (c == '/') {
49992 + while (*n != '\0' && *n != '/')
49993 + ++n;
49994 + if (*n == '/' && !glob_match(p, n + 1))
49995 + return 0;
49996 + } else {
49997 + for (--p; n < endp; ++n)
49998 + if (*n == c && !glob_match(p, n))
49999 + return 0;
50000 + }
50001 +
50002 + return 1;
50003 + }
50004 + case '[':
50005 + {
50006 + int not;
50007 + char cold;
50008 +
50009 + if (*n == '\0' || *n == '/')
50010 + return 1;
50011 +
50012 + not = (*p == '!' || *p == '^');
50013 + if (not)
50014 + ++p;
50015 +
50016 + c = *p++;
50017 + for (;;) {
50018 + unsigned char fn = (unsigned char)*n;
50019 +
50020 + if (c == '\0')
50021 + return 1;
50022 + else {
50023 + if (c == fn)
50024 + goto matched;
50025 + cold = c;
50026 + c = *p++;
50027 +
50028 + if (c == '-' && *p != ']') {
50029 + unsigned char cend = *p++;
50030 +
50031 + if (cend == '\0')
50032 + return 1;
50033 +
50034 + if (cold <= fn && fn <= cend)
50035 + goto matched;
50036 +
50037 + c = *p++;
50038 + }
50039 + }
50040 +
50041 + if (c == ']')
50042 + break;
50043 + }
50044 + if (!not)
50045 + return 1;
50046 + break;
50047 + matched:
50048 + while (c != ']') {
50049 + if (c == '\0')
50050 + return 1;
50051 +
50052 + c = *p++;
50053 + }
50054 + if (not)
50055 + return 1;
50056 + }
50057 + break;
50058 + default:
50059 + if (c != *n)
50060 + return 1;
50061 + }
50062 +
50063 + ++n;
50064 + }
50065 +
50066 + if (*n == '\0')
50067 + return 0;
50068 +
50069 + if (*n == '/')
50070 + return 0;
50071 +
50072 + return 1;
50073 +}
50074 +
50075 +static struct acl_object_label *
50076 +chk_glob_label(struct acl_object_label *globbed,
50077 + struct dentry *dentry, struct vfsmount *mnt, char **path)
50078 +{
50079 + struct acl_object_label *tmp;
50080 +
50081 + if (*path == NULL)
50082 + *path = gr_to_filename_nolock(dentry, mnt);
50083 +
50084 + tmp = globbed;
50085 +
50086 + while (tmp) {
50087 + if (!glob_match(tmp->filename, *path))
50088 + return tmp;
50089 + tmp = tmp->next;
50090 + }
50091 +
50092 + return NULL;
50093 +}
50094 +
50095 +static struct acl_object_label *
50096 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
50097 + const ino_t curr_ino, const dev_t curr_dev,
50098 + const struct acl_subject_label *subj, char **path, const int checkglob)
50099 +{
50100 + struct acl_subject_label *tmpsubj;
50101 + struct acl_object_label *retval;
50102 + struct acl_object_label *retval2;
50103 +
50104 + tmpsubj = (struct acl_subject_label *) subj;
50105 + read_lock(&gr_inode_lock);
50106 + do {
50107 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
50108 + if (retval) {
50109 + if (checkglob && retval->globbed) {
50110 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
50111 + (struct vfsmount *)orig_mnt, path);
50112 + if (retval2)
50113 + retval = retval2;
50114 + }
50115 + break;
50116 + }
50117 + } while ((tmpsubj = tmpsubj->parent_subject));
50118 + read_unlock(&gr_inode_lock);
50119 +
50120 + return retval;
50121 +}
50122 +
50123 +static __inline__ struct acl_object_label *
50124 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
50125 + struct dentry *curr_dentry,
50126 + const struct acl_subject_label *subj, char **path, const int checkglob)
50127 +{
50128 + int newglob = checkglob;
50129 + ino_t inode;
50130 + dev_t device;
50131 +
50132 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
50133 + as we don't want a / * rule to match instead of the / object
50134 + don't do this for create lookups that call this function though, since they're looking up
50135 + on the parent and thus need globbing checks on all paths
50136 + */
50137 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
50138 + newglob = GR_NO_GLOB;
50139 +
50140 + spin_lock(&curr_dentry->d_lock);
50141 + inode = curr_dentry->d_inode->i_ino;
50142 + device = __get_dev(curr_dentry);
50143 + spin_unlock(&curr_dentry->d_lock);
50144 +
50145 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
50146 +}
50147 +
50148 +static struct acl_object_label *
50149 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50150 + const struct acl_subject_label *subj, char *path, const int checkglob)
50151 +{
50152 + struct dentry *dentry = (struct dentry *) l_dentry;
50153 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
50154 + struct acl_object_label *retval;
50155 + struct dentry *parent;
50156 +
50157 + write_seqlock(&rename_lock);
50158 + br_read_lock(vfsmount_lock);
50159 +
50160 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
50161 +#ifdef CONFIG_NET
50162 + mnt == sock_mnt ||
50163 +#endif
50164 +#ifdef CONFIG_HUGETLBFS
50165 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
50166 +#endif
50167 + /* ignore Eric Biederman */
50168 + IS_PRIVATE(l_dentry->d_inode))) {
50169 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
50170 + goto out;
50171 + }
50172 +
50173 + for (;;) {
50174 + if (dentry == real_root.dentry && mnt == real_root.mnt)
50175 + break;
50176 +
50177 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
50178 + if (mnt->mnt_parent == mnt)
50179 + break;
50180 +
50181 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50182 + if (retval != NULL)
50183 + goto out;
50184 +
50185 + dentry = mnt->mnt_mountpoint;
50186 + mnt = mnt->mnt_parent;
50187 + continue;
50188 + }
50189 +
50190 + parent = dentry->d_parent;
50191 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50192 + if (retval != NULL)
50193 + goto out;
50194 +
50195 + dentry = parent;
50196 + }
50197 +
50198 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50199 +
50200 + /* real_root is pinned so we don't have to hold a reference */
50201 + if (retval == NULL)
50202 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
50203 +out:
50204 + br_read_unlock(vfsmount_lock);
50205 + write_sequnlock(&rename_lock);
50206 +
50207 + BUG_ON(retval == NULL);
50208 +
50209 + return retval;
50210 +}
50211 +
50212 +static __inline__ struct acl_object_label *
50213 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50214 + const struct acl_subject_label *subj)
50215 +{
50216 + char *path = NULL;
50217 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
50218 +}
50219 +
50220 +static __inline__ struct acl_object_label *
50221 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50222 + const struct acl_subject_label *subj)
50223 +{
50224 + char *path = NULL;
50225 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
50226 +}
50227 +
50228 +static __inline__ struct acl_object_label *
50229 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50230 + const struct acl_subject_label *subj, char *path)
50231 +{
50232 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
50233 +}
50234 +
50235 +static struct acl_subject_label *
50236 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50237 + const struct acl_role_label *role)
50238 +{
50239 + struct dentry *dentry = (struct dentry *) l_dentry;
50240 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
50241 + struct acl_subject_label *retval;
50242 + struct dentry *parent;
50243 +
50244 + write_seqlock(&rename_lock);
50245 + br_read_lock(vfsmount_lock);
50246 +
50247 + for (;;) {
50248 + if (dentry == real_root.dentry && mnt == real_root.mnt)
50249 + break;
50250 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
50251 + if (mnt->mnt_parent == mnt)
50252 + break;
50253 +
50254 + spin_lock(&dentry->d_lock);
50255 + read_lock(&gr_inode_lock);
50256 + retval =
50257 + lookup_acl_subj_label(dentry->d_inode->i_ino,
50258 + __get_dev(dentry), role);
50259 + read_unlock(&gr_inode_lock);
50260 + spin_unlock(&dentry->d_lock);
50261 + if (retval != NULL)
50262 + goto out;
50263 +
50264 + dentry = mnt->mnt_mountpoint;
50265 + mnt = mnt->mnt_parent;
50266 + continue;
50267 + }
50268 +
50269 + spin_lock(&dentry->d_lock);
50270 + read_lock(&gr_inode_lock);
50271 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
50272 + __get_dev(dentry), role);
50273 + read_unlock(&gr_inode_lock);
50274 + parent = dentry->d_parent;
50275 + spin_unlock(&dentry->d_lock);
50276 +
50277 + if (retval != NULL)
50278 + goto out;
50279 +
50280 + dentry = parent;
50281 + }
50282 +
50283 + spin_lock(&dentry->d_lock);
50284 + read_lock(&gr_inode_lock);
50285 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
50286 + __get_dev(dentry), role);
50287 + read_unlock(&gr_inode_lock);
50288 + spin_unlock(&dentry->d_lock);
50289 +
50290 + if (unlikely(retval == NULL)) {
50291 + /* real_root is pinned, we don't need to hold a reference */
50292 + read_lock(&gr_inode_lock);
50293 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
50294 + __get_dev(real_root.dentry), role);
50295 + read_unlock(&gr_inode_lock);
50296 + }
50297 +out:
50298 + br_read_unlock(vfsmount_lock);
50299 + write_sequnlock(&rename_lock);
50300 +
50301 + BUG_ON(retval == NULL);
50302 +
50303 + return retval;
50304 +}
50305 +
50306 +static void
50307 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
50308 +{
50309 + struct task_struct *task = current;
50310 + const struct cred *cred = current_cred();
50311 +
50312 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
50313 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50314 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50315 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
50316 +
50317 + return;
50318 +}
50319 +
50320 +static void
50321 +gr_log_learn_sysctl(const char *path, const __u32 mode)
50322 +{
50323 + struct task_struct *task = current;
50324 + const struct cred *cred = current_cred();
50325 +
50326 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
50327 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50328 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50329 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
50330 +
50331 + return;
50332 +}
50333 +
50334 +static void
50335 +gr_log_learn_id_change(const char type, const unsigned int real,
50336 + const unsigned int effective, const unsigned int fs)
50337 +{
50338 + struct task_struct *task = current;
50339 + const struct cred *cred = current_cred();
50340 +
50341 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
50342 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50343 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50344 + type, real, effective, fs, &task->signal->saved_ip);
50345 +
50346 + return;
50347 +}
50348 +
50349 +__u32
50350 +gr_search_file(const struct dentry * dentry, const __u32 mode,
50351 + const struct vfsmount * mnt)
50352 +{
50353 + __u32 retval = mode;
50354 + struct acl_subject_label *curracl;
50355 + struct acl_object_label *currobj;
50356 +
50357 + if (unlikely(!(gr_status & GR_READY)))
50358 + return (mode & ~GR_AUDITS);
50359 +
50360 + curracl = current->acl;
50361 +
50362 + currobj = chk_obj_label(dentry, mnt, curracl);
50363 + retval = currobj->mode & mode;
50364 +
50365 + /* if we're opening a specified transfer file for writing
50366 + (e.g. /dev/initctl), then transfer our role to init
50367 + */
50368 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
50369 + current->role->roletype & GR_ROLE_PERSIST)) {
50370 + struct task_struct *task = init_pid_ns.child_reaper;
50371 +
50372 + if (task->role != current->role) {
50373 + task->acl_sp_role = 0;
50374 + task->acl_role_id = current->acl_role_id;
50375 + task->role = current->role;
50376 + rcu_read_lock();
50377 + read_lock(&grsec_exec_file_lock);
50378 + gr_apply_subject_to_task(task);
50379 + read_unlock(&grsec_exec_file_lock);
50380 + rcu_read_unlock();
50381 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
50382 + }
50383 + }
50384 +
50385 + if (unlikely
50386 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
50387 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
50388 + __u32 new_mode = mode;
50389 +
50390 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
50391 +
50392 + retval = new_mode;
50393 +
50394 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
50395 + new_mode |= GR_INHERIT;
50396 +
50397 + if (!(mode & GR_NOLEARN))
50398 + gr_log_learn(dentry, mnt, new_mode);
50399 + }
50400 +
50401 + return retval;
50402 +}
50403 +
50404 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
50405 + const struct dentry *parent,
50406 + const struct vfsmount *mnt)
50407 +{
50408 + struct name_entry *match;
50409 + struct acl_object_label *matchpo;
50410 + struct acl_subject_label *curracl;
50411 + char *path;
50412 +
50413 + if (unlikely(!(gr_status & GR_READY)))
50414 + return NULL;
50415 +
50416 + preempt_disable();
50417 + path = gr_to_filename_rbac(new_dentry, mnt);
50418 + match = lookup_name_entry_create(path);
50419 +
50420 + curracl = current->acl;
50421 +
50422 + if (match) {
50423 + read_lock(&gr_inode_lock);
50424 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
50425 + read_unlock(&gr_inode_lock);
50426 +
50427 + if (matchpo) {
50428 + preempt_enable();
50429 + return matchpo;
50430 + }
50431 + }
50432 +
50433 + // lookup parent
50434 +
50435 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
50436 +
50437 + preempt_enable();
50438 + return matchpo;
50439 +}
50440 +
50441 +__u32
50442 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
50443 + const struct vfsmount * mnt, const __u32 mode)
50444 +{
50445 + struct acl_object_label *matchpo;
50446 + __u32 retval;
50447 +
50448 + if (unlikely(!(gr_status & GR_READY)))
50449 + return (mode & ~GR_AUDITS);
50450 +
50451 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
50452 +
50453 + retval = matchpo->mode & mode;
50454 +
50455 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
50456 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
50457 + __u32 new_mode = mode;
50458 +
50459 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
50460 +
50461 + gr_log_learn(new_dentry, mnt, new_mode);
50462 + return new_mode;
50463 + }
50464 +
50465 + return retval;
50466 +}
50467 +
50468 +__u32
50469 +gr_check_link(const struct dentry * new_dentry,
50470 + const struct dentry * parent_dentry,
50471 + const struct vfsmount * parent_mnt,
50472 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
50473 +{
50474 + struct acl_object_label *obj;
50475 + __u32 oldmode, newmode;
50476 + __u32 needmode;
50477 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
50478 + GR_DELETE | GR_INHERIT;
50479 +
50480 + if (unlikely(!(gr_status & GR_READY)))
50481 + return (GR_CREATE | GR_LINK);
50482 +
50483 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
50484 + oldmode = obj->mode;
50485 +
50486 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
50487 + newmode = obj->mode;
50488 +
50489 + needmode = newmode & checkmodes;
50490 +
50491 + // old name for hardlink must have at least the permissions of the new name
50492 + if ((oldmode & needmode) != needmode)
50493 + goto bad;
50494 +
50495 + // if old name had restrictions/auditing, make sure the new name does as well
50496 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
50497 +
50498 + // don't allow hardlinking of suid/sgid files without permission
50499 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
50500 + needmode |= GR_SETID;
50501 +
50502 + if ((newmode & needmode) != needmode)
50503 + goto bad;
50504 +
50505 + // enforce minimum permissions
50506 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
50507 + return newmode;
50508 +bad:
50509 + needmode = oldmode;
50510 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
50511 + needmode |= GR_SETID;
50512 +
50513 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
50514 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
50515 + return (GR_CREATE | GR_LINK);
50516 + } else if (newmode & GR_SUPPRESS)
50517 + return GR_SUPPRESS;
50518 + else
50519 + return 0;
50520 +}
50521 +
50522 +int
50523 +gr_check_hidden_task(const struct task_struct *task)
50524 +{
50525 + if (unlikely(!(gr_status & GR_READY)))
50526 + return 0;
50527 +
50528 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
50529 + return 1;
50530 +
50531 + return 0;
50532 +}
50533 +
50534 +int
50535 +gr_check_protected_task(const struct task_struct *task)
50536 +{
50537 + if (unlikely(!(gr_status & GR_READY) || !task))
50538 + return 0;
50539 +
50540 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
50541 + task->acl != current->acl)
50542 + return 1;
50543 +
50544 + return 0;
50545 +}
50546 +
50547 +int
50548 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
50549 +{
50550 + struct task_struct *p;
50551 + int ret = 0;
50552 +
50553 + if (unlikely(!(gr_status & GR_READY) || !pid))
50554 + return ret;
50555 +
50556 + read_lock(&tasklist_lock);
50557 + do_each_pid_task(pid, type, p) {
50558 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
50559 + p->acl != current->acl) {
50560 + ret = 1;
50561 + goto out;
50562 + }
50563 + } while_each_pid_task(pid, type, p);
50564 +out:
50565 + read_unlock(&tasklist_lock);
50566 +
50567 + return ret;
50568 +}
50569 +
50570 +void
50571 +gr_copy_label(struct task_struct *tsk)
50572 +{
50573 + tsk->signal->used_accept = 0;
50574 + tsk->acl_sp_role = 0;
50575 + tsk->acl_role_id = current->acl_role_id;
50576 + tsk->acl = current->acl;
50577 + tsk->role = current->role;
50578 + tsk->signal->curr_ip = current->signal->curr_ip;
50579 + tsk->signal->saved_ip = current->signal->saved_ip;
50580 + if (current->exec_file)
50581 + get_file(current->exec_file);
50582 + tsk->exec_file = current->exec_file;
50583 + tsk->is_writable = current->is_writable;
50584 + if (unlikely(current->signal->used_accept)) {
50585 + current->signal->curr_ip = 0;
50586 + current->signal->saved_ip = 0;
50587 + }
50588 +
50589 + return;
50590 +}
50591 +
50592 +static void
50593 +gr_set_proc_res(struct task_struct *task)
50594 +{
50595 + struct acl_subject_label *proc;
50596 + unsigned short i;
50597 +
50598 + proc = task->acl;
50599 +
50600 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
50601 + return;
50602 +
50603 + for (i = 0; i < RLIM_NLIMITS; i++) {
50604 + if (!(proc->resmask & (1 << i)))
50605 + continue;
50606 +
50607 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
50608 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
50609 + }
50610 +
50611 + return;
50612 +}
50613 +
50614 +extern int __gr_process_user_ban(struct user_struct *user);
50615 +
50616 +int
50617 +gr_check_user_change(int real, int effective, int fs)
50618 +{
50619 + unsigned int i;
50620 + __u16 num;
50621 + uid_t *uidlist;
50622 + int curuid;
50623 + int realok = 0;
50624 + int effectiveok = 0;
50625 + int fsok = 0;
50626 +
50627 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
50628 + struct user_struct *user;
50629 +
50630 + if (real == -1)
50631 + goto skipit;
50632 +
50633 + user = find_user(real);
50634 + if (user == NULL)
50635 + goto skipit;
50636 +
50637 + if (__gr_process_user_ban(user)) {
50638 + /* for find_user */
50639 + free_uid(user);
50640 + return 1;
50641 + }
50642 +
50643 + /* for find_user */
50644 + free_uid(user);
50645 +
50646 +skipit:
50647 +#endif
50648 +
50649 + if (unlikely(!(gr_status & GR_READY)))
50650 + return 0;
50651 +
50652 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
50653 + gr_log_learn_id_change('u', real, effective, fs);
50654 +
50655 + num = current->acl->user_trans_num;
50656 + uidlist = current->acl->user_transitions;
50657 +
50658 + if (uidlist == NULL)
50659 + return 0;
50660 +
50661 + if (real == -1)
50662 + realok = 1;
50663 + if (effective == -1)
50664 + effectiveok = 1;
50665 + if (fs == -1)
50666 + fsok = 1;
50667 +
50668 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
50669 + for (i = 0; i < num; i++) {
50670 + curuid = (int)uidlist[i];
50671 + if (real == curuid)
50672 + realok = 1;
50673 + if (effective == curuid)
50674 + effectiveok = 1;
50675 + if (fs == curuid)
50676 + fsok = 1;
50677 + }
50678 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
50679 + for (i = 0; i < num; i++) {
50680 + curuid = (int)uidlist[i];
50681 + if (real == curuid)
50682 + break;
50683 + if (effective == curuid)
50684 + break;
50685 + if (fs == curuid)
50686 + break;
50687 + }
50688 + /* not in deny list */
50689 + if (i == num) {
50690 + realok = 1;
50691 + effectiveok = 1;
50692 + fsok = 1;
50693 + }
50694 + }
50695 +
50696 + if (realok && effectiveok && fsok)
50697 + return 0;
50698 + else {
50699 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
50700 + return 1;
50701 + }
50702 +}
50703 +
50704 +int
50705 +gr_check_group_change(int real, int effective, int fs)
50706 +{
50707 + unsigned int i;
50708 + __u16 num;
50709 + gid_t *gidlist;
50710 + int curgid;
50711 + int realok = 0;
50712 + int effectiveok = 0;
50713 + int fsok = 0;
50714 +
50715 + if (unlikely(!(gr_status & GR_READY)))
50716 + return 0;
50717 +
50718 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
50719 + gr_log_learn_id_change('g', real, effective, fs);
50720 +
50721 + num = current->acl->group_trans_num;
50722 + gidlist = current->acl->group_transitions;
50723 +
50724 + if (gidlist == NULL)
50725 + return 0;
50726 +
50727 + if (real == -1)
50728 + realok = 1;
50729 + if (effective == -1)
50730 + effectiveok = 1;
50731 + if (fs == -1)
50732 + fsok = 1;
50733 +
50734 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
50735 + for (i = 0; i < num; i++) {
50736 + curgid = (int)gidlist[i];
50737 + if (real == curgid)
50738 + realok = 1;
50739 + if (effective == curgid)
50740 + effectiveok = 1;
50741 + if (fs == curgid)
50742 + fsok = 1;
50743 + }
50744 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
50745 + for (i = 0; i < num; i++) {
50746 + curgid = (int)gidlist[i];
50747 + if (real == curgid)
50748 + break;
50749 + if (effective == curgid)
50750 + break;
50751 + if (fs == curgid)
50752 + break;
50753 + }
50754 + /* not in deny list */
50755 + if (i == num) {
50756 + realok = 1;
50757 + effectiveok = 1;
50758 + fsok = 1;
50759 + }
50760 + }
50761 +
50762 + if (realok && effectiveok && fsok)
50763 + return 0;
50764 + else {
50765 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
50766 + return 1;
50767 + }
50768 +}
50769 +
50770 +void
50771 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
50772 +{
50773 + struct acl_role_label *role = task->role;
50774 + struct acl_subject_label *subj = NULL;
50775 + struct acl_object_label *obj;
50776 + struct file *filp;
50777 +
50778 + if (unlikely(!(gr_status & GR_READY)))
50779 + return;
50780 +
50781 + filp = task->exec_file;
50782 +
50783 + /* kernel process, we'll give them the kernel role */
50784 + if (unlikely(!filp)) {
50785 + task->role = kernel_role;
50786 + task->acl = kernel_role->root_label;
50787 + return;
50788 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
50789 + role = lookup_acl_role_label(task, uid, gid);
50790 +
50791 + /* perform subject lookup in possibly new role
50792 + we can use this result below in the case where role == task->role
50793 + */
50794 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
50795 +
50796 + /* if we changed uid/gid, but result in the same role
50797 + and are using inheritance, don't lose the inherited subject
50798 + if current subject is other than what normal lookup
50799 + would result in, we arrived via inheritance, don't
50800 + lose subject
50801 + */
50802 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
50803 + (subj == task->acl)))
50804 + task->acl = subj;
50805 +
50806 + task->role = role;
50807 +
50808 + task->is_writable = 0;
50809 +
50810 + /* ignore additional mmap checks for processes that are writable
50811 + by the default ACL */
50812 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
50813 + if (unlikely(obj->mode & GR_WRITE))
50814 + task->is_writable = 1;
50815 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
50816 + if (unlikely(obj->mode & GR_WRITE))
50817 + task->is_writable = 1;
50818 +
50819 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50820 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
50821 +#endif
50822 +
50823 + gr_set_proc_res(task);
50824 +
50825 + return;
50826 +}
50827 +
50828 +int
50829 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
50830 + const int unsafe_share)
50831 +{
50832 + struct task_struct *task = current;
50833 + struct acl_subject_label *newacl;
50834 + struct acl_object_label *obj;
50835 + __u32 retmode;
50836 +
50837 + if (unlikely(!(gr_status & GR_READY)))
50838 + return 0;
50839 +
50840 + newacl = chk_subj_label(dentry, mnt, task->role);
50841 +
50842 + task_lock(task);
50843 + if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
50844 + !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
50845 + !(task->role->roletype & GR_ROLE_GOD) &&
50846 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
50847 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
50848 + task_unlock(task);
50849 + if (unsafe_share)
50850 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
50851 + else
50852 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
50853 + return -EACCES;
50854 + }
50855 + task_unlock(task);
50856 +
50857 + obj = chk_obj_label(dentry, mnt, task->acl);
50858 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
50859 +
50860 + if (!(task->acl->mode & GR_INHERITLEARN) &&
50861 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
50862 + if (obj->nested)
50863 + task->acl = obj->nested;
50864 + else
50865 + task->acl = newacl;
50866 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
50867 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
50868 +
50869 + task->is_writable = 0;
50870 +
50871 + /* ignore additional mmap checks for processes that are writable
50872 + by the default ACL */
50873 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
50874 + if (unlikely(obj->mode & GR_WRITE))
50875 + task->is_writable = 1;
50876 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
50877 + if (unlikely(obj->mode & GR_WRITE))
50878 + task->is_writable = 1;
50879 +
50880 + gr_set_proc_res(task);
50881 +
50882 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50883 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
50884 +#endif
50885 + return 0;
50886 +}
50887 +
50888 +/* always called with valid inodev ptr */
50889 +static void
50890 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
50891 +{
50892 + struct acl_object_label *matchpo;
50893 + struct acl_subject_label *matchps;
50894 + struct acl_subject_label *subj;
50895 + struct acl_role_label *role;
50896 + unsigned int x;
50897 +
50898 + FOR_EACH_ROLE_START(role)
50899 + FOR_EACH_SUBJECT_START(role, subj, x)
50900 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
50901 + matchpo->mode |= GR_DELETED;
50902 + FOR_EACH_SUBJECT_END(subj,x)
50903 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
50904 + if (subj->inode == ino && subj->device == dev)
50905 + subj->mode |= GR_DELETED;
50906 + FOR_EACH_NESTED_SUBJECT_END(subj)
50907 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
50908 + matchps->mode |= GR_DELETED;
50909 + FOR_EACH_ROLE_END(role)
50910 +
50911 + inodev->nentry->deleted = 1;
50912 +
50913 + return;
50914 +}
50915 +
50916 +void
50917 +gr_handle_delete(const ino_t ino, const dev_t dev)
50918 +{
50919 + struct inodev_entry *inodev;
50920 +
50921 + if (unlikely(!(gr_status & GR_READY)))
50922 + return;
50923 +
50924 + write_lock(&gr_inode_lock);
50925 + inodev = lookup_inodev_entry(ino, dev);
50926 + if (inodev != NULL)
50927 + do_handle_delete(inodev, ino, dev);
50928 + write_unlock(&gr_inode_lock);
50929 +
50930 + return;
50931 +}
50932 +
50933 +static void
50934 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
50935 + const ino_t newinode, const dev_t newdevice,
50936 + struct acl_subject_label *subj)
50937 +{
50938 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
50939 + struct acl_object_label *match;
50940 +
50941 + match = subj->obj_hash[index];
50942 +
50943 + while (match && (match->inode != oldinode ||
50944 + match->device != olddevice ||
50945 + !(match->mode & GR_DELETED)))
50946 + match = match->next;
50947 +
50948 + if (match && (match->inode == oldinode)
50949 + && (match->device == olddevice)
50950 + && (match->mode & GR_DELETED)) {
50951 + if (match->prev == NULL) {
50952 + subj->obj_hash[index] = match->next;
50953 + if (match->next != NULL)
50954 + match->next->prev = NULL;
50955 + } else {
50956 + match->prev->next = match->next;
50957 + if (match->next != NULL)
50958 + match->next->prev = match->prev;
50959 + }
50960 + match->prev = NULL;
50961 + match->next = NULL;
50962 + match->inode = newinode;
50963 + match->device = newdevice;
50964 + match->mode &= ~GR_DELETED;
50965 +
50966 + insert_acl_obj_label(match, subj);
50967 + }
50968 +
50969 + return;
50970 +}
50971 +
50972 +static void
50973 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
50974 + const ino_t newinode, const dev_t newdevice,
50975 + struct acl_role_label *role)
50976 +{
50977 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
50978 + struct acl_subject_label *match;
50979 +
50980 + match = role->subj_hash[index];
50981 +
50982 + while (match && (match->inode != oldinode ||
50983 + match->device != olddevice ||
50984 + !(match->mode & GR_DELETED)))
50985 + match = match->next;
50986 +
50987 + if (match && (match->inode == oldinode)
50988 + && (match->device == olddevice)
50989 + && (match->mode & GR_DELETED)) {
50990 + if (match->prev == NULL) {
50991 + role->subj_hash[index] = match->next;
50992 + if (match->next != NULL)
50993 + match->next->prev = NULL;
50994 + } else {
50995 + match->prev->next = match->next;
50996 + if (match->next != NULL)
50997 + match->next->prev = match->prev;
50998 + }
50999 + match->prev = NULL;
51000 + match->next = NULL;
51001 + match->inode = newinode;
51002 + match->device = newdevice;
51003 + match->mode &= ~GR_DELETED;
51004 +
51005 + insert_acl_subj_label(match, role);
51006 + }
51007 +
51008 + return;
51009 +}
51010 +
51011 +static void
51012 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
51013 + const ino_t newinode, const dev_t newdevice)
51014 +{
51015 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
51016 + struct inodev_entry *match;
51017 +
51018 + match = inodev_set.i_hash[index];
51019 +
51020 + while (match && (match->nentry->inode != oldinode ||
51021 + match->nentry->device != olddevice || !match->nentry->deleted))
51022 + match = match->next;
51023 +
51024 + if (match && (match->nentry->inode == oldinode)
51025 + && (match->nentry->device == olddevice) &&
51026 + match->nentry->deleted) {
51027 + if (match->prev == NULL) {
51028 + inodev_set.i_hash[index] = match->next;
51029 + if (match->next != NULL)
51030 + match->next->prev = NULL;
51031 + } else {
51032 + match->prev->next = match->next;
51033 + if (match->next != NULL)
51034 + match->next->prev = match->prev;
51035 + }
51036 + match->prev = NULL;
51037 + match->next = NULL;
51038 + match->nentry->inode = newinode;
51039 + match->nentry->device = newdevice;
51040 + match->nentry->deleted = 0;
51041 +
51042 + insert_inodev_entry(match);
51043 + }
51044 +
51045 + return;
51046 +}
51047 +
51048 +static void
51049 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
51050 +{
51051 + struct acl_subject_label *subj;
51052 + struct acl_role_label *role;
51053 + unsigned int x;
51054 +
51055 + FOR_EACH_ROLE_START(role)
51056 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
51057 +
51058 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
51059 + if ((subj->inode == ino) && (subj->device == dev)) {
51060 + subj->inode = ino;
51061 + subj->device = dev;
51062 + }
51063 + FOR_EACH_NESTED_SUBJECT_END(subj)
51064 + FOR_EACH_SUBJECT_START(role, subj, x)
51065 + update_acl_obj_label(matchn->inode, matchn->device,
51066 + ino, dev, subj);
51067 + FOR_EACH_SUBJECT_END(subj,x)
51068 + FOR_EACH_ROLE_END(role)
51069 +
51070 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
51071 +
51072 + return;
51073 +}
51074 +
51075 +static void
51076 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
51077 + const struct vfsmount *mnt)
51078 +{
51079 + ino_t ino = dentry->d_inode->i_ino;
51080 + dev_t dev = __get_dev(dentry);
51081 +
51082 + __do_handle_create(matchn, ino, dev);
51083 +
51084 + return;
51085 +}
51086 +
51087 +void
51088 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
51089 +{
51090 + struct name_entry *matchn;
51091 +
51092 + if (unlikely(!(gr_status & GR_READY)))
51093 + return;
51094 +
51095 + preempt_disable();
51096 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
51097 +
51098 + if (unlikely((unsigned long)matchn)) {
51099 + write_lock(&gr_inode_lock);
51100 + do_handle_create(matchn, dentry, mnt);
51101 + write_unlock(&gr_inode_lock);
51102 + }
51103 + preempt_enable();
51104 +
51105 + return;
51106 +}
51107 +
51108 +void
51109 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
51110 +{
51111 + struct name_entry *matchn;
51112 +
51113 + if (unlikely(!(gr_status & GR_READY)))
51114 + return;
51115 +
51116 + preempt_disable();
51117 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
51118 +
51119 + if (unlikely((unsigned long)matchn)) {
51120 + write_lock(&gr_inode_lock);
51121 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
51122 + write_unlock(&gr_inode_lock);
51123 + }
51124 + preempt_enable();
51125 +
51126 + return;
51127 +}
51128 +
51129 +void
51130 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
51131 + struct dentry *old_dentry,
51132 + struct dentry *new_dentry,
51133 + struct vfsmount *mnt, const __u8 replace)
51134 +{
51135 + struct name_entry *matchn;
51136 + struct inodev_entry *inodev;
51137 + struct inode *inode = new_dentry->d_inode;
51138 + ino_t old_ino = old_dentry->d_inode->i_ino;
51139 + dev_t old_dev = __get_dev(old_dentry);
51140 +
51141 + /* vfs_rename swaps the name and parent link for old_dentry and
51142 + new_dentry
51143 + at this point, old_dentry has the new name, parent link, and inode
51144 + for the renamed file
51145 + if a file is being replaced by a rename, new_dentry has the inode
51146 + and name for the replaced file
51147 + */
51148 +
51149 + if (unlikely(!(gr_status & GR_READY)))
51150 + return;
51151 +
51152 + preempt_disable();
51153 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
51154 +
51155 + /* we wouldn't have to check d_inode if it weren't for
51156 + NFS silly-renaming
51157 + */
51158 +
51159 + write_lock(&gr_inode_lock);
51160 + if (unlikely(replace && inode)) {
51161 + ino_t new_ino = inode->i_ino;
51162 + dev_t new_dev = __get_dev(new_dentry);
51163 +
51164 + inodev = lookup_inodev_entry(new_ino, new_dev);
51165 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
51166 + do_handle_delete(inodev, new_ino, new_dev);
51167 + }
51168 +
51169 + inodev = lookup_inodev_entry(old_ino, old_dev);
51170 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
51171 + do_handle_delete(inodev, old_ino, old_dev);
51172 +
51173 + if (unlikely((unsigned long)matchn))
51174 + do_handle_create(matchn, old_dentry, mnt);
51175 +
51176 + write_unlock(&gr_inode_lock);
51177 + preempt_enable();
51178 +
51179 + return;
51180 +}
51181 +
51182 +static int
51183 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
51184 + unsigned char **sum)
51185 +{
51186 + struct acl_role_label *r;
51187 + struct role_allowed_ip *ipp;
51188 + struct role_transition *trans;
51189 + unsigned int i;
51190 + int found = 0;
51191 + u32 curr_ip = current->signal->curr_ip;
51192 +
51193 + current->signal->saved_ip = curr_ip;
51194 +
51195 + /* check transition table */
51196 +
51197 + for (trans = current->role->transitions; trans; trans = trans->next) {
51198 + if (!strcmp(rolename, trans->rolename)) {
51199 + found = 1;
51200 + break;
51201 + }
51202 + }
51203 +
51204 + if (!found)
51205 + return 0;
51206 +
51207 + /* handle special roles that do not require authentication
51208 + and check ip */
51209 +
51210 + FOR_EACH_ROLE_START(r)
51211 + if (!strcmp(rolename, r->rolename) &&
51212 + (r->roletype & GR_ROLE_SPECIAL)) {
51213 + found = 0;
51214 + if (r->allowed_ips != NULL) {
51215 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
51216 + if ((ntohl(curr_ip) & ipp->netmask) ==
51217 + (ntohl(ipp->addr) & ipp->netmask))
51218 + found = 1;
51219 + }
51220 + } else
51221 + found = 2;
51222 + if (!found)
51223 + return 0;
51224 +
51225 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
51226 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
51227 + *salt = NULL;
51228 + *sum = NULL;
51229 + return 1;
51230 + }
51231 + }
51232 + FOR_EACH_ROLE_END(r)
51233 +
51234 + for (i = 0; i < num_sprole_pws; i++) {
51235 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
51236 + *salt = acl_special_roles[i]->salt;
51237 + *sum = acl_special_roles[i]->sum;
51238 + return 1;
51239 + }
51240 + }
51241 +
51242 + return 0;
51243 +}
51244 +
51245 +static void
51246 +assign_special_role(char *rolename)
51247 +{
51248 + struct acl_object_label *obj;
51249 + struct acl_role_label *r;
51250 + struct acl_role_label *assigned = NULL;
51251 + struct task_struct *tsk;
51252 + struct file *filp;
51253 +
51254 + FOR_EACH_ROLE_START(r)
51255 + if (!strcmp(rolename, r->rolename) &&
51256 + (r->roletype & GR_ROLE_SPECIAL)) {
51257 + assigned = r;
51258 + break;
51259 + }
51260 + FOR_EACH_ROLE_END(r)
51261 +
51262 + if (!assigned)
51263 + return;
51264 +
51265 + read_lock(&tasklist_lock);
51266 + read_lock(&grsec_exec_file_lock);
51267 +
51268 + tsk = current->real_parent;
51269 + if (tsk == NULL)
51270 + goto out_unlock;
51271 +
51272 + filp = tsk->exec_file;
51273 + if (filp == NULL)
51274 + goto out_unlock;
51275 +
51276 + tsk->is_writable = 0;
51277 +
51278 + tsk->acl_sp_role = 1;
51279 + tsk->acl_role_id = ++acl_sp_role_value;
51280 + tsk->role = assigned;
51281 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
51282 +
51283 + /* ignore additional mmap checks for processes that are writable
51284 + by the default ACL */
51285 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
51286 + if (unlikely(obj->mode & GR_WRITE))
51287 + tsk->is_writable = 1;
51288 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
51289 + if (unlikely(obj->mode & GR_WRITE))
51290 + tsk->is_writable = 1;
51291 +
51292 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51293 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
51294 +#endif
51295 +
51296 +out_unlock:
51297 + read_unlock(&grsec_exec_file_lock);
51298 + read_unlock(&tasklist_lock);
51299 + return;
51300 +}
51301 +
51302 +int gr_check_secure_terminal(struct task_struct *task)
51303 +{
51304 + struct task_struct *p, *p2, *p3;
51305 + struct files_struct *files;
51306 + struct fdtable *fdt;
51307 + struct file *our_file = NULL, *file;
51308 + int i;
51309 +
51310 + if (task->signal->tty == NULL)
51311 + return 1;
51312 +
51313 + files = get_files_struct(task);
51314 + if (files != NULL) {
51315 + rcu_read_lock();
51316 + fdt = files_fdtable(files);
51317 + for (i=0; i < fdt->max_fds; i++) {
51318 + file = fcheck_files(files, i);
51319 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
51320 + get_file(file);
51321 + our_file = file;
51322 + }
51323 + }
51324 + rcu_read_unlock();
51325 + put_files_struct(files);
51326 + }
51327 +
51328 + if (our_file == NULL)
51329 + return 1;
51330 +
51331 + read_lock(&tasklist_lock);
51332 + do_each_thread(p2, p) {
51333 + files = get_files_struct(p);
51334 + if (files == NULL ||
51335 + (p->signal && p->signal->tty == task->signal->tty)) {
51336 + if (files != NULL)
51337 + put_files_struct(files);
51338 + continue;
51339 + }
51340 + rcu_read_lock();
51341 + fdt = files_fdtable(files);
51342 + for (i=0; i < fdt->max_fds; i++) {
51343 + file = fcheck_files(files, i);
51344 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
51345 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
51346 + p3 = task;
51347 + while (p3->pid > 0) {
51348 + if (p3 == p)
51349 + break;
51350 + p3 = p3->real_parent;
51351 + }
51352 + if (p3 == p)
51353 + break;
51354 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
51355 + gr_handle_alertkill(p);
51356 + rcu_read_unlock();
51357 + put_files_struct(files);
51358 + read_unlock(&tasklist_lock);
51359 + fput(our_file);
51360 + return 0;
51361 + }
51362 + }
51363 + rcu_read_unlock();
51364 + put_files_struct(files);
51365 + } while_each_thread(p2, p);
51366 + read_unlock(&tasklist_lock);
51367 +
51368 + fput(our_file);
51369 + return 1;
51370 +}
51371 +
51372 +ssize_t
51373 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
51374 +{
51375 + struct gr_arg_wrapper uwrap;
51376 + unsigned char *sprole_salt = NULL;
51377 + unsigned char *sprole_sum = NULL;
51378 + int error = sizeof (struct gr_arg_wrapper);
51379 + int error2 = 0;
51380 +
51381 + mutex_lock(&gr_dev_mutex);
51382 +
51383 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
51384 + error = -EPERM;
51385 + goto out;
51386 + }
51387 +
51388 + if (count != sizeof (struct gr_arg_wrapper)) {
51389 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
51390 + error = -EINVAL;
51391 + goto out;
51392 + }
51393 +
51394 +
51395 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
51396 + gr_auth_expires = 0;
51397 + gr_auth_attempts = 0;
51398 + }
51399 +
51400 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
51401 + error = -EFAULT;
51402 + goto out;
51403 + }
51404 +
51405 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
51406 + error = -EINVAL;
51407 + goto out;
51408 + }
51409 +
51410 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
51411 + error = -EFAULT;
51412 + goto out;
51413 + }
51414 +
51415 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
51416 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
51417 + time_after(gr_auth_expires, get_seconds())) {
51418 + error = -EBUSY;
51419 + goto out;
51420 + }
51421 +
51422 + /* if non-root trying to do anything other than use a special role,
51423 + do not attempt authentication, do not count towards authentication
51424 + locking
51425 + */
51426 +
51427 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
51428 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
51429 + current_uid()) {
51430 + error = -EPERM;
51431 + goto out;
51432 + }
51433 +
51434 + /* ensure pw and special role name are null terminated */
51435 +
51436 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
51437 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
51438 +
51439 + /* Okay.
51440 + * We have our enough of the argument structure..(we have yet
51441 + * to copy_from_user the tables themselves) . Copy the tables
51442 + * only if we need them, i.e. for loading operations. */
51443 +
51444 + switch (gr_usermode->mode) {
51445 + case GR_STATUS:
51446 + if (gr_status & GR_READY) {
51447 + error = 1;
51448 + if (!gr_check_secure_terminal(current))
51449 + error = 3;
51450 + } else
51451 + error = 2;
51452 + goto out;
51453 + case GR_SHUTDOWN:
51454 + if ((gr_status & GR_READY)
51455 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51456 + pax_open_kernel();
51457 + gr_status &= ~GR_READY;
51458 + pax_close_kernel();
51459 +
51460 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
51461 + free_variables();
51462 + memset(gr_usermode, 0, sizeof (struct gr_arg));
51463 + memset(gr_system_salt, 0, GR_SALT_LEN);
51464 + memset(gr_system_sum, 0, GR_SHA_LEN);
51465 + } else if (gr_status & GR_READY) {
51466 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
51467 + error = -EPERM;
51468 + } else {
51469 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
51470 + error = -EAGAIN;
51471 + }
51472 + break;
51473 + case GR_ENABLE:
51474 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
51475 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
51476 + else {
51477 + if (gr_status & GR_READY)
51478 + error = -EAGAIN;
51479 + else
51480 + error = error2;
51481 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
51482 + }
51483 + break;
51484 + case GR_RELOAD:
51485 + if (!(gr_status & GR_READY)) {
51486 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
51487 + error = -EAGAIN;
51488 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51489 + preempt_disable();
51490 +
51491 + pax_open_kernel();
51492 + gr_status &= ~GR_READY;
51493 + pax_close_kernel();
51494 +
51495 + free_variables();
51496 + if (!(error2 = gracl_init(gr_usermode))) {
51497 + preempt_enable();
51498 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
51499 + } else {
51500 + preempt_enable();
51501 + error = error2;
51502 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
51503 + }
51504 + } else {
51505 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
51506 + error = -EPERM;
51507 + }
51508 + break;
51509 + case GR_SEGVMOD:
51510 + if (unlikely(!(gr_status & GR_READY))) {
51511 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
51512 + error = -EAGAIN;
51513 + break;
51514 + }
51515 +
51516 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51517 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
51518 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
51519 + struct acl_subject_label *segvacl;
51520 + segvacl =
51521 + lookup_acl_subj_label(gr_usermode->segv_inode,
51522 + gr_usermode->segv_device,
51523 + current->role);
51524 + if (segvacl) {
51525 + segvacl->crashes = 0;
51526 + segvacl->expires = 0;
51527 + }
51528 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
51529 + gr_remove_uid(gr_usermode->segv_uid);
51530 + }
51531 + } else {
51532 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
51533 + error = -EPERM;
51534 + }
51535 + break;
51536 + case GR_SPROLE:
51537 + case GR_SPROLEPAM:
51538 + if (unlikely(!(gr_status & GR_READY))) {
51539 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
51540 + error = -EAGAIN;
51541 + break;
51542 + }
51543 +
51544 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
51545 + current->role->expires = 0;
51546 + current->role->auth_attempts = 0;
51547 + }
51548 +
51549 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
51550 + time_after(current->role->expires, get_seconds())) {
51551 + error = -EBUSY;
51552 + goto out;
51553 + }
51554 +
51555 + if (lookup_special_role_auth
51556 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
51557 + && ((!sprole_salt && !sprole_sum)
51558 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
51559 + char *p = "";
51560 + assign_special_role(gr_usermode->sp_role);
51561 + read_lock(&tasklist_lock);
51562 + if (current->real_parent)
51563 + p = current->real_parent->role->rolename;
51564 + read_unlock(&tasklist_lock);
51565 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
51566 + p, acl_sp_role_value);
51567 + } else {
51568 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
51569 + error = -EPERM;
51570 + if(!(current->role->auth_attempts++))
51571 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
51572 +
51573 + goto out;
51574 + }
51575 + break;
51576 + case GR_UNSPROLE:
51577 + if (unlikely(!(gr_status & GR_READY))) {
51578 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
51579 + error = -EAGAIN;
51580 + break;
51581 + }
51582 +
51583 + if (current->role->roletype & GR_ROLE_SPECIAL) {
51584 + char *p = "";
51585 + int i = 0;
51586 +
51587 + read_lock(&tasklist_lock);
51588 + if (current->real_parent) {
51589 + p = current->real_parent->role->rolename;
51590 + i = current->real_parent->acl_role_id;
51591 + }
51592 + read_unlock(&tasklist_lock);
51593 +
51594 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
51595 + gr_set_acls(1);
51596 + } else {
51597 + error = -EPERM;
51598 + goto out;
51599 + }
51600 + break;
51601 + default:
51602 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
51603 + error = -EINVAL;
51604 + break;
51605 + }
51606 +
51607 + if (error != -EPERM)
51608 + goto out;
51609 +
51610 + if(!(gr_auth_attempts++))
51611 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
51612 +
51613 + out:
51614 + mutex_unlock(&gr_dev_mutex);
51615 + return error;
51616 +}
51617 +
51618 +/* must be called with
51619 + rcu_read_lock();
51620 + read_lock(&tasklist_lock);
51621 + read_lock(&grsec_exec_file_lock);
51622 +*/
51623 +int gr_apply_subject_to_task(struct task_struct *task)
51624 +{
51625 + struct acl_object_label *obj;
51626 + char *tmpname;
51627 + struct acl_subject_label *tmpsubj;
51628 + struct file *filp;
51629 + struct name_entry *nmatch;
51630 +
51631 + filp = task->exec_file;
51632 + if (filp == NULL)
51633 + return 0;
51634 +
51635 + /* the following is to apply the correct subject
51636 + on binaries running when the RBAC system
51637 + is enabled, when the binaries have been
51638 + replaced or deleted since their execution
51639 + -----
51640 + when the RBAC system starts, the inode/dev
51641 + from exec_file will be one the RBAC system
51642 + is unaware of. It only knows the inode/dev
51643 + of the present file on disk, or the absence
51644 + of it.
51645 + */
51646 + preempt_disable();
51647 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
51648 +
51649 + nmatch = lookup_name_entry(tmpname);
51650 + preempt_enable();
51651 + tmpsubj = NULL;
51652 + if (nmatch) {
51653 + if (nmatch->deleted)
51654 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
51655 + else
51656 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
51657 + if (tmpsubj != NULL)
51658 + task->acl = tmpsubj;
51659 + }
51660 + if (tmpsubj == NULL)
51661 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
51662 + task->role);
51663 + if (task->acl) {
51664 + task->is_writable = 0;
51665 + /* ignore additional mmap checks for processes that are writable
51666 + by the default ACL */
51667 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
51668 + if (unlikely(obj->mode & GR_WRITE))
51669 + task->is_writable = 1;
51670 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
51671 + if (unlikely(obj->mode & GR_WRITE))
51672 + task->is_writable = 1;
51673 +
51674 + gr_set_proc_res(task);
51675 +
51676 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51677 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
51678 +#endif
51679 + } else {
51680 + return 1;
51681 + }
51682 +
51683 + return 0;
51684 +}
51685 +
51686 +int
51687 +gr_set_acls(const int type)
51688 +{
51689 + struct task_struct *task, *task2;
51690 + struct acl_role_label *role = current->role;
51691 + __u16 acl_role_id = current->acl_role_id;
51692 + const struct cred *cred;
51693 + int ret;
51694 +
51695 + rcu_read_lock();
51696 + read_lock(&tasklist_lock);
51697 + read_lock(&grsec_exec_file_lock);
51698 + do_each_thread(task2, task) {
51699 + /* check to see if we're called from the exit handler,
51700 + if so, only replace ACLs that have inherited the admin
51701 + ACL */
51702 +
51703 + if (type && (task->role != role ||
51704 + task->acl_role_id != acl_role_id))
51705 + continue;
51706 +
51707 + task->acl_role_id = 0;
51708 + task->acl_sp_role = 0;
51709 +
51710 + if (task->exec_file) {
51711 + cred = __task_cred(task);
51712 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
51713 + ret = gr_apply_subject_to_task(task);
51714 + if (ret) {
51715 + read_unlock(&grsec_exec_file_lock);
51716 + read_unlock(&tasklist_lock);
51717 + rcu_read_unlock();
51718 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
51719 + return ret;
51720 + }
51721 + } else {
51722 + // it's a kernel process
51723 + task->role = kernel_role;
51724 + task->acl = kernel_role->root_label;
51725 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
51726 + task->acl->mode &= ~GR_PROCFIND;
51727 +#endif
51728 + }
51729 + } while_each_thread(task2, task);
51730 + read_unlock(&grsec_exec_file_lock);
51731 + read_unlock(&tasklist_lock);
51732 + rcu_read_unlock();
51733 +
51734 + return 0;
51735 +}
51736 +
51737 +void
51738 +gr_learn_resource(const struct task_struct *task,
51739 + const int res, const unsigned long wanted, const int gt)
51740 +{
51741 + struct acl_subject_label *acl;
51742 + const struct cred *cred;
51743 +
51744 + if (unlikely((gr_status & GR_READY) &&
51745 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
51746 + goto skip_reslog;
51747 +
51748 +#ifdef CONFIG_GRKERNSEC_RESLOG
51749 + gr_log_resource(task, res, wanted, gt);
51750 +#endif
51751 + skip_reslog:
51752 +
51753 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
51754 + return;
51755 +
51756 + acl = task->acl;
51757 +
51758 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
51759 + !(acl->resmask & (1 << (unsigned short) res))))
51760 + return;
51761 +
51762 + if (wanted >= acl->res[res].rlim_cur) {
51763 + unsigned long res_add;
51764 +
51765 + res_add = wanted;
51766 + switch (res) {
51767 + case RLIMIT_CPU:
51768 + res_add += GR_RLIM_CPU_BUMP;
51769 + break;
51770 + case RLIMIT_FSIZE:
51771 + res_add += GR_RLIM_FSIZE_BUMP;
51772 + break;
51773 + case RLIMIT_DATA:
51774 + res_add += GR_RLIM_DATA_BUMP;
51775 + break;
51776 + case RLIMIT_STACK:
51777 + res_add += GR_RLIM_STACK_BUMP;
51778 + break;
51779 + case RLIMIT_CORE:
51780 + res_add += GR_RLIM_CORE_BUMP;
51781 + break;
51782 + case RLIMIT_RSS:
51783 + res_add += GR_RLIM_RSS_BUMP;
51784 + break;
51785 + case RLIMIT_NPROC:
51786 + res_add += GR_RLIM_NPROC_BUMP;
51787 + break;
51788 + case RLIMIT_NOFILE:
51789 + res_add += GR_RLIM_NOFILE_BUMP;
51790 + break;
51791 + case RLIMIT_MEMLOCK:
51792 + res_add += GR_RLIM_MEMLOCK_BUMP;
51793 + break;
51794 + case RLIMIT_AS:
51795 + res_add += GR_RLIM_AS_BUMP;
51796 + break;
51797 + case RLIMIT_LOCKS:
51798 + res_add += GR_RLIM_LOCKS_BUMP;
51799 + break;
51800 + case RLIMIT_SIGPENDING:
51801 + res_add += GR_RLIM_SIGPENDING_BUMP;
51802 + break;
51803 + case RLIMIT_MSGQUEUE:
51804 + res_add += GR_RLIM_MSGQUEUE_BUMP;
51805 + break;
51806 + case RLIMIT_NICE:
51807 + res_add += GR_RLIM_NICE_BUMP;
51808 + break;
51809 + case RLIMIT_RTPRIO:
51810 + res_add += GR_RLIM_RTPRIO_BUMP;
51811 + break;
51812 + case RLIMIT_RTTIME:
51813 + res_add += GR_RLIM_RTTIME_BUMP;
51814 + break;
51815 + }
51816 +
51817 + acl->res[res].rlim_cur = res_add;
51818 +
51819 + if (wanted > acl->res[res].rlim_max)
51820 + acl->res[res].rlim_max = res_add;
51821 +
51822 + /* only log the subject filename, since resource logging is supported for
51823 + single-subject learning only */
51824 + rcu_read_lock();
51825 + cred = __task_cred(task);
51826 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
51827 + task->role->roletype, cred->uid, cred->gid, acl->filename,
51828 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
51829 + "", (unsigned long) res, &task->signal->saved_ip);
51830 + rcu_read_unlock();
51831 + }
51832 +
51833 + return;
51834 +}
51835 +
51836 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
51837 +void
51838 +pax_set_initial_flags(struct linux_binprm *bprm)
51839 +{
51840 + struct task_struct *task = current;
51841 + struct acl_subject_label *proc;
51842 + unsigned long flags;
51843 +
51844 + if (unlikely(!(gr_status & GR_READY)))
51845 + return;
51846 +
51847 + flags = pax_get_flags(task);
51848 +
51849 + proc = task->acl;
51850 +
51851 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
51852 + flags &= ~MF_PAX_PAGEEXEC;
51853 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
51854 + flags &= ~MF_PAX_SEGMEXEC;
51855 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
51856 + flags &= ~MF_PAX_RANDMMAP;
51857 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
51858 + flags &= ~MF_PAX_EMUTRAMP;
51859 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
51860 + flags &= ~MF_PAX_MPROTECT;
51861 +
51862 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
51863 + flags |= MF_PAX_PAGEEXEC;
51864 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
51865 + flags |= MF_PAX_SEGMEXEC;
51866 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
51867 + flags |= MF_PAX_RANDMMAP;
51868 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
51869 + flags |= MF_PAX_EMUTRAMP;
51870 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
51871 + flags |= MF_PAX_MPROTECT;
51872 +
51873 + pax_set_flags(task, flags);
51874 +
51875 + return;
51876 +}
51877 +#endif
51878 +
51879 +#ifdef CONFIG_SYSCTL
51880 +/* Eric Biederman likes breaking userland ABI and every inode-based security
51881 + system to save 35kb of memory */
51882 +
51883 +/* we modify the passed in filename, but adjust it back before returning */
51884 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
51885 +{
51886 + struct name_entry *nmatch;
51887 + char *p, *lastp = NULL;
51888 + struct acl_object_label *obj = NULL, *tmp;
51889 + struct acl_subject_label *tmpsubj;
51890 + char c = '\0';
51891 +
51892 + read_lock(&gr_inode_lock);
51893 +
51894 + p = name + len - 1;
51895 + do {
51896 + nmatch = lookup_name_entry(name);
51897 + if (lastp != NULL)
51898 + *lastp = c;
51899 +
51900 + if (nmatch == NULL)
51901 + goto next_component;
51902 + tmpsubj = current->acl;
51903 + do {
51904 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
51905 + if (obj != NULL) {
51906 + tmp = obj->globbed;
51907 + while (tmp) {
51908 + if (!glob_match(tmp->filename, name)) {
51909 + obj = tmp;
51910 + goto found_obj;
51911 + }
51912 + tmp = tmp->next;
51913 + }
51914 + goto found_obj;
51915 + }
51916 + } while ((tmpsubj = tmpsubj->parent_subject));
51917 +next_component:
51918 + /* end case */
51919 + if (p == name)
51920 + break;
51921 +
51922 + while (*p != '/')
51923 + p--;
51924 + if (p == name)
51925 + lastp = p + 1;
51926 + else {
51927 + lastp = p;
51928 + p--;
51929 + }
51930 + c = *lastp;
51931 + *lastp = '\0';
51932 + } while (1);
51933 +found_obj:
51934 + read_unlock(&gr_inode_lock);
51935 + /* obj returned will always be non-null */
51936 + return obj;
51937 +}
51938 +
51939 +/* returns 0 when allowing, non-zero on error
51940 + op of 0 is used for readdir, so we don't log the names of hidden files
51941 +*/
51942 +__u32
51943 +gr_handle_sysctl(const struct ctl_table *table, const int op)
51944 +{
51945 + struct ctl_table *tmp;
51946 + const char *proc_sys = "/proc/sys";
51947 + char *path;
51948 + struct acl_object_label *obj;
51949 + unsigned short len = 0, pos = 0, depth = 0, i;
51950 + __u32 err = 0;
51951 + __u32 mode = 0;
51952 +
51953 + if (unlikely(!(gr_status & GR_READY)))
51954 + return 0;
51955 +
51956 + /* for now, ignore operations on non-sysctl entries if it's not a
51957 + readdir*/
51958 + if (table->child != NULL && op != 0)
51959 + return 0;
51960 +
51961 + mode |= GR_FIND;
51962 + /* it's only a read if it's an entry, read on dirs is for readdir */
51963 + if (op & MAY_READ)
51964 + mode |= GR_READ;
51965 + if (op & MAY_WRITE)
51966 + mode |= GR_WRITE;
51967 +
51968 + preempt_disable();
51969 +
51970 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51971 +
51972 + /* it's only a read/write if it's an actual entry, not a dir
51973 + (which are opened for readdir)
51974 + */
51975 +
51976 + /* convert the requested sysctl entry into a pathname */
51977 +
51978 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
51979 + len += strlen(tmp->procname);
51980 + len++;
51981 + depth++;
51982 + }
51983 +
51984 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
51985 + /* deny */
51986 + goto out;
51987 + }
51988 +
51989 + memset(path, 0, PAGE_SIZE);
51990 +
51991 + memcpy(path, proc_sys, strlen(proc_sys));
51992 +
51993 + pos += strlen(proc_sys);
51994 +
51995 + for (; depth > 0; depth--) {
51996 + path[pos] = '/';
51997 + pos++;
51998 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
51999 + if (depth == i) {
52000 + memcpy(path + pos, tmp->procname,
52001 + strlen(tmp->procname));
52002 + pos += strlen(tmp->procname);
52003 + }
52004 + i++;
52005 + }
52006 + }
52007 +
52008 + obj = gr_lookup_by_name(path, pos);
52009 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
52010 +
52011 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
52012 + ((err & mode) != mode))) {
52013 + __u32 new_mode = mode;
52014 +
52015 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52016 +
52017 + err = 0;
52018 + gr_log_learn_sysctl(path, new_mode);
52019 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
52020 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
52021 + err = -ENOENT;
52022 + } else if (!(err & GR_FIND)) {
52023 + err = -ENOENT;
52024 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
52025 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
52026 + path, (mode & GR_READ) ? " reading" : "",
52027 + (mode & GR_WRITE) ? " writing" : "");
52028 + err = -EACCES;
52029 + } else if ((err & mode) != mode) {
52030 + err = -EACCES;
52031 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
52032 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
52033 + path, (mode & GR_READ) ? " reading" : "",
52034 + (mode & GR_WRITE) ? " writing" : "");
52035 + err = 0;
52036 + } else
52037 + err = 0;
52038 +
52039 + out:
52040 + preempt_enable();
52041 +
52042 + return err;
52043 +}
52044 +#endif
52045 +
52046 +int
52047 +gr_handle_proc_ptrace(struct task_struct *task)
52048 +{
52049 + struct file *filp;
52050 + struct task_struct *tmp = task;
52051 + struct task_struct *curtemp = current;
52052 + __u32 retmode;
52053 +
52054 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
52055 + if (unlikely(!(gr_status & GR_READY)))
52056 + return 0;
52057 +#endif
52058 +
52059 + read_lock(&tasklist_lock);
52060 + read_lock(&grsec_exec_file_lock);
52061 + filp = task->exec_file;
52062 +
52063 + while (tmp->pid > 0) {
52064 + if (tmp == curtemp)
52065 + break;
52066 + tmp = tmp->real_parent;
52067 + }
52068 +
52069 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
52070 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
52071 + read_unlock(&grsec_exec_file_lock);
52072 + read_unlock(&tasklist_lock);
52073 + return 1;
52074 + }
52075 +
52076 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52077 + if (!(gr_status & GR_READY)) {
52078 + read_unlock(&grsec_exec_file_lock);
52079 + read_unlock(&tasklist_lock);
52080 + return 0;
52081 + }
52082 +#endif
52083 +
52084 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
52085 + read_unlock(&grsec_exec_file_lock);
52086 + read_unlock(&tasklist_lock);
52087 +
52088 + if (retmode & GR_NOPTRACE)
52089 + return 1;
52090 +
52091 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
52092 + && (current->acl != task->acl || (current->acl != current->role->root_label
52093 + && current->pid != task->pid)))
52094 + return 1;
52095 +
52096 + return 0;
52097 +}
52098 +
52099 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
52100 +{
52101 + if (unlikely(!(gr_status & GR_READY)))
52102 + return;
52103 +
52104 + if (!(current->role->roletype & GR_ROLE_GOD))
52105 + return;
52106 +
52107 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
52108 + p->role->rolename, gr_task_roletype_to_char(p),
52109 + p->acl->filename);
52110 +}
52111 +
52112 +int
52113 +gr_handle_ptrace(struct task_struct *task, const long request)
52114 +{
52115 + struct task_struct *tmp = task;
52116 + struct task_struct *curtemp = current;
52117 + __u32 retmode;
52118 +
52119 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
52120 + if (unlikely(!(gr_status & GR_READY)))
52121 + return 0;
52122 +#endif
52123 +
52124 + read_lock(&tasklist_lock);
52125 + while (tmp->pid > 0) {
52126 + if (tmp == curtemp)
52127 + break;
52128 + tmp = tmp->real_parent;
52129 + }
52130 +
52131 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
52132 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
52133 + read_unlock(&tasklist_lock);
52134 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52135 + return 1;
52136 + }
52137 + read_unlock(&tasklist_lock);
52138 +
52139 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52140 + if (!(gr_status & GR_READY))
52141 + return 0;
52142 +#endif
52143 +
52144 + read_lock(&grsec_exec_file_lock);
52145 + if (unlikely(!task->exec_file)) {
52146 + read_unlock(&grsec_exec_file_lock);
52147 + return 0;
52148 + }
52149 +
52150 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
52151 + read_unlock(&grsec_exec_file_lock);
52152 +
52153 + if (retmode & GR_NOPTRACE) {
52154 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52155 + return 1;
52156 + }
52157 +
52158 + if (retmode & GR_PTRACERD) {
52159 + switch (request) {
52160 + case PTRACE_SEIZE:
52161 + case PTRACE_POKETEXT:
52162 + case PTRACE_POKEDATA:
52163 + case PTRACE_POKEUSR:
52164 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
52165 + case PTRACE_SETREGS:
52166 + case PTRACE_SETFPREGS:
52167 +#endif
52168 +#ifdef CONFIG_X86
52169 + case PTRACE_SETFPXREGS:
52170 +#endif
52171 +#ifdef CONFIG_ALTIVEC
52172 + case PTRACE_SETVRREGS:
52173 +#endif
52174 + return 1;
52175 + default:
52176 + return 0;
52177 + }
52178 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
52179 + !(current->role->roletype & GR_ROLE_GOD) &&
52180 + (current->acl != task->acl)) {
52181 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52182 + return 1;
52183 + }
52184 +
52185 + return 0;
52186 +}
52187 +
52188 +static int is_writable_mmap(const struct file *filp)
52189 +{
52190 + struct task_struct *task = current;
52191 + struct acl_object_label *obj, *obj2;
52192 +
52193 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
52194 + !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode) && (filp->f_path.mnt != shm_mnt || (filp->f_path.dentry->d_inode->i_nlink > 0))) {
52195 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52196 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
52197 + task->role->root_label);
52198 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
52199 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
52200 + return 1;
52201 + }
52202 + }
52203 + return 0;
52204 +}
52205 +
52206 +int
52207 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
52208 +{
52209 + __u32 mode;
52210 +
52211 + if (unlikely(!file || !(prot & PROT_EXEC)))
52212 + return 1;
52213 +
52214 + if (is_writable_mmap(file))
52215 + return 0;
52216 +
52217 + mode =
52218 + gr_search_file(file->f_path.dentry,
52219 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
52220 + file->f_path.mnt);
52221 +
52222 + if (!gr_tpe_allow(file))
52223 + return 0;
52224 +
52225 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
52226 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52227 + return 0;
52228 + } else if (unlikely(!(mode & GR_EXEC))) {
52229 + return 0;
52230 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
52231 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52232 + return 1;
52233 + }
52234 +
52235 + return 1;
52236 +}
52237 +
52238 +int
52239 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
52240 +{
52241 + __u32 mode;
52242 +
52243 + if (unlikely(!file || !(prot & PROT_EXEC)))
52244 + return 1;
52245 +
52246 + if (is_writable_mmap(file))
52247 + return 0;
52248 +
52249 + mode =
52250 + gr_search_file(file->f_path.dentry,
52251 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
52252 + file->f_path.mnt);
52253 +
52254 + if (!gr_tpe_allow(file))
52255 + return 0;
52256 +
52257 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
52258 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52259 + return 0;
52260 + } else if (unlikely(!(mode & GR_EXEC))) {
52261 + return 0;
52262 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
52263 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52264 + return 1;
52265 + }
52266 +
52267 + return 1;
52268 +}
52269 +
52270 +void
52271 +gr_acl_handle_psacct(struct task_struct *task, const long code)
52272 +{
52273 + unsigned long runtime;
52274 + unsigned long cputime;
52275 + unsigned int wday, cday;
52276 + __u8 whr, chr;
52277 + __u8 wmin, cmin;
52278 + __u8 wsec, csec;
52279 + struct timespec timeval;
52280 +
52281 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
52282 + !(task->acl->mode & GR_PROCACCT)))
52283 + return;
52284 +
52285 + do_posix_clock_monotonic_gettime(&timeval);
52286 + runtime = timeval.tv_sec - task->start_time.tv_sec;
52287 + wday = runtime / (3600 * 24);
52288 + runtime -= wday * (3600 * 24);
52289 + whr = runtime / 3600;
52290 + runtime -= whr * 3600;
52291 + wmin = runtime / 60;
52292 + runtime -= wmin * 60;
52293 + wsec = runtime;
52294 +
52295 + cputime = (task->utime + task->stime) / HZ;
52296 + cday = cputime / (3600 * 24);
52297 + cputime -= cday * (3600 * 24);
52298 + chr = cputime / 3600;
52299 + cputime -= chr * 3600;
52300 + cmin = cputime / 60;
52301 + cputime -= cmin * 60;
52302 + csec = cputime;
52303 +
52304 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
52305 +
52306 + return;
52307 +}
52308 +
52309 +void gr_set_kernel_label(struct task_struct *task)
52310 +{
52311 + if (gr_status & GR_READY) {
52312 + task->role = kernel_role;
52313 + task->acl = kernel_role->root_label;
52314 + }
52315 + return;
52316 +}
52317 +
52318 +#ifdef CONFIG_TASKSTATS
52319 +int gr_is_taskstats_denied(int pid)
52320 +{
52321 + struct task_struct *task;
52322 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52323 + const struct cred *cred;
52324 +#endif
52325 + int ret = 0;
52326 +
52327 + /* restrict taskstats viewing to un-chrooted root users
52328 + who have the 'view' subject flag if the RBAC system is enabled
52329 + */
52330 +
52331 + rcu_read_lock();
52332 + read_lock(&tasklist_lock);
52333 + task = find_task_by_vpid(pid);
52334 + if (task) {
52335 +#ifdef CONFIG_GRKERNSEC_CHROOT
52336 + if (proc_is_chrooted(task))
52337 + ret = -EACCES;
52338 +#endif
52339 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52340 + cred = __task_cred(task);
52341 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52342 + if (cred->uid != 0)
52343 + ret = -EACCES;
52344 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52345 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
52346 + ret = -EACCES;
52347 +#endif
52348 +#endif
52349 + if (gr_status & GR_READY) {
52350 + if (!(task->acl->mode & GR_VIEW))
52351 + ret = -EACCES;
52352 + }
52353 + } else
52354 + ret = -ENOENT;
52355 +
52356 + read_unlock(&tasklist_lock);
52357 + rcu_read_unlock();
52358 +
52359 + return ret;
52360 +}
52361 +#endif
52362 +
52363 +/* AUXV entries are filled via a descendant of search_binary_handler
52364 + after we've already applied the subject for the target
52365 +*/
52366 +int gr_acl_enable_at_secure(void)
52367 +{
52368 + if (unlikely(!(gr_status & GR_READY)))
52369 + return 0;
52370 +
52371 + if (current->acl->mode & GR_ATSECURE)
52372 + return 1;
52373 +
52374 + return 0;
52375 +}
52376 +
52377 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
52378 +{
52379 + struct task_struct *task = current;
52380 + struct dentry *dentry = file->f_path.dentry;
52381 + struct vfsmount *mnt = file->f_path.mnt;
52382 + struct acl_object_label *obj, *tmp;
52383 + struct acl_subject_label *subj;
52384 + unsigned int bufsize;
52385 + int is_not_root;
52386 + char *path;
52387 + dev_t dev = __get_dev(dentry);
52388 +
52389 + if (unlikely(!(gr_status & GR_READY)))
52390 + return 1;
52391 +
52392 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52393 + return 1;
52394 +
52395 + /* ignore Eric Biederman */
52396 + if (IS_PRIVATE(dentry->d_inode))
52397 + return 1;
52398 +
52399 + subj = task->acl;
52400 + do {
52401 + obj = lookup_acl_obj_label(ino, dev, subj);
52402 + if (obj != NULL)
52403 + return (obj->mode & GR_FIND) ? 1 : 0;
52404 + } while ((subj = subj->parent_subject));
52405 +
52406 + /* this is purely an optimization since we're looking for an object
52407 + for the directory we're doing a readdir on
52408 + if it's possible for any globbed object to match the entry we're
52409 + filling into the directory, then the object we find here will be
52410 + an anchor point with attached globbed objects
52411 + */
52412 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
52413 + if (obj->globbed == NULL)
52414 + return (obj->mode & GR_FIND) ? 1 : 0;
52415 +
52416 + is_not_root = ((obj->filename[0] == '/') &&
52417 + (obj->filename[1] == '\0')) ? 0 : 1;
52418 + bufsize = PAGE_SIZE - namelen - is_not_root;
52419 +
52420 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
52421 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
52422 + return 1;
52423 +
52424 + preempt_disable();
52425 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52426 + bufsize);
52427 +
52428 + bufsize = strlen(path);
52429 +
52430 + /* if base is "/", don't append an additional slash */
52431 + if (is_not_root)
52432 + *(path + bufsize) = '/';
52433 + memcpy(path + bufsize + is_not_root, name, namelen);
52434 + *(path + bufsize + namelen + is_not_root) = '\0';
52435 +
52436 + tmp = obj->globbed;
52437 + while (tmp) {
52438 + if (!glob_match(tmp->filename, path)) {
52439 + preempt_enable();
52440 + return (tmp->mode & GR_FIND) ? 1 : 0;
52441 + }
52442 + tmp = tmp->next;
52443 + }
52444 + preempt_enable();
52445 + return (obj->mode & GR_FIND) ? 1 : 0;
52446 +}
52447 +
52448 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
52449 +EXPORT_SYMBOL(gr_acl_is_enabled);
52450 +#endif
52451 +EXPORT_SYMBOL(gr_learn_resource);
52452 +EXPORT_SYMBOL(gr_set_kernel_label);
52453 +#ifdef CONFIG_SECURITY
52454 +EXPORT_SYMBOL(gr_check_user_change);
52455 +EXPORT_SYMBOL(gr_check_group_change);
52456 +#endif
52457 +
52458 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
52459 new file mode 100644
52460 index 0000000..34fefda
52461 --- /dev/null
52462 +++ b/grsecurity/gracl_alloc.c
52463 @@ -0,0 +1,105 @@
52464 +#include <linux/kernel.h>
52465 +#include <linux/mm.h>
52466 +#include <linux/slab.h>
52467 +#include <linux/vmalloc.h>
52468 +#include <linux/gracl.h>
52469 +#include <linux/grsecurity.h>
52470 +
52471 +static unsigned long alloc_stack_next = 1;
52472 +static unsigned long alloc_stack_size = 1;
52473 +static void **alloc_stack;
52474 +
52475 +static __inline__ int
52476 +alloc_pop(void)
52477 +{
52478 + if (alloc_stack_next == 1)
52479 + return 0;
52480 +
52481 + kfree(alloc_stack[alloc_stack_next - 2]);
52482 +
52483 + alloc_stack_next--;
52484 +
52485 + return 1;
52486 +}
52487 +
52488 +static __inline__ int
52489 +alloc_push(void *buf)
52490 +{
52491 + if (alloc_stack_next >= alloc_stack_size)
52492 + return 1;
52493 +
52494 + alloc_stack[alloc_stack_next - 1] = buf;
52495 +
52496 + alloc_stack_next++;
52497 +
52498 + return 0;
52499 +}
52500 +
52501 +void *
52502 +acl_alloc(unsigned long len)
52503 +{
52504 + void *ret = NULL;
52505 +
52506 + if (!len || len > PAGE_SIZE)
52507 + goto out;
52508 +
52509 + ret = kmalloc(len, GFP_KERNEL);
52510 +
52511 + if (ret) {
52512 + if (alloc_push(ret)) {
52513 + kfree(ret);
52514 + ret = NULL;
52515 + }
52516 + }
52517 +
52518 +out:
52519 + return ret;
52520 +}
52521 +
52522 +void *
52523 +acl_alloc_num(unsigned long num, unsigned long len)
52524 +{
52525 + if (!len || (num > (PAGE_SIZE / len)))
52526 + return NULL;
52527 +
52528 + return acl_alloc(num * len);
52529 +}
52530 +
52531 +void
52532 +acl_free_all(void)
52533 +{
52534 + if (gr_acl_is_enabled() || !alloc_stack)
52535 + return;
52536 +
52537 + while (alloc_pop()) ;
52538 +
52539 + if (alloc_stack) {
52540 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
52541 + kfree(alloc_stack);
52542 + else
52543 + vfree(alloc_stack);
52544 + }
52545 +
52546 + alloc_stack = NULL;
52547 + alloc_stack_size = 1;
52548 + alloc_stack_next = 1;
52549 +
52550 + return;
52551 +}
52552 +
52553 +int
52554 +acl_alloc_stack_init(unsigned long size)
52555 +{
52556 + if ((size * sizeof (void *)) <= PAGE_SIZE)
52557 + alloc_stack =
52558 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
52559 + else
52560 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
52561 +
52562 + alloc_stack_size = size;
52563 +
52564 + if (!alloc_stack)
52565 + return 0;
52566 + else
52567 + return 1;
52568 +}
52569 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
52570 new file mode 100644
52571 index 0000000..955ddfb
52572 --- /dev/null
52573 +++ b/grsecurity/gracl_cap.c
52574 @@ -0,0 +1,101 @@
52575 +#include <linux/kernel.h>
52576 +#include <linux/module.h>
52577 +#include <linux/sched.h>
52578 +#include <linux/gracl.h>
52579 +#include <linux/grsecurity.h>
52580 +#include <linux/grinternal.h>
52581 +
52582 +extern const char *captab_log[];
52583 +extern int captab_log_entries;
52584 +
52585 +int
52586 +gr_acl_is_capable(const int cap)
52587 +{
52588 + struct task_struct *task = current;
52589 + const struct cred *cred = current_cred();
52590 + struct acl_subject_label *curracl;
52591 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
52592 + kernel_cap_t cap_audit = __cap_empty_set;
52593 +
52594 + if (!gr_acl_is_enabled())
52595 + return 1;
52596 +
52597 + curracl = task->acl;
52598 +
52599 + cap_drop = curracl->cap_lower;
52600 + cap_mask = curracl->cap_mask;
52601 + cap_audit = curracl->cap_invert_audit;
52602 +
52603 + while ((curracl = curracl->parent_subject)) {
52604 + /* if the cap isn't specified in the current computed mask but is specified in the
52605 + current level subject, and is lowered in the current level subject, then add
52606 + it to the set of dropped capabilities
52607 + otherwise, add the current level subject's mask to the current computed mask
52608 + */
52609 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
52610 + cap_raise(cap_mask, cap);
52611 + if (cap_raised(curracl->cap_lower, cap))
52612 + cap_raise(cap_drop, cap);
52613 + if (cap_raised(curracl->cap_invert_audit, cap))
52614 + cap_raise(cap_audit, cap);
52615 + }
52616 + }
52617 +
52618 + if (!cap_raised(cap_drop, cap)) {
52619 + if (cap_raised(cap_audit, cap))
52620 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
52621 + return 1;
52622 + }
52623 +
52624 + curracl = task->acl;
52625 +
52626 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
52627 + && cap_raised(cred->cap_effective, cap)) {
52628 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
52629 + task->role->roletype, cred->uid,
52630 + cred->gid, task->exec_file ?
52631 + gr_to_filename(task->exec_file->f_path.dentry,
52632 + task->exec_file->f_path.mnt) : curracl->filename,
52633 + curracl->filename, 0UL,
52634 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
52635 + return 1;
52636 + }
52637 +
52638 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
52639 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
52640 + return 0;
52641 +}
52642 +
52643 +int
52644 +gr_acl_is_capable_nolog(const int cap)
52645 +{
52646 + struct acl_subject_label *curracl;
52647 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
52648 +
52649 + if (!gr_acl_is_enabled())
52650 + return 1;
52651 +
52652 + curracl = current->acl;
52653 +
52654 + cap_drop = curracl->cap_lower;
52655 + cap_mask = curracl->cap_mask;
52656 +
52657 + while ((curracl = curracl->parent_subject)) {
52658 + /* if the cap isn't specified in the current computed mask but is specified in the
52659 + current level subject, and is lowered in the current level subject, then add
52660 + it to the set of dropped capabilities
52661 + otherwise, add the current level subject's mask to the current computed mask
52662 + */
52663 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
52664 + cap_raise(cap_mask, cap);
52665 + if (cap_raised(curracl->cap_lower, cap))
52666 + cap_raise(cap_drop, cap);
52667 + }
52668 + }
52669 +
52670 + if (!cap_raised(cap_drop, cap))
52671 + return 1;
52672 +
52673 + return 0;
52674 +}
52675 +
52676 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
52677 new file mode 100644
52678 index 0000000..4eda5c3
52679 --- /dev/null
52680 +++ b/grsecurity/gracl_fs.c
52681 @@ -0,0 +1,433 @@
52682 +#include <linux/kernel.h>
52683 +#include <linux/sched.h>
52684 +#include <linux/types.h>
52685 +#include <linux/fs.h>
52686 +#include <linux/file.h>
52687 +#include <linux/stat.h>
52688 +#include <linux/grsecurity.h>
52689 +#include <linux/grinternal.h>
52690 +#include <linux/gracl.h>
52691 +
52692 +__u32
52693 +gr_acl_handle_hidden_file(const struct dentry * dentry,
52694 + const struct vfsmount * mnt)
52695 +{
52696 + __u32 mode;
52697 +
52698 + if (unlikely(!dentry->d_inode))
52699 + return GR_FIND;
52700 +
52701 + mode =
52702 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
52703 +
52704 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
52705 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
52706 + return mode;
52707 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
52708 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
52709 + return 0;
52710 + } else if (unlikely(!(mode & GR_FIND)))
52711 + return 0;
52712 +
52713 + return GR_FIND;
52714 +}
52715 +
52716 +__u32
52717 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
52718 + int acc_mode)
52719 +{
52720 + __u32 reqmode = GR_FIND;
52721 + __u32 mode;
52722 +
52723 + if (unlikely(!dentry->d_inode))
52724 + return reqmode;
52725 +
52726 + if (acc_mode & MAY_APPEND)
52727 + reqmode |= GR_APPEND;
52728 + else if (acc_mode & MAY_WRITE)
52729 + reqmode |= GR_WRITE;
52730 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
52731 + reqmode |= GR_READ;
52732 +
52733 + mode =
52734 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
52735 + mnt);
52736 +
52737 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
52738 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
52739 + reqmode & GR_READ ? " reading" : "",
52740 + reqmode & GR_WRITE ? " writing" : reqmode &
52741 + GR_APPEND ? " appending" : "");
52742 + return reqmode;
52743 + } else
52744 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
52745 + {
52746 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
52747 + reqmode & GR_READ ? " reading" : "",
52748 + reqmode & GR_WRITE ? " writing" : reqmode &
52749 + GR_APPEND ? " appending" : "");
52750 + return 0;
52751 + } else if (unlikely((mode & reqmode) != reqmode))
52752 + return 0;
52753 +
52754 + return reqmode;
52755 +}
52756 +
52757 +__u32
52758 +gr_acl_handle_creat(const struct dentry * dentry,
52759 + const struct dentry * p_dentry,
52760 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
52761 + const int imode)
52762 +{
52763 + __u32 reqmode = GR_WRITE | GR_CREATE;
52764 + __u32 mode;
52765 +
52766 + if (acc_mode & MAY_APPEND)
52767 + reqmode |= GR_APPEND;
52768 + // if a directory was required or the directory already exists, then
52769 + // don't count this open as a read
52770 + if ((acc_mode & MAY_READ) &&
52771 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
52772 + reqmode |= GR_READ;
52773 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
52774 + reqmode |= GR_SETID;
52775 +
52776 + mode =
52777 + gr_check_create(dentry, p_dentry, p_mnt,
52778 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
52779 +
52780 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
52781 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
52782 + reqmode & GR_READ ? " reading" : "",
52783 + reqmode & GR_WRITE ? " writing" : reqmode &
52784 + GR_APPEND ? " appending" : "");
52785 + return reqmode;
52786 + } else
52787 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
52788 + {
52789 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
52790 + reqmode & GR_READ ? " reading" : "",
52791 + reqmode & GR_WRITE ? " writing" : reqmode &
52792 + GR_APPEND ? " appending" : "");
52793 + return 0;
52794 + } else if (unlikely((mode & reqmode) != reqmode))
52795 + return 0;
52796 +
52797 + return reqmode;
52798 +}
52799 +
52800 +__u32
52801 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
52802 + const int fmode)
52803 +{
52804 + __u32 mode, reqmode = GR_FIND;
52805 +
52806 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
52807 + reqmode |= GR_EXEC;
52808 + if (fmode & S_IWOTH)
52809 + reqmode |= GR_WRITE;
52810 + if (fmode & S_IROTH)
52811 + reqmode |= GR_READ;
52812 +
52813 + mode =
52814 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
52815 + mnt);
52816 +
52817 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
52818 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
52819 + reqmode & GR_READ ? " reading" : "",
52820 + reqmode & GR_WRITE ? " writing" : "",
52821 + reqmode & GR_EXEC ? " executing" : "");
52822 + return reqmode;
52823 + } else
52824 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
52825 + {
52826 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
52827 + reqmode & GR_READ ? " reading" : "",
52828 + reqmode & GR_WRITE ? " writing" : "",
52829 + reqmode & GR_EXEC ? " executing" : "");
52830 + return 0;
52831 + } else if (unlikely((mode & reqmode) != reqmode))
52832 + return 0;
52833 +
52834 + return reqmode;
52835 +}
52836 +
52837 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
52838 +{
52839 + __u32 mode;
52840 +
52841 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
52842 +
52843 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
52844 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
52845 + return mode;
52846 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
52847 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
52848 + return 0;
52849 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
52850 + return 0;
52851 +
52852 + return (reqmode);
52853 +}
52854 +
52855 +__u32
52856 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
52857 +{
52858 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
52859 +}
52860 +
52861 +__u32
52862 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
52863 +{
52864 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
52865 +}
52866 +
52867 +__u32
52868 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
52869 +{
52870 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
52871 +}
52872 +
52873 +__u32
52874 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
52875 +{
52876 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
52877 +}
52878 +
52879 +__u32
52880 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
52881 + mode_t mode)
52882 +{
52883 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
52884 + return 1;
52885 +
52886 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
52887 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
52888 + GR_FCHMOD_ACL_MSG);
52889 + } else {
52890 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
52891 + }
52892 +}
52893 +
52894 +__u32
52895 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
52896 + mode_t mode)
52897 +{
52898 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
52899 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
52900 + GR_CHMOD_ACL_MSG);
52901 + } else {
52902 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
52903 + }
52904 +}
52905 +
52906 +__u32
52907 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
52908 +{
52909 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
52910 +}
52911 +
52912 +__u32
52913 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
52914 +{
52915 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
52916 +}
52917 +
52918 +__u32
52919 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
52920 +{
52921 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
52922 +}
52923 +
52924 +__u32
52925 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
52926 +{
52927 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
52928 + GR_UNIXCONNECT_ACL_MSG);
52929 +}
52930 +
52931 +/* hardlinks require at minimum create and link permission,
52932 + any additional privilege required is based on the
52933 + privilege of the file being linked to
52934 +*/
52935 +__u32
52936 +gr_acl_handle_link(const struct dentry * new_dentry,
52937 + const struct dentry * parent_dentry,
52938 + const struct vfsmount * parent_mnt,
52939 + const struct dentry * old_dentry,
52940 + const struct vfsmount * old_mnt, const char *to)
52941 +{
52942 + __u32 mode;
52943 + __u32 needmode = GR_CREATE | GR_LINK;
52944 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
52945 +
52946 + mode =
52947 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
52948 + old_mnt);
52949 +
52950 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
52951 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
52952 + return mode;
52953 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
52954 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
52955 + return 0;
52956 + } else if (unlikely((mode & needmode) != needmode))
52957 + return 0;
52958 +
52959 + return 1;
52960 +}
52961 +
52962 +__u32
52963 +gr_acl_handle_symlink(const struct dentry * new_dentry,
52964 + const struct dentry * parent_dentry,
52965 + const struct vfsmount * parent_mnt, const char *from)
52966 +{
52967 + __u32 needmode = GR_WRITE | GR_CREATE;
52968 + __u32 mode;
52969 +
52970 + mode =
52971 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
52972 + GR_CREATE | GR_AUDIT_CREATE |
52973 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
52974 +
52975 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
52976 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
52977 + return mode;
52978 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
52979 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
52980 + return 0;
52981 + } else if (unlikely((mode & needmode) != needmode))
52982 + return 0;
52983 +
52984 + return (GR_WRITE | GR_CREATE);
52985 +}
52986 +
52987 +static __u32 generic_fs_create_handler(const struct dentry *new_dentry, const struct dentry *parent_dentry, const struct vfsmount *parent_mnt, __u32 reqmode, const char *fmt)
52988 +{
52989 + __u32 mode;
52990 +
52991 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
52992 +
52993 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
52994 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
52995 + return mode;
52996 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
52997 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
52998 + return 0;
52999 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
53000 + return 0;
53001 +
53002 + return (reqmode);
53003 +}
53004 +
53005 +__u32
53006 +gr_acl_handle_mknod(const struct dentry * new_dentry,
53007 + const struct dentry * parent_dentry,
53008 + const struct vfsmount * parent_mnt,
53009 + const int mode)
53010 +{
53011 + __u32 reqmode = GR_WRITE | GR_CREATE;
53012 + if (unlikely(mode & (S_ISUID | S_ISGID)))
53013 + reqmode |= GR_SETID;
53014 +
53015 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
53016 + reqmode, GR_MKNOD_ACL_MSG);
53017 +}
53018 +
53019 +__u32
53020 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
53021 + const struct dentry *parent_dentry,
53022 + const struct vfsmount *parent_mnt)
53023 +{
53024 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
53025 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
53026 +}
53027 +
53028 +#define RENAME_CHECK_SUCCESS(old, new) \
53029 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
53030 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
53031 +
53032 +int
53033 +gr_acl_handle_rename(struct dentry *new_dentry,
53034 + struct dentry *parent_dentry,
53035 + const struct vfsmount *parent_mnt,
53036 + struct dentry *old_dentry,
53037 + struct inode *old_parent_inode,
53038 + struct vfsmount *old_mnt, const char *newname)
53039 +{
53040 + __u32 comp1, comp2;
53041 + int error = 0;
53042 +
53043 + if (unlikely(!gr_acl_is_enabled()))
53044 + return 0;
53045 +
53046 + if (!new_dentry->d_inode) {
53047 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
53048 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
53049 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
53050 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
53051 + GR_DELETE | GR_AUDIT_DELETE |
53052 + GR_AUDIT_READ | GR_AUDIT_WRITE |
53053 + GR_SUPPRESS, old_mnt);
53054 + } else {
53055 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
53056 + GR_CREATE | GR_DELETE |
53057 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
53058 + GR_AUDIT_READ | GR_AUDIT_WRITE |
53059 + GR_SUPPRESS, parent_mnt);
53060 + comp2 =
53061 + gr_search_file(old_dentry,
53062 + GR_READ | GR_WRITE | GR_AUDIT_READ |
53063 + GR_DELETE | GR_AUDIT_DELETE |
53064 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
53065 + }
53066 +
53067 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
53068 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
53069 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
53070 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
53071 + && !(comp2 & GR_SUPPRESS)) {
53072 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
53073 + error = -EACCES;
53074 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
53075 + error = -EACCES;
53076 +
53077 + return error;
53078 +}
53079 +
53080 +void
53081 +gr_acl_handle_exit(void)
53082 +{
53083 + u16 id;
53084 + char *rolename;
53085 + struct file *exec_file;
53086 +
53087 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
53088 + !(current->role->roletype & GR_ROLE_PERSIST))) {
53089 + id = current->acl_role_id;
53090 + rolename = current->role->rolename;
53091 + gr_set_acls(1);
53092 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
53093 + }
53094 +
53095 + write_lock(&grsec_exec_file_lock);
53096 + exec_file = current->exec_file;
53097 + current->exec_file = NULL;
53098 + write_unlock(&grsec_exec_file_lock);
53099 +
53100 + if (exec_file)
53101 + fput(exec_file);
53102 +}
53103 +
53104 +int
53105 +gr_acl_handle_procpidmem(const struct task_struct *task)
53106 +{
53107 + if (unlikely(!gr_acl_is_enabled()))
53108 + return 0;
53109 +
53110 + if (task != current && task->acl->mode & GR_PROTPROCFD)
53111 + return -EACCES;
53112 +
53113 + return 0;
53114 +}
53115 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
53116 new file mode 100644
53117 index 0000000..17050ca
53118 --- /dev/null
53119 +++ b/grsecurity/gracl_ip.c
53120 @@ -0,0 +1,381 @@
53121 +#include <linux/kernel.h>
53122 +#include <asm/uaccess.h>
53123 +#include <asm/errno.h>
53124 +#include <net/sock.h>
53125 +#include <linux/file.h>
53126 +#include <linux/fs.h>
53127 +#include <linux/net.h>
53128 +#include <linux/in.h>
53129 +#include <linux/skbuff.h>
53130 +#include <linux/ip.h>
53131 +#include <linux/udp.h>
53132 +#include <linux/types.h>
53133 +#include <linux/sched.h>
53134 +#include <linux/netdevice.h>
53135 +#include <linux/inetdevice.h>
53136 +#include <linux/gracl.h>
53137 +#include <linux/grsecurity.h>
53138 +#include <linux/grinternal.h>
53139 +
53140 +#define GR_BIND 0x01
53141 +#define GR_CONNECT 0x02
53142 +#define GR_INVERT 0x04
53143 +#define GR_BINDOVERRIDE 0x08
53144 +#define GR_CONNECTOVERRIDE 0x10
53145 +#define GR_SOCK_FAMILY 0x20
53146 +
53147 +static const char * gr_protocols[IPPROTO_MAX] = {
53148 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
53149 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
53150 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
53151 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
53152 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
53153 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
53154 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
53155 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
53156 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
53157 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
53158 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
53159 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
53160 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
53161 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
53162 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
53163 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
53164 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
53165 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
53166 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
53167 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
53168 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
53169 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
53170 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
53171 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
53172 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
53173 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
53174 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
53175 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
53176 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
53177 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
53178 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
53179 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
53180 + };
53181 +
53182 +static const char * gr_socktypes[SOCK_MAX] = {
53183 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
53184 + "unknown:7", "unknown:8", "unknown:9", "packet"
53185 + };
53186 +
53187 +static const char * gr_sockfamilies[AF_MAX+1] = {
53188 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
53189 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
53190 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
53191 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
53192 + };
53193 +
53194 +const char *
53195 +gr_proto_to_name(unsigned char proto)
53196 +{
53197 + return gr_protocols[proto];
53198 +}
53199 +
53200 +const char *
53201 +gr_socktype_to_name(unsigned char type)
53202 +{
53203 + return gr_socktypes[type];
53204 +}
53205 +
53206 +const char *
53207 +gr_sockfamily_to_name(unsigned char family)
53208 +{
53209 + return gr_sockfamilies[family];
53210 +}
53211 +
53212 +int
53213 +gr_search_socket(const int domain, const int type, const int protocol)
53214 +{
53215 + struct acl_subject_label *curr;
53216 + const struct cred *cred = current_cred();
53217 +
53218 + if (unlikely(!gr_acl_is_enabled()))
53219 + goto exit;
53220 +
53221 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
53222 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
53223 + goto exit; // let the kernel handle it
53224 +
53225 + curr = current->acl;
53226 +
53227 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
53228 + /* the family is allowed, if this is PF_INET allow it only if
53229 + the extra sock type/protocol checks pass */
53230 + if (domain == PF_INET)
53231 + goto inet_check;
53232 + goto exit;
53233 + } else {
53234 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53235 + __u32 fakeip = 0;
53236 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53237 + current->role->roletype, cred->uid,
53238 + cred->gid, current->exec_file ?
53239 + gr_to_filename(current->exec_file->f_path.dentry,
53240 + current->exec_file->f_path.mnt) :
53241 + curr->filename, curr->filename,
53242 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
53243 + &current->signal->saved_ip);
53244 + goto exit;
53245 + }
53246 + goto exit_fail;
53247 + }
53248 +
53249 +inet_check:
53250 + /* the rest of this checking is for IPv4 only */
53251 + if (!curr->ips)
53252 + goto exit;
53253 +
53254 + if ((curr->ip_type & (1 << type)) &&
53255 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
53256 + goto exit;
53257 +
53258 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53259 + /* we don't place acls on raw sockets , and sometimes
53260 + dgram/ip sockets are opened for ioctl and not
53261 + bind/connect, so we'll fake a bind learn log */
53262 + if (type == SOCK_RAW || type == SOCK_PACKET) {
53263 + __u32 fakeip = 0;
53264 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53265 + current->role->roletype, cred->uid,
53266 + cred->gid, current->exec_file ?
53267 + gr_to_filename(current->exec_file->f_path.dentry,
53268 + current->exec_file->f_path.mnt) :
53269 + curr->filename, curr->filename,
53270 + &fakeip, 0, type,
53271 + protocol, GR_CONNECT, &current->signal->saved_ip);
53272 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
53273 + __u32 fakeip = 0;
53274 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53275 + current->role->roletype, cred->uid,
53276 + cred->gid, current->exec_file ?
53277 + gr_to_filename(current->exec_file->f_path.dentry,
53278 + current->exec_file->f_path.mnt) :
53279 + curr->filename, curr->filename,
53280 + &fakeip, 0, type,
53281 + protocol, GR_BIND, &current->signal->saved_ip);
53282 + }
53283 + /* we'll log when they use connect or bind */
53284 + goto exit;
53285 + }
53286 +
53287 +exit_fail:
53288 + if (domain == PF_INET)
53289 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
53290 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
53291 + else
53292 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
53293 + gr_socktype_to_name(type), protocol);
53294 +
53295 + return 0;
53296 +exit:
53297 + return 1;
53298 +}
53299 +
53300 +int check_ip_policy(struct acl_ip_label *ip, __u32 ip_addr, __u16 ip_port, __u8 protocol, const int mode, const int type, __u32 our_addr, __u32 our_netmask)
53301 +{
53302 + if ((ip->mode & mode) &&
53303 + (ip_port >= ip->low) &&
53304 + (ip_port <= ip->high) &&
53305 + ((ntohl(ip_addr) & our_netmask) ==
53306 + (ntohl(our_addr) & our_netmask))
53307 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
53308 + && (ip->type & (1 << type))) {
53309 + if (ip->mode & GR_INVERT)
53310 + return 2; // specifically denied
53311 + else
53312 + return 1; // allowed
53313 + }
53314 +
53315 + return 0; // not specifically allowed, may continue parsing
53316 +}
53317 +
53318 +static int
53319 +gr_search_connectbind(const int full_mode, struct sock *sk,
53320 + struct sockaddr_in *addr, const int type)
53321 +{
53322 + char iface[IFNAMSIZ] = {0};
53323 + struct acl_subject_label *curr;
53324 + struct acl_ip_label *ip;
53325 + struct inet_sock *isk;
53326 + struct net_device *dev;
53327 + struct in_device *idev;
53328 + unsigned long i;
53329 + int ret;
53330 + int mode = full_mode & (GR_BIND | GR_CONNECT);
53331 + __u32 ip_addr = 0;
53332 + __u32 our_addr;
53333 + __u32 our_netmask;
53334 + char *p;
53335 + __u16 ip_port = 0;
53336 + const struct cred *cred = current_cred();
53337 +
53338 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
53339 + return 0;
53340 +
53341 + curr = current->acl;
53342 + isk = inet_sk(sk);
53343 +
53344 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
53345 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
53346 + addr->sin_addr.s_addr = curr->inaddr_any_override;
53347 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
53348 + struct sockaddr_in saddr;
53349 + int err;
53350 +
53351 + saddr.sin_family = AF_INET;
53352 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
53353 + saddr.sin_port = isk->inet_sport;
53354 +
53355 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
53356 + if (err)
53357 + return err;
53358 +
53359 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
53360 + if (err)
53361 + return err;
53362 + }
53363 +
53364 + if (!curr->ips)
53365 + return 0;
53366 +
53367 + ip_addr = addr->sin_addr.s_addr;
53368 + ip_port = ntohs(addr->sin_port);
53369 +
53370 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53371 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53372 + current->role->roletype, cred->uid,
53373 + cred->gid, current->exec_file ?
53374 + gr_to_filename(current->exec_file->f_path.dentry,
53375 + current->exec_file->f_path.mnt) :
53376 + curr->filename, curr->filename,
53377 + &ip_addr, ip_port, type,
53378 + sk->sk_protocol, mode, &current->signal->saved_ip);
53379 + return 0;
53380 + }
53381 +
53382 + for (i = 0; i < curr->ip_num; i++) {
53383 + ip = *(curr->ips + i);
53384 + if (ip->iface != NULL) {
53385 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
53386 + p = strchr(iface, ':');
53387 + if (p != NULL)
53388 + *p = '\0';
53389 + dev = dev_get_by_name(sock_net(sk), iface);
53390 + if (dev == NULL)
53391 + continue;
53392 + idev = in_dev_get(dev);
53393 + if (idev == NULL) {
53394 + dev_put(dev);
53395 + continue;
53396 + }
53397 + rcu_read_lock();
53398 + for_ifa(idev) {
53399 + if (!strcmp(ip->iface, ifa->ifa_label)) {
53400 + our_addr = ifa->ifa_address;
53401 + our_netmask = 0xffffffff;
53402 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
53403 + if (ret == 1) {
53404 + rcu_read_unlock();
53405 + in_dev_put(idev);
53406 + dev_put(dev);
53407 + return 0;
53408 + } else if (ret == 2) {
53409 + rcu_read_unlock();
53410 + in_dev_put(idev);
53411 + dev_put(dev);
53412 + goto denied;
53413 + }
53414 + }
53415 + } endfor_ifa(idev);
53416 + rcu_read_unlock();
53417 + in_dev_put(idev);
53418 + dev_put(dev);
53419 + } else {
53420 + our_addr = ip->addr;
53421 + our_netmask = ip->netmask;
53422 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
53423 + if (ret == 1)
53424 + return 0;
53425 + else if (ret == 2)
53426 + goto denied;
53427 + }
53428 + }
53429 +
53430 +denied:
53431 + if (mode == GR_BIND)
53432 + gr_log_int5_str2(GR_DONT_AUDIT, GR_BIND_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
53433 + else if (mode == GR_CONNECT)
53434 + gr_log_int5_str2(GR_DONT_AUDIT, GR_CONNECT_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
53435 +
53436 + return -EACCES;
53437 +}
53438 +
53439 +int
53440 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
53441 +{
53442 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
53443 +}
53444 +
53445 +int
53446 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
53447 +{
53448 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
53449 +}
53450 +
53451 +int gr_search_listen(struct socket *sock)
53452 +{
53453 + struct sock *sk = sock->sk;
53454 + struct sockaddr_in addr;
53455 +
53456 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
53457 + addr.sin_port = inet_sk(sk)->inet_sport;
53458 +
53459 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
53460 +}
53461 +
53462 +int gr_search_accept(struct socket *sock)
53463 +{
53464 + struct sock *sk = sock->sk;
53465 + struct sockaddr_in addr;
53466 +
53467 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
53468 + addr.sin_port = inet_sk(sk)->inet_sport;
53469 +
53470 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
53471 +}
53472 +
53473 +int
53474 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
53475 +{
53476 + if (addr)
53477 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
53478 + else {
53479 + struct sockaddr_in sin;
53480 + const struct inet_sock *inet = inet_sk(sk);
53481 +
53482 + sin.sin_addr.s_addr = inet->inet_daddr;
53483 + sin.sin_port = inet->inet_dport;
53484 +
53485 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
53486 + }
53487 +}
53488 +
53489 +int
53490 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
53491 +{
53492 + struct sockaddr_in sin;
53493 +
53494 + if (unlikely(skb->len < sizeof (struct udphdr)))
53495 + return 0; // skip this packet
53496 +
53497 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
53498 + sin.sin_port = udp_hdr(skb)->source;
53499 +
53500 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
53501 +}
53502 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
53503 new file mode 100644
53504 index 0000000..25f54ef
53505 --- /dev/null
53506 +++ b/grsecurity/gracl_learn.c
53507 @@ -0,0 +1,207 @@
53508 +#include <linux/kernel.h>
53509 +#include <linux/mm.h>
53510 +#include <linux/sched.h>
53511 +#include <linux/poll.h>
53512 +#include <linux/string.h>
53513 +#include <linux/file.h>
53514 +#include <linux/types.h>
53515 +#include <linux/vmalloc.h>
53516 +#include <linux/grinternal.h>
53517 +
53518 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
53519 + size_t count, loff_t *ppos);
53520 +extern int gr_acl_is_enabled(void);
53521 +
53522 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
53523 +static int gr_learn_attached;
53524 +
53525 +/* use a 512k buffer */
53526 +#define LEARN_BUFFER_SIZE (512 * 1024)
53527 +
53528 +static DEFINE_SPINLOCK(gr_learn_lock);
53529 +static DEFINE_MUTEX(gr_learn_user_mutex);
53530 +
53531 +/* we need to maintain two buffers, so that the kernel context of grlearn
53532 + uses a semaphore around the userspace copying, and the other kernel contexts
53533 + use a spinlock when copying into the buffer, since they cannot sleep
53534 +*/
53535 +static char *learn_buffer;
53536 +static char *learn_buffer_user;
53537 +static int learn_buffer_len;
53538 +static int learn_buffer_user_len;
53539 +
53540 +static ssize_t
53541 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
53542 +{
53543 + DECLARE_WAITQUEUE(wait, current);
53544 + ssize_t retval = 0;
53545 +
53546 + add_wait_queue(&learn_wait, &wait);
53547 + set_current_state(TASK_INTERRUPTIBLE);
53548 + do {
53549 + mutex_lock(&gr_learn_user_mutex);
53550 + spin_lock(&gr_learn_lock);
53551 + if (learn_buffer_len)
53552 + break;
53553 + spin_unlock(&gr_learn_lock);
53554 + mutex_unlock(&gr_learn_user_mutex);
53555 + if (file->f_flags & O_NONBLOCK) {
53556 + retval = -EAGAIN;
53557 + goto out;
53558 + }
53559 + if (signal_pending(current)) {
53560 + retval = -ERESTARTSYS;
53561 + goto out;
53562 + }
53563 +
53564 + schedule();
53565 + } while (1);
53566 +
53567 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
53568 + learn_buffer_user_len = learn_buffer_len;
53569 + retval = learn_buffer_len;
53570 + learn_buffer_len = 0;
53571 +
53572 + spin_unlock(&gr_learn_lock);
53573 +
53574 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
53575 + retval = -EFAULT;
53576 +
53577 + mutex_unlock(&gr_learn_user_mutex);
53578 +out:
53579 + set_current_state(TASK_RUNNING);
53580 + remove_wait_queue(&learn_wait, &wait);
53581 + return retval;
53582 +}
53583 +
53584 +static unsigned int
53585 +poll_learn(struct file * file, poll_table * wait)
53586 +{
53587 + poll_wait(file, &learn_wait, wait);
53588 +
53589 + if (learn_buffer_len)
53590 + return (POLLIN | POLLRDNORM);
53591 +
53592 + return 0;
53593 +}
53594 +
53595 +void
53596 +gr_clear_learn_entries(void)
53597 +{
53598 + char *tmp;
53599 +
53600 + mutex_lock(&gr_learn_user_mutex);
53601 + spin_lock(&gr_learn_lock);
53602 + tmp = learn_buffer;
53603 + learn_buffer = NULL;
53604 + spin_unlock(&gr_learn_lock);
53605 + if (tmp)
53606 + vfree(tmp);
53607 + if (learn_buffer_user != NULL) {
53608 + vfree(learn_buffer_user);
53609 + learn_buffer_user = NULL;
53610 + }
53611 + learn_buffer_len = 0;
53612 + mutex_unlock(&gr_learn_user_mutex);
53613 +
53614 + return;
53615 +}
53616 +
53617 +void
53618 +gr_add_learn_entry(const char *fmt, ...)
53619 +{
53620 + va_list args;
53621 + unsigned int len;
53622 +
53623 + if (!gr_learn_attached)
53624 + return;
53625 +
53626 + spin_lock(&gr_learn_lock);
53627 +
53628 + /* leave a gap at the end so we know when it's "full" but don't have to
53629 + compute the exact length of the string we're trying to append
53630 + */
53631 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
53632 + spin_unlock(&gr_learn_lock);
53633 + wake_up_interruptible(&learn_wait);
53634 + return;
53635 + }
53636 + if (learn_buffer == NULL) {
53637 + spin_unlock(&gr_learn_lock);
53638 + return;
53639 + }
53640 +
53641 + va_start(args, fmt);
53642 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
53643 + va_end(args);
53644 +
53645 + learn_buffer_len += len + 1;
53646 +
53647 + spin_unlock(&gr_learn_lock);
53648 + wake_up_interruptible(&learn_wait);
53649 +
53650 + return;
53651 +}
53652 +
53653 +static int
53654 +open_learn(struct inode *inode, struct file *file)
53655 +{
53656 + if (file->f_mode & FMODE_READ && gr_learn_attached)
53657 + return -EBUSY;
53658 + if (file->f_mode & FMODE_READ) {
53659 + int retval = 0;
53660 + mutex_lock(&gr_learn_user_mutex);
53661 + if (learn_buffer == NULL)
53662 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
53663 + if (learn_buffer_user == NULL)
53664 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
53665 + if (learn_buffer == NULL) {
53666 + retval = -ENOMEM;
53667 + goto out_error;
53668 + }
53669 + if (learn_buffer_user == NULL) {
53670 + retval = -ENOMEM;
53671 + goto out_error;
53672 + }
53673 + learn_buffer_len = 0;
53674 + learn_buffer_user_len = 0;
53675 + gr_learn_attached = 1;
53676 +out_error:
53677 + mutex_unlock(&gr_learn_user_mutex);
53678 + return retval;
53679 + }
53680 + return 0;
53681 +}
53682 +
53683 +static int
53684 +close_learn(struct inode *inode, struct file *file)
53685 +{
53686 + if (file->f_mode & FMODE_READ) {
53687 + char *tmp = NULL;
53688 + mutex_lock(&gr_learn_user_mutex);
53689 + spin_lock(&gr_learn_lock);
53690 + tmp = learn_buffer;
53691 + learn_buffer = NULL;
53692 + spin_unlock(&gr_learn_lock);
53693 + if (tmp)
53694 + vfree(tmp);
53695 + if (learn_buffer_user != NULL) {
53696 + vfree(learn_buffer_user);
53697 + learn_buffer_user = NULL;
53698 + }
53699 + learn_buffer_len = 0;
53700 + learn_buffer_user_len = 0;
53701 + gr_learn_attached = 0;
53702 + mutex_unlock(&gr_learn_user_mutex);
53703 + }
53704 +
53705 + return 0;
53706 +}
53707 +
53708 +const struct file_operations grsec_fops = {
53709 + .read = read_learn,
53710 + .write = write_grsec_handler,
53711 + .open = open_learn,
53712 + .release = close_learn,
53713 + .poll = poll_learn,
53714 +};
53715 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
53716 new file mode 100644
53717 index 0000000..39645c9
53718 --- /dev/null
53719 +++ b/grsecurity/gracl_res.c
53720 @@ -0,0 +1,68 @@
53721 +#include <linux/kernel.h>
53722 +#include <linux/sched.h>
53723 +#include <linux/gracl.h>
53724 +#include <linux/grinternal.h>
53725 +
53726 +static const char *restab_log[] = {
53727 + [RLIMIT_CPU] = "RLIMIT_CPU",
53728 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
53729 + [RLIMIT_DATA] = "RLIMIT_DATA",
53730 + [RLIMIT_STACK] = "RLIMIT_STACK",
53731 + [RLIMIT_CORE] = "RLIMIT_CORE",
53732 + [RLIMIT_RSS] = "RLIMIT_RSS",
53733 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
53734 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
53735 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
53736 + [RLIMIT_AS] = "RLIMIT_AS",
53737 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
53738 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
53739 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
53740 + [RLIMIT_NICE] = "RLIMIT_NICE",
53741 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
53742 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
53743 + [GR_CRASH_RES] = "RLIMIT_CRASH"
53744 +};
53745 +
53746 +void
53747 +gr_log_resource(const struct task_struct *task,
53748 + const int res, const unsigned long wanted, const int gt)
53749 +{
53750 + const struct cred *cred;
53751 + unsigned long rlim;
53752 +
53753 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
53754 + return;
53755 +
53756 + // not yet supported resource
53757 + if (unlikely(!restab_log[res]))
53758 + return;
53759 +
53760 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
53761 + rlim = task_rlimit_max(task, res);
53762 + else
53763 + rlim = task_rlimit(task, res);
53764 +
53765 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
53766 + return;
53767 +
53768 + rcu_read_lock();
53769 + cred = __task_cred(task);
53770 +
53771 + if (res == RLIMIT_NPROC &&
53772 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
53773 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
53774 + goto out_rcu_unlock;
53775 + else if (res == RLIMIT_MEMLOCK &&
53776 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
53777 + goto out_rcu_unlock;
53778 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
53779 + goto out_rcu_unlock;
53780 + rcu_read_unlock();
53781 +
53782 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
53783 +
53784 + return;
53785 +out_rcu_unlock:
53786 + rcu_read_unlock();
53787 + return;
53788 +}
53789 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
53790 new file mode 100644
53791 index 0000000..5556be3
53792 --- /dev/null
53793 +++ b/grsecurity/gracl_segv.c
53794 @@ -0,0 +1,299 @@
53795 +#include <linux/kernel.h>
53796 +#include <linux/mm.h>
53797 +#include <asm/uaccess.h>
53798 +#include <asm/errno.h>
53799 +#include <asm/mman.h>
53800 +#include <net/sock.h>
53801 +#include <linux/file.h>
53802 +#include <linux/fs.h>
53803 +#include <linux/net.h>
53804 +#include <linux/in.h>
53805 +#include <linux/slab.h>
53806 +#include <linux/types.h>
53807 +#include <linux/sched.h>
53808 +#include <linux/timer.h>
53809 +#include <linux/gracl.h>
53810 +#include <linux/grsecurity.h>
53811 +#include <linux/grinternal.h>
53812 +
53813 +static struct crash_uid *uid_set;
53814 +static unsigned short uid_used;
53815 +static DEFINE_SPINLOCK(gr_uid_lock);
53816 +extern rwlock_t gr_inode_lock;
53817 +extern struct acl_subject_label *
53818 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
53819 + struct acl_role_label *role);
53820 +
53821 +#ifdef CONFIG_BTRFS_FS
53822 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53823 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53824 +#endif
53825 +
53826 +static inline dev_t __get_dev(const struct dentry *dentry)
53827 +{
53828 +#ifdef CONFIG_BTRFS_FS
53829 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53830 + return get_btrfs_dev_from_inode(dentry->d_inode);
53831 + else
53832 +#endif
53833 + return dentry->d_inode->i_sb->s_dev;
53834 +}
53835 +
53836 +int
53837 +gr_init_uidset(void)
53838 +{
53839 + uid_set =
53840 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
53841 + uid_used = 0;
53842 +
53843 + return uid_set ? 1 : 0;
53844 +}
53845 +
53846 +void
53847 +gr_free_uidset(void)
53848 +{
53849 + if (uid_set)
53850 + kfree(uid_set);
53851 +
53852 + return;
53853 +}
53854 +
53855 +int
53856 +gr_find_uid(const uid_t uid)
53857 +{
53858 + struct crash_uid *tmp = uid_set;
53859 + uid_t buid;
53860 + int low = 0, high = uid_used - 1, mid;
53861 +
53862 + while (high >= low) {
53863 + mid = (low + high) >> 1;
53864 + buid = tmp[mid].uid;
53865 + if (buid == uid)
53866 + return mid;
53867 + if (buid > uid)
53868 + high = mid - 1;
53869 + if (buid < uid)
53870 + low = mid + 1;
53871 + }
53872 +
53873 + return -1;
53874 +}
53875 +
53876 +static __inline__ void
53877 +gr_insertsort(void)
53878 +{
53879 + unsigned short i, j;
53880 + struct crash_uid index;
53881 +
53882 + for (i = 1; i < uid_used; i++) {
53883 + index = uid_set[i];
53884 + j = i;
53885 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
53886 + uid_set[j] = uid_set[j - 1];
53887 + j--;
53888 + }
53889 + uid_set[j] = index;
53890 + }
53891 +
53892 + return;
53893 +}
53894 +
53895 +static __inline__ void
53896 +gr_insert_uid(const uid_t uid, const unsigned long expires)
53897 +{
53898 + int loc;
53899 +
53900 + if (uid_used == GR_UIDTABLE_MAX)
53901 + return;
53902 +
53903 + loc = gr_find_uid(uid);
53904 +
53905 + if (loc >= 0) {
53906 + uid_set[loc].expires = expires;
53907 + return;
53908 + }
53909 +
53910 + uid_set[uid_used].uid = uid;
53911 + uid_set[uid_used].expires = expires;
53912 + uid_used++;
53913 +
53914 + gr_insertsort();
53915 +
53916 + return;
53917 +}
53918 +
53919 +void
53920 +gr_remove_uid(const unsigned short loc)
53921 +{
53922 + unsigned short i;
53923 +
53924 + for (i = loc + 1; i < uid_used; i++)
53925 + uid_set[i - 1] = uid_set[i];
53926 +
53927 + uid_used--;
53928 +
53929 + return;
53930 +}
53931 +
53932 +int
53933 +gr_check_crash_uid(const uid_t uid)
53934 +{
53935 + int loc;
53936 + int ret = 0;
53937 +
53938 + if (unlikely(!gr_acl_is_enabled()))
53939 + return 0;
53940 +
53941 + spin_lock(&gr_uid_lock);
53942 + loc = gr_find_uid(uid);
53943 +
53944 + if (loc < 0)
53945 + goto out_unlock;
53946 +
53947 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
53948 + gr_remove_uid(loc);
53949 + else
53950 + ret = 1;
53951 +
53952 +out_unlock:
53953 + spin_unlock(&gr_uid_lock);
53954 + return ret;
53955 +}
53956 +
53957 +static __inline__ int
53958 +proc_is_setxid(const struct cred *cred)
53959 +{
53960 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
53961 + cred->uid != cred->fsuid)
53962 + return 1;
53963 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
53964 + cred->gid != cred->fsgid)
53965 + return 1;
53966 +
53967 + return 0;
53968 +}
53969 +
53970 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
53971 +
53972 +void
53973 +gr_handle_crash(struct task_struct *task, const int sig)
53974 +{
53975 + struct acl_subject_label *curr;
53976 + struct task_struct *tsk, *tsk2;
53977 + const struct cred *cred;
53978 + const struct cred *cred2;
53979 +
53980 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
53981 + return;
53982 +
53983 + if (unlikely(!gr_acl_is_enabled()))
53984 + return;
53985 +
53986 + curr = task->acl;
53987 +
53988 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
53989 + return;
53990 +
53991 + if (time_before_eq(curr->expires, get_seconds())) {
53992 + curr->expires = 0;
53993 + curr->crashes = 0;
53994 + }
53995 +
53996 + curr->crashes++;
53997 +
53998 + if (!curr->expires)
53999 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
54000 +
54001 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
54002 + time_after(curr->expires, get_seconds())) {
54003 + rcu_read_lock();
54004 + cred = __task_cred(task);
54005 + if (cred->uid && proc_is_setxid(cred)) {
54006 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
54007 + spin_lock(&gr_uid_lock);
54008 + gr_insert_uid(cred->uid, curr->expires);
54009 + spin_unlock(&gr_uid_lock);
54010 + curr->expires = 0;
54011 + curr->crashes = 0;
54012 + read_lock(&tasklist_lock);
54013 + do_each_thread(tsk2, tsk) {
54014 + cred2 = __task_cred(tsk);
54015 + if (tsk != task && cred2->uid == cred->uid)
54016 + gr_fake_force_sig(SIGKILL, tsk);
54017 + } while_each_thread(tsk2, tsk);
54018 + read_unlock(&tasklist_lock);
54019 + } else {
54020 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
54021 + read_lock(&tasklist_lock);
54022 + read_lock(&grsec_exec_file_lock);
54023 + do_each_thread(tsk2, tsk) {
54024 + if (likely(tsk != task)) {
54025 + // if this thread has the same subject as the one that triggered
54026 + // RES_CRASH and it's the same binary, kill it
54027 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
54028 + gr_fake_force_sig(SIGKILL, tsk);
54029 + }
54030 + } while_each_thread(tsk2, tsk);
54031 + read_unlock(&grsec_exec_file_lock);
54032 + read_unlock(&tasklist_lock);
54033 + }
54034 + rcu_read_unlock();
54035 + }
54036 +
54037 + return;
54038 +}
54039 +
54040 +int
54041 +gr_check_crash_exec(const struct file *filp)
54042 +{
54043 + struct acl_subject_label *curr;
54044 +
54045 + if (unlikely(!gr_acl_is_enabled()))
54046 + return 0;
54047 +
54048 + read_lock(&gr_inode_lock);
54049 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
54050 + __get_dev(filp->f_path.dentry),
54051 + current->role);
54052 + read_unlock(&gr_inode_lock);
54053 +
54054 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
54055 + (!curr->crashes && !curr->expires))
54056 + return 0;
54057 +
54058 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
54059 + time_after(curr->expires, get_seconds()))
54060 + return 1;
54061 + else if (time_before_eq(curr->expires, get_seconds())) {
54062 + curr->crashes = 0;
54063 + curr->expires = 0;
54064 + }
54065 +
54066 + return 0;
54067 +}
54068 +
54069 +void
54070 +gr_handle_alertkill(struct task_struct *task)
54071 +{
54072 + struct acl_subject_label *curracl;
54073 + __u32 curr_ip;
54074 + struct task_struct *p, *p2;
54075 +
54076 + if (unlikely(!gr_acl_is_enabled()))
54077 + return;
54078 +
54079 + curracl = task->acl;
54080 + curr_ip = task->signal->curr_ip;
54081 +
54082 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
54083 + read_lock(&tasklist_lock);
54084 + do_each_thread(p2, p) {
54085 + if (p->signal->curr_ip == curr_ip)
54086 + gr_fake_force_sig(SIGKILL, p);
54087 + } while_each_thread(p2, p);
54088 + read_unlock(&tasklist_lock);
54089 + } else if (curracl->mode & GR_KILLPROC)
54090 + gr_fake_force_sig(SIGKILL, task);
54091 +
54092 + return;
54093 +}
54094 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
54095 new file mode 100644
54096 index 0000000..9d83a69
54097 --- /dev/null
54098 +++ b/grsecurity/gracl_shm.c
54099 @@ -0,0 +1,40 @@
54100 +#include <linux/kernel.h>
54101 +#include <linux/mm.h>
54102 +#include <linux/sched.h>
54103 +#include <linux/file.h>
54104 +#include <linux/ipc.h>
54105 +#include <linux/gracl.h>
54106 +#include <linux/grsecurity.h>
54107 +#include <linux/grinternal.h>
54108 +
54109 +int
54110 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54111 + const time_t shm_createtime, const uid_t cuid, const int shmid)
54112 +{
54113 + struct task_struct *task;
54114 +
54115 + if (!gr_acl_is_enabled())
54116 + return 1;
54117 +
54118 + rcu_read_lock();
54119 + read_lock(&tasklist_lock);
54120 +
54121 + task = find_task_by_vpid(shm_cprid);
54122 +
54123 + if (unlikely(!task))
54124 + task = find_task_by_vpid(shm_lapid);
54125 +
54126 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
54127 + (task->pid == shm_lapid)) &&
54128 + (task->acl->mode & GR_PROTSHM) &&
54129 + (task->acl != current->acl))) {
54130 + read_unlock(&tasklist_lock);
54131 + rcu_read_unlock();
54132 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
54133 + return 0;
54134 + }
54135 + read_unlock(&tasklist_lock);
54136 + rcu_read_unlock();
54137 +
54138 + return 1;
54139 +}
54140 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
54141 new file mode 100644
54142 index 0000000..bc0be01
54143 --- /dev/null
54144 +++ b/grsecurity/grsec_chdir.c
54145 @@ -0,0 +1,19 @@
54146 +#include <linux/kernel.h>
54147 +#include <linux/sched.h>
54148 +#include <linux/fs.h>
54149 +#include <linux/file.h>
54150 +#include <linux/grsecurity.h>
54151 +#include <linux/grinternal.h>
54152 +
54153 +void
54154 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
54155 +{
54156 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
54157 + if ((grsec_enable_chdir && grsec_enable_group &&
54158 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
54159 + !grsec_enable_group)) {
54160 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
54161 + }
54162 +#endif
54163 + return;
54164 +}
54165 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
54166 new file mode 100644
54167 index 0000000..a2dc675
54168 --- /dev/null
54169 +++ b/grsecurity/grsec_chroot.c
54170 @@ -0,0 +1,351 @@
54171 +#include <linux/kernel.h>
54172 +#include <linux/module.h>
54173 +#include <linux/sched.h>
54174 +#include <linux/file.h>
54175 +#include <linux/fs.h>
54176 +#include <linux/mount.h>
54177 +#include <linux/types.h>
54178 +#include <linux/pid_namespace.h>
54179 +#include <linux/grsecurity.h>
54180 +#include <linux/grinternal.h>
54181 +
54182 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
54183 +{
54184 +#ifdef CONFIG_GRKERNSEC
54185 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
54186 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
54187 + task->gr_is_chrooted = 1;
54188 + else
54189 + task->gr_is_chrooted = 0;
54190 +
54191 + task->gr_chroot_dentry = path->dentry;
54192 +#endif
54193 + return;
54194 +}
54195 +
54196 +void gr_clear_chroot_entries(struct task_struct *task)
54197 +{
54198 +#ifdef CONFIG_GRKERNSEC
54199 + task->gr_is_chrooted = 0;
54200 + task->gr_chroot_dentry = NULL;
54201 +#endif
54202 + return;
54203 +}
54204 +
54205 +int
54206 +gr_handle_chroot_unix(const pid_t pid)
54207 +{
54208 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
54209 + struct task_struct *p;
54210 +
54211 + if (unlikely(!grsec_enable_chroot_unix))
54212 + return 1;
54213 +
54214 + if (likely(!proc_is_chrooted(current)))
54215 + return 1;
54216 +
54217 + rcu_read_lock();
54218 + read_lock(&tasklist_lock);
54219 + p = find_task_by_vpid_unrestricted(pid);
54220 + if (unlikely(p && !have_same_root(current, p))) {
54221 + read_unlock(&tasklist_lock);
54222 + rcu_read_unlock();
54223 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
54224 + return 0;
54225 + }
54226 + read_unlock(&tasklist_lock);
54227 + rcu_read_unlock();
54228 +#endif
54229 + return 1;
54230 +}
54231 +
54232 +int
54233 +gr_handle_chroot_nice(void)
54234 +{
54235 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
54236 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
54237 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
54238 + return -EPERM;
54239 + }
54240 +#endif
54241 + return 0;
54242 +}
54243 +
54244 +int
54245 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
54246 +{
54247 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
54248 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
54249 + && proc_is_chrooted(current)) {
54250 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
54251 + return -EACCES;
54252 + }
54253 +#endif
54254 + return 0;
54255 +}
54256 +
54257 +int
54258 +gr_handle_chroot_rawio(const struct inode *inode)
54259 +{
54260 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54261 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54262 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
54263 + return 1;
54264 +#endif
54265 + return 0;
54266 +}
54267 +
54268 +int
54269 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
54270 +{
54271 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
54272 + struct task_struct *p;
54273 + int ret = 0;
54274 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
54275 + return ret;
54276 +
54277 + read_lock(&tasklist_lock);
54278 + do_each_pid_task(pid, type, p) {
54279 + if (!have_same_root(current, p)) {
54280 + ret = 1;
54281 + goto out;
54282 + }
54283 + } while_each_pid_task(pid, type, p);
54284 +out:
54285 + read_unlock(&tasklist_lock);
54286 + return ret;
54287 +#endif
54288 + return 0;
54289 +}
54290 +
54291 +int
54292 +gr_pid_is_chrooted(struct task_struct *p)
54293 +{
54294 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
54295 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
54296 + return 0;
54297 +
54298 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
54299 + !have_same_root(current, p)) {
54300 + return 1;
54301 + }
54302 +#endif
54303 + return 0;
54304 +}
54305 +
54306 +EXPORT_SYMBOL(gr_pid_is_chrooted);
54307 +
54308 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
54309 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
54310 +{
54311 + struct path path, currentroot;
54312 + int ret = 0;
54313 +
54314 + path.dentry = (struct dentry *)u_dentry;
54315 + path.mnt = (struct vfsmount *)u_mnt;
54316 + get_fs_root(current->fs, &currentroot);
54317 + if (path_is_under(&path, &currentroot))
54318 + ret = 1;
54319 + path_put(&currentroot);
54320 +
54321 + return ret;
54322 +}
54323 +#endif
54324 +
54325 +int
54326 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
54327 +{
54328 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
54329 + if (!grsec_enable_chroot_fchdir)
54330 + return 1;
54331 +
54332 + if (!proc_is_chrooted(current))
54333 + return 1;
54334 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
54335 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
54336 + return 0;
54337 + }
54338 +#endif
54339 + return 1;
54340 +}
54341 +
54342 +int
54343 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54344 + const time_t shm_createtime)
54345 +{
54346 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
54347 + struct task_struct *p;
54348 + time_t starttime;
54349 +
54350 + if (unlikely(!grsec_enable_chroot_shmat))
54351 + return 1;
54352 +
54353 + if (likely(!proc_is_chrooted(current)))
54354 + return 1;
54355 +
54356 + rcu_read_lock();
54357 + read_lock(&tasklist_lock);
54358 +
54359 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
54360 + starttime = p->start_time.tv_sec;
54361 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
54362 + if (have_same_root(current, p)) {
54363 + goto allow;
54364 + } else {
54365 + read_unlock(&tasklist_lock);
54366 + rcu_read_unlock();
54367 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
54368 + return 0;
54369 + }
54370 + }
54371 + /* creator exited, pid reuse, fall through to next check */
54372 + }
54373 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
54374 + if (unlikely(!have_same_root(current, p))) {
54375 + read_unlock(&tasklist_lock);
54376 + rcu_read_unlock();
54377 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
54378 + return 0;
54379 + }
54380 + }
54381 +
54382 +allow:
54383 + read_unlock(&tasklist_lock);
54384 + rcu_read_unlock();
54385 +#endif
54386 + return 1;
54387 +}
54388 +
54389 +void
54390 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
54391 +{
54392 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
54393 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
54394 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
54395 +#endif
54396 + return;
54397 +}
54398 +
54399 +int
54400 +gr_handle_chroot_mknod(const struct dentry *dentry,
54401 + const struct vfsmount *mnt, const int mode)
54402 +{
54403 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
54404 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
54405 + proc_is_chrooted(current)) {
54406 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
54407 + return -EPERM;
54408 + }
54409 +#endif
54410 + return 0;
54411 +}
54412 +
54413 +int
54414 +gr_handle_chroot_mount(const struct dentry *dentry,
54415 + const struct vfsmount *mnt, const char *dev_name)
54416 +{
54417 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
54418 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
54419 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
54420 + return -EPERM;
54421 + }
54422 +#endif
54423 + return 0;
54424 +}
54425 +
54426 +int
54427 +gr_handle_chroot_pivot(void)
54428 +{
54429 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
54430 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
54431 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
54432 + return -EPERM;
54433 + }
54434 +#endif
54435 + return 0;
54436 +}
54437 +
54438 +int
54439 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
54440 +{
54441 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
54442 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
54443 + !gr_is_outside_chroot(dentry, mnt)) {
54444 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
54445 + return -EPERM;
54446 + }
54447 +#endif
54448 + return 0;
54449 +}
54450 +
54451 +extern const char *captab_log[];
54452 +extern int captab_log_entries;
54453 +
54454 +int
54455 +gr_chroot_is_capable(const int cap)
54456 +{
54457 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54458 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
54459 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
54460 + if (cap_raised(chroot_caps, cap)) {
54461 + const struct cred *creds = current_cred();
54462 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
54463 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
54464 + }
54465 + return 0;
54466 + }
54467 + }
54468 +#endif
54469 + return 1;
54470 +}
54471 +
54472 +int
54473 +gr_chroot_is_capable_nolog(const int cap)
54474 +{
54475 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54476 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
54477 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
54478 + if (cap_raised(chroot_caps, cap)) {
54479 + return 0;
54480 + }
54481 + }
54482 +#endif
54483 + return 1;
54484 +}
54485 +
54486 +int
54487 +gr_handle_chroot_sysctl(const int op)
54488 +{
54489 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
54490 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
54491 + proc_is_chrooted(current))
54492 + return -EACCES;
54493 +#endif
54494 + return 0;
54495 +}
54496 +
54497 +void
54498 +gr_handle_chroot_chdir(struct path *path)
54499 +{
54500 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
54501 + if (grsec_enable_chroot_chdir)
54502 + set_fs_pwd(current->fs, path);
54503 +#endif
54504 + return;
54505 +}
54506 +
54507 +int
54508 +gr_handle_chroot_chmod(const struct dentry *dentry,
54509 + const struct vfsmount *mnt, const int mode)
54510 +{
54511 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
54512 + /* allow chmod +s on directories, but not files */
54513 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
54514 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
54515 + proc_is_chrooted(current)) {
54516 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
54517 + return -EPERM;
54518 + }
54519 +#endif
54520 + return 0;
54521 +}
54522 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
54523 new file mode 100644
54524 index 0000000..d81a586
54525 --- /dev/null
54526 +++ b/grsecurity/grsec_disabled.c
54527 @@ -0,0 +1,439 @@
54528 +#include <linux/kernel.h>
54529 +#include <linux/module.h>
54530 +#include <linux/sched.h>
54531 +#include <linux/file.h>
54532 +#include <linux/fs.h>
54533 +#include <linux/kdev_t.h>
54534 +#include <linux/net.h>
54535 +#include <linux/in.h>
54536 +#include <linux/ip.h>
54537 +#include <linux/skbuff.h>
54538 +#include <linux/sysctl.h>
54539 +
54540 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54541 +void
54542 +pax_set_initial_flags(struct linux_binprm *bprm)
54543 +{
54544 + return;
54545 +}
54546 +#endif
54547 +
54548 +#ifdef CONFIG_SYSCTL
54549 +__u32
54550 +gr_handle_sysctl(const struct ctl_table * table, const int op)
54551 +{
54552 + return 0;
54553 +}
54554 +#endif
54555 +
54556 +#ifdef CONFIG_TASKSTATS
54557 +int gr_is_taskstats_denied(int pid)
54558 +{
54559 + return 0;
54560 +}
54561 +#endif
54562 +
54563 +int
54564 +gr_acl_is_enabled(void)
54565 +{
54566 + return 0;
54567 +}
54568 +
54569 +void
54570 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54571 +{
54572 + return;
54573 +}
54574 +
54575 +int
54576 +gr_handle_rawio(const struct inode *inode)
54577 +{
54578 + return 0;
54579 +}
54580 +
54581 +void
54582 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54583 +{
54584 + return;
54585 +}
54586 +
54587 +int
54588 +gr_handle_ptrace(struct task_struct *task, const long request)
54589 +{
54590 + return 0;
54591 +}
54592 +
54593 +int
54594 +gr_handle_proc_ptrace(struct task_struct *task)
54595 +{
54596 + return 0;
54597 +}
54598 +
54599 +void
54600 +gr_learn_resource(const struct task_struct *task,
54601 + const int res, const unsigned long wanted, const int gt)
54602 +{
54603 + return;
54604 +}
54605 +
54606 +int
54607 +gr_set_acls(const int type)
54608 +{
54609 + return 0;
54610 +}
54611 +
54612 +int
54613 +gr_check_hidden_task(const struct task_struct *tsk)
54614 +{
54615 + return 0;
54616 +}
54617 +
54618 +int
54619 +gr_check_protected_task(const struct task_struct *task)
54620 +{
54621 + return 0;
54622 +}
54623 +
54624 +int
54625 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54626 +{
54627 + return 0;
54628 +}
54629 +
54630 +void
54631 +gr_copy_label(struct task_struct *tsk)
54632 +{
54633 + return;
54634 +}
54635 +
54636 +void
54637 +gr_set_pax_flags(struct task_struct *task)
54638 +{
54639 + return;
54640 +}
54641 +
54642 +int
54643 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54644 + const int unsafe_share)
54645 +{
54646 + return 0;
54647 +}
54648 +
54649 +void
54650 +gr_handle_delete(const ino_t ino, const dev_t dev)
54651 +{
54652 + return;
54653 +}
54654 +
54655 +void
54656 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54657 +{
54658 + return;
54659 +}
54660 +
54661 +void
54662 +gr_handle_crash(struct task_struct *task, const int sig)
54663 +{
54664 + return;
54665 +}
54666 +
54667 +int
54668 +gr_check_crash_exec(const struct file *filp)
54669 +{
54670 + return 0;
54671 +}
54672 +
54673 +int
54674 +gr_check_crash_uid(const uid_t uid)
54675 +{
54676 + return 0;
54677 +}
54678 +
54679 +void
54680 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54681 + struct dentry *old_dentry,
54682 + struct dentry *new_dentry,
54683 + struct vfsmount *mnt, const __u8 replace)
54684 +{
54685 + return;
54686 +}
54687 +
54688 +int
54689 +gr_search_socket(const int family, const int type, const int protocol)
54690 +{
54691 + return 1;
54692 +}
54693 +
54694 +int
54695 +gr_search_connectbind(const int mode, const struct socket *sock,
54696 + const struct sockaddr_in *addr)
54697 +{
54698 + return 0;
54699 +}
54700 +
54701 +void
54702 +gr_handle_alertkill(struct task_struct *task)
54703 +{
54704 + return;
54705 +}
54706 +
54707 +__u32
54708 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
54709 +{
54710 + return 1;
54711 +}
54712 +
54713 +__u32
54714 +gr_acl_handle_hidden_file(const struct dentry * dentry,
54715 + const struct vfsmount * mnt)
54716 +{
54717 + return 1;
54718 +}
54719 +
54720 +__u32
54721 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54722 + int acc_mode)
54723 +{
54724 + return 1;
54725 +}
54726 +
54727 +__u32
54728 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54729 +{
54730 + return 1;
54731 +}
54732 +
54733 +__u32
54734 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
54735 +{
54736 + return 1;
54737 +}
54738 +
54739 +int
54740 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
54741 + unsigned int *vm_flags)
54742 +{
54743 + return 1;
54744 +}
54745 +
54746 +__u32
54747 +gr_acl_handle_truncate(const struct dentry * dentry,
54748 + const struct vfsmount * mnt)
54749 +{
54750 + return 1;
54751 +}
54752 +
54753 +__u32
54754 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
54755 +{
54756 + return 1;
54757 +}
54758 +
54759 +__u32
54760 +gr_acl_handle_access(const struct dentry * dentry,
54761 + const struct vfsmount * mnt, const int fmode)
54762 +{
54763 + return 1;
54764 +}
54765 +
54766 +__u32
54767 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
54768 + mode_t mode)
54769 +{
54770 + return 1;
54771 +}
54772 +
54773 +__u32
54774 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
54775 + mode_t mode)
54776 +{
54777 + return 1;
54778 +}
54779 +
54780 +__u32
54781 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
54782 +{
54783 + return 1;
54784 +}
54785 +
54786 +__u32
54787 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
54788 +{
54789 + return 1;
54790 +}
54791 +
54792 +void
54793 +grsecurity_init(void)
54794 +{
54795 + return;
54796 +}
54797 +
54798 +__u32
54799 +gr_acl_handle_mknod(const struct dentry * new_dentry,
54800 + const struct dentry * parent_dentry,
54801 + const struct vfsmount * parent_mnt,
54802 + const int mode)
54803 +{
54804 + return 1;
54805 +}
54806 +
54807 +__u32
54808 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
54809 + const struct dentry * parent_dentry,
54810 + const struct vfsmount * parent_mnt)
54811 +{
54812 + return 1;
54813 +}
54814 +
54815 +__u32
54816 +gr_acl_handle_symlink(const struct dentry * new_dentry,
54817 + const struct dentry * parent_dentry,
54818 + const struct vfsmount * parent_mnt, const char *from)
54819 +{
54820 + return 1;
54821 +}
54822 +
54823 +__u32
54824 +gr_acl_handle_link(const struct dentry * new_dentry,
54825 + const struct dentry * parent_dentry,
54826 + const struct vfsmount * parent_mnt,
54827 + const struct dentry * old_dentry,
54828 + const struct vfsmount * old_mnt, const char *to)
54829 +{
54830 + return 1;
54831 +}
54832 +
54833 +int
54834 +gr_acl_handle_rename(const struct dentry *new_dentry,
54835 + const struct dentry *parent_dentry,
54836 + const struct vfsmount *parent_mnt,
54837 + const struct dentry *old_dentry,
54838 + const struct inode *old_parent_inode,
54839 + const struct vfsmount *old_mnt, const char *newname)
54840 +{
54841 + return 0;
54842 +}
54843 +
54844 +int
54845 +gr_acl_handle_filldir(const struct file *file, const char *name,
54846 + const int namelen, const ino_t ino)
54847 +{
54848 + return 1;
54849 +}
54850 +
54851 +int
54852 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54853 + const time_t shm_createtime, const uid_t cuid, const int shmid)
54854 +{
54855 + return 1;
54856 +}
54857 +
54858 +int
54859 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
54860 +{
54861 + return 0;
54862 +}
54863 +
54864 +int
54865 +gr_search_accept(const struct socket *sock)
54866 +{
54867 + return 0;
54868 +}
54869 +
54870 +int
54871 +gr_search_listen(const struct socket *sock)
54872 +{
54873 + return 0;
54874 +}
54875 +
54876 +int
54877 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
54878 +{
54879 + return 0;
54880 +}
54881 +
54882 +__u32
54883 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
54884 +{
54885 + return 1;
54886 +}
54887 +
54888 +__u32
54889 +gr_acl_handle_creat(const struct dentry * dentry,
54890 + const struct dentry * p_dentry,
54891 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54892 + const int imode)
54893 +{
54894 + return 1;
54895 +}
54896 +
54897 +void
54898 +gr_acl_handle_exit(void)
54899 +{
54900 + return;
54901 +}
54902 +
54903 +int
54904 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54905 +{
54906 + return 1;
54907 +}
54908 +
54909 +void
54910 +gr_set_role_label(const uid_t uid, const gid_t gid)
54911 +{
54912 + return;
54913 +}
54914 +
54915 +int
54916 +gr_acl_handle_procpidmem(const struct task_struct *task)
54917 +{
54918 + return 0;
54919 +}
54920 +
54921 +int
54922 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
54923 +{
54924 + return 0;
54925 +}
54926 +
54927 +int
54928 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
54929 +{
54930 + return 0;
54931 +}
54932 +
54933 +void
54934 +gr_set_kernel_label(struct task_struct *task)
54935 +{
54936 + return;
54937 +}
54938 +
54939 +int
54940 +gr_check_user_change(int real, int effective, int fs)
54941 +{
54942 + return 0;
54943 +}
54944 +
54945 +int
54946 +gr_check_group_change(int real, int effective, int fs)
54947 +{
54948 + return 0;
54949 +}
54950 +
54951 +int gr_acl_enable_at_secure(void)
54952 +{
54953 + return 0;
54954 +}
54955 +
54956 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
54957 +{
54958 + return dentry->d_inode->i_sb->s_dev;
54959 +}
54960 +
54961 +EXPORT_SYMBOL(gr_learn_resource);
54962 +EXPORT_SYMBOL(gr_set_kernel_label);
54963 +#ifdef CONFIG_SECURITY
54964 +EXPORT_SYMBOL(gr_check_user_change);
54965 +EXPORT_SYMBOL(gr_check_group_change);
54966 +#endif
54967 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
54968 new file mode 100644
54969 index 0000000..2b05ada
54970 --- /dev/null
54971 +++ b/grsecurity/grsec_exec.c
54972 @@ -0,0 +1,146 @@
54973 +#include <linux/kernel.h>
54974 +#include <linux/sched.h>
54975 +#include <linux/file.h>
54976 +#include <linux/binfmts.h>
54977 +#include <linux/fs.h>
54978 +#include <linux/types.h>
54979 +#include <linux/grdefs.h>
54980 +#include <linux/grsecurity.h>
54981 +#include <linux/grinternal.h>
54982 +#include <linux/capability.h>
54983 +#include <linux/module.h>
54984 +
54985 +#include <asm/uaccess.h>
54986 +
54987 +#ifdef CONFIG_GRKERNSEC_EXECLOG
54988 +static char gr_exec_arg_buf[132];
54989 +static DEFINE_MUTEX(gr_exec_arg_mutex);
54990 +#endif
54991 +
54992 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
54993 +
54994 +void
54995 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
54996 +{
54997 +#ifdef CONFIG_GRKERNSEC_EXECLOG
54998 + char *grarg = gr_exec_arg_buf;
54999 + unsigned int i, x, execlen = 0;
55000 + char c;
55001 +
55002 + if (!((grsec_enable_execlog && grsec_enable_group &&
55003 + in_group_p(grsec_audit_gid))
55004 + || (grsec_enable_execlog && !grsec_enable_group)))
55005 + return;
55006 +
55007 + mutex_lock(&gr_exec_arg_mutex);
55008 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
55009 +
55010 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
55011 + const char __user *p;
55012 + unsigned int len;
55013 +
55014 + p = get_user_arg_ptr(argv, i);
55015 + if (IS_ERR(p))
55016 + goto log;
55017 +
55018 + len = strnlen_user(p, 128 - execlen);
55019 + if (len > 128 - execlen)
55020 + len = 128 - execlen;
55021 + else if (len > 0)
55022 + len--;
55023 + if (copy_from_user(grarg + execlen, p, len))
55024 + goto log;
55025 +
55026 + /* rewrite unprintable characters */
55027 + for (x = 0; x < len; x++) {
55028 + c = *(grarg + execlen + x);
55029 + if (c < 32 || c > 126)
55030 + *(grarg + execlen + x) = ' ';
55031 + }
55032 +
55033 + execlen += len;
55034 + *(grarg + execlen) = ' ';
55035 + *(grarg + execlen + 1) = '\0';
55036 + execlen++;
55037 + }
55038 +
55039 + log:
55040 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
55041 + bprm->file->f_path.mnt, grarg);
55042 + mutex_unlock(&gr_exec_arg_mutex);
55043 +#endif
55044 + return;
55045 +}
55046 +
55047 +#ifdef CONFIG_GRKERNSEC
55048 +extern int gr_acl_is_capable(const int cap);
55049 +extern int gr_acl_is_capable_nolog(const int cap);
55050 +extern int gr_chroot_is_capable(const int cap);
55051 +extern int gr_chroot_is_capable_nolog(const int cap);
55052 +#endif
55053 +
55054 +const char *captab_log[] = {
55055 + "CAP_CHOWN",
55056 + "CAP_DAC_OVERRIDE",
55057 + "CAP_DAC_READ_SEARCH",
55058 + "CAP_FOWNER",
55059 + "CAP_FSETID",
55060 + "CAP_KILL",
55061 + "CAP_SETGID",
55062 + "CAP_SETUID",
55063 + "CAP_SETPCAP",
55064 + "CAP_LINUX_IMMUTABLE",
55065 + "CAP_NET_BIND_SERVICE",
55066 + "CAP_NET_BROADCAST",
55067 + "CAP_NET_ADMIN",
55068 + "CAP_NET_RAW",
55069 + "CAP_IPC_LOCK",
55070 + "CAP_IPC_OWNER",
55071 + "CAP_SYS_MODULE",
55072 + "CAP_SYS_RAWIO",
55073 + "CAP_SYS_CHROOT",
55074 + "CAP_SYS_PTRACE",
55075 + "CAP_SYS_PACCT",
55076 + "CAP_SYS_ADMIN",
55077 + "CAP_SYS_BOOT",
55078 + "CAP_SYS_NICE",
55079 + "CAP_SYS_RESOURCE",
55080 + "CAP_SYS_TIME",
55081 + "CAP_SYS_TTY_CONFIG",
55082 + "CAP_MKNOD",
55083 + "CAP_LEASE",
55084 + "CAP_AUDIT_WRITE",
55085 + "CAP_AUDIT_CONTROL",
55086 + "CAP_SETFCAP",
55087 + "CAP_MAC_OVERRIDE",
55088 + "CAP_MAC_ADMIN",
55089 + "CAP_SYSLOG",
55090 + "CAP_WAKE_ALARM"
55091 +};
55092 +
55093 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
55094 +
55095 +int gr_is_capable(const int cap)
55096 +{
55097 +#ifdef CONFIG_GRKERNSEC
55098 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
55099 + return 1;
55100 + return 0;
55101 +#else
55102 + return 1;
55103 +#endif
55104 +}
55105 +
55106 +int gr_is_capable_nolog(const int cap)
55107 +{
55108 +#ifdef CONFIG_GRKERNSEC
55109 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
55110 + return 1;
55111 + return 0;
55112 +#else
55113 + return 1;
55114 +#endif
55115 +}
55116 +
55117 +EXPORT_SYMBOL(gr_is_capable);
55118 +EXPORT_SYMBOL(gr_is_capable_nolog);
55119 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
55120 new file mode 100644
55121 index 0000000..d3ee748
55122 --- /dev/null
55123 +++ b/grsecurity/grsec_fifo.c
55124 @@ -0,0 +1,24 @@
55125 +#include <linux/kernel.h>
55126 +#include <linux/sched.h>
55127 +#include <linux/fs.h>
55128 +#include <linux/file.h>
55129 +#include <linux/grinternal.h>
55130 +
55131 +int
55132 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
55133 + const struct dentry *dir, const int flag, const int acc_mode)
55134 +{
55135 +#ifdef CONFIG_GRKERNSEC_FIFO
55136 + const struct cred *cred = current_cred();
55137 +
55138 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
55139 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
55140 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
55141 + (cred->fsuid != dentry->d_inode->i_uid)) {
55142 + if (!inode_permission(dentry->d_inode, acc_mode))
55143 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
55144 + return -EACCES;
55145 + }
55146 +#endif
55147 + return 0;
55148 +}
55149 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
55150 new file mode 100644
55151 index 0000000..8ca18bf
55152 --- /dev/null
55153 +++ b/grsecurity/grsec_fork.c
55154 @@ -0,0 +1,23 @@
55155 +#include <linux/kernel.h>
55156 +#include <linux/sched.h>
55157 +#include <linux/grsecurity.h>
55158 +#include <linux/grinternal.h>
55159 +#include <linux/errno.h>
55160 +
55161 +void
55162 +gr_log_forkfail(const int retval)
55163 +{
55164 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
55165 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
55166 + switch (retval) {
55167 + case -EAGAIN:
55168 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
55169 + break;
55170 + case -ENOMEM:
55171 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
55172 + break;
55173 + }
55174 + }
55175 +#endif
55176 + return;
55177 +}
55178 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
55179 new file mode 100644
55180 index 0000000..01ddde4
55181 --- /dev/null
55182 +++ b/grsecurity/grsec_init.c
55183 @@ -0,0 +1,277 @@
55184 +#include <linux/kernel.h>
55185 +#include <linux/sched.h>
55186 +#include <linux/mm.h>
55187 +#include <linux/gracl.h>
55188 +#include <linux/slab.h>
55189 +#include <linux/vmalloc.h>
55190 +#include <linux/percpu.h>
55191 +#include <linux/module.h>
55192 +
55193 +int grsec_enable_ptrace_readexec;
55194 +int grsec_enable_setxid;
55195 +int grsec_enable_brute;
55196 +int grsec_enable_link;
55197 +int grsec_enable_dmesg;
55198 +int grsec_enable_harden_ptrace;
55199 +int grsec_enable_fifo;
55200 +int grsec_enable_execlog;
55201 +int grsec_enable_signal;
55202 +int grsec_enable_forkfail;
55203 +int grsec_enable_audit_ptrace;
55204 +int grsec_enable_time;
55205 +int grsec_enable_audit_textrel;
55206 +int grsec_enable_group;
55207 +int grsec_audit_gid;
55208 +int grsec_enable_chdir;
55209 +int grsec_enable_mount;
55210 +int grsec_enable_rofs;
55211 +int grsec_enable_chroot_findtask;
55212 +int grsec_enable_chroot_mount;
55213 +int grsec_enable_chroot_shmat;
55214 +int grsec_enable_chroot_fchdir;
55215 +int grsec_enable_chroot_double;
55216 +int grsec_enable_chroot_pivot;
55217 +int grsec_enable_chroot_chdir;
55218 +int grsec_enable_chroot_chmod;
55219 +int grsec_enable_chroot_mknod;
55220 +int grsec_enable_chroot_nice;
55221 +int grsec_enable_chroot_execlog;
55222 +int grsec_enable_chroot_caps;
55223 +int grsec_enable_chroot_sysctl;
55224 +int grsec_enable_chroot_unix;
55225 +int grsec_enable_tpe;
55226 +int grsec_tpe_gid;
55227 +int grsec_enable_blackhole;
55228 +#ifdef CONFIG_IPV6_MODULE
55229 +EXPORT_SYMBOL(grsec_enable_blackhole);
55230 +#endif
55231 +int grsec_lastack_retries;
55232 +int grsec_enable_tpe_all;
55233 +int grsec_enable_tpe_invert;
55234 +int grsec_enable_socket_all;
55235 +int grsec_socket_all_gid;
55236 +int grsec_enable_socket_client;
55237 +int grsec_socket_client_gid;
55238 +int grsec_enable_socket_server;
55239 +int grsec_socket_server_gid;
55240 +int grsec_resource_logging;
55241 +int grsec_disable_privio;
55242 +int grsec_enable_log_rwxmaps;
55243 +int grsec_lock;
55244 +
55245 +DEFINE_SPINLOCK(grsec_alert_lock);
55246 +unsigned long grsec_alert_wtime = 0;
55247 +unsigned long grsec_alert_fyet = 0;
55248 +
55249 +DEFINE_SPINLOCK(grsec_audit_lock);
55250 +
55251 +DEFINE_RWLOCK(grsec_exec_file_lock);
55252 +
55253 +char *gr_shared_page[4];
55254 +
55255 +char *gr_alert_log_fmt;
55256 +char *gr_audit_log_fmt;
55257 +char *gr_alert_log_buf;
55258 +char *gr_audit_log_buf;
55259 +
55260 +extern struct gr_arg *gr_usermode;
55261 +extern unsigned char *gr_system_salt;
55262 +extern unsigned char *gr_system_sum;
55263 +
55264 +void __init
55265 +grsecurity_init(void)
55266 +{
55267 + int j;
55268 + /* create the per-cpu shared pages */
55269 +
55270 +#ifdef CONFIG_X86
55271 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
55272 +#endif
55273 +
55274 + for (j = 0; j < 4; j++) {
55275 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
55276 + if (gr_shared_page[j] == NULL) {
55277 + panic("Unable to allocate grsecurity shared page");
55278 + return;
55279 + }
55280 + }
55281 +
55282 + /* allocate log buffers */
55283 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
55284 + if (!gr_alert_log_fmt) {
55285 + panic("Unable to allocate grsecurity alert log format buffer");
55286 + return;
55287 + }
55288 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
55289 + if (!gr_audit_log_fmt) {
55290 + panic("Unable to allocate grsecurity audit log format buffer");
55291 + return;
55292 + }
55293 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
55294 + if (!gr_alert_log_buf) {
55295 + panic("Unable to allocate grsecurity alert log buffer");
55296 + return;
55297 + }
55298 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
55299 + if (!gr_audit_log_buf) {
55300 + panic("Unable to allocate grsecurity audit log buffer");
55301 + return;
55302 + }
55303 +
55304 + /* allocate memory for authentication structure */
55305 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
55306 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
55307 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
55308 +
55309 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
55310 + panic("Unable to allocate grsecurity authentication structure");
55311 + return;
55312 + }
55313 +
55314 +
55315 +#ifdef CONFIG_GRKERNSEC_IO
55316 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
55317 + grsec_disable_privio = 1;
55318 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
55319 + grsec_disable_privio = 1;
55320 +#else
55321 + grsec_disable_privio = 0;
55322 +#endif
55323 +#endif
55324 +
55325 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
55326 + /* for backward compatibility, tpe_invert always defaults to on if
55327 + enabled in the kernel
55328 + */
55329 + grsec_enable_tpe_invert = 1;
55330 +#endif
55331 +
55332 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
55333 +#ifndef CONFIG_GRKERNSEC_SYSCTL
55334 + grsec_lock = 1;
55335 +#endif
55336 +
55337 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
55338 + grsec_enable_audit_textrel = 1;
55339 +#endif
55340 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55341 + grsec_enable_log_rwxmaps = 1;
55342 +#endif
55343 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
55344 + grsec_enable_group = 1;
55345 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
55346 +#endif
55347 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
55348 + grsec_enable_ptrace_readexec = 1;
55349 +#endif
55350 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55351 + grsec_enable_chdir = 1;
55352 +#endif
55353 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55354 + grsec_enable_harden_ptrace = 1;
55355 +#endif
55356 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55357 + grsec_enable_mount = 1;
55358 +#endif
55359 +#ifdef CONFIG_GRKERNSEC_LINK
55360 + grsec_enable_link = 1;
55361 +#endif
55362 +#ifdef CONFIG_GRKERNSEC_BRUTE
55363 + grsec_enable_brute = 1;
55364 +#endif
55365 +#ifdef CONFIG_GRKERNSEC_DMESG
55366 + grsec_enable_dmesg = 1;
55367 +#endif
55368 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
55369 + grsec_enable_blackhole = 1;
55370 + grsec_lastack_retries = 4;
55371 +#endif
55372 +#ifdef CONFIG_GRKERNSEC_FIFO
55373 + grsec_enable_fifo = 1;
55374 +#endif
55375 +#ifdef CONFIG_GRKERNSEC_EXECLOG
55376 + grsec_enable_execlog = 1;
55377 +#endif
55378 +#ifdef CONFIG_GRKERNSEC_SETXID
55379 + grsec_enable_setxid = 1;
55380 +#endif
55381 +#ifdef CONFIG_GRKERNSEC_SIGNAL
55382 + grsec_enable_signal = 1;
55383 +#endif
55384 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
55385 + grsec_enable_forkfail = 1;
55386 +#endif
55387 +#ifdef CONFIG_GRKERNSEC_TIME
55388 + grsec_enable_time = 1;
55389 +#endif
55390 +#ifdef CONFIG_GRKERNSEC_RESLOG
55391 + grsec_resource_logging = 1;
55392 +#endif
55393 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55394 + grsec_enable_chroot_findtask = 1;
55395 +#endif
55396 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55397 + grsec_enable_chroot_unix = 1;
55398 +#endif
55399 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
55400 + grsec_enable_chroot_mount = 1;
55401 +#endif
55402 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
55403 + grsec_enable_chroot_fchdir = 1;
55404 +#endif
55405 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
55406 + grsec_enable_chroot_shmat = 1;
55407 +#endif
55408 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
55409 + grsec_enable_audit_ptrace = 1;
55410 +#endif
55411 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
55412 + grsec_enable_chroot_double = 1;
55413 +#endif
55414 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
55415 + grsec_enable_chroot_pivot = 1;
55416 +#endif
55417 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
55418 + grsec_enable_chroot_chdir = 1;
55419 +#endif
55420 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
55421 + grsec_enable_chroot_chmod = 1;
55422 +#endif
55423 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
55424 + grsec_enable_chroot_mknod = 1;
55425 +#endif
55426 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55427 + grsec_enable_chroot_nice = 1;
55428 +#endif
55429 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
55430 + grsec_enable_chroot_execlog = 1;
55431 +#endif
55432 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55433 + grsec_enable_chroot_caps = 1;
55434 +#endif
55435 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
55436 + grsec_enable_chroot_sysctl = 1;
55437 +#endif
55438 +#ifdef CONFIG_GRKERNSEC_TPE
55439 + grsec_enable_tpe = 1;
55440 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
55441 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
55442 + grsec_enable_tpe_all = 1;
55443 +#endif
55444 +#endif
55445 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
55446 + grsec_enable_socket_all = 1;
55447 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
55448 +#endif
55449 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
55450 + grsec_enable_socket_client = 1;
55451 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
55452 +#endif
55453 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
55454 + grsec_enable_socket_server = 1;
55455 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
55456 +#endif
55457 +#endif
55458 +
55459 + return;
55460 +}
55461 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
55462 new file mode 100644
55463 index 0000000..3efe141
55464 --- /dev/null
55465 +++ b/grsecurity/grsec_link.c
55466 @@ -0,0 +1,43 @@
55467 +#include <linux/kernel.h>
55468 +#include <linux/sched.h>
55469 +#include <linux/fs.h>
55470 +#include <linux/file.h>
55471 +#include <linux/grinternal.h>
55472 +
55473 +int
55474 +gr_handle_follow_link(const struct inode *parent,
55475 + const struct inode *inode,
55476 + const struct dentry *dentry, const struct vfsmount *mnt)
55477 +{
55478 +#ifdef CONFIG_GRKERNSEC_LINK
55479 + const struct cred *cred = current_cred();
55480 +
55481 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
55482 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
55483 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
55484 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
55485 + return -EACCES;
55486 + }
55487 +#endif
55488 + return 0;
55489 +}
55490 +
55491 +int
55492 +gr_handle_hardlink(const struct dentry *dentry,
55493 + const struct vfsmount *mnt,
55494 + struct inode *inode, const int mode, const char *to)
55495 +{
55496 +#ifdef CONFIG_GRKERNSEC_LINK
55497 + const struct cred *cred = current_cred();
55498 +
55499 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
55500 + (!S_ISREG(mode) || (mode & S_ISUID) ||
55501 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
55502 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
55503 + !capable(CAP_FOWNER) && cred->uid) {
55504 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
55505 + return -EPERM;
55506 + }
55507 +#endif
55508 + return 0;
55509 +}
55510 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
55511 new file mode 100644
55512 index 0000000..a45d2e9
55513 --- /dev/null
55514 +++ b/grsecurity/grsec_log.c
55515 @@ -0,0 +1,322 @@
55516 +#include <linux/kernel.h>
55517 +#include <linux/sched.h>
55518 +#include <linux/file.h>
55519 +#include <linux/tty.h>
55520 +#include <linux/fs.h>
55521 +#include <linux/grinternal.h>
55522 +
55523 +#ifdef CONFIG_TREE_PREEMPT_RCU
55524 +#define DISABLE_PREEMPT() preempt_disable()
55525 +#define ENABLE_PREEMPT() preempt_enable()
55526 +#else
55527 +#define DISABLE_PREEMPT()
55528 +#define ENABLE_PREEMPT()
55529 +#endif
55530 +
55531 +#define BEGIN_LOCKS(x) \
55532 + DISABLE_PREEMPT(); \
55533 + rcu_read_lock(); \
55534 + read_lock(&tasklist_lock); \
55535 + read_lock(&grsec_exec_file_lock); \
55536 + if (x != GR_DO_AUDIT) \
55537 + spin_lock(&grsec_alert_lock); \
55538 + else \
55539 + spin_lock(&grsec_audit_lock)
55540 +
55541 +#define END_LOCKS(x) \
55542 + if (x != GR_DO_AUDIT) \
55543 + spin_unlock(&grsec_alert_lock); \
55544 + else \
55545 + spin_unlock(&grsec_audit_lock); \
55546 + read_unlock(&grsec_exec_file_lock); \
55547 + read_unlock(&tasklist_lock); \
55548 + rcu_read_unlock(); \
55549 + ENABLE_PREEMPT(); \
55550 + if (x == GR_DONT_AUDIT) \
55551 + gr_handle_alertkill(current)
55552 +
55553 +enum {
55554 + FLOODING,
55555 + NO_FLOODING
55556 +};
55557 +
55558 +extern char *gr_alert_log_fmt;
55559 +extern char *gr_audit_log_fmt;
55560 +extern char *gr_alert_log_buf;
55561 +extern char *gr_audit_log_buf;
55562 +
55563 +static int gr_log_start(int audit)
55564 +{
55565 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
55566 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
55567 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55568 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
55569 + unsigned long curr_secs = get_seconds();
55570 +
55571 + if (audit == GR_DO_AUDIT)
55572 + goto set_fmt;
55573 +
55574 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
55575 + grsec_alert_wtime = curr_secs;
55576 + grsec_alert_fyet = 0;
55577 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
55578 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
55579 + grsec_alert_fyet++;
55580 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
55581 + grsec_alert_wtime = curr_secs;
55582 + grsec_alert_fyet++;
55583 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
55584 + return FLOODING;
55585 + }
55586 + else return FLOODING;
55587 +
55588 +set_fmt:
55589 +#endif
55590 + memset(buf, 0, PAGE_SIZE);
55591 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
55592 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
55593 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
55594 + } else if (current->signal->curr_ip) {
55595 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
55596 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
55597 + } else if (gr_acl_is_enabled()) {
55598 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
55599 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
55600 + } else {
55601 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
55602 + strcpy(buf, fmt);
55603 + }
55604 +
55605 + return NO_FLOODING;
55606 +}
55607 +
55608 +static void gr_log_middle(int audit, const char *msg, va_list ap)
55609 + __attribute__ ((format (printf, 2, 0)));
55610 +
55611 +static void gr_log_middle(int audit, const char *msg, va_list ap)
55612 +{
55613 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55614 + unsigned int len = strlen(buf);
55615 +
55616 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
55617 +
55618 + return;
55619 +}
55620 +
55621 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
55622 + __attribute__ ((format (printf, 2, 3)));
55623 +
55624 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
55625 +{
55626 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55627 + unsigned int len = strlen(buf);
55628 + va_list ap;
55629 +
55630 + va_start(ap, msg);
55631 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
55632 + va_end(ap);
55633 +
55634 + return;
55635 +}
55636 +
55637 +static void gr_log_end(int audit, int append_default)
55638 +{
55639 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55640 +
55641 + if (append_default) {
55642 + unsigned int len = strlen(buf);
55643 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
55644 + }
55645 +
55646 + printk("%s\n", buf);
55647 +
55648 + return;
55649 +}
55650 +
55651 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
55652 +{
55653 + int logtype;
55654 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
55655 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
55656 + void *voidptr = NULL;
55657 + int num1 = 0, num2 = 0;
55658 + unsigned long ulong1 = 0, ulong2 = 0;
55659 + struct dentry *dentry = NULL;
55660 + struct vfsmount *mnt = NULL;
55661 + struct file *file = NULL;
55662 + struct task_struct *task = NULL;
55663 + const struct cred *cred, *pcred;
55664 + va_list ap;
55665 +
55666 + BEGIN_LOCKS(audit);
55667 + logtype = gr_log_start(audit);
55668 + if (logtype == FLOODING) {
55669 + END_LOCKS(audit);
55670 + return;
55671 + }
55672 + va_start(ap, argtypes);
55673 + switch (argtypes) {
55674 + case GR_TTYSNIFF:
55675 + task = va_arg(ap, struct task_struct *);
55676 + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid);
55677 + break;
55678 + case GR_SYSCTL_HIDDEN:
55679 + str1 = va_arg(ap, char *);
55680 + gr_log_middle_varargs(audit, msg, result, str1);
55681 + break;
55682 + case GR_RBAC:
55683 + dentry = va_arg(ap, struct dentry *);
55684 + mnt = va_arg(ap, struct vfsmount *);
55685 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
55686 + break;
55687 + case GR_RBAC_STR:
55688 + dentry = va_arg(ap, struct dentry *);
55689 + mnt = va_arg(ap, struct vfsmount *);
55690 + str1 = va_arg(ap, char *);
55691 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
55692 + break;
55693 + case GR_STR_RBAC:
55694 + str1 = va_arg(ap, char *);
55695 + dentry = va_arg(ap, struct dentry *);
55696 + mnt = va_arg(ap, struct vfsmount *);
55697 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
55698 + break;
55699 + case GR_RBAC_MODE2:
55700 + dentry = va_arg(ap, struct dentry *);
55701 + mnt = va_arg(ap, struct vfsmount *);
55702 + str1 = va_arg(ap, char *);
55703 + str2 = va_arg(ap, char *);
55704 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
55705 + break;
55706 + case GR_RBAC_MODE3:
55707 + dentry = va_arg(ap, struct dentry *);
55708 + mnt = va_arg(ap, struct vfsmount *);
55709 + str1 = va_arg(ap, char *);
55710 + str2 = va_arg(ap, char *);
55711 + str3 = va_arg(ap, char *);
55712 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
55713 + break;
55714 + case GR_FILENAME:
55715 + dentry = va_arg(ap, struct dentry *);
55716 + mnt = va_arg(ap, struct vfsmount *);
55717 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
55718 + break;
55719 + case GR_STR_FILENAME:
55720 + str1 = va_arg(ap, char *);
55721 + dentry = va_arg(ap, struct dentry *);
55722 + mnt = va_arg(ap, struct vfsmount *);
55723 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
55724 + break;
55725 + case GR_FILENAME_STR:
55726 + dentry = va_arg(ap, struct dentry *);
55727 + mnt = va_arg(ap, struct vfsmount *);
55728 + str1 = va_arg(ap, char *);
55729 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
55730 + break;
55731 + case GR_FILENAME_TWO_INT:
55732 + dentry = va_arg(ap, struct dentry *);
55733 + mnt = va_arg(ap, struct vfsmount *);
55734 + num1 = va_arg(ap, int);
55735 + num2 = va_arg(ap, int);
55736 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
55737 + break;
55738 + case GR_FILENAME_TWO_INT_STR:
55739 + dentry = va_arg(ap, struct dentry *);
55740 + mnt = va_arg(ap, struct vfsmount *);
55741 + num1 = va_arg(ap, int);
55742 + num2 = va_arg(ap, int);
55743 + str1 = va_arg(ap, char *);
55744 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
55745 + break;
55746 + case GR_TEXTREL:
55747 + file = va_arg(ap, struct file *);
55748 + ulong1 = va_arg(ap, unsigned long);
55749 + ulong2 = va_arg(ap, unsigned long);
55750 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
55751 + break;
55752 + case GR_PTRACE:
55753 + task = va_arg(ap, struct task_struct *);
55754 + gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task->pid);
55755 + break;
55756 + case GR_RESOURCE:
55757 + task = va_arg(ap, struct task_struct *);
55758 + cred = __task_cred(task);
55759 + pcred = __task_cred(task->real_parent);
55760 + ulong1 = va_arg(ap, unsigned long);
55761 + str1 = va_arg(ap, char *);
55762 + ulong2 = va_arg(ap, unsigned long);
55763 + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
55764 + break;
55765 + case GR_CAP:
55766 + task = va_arg(ap, struct task_struct *);
55767 + cred = __task_cred(task);
55768 + pcred = __task_cred(task->real_parent);
55769 + str1 = va_arg(ap, char *);
55770 + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
55771 + break;
55772 + case GR_SIG:
55773 + str1 = va_arg(ap, char *);
55774 + voidptr = va_arg(ap, void *);
55775 + gr_log_middle_varargs(audit, msg, str1, voidptr);
55776 + break;
55777 + case GR_SIG2:
55778 + task = va_arg(ap, struct task_struct *);
55779 + cred = __task_cred(task);
55780 + pcred = __task_cred(task->real_parent);
55781 + num1 = va_arg(ap, int);
55782 + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
55783 + break;
55784 + case GR_CRASH1:
55785 + task = va_arg(ap, struct task_struct *);
55786 + cred = __task_cred(task);
55787 + pcred = __task_cred(task->real_parent);
55788 + ulong1 = va_arg(ap, unsigned long);
55789 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1);
55790 + break;
55791 + case GR_CRASH2:
55792 + task = va_arg(ap, struct task_struct *);
55793 + cred = __task_cred(task);
55794 + pcred = __task_cred(task->real_parent);
55795 + ulong1 = va_arg(ap, unsigned long);
55796 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1);
55797 + break;
55798 + case GR_RWXMAP:
55799 + file = va_arg(ap, struct file *);
55800 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
55801 + break;
55802 + case GR_PSACCT:
55803 + {
55804 + unsigned int wday, cday;
55805 + __u8 whr, chr;
55806 + __u8 wmin, cmin;
55807 + __u8 wsec, csec;
55808 + char cur_tty[64] = { 0 };
55809 + char parent_tty[64] = { 0 };
55810 +
55811 + task = va_arg(ap, struct task_struct *);
55812 + wday = va_arg(ap, unsigned int);
55813 + cday = va_arg(ap, unsigned int);
55814 + whr = va_arg(ap, int);
55815 + chr = va_arg(ap, int);
55816 + wmin = va_arg(ap, int);
55817 + cmin = va_arg(ap, int);
55818 + wsec = va_arg(ap, int);
55819 + csec = va_arg(ap, int);
55820 + ulong1 = va_arg(ap, unsigned long);
55821 + cred = __task_cred(task);
55822 + pcred = __task_cred(task->real_parent);
55823 +
55824 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), cred->uid, cred->euid, cred->gid, cred->egid, wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid);
55825 + }
55826 + break;
55827 + default:
55828 + gr_log_middle(audit, msg, ap);
55829 + }
55830 + va_end(ap);
55831 + // these don't need DEFAULTSECARGS printed on the end
55832 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
55833 + gr_log_end(audit, 0);
55834 + else
55835 + gr_log_end(audit, 1);
55836 + END_LOCKS(audit);
55837 +}
55838 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
55839 new file mode 100644
55840 index 0000000..6c0416b
55841 --- /dev/null
55842 +++ b/grsecurity/grsec_mem.c
55843 @@ -0,0 +1,33 @@
55844 +#include <linux/kernel.h>
55845 +#include <linux/sched.h>
55846 +#include <linux/mm.h>
55847 +#include <linux/mman.h>
55848 +#include <linux/grinternal.h>
55849 +
55850 +void
55851 +gr_handle_ioperm(void)
55852 +{
55853 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
55854 + return;
55855 +}
55856 +
55857 +void
55858 +gr_handle_iopl(void)
55859 +{
55860 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
55861 + return;
55862 +}
55863 +
55864 +void
55865 +gr_handle_mem_readwrite(u64 from, u64 to)
55866 +{
55867 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
55868 + return;
55869 +}
55870 +
55871 +void
55872 +gr_handle_vm86(void)
55873 +{
55874 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
55875 + return;
55876 +}
55877 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
55878 new file mode 100644
55879 index 0000000..2131422
55880 --- /dev/null
55881 +++ b/grsecurity/grsec_mount.c
55882 @@ -0,0 +1,62 @@
55883 +#include <linux/kernel.h>
55884 +#include <linux/sched.h>
55885 +#include <linux/mount.h>
55886 +#include <linux/grsecurity.h>
55887 +#include <linux/grinternal.h>
55888 +
55889 +void
55890 +gr_log_remount(const char *devname, const int retval)
55891 +{
55892 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55893 + if (grsec_enable_mount && (retval >= 0))
55894 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
55895 +#endif
55896 + return;
55897 +}
55898 +
55899 +void
55900 +gr_log_unmount(const char *devname, const int retval)
55901 +{
55902 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55903 + if (grsec_enable_mount && (retval >= 0))
55904 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
55905 +#endif
55906 + return;
55907 +}
55908 +
55909 +void
55910 +gr_log_mount(const char *from, const char *to, const int retval)
55911 +{
55912 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55913 + if (grsec_enable_mount && (retval >= 0))
55914 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
55915 +#endif
55916 + return;
55917 +}
55918 +
55919 +int
55920 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
55921 +{
55922 +#ifdef CONFIG_GRKERNSEC_ROFS
55923 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
55924 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
55925 + return -EPERM;
55926 + } else
55927 + return 0;
55928 +#endif
55929 + return 0;
55930 +}
55931 +
55932 +int
55933 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
55934 +{
55935 +#ifdef CONFIG_GRKERNSEC_ROFS
55936 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
55937 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
55938 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
55939 + return -EPERM;
55940 + } else
55941 + return 0;
55942 +#endif
55943 + return 0;
55944 +}
55945 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
55946 new file mode 100644
55947 index 0000000..a3b12a0
55948 --- /dev/null
55949 +++ b/grsecurity/grsec_pax.c
55950 @@ -0,0 +1,36 @@
55951 +#include <linux/kernel.h>
55952 +#include <linux/sched.h>
55953 +#include <linux/mm.h>
55954 +#include <linux/file.h>
55955 +#include <linux/grinternal.h>
55956 +#include <linux/grsecurity.h>
55957 +
55958 +void
55959 +gr_log_textrel(struct vm_area_struct * vma)
55960 +{
55961 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
55962 + if (grsec_enable_audit_textrel)
55963 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
55964 +#endif
55965 + return;
55966 +}
55967 +
55968 +void
55969 +gr_log_rwxmmap(struct file *file)
55970 +{
55971 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55972 + if (grsec_enable_log_rwxmaps)
55973 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
55974 +#endif
55975 + return;
55976 +}
55977 +
55978 +void
55979 +gr_log_rwxmprotect(struct file *file)
55980 +{
55981 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55982 + if (grsec_enable_log_rwxmaps)
55983 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
55984 +#endif
55985 + return;
55986 +}
55987 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
55988 new file mode 100644
55989 index 0000000..f7f29aa
55990 --- /dev/null
55991 +++ b/grsecurity/grsec_ptrace.c
55992 @@ -0,0 +1,30 @@
55993 +#include <linux/kernel.h>
55994 +#include <linux/sched.h>
55995 +#include <linux/grinternal.h>
55996 +#include <linux/security.h>
55997 +
55998 +void
55999 +gr_audit_ptrace(struct task_struct *task)
56000 +{
56001 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
56002 + if (grsec_enable_audit_ptrace)
56003 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
56004 +#endif
56005 + return;
56006 +}
56007 +
56008 +int
56009 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
56010 +{
56011 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56012 + const struct dentry *dentry = file->f_path.dentry;
56013 + const struct vfsmount *mnt = file->f_path.mnt;
56014 +
56015 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
56016 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
56017 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
56018 + return -EACCES;
56019 + }
56020 +#endif
56021 + return 0;
56022 +}
56023 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
56024 new file mode 100644
56025 index 0000000..7a5b2de
56026 --- /dev/null
56027 +++ b/grsecurity/grsec_sig.c
56028 @@ -0,0 +1,207 @@
56029 +#include <linux/kernel.h>
56030 +#include <linux/sched.h>
56031 +#include <linux/delay.h>
56032 +#include <linux/grsecurity.h>
56033 +#include <linux/grinternal.h>
56034 +#include <linux/hardirq.h>
56035 +
56036 +char *signames[] = {
56037 + [SIGSEGV] = "Segmentation fault",
56038 + [SIGILL] = "Illegal instruction",
56039 + [SIGABRT] = "Abort",
56040 + [SIGBUS] = "Invalid alignment/Bus error"
56041 +};
56042 +
56043 +void
56044 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
56045 +{
56046 +#ifdef CONFIG_GRKERNSEC_SIGNAL
56047 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
56048 + (sig == SIGABRT) || (sig == SIGBUS))) {
56049 + if (t->pid == current->pid) {
56050 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
56051 + } else {
56052 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
56053 + }
56054 + }
56055 +#endif
56056 + return;
56057 +}
56058 +
56059 +int
56060 +gr_handle_signal(const struct task_struct *p, const int sig)
56061 +{
56062 +#ifdef CONFIG_GRKERNSEC
56063 + /* ignore the 0 signal for protected task checks */
56064 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
56065 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
56066 + return -EPERM;
56067 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
56068 + return -EPERM;
56069 + }
56070 +#endif
56071 + return 0;
56072 +}
56073 +
56074 +#ifdef CONFIG_GRKERNSEC
56075 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
56076 +
56077 +int gr_fake_force_sig(int sig, struct task_struct *t)
56078 +{
56079 + unsigned long int flags;
56080 + int ret, blocked, ignored;
56081 + struct k_sigaction *action;
56082 +
56083 + spin_lock_irqsave(&t->sighand->siglock, flags);
56084 + action = &t->sighand->action[sig-1];
56085 + ignored = action->sa.sa_handler == SIG_IGN;
56086 + blocked = sigismember(&t->blocked, sig);
56087 + if (blocked || ignored) {
56088 + action->sa.sa_handler = SIG_DFL;
56089 + if (blocked) {
56090 + sigdelset(&t->blocked, sig);
56091 + recalc_sigpending_and_wake(t);
56092 + }
56093 + }
56094 + if (action->sa.sa_handler == SIG_DFL)
56095 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
56096 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
56097 +
56098 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
56099 +
56100 + return ret;
56101 +}
56102 +#endif
56103 +
56104 +#ifdef CONFIG_GRKERNSEC_BRUTE
56105 +#define GR_USER_BAN_TIME (15 * 60)
56106 +
56107 +static int __get_dumpable(unsigned long mm_flags)
56108 +{
56109 + int ret;
56110 +
56111 + ret = mm_flags & MMF_DUMPABLE_MASK;
56112 + return (ret >= 2) ? 2 : ret;
56113 +}
56114 +#endif
56115 +
56116 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
56117 +{
56118 +#ifdef CONFIG_GRKERNSEC_BRUTE
56119 + uid_t uid = 0;
56120 +
56121 + if (!grsec_enable_brute)
56122 + return;
56123 +
56124 + rcu_read_lock();
56125 + read_lock(&tasklist_lock);
56126 + read_lock(&grsec_exec_file_lock);
56127 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
56128 + p->real_parent->brute = 1;
56129 + else {
56130 + const struct cred *cred = __task_cred(p), *cred2;
56131 + struct task_struct *tsk, *tsk2;
56132 +
56133 + if (!__get_dumpable(mm_flags) && cred->uid) {
56134 + struct user_struct *user;
56135 +
56136 + uid = cred->uid;
56137 +
56138 + /* this is put upon execution past expiration */
56139 + user = find_user(uid);
56140 + if (user == NULL)
56141 + goto unlock;
56142 + user->banned = 1;
56143 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
56144 + if (user->ban_expires == ~0UL)
56145 + user->ban_expires--;
56146 +
56147 + do_each_thread(tsk2, tsk) {
56148 + cred2 = __task_cred(tsk);
56149 + if (tsk != p && cred2->uid == uid)
56150 + gr_fake_force_sig(SIGKILL, tsk);
56151 + } while_each_thread(tsk2, tsk);
56152 + }
56153 + }
56154 +unlock:
56155 + read_unlock(&grsec_exec_file_lock);
56156 + read_unlock(&tasklist_lock);
56157 + rcu_read_unlock();
56158 +
56159 + if (uid)
56160 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
56161 +
56162 +#endif
56163 + return;
56164 +}
56165 +
56166 +void gr_handle_brute_check(void)
56167 +{
56168 +#ifdef CONFIG_GRKERNSEC_BRUTE
56169 + if (current->brute)
56170 + msleep(30 * 1000);
56171 +#endif
56172 + return;
56173 +}
56174 +
56175 +void gr_handle_kernel_exploit(void)
56176 +{
56177 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
56178 + const struct cred *cred;
56179 + struct task_struct *tsk, *tsk2;
56180 + struct user_struct *user;
56181 + uid_t uid;
56182 +
56183 + if (in_irq() || in_serving_softirq() || in_nmi())
56184 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
56185 +
56186 + uid = current_uid();
56187 +
56188 + if (uid == 0)
56189 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
56190 + else {
56191 + /* kill all the processes of this user, hold a reference
56192 + to their creds struct, and prevent them from creating
56193 + another process until system reset
56194 + */
56195 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
56196 + /* we intentionally leak this ref */
56197 + user = get_uid(current->cred->user);
56198 + if (user) {
56199 + user->banned = 1;
56200 + user->ban_expires = ~0UL;
56201 + }
56202 +
56203 + read_lock(&tasklist_lock);
56204 + do_each_thread(tsk2, tsk) {
56205 + cred = __task_cred(tsk);
56206 + if (cred->uid == uid)
56207 + gr_fake_force_sig(SIGKILL, tsk);
56208 + } while_each_thread(tsk2, tsk);
56209 + read_unlock(&tasklist_lock);
56210 + }
56211 +#endif
56212 +}
56213 +
56214 +int __gr_process_user_ban(struct user_struct *user)
56215 +{
56216 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56217 + if (unlikely(user->banned)) {
56218 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
56219 + user->banned = 0;
56220 + user->ban_expires = 0;
56221 + free_uid(user);
56222 + } else
56223 + return -EPERM;
56224 + }
56225 +#endif
56226 + return 0;
56227 +}
56228 +
56229 +int gr_process_user_ban(void)
56230 +{
56231 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56232 + return __gr_process_user_ban(current->cred->user);
56233 +#endif
56234 + return 0;
56235 +}
56236 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
56237 new file mode 100644
56238 index 0000000..4030d57
56239 --- /dev/null
56240 +++ b/grsecurity/grsec_sock.c
56241 @@ -0,0 +1,244 @@
56242 +#include <linux/kernel.h>
56243 +#include <linux/module.h>
56244 +#include <linux/sched.h>
56245 +#include <linux/file.h>
56246 +#include <linux/net.h>
56247 +#include <linux/in.h>
56248 +#include <linux/ip.h>
56249 +#include <net/sock.h>
56250 +#include <net/inet_sock.h>
56251 +#include <linux/grsecurity.h>
56252 +#include <linux/grinternal.h>
56253 +#include <linux/gracl.h>
56254 +
56255 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
56256 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
56257 +
56258 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
56259 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
56260 +
56261 +#ifdef CONFIG_UNIX_MODULE
56262 +EXPORT_SYMBOL(gr_acl_handle_unix);
56263 +EXPORT_SYMBOL(gr_acl_handle_mknod);
56264 +EXPORT_SYMBOL(gr_handle_chroot_unix);
56265 +EXPORT_SYMBOL(gr_handle_create);
56266 +#endif
56267 +
56268 +#ifdef CONFIG_GRKERNSEC
56269 +#define gr_conn_table_size 32749
56270 +struct conn_table_entry {
56271 + struct conn_table_entry *next;
56272 + struct signal_struct *sig;
56273 +};
56274 +
56275 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
56276 +DEFINE_SPINLOCK(gr_conn_table_lock);
56277 +
56278 +extern const char * gr_socktype_to_name(unsigned char type);
56279 +extern const char * gr_proto_to_name(unsigned char proto);
56280 +extern const char * gr_sockfamily_to_name(unsigned char family);
56281 +
56282 +static __inline__ int
56283 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
56284 +{
56285 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
56286 +}
56287 +
56288 +static __inline__ int
56289 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
56290 + __u16 sport, __u16 dport)
56291 +{
56292 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
56293 + sig->gr_sport == sport && sig->gr_dport == dport))
56294 + return 1;
56295 + else
56296 + return 0;
56297 +}
56298 +
56299 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
56300 +{
56301 + struct conn_table_entry **match;
56302 + unsigned int index;
56303 +
56304 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
56305 + sig->gr_sport, sig->gr_dport,
56306 + gr_conn_table_size);
56307 +
56308 + newent->sig = sig;
56309 +
56310 + match = &gr_conn_table[index];
56311 + newent->next = *match;
56312 + *match = newent;
56313 +
56314 + return;
56315 +}
56316 +
56317 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
56318 +{
56319 + struct conn_table_entry *match, *last = NULL;
56320 + unsigned int index;
56321 +
56322 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
56323 + sig->gr_sport, sig->gr_dport,
56324 + gr_conn_table_size);
56325 +
56326 + match = gr_conn_table[index];
56327 + while (match && !conn_match(match->sig,
56328 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
56329 + sig->gr_dport)) {
56330 + last = match;
56331 + match = match->next;
56332 + }
56333 +
56334 + if (match) {
56335 + if (last)
56336 + last->next = match->next;
56337 + else
56338 + gr_conn_table[index] = NULL;
56339 + kfree(match);
56340 + }
56341 +
56342 + return;
56343 +}
56344 +
56345 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
56346 + __u16 sport, __u16 dport)
56347 +{
56348 + struct conn_table_entry *match;
56349 + unsigned int index;
56350 +
56351 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
56352 +
56353 + match = gr_conn_table[index];
56354 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
56355 + match = match->next;
56356 +
56357 + if (match)
56358 + return match->sig;
56359 + else
56360 + return NULL;
56361 +}
56362 +
56363 +#endif
56364 +
56365 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
56366 +{
56367 +#ifdef CONFIG_GRKERNSEC
56368 + struct signal_struct *sig = task->signal;
56369 + struct conn_table_entry *newent;
56370 +
56371 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
56372 + if (newent == NULL)
56373 + return;
56374 + /* no bh lock needed since we are called with bh disabled */
56375 + spin_lock(&gr_conn_table_lock);
56376 + gr_del_task_from_ip_table_nolock(sig);
56377 + sig->gr_saddr = inet->inet_rcv_saddr;
56378 + sig->gr_daddr = inet->inet_daddr;
56379 + sig->gr_sport = inet->inet_sport;
56380 + sig->gr_dport = inet->inet_dport;
56381 + gr_add_to_task_ip_table_nolock(sig, newent);
56382 + spin_unlock(&gr_conn_table_lock);
56383 +#endif
56384 + return;
56385 +}
56386 +
56387 +void gr_del_task_from_ip_table(struct task_struct *task)
56388 +{
56389 +#ifdef CONFIG_GRKERNSEC
56390 + spin_lock_bh(&gr_conn_table_lock);
56391 + gr_del_task_from_ip_table_nolock(task->signal);
56392 + spin_unlock_bh(&gr_conn_table_lock);
56393 +#endif
56394 + return;
56395 +}
56396 +
56397 +void
56398 +gr_attach_curr_ip(const struct sock *sk)
56399 +{
56400 +#ifdef CONFIG_GRKERNSEC
56401 + struct signal_struct *p, *set;
56402 + const struct inet_sock *inet = inet_sk(sk);
56403 +
56404 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
56405 + return;
56406 +
56407 + set = current->signal;
56408 +
56409 + spin_lock_bh(&gr_conn_table_lock);
56410 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
56411 + inet->inet_dport, inet->inet_sport);
56412 + if (unlikely(p != NULL)) {
56413 + set->curr_ip = p->curr_ip;
56414 + set->used_accept = 1;
56415 + gr_del_task_from_ip_table_nolock(p);
56416 + spin_unlock_bh(&gr_conn_table_lock);
56417 + return;
56418 + }
56419 + spin_unlock_bh(&gr_conn_table_lock);
56420 +
56421 + set->curr_ip = inet->inet_daddr;
56422 + set->used_accept = 1;
56423 +#endif
56424 + return;
56425 +}
56426 +
56427 +int
56428 +gr_handle_sock_all(const int family, const int type, const int protocol)
56429 +{
56430 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
56431 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
56432 + (family != AF_UNIX)) {
56433 + if (family == AF_INET)
56434 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
56435 + else
56436 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
56437 + return -EACCES;
56438 + }
56439 +#endif
56440 + return 0;
56441 +}
56442 +
56443 +int
56444 +gr_handle_sock_server(const struct sockaddr *sck)
56445 +{
56446 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56447 + if (grsec_enable_socket_server &&
56448 + in_group_p(grsec_socket_server_gid) &&
56449 + sck && (sck->sa_family != AF_UNIX) &&
56450 + (sck->sa_family != AF_LOCAL)) {
56451 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
56452 + return -EACCES;
56453 + }
56454 +#endif
56455 + return 0;
56456 +}
56457 +
56458 +int
56459 +gr_handle_sock_server_other(const struct sock *sck)
56460 +{
56461 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56462 + if (grsec_enable_socket_server &&
56463 + in_group_p(grsec_socket_server_gid) &&
56464 + sck && (sck->sk_family != AF_UNIX) &&
56465 + (sck->sk_family != AF_LOCAL)) {
56466 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
56467 + return -EACCES;
56468 + }
56469 +#endif
56470 + return 0;
56471 +}
56472 +
56473 +int
56474 +gr_handle_sock_client(const struct sockaddr *sck)
56475 +{
56476 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
56477 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
56478 + sck && (sck->sa_family != AF_UNIX) &&
56479 + (sck->sa_family != AF_LOCAL)) {
56480 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
56481 + return -EACCES;
56482 + }
56483 +#endif
56484 + return 0;
56485 +}
56486 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
56487 new file mode 100644
56488 index 0000000..a1aedd7
56489 --- /dev/null
56490 +++ b/grsecurity/grsec_sysctl.c
56491 @@ -0,0 +1,451 @@
56492 +#include <linux/kernel.h>
56493 +#include <linux/sched.h>
56494 +#include <linux/sysctl.h>
56495 +#include <linux/grsecurity.h>
56496 +#include <linux/grinternal.h>
56497 +
56498 +int
56499 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
56500 +{
56501 +#ifdef CONFIG_GRKERNSEC_SYSCTL
56502 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
56503 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
56504 + return -EACCES;
56505 + }
56506 +#endif
56507 + return 0;
56508 +}
56509 +
56510 +#ifdef CONFIG_GRKERNSEC_ROFS
56511 +static int __maybe_unused one = 1;
56512 +#endif
56513 +
56514 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
56515 +struct ctl_table grsecurity_table[] = {
56516 +#ifdef CONFIG_GRKERNSEC_SYSCTL
56517 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
56518 +#ifdef CONFIG_GRKERNSEC_IO
56519 + {
56520 + .procname = "disable_priv_io",
56521 + .data = &grsec_disable_privio,
56522 + .maxlen = sizeof(int),
56523 + .mode = 0600,
56524 + .proc_handler = &proc_dointvec,
56525 + },
56526 +#endif
56527 +#endif
56528 +#ifdef CONFIG_GRKERNSEC_LINK
56529 + {
56530 + .procname = "linking_restrictions",
56531 + .data = &grsec_enable_link,
56532 + .maxlen = sizeof(int),
56533 + .mode = 0600,
56534 + .proc_handler = &proc_dointvec,
56535 + },
56536 +#endif
56537 +#ifdef CONFIG_GRKERNSEC_BRUTE
56538 + {
56539 + .procname = "deter_bruteforce",
56540 + .data = &grsec_enable_brute,
56541 + .maxlen = sizeof(int),
56542 + .mode = 0600,
56543 + .proc_handler = &proc_dointvec,
56544 + },
56545 +#endif
56546 +#ifdef CONFIG_GRKERNSEC_FIFO
56547 + {
56548 + .procname = "fifo_restrictions",
56549 + .data = &grsec_enable_fifo,
56550 + .maxlen = sizeof(int),
56551 + .mode = 0600,
56552 + .proc_handler = &proc_dointvec,
56553 + },
56554 +#endif
56555 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56556 + {
56557 + .procname = "ptrace_readexec",
56558 + .data = &grsec_enable_ptrace_readexec,
56559 + .maxlen = sizeof(int),
56560 + .mode = 0600,
56561 + .proc_handler = &proc_dointvec,
56562 + },
56563 +#endif
56564 +#ifdef CONFIG_GRKERNSEC_SETXID
56565 + {
56566 + .procname = "consistent_setxid",
56567 + .data = &grsec_enable_setxid,
56568 + .maxlen = sizeof(int),
56569 + .mode = 0600,
56570 + .proc_handler = &proc_dointvec,
56571 + },
56572 +#endif
56573 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56574 + {
56575 + .procname = "ip_blackhole",
56576 + .data = &grsec_enable_blackhole,
56577 + .maxlen = sizeof(int),
56578 + .mode = 0600,
56579 + .proc_handler = &proc_dointvec,
56580 + },
56581 + {
56582 + .procname = "lastack_retries",
56583 + .data = &grsec_lastack_retries,
56584 + .maxlen = sizeof(int),
56585 + .mode = 0600,
56586 + .proc_handler = &proc_dointvec,
56587 + },
56588 +#endif
56589 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56590 + {
56591 + .procname = "exec_logging",
56592 + .data = &grsec_enable_execlog,
56593 + .maxlen = sizeof(int),
56594 + .mode = 0600,
56595 + .proc_handler = &proc_dointvec,
56596 + },
56597 +#endif
56598 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56599 + {
56600 + .procname = "rwxmap_logging",
56601 + .data = &grsec_enable_log_rwxmaps,
56602 + .maxlen = sizeof(int),
56603 + .mode = 0600,
56604 + .proc_handler = &proc_dointvec,
56605 + },
56606 +#endif
56607 +#ifdef CONFIG_GRKERNSEC_SIGNAL
56608 + {
56609 + .procname = "signal_logging",
56610 + .data = &grsec_enable_signal,
56611 + .maxlen = sizeof(int),
56612 + .mode = 0600,
56613 + .proc_handler = &proc_dointvec,
56614 + },
56615 +#endif
56616 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56617 + {
56618 + .procname = "forkfail_logging",
56619 + .data = &grsec_enable_forkfail,
56620 + .maxlen = sizeof(int),
56621 + .mode = 0600,
56622 + .proc_handler = &proc_dointvec,
56623 + },
56624 +#endif
56625 +#ifdef CONFIG_GRKERNSEC_TIME
56626 + {
56627 + .procname = "timechange_logging",
56628 + .data = &grsec_enable_time,
56629 + .maxlen = sizeof(int),
56630 + .mode = 0600,
56631 + .proc_handler = &proc_dointvec,
56632 + },
56633 +#endif
56634 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56635 + {
56636 + .procname = "chroot_deny_shmat",
56637 + .data = &grsec_enable_chroot_shmat,
56638 + .maxlen = sizeof(int),
56639 + .mode = 0600,
56640 + .proc_handler = &proc_dointvec,
56641 + },
56642 +#endif
56643 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56644 + {
56645 + .procname = "chroot_deny_unix",
56646 + .data = &grsec_enable_chroot_unix,
56647 + .maxlen = sizeof(int),
56648 + .mode = 0600,
56649 + .proc_handler = &proc_dointvec,
56650 + },
56651 +#endif
56652 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56653 + {
56654 + .procname = "chroot_deny_mount",
56655 + .data = &grsec_enable_chroot_mount,
56656 + .maxlen = sizeof(int),
56657 + .mode = 0600,
56658 + .proc_handler = &proc_dointvec,
56659 + },
56660 +#endif
56661 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56662 + {
56663 + .procname = "chroot_deny_fchdir",
56664 + .data = &grsec_enable_chroot_fchdir,
56665 + .maxlen = sizeof(int),
56666 + .mode = 0600,
56667 + .proc_handler = &proc_dointvec,
56668 + },
56669 +#endif
56670 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56671 + {
56672 + .procname = "chroot_deny_chroot",
56673 + .data = &grsec_enable_chroot_double,
56674 + .maxlen = sizeof(int),
56675 + .mode = 0600,
56676 + .proc_handler = &proc_dointvec,
56677 + },
56678 +#endif
56679 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56680 + {
56681 + .procname = "chroot_deny_pivot",
56682 + .data = &grsec_enable_chroot_pivot,
56683 + .maxlen = sizeof(int),
56684 + .mode = 0600,
56685 + .proc_handler = &proc_dointvec,
56686 + },
56687 +#endif
56688 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56689 + {
56690 + .procname = "chroot_enforce_chdir",
56691 + .data = &grsec_enable_chroot_chdir,
56692 + .maxlen = sizeof(int),
56693 + .mode = 0600,
56694 + .proc_handler = &proc_dointvec,
56695 + },
56696 +#endif
56697 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56698 + {
56699 + .procname = "chroot_deny_chmod",
56700 + .data = &grsec_enable_chroot_chmod,
56701 + .maxlen = sizeof(int),
56702 + .mode = 0600,
56703 + .proc_handler = &proc_dointvec,
56704 + },
56705 +#endif
56706 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56707 + {
56708 + .procname = "chroot_deny_mknod",
56709 + .data = &grsec_enable_chroot_mknod,
56710 + .maxlen = sizeof(int),
56711 + .mode = 0600,
56712 + .proc_handler = &proc_dointvec,
56713 + },
56714 +#endif
56715 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56716 + {
56717 + .procname = "chroot_restrict_nice",
56718 + .data = &grsec_enable_chroot_nice,
56719 + .maxlen = sizeof(int),
56720 + .mode = 0600,
56721 + .proc_handler = &proc_dointvec,
56722 + },
56723 +#endif
56724 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56725 + {
56726 + .procname = "chroot_execlog",
56727 + .data = &grsec_enable_chroot_execlog,
56728 + .maxlen = sizeof(int),
56729 + .mode = 0600,
56730 + .proc_handler = &proc_dointvec,
56731 + },
56732 +#endif
56733 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56734 + {
56735 + .procname = "chroot_caps",
56736 + .data = &grsec_enable_chroot_caps,
56737 + .maxlen = sizeof(int),
56738 + .mode = 0600,
56739 + .proc_handler = &proc_dointvec,
56740 + },
56741 +#endif
56742 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56743 + {
56744 + .procname = "chroot_deny_sysctl",
56745 + .data = &grsec_enable_chroot_sysctl,
56746 + .maxlen = sizeof(int),
56747 + .mode = 0600,
56748 + .proc_handler = &proc_dointvec,
56749 + },
56750 +#endif
56751 +#ifdef CONFIG_GRKERNSEC_TPE
56752 + {
56753 + .procname = "tpe",
56754 + .data = &grsec_enable_tpe,
56755 + .maxlen = sizeof(int),
56756 + .mode = 0600,
56757 + .proc_handler = &proc_dointvec,
56758 + },
56759 + {
56760 + .procname = "tpe_gid",
56761 + .data = &grsec_tpe_gid,
56762 + .maxlen = sizeof(int),
56763 + .mode = 0600,
56764 + .proc_handler = &proc_dointvec,
56765 + },
56766 +#endif
56767 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
56768 + {
56769 + .procname = "tpe_invert",
56770 + .data = &grsec_enable_tpe_invert,
56771 + .maxlen = sizeof(int),
56772 + .mode = 0600,
56773 + .proc_handler = &proc_dointvec,
56774 + },
56775 +#endif
56776 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
56777 + {
56778 + .procname = "tpe_restrict_all",
56779 + .data = &grsec_enable_tpe_all,
56780 + .maxlen = sizeof(int),
56781 + .mode = 0600,
56782 + .proc_handler = &proc_dointvec,
56783 + },
56784 +#endif
56785 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
56786 + {
56787 + .procname = "socket_all",
56788 + .data = &grsec_enable_socket_all,
56789 + .maxlen = sizeof(int),
56790 + .mode = 0600,
56791 + .proc_handler = &proc_dointvec,
56792 + },
56793 + {
56794 + .procname = "socket_all_gid",
56795 + .data = &grsec_socket_all_gid,
56796 + .maxlen = sizeof(int),
56797 + .mode = 0600,
56798 + .proc_handler = &proc_dointvec,
56799 + },
56800 +#endif
56801 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
56802 + {
56803 + .procname = "socket_client",
56804 + .data = &grsec_enable_socket_client,
56805 + .maxlen = sizeof(int),
56806 + .mode = 0600,
56807 + .proc_handler = &proc_dointvec,
56808 + },
56809 + {
56810 + .procname = "socket_client_gid",
56811 + .data = &grsec_socket_client_gid,
56812 + .maxlen = sizeof(int),
56813 + .mode = 0600,
56814 + .proc_handler = &proc_dointvec,
56815 + },
56816 +#endif
56817 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56818 + {
56819 + .procname = "socket_server",
56820 + .data = &grsec_enable_socket_server,
56821 + .maxlen = sizeof(int),
56822 + .mode = 0600,
56823 + .proc_handler = &proc_dointvec,
56824 + },
56825 + {
56826 + .procname = "socket_server_gid",
56827 + .data = &grsec_socket_server_gid,
56828 + .maxlen = sizeof(int),
56829 + .mode = 0600,
56830 + .proc_handler = &proc_dointvec,
56831 + },
56832 +#endif
56833 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
56834 + {
56835 + .procname = "audit_group",
56836 + .data = &grsec_enable_group,
56837 + .maxlen = sizeof(int),
56838 + .mode = 0600,
56839 + .proc_handler = &proc_dointvec,
56840 + },
56841 + {
56842 + .procname = "audit_gid",
56843 + .data = &grsec_audit_gid,
56844 + .maxlen = sizeof(int),
56845 + .mode = 0600,
56846 + .proc_handler = &proc_dointvec,
56847 + },
56848 +#endif
56849 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56850 + {
56851 + .procname = "audit_chdir",
56852 + .data = &grsec_enable_chdir,
56853 + .maxlen = sizeof(int),
56854 + .mode = 0600,
56855 + .proc_handler = &proc_dointvec,
56856 + },
56857 +#endif
56858 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56859 + {
56860 + .procname = "audit_mount",
56861 + .data = &grsec_enable_mount,
56862 + .maxlen = sizeof(int),
56863 + .mode = 0600,
56864 + .proc_handler = &proc_dointvec,
56865 + },
56866 +#endif
56867 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
56868 + {
56869 + .procname = "audit_textrel",
56870 + .data = &grsec_enable_audit_textrel,
56871 + .maxlen = sizeof(int),
56872 + .mode = 0600,
56873 + .proc_handler = &proc_dointvec,
56874 + },
56875 +#endif
56876 +#ifdef CONFIG_GRKERNSEC_DMESG
56877 + {
56878 + .procname = "dmesg",
56879 + .data = &grsec_enable_dmesg,
56880 + .maxlen = sizeof(int),
56881 + .mode = 0600,
56882 + .proc_handler = &proc_dointvec,
56883 + },
56884 +#endif
56885 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56886 + {
56887 + .procname = "chroot_findtask",
56888 + .data = &grsec_enable_chroot_findtask,
56889 + .maxlen = sizeof(int),
56890 + .mode = 0600,
56891 + .proc_handler = &proc_dointvec,
56892 + },
56893 +#endif
56894 +#ifdef CONFIG_GRKERNSEC_RESLOG
56895 + {
56896 + .procname = "resource_logging",
56897 + .data = &grsec_resource_logging,
56898 + .maxlen = sizeof(int),
56899 + .mode = 0600,
56900 + .proc_handler = &proc_dointvec,
56901 + },
56902 +#endif
56903 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
56904 + {
56905 + .procname = "audit_ptrace",
56906 + .data = &grsec_enable_audit_ptrace,
56907 + .maxlen = sizeof(int),
56908 + .mode = 0600,
56909 + .proc_handler = &proc_dointvec,
56910 + },
56911 +#endif
56912 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56913 + {
56914 + .procname = "harden_ptrace",
56915 + .data = &grsec_enable_harden_ptrace,
56916 + .maxlen = sizeof(int),
56917 + .mode = 0600,
56918 + .proc_handler = &proc_dointvec,
56919 + },
56920 +#endif
56921 + {
56922 + .procname = "grsec_lock",
56923 + .data = &grsec_lock,
56924 + .maxlen = sizeof(int),
56925 + .mode = 0600,
56926 + .proc_handler = &proc_dointvec,
56927 + },
56928 +#endif
56929 +#ifdef CONFIG_GRKERNSEC_ROFS
56930 + {
56931 + .procname = "romount_protect",
56932 + .data = &grsec_enable_rofs,
56933 + .maxlen = sizeof(int),
56934 + .mode = 0600,
56935 + .proc_handler = &proc_dointvec_minmax,
56936 + .extra1 = &one,
56937 + .extra2 = &one,
56938 + },
56939 +#endif
56940 + { }
56941 +};
56942 +#endif
56943 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
56944 new file mode 100644
56945 index 0000000..0dc13c3
56946 --- /dev/null
56947 +++ b/grsecurity/grsec_time.c
56948 @@ -0,0 +1,16 @@
56949 +#include <linux/kernel.h>
56950 +#include <linux/sched.h>
56951 +#include <linux/grinternal.h>
56952 +#include <linux/module.h>
56953 +
56954 +void
56955 +gr_log_timechange(void)
56956 +{
56957 +#ifdef CONFIG_GRKERNSEC_TIME
56958 + if (grsec_enable_time)
56959 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
56960 +#endif
56961 + return;
56962 +}
56963 +
56964 +EXPORT_SYMBOL(gr_log_timechange);
56965 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
56966 new file mode 100644
56967 index 0000000..4a78774
56968 --- /dev/null
56969 +++ b/grsecurity/grsec_tpe.c
56970 @@ -0,0 +1,39 @@
56971 +#include <linux/kernel.h>
56972 +#include <linux/sched.h>
56973 +#include <linux/file.h>
56974 +#include <linux/fs.h>
56975 +#include <linux/grinternal.h>
56976 +
56977 +extern int gr_acl_tpe_check(void);
56978 +
56979 +int
56980 +gr_tpe_allow(const struct file *file)
56981 +{
56982 +#ifdef CONFIG_GRKERNSEC
56983 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
56984 + const struct cred *cred = current_cred();
56985 +
56986 + if (cred->uid && ((grsec_enable_tpe &&
56987 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
56988 + ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
56989 + (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
56990 +#else
56991 + in_group_p(grsec_tpe_gid)
56992 +#endif
56993 + ) || gr_acl_tpe_check()) &&
56994 + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
56995 + (inode->i_mode & S_IWOTH))))) {
56996 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
56997 + return 0;
56998 + }
56999 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57000 + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
57001 + ((inode->i_uid && (inode->i_uid != cred->uid)) ||
57002 + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
57003 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
57004 + return 0;
57005 + }
57006 +#endif
57007 +#endif
57008 + return 1;
57009 +}
57010 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
57011 new file mode 100644
57012 index 0000000..9f7b1ac
57013 --- /dev/null
57014 +++ b/grsecurity/grsum.c
57015 @@ -0,0 +1,61 @@
57016 +#include <linux/err.h>
57017 +#include <linux/kernel.h>
57018 +#include <linux/sched.h>
57019 +#include <linux/mm.h>
57020 +#include <linux/scatterlist.h>
57021 +#include <linux/crypto.h>
57022 +#include <linux/gracl.h>
57023 +
57024 +
57025 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
57026 +#error "crypto and sha256 must be built into the kernel"
57027 +#endif
57028 +
57029 +int
57030 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
57031 +{
57032 + char *p;
57033 + struct crypto_hash *tfm;
57034 + struct hash_desc desc;
57035 + struct scatterlist sg;
57036 + unsigned char temp_sum[GR_SHA_LEN];
57037 + volatile int retval = 0;
57038 + volatile int dummy = 0;
57039 + unsigned int i;
57040 +
57041 + sg_init_table(&sg, 1);
57042 +
57043 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
57044 + if (IS_ERR(tfm)) {
57045 + /* should never happen, since sha256 should be built in */
57046 + return 1;
57047 + }
57048 +
57049 + desc.tfm = tfm;
57050 + desc.flags = 0;
57051 +
57052 + crypto_hash_init(&desc);
57053 +
57054 + p = salt;
57055 + sg_set_buf(&sg, p, GR_SALT_LEN);
57056 + crypto_hash_update(&desc, &sg, sg.length);
57057 +
57058 + p = entry->pw;
57059 + sg_set_buf(&sg, p, strlen(p));
57060 +
57061 + crypto_hash_update(&desc, &sg, sg.length);
57062 +
57063 + crypto_hash_final(&desc, temp_sum);
57064 +
57065 + memset(entry->pw, 0, GR_PW_LEN);
57066 +
57067 + for (i = 0; i < GR_SHA_LEN; i++)
57068 + if (sum[i] != temp_sum[i])
57069 + retval = 1;
57070 + else
57071 + dummy = 1; // waste a cycle
57072 +
57073 + crypto_free_hash(tfm);
57074 +
57075 + return retval;
57076 +}
57077 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
57078 index 6cd5b64..f620d2d 100644
57079 --- a/include/acpi/acpi_bus.h
57080 +++ b/include/acpi/acpi_bus.h
57081 @@ -107,7 +107,7 @@ struct acpi_device_ops {
57082 acpi_op_bind bind;
57083 acpi_op_unbind unbind;
57084 acpi_op_notify notify;
57085 -};
57086 +} __no_const;
57087
57088 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
57089
57090 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
57091 index b7babf0..71e4e74 100644
57092 --- a/include/asm-generic/atomic-long.h
57093 +++ b/include/asm-generic/atomic-long.h
57094 @@ -22,6 +22,12 @@
57095
57096 typedef atomic64_t atomic_long_t;
57097
57098 +#ifdef CONFIG_PAX_REFCOUNT
57099 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
57100 +#else
57101 +typedef atomic64_t atomic_long_unchecked_t;
57102 +#endif
57103 +
57104 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
57105
57106 static inline long atomic_long_read(atomic_long_t *l)
57107 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
57108 return (long)atomic64_read(v);
57109 }
57110
57111 +#ifdef CONFIG_PAX_REFCOUNT
57112 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
57113 +{
57114 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57115 +
57116 + return (long)atomic64_read_unchecked(v);
57117 +}
57118 +#endif
57119 +
57120 static inline void atomic_long_set(atomic_long_t *l, long i)
57121 {
57122 atomic64_t *v = (atomic64_t *)l;
57123 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
57124 atomic64_set(v, i);
57125 }
57126
57127 +#ifdef CONFIG_PAX_REFCOUNT
57128 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
57129 +{
57130 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57131 +
57132 + atomic64_set_unchecked(v, i);
57133 +}
57134 +#endif
57135 +
57136 static inline void atomic_long_inc(atomic_long_t *l)
57137 {
57138 atomic64_t *v = (atomic64_t *)l;
57139 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
57140 atomic64_inc(v);
57141 }
57142
57143 +#ifdef CONFIG_PAX_REFCOUNT
57144 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
57145 +{
57146 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57147 +
57148 + atomic64_inc_unchecked(v);
57149 +}
57150 +#endif
57151 +
57152 static inline void atomic_long_dec(atomic_long_t *l)
57153 {
57154 atomic64_t *v = (atomic64_t *)l;
57155 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
57156 atomic64_dec(v);
57157 }
57158
57159 +#ifdef CONFIG_PAX_REFCOUNT
57160 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
57161 +{
57162 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57163 +
57164 + atomic64_dec_unchecked(v);
57165 +}
57166 +#endif
57167 +
57168 static inline void atomic_long_add(long i, atomic_long_t *l)
57169 {
57170 atomic64_t *v = (atomic64_t *)l;
57171 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
57172 atomic64_add(i, v);
57173 }
57174
57175 +#ifdef CONFIG_PAX_REFCOUNT
57176 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
57177 +{
57178 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57179 +
57180 + atomic64_add_unchecked(i, v);
57181 +}
57182 +#endif
57183 +
57184 static inline void atomic_long_sub(long i, atomic_long_t *l)
57185 {
57186 atomic64_t *v = (atomic64_t *)l;
57187 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
57188 atomic64_sub(i, v);
57189 }
57190
57191 +#ifdef CONFIG_PAX_REFCOUNT
57192 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
57193 +{
57194 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57195 +
57196 + atomic64_sub_unchecked(i, v);
57197 +}
57198 +#endif
57199 +
57200 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
57201 {
57202 atomic64_t *v = (atomic64_t *)l;
57203 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
57204 return (long)atomic64_inc_return(v);
57205 }
57206
57207 +#ifdef CONFIG_PAX_REFCOUNT
57208 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
57209 +{
57210 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57211 +
57212 + return (long)atomic64_inc_return_unchecked(v);
57213 +}
57214 +#endif
57215 +
57216 static inline long atomic_long_dec_return(atomic_long_t *l)
57217 {
57218 atomic64_t *v = (atomic64_t *)l;
57219 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
57220
57221 typedef atomic_t atomic_long_t;
57222
57223 +#ifdef CONFIG_PAX_REFCOUNT
57224 +typedef atomic_unchecked_t atomic_long_unchecked_t;
57225 +#else
57226 +typedef atomic_t atomic_long_unchecked_t;
57227 +#endif
57228 +
57229 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
57230 static inline long atomic_long_read(atomic_long_t *l)
57231 {
57232 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
57233 return (long)atomic_read(v);
57234 }
57235
57236 +#ifdef CONFIG_PAX_REFCOUNT
57237 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
57238 +{
57239 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57240 +
57241 + return (long)atomic_read_unchecked(v);
57242 +}
57243 +#endif
57244 +
57245 static inline void atomic_long_set(atomic_long_t *l, long i)
57246 {
57247 atomic_t *v = (atomic_t *)l;
57248 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
57249 atomic_set(v, i);
57250 }
57251
57252 +#ifdef CONFIG_PAX_REFCOUNT
57253 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
57254 +{
57255 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57256 +
57257 + atomic_set_unchecked(v, i);
57258 +}
57259 +#endif
57260 +
57261 static inline void atomic_long_inc(atomic_long_t *l)
57262 {
57263 atomic_t *v = (atomic_t *)l;
57264 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
57265 atomic_inc(v);
57266 }
57267
57268 +#ifdef CONFIG_PAX_REFCOUNT
57269 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
57270 +{
57271 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57272 +
57273 + atomic_inc_unchecked(v);
57274 +}
57275 +#endif
57276 +
57277 static inline void atomic_long_dec(atomic_long_t *l)
57278 {
57279 atomic_t *v = (atomic_t *)l;
57280 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
57281 atomic_dec(v);
57282 }
57283
57284 +#ifdef CONFIG_PAX_REFCOUNT
57285 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
57286 +{
57287 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57288 +
57289 + atomic_dec_unchecked(v);
57290 +}
57291 +#endif
57292 +
57293 static inline void atomic_long_add(long i, atomic_long_t *l)
57294 {
57295 atomic_t *v = (atomic_t *)l;
57296 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
57297 atomic_add(i, v);
57298 }
57299
57300 +#ifdef CONFIG_PAX_REFCOUNT
57301 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
57302 +{
57303 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57304 +
57305 + atomic_add_unchecked(i, v);
57306 +}
57307 +#endif
57308 +
57309 static inline void atomic_long_sub(long i, atomic_long_t *l)
57310 {
57311 atomic_t *v = (atomic_t *)l;
57312 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
57313 atomic_sub(i, v);
57314 }
57315
57316 +#ifdef CONFIG_PAX_REFCOUNT
57317 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
57318 +{
57319 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57320 +
57321 + atomic_sub_unchecked(i, v);
57322 +}
57323 +#endif
57324 +
57325 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
57326 {
57327 atomic_t *v = (atomic_t *)l;
57328 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
57329 return (long)atomic_inc_return(v);
57330 }
57331
57332 +#ifdef CONFIG_PAX_REFCOUNT
57333 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
57334 +{
57335 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57336 +
57337 + return (long)atomic_inc_return_unchecked(v);
57338 +}
57339 +#endif
57340 +
57341 static inline long atomic_long_dec_return(atomic_long_t *l)
57342 {
57343 atomic_t *v = (atomic_t *)l;
57344 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
57345
57346 #endif /* BITS_PER_LONG == 64 */
57347
57348 +#ifdef CONFIG_PAX_REFCOUNT
57349 +static inline void pax_refcount_needs_these_functions(void)
57350 +{
57351 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
57352 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
57353 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
57354 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
57355 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
57356 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
57357 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
57358 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
57359 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
57360 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
57361 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
57362 +
57363 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
57364 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
57365 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
57366 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
57367 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
57368 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
57369 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
57370 +}
57371 +#else
57372 +#define atomic_read_unchecked(v) atomic_read(v)
57373 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
57374 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
57375 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
57376 +#define atomic_inc_unchecked(v) atomic_inc(v)
57377 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
57378 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
57379 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
57380 +#define atomic_dec_unchecked(v) atomic_dec(v)
57381 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
57382 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
57383 +
57384 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
57385 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
57386 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
57387 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
57388 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
57389 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
57390 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
57391 +#endif
57392 +
57393 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
57394 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
57395 index b18ce4f..2ee2843 100644
57396 --- a/include/asm-generic/atomic64.h
57397 +++ b/include/asm-generic/atomic64.h
57398 @@ -16,6 +16,8 @@ typedef struct {
57399 long long counter;
57400 } atomic64_t;
57401
57402 +typedef atomic64_t atomic64_unchecked_t;
57403 +
57404 #define ATOMIC64_INIT(i) { (i) }
57405
57406 extern long long atomic64_read(const atomic64_t *v);
57407 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
57408 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
57409 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
57410
57411 +#define atomic64_read_unchecked(v) atomic64_read(v)
57412 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
57413 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
57414 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
57415 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
57416 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
57417 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
57418 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
57419 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
57420 +
57421 #endif /* _ASM_GENERIC_ATOMIC64_H */
57422 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
57423 index 1bfcfe5..e04c5c9 100644
57424 --- a/include/asm-generic/cache.h
57425 +++ b/include/asm-generic/cache.h
57426 @@ -6,7 +6,7 @@
57427 * cache lines need to provide their own cache.h.
57428 */
57429
57430 -#define L1_CACHE_SHIFT 5
57431 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
57432 +#define L1_CACHE_SHIFT 5UL
57433 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
57434
57435 #endif /* __ASM_GENERIC_CACHE_H */
57436 diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
57437 index 1ca3efc..e3dc852 100644
57438 --- a/include/asm-generic/int-l64.h
57439 +++ b/include/asm-generic/int-l64.h
57440 @@ -46,6 +46,8 @@ typedef unsigned int u32;
57441 typedef signed long s64;
57442 typedef unsigned long u64;
57443
57444 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
57445 +
57446 #define S8_C(x) x
57447 #define U8_C(x) x ## U
57448 #define S16_C(x) x
57449 diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
57450 index f394147..b6152b9 100644
57451 --- a/include/asm-generic/int-ll64.h
57452 +++ b/include/asm-generic/int-ll64.h
57453 @@ -51,6 +51,8 @@ typedef unsigned int u32;
57454 typedef signed long long s64;
57455 typedef unsigned long long u64;
57456
57457 +typedef unsigned long long intoverflow_t;
57458 +
57459 #define S8_C(x) x
57460 #define U8_C(x) x ## U
57461 #define S16_C(x) x
57462 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
57463 index 0232ccb..13d9165 100644
57464 --- a/include/asm-generic/kmap_types.h
57465 +++ b/include/asm-generic/kmap_types.h
57466 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
57467 KMAP_D(17) KM_NMI,
57468 KMAP_D(18) KM_NMI_PTE,
57469 KMAP_D(19) KM_KDB,
57470 +KMAP_D(20) KM_CLEARPAGE,
57471 /*
57472 * Remember to update debug_kmap_atomic() when adding new kmap types!
57473 */
57474 -KMAP_D(20) KM_TYPE_NR
57475 +KMAP_D(21) KM_TYPE_NR
57476 };
57477
57478 #undef KMAP_D
57479 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
57480 index 725612b..9cc513a 100644
57481 --- a/include/asm-generic/pgtable-nopmd.h
57482 +++ b/include/asm-generic/pgtable-nopmd.h
57483 @@ -1,14 +1,19 @@
57484 #ifndef _PGTABLE_NOPMD_H
57485 #define _PGTABLE_NOPMD_H
57486
57487 -#ifndef __ASSEMBLY__
57488 -
57489 #include <asm-generic/pgtable-nopud.h>
57490
57491 -struct mm_struct;
57492 -
57493 #define __PAGETABLE_PMD_FOLDED
57494
57495 +#define PMD_SHIFT PUD_SHIFT
57496 +#define PTRS_PER_PMD 1
57497 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
57498 +#define PMD_MASK (~(PMD_SIZE-1))
57499 +
57500 +#ifndef __ASSEMBLY__
57501 +
57502 +struct mm_struct;
57503 +
57504 /*
57505 * Having the pmd type consist of a pud gets the size right, and allows
57506 * us to conceptually access the pud entry that this pmd is folded into
57507 @@ -16,11 +21,6 @@ struct mm_struct;
57508 */
57509 typedef struct { pud_t pud; } pmd_t;
57510
57511 -#define PMD_SHIFT PUD_SHIFT
57512 -#define PTRS_PER_PMD 1
57513 -#define PMD_SIZE (1UL << PMD_SHIFT)
57514 -#define PMD_MASK (~(PMD_SIZE-1))
57515 -
57516 /*
57517 * The "pud_xxx()" functions here are trivial for a folded two-level
57518 * setup: the pmd is never bad, and a pmd always exists (as it's folded
57519 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
57520 index 810431d..ccc3638 100644
57521 --- a/include/asm-generic/pgtable-nopud.h
57522 +++ b/include/asm-generic/pgtable-nopud.h
57523 @@ -1,10 +1,15 @@
57524 #ifndef _PGTABLE_NOPUD_H
57525 #define _PGTABLE_NOPUD_H
57526
57527 -#ifndef __ASSEMBLY__
57528 -
57529 #define __PAGETABLE_PUD_FOLDED
57530
57531 +#define PUD_SHIFT PGDIR_SHIFT
57532 +#define PTRS_PER_PUD 1
57533 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
57534 +#define PUD_MASK (~(PUD_SIZE-1))
57535 +
57536 +#ifndef __ASSEMBLY__
57537 +
57538 /*
57539 * Having the pud type consist of a pgd gets the size right, and allows
57540 * us to conceptually access the pgd entry that this pud is folded into
57541 @@ -12,11 +17,6 @@
57542 */
57543 typedef struct { pgd_t pgd; } pud_t;
57544
57545 -#define PUD_SHIFT PGDIR_SHIFT
57546 -#define PTRS_PER_PUD 1
57547 -#define PUD_SIZE (1UL << PUD_SHIFT)
57548 -#define PUD_MASK (~(PUD_SIZE-1))
57549 -
57550 /*
57551 * The "pgd_xxx()" functions here are trivial for a folded two-level
57552 * setup: the pud is never bad, and a pud always exists (as it's folded
57553 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
57554 index 76bff2b..c7a14e2 100644
57555 --- a/include/asm-generic/pgtable.h
57556 +++ b/include/asm-generic/pgtable.h
57557 @@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
57558 #endif /* __HAVE_ARCH_PMD_WRITE */
57559 #endif
57560
57561 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
57562 +static inline unsigned long pax_open_kernel(void) { return 0; }
57563 +#endif
57564 +
57565 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
57566 +static inline unsigned long pax_close_kernel(void) { return 0; }
57567 +#endif
57568 +
57569 #endif /* !__ASSEMBLY__ */
57570
57571 #endif /* _ASM_GENERIC_PGTABLE_H */
57572 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
57573 index b5e2e4c..6a5373e 100644
57574 --- a/include/asm-generic/vmlinux.lds.h
57575 +++ b/include/asm-generic/vmlinux.lds.h
57576 @@ -217,6 +217,7 @@
57577 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
57578 VMLINUX_SYMBOL(__start_rodata) = .; \
57579 *(.rodata) *(.rodata.*) \
57580 + *(.data..read_only) \
57581 *(__vermagic) /* Kernel version magic */ \
57582 . = ALIGN(8); \
57583 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
57584 @@ -722,17 +723,18 @@
57585 * section in the linker script will go there too. @phdr should have
57586 * a leading colon.
57587 *
57588 - * Note that this macros defines __per_cpu_load as an absolute symbol.
57589 + * Note that this macros defines per_cpu_load as an absolute symbol.
57590 * If there is no need to put the percpu section at a predetermined
57591 * address, use PERCPU_SECTION.
57592 */
57593 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
57594 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
57595 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
57596 + per_cpu_load = .; \
57597 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
57598 - LOAD_OFFSET) { \
57599 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
57600 PERCPU_INPUT(cacheline) \
57601 } phdr \
57602 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
57603 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
57604
57605 /**
57606 * PERCPU_SECTION - define output section for percpu area, simple version
57607 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
57608 index 1f9e951..14ef517 100644
57609 --- a/include/drm/drmP.h
57610 +++ b/include/drm/drmP.h
57611 @@ -72,6 +72,7 @@
57612 #include <linux/workqueue.h>
57613 #include <linux/poll.h>
57614 #include <asm/pgalloc.h>
57615 +#include <asm/local.h>
57616 #include "drm.h"
57617
57618 #include <linux/idr.h>
57619 @@ -1038,7 +1039,7 @@ struct drm_device {
57620
57621 /** \name Usage Counters */
57622 /*@{ */
57623 - int open_count; /**< Outstanding files open */
57624 + local_t open_count; /**< Outstanding files open */
57625 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
57626 atomic_t vma_count; /**< Outstanding vma areas open */
57627 int buf_use; /**< Buffers in use -- cannot alloc */
57628 @@ -1049,7 +1050,7 @@ struct drm_device {
57629 /*@{ */
57630 unsigned long counters;
57631 enum drm_stat_type types[15];
57632 - atomic_t counts[15];
57633 + atomic_unchecked_t counts[15];
57634 /*@} */
57635
57636 struct list_head filelist;
57637 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
57638 index 73b0712..0b7ef2f 100644
57639 --- a/include/drm/drm_crtc_helper.h
57640 +++ b/include/drm/drm_crtc_helper.h
57641 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
57642
57643 /* disable crtc when not in use - more explicit than dpms off */
57644 void (*disable)(struct drm_crtc *crtc);
57645 -};
57646 +} __no_const;
57647
57648 struct drm_encoder_helper_funcs {
57649 void (*dpms)(struct drm_encoder *encoder, int mode);
57650 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
57651 struct drm_connector *connector);
57652 /* disable encoder when not in use - more explicit than dpms off */
57653 void (*disable)(struct drm_encoder *encoder);
57654 -};
57655 +} __no_const;
57656
57657 struct drm_connector_helper_funcs {
57658 int (*get_modes)(struct drm_connector *connector);
57659 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
57660 index 26c1f78..6722682 100644
57661 --- a/include/drm/ttm/ttm_memory.h
57662 +++ b/include/drm/ttm/ttm_memory.h
57663 @@ -47,7 +47,7 @@
57664
57665 struct ttm_mem_shrink {
57666 int (*do_shrink) (struct ttm_mem_shrink *);
57667 -};
57668 +} __no_const;
57669
57670 /**
57671 * struct ttm_mem_global - Global memory accounting structure.
57672 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
57673 index e86dfca..40cc55f 100644
57674 --- a/include/linux/a.out.h
57675 +++ b/include/linux/a.out.h
57676 @@ -39,6 +39,14 @@ enum machine_type {
57677 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
57678 };
57679
57680 +/* Constants for the N_FLAGS field */
57681 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
57682 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
57683 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
57684 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
57685 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
57686 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
57687 +
57688 #if !defined (N_MAGIC)
57689 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
57690 #endif
57691 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
57692 index 49a83ca..df96b54 100644
57693 --- a/include/linux/atmdev.h
57694 +++ b/include/linux/atmdev.h
57695 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
57696 #endif
57697
57698 struct k_atm_aal_stats {
57699 -#define __HANDLE_ITEM(i) atomic_t i
57700 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
57701 __AAL_STAT_ITEMS
57702 #undef __HANDLE_ITEM
57703 };
57704 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
57705 index fd88a39..f4d0bad 100644
57706 --- a/include/linux/binfmts.h
57707 +++ b/include/linux/binfmts.h
57708 @@ -88,6 +88,7 @@ struct linux_binfmt {
57709 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
57710 int (*load_shlib)(struct file *);
57711 int (*core_dump)(struct coredump_params *cprm);
57712 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
57713 unsigned long min_coredump; /* minimal dump size */
57714 };
57715
57716 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
57717 index 94acd81..3ab569b 100644
57718 --- a/include/linux/blkdev.h
57719 +++ b/include/linux/blkdev.h
57720 @@ -675,6 +675,9 @@ extern int blk_insert_cloned_request(struct request_queue *q,
57721 struct request *rq);
57722 extern void blk_delay_queue(struct request_queue *, unsigned long);
57723 extern void blk_recount_segments(struct request_queue *, struct bio *);
57724 +extern int scsi_verify_blk_ioctl(struct block_device *, unsigned int);
57725 +extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t,
57726 + unsigned int, void __user *);
57727 extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
57728 unsigned int, void __user *);
57729 extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
57730 @@ -1312,7 +1315,7 @@ struct block_device_operations {
57731 /* this callback is with swap_lock and sometimes page table lock held */
57732 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
57733 struct module *owner;
57734 -};
57735 +} __do_const;
57736
57737 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
57738 unsigned long);
57739 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
57740 index 4d1a074..88f929a 100644
57741 --- a/include/linux/blktrace_api.h
57742 +++ b/include/linux/blktrace_api.h
57743 @@ -162,7 +162,7 @@ struct blk_trace {
57744 struct dentry *dir;
57745 struct dentry *dropped_file;
57746 struct dentry *msg_file;
57747 - atomic_t dropped;
57748 + atomic_unchecked_t dropped;
57749 };
57750
57751 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
57752 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
57753 index 83195fb..0b0f77d 100644
57754 --- a/include/linux/byteorder/little_endian.h
57755 +++ b/include/linux/byteorder/little_endian.h
57756 @@ -42,51 +42,51 @@
57757
57758 static inline __le64 __cpu_to_le64p(const __u64 *p)
57759 {
57760 - return (__force __le64)*p;
57761 + return (__force const __le64)*p;
57762 }
57763 static inline __u64 __le64_to_cpup(const __le64 *p)
57764 {
57765 - return (__force __u64)*p;
57766 + return (__force const __u64)*p;
57767 }
57768 static inline __le32 __cpu_to_le32p(const __u32 *p)
57769 {
57770 - return (__force __le32)*p;
57771 + return (__force const __le32)*p;
57772 }
57773 static inline __u32 __le32_to_cpup(const __le32 *p)
57774 {
57775 - return (__force __u32)*p;
57776 + return (__force const __u32)*p;
57777 }
57778 static inline __le16 __cpu_to_le16p(const __u16 *p)
57779 {
57780 - return (__force __le16)*p;
57781 + return (__force const __le16)*p;
57782 }
57783 static inline __u16 __le16_to_cpup(const __le16 *p)
57784 {
57785 - return (__force __u16)*p;
57786 + return (__force const __u16)*p;
57787 }
57788 static inline __be64 __cpu_to_be64p(const __u64 *p)
57789 {
57790 - return (__force __be64)__swab64p(p);
57791 + return (__force const __be64)__swab64p(p);
57792 }
57793 static inline __u64 __be64_to_cpup(const __be64 *p)
57794 {
57795 - return __swab64p((__u64 *)p);
57796 + return __swab64p((const __u64 *)p);
57797 }
57798 static inline __be32 __cpu_to_be32p(const __u32 *p)
57799 {
57800 - return (__force __be32)__swab32p(p);
57801 + return (__force const __be32)__swab32p(p);
57802 }
57803 static inline __u32 __be32_to_cpup(const __be32 *p)
57804 {
57805 - return __swab32p((__u32 *)p);
57806 + return __swab32p((const __u32 *)p);
57807 }
57808 static inline __be16 __cpu_to_be16p(const __u16 *p)
57809 {
57810 - return (__force __be16)__swab16p(p);
57811 + return (__force const __be16)__swab16p(p);
57812 }
57813 static inline __u16 __be16_to_cpup(const __be16 *p)
57814 {
57815 - return __swab16p((__u16 *)p);
57816 + return __swab16p((const __u16 *)p);
57817 }
57818 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
57819 #define __le64_to_cpus(x) do { (void)(x); } while (0)
57820 diff --git a/include/linux/cache.h b/include/linux/cache.h
57821 index 4c57065..4307975 100644
57822 --- a/include/linux/cache.h
57823 +++ b/include/linux/cache.h
57824 @@ -16,6 +16,10 @@
57825 #define __read_mostly
57826 #endif
57827
57828 +#ifndef __read_only
57829 +#define __read_only __read_mostly
57830 +#endif
57831 +
57832 #ifndef ____cacheline_aligned
57833 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
57834 #endif
57835 diff --git a/include/linux/capability.h b/include/linux/capability.h
57836 index a63d13d..069bfd5 100644
57837 --- a/include/linux/capability.h
57838 +++ b/include/linux/capability.h
57839 @@ -548,6 +548,9 @@ extern bool capable(int cap);
57840 extern bool ns_capable(struct user_namespace *ns, int cap);
57841 extern bool task_ns_capable(struct task_struct *t, int cap);
57842 extern bool nsown_capable(int cap);
57843 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
57844 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
57845 +extern bool capable_nolog(int cap);
57846
57847 /* audit system wants to get cap info from files as well */
57848 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
57849 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
57850 index 04ffb2e..6799180 100644
57851 --- a/include/linux/cleancache.h
57852 +++ b/include/linux/cleancache.h
57853 @@ -31,7 +31,7 @@ struct cleancache_ops {
57854 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
57855 void (*flush_inode)(int, struct cleancache_filekey);
57856 void (*flush_fs)(int);
57857 -};
57858 +} __no_const;
57859
57860 extern struct cleancache_ops
57861 cleancache_register_ops(struct cleancache_ops *ops);
57862 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
57863 index dfadc96..c0e70c1 100644
57864 --- a/include/linux/compiler-gcc4.h
57865 +++ b/include/linux/compiler-gcc4.h
57866 @@ -31,6 +31,12 @@
57867
57868
57869 #if __GNUC_MINOR__ >= 5
57870 +
57871 +#ifdef CONSTIFY_PLUGIN
57872 +#define __no_const __attribute__((no_const))
57873 +#define __do_const __attribute__((do_const))
57874 +#endif
57875 +
57876 /*
57877 * Mark a position in code as unreachable. This can be used to
57878 * suppress control flow warnings after asm blocks that transfer
57879 @@ -46,6 +52,11 @@
57880 #define __noclone __attribute__((__noclone__))
57881
57882 #endif
57883 +
57884 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
57885 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
57886 +#define __bos0(ptr) __bos((ptr), 0)
57887 +#define __bos1(ptr) __bos((ptr), 1)
57888 #endif
57889
57890 #if __GNUC_MINOR__ > 0
57891 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
57892 index 320d6c9..8573a1c 100644
57893 --- a/include/linux/compiler.h
57894 +++ b/include/linux/compiler.h
57895 @@ -5,31 +5,62 @@
57896
57897 #ifdef __CHECKER__
57898 # define __user __attribute__((noderef, address_space(1)))
57899 +# define __force_user __force __user
57900 # define __kernel __attribute__((address_space(0)))
57901 +# define __force_kernel __force __kernel
57902 # define __safe __attribute__((safe))
57903 # define __force __attribute__((force))
57904 # define __nocast __attribute__((nocast))
57905 # define __iomem __attribute__((noderef, address_space(2)))
57906 +# define __force_iomem __force __iomem
57907 # define __acquires(x) __attribute__((context(x,0,1)))
57908 # define __releases(x) __attribute__((context(x,1,0)))
57909 # define __acquire(x) __context__(x,1)
57910 # define __release(x) __context__(x,-1)
57911 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
57912 # define __percpu __attribute__((noderef, address_space(3)))
57913 +# define __force_percpu __force __percpu
57914 #ifdef CONFIG_SPARSE_RCU_POINTER
57915 # define __rcu __attribute__((noderef, address_space(4)))
57916 +# define __force_rcu __force __rcu
57917 #else
57918 # define __rcu
57919 +# define __force_rcu
57920 #endif
57921 extern void __chk_user_ptr(const volatile void __user *);
57922 extern void __chk_io_ptr(const volatile void __iomem *);
57923 +#elif defined(CHECKER_PLUGIN)
57924 +//# define __user
57925 +//# define __force_user
57926 +//# define __kernel
57927 +//# define __force_kernel
57928 +# define __safe
57929 +# define __force
57930 +# define __nocast
57931 +# define __iomem
57932 +# define __force_iomem
57933 +# define __chk_user_ptr(x) (void)0
57934 +# define __chk_io_ptr(x) (void)0
57935 +# define __builtin_warning(x, y...) (1)
57936 +# define __acquires(x)
57937 +# define __releases(x)
57938 +# define __acquire(x) (void)0
57939 +# define __release(x) (void)0
57940 +# define __cond_lock(x,c) (c)
57941 +# define __percpu
57942 +# define __force_percpu
57943 +# define __rcu
57944 +# define __force_rcu
57945 #else
57946 # define __user
57947 +# define __force_user
57948 # define __kernel
57949 +# define __force_kernel
57950 # define __safe
57951 # define __force
57952 # define __nocast
57953 # define __iomem
57954 +# define __force_iomem
57955 # define __chk_user_ptr(x) (void)0
57956 # define __chk_io_ptr(x) (void)0
57957 # define __builtin_warning(x, y...) (1)
57958 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
57959 # define __release(x) (void)0
57960 # define __cond_lock(x,c) (c)
57961 # define __percpu
57962 +# define __force_percpu
57963 # define __rcu
57964 +# define __force_rcu
57965 #endif
57966
57967 #ifdef __KERNEL__
57968 @@ -264,6 +297,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
57969 # define __attribute_const__ /* unimplemented */
57970 #endif
57971
57972 +#ifndef __no_const
57973 +# define __no_const
57974 +#endif
57975 +
57976 +#ifndef __do_const
57977 +# define __do_const
57978 +#endif
57979 +
57980 /*
57981 * Tell gcc if a function is cold. The compiler will assume any path
57982 * directly leading to the call is unlikely.
57983 @@ -273,6 +314,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
57984 #define __cold
57985 #endif
57986
57987 +#ifndef __alloc_size
57988 +#define __alloc_size(...)
57989 +#endif
57990 +
57991 +#ifndef __bos
57992 +#define __bos(ptr, arg)
57993 +#endif
57994 +
57995 +#ifndef __bos0
57996 +#define __bos0(ptr)
57997 +#endif
57998 +
57999 +#ifndef __bos1
58000 +#define __bos1(ptr)
58001 +#endif
58002 +
58003 /* Simple shorthand for a section definition */
58004 #ifndef __section
58005 # define __section(S) __attribute__ ((__section__(#S)))
58006 @@ -306,6 +363,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
58007 * use is to mediate communication between process-level code and irq/NMI
58008 * handlers, all running on the same CPU.
58009 */
58010 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
58011 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
58012 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
58013
58014 #endif /* __LINUX_COMPILER_H */
58015 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
58016 index e9eaec5..bfeb9bb 100644
58017 --- a/include/linux/cpuset.h
58018 +++ b/include/linux/cpuset.h
58019 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
58020 * nodemask.
58021 */
58022 smp_mb();
58023 - --ACCESS_ONCE(current->mems_allowed_change_disable);
58024 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
58025 }
58026
58027 static inline void set_mems_allowed(nodemask_t nodemask)
58028 diff --git a/include/linux/cred.h b/include/linux/cred.h
58029 index 4030896..8d6f342 100644
58030 --- a/include/linux/cred.h
58031 +++ b/include/linux/cred.h
58032 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
58033 static inline void validate_process_creds(void)
58034 {
58035 }
58036 +static inline void validate_task_creds(struct task_struct *task)
58037 +{
58038 +}
58039 #endif
58040
58041 /**
58042 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
58043 index 8a94217..15d49e3 100644
58044 --- a/include/linux/crypto.h
58045 +++ b/include/linux/crypto.h
58046 @@ -365,7 +365,7 @@ struct cipher_tfm {
58047 const u8 *key, unsigned int keylen);
58048 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
58049 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
58050 -};
58051 +} __no_const;
58052
58053 struct hash_tfm {
58054 int (*init)(struct hash_desc *desc);
58055 @@ -386,13 +386,13 @@ struct compress_tfm {
58056 int (*cot_decompress)(struct crypto_tfm *tfm,
58057 const u8 *src, unsigned int slen,
58058 u8 *dst, unsigned int *dlen);
58059 -};
58060 +} __no_const;
58061
58062 struct rng_tfm {
58063 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
58064 unsigned int dlen);
58065 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
58066 -};
58067 +} __no_const;
58068
58069 #define crt_ablkcipher crt_u.ablkcipher
58070 #define crt_aead crt_u.aead
58071 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
58072 index 7925bf0..d5143d2 100644
58073 --- a/include/linux/decompress/mm.h
58074 +++ b/include/linux/decompress/mm.h
58075 @@ -77,7 +77,7 @@ static void free(void *where)
58076 * warnings when not needed (indeed large_malloc / large_free are not
58077 * needed by inflate */
58078
58079 -#define malloc(a) kmalloc(a, GFP_KERNEL)
58080 +#define malloc(a) kmalloc((a), GFP_KERNEL)
58081 #define free(a) kfree(a)
58082
58083 #define large_malloc(a) vmalloc(a)
58084 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
58085 index e13117c..e9fc938 100644
58086 --- a/include/linux/dma-mapping.h
58087 +++ b/include/linux/dma-mapping.h
58088 @@ -46,7 +46,7 @@ struct dma_map_ops {
58089 u64 (*get_required_mask)(struct device *dev);
58090 #endif
58091 int is_phys;
58092 -};
58093 +} __do_const;
58094
58095 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
58096
58097 diff --git a/include/linux/efi.h b/include/linux/efi.h
58098 index 2362a0b..cfaf8fcc 100644
58099 --- a/include/linux/efi.h
58100 +++ b/include/linux/efi.h
58101 @@ -446,7 +446,7 @@ struct efivar_operations {
58102 efi_get_variable_t *get_variable;
58103 efi_get_next_variable_t *get_next_variable;
58104 efi_set_variable_t *set_variable;
58105 -};
58106 +} __no_const;
58107
58108 struct efivars {
58109 /*
58110 diff --git a/include/linux/elf.h b/include/linux/elf.h
58111 index 31f0508..5421c01 100644
58112 --- a/include/linux/elf.h
58113 +++ b/include/linux/elf.h
58114 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
58115 #define PT_GNU_EH_FRAME 0x6474e550
58116
58117 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
58118 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
58119 +
58120 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
58121 +
58122 +/* Constants for the e_flags field */
58123 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
58124 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
58125 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
58126 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
58127 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
58128 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
58129
58130 /*
58131 * Extended Numbering
58132 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
58133 #define DT_DEBUG 21
58134 #define DT_TEXTREL 22
58135 #define DT_JMPREL 23
58136 +#define DT_FLAGS 30
58137 + #define DF_TEXTREL 0x00000004
58138 #define DT_ENCODING 32
58139 #define OLD_DT_LOOS 0x60000000
58140 #define DT_LOOS 0x6000000d
58141 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
58142 #define PF_W 0x2
58143 #define PF_X 0x1
58144
58145 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
58146 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
58147 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
58148 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
58149 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
58150 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
58151 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
58152 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
58153 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
58154 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
58155 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
58156 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
58157 +
58158 typedef struct elf32_phdr{
58159 Elf32_Word p_type;
58160 Elf32_Off p_offset;
58161 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
58162 #define EI_OSABI 7
58163 #define EI_PAD 8
58164
58165 +#define EI_PAX 14
58166 +
58167 #define ELFMAG0 0x7f /* EI_MAG */
58168 #define ELFMAG1 'E'
58169 #define ELFMAG2 'L'
58170 @@ -423,6 +451,7 @@ extern Elf32_Dyn _DYNAMIC [];
58171 #define elf_note elf32_note
58172 #define elf_addr_t Elf32_Off
58173 #define Elf_Half Elf32_Half
58174 +#define elf_dyn Elf32_Dyn
58175
58176 #else
58177
58178 @@ -433,6 +462,7 @@ extern Elf64_Dyn _DYNAMIC [];
58179 #define elf_note elf64_note
58180 #define elf_addr_t Elf64_Off
58181 #define Elf_Half Elf64_Half
58182 +#define elf_dyn Elf64_Dyn
58183
58184 #endif
58185
58186 diff --git a/include/linux/filter.h b/include/linux/filter.h
58187 index 8eeb205..d59bfa2 100644
58188 --- a/include/linux/filter.h
58189 +++ b/include/linux/filter.h
58190 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
58191
58192 struct sk_buff;
58193 struct sock;
58194 +struct bpf_jit_work;
58195
58196 struct sk_filter
58197 {
58198 @@ -141,6 +142,9 @@ struct sk_filter
58199 unsigned int len; /* Number of filter blocks */
58200 unsigned int (*bpf_func)(const struct sk_buff *skb,
58201 const struct sock_filter *filter);
58202 +#ifdef CONFIG_BPF_JIT
58203 + struct bpf_jit_work *work;
58204 +#endif
58205 struct rcu_head rcu;
58206 struct sock_filter insns[0];
58207 };
58208 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
58209 index 84ccf8e..2e9b14c 100644
58210 --- a/include/linux/firewire.h
58211 +++ b/include/linux/firewire.h
58212 @@ -428,7 +428,7 @@ struct fw_iso_context {
58213 union {
58214 fw_iso_callback_t sc;
58215 fw_iso_mc_callback_t mc;
58216 - } callback;
58217 + } __no_const callback;
58218 void *callback_data;
58219 };
58220
58221 diff --git a/include/linux/fs.h b/include/linux/fs.h
58222 index e0bc4ff..d79c2fa 100644
58223 --- a/include/linux/fs.h
58224 +++ b/include/linux/fs.h
58225 @@ -1608,7 +1608,8 @@ struct file_operations {
58226 int (*setlease)(struct file *, long, struct file_lock **);
58227 long (*fallocate)(struct file *file, int mode, loff_t offset,
58228 loff_t len);
58229 -};
58230 +} __do_const;
58231 +typedef struct file_operations __no_const file_operations_no_const;
58232
58233 struct inode_operations {
58234 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
58235 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
58236 index 003dc0f..3c4ea97 100644
58237 --- a/include/linux/fs_struct.h
58238 +++ b/include/linux/fs_struct.h
58239 @@ -6,7 +6,7 @@
58240 #include <linux/seqlock.h>
58241
58242 struct fs_struct {
58243 - int users;
58244 + atomic_t users;
58245 spinlock_t lock;
58246 seqcount_t seq;
58247 int umask;
58248 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
58249 index ce31408..b1ad003 100644
58250 --- a/include/linux/fscache-cache.h
58251 +++ b/include/linux/fscache-cache.h
58252 @@ -102,7 +102,7 @@ struct fscache_operation {
58253 fscache_operation_release_t release;
58254 };
58255
58256 -extern atomic_t fscache_op_debug_id;
58257 +extern atomic_unchecked_t fscache_op_debug_id;
58258 extern void fscache_op_work_func(struct work_struct *work);
58259
58260 extern void fscache_enqueue_operation(struct fscache_operation *);
58261 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
58262 {
58263 INIT_WORK(&op->work, fscache_op_work_func);
58264 atomic_set(&op->usage, 1);
58265 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58266 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58267 op->processor = processor;
58268 op->release = release;
58269 INIT_LIST_HEAD(&op->pend_link);
58270 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
58271 index 2a53f10..0187fdf 100644
58272 --- a/include/linux/fsnotify.h
58273 +++ b/include/linux/fsnotify.h
58274 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
58275 */
58276 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
58277 {
58278 - return kstrdup(name, GFP_KERNEL);
58279 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
58280 }
58281
58282 /*
58283 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
58284 index 91d0e0a3..035666b 100644
58285 --- a/include/linux/fsnotify_backend.h
58286 +++ b/include/linux/fsnotify_backend.h
58287 @@ -105,6 +105,7 @@ struct fsnotify_ops {
58288 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
58289 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
58290 };
58291 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
58292
58293 /*
58294 * A group is a "thing" that wants to receive notification about filesystem
58295 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
58296 index c3da42d..c70e0df 100644
58297 --- a/include/linux/ftrace_event.h
58298 +++ b/include/linux/ftrace_event.h
58299 @@ -97,7 +97,7 @@ struct trace_event_functions {
58300 trace_print_func raw;
58301 trace_print_func hex;
58302 trace_print_func binary;
58303 -};
58304 +} __no_const;
58305
58306 struct trace_event {
58307 struct hlist_node node;
58308 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
58309 extern int trace_add_event_call(struct ftrace_event_call *call);
58310 extern void trace_remove_event_call(struct ftrace_event_call *call);
58311
58312 -#define is_signed_type(type) (((type)(-1)) < 0)
58313 +#define is_signed_type(type) (((type)(-1)) < (type)1)
58314
58315 int trace_set_clr_event(const char *system, const char *event, int set);
58316
58317 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
58318 index 6d18f35..ab71e2c 100644
58319 --- a/include/linux/genhd.h
58320 +++ b/include/linux/genhd.h
58321 @@ -185,7 +185,7 @@ struct gendisk {
58322 struct kobject *slave_dir;
58323
58324 struct timer_rand_state *random;
58325 - atomic_t sync_io; /* RAID */
58326 + atomic_unchecked_t sync_io; /* RAID */
58327 struct disk_events *ev;
58328 #ifdef CONFIG_BLK_DEV_INTEGRITY
58329 struct blk_integrity *integrity;
58330 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
58331 new file mode 100644
58332 index 0000000..0dc3943
58333 --- /dev/null
58334 +++ b/include/linux/gracl.h
58335 @@ -0,0 +1,317 @@
58336 +#ifndef GR_ACL_H
58337 +#define GR_ACL_H
58338 +
58339 +#include <linux/grdefs.h>
58340 +#include <linux/resource.h>
58341 +#include <linux/capability.h>
58342 +#include <linux/dcache.h>
58343 +#include <asm/resource.h>
58344 +
58345 +/* Major status information */
58346 +
58347 +#define GR_VERSION "grsecurity 2.2.2"
58348 +#define GRSECURITY_VERSION 0x2202
58349 +
58350 +enum {
58351 + GR_SHUTDOWN = 0,
58352 + GR_ENABLE = 1,
58353 + GR_SPROLE = 2,
58354 + GR_RELOAD = 3,
58355 + GR_SEGVMOD = 4,
58356 + GR_STATUS = 5,
58357 + GR_UNSPROLE = 6,
58358 + GR_PASSSET = 7,
58359 + GR_SPROLEPAM = 8,
58360 +};
58361 +
58362 +/* Password setup definitions
58363 + * kernel/grhash.c */
58364 +enum {
58365 + GR_PW_LEN = 128,
58366 + GR_SALT_LEN = 16,
58367 + GR_SHA_LEN = 32,
58368 +};
58369 +
58370 +enum {
58371 + GR_SPROLE_LEN = 64,
58372 +};
58373 +
58374 +enum {
58375 + GR_NO_GLOB = 0,
58376 + GR_REG_GLOB,
58377 + GR_CREATE_GLOB
58378 +};
58379 +
58380 +#define GR_NLIMITS 32
58381 +
58382 +/* Begin Data Structures */
58383 +
58384 +struct sprole_pw {
58385 + unsigned char *rolename;
58386 + unsigned char salt[GR_SALT_LEN];
58387 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
58388 +};
58389 +
58390 +struct name_entry {
58391 + __u32 key;
58392 + ino_t inode;
58393 + dev_t device;
58394 + char *name;
58395 + __u16 len;
58396 + __u8 deleted;
58397 + struct name_entry *prev;
58398 + struct name_entry *next;
58399 +};
58400 +
58401 +struct inodev_entry {
58402 + struct name_entry *nentry;
58403 + struct inodev_entry *prev;
58404 + struct inodev_entry *next;
58405 +};
58406 +
58407 +struct acl_role_db {
58408 + struct acl_role_label **r_hash;
58409 + __u32 r_size;
58410 +};
58411 +
58412 +struct inodev_db {
58413 + struct inodev_entry **i_hash;
58414 + __u32 i_size;
58415 +};
58416 +
58417 +struct name_db {
58418 + struct name_entry **n_hash;
58419 + __u32 n_size;
58420 +};
58421 +
58422 +struct crash_uid {
58423 + uid_t uid;
58424 + unsigned long expires;
58425 +};
58426 +
58427 +struct gr_hash_struct {
58428 + void **table;
58429 + void **nametable;
58430 + void *first;
58431 + __u32 table_size;
58432 + __u32 used_size;
58433 + int type;
58434 +};
58435 +
58436 +/* Userspace Grsecurity ACL data structures */
58437 +
58438 +struct acl_subject_label {
58439 + char *filename;
58440 + ino_t inode;
58441 + dev_t device;
58442 + __u32 mode;
58443 + kernel_cap_t cap_mask;
58444 + kernel_cap_t cap_lower;
58445 + kernel_cap_t cap_invert_audit;
58446 +
58447 + struct rlimit res[GR_NLIMITS];
58448 + __u32 resmask;
58449 +
58450 + __u8 user_trans_type;
58451 + __u8 group_trans_type;
58452 + uid_t *user_transitions;
58453 + gid_t *group_transitions;
58454 + __u16 user_trans_num;
58455 + __u16 group_trans_num;
58456 +
58457 + __u32 sock_families[2];
58458 + __u32 ip_proto[8];
58459 + __u32 ip_type;
58460 + struct acl_ip_label **ips;
58461 + __u32 ip_num;
58462 + __u32 inaddr_any_override;
58463 +
58464 + __u32 crashes;
58465 + unsigned long expires;
58466 +
58467 + struct acl_subject_label *parent_subject;
58468 + struct gr_hash_struct *hash;
58469 + struct acl_subject_label *prev;
58470 + struct acl_subject_label *next;
58471 +
58472 + struct acl_object_label **obj_hash;
58473 + __u32 obj_hash_size;
58474 + __u16 pax_flags;
58475 +};
58476 +
58477 +struct role_allowed_ip {
58478 + __u32 addr;
58479 + __u32 netmask;
58480 +
58481 + struct role_allowed_ip *prev;
58482 + struct role_allowed_ip *next;
58483 +};
58484 +
58485 +struct role_transition {
58486 + char *rolename;
58487 +
58488 + struct role_transition *prev;
58489 + struct role_transition *next;
58490 +};
58491 +
58492 +struct acl_role_label {
58493 + char *rolename;
58494 + uid_t uidgid;
58495 + __u16 roletype;
58496 +
58497 + __u16 auth_attempts;
58498 + unsigned long expires;
58499 +
58500 + struct acl_subject_label *root_label;
58501 + struct gr_hash_struct *hash;
58502 +
58503 + struct acl_role_label *prev;
58504 + struct acl_role_label *next;
58505 +
58506 + struct role_transition *transitions;
58507 + struct role_allowed_ip *allowed_ips;
58508 + uid_t *domain_children;
58509 + __u16 domain_child_num;
58510 +
58511 + struct acl_subject_label **subj_hash;
58512 + __u32 subj_hash_size;
58513 +};
58514 +
58515 +struct user_acl_role_db {
58516 + struct acl_role_label **r_table;
58517 + __u32 num_pointers; /* Number of allocations to track */
58518 + __u32 num_roles; /* Number of roles */
58519 + __u32 num_domain_children; /* Number of domain children */
58520 + __u32 num_subjects; /* Number of subjects */
58521 + __u32 num_objects; /* Number of objects */
58522 +};
58523 +
58524 +struct acl_object_label {
58525 + char *filename;
58526 + ino_t inode;
58527 + dev_t device;
58528 + __u32 mode;
58529 +
58530 + struct acl_subject_label *nested;
58531 + struct acl_object_label *globbed;
58532 +
58533 + /* next two structures not used */
58534 +
58535 + struct acl_object_label *prev;
58536 + struct acl_object_label *next;
58537 +};
58538 +
58539 +struct acl_ip_label {
58540 + char *iface;
58541 + __u32 addr;
58542 + __u32 netmask;
58543 + __u16 low, high;
58544 + __u8 mode;
58545 + __u32 type;
58546 + __u32 proto[8];
58547 +
58548 + /* next two structures not used */
58549 +
58550 + struct acl_ip_label *prev;
58551 + struct acl_ip_label *next;
58552 +};
58553 +
58554 +struct gr_arg {
58555 + struct user_acl_role_db role_db;
58556 + unsigned char pw[GR_PW_LEN];
58557 + unsigned char salt[GR_SALT_LEN];
58558 + unsigned char sum[GR_SHA_LEN];
58559 + unsigned char sp_role[GR_SPROLE_LEN];
58560 + struct sprole_pw *sprole_pws;
58561 + dev_t segv_device;
58562 + ino_t segv_inode;
58563 + uid_t segv_uid;
58564 + __u16 num_sprole_pws;
58565 + __u16 mode;
58566 +};
58567 +
58568 +struct gr_arg_wrapper {
58569 + struct gr_arg *arg;
58570 + __u32 version;
58571 + __u32 size;
58572 +};
58573 +
58574 +struct subject_map {
58575 + struct acl_subject_label *user;
58576 + struct acl_subject_label *kernel;
58577 + struct subject_map *prev;
58578 + struct subject_map *next;
58579 +};
58580 +
58581 +struct acl_subj_map_db {
58582 + struct subject_map **s_hash;
58583 + __u32 s_size;
58584 +};
58585 +
58586 +/* End Data Structures Section */
58587 +
58588 +/* Hash functions generated by empirical testing by Brad Spengler
58589 + Makes good use of the low bits of the inode. Generally 0-1 times
58590 + in loop for successful match. 0-3 for unsuccessful match.
58591 + Shift/add algorithm with modulus of table size and an XOR*/
58592 +
58593 +static __inline__ unsigned int
58594 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
58595 +{
58596 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
58597 +}
58598 +
58599 + static __inline__ unsigned int
58600 +shash(const struct acl_subject_label *userp, const unsigned int sz)
58601 +{
58602 + return ((const unsigned long)userp % sz);
58603 +}
58604 +
58605 +static __inline__ unsigned int
58606 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
58607 +{
58608 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
58609 +}
58610 +
58611 +static __inline__ unsigned int
58612 +nhash(const char *name, const __u16 len, const unsigned int sz)
58613 +{
58614 + return full_name_hash((const unsigned char *)name, len) % sz;
58615 +}
58616 +
58617 +#define FOR_EACH_ROLE_START(role) \
58618 + role = role_list; \
58619 + while (role) {
58620 +
58621 +#define FOR_EACH_ROLE_END(role) \
58622 + role = role->prev; \
58623 + }
58624 +
58625 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
58626 + subj = NULL; \
58627 + iter = 0; \
58628 + while (iter < role->subj_hash_size) { \
58629 + if (subj == NULL) \
58630 + subj = role->subj_hash[iter]; \
58631 + if (subj == NULL) { \
58632 + iter++; \
58633 + continue; \
58634 + }
58635 +
58636 +#define FOR_EACH_SUBJECT_END(subj,iter) \
58637 + subj = subj->next; \
58638 + if (subj == NULL) \
58639 + iter++; \
58640 + }
58641 +
58642 +
58643 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
58644 + subj = role->hash->first; \
58645 + while (subj != NULL) {
58646 +
58647 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
58648 + subj = subj->next; \
58649 + }
58650 +
58651 +#endif
58652 +
58653 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
58654 new file mode 100644
58655 index 0000000..323ecf2
58656 --- /dev/null
58657 +++ b/include/linux/gralloc.h
58658 @@ -0,0 +1,9 @@
58659 +#ifndef __GRALLOC_H
58660 +#define __GRALLOC_H
58661 +
58662 +void acl_free_all(void);
58663 +int acl_alloc_stack_init(unsigned long size);
58664 +void *acl_alloc(unsigned long len);
58665 +void *acl_alloc_num(unsigned long num, unsigned long len);
58666 +
58667 +#endif
58668 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
58669 new file mode 100644
58670 index 0000000..b30e9bc
58671 --- /dev/null
58672 +++ b/include/linux/grdefs.h
58673 @@ -0,0 +1,140 @@
58674 +#ifndef GRDEFS_H
58675 +#define GRDEFS_H
58676 +
58677 +/* Begin grsecurity status declarations */
58678 +
58679 +enum {
58680 + GR_READY = 0x01,
58681 + GR_STATUS_INIT = 0x00 // disabled state
58682 +};
58683 +
58684 +/* Begin ACL declarations */
58685 +
58686 +/* Role flags */
58687 +
58688 +enum {
58689 + GR_ROLE_USER = 0x0001,
58690 + GR_ROLE_GROUP = 0x0002,
58691 + GR_ROLE_DEFAULT = 0x0004,
58692 + GR_ROLE_SPECIAL = 0x0008,
58693 + GR_ROLE_AUTH = 0x0010,
58694 + GR_ROLE_NOPW = 0x0020,
58695 + GR_ROLE_GOD = 0x0040,
58696 + GR_ROLE_LEARN = 0x0080,
58697 + GR_ROLE_TPE = 0x0100,
58698 + GR_ROLE_DOMAIN = 0x0200,
58699 + GR_ROLE_PAM = 0x0400,
58700 + GR_ROLE_PERSIST = 0x0800
58701 +};
58702 +
58703 +/* ACL Subject and Object mode flags */
58704 +enum {
58705 + GR_DELETED = 0x80000000
58706 +};
58707 +
58708 +/* ACL Object-only mode flags */
58709 +enum {
58710 + GR_READ = 0x00000001,
58711 + GR_APPEND = 0x00000002,
58712 + GR_WRITE = 0x00000004,
58713 + GR_EXEC = 0x00000008,
58714 + GR_FIND = 0x00000010,
58715 + GR_INHERIT = 0x00000020,
58716 + GR_SETID = 0x00000040,
58717 + GR_CREATE = 0x00000080,
58718 + GR_DELETE = 0x00000100,
58719 + GR_LINK = 0x00000200,
58720 + GR_AUDIT_READ = 0x00000400,
58721 + GR_AUDIT_APPEND = 0x00000800,
58722 + GR_AUDIT_WRITE = 0x00001000,
58723 + GR_AUDIT_EXEC = 0x00002000,
58724 + GR_AUDIT_FIND = 0x00004000,
58725 + GR_AUDIT_INHERIT= 0x00008000,
58726 + GR_AUDIT_SETID = 0x00010000,
58727 + GR_AUDIT_CREATE = 0x00020000,
58728 + GR_AUDIT_DELETE = 0x00040000,
58729 + GR_AUDIT_LINK = 0x00080000,
58730 + GR_PTRACERD = 0x00100000,
58731 + GR_NOPTRACE = 0x00200000,
58732 + GR_SUPPRESS = 0x00400000,
58733 + GR_NOLEARN = 0x00800000,
58734 + GR_INIT_TRANSFER= 0x01000000
58735 +};
58736 +
58737 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
58738 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
58739 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
58740 +
58741 +/* ACL subject-only mode flags */
58742 +enum {
58743 + GR_KILL = 0x00000001,
58744 + GR_VIEW = 0x00000002,
58745 + GR_PROTECTED = 0x00000004,
58746 + GR_LEARN = 0x00000008,
58747 + GR_OVERRIDE = 0x00000010,
58748 + /* just a placeholder, this mode is only used in userspace */
58749 + GR_DUMMY = 0x00000020,
58750 + GR_PROTSHM = 0x00000040,
58751 + GR_KILLPROC = 0x00000080,
58752 + GR_KILLIPPROC = 0x00000100,
58753 + /* just a placeholder, this mode is only used in userspace */
58754 + GR_NOTROJAN = 0x00000200,
58755 + GR_PROTPROCFD = 0x00000400,
58756 + GR_PROCACCT = 0x00000800,
58757 + GR_RELAXPTRACE = 0x00001000,
58758 + GR_NESTED = 0x00002000,
58759 + GR_INHERITLEARN = 0x00004000,
58760 + GR_PROCFIND = 0x00008000,
58761 + GR_POVERRIDE = 0x00010000,
58762 + GR_KERNELAUTH = 0x00020000,
58763 + GR_ATSECURE = 0x00040000,
58764 + GR_SHMEXEC = 0x00080000
58765 +};
58766 +
58767 +enum {
58768 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
58769 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
58770 + GR_PAX_ENABLE_MPROTECT = 0x0004,
58771 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
58772 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
58773 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
58774 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
58775 + GR_PAX_DISABLE_MPROTECT = 0x0400,
58776 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
58777 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
58778 +};
58779 +
58780 +enum {
58781 + GR_ID_USER = 0x01,
58782 + GR_ID_GROUP = 0x02,
58783 +};
58784 +
58785 +enum {
58786 + GR_ID_ALLOW = 0x01,
58787 + GR_ID_DENY = 0x02,
58788 +};
58789 +
58790 +#define GR_CRASH_RES 31
58791 +#define GR_UIDTABLE_MAX 500
58792 +
58793 +/* begin resource learning section */
58794 +enum {
58795 + GR_RLIM_CPU_BUMP = 60,
58796 + GR_RLIM_FSIZE_BUMP = 50000,
58797 + GR_RLIM_DATA_BUMP = 10000,
58798 + GR_RLIM_STACK_BUMP = 1000,
58799 + GR_RLIM_CORE_BUMP = 10000,
58800 + GR_RLIM_RSS_BUMP = 500000,
58801 + GR_RLIM_NPROC_BUMP = 1,
58802 + GR_RLIM_NOFILE_BUMP = 5,
58803 + GR_RLIM_MEMLOCK_BUMP = 50000,
58804 + GR_RLIM_AS_BUMP = 500000,
58805 + GR_RLIM_LOCKS_BUMP = 2,
58806 + GR_RLIM_SIGPENDING_BUMP = 5,
58807 + GR_RLIM_MSGQUEUE_BUMP = 10000,
58808 + GR_RLIM_NICE_BUMP = 1,
58809 + GR_RLIM_RTPRIO_BUMP = 1,
58810 + GR_RLIM_RTTIME_BUMP = 1000000
58811 +};
58812 +
58813 +#endif
58814 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
58815 new file mode 100644
58816 index 0000000..da390f1
58817 --- /dev/null
58818 +++ b/include/linux/grinternal.h
58819 @@ -0,0 +1,221 @@
58820 +#ifndef __GRINTERNAL_H
58821 +#define __GRINTERNAL_H
58822 +
58823 +#ifdef CONFIG_GRKERNSEC
58824 +
58825 +#include <linux/fs.h>
58826 +#include <linux/mnt_namespace.h>
58827 +#include <linux/nsproxy.h>
58828 +#include <linux/gracl.h>
58829 +#include <linux/grdefs.h>
58830 +#include <linux/grmsg.h>
58831 +
58832 +void gr_add_learn_entry(const char *fmt, ...)
58833 + __attribute__ ((format (printf, 1, 2)));
58834 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
58835 + const struct vfsmount *mnt);
58836 +__u32 gr_check_create(const struct dentry *new_dentry,
58837 + const struct dentry *parent,
58838 + const struct vfsmount *mnt, const __u32 mode);
58839 +int gr_check_protected_task(const struct task_struct *task);
58840 +__u32 to_gr_audit(const __u32 reqmode);
58841 +int gr_set_acls(const int type);
58842 +int gr_apply_subject_to_task(struct task_struct *task);
58843 +int gr_acl_is_enabled(void);
58844 +char gr_roletype_to_char(void);
58845 +
58846 +void gr_handle_alertkill(struct task_struct *task);
58847 +char *gr_to_filename(const struct dentry *dentry,
58848 + const struct vfsmount *mnt);
58849 +char *gr_to_filename1(const struct dentry *dentry,
58850 + const struct vfsmount *mnt);
58851 +char *gr_to_filename2(const struct dentry *dentry,
58852 + const struct vfsmount *mnt);
58853 +char *gr_to_filename3(const struct dentry *dentry,
58854 + const struct vfsmount *mnt);
58855 +
58856 +extern int grsec_enable_ptrace_readexec;
58857 +extern int grsec_enable_harden_ptrace;
58858 +extern int grsec_enable_link;
58859 +extern int grsec_enable_fifo;
58860 +extern int grsec_enable_execve;
58861 +extern int grsec_enable_shm;
58862 +extern int grsec_enable_execlog;
58863 +extern int grsec_enable_signal;
58864 +extern int grsec_enable_audit_ptrace;
58865 +extern int grsec_enable_forkfail;
58866 +extern int grsec_enable_time;
58867 +extern int grsec_enable_rofs;
58868 +extern int grsec_enable_chroot_shmat;
58869 +extern int grsec_enable_chroot_mount;
58870 +extern int grsec_enable_chroot_double;
58871 +extern int grsec_enable_chroot_pivot;
58872 +extern int grsec_enable_chroot_chdir;
58873 +extern int grsec_enable_chroot_chmod;
58874 +extern int grsec_enable_chroot_mknod;
58875 +extern int grsec_enable_chroot_fchdir;
58876 +extern int grsec_enable_chroot_nice;
58877 +extern int grsec_enable_chroot_execlog;
58878 +extern int grsec_enable_chroot_caps;
58879 +extern int grsec_enable_chroot_sysctl;
58880 +extern int grsec_enable_chroot_unix;
58881 +extern int grsec_enable_tpe;
58882 +extern int grsec_tpe_gid;
58883 +extern int grsec_enable_tpe_all;
58884 +extern int grsec_enable_tpe_invert;
58885 +extern int grsec_enable_socket_all;
58886 +extern int grsec_socket_all_gid;
58887 +extern int grsec_enable_socket_client;
58888 +extern int grsec_socket_client_gid;
58889 +extern int grsec_enable_socket_server;
58890 +extern int grsec_socket_server_gid;
58891 +extern int grsec_audit_gid;
58892 +extern int grsec_enable_group;
58893 +extern int grsec_enable_audit_textrel;
58894 +extern int grsec_enable_log_rwxmaps;
58895 +extern int grsec_enable_mount;
58896 +extern int grsec_enable_chdir;
58897 +extern int grsec_resource_logging;
58898 +extern int grsec_enable_blackhole;
58899 +extern int grsec_lastack_retries;
58900 +extern int grsec_enable_brute;
58901 +extern int grsec_lock;
58902 +
58903 +extern spinlock_t grsec_alert_lock;
58904 +extern unsigned long grsec_alert_wtime;
58905 +extern unsigned long grsec_alert_fyet;
58906 +
58907 +extern spinlock_t grsec_audit_lock;
58908 +
58909 +extern rwlock_t grsec_exec_file_lock;
58910 +
58911 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
58912 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
58913 + (tsk)->exec_file->f_vfsmnt) : "/")
58914 +
58915 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
58916 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
58917 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
58918 +
58919 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
58920 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
58921 + (tsk)->exec_file->f_vfsmnt) : "/")
58922 +
58923 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
58924 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
58925 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
58926 +
58927 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
58928 +
58929 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
58930 +
58931 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
58932 + (task)->pid, (cred)->uid, \
58933 + (cred)->euid, (cred)->gid, (cred)->egid, \
58934 + gr_parent_task_fullpath(task), \
58935 + (task)->real_parent->comm, (task)->real_parent->pid, \
58936 + (pcred)->uid, (pcred)->euid, \
58937 + (pcred)->gid, (pcred)->egid
58938 +
58939 +#define GR_CHROOT_CAPS {{ \
58940 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
58941 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
58942 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
58943 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
58944 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
58945 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
58946 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
58947 +
58948 +#define security_learn(normal_msg,args...) \
58949 +({ \
58950 + read_lock(&grsec_exec_file_lock); \
58951 + gr_add_learn_entry(normal_msg "\n", ## args); \
58952 + read_unlock(&grsec_exec_file_lock); \
58953 +})
58954 +
58955 +enum {
58956 + GR_DO_AUDIT,
58957 + GR_DONT_AUDIT,
58958 + /* used for non-audit messages that we shouldn't kill the task on */
58959 + GR_DONT_AUDIT_GOOD
58960 +};
58961 +
58962 +enum {
58963 + GR_TTYSNIFF,
58964 + GR_RBAC,
58965 + GR_RBAC_STR,
58966 + GR_STR_RBAC,
58967 + GR_RBAC_MODE2,
58968 + GR_RBAC_MODE3,
58969 + GR_FILENAME,
58970 + GR_SYSCTL_HIDDEN,
58971 + GR_NOARGS,
58972 + GR_ONE_INT,
58973 + GR_ONE_INT_TWO_STR,
58974 + GR_ONE_STR,
58975 + GR_STR_INT,
58976 + GR_TWO_STR_INT,
58977 + GR_TWO_INT,
58978 + GR_TWO_U64,
58979 + GR_THREE_INT,
58980 + GR_FIVE_INT_TWO_STR,
58981 + GR_TWO_STR,
58982 + GR_THREE_STR,
58983 + GR_FOUR_STR,
58984 + GR_STR_FILENAME,
58985 + GR_FILENAME_STR,
58986 + GR_FILENAME_TWO_INT,
58987 + GR_FILENAME_TWO_INT_STR,
58988 + GR_TEXTREL,
58989 + GR_PTRACE,
58990 + GR_RESOURCE,
58991 + GR_CAP,
58992 + GR_SIG,
58993 + GR_SIG2,
58994 + GR_CRASH1,
58995 + GR_CRASH2,
58996 + GR_PSACCT,
58997 + GR_RWXMAP
58998 +};
58999 +
59000 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
59001 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
59002 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
59003 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
59004 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
59005 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
59006 +#define gr_log_fs_rbac_mode3(audit, msg, dentry, mnt, str1, str2, str3) gr_log_varargs(audit, msg, GR_RBAC_MODE3, dentry, mnt, str1, str2, str3)
59007 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
59008 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
59009 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
59010 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
59011 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
59012 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
59013 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
59014 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
59015 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
59016 +#define gr_log_int5_str2(audit, msg, num1, num2, str1, str2) gr_log_varargs(audit, msg, GR_FIVE_INT_TWO_STR, num1, num2, str1, str2)
59017 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
59018 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
59019 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
59020 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
59021 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
59022 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
59023 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
59024 +#define gr_log_fs_int2_str(audit, msg, dentry, mnt, num1, num2, str) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT_STR, dentry, mnt, num1, num2, str)
59025 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
59026 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
59027 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
59028 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
59029 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
59030 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
59031 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
59032 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
59033 +#define gr_log_procacct(audit, msg, task, num1, num2, num3, num4, num5, num6, num7, num8, num9) gr_log_varargs(audit, msg, GR_PSACCT, task, num1, num2, num3, num4, num5, num6, num7, num8, num9)
59034 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
59035 +
59036 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
59037 +
59038 +#endif
59039 +
59040 +#endif
59041 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
59042 new file mode 100644
59043 index 0000000..cf49370
59044 --- /dev/null
59045 +++ b/include/linux/grmsg.h
59046 @@ -0,0 +1,109 @@
59047 +#define DEFAULTSECMSG "%.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u, parent %.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u"
59048 +#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u run time:[%ud %uh %um %us] cpu time:[%ud %uh %um %us] %s with exit code %ld, parent %.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u"
59049 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
59050 +#define GR_STOPMOD_MSG "denied modification of module state by "
59051 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
59052 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
59053 +#define GR_IOPERM_MSG "denied use of ioperm() by "
59054 +#define GR_IOPL_MSG "denied use of iopl() by "
59055 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
59056 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
59057 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
59058 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
59059 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
59060 +#define GR_LEARN_AUDIT_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%lu\t%lu\t%.4095s\t%lu\t%pI4"
59061 +#define GR_ID_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%c\t%d\t%d\t%d\t%pI4"
59062 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
59063 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
59064 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
59065 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
59066 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
59067 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
59068 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
59069 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
59070 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
59071 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
59072 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
59073 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
59074 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
59075 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
59076 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
59077 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
59078 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
59079 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
59080 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
59081 +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
59082 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
59083 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
59084 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
59085 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
59086 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
59087 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
59088 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
59089 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
59090 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
59091 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
59092 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
59093 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
59094 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
59095 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
59096 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
59097 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
59098 +#define GR_DISABLED_ACL_MSG "Error loading %s, trying to run kernel with acls disabled. To disable acls at startup use <kernel image name> gracl=off from your boot loader"
59099 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
59100 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
59101 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
59102 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
59103 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
59104 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
59105 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
59106 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
59107 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
59108 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
59109 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
59110 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
59111 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
59112 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
59113 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
59114 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
59115 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
59116 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
59117 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
59118 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
59119 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
59120 +#define GR_NICE_CHROOT_MSG "denied priority change by "
59121 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
59122 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
59123 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
59124 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
59125 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
59126 +#define GR_TIME_MSG "time set by "
59127 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
59128 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
59129 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
59130 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
59131 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
59132 +#define GR_BIND_MSG "denied bind() by "
59133 +#define GR_CONNECT_MSG "denied connect() by "
59134 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
59135 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
59136 +#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%pI4\t%u\t%u\t%u\t%u\t%pI4"
59137 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
59138 +#define GR_CAP_ACL_MSG "use of %s denied for "
59139 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
59140 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
59141 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
59142 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
59143 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
59144 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
59145 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
59146 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
59147 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
59148 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
59149 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
59150 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
59151 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
59152 +#define GR_VM86_MSG "denied use of vm86 by "
59153 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
59154 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable suid/sgid binary %.950s by "
59155 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
59156 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
59157 new file mode 100644
59158 index 0000000..1ca3931
59159 --- /dev/null
59160 +++ b/include/linux/grsecurity.h
59161 @@ -0,0 +1,233 @@
59162 +#ifndef GR_SECURITY_H
59163 +#define GR_SECURITY_H
59164 +#include <linux/fs.h>
59165 +#include <linux/fs_struct.h>
59166 +#include <linux/binfmts.h>
59167 +#include <linux/gracl.h>
59168 +
59169 +/* notify of brain-dead configs */
59170 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59171 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
59172 +#endif
59173 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
59174 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
59175 +#endif
59176 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
59177 +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
59178 +#endif
59179 +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
59180 +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
59181 +#endif
59182 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
59183 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
59184 +#endif
59185 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
59186 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
59187 +#endif
59188 +
59189 +#include <linux/compat.h>
59190 +
59191 +struct user_arg_ptr {
59192 +#ifdef CONFIG_COMPAT
59193 + bool is_compat;
59194 +#endif
59195 + union {
59196 + const char __user *const __user *native;
59197 +#ifdef CONFIG_COMPAT
59198 + compat_uptr_t __user *compat;
59199 +#endif
59200 + } ptr;
59201 +};
59202 +
59203 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
59204 +void gr_handle_brute_check(void);
59205 +void gr_handle_kernel_exploit(void);
59206 +int gr_process_user_ban(void);
59207 +
59208 +char gr_roletype_to_char(void);
59209 +
59210 +int gr_acl_enable_at_secure(void);
59211 +
59212 +int gr_check_user_change(int real, int effective, int fs);
59213 +int gr_check_group_change(int real, int effective, int fs);
59214 +
59215 +void gr_del_task_from_ip_table(struct task_struct *p);
59216 +
59217 +int gr_pid_is_chrooted(struct task_struct *p);
59218 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
59219 +int gr_handle_chroot_nice(void);
59220 +int gr_handle_chroot_sysctl(const int op);
59221 +int gr_handle_chroot_setpriority(struct task_struct *p,
59222 + const int niceval);
59223 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
59224 +int gr_handle_chroot_chroot(const struct dentry *dentry,
59225 + const struct vfsmount *mnt);
59226 +void gr_handle_chroot_chdir(struct path *path);
59227 +int gr_handle_chroot_chmod(const struct dentry *dentry,
59228 + const struct vfsmount *mnt, const int mode);
59229 +int gr_handle_chroot_mknod(const struct dentry *dentry,
59230 + const struct vfsmount *mnt, const int mode);
59231 +int gr_handle_chroot_mount(const struct dentry *dentry,
59232 + const struct vfsmount *mnt,
59233 + const char *dev_name);
59234 +int gr_handle_chroot_pivot(void);
59235 +int gr_handle_chroot_unix(const pid_t pid);
59236 +
59237 +int gr_handle_rawio(const struct inode *inode);
59238 +
59239 +void gr_handle_ioperm(void);
59240 +void gr_handle_iopl(void);
59241 +
59242 +int gr_tpe_allow(const struct file *file);
59243 +
59244 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
59245 +void gr_clear_chroot_entries(struct task_struct *task);
59246 +
59247 +void gr_log_forkfail(const int retval);
59248 +void gr_log_timechange(void);
59249 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
59250 +void gr_log_chdir(const struct dentry *dentry,
59251 + const struct vfsmount *mnt);
59252 +void gr_log_chroot_exec(const struct dentry *dentry,
59253 + const struct vfsmount *mnt);
59254 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
59255 +void gr_log_remount(const char *devname, const int retval);
59256 +void gr_log_unmount(const char *devname, const int retval);
59257 +void gr_log_mount(const char *from, const char *to, const int retval);
59258 +void gr_log_textrel(struct vm_area_struct *vma);
59259 +void gr_log_rwxmmap(struct file *file);
59260 +void gr_log_rwxmprotect(struct file *file);
59261 +
59262 +int gr_handle_follow_link(const struct inode *parent,
59263 + const struct inode *inode,
59264 + const struct dentry *dentry,
59265 + const struct vfsmount *mnt);
59266 +int gr_handle_fifo(const struct dentry *dentry,
59267 + const struct vfsmount *mnt,
59268 + const struct dentry *dir, const int flag,
59269 + const int acc_mode);
59270 +int gr_handle_hardlink(const struct dentry *dentry,
59271 + const struct vfsmount *mnt,
59272 + struct inode *inode,
59273 + const int mode, const char *to);
59274 +
59275 +int gr_is_capable(const int cap);
59276 +int gr_is_capable_nolog(const int cap);
59277 +void gr_learn_resource(const struct task_struct *task, const int limit,
59278 + const unsigned long wanted, const int gt);
59279 +void gr_copy_label(struct task_struct *tsk);
59280 +void gr_handle_crash(struct task_struct *task, const int sig);
59281 +int gr_handle_signal(const struct task_struct *p, const int sig);
59282 +int gr_check_crash_uid(const uid_t uid);
59283 +int gr_check_protected_task(const struct task_struct *task);
59284 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
59285 +int gr_acl_handle_mmap(const struct file *file,
59286 + const unsigned long prot);
59287 +int gr_acl_handle_mprotect(const struct file *file,
59288 + const unsigned long prot);
59289 +int gr_check_hidden_task(const struct task_struct *tsk);
59290 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
59291 + const struct vfsmount *mnt);
59292 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
59293 + const struct vfsmount *mnt);
59294 +__u32 gr_acl_handle_access(const struct dentry *dentry,
59295 + const struct vfsmount *mnt, const int fmode);
59296 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
59297 + const struct vfsmount *mnt, mode_t mode);
59298 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
59299 + const struct vfsmount *mnt, mode_t mode);
59300 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
59301 + const struct vfsmount *mnt);
59302 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
59303 + const struct vfsmount *mnt);
59304 +int gr_handle_ptrace(struct task_struct *task, const long request);
59305 +int gr_handle_proc_ptrace(struct task_struct *task);
59306 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
59307 + const struct vfsmount *mnt);
59308 +int gr_check_crash_exec(const struct file *filp);
59309 +int gr_acl_is_enabled(void);
59310 +void gr_set_kernel_label(struct task_struct *task);
59311 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
59312 + const gid_t gid);
59313 +int gr_set_proc_label(const struct dentry *dentry,
59314 + const struct vfsmount *mnt,
59315 + const int unsafe_share);
59316 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
59317 + const struct vfsmount *mnt);
59318 +__u32 gr_acl_handle_open(const struct dentry *dentry,
59319 + const struct vfsmount *mnt, int acc_mode);
59320 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
59321 + const struct dentry *p_dentry,
59322 + const struct vfsmount *p_mnt,
59323 + int open_flags, int acc_mode, const int imode);
59324 +void gr_handle_create(const struct dentry *dentry,
59325 + const struct vfsmount *mnt);
59326 +void gr_handle_proc_create(const struct dentry *dentry,
59327 + const struct inode *inode);
59328 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
59329 + const struct dentry *parent_dentry,
59330 + const struct vfsmount *parent_mnt,
59331 + const int mode);
59332 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
59333 + const struct dentry *parent_dentry,
59334 + const struct vfsmount *parent_mnt);
59335 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
59336 + const struct vfsmount *mnt);
59337 +void gr_handle_delete(const ino_t ino, const dev_t dev);
59338 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
59339 + const struct vfsmount *mnt);
59340 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
59341 + const struct dentry *parent_dentry,
59342 + const struct vfsmount *parent_mnt,
59343 + const char *from);
59344 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
59345 + const struct dentry *parent_dentry,
59346 + const struct vfsmount *parent_mnt,
59347 + const struct dentry *old_dentry,
59348 + const struct vfsmount *old_mnt, const char *to);
59349 +int gr_acl_handle_rename(struct dentry *new_dentry,
59350 + struct dentry *parent_dentry,
59351 + const struct vfsmount *parent_mnt,
59352 + struct dentry *old_dentry,
59353 + struct inode *old_parent_inode,
59354 + struct vfsmount *old_mnt, const char *newname);
59355 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59356 + struct dentry *old_dentry,
59357 + struct dentry *new_dentry,
59358 + struct vfsmount *mnt, const __u8 replace);
59359 +__u32 gr_check_link(const struct dentry *new_dentry,
59360 + const struct dentry *parent_dentry,
59361 + const struct vfsmount *parent_mnt,
59362 + const struct dentry *old_dentry,
59363 + const struct vfsmount *old_mnt);
59364 +int gr_acl_handle_filldir(const struct file *file, const char *name,
59365 + const unsigned int namelen, const ino_t ino);
59366 +
59367 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
59368 + const struct vfsmount *mnt);
59369 +void gr_acl_handle_exit(void);
59370 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
59371 +int gr_acl_handle_procpidmem(const struct task_struct *task);
59372 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
59373 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
59374 +void gr_audit_ptrace(struct task_struct *task);
59375 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
59376 +
59377 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
59378 +
59379 +#ifdef CONFIG_GRKERNSEC
59380 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
59381 +void gr_handle_vm86(void);
59382 +void gr_handle_mem_readwrite(u64 from, u64 to);
59383 +
59384 +extern int grsec_enable_dmesg;
59385 +extern int grsec_disable_privio;
59386 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59387 +extern int grsec_enable_chroot_findtask;
59388 +#endif
59389 +#ifdef CONFIG_GRKERNSEC_SETXID
59390 +extern int grsec_enable_setxid;
59391 +#endif
59392 +#endif
59393 +
59394 +#endif
59395 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
59396 new file mode 100644
59397 index 0000000..e7ffaaf
59398 --- /dev/null
59399 +++ b/include/linux/grsock.h
59400 @@ -0,0 +1,19 @@
59401 +#ifndef __GRSOCK_H
59402 +#define __GRSOCK_H
59403 +
59404 +extern void gr_attach_curr_ip(const struct sock *sk);
59405 +extern int gr_handle_sock_all(const int family, const int type,
59406 + const int protocol);
59407 +extern int gr_handle_sock_server(const struct sockaddr *sck);
59408 +extern int gr_handle_sock_server_other(const struct sock *sck);
59409 +extern int gr_handle_sock_client(const struct sockaddr *sck);
59410 +extern int gr_search_connect(struct socket * sock,
59411 + struct sockaddr_in * addr);
59412 +extern int gr_search_bind(struct socket * sock,
59413 + struct sockaddr_in * addr);
59414 +extern int gr_search_listen(struct socket * sock);
59415 +extern int gr_search_accept(struct socket * sock);
59416 +extern int gr_search_socket(const int domain, const int type,
59417 + const int protocol);
59418 +
59419 +#endif
59420 diff --git a/include/linux/hid.h b/include/linux/hid.h
59421 index c235e4e..f0cf7a0 100644
59422 --- a/include/linux/hid.h
59423 +++ b/include/linux/hid.h
59424 @@ -679,7 +679,7 @@ struct hid_ll_driver {
59425 unsigned int code, int value);
59426
59427 int (*parse)(struct hid_device *hdev);
59428 -};
59429 +} __no_const;
59430
59431 #define PM_HINT_FULLON 1<<5
59432 #define PM_HINT_NORMAL 1<<1
59433 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
59434 index 3a93f73..b19d0b3 100644
59435 --- a/include/linux/highmem.h
59436 +++ b/include/linux/highmem.h
59437 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
59438 kunmap_atomic(kaddr, KM_USER0);
59439 }
59440
59441 +static inline void sanitize_highpage(struct page *page)
59442 +{
59443 + void *kaddr;
59444 + unsigned long flags;
59445 +
59446 + local_irq_save(flags);
59447 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
59448 + clear_page(kaddr);
59449 + kunmap_atomic(kaddr, KM_CLEARPAGE);
59450 + local_irq_restore(flags);
59451 +}
59452 +
59453 static inline void zero_user_segments(struct page *page,
59454 unsigned start1, unsigned end1,
59455 unsigned start2, unsigned end2)
59456 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
59457 index 07d103a..04ec65b 100644
59458 --- a/include/linux/i2c.h
59459 +++ b/include/linux/i2c.h
59460 @@ -364,6 +364,7 @@ struct i2c_algorithm {
59461 /* To determine what the adapter supports */
59462 u32 (*functionality) (struct i2c_adapter *);
59463 };
59464 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
59465
59466 /*
59467 * i2c_adapter is the structure used to identify a physical i2c bus along
59468 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
59469 index a6deef4..c56a7f2 100644
59470 --- a/include/linux/i2o.h
59471 +++ b/include/linux/i2o.h
59472 @@ -564,7 +564,7 @@ struct i2o_controller {
59473 struct i2o_device *exec; /* Executive */
59474 #if BITS_PER_LONG == 64
59475 spinlock_t context_list_lock; /* lock for context_list */
59476 - atomic_t context_list_counter; /* needed for unique contexts */
59477 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
59478 struct list_head context_list; /* list of context id's
59479 and pointers */
59480 #endif
59481 diff --git a/include/linux/init.h b/include/linux/init.h
59482 index 9146f39..885354d 100644
59483 --- a/include/linux/init.h
59484 +++ b/include/linux/init.h
59485 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cmdline);
59486
59487 /* Each module must use one module_init(). */
59488 #define module_init(initfn) \
59489 - static inline initcall_t __inittest(void) \
59490 + static inline __used initcall_t __inittest(void) \
59491 { return initfn; } \
59492 int init_module(void) __attribute__((alias(#initfn)));
59493
59494 /* This is only required if you want to be unloadable. */
59495 #define module_exit(exitfn) \
59496 - static inline exitcall_t __exittest(void) \
59497 + static inline __used exitcall_t __exittest(void) \
59498 { return exitfn; } \
59499 void cleanup_module(void) __attribute__((alias(#exitfn)));
59500
59501 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
59502 index 32574ee..00d4ef1 100644
59503 --- a/include/linux/init_task.h
59504 +++ b/include/linux/init_task.h
59505 @@ -128,6 +128,12 @@ extern struct cred init_cred;
59506
59507 #define INIT_TASK_COMM "swapper"
59508
59509 +#ifdef CONFIG_X86
59510 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
59511 +#else
59512 +#define INIT_TASK_THREAD_INFO
59513 +#endif
59514 +
59515 /*
59516 * INIT_TASK is used to set up the first task table, touch at
59517 * your own risk!. Base=0, limit=0x1fffff (=2MB)
59518 @@ -166,6 +172,7 @@ extern struct cred init_cred;
59519 RCU_INIT_POINTER(.cred, &init_cred), \
59520 .comm = INIT_TASK_COMM, \
59521 .thread = INIT_THREAD, \
59522 + INIT_TASK_THREAD_INFO \
59523 .fs = &init_fs, \
59524 .files = &init_files, \
59525 .signal = &init_signals, \
59526 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
59527 index e6ca56d..8583707 100644
59528 --- a/include/linux/intel-iommu.h
59529 +++ b/include/linux/intel-iommu.h
59530 @@ -296,7 +296,7 @@ struct iommu_flush {
59531 u8 fm, u64 type);
59532 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
59533 unsigned int size_order, u64 type);
59534 -};
59535 +} __no_const;
59536
59537 enum {
59538 SR_DMAR_FECTL_REG,
59539 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
59540 index a64b00e..464d8bc 100644
59541 --- a/include/linux/interrupt.h
59542 +++ b/include/linux/interrupt.h
59543 @@ -441,7 +441,7 @@ enum
59544 /* map softirq index to softirq name. update 'softirq_to_name' in
59545 * kernel/softirq.c when adding a new softirq.
59546 */
59547 -extern char *softirq_to_name[NR_SOFTIRQS];
59548 +extern const char * const softirq_to_name[NR_SOFTIRQS];
59549
59550 /* softirq mask and active fields moved to irq_cpustat_t in
59551 * asm/hardirq.h to get better cache usage. KAO
59552 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
59553
59554 struct softirq_action
59555 {
59556 - void (*action)(struct softirq_action *);
59557 + void (*action)(void);
59558 };
59559
59560 asmlinkage void do_softirq(void);
59561 asmlinkage void __do_softirq(void);
59562 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
59563 +extern void open_softirq(int nr, void (*action)(void));
59564 extern void softirq_init(void);
59565 static inline void __raise_softirq_irqoff(unsigned int nr)
59566 {
59567 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
59568 index 3875719..4cd454c 100644
59569 --- a/include/linux/kallsyms.h
59570 +++ b/include/linux/kallsyms.h
59571 @@ -15,7 +15,8 @@
59572
59573 struct module;
59574
59575 -#ifdef CONFIG_KALLSYMS
59576 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
59577 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59578 /* Lookup the address for a symbol. Returns 0 if not found. */
59579 unsigned long kallsyms_lookup_name(const char *name);
59580
59581 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
59582 /* Stupid that this does nothing, but I didn't create this mess. */
59583 #define __print_symbol(fmt, addr)
59584 #endif /*CONFIG_KALLSYMS*/
59585 +#else /* when included by kallsyms.c, vsnprintf.c, or
59586 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
59587 +extern void __print_symbol(const char *fmt, unsigned long address);
59588 +extern int sprint_backtrace(char *buffer, unsigned long address);
59589 +extern int sprint_symbol(char *buffer, unsigned long address);
59590 +const char *kallsyms_lookup(unsigned long addr,
59591 + unsigned long *symbolsize,
59592 + unsigned long *offset,
59593 + char **modname, char *namebuf);
59594 +#endif
59595
59596 /* This macro allows us to keep printk typechecking */
59597 static __printf(1, 2)
59598 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
59599 index fa39183..40160be 100644
59600 --- a/include/linux/kgdb.h
59601 +++ b/include/linux/kgdb.h
59602 @@ -53,7 +53,7 @@ extern int kgdb_connected;
59603 extern int kgdb_io_module_registered;
59604
59605 extern atomic_t kgdb_setting_breakpoint;
59606 -extern atomic_t kgdb_cpu_doing_single_step;
59607 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
59608
59609 extern struct task_struct *kgdb_usethread;
59610 extern struct task_struct *kgdb_contthread;
59611 @@ -251,7 +251,7 @@ struct kgdb_arch {
59612 void (*disable_hw_break)(struct pt_regs *regs);
59613 void (*remove_all_hw_break)(void);
59614 void (*correct_hw_break)(void);
59615 -};
59616 +} __do_const;
59617
59618 /**
59619 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
59620 @@ -276,7 +276,7 @@ struct kgdb_io {
59621 void (*pre_exception) (void);
59622 void (*post_exception) (void);
59623 int is_console;
59624 -};
59625 +} __do_const;
59626
59627 extern struct kgdb_arch arch_kgdb_ops;
59628
59629 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
59630 index b16f653..eb908f4 100644
59631 --- a/include/linux/kmod.h
59632 +++ b/include/linux/kmod.h
59633 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
59634 * usually useless though. */
59635 extern __printf(2, 3)
59636 int __request_module(bool wait, const char *name, ...);
59637 +extern __printf(3, 4)
59638 +int ___request_module(bool wait, char *param_name, const char *name, ...);
59639 #define request_module(mod...) __request_module(true, mod)
59640 #define request_module_nowait(mod...) __request_module(false, mod)
59641 #define try_then_request_module(x, mod...) \
59642 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
59643 index d526231..086e89b 100644
59644 --- a/include/linux/kvm_host.h
59645 +++ b/include/linux/kvm_host.h
59646 @@ -308,7 +308,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
59647 void vcpu_load(struct kvm_vcpu *vcpu);
59648 void vcpu_put(struct kvm_vcpu *vcpu);
59649
59650 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
59651 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
59652 struct module *module);
59653 void kvm_exit(void);
59654
59655 @@ -454,7 +454,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
59656 struct kvm_guest_debug *dbg);
59657 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
59658
59659 -int kvm_arch_init(void *opaque);
59660 +int kvm_arch_init(const void *opaque);
59661 void kvm_arch_exit(void);
59662
59663 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
59664 diff --git a/include/linux/libata.h b/include/linux/libata.h
59665 index cafc09a..d7e7829 100644
59666 --- a/include/linux/libata.h
59667 +++ b/include/linux/libata.h
59668 @@ -909,7 +909,7 @@ struct ata_port_operations {
59669 * fields must be pointers.
59670 */
59671 const struct ata_port_operations *inherits;
59672 -};
59673 +} __do_const;
59674
59675 struct ata_port_info {
59676 unsigned long flags;
59677 diff --git a/include/linux/mca.h b/include/linux/mca.h
59678 index 3797270..7765ede 100644
59679 --- a/include/linux/mca.h
59680 +++ b/include/linux/mca.h
59681 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
59682 int region);
59683 void * (*mca_transform_memory)(struct mca_device *,
59684 void *memory);
59685 -};
59686 +} __no_const;
59687
59688 struct mca_bus {
59689 u64 default_dma_mask;
59690 diff --git a/include/linux/memory.h b/include/linux/memory.h
59691 index 935699b..11042cc 100644
59692 --- a/include/linux/memory.h
59693 +++ b/include/linux/memory.h
59694 @@ -144,7 +144,7 @@ struct memory_accessor {
59695 size_t count);
59696 ssize_t (*write)(struct memory_accessor *, const char *buf,
59697 off_t offset, size_t count);
59698 -};
59699 +} __no_const;
59700
59701 /*
59702 * Kernel text modification mutex, used for code patching. Users of this lock
59703 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
59704 index 9970337..9444122 100644
59705 --- a/include/linux/mfd/abx500.h
59706 +++ b/include/linux/mfd/abx500.h
59707 @@ -188,6 +188,7 @@ struct abx500_ops {
59708 int (*event_registers_startup_state_get) (struct device *, u8 *);
59709 int (*startup_irq_enabled) (struct device *, unsigned int);
59710 };
59711 +typedef struct abx500_ops __no_const abx500_ops_no_const;
59712
59713 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
59714 void abx500_remove_ops(struct device *dev);
59715 diff --git a/include/linux/mm.h b/include/linux/mm.h
59716 index 4baadd1..2e0b45e 100644
59717 --- a/include/linux/mm.h
59718 +++ b/include/linux/mm.h
59719 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
59720
59721 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
59722 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
59723 +
59724 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
59725 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
59726 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
59727 +#else
59728 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
59729 +#endif
59730 +
59731 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
59732 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
59733
59734 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
59735 int set_page_dirty_lock(struct page *page);
59736 int clear_page_dirty_for_io(struct page *page);
59737
59738 -/* Is the vma a continuation of the stack vma above it? */
59739 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
59740 -{
59741 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
59742 -}
59743 -
59744 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
59745 - unsigned long addr)
59746 -{
59747 - return (vma->vm_flags & VM_GROWSDOWN) &&
59748 - (vma->vm_start == addr) &&
59749 - !vma_growsdown(vma->vm_prev, addr);
59750 -}
59751 -
59752 -/* Is the vma a continuation of the stack vma below it? */
59753 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
59754 -{
59755 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
59756 -}
59757 -
59758 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
59759 - unsigned long addr)
59760 -{
59761 - return (vma->vm_flags & VM_GROWSUP) &&
59762 - (vma->vm_end == addr) &&
59763 - !vma_growsup(vma->vm_next, addr);
59764 -}
59765 -
59766 extern unsigned long move_page_tables(struct vm_area_struct *vma,
59767 unsigned long old_addr, struct vm_area_struct *new_vma,
59768 unsigned long new_addr, unsigned long len);
59769 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
59770 }
59771 #endif
59772
59773 +#ifdef CONFIG_MMU
59774 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
59775 +#else
59776 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
59777 +{
59778 + return __pgprot(0);
59779 +}
59780 +#endif
59781 +
59782 int vma_wants_writenotify(struct vm_area_struct *vma);
59783
59784 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
59785 @@ -1419,6 +1407,7 @@ out:
59786 }
59787
59788 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
59789 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
59790
59791 extern unsigned long do_brk(unsigned long, unsigned long);
59792
59793 @@ -1476,6 +1465,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
59794 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
59795 struct vm_area_struct **pprev);
59796
59797 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
59798 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
59799 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
59800 +
59801 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
59802 NULL if none. Assume start_addr < end_addr. */
59803 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
59804 @@ -1492,15 +1485,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
59805 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
59806 }
59807
59808 -#ifdef CONFIG_MMU
59809 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
59810 -#else
59811 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
59812 -{
59813 - return __pgprot(0);
59814 -}
59815 -#endif
59816 -
59817 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
59818 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
59819 unsigned long pfn, unsigned long size, pgprot_t);
59820 @@ -1614,7 +1598,7 @@ extern int unpoison_memory(unsigned long pfn);
59821 extern int sysctl_memory_failure_early_kill;
59822 extern int sysctl_memory_failure_recovery;
59823 extern void shake_page(struct page *p, int access);
59824 -extern atomic_long_t mce_bad_pages;
59825 +extern atomic_long_unchecked_t mce_bad_pages;
59826 extern int soft_offline_page(struct page *page, int flags);
59827
59828 extern void dump_page(struct page *page);
59829 @@ -1628,5 +1612,11 @@ extern void copy_user_huge_page(struct page *dst, struct page *src,
59830 unsigned int pages_per_huge_page);
59831 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
59832
59833 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59834 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
59835 +#else
59836 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
59837 +#endif
59838 +
59839 #endif /* __KERNEL__ */
59840 #endif /* _LINUX_MM_H */
59841 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
59842 index 5b42f1b..759e4b4 100644
59843 --- a/include/linux/mm_types.h
59844 +++ b/include/linux/mm_types.h
59845 @@ -253,6 +253,8 @@ struct vm_area_struct {
59846 #ifdef CONFIG_NUMA
59847 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
59848 #endif
59849 +
59850 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
59851 };
59852
59853 struct core_thread {
59854 @@ -389,6 +391,24 @@ struct mm_struct {
59855 #ifdef CONFIG_CPUMASK_OFFSTACK
59856 struct cpumask cpumask_allocation;
59857 #endif
59858 +
59859 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59860 + unsigned long pax_flags;
59861 +#endif
59862 +
59863 +#ifdef CONFIG_PAX_DLRESOLVE
59864 + unsigned long call_dl_resolve;
59865 +#endif
59866 +
59867 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59868 + unsigned long call_syscall;
59869 +#endif
59870 +
59871 +#ifdef CONFIG_PAX_ASLR
59872 + unsigned long delta_mmap; /* randomized offset */
59873 + unsigned long delta_stack; /* randomized offset */
59874 +#endif
59875 +
59876 };
59877
59878 static inline void mm_init_cpumask(struct mm_struct *mm)
59879 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
59880 index 1d1b1e1..2a13c78 100644
59881 --- a/include/linux/mmu_notifier.h
59882 +++ b/include/linux/mmu_notifier.h
59883 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
59884 */
59885 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
59886 ({ \
59887 - pte_t __pte; \
59888 + pte_t ___pte; \
59889 struct vm_area_struct *___vma = __vma; \
59890 unsigned long ___address = __address; \
59891 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
59892 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
59893 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
59894 - __pte; \
59895 + ___pte; \
59896 })
59897
59898 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
59899 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
59900 index 188cb2f..d78409b 100644
59901 --- a/include/linux/mmzone.h
59902 +++ b/include/linux/mmzone.h
59903 @@ -369,7 +369,7 @@ struct zone {
59904 unsigned long flags; /* zone flags, see below */
59905
59906 /* Zone statistics */
59907 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
59908 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
59909
59910 /*
59911 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
59912 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
59913 index 468819c..17b9db3 100644
59914 --- a/include/linux/mod_devicetable.h
59915 +++ b/include/linux/mod_devicetable.h
59916 @@ -12,7 +12,7 @@
59917 typedef unsigned long kernel_ulong_t;
59918 #endif
59919
59920 -#define PCI_ANY_ID (~0)
59921 +#define PCI_ANY_ID ((__u16)~0)
59922
59923 struct pci_device_id {
59924 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
59925 @@ -131,7 +131,7 @@ struct usb_device_id {
59926 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
59927 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
59928
59929 -#define HID_ANY_ID (~0)
59930 +#define HID_ANY_ID (~0U)
59931
59932 struct hid_device_id {
59933 __u16 bus;
59934 diff --git a/include/linux/module.h b/include/linux/module.h
59935 index 3cb7839..511cb87 100644
59936 --- a/include/linux/module.h
59937 +++ b/include/linux/module.h
59938 @@ -17,6 +17,7 @@
59939 #include <linux/moduleparam.h>
59940 #include <linux/tracepoint.h>
59941 #include <linux/export.h>
59942 +#include <linux/fs.h>
59943
59944 #include <linux/percpu.h>
59945 #include <asm/module.h>
59946 @@ -261,19 +262,16 @@ struct module
59947 int (*init)(void);
59948
59949 /* If this is non-NULL, vfree after init() returns */
59950 - void *module_init;
59951 + void *module_init_rx, *module_init_rw;
59952
59953 /* Here is the actual code + data, vfree'd on unload. */
59954 - void *module_core;
59955 + void *module_core_rx, *module_core_rw;
59956
59957 /* Here are the sizes of the init and core sections */
59958 - unsigned int init_size, core_size;
59959 + unsigned int init_size_rw, core_size_rw;
59960
59961 /* The size of the executable code in each section. */
59962 - unsigned int init_text_size, core_text_size;
59963 -
59964 - /* Size of RO sections of the module (text+rodata) */
59965 - unsigned int init_ro_size, core_ro_size;
59966 + unsigned int init_size_rx, core_size_rx;
59967
59968 /* Arch-specific module values */
59969 struct mod_arch_specific arch;
59970 @@ -329,6 +327,10 @@ struct module
59971 #ifdef CONFIG_EVENT_TRACING
59972 struct ftrace_event_call **trace_events;
59973 unsigned int num_trace_events;
59974 + struct file_operations trace_id;
59975 + struct file_operations trace_enable;
59976 + struct file_operations trace_format;
59977 + struct file_operations trace_filter;
59978 #endif
59979 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
59980 unsigned int num_ftrace_callsites;
59981 @@ -379,16 +381,46 @@ bool is_module_address(unsigned long addr);
59982 bool is_module_percpu_address(unsigned long addr);
59983 bool is_module_text_address(unsigned long addr);
59984
59985 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
59986 +{
59987 +
59988 +#ifdef CONFIG_PAX_KERNEXEC
59989 + if (ktla_ktva(addr) >= (unsigned long)start &&
59990 + ktla_ktva(addr) < (unsigned long)start + size)
59991 + return 1;
59992 +#endif
59993 +
59994 + return ((void *)addr >= start && (void *)addr < start + size);
59995 +}
59996 +
59997 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
59998 +{
59999 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
60000 +}
60001 +
60002 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
60003 +{
60004 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
60005 +}
60006 +
60007 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
60008 +{
60009 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
60010 +}
60011 +
60012 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
60013 +{
60014 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
60015 +}
60016 +
60017 static inline int within_module_core(unsigned long addr, struct module *mod)
60018 {
60019 - return (unsigned long)mod->module_core <= addr &&
60020 - addr < (unsigned long)mod->module_core + mod->core_size;
60021 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
60022 }
60023
60024 static inline int within_module_init(unsigned long addr, struct module *mod)
60025 {
60026 - return (unsigned long)mod->module_init <= addr &&
60027 - addr < (unsigned long)mod->module_init + mod->init_size;
60028 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
60029 }
60030
60031 /* Search for module by name: must hold module_mutex. */
60032 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
60033 index b2be02e..6a9fdb1 100644
60034 --- a/include/linux/moduleloader.h
60035 +++ b/include/linux/moduleloader.h
60036 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
60037 sections. Returns NULL on failure. */
60038 void *module_alloc(unsigned long size);
60039
60040 +#ifdef CONFIG_PAX_KERNEXEC
60041 +void *module_alloc_exec(unsigned long size);
60042 +#else
60043 +#define module_alloc_exec(x) module_alloc(x)
60044 +#endif
60045 +
60046 /* Free memory returned from module_alloc. */
60047 void module_free(struct module *mod, void *module_region);
60048
60049 +#ifdef CONFIG_PAX_KERNEXEC
60050 +void module_free_exec(struct module *mod, void *module_region);
60051 +#else
60052 +#define module_free_exec(x, y) module_free((x), (y))
60053 +#endif
60054 +
60055 /* Apply the given relocation to the (simplified) ELF. Return -error
60056 or 0. */
60057 int apply_relocate(Elf_Shdr *sechdrs,
60058 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
60059 index 7939f63..ec6df57 100644
60060 --- a/include/linux/moduleparam.h
60061 +++ b/include/linux/moduleparam.h
60062 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
60063 * @len is usually just sizeof(string).
60064 */
60065 #define module_param_string(name, string, len, perm) \
60066 - static const struct kparam_string __param_string_##name \
60067 + static const struct kparam_string __param_string_##name __used \
60068 = { len, string }; \
60069 __module_param_call(MODULE_PARAM_PREFIX, name, \
60070 &param_ops_string, \
60071 @@ -395,7 +395,7 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
60072 * module_param_named() for why this might be necessary.
60073 */
60074 #define module_param_array_named(name, array, type, nump, perm) \
60075 - static const struct kparam_array __param_arr_##name \
60076 + static const struct kparam_array __param_arr_##name __used \
60077 = { .max = ARRAY_SIZE(array), .num = nump, \
60078 .ops = &param_ops_##type, \
60079 .elemsize = sizeof(array[0]), .elem = array }; \
60080 diff --git a/include/linux/namei.h b/include/linux/namei.h
60081 index ffc0213..2c1f2cb 100644
60082 --- a/include/linux/namei.h
60083 +++ b/include/linux/namei.h
60084 @@ -24,7 +24,7 @@ struct nameidata {
60085 unsigned seq;
60086 int last_type;
60087 unsigned depth;
60088 - char *saved_names[MAX_NESTED_LINKS + 1];
60089 + const char *saved_names[MAX_NESTED_LINKS + 1];
60090
60091 /* Intent data */
60092 union {
60093 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
60094 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
60095 extern void unlock_rename(struct dentry *, struct dentry *);
60096
60097 -static inline void nd_set_link(struct nameidata *nd, char *path)
60098 +static inline void nd_set_link(struct nameidata *nd, const char *path)
60099 {
60100 nd->saved_names[nd->depth] = path;
60101 }
60102
60103 -static inline char *nd_get_link(struct nameidata *nd)
60104 +static inline const char *nd_get_link(const struct nameidata *nd)
60105 {
60106 return nd->saved_names[nd->depth];
60107 }
60108 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
60109 index a82ad4d..be68b4b 100644
60110 --- a/include/linux/netdevice.h
60111 +++ b/include/linux/netdevice.h
60112 @@ -949,6 +949,7 @@ struct net_device_ops {
60113 int (*ndo_set_features)(struct net_device *dev,
60114 u32 features);
60115 };
60116 +typedef struct net_device_ops __no_const net_device_ops_no_const;
60117
60118 /*
60119 * The DEVICE structure.
60120 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
60121 new file mode 100644
60122 index 0000000..33f4af8
60123 --- /dev/null
60124 +++ b/include/linux/netfilter/xt_gradm.h
60125 @@ -0,0 +1,9 @@
60126 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
60127 +#define _LINUX_NETFILTER_XT_GRADM_H 1
60128 +
60129 +struct xt_gradm_mtinfo {
60130 + __u16 flags;
60131 + __u16 invflags;
60132 +};
60133 +
60134 +#endif
60135 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
60136 index c65a18a..0c05f3a 100644
60137 --- a/include/linux/of_pdt.h
60138 +++ b/include/linux/of_pdt.h
60139 @@ -32,7 +32,7 @@ struct of_pdt_ops {
60140
60141 /* return 0 on success; fill in 'len' with number of bytes in path */
60142 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
60143 -};
60144 +} __no_const;
60145
60146 extern void *prom_early_alloc(unsigned long size);
60147
60148 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
60149 index a4c5624..79d6d88 100644
60150 --- a/include/linux/oprofile.h
60151 +++ b/include/linux/oprofile.h
60152 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
60153 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
60154 char const * name, ulong * val);
60155
60156 -/** Create a file for read-only access to an atomic_t. */
60157 +/** Create a file for read-only access to an atomic_unchecked_t. */
60158 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
60159 - char const * name, atomic_t * val);
60160 + char const * name, atomic_unchecked_t * val);
60161
60162 /** create a directory */
60163 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
60164 diff --git a/include/linux/padata.h b/include/linux/padata.h
60165 index 4633b2f..988bc08 100644
60166 --- a/include/linux/padata.h
60167 +++ b/include/linux/padata.h
60168 @@ -129,7 +129,7 @@ struct parallel_data {
60169 struct padata_instance *pinst;
60170 struct padata_parallel_queue __percpu *pqueue;
60171 struct padata_serial_queue __percpu *squeue;
60172 - atomic_t seq_nr;
60173 + atomic_unchecked_t seq_nr;
60174 atomic_t reorder_objects;
60175 atomic_t refcnt;
60176 unsigned int max_seq_nr;
60177 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
60178 index b1f8912..c955bff 100644
60179 --- a/include/linux/perf_event.h
60180 +++ b/include/linux/perf_event.h
60181 @@ -748,8 +748,8 @@ struct perf_event {
60182
60183 enum perf_event_active_state state;
60184 unsigned int attach_state;
60185 - local64_t count;
60186 - atomic64_t child_count;
60187 + local64_t count; /* PaX: fix it one day */
60188 + atomic64_unchecked_t child_count;
60189
60190 /*
60191 * These are the total time in nanoseconds that the event
60192 @@ -800,8 +800,8 @@ struct perf_event {
60193 * These accumulate total time (in nanoseconds) that children
60194 * events have been enabled and running, respectively.
60195 */
60196 - atomic64_t child_total_time_enabled;
60197 - atomic64_t child_total_time_running;
60198 + atomic64_unchecked_t child_total_time_enabled;
60199 + atomic64_unchecked_t child_total_time_running;
60200
60201 /*
60202 * Protect attach/detach and child_list:
60203 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
60204 index 77257c9..51d473a 100644
60205 --- a/include/linux/pipe_fs_i.h
60206 +++ b/include/linux/pipe_fs_i.h
60207 @@ -46,9 +46,9 @@ struct pipe_buffer {
60208 struct pipe_inode_info {
60209 wait_queue_head_t wait;
60210 unsigned int nrbufs, curbuf, buffers;
60211 - unsigned int readers;
60212 - unsigned int writers;
60213 - unsigned int waiting_writers;
60214 + atomic_t readers;
60215 + atomic_t writers;
60216 + atomic_t waiting_writers;
60217 unsigned int r_counter;
60218 unsigned int w_counter;
60219 struct page *tmp_page;
60220 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
60221 index d3085e7..fd01052 100644
60222 --- a/include/linux/pm_runtime.h
60223 +++ b/include/linux/pm_runtime.h
60224 @@ -95,7 +95,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
60225
60226 static inline void pm_runtime_mark_last_busy(struct device *dev)
60227 {
60228 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
60229 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
60230 }
60231
60232 #else /* !CONFIG_PM_RUNTIME */
60233 diff --git a/include/linux/poison.h b/include/linux/poison.h
60234 index 79159de..f1233a9 100644
60235 --- a/include/linux/poison.h
60236 +++ b/include/linux/poison.h
60237 @@ -19,8 +19,8 @@
60238 * under normal circumstances, used to verify that nobody uses
60239 * non-initialized list entries.
60240 */
60241 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
60242 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
60243 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
60244 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
60245
60246 /********** include/linux/timer.h **********/
60247 /*
60248 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
60249 index 58969b2..ead129b 100644
60250 --- a/include/linux/preempt.h
60251 +++ b/include/linux/preempt.h
60252 @@ -123,7 +123,7 @@ struct preempt_ops {
60253 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
60254 void (*sched_out)(struct preempt_notifier *notifier,
60255 struct task_struct *next);
60256 -};
60257 +} __no_const;
60258
60259 /**
60260 * preempt_notifier - key for installing preemption notifiers
60261 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
60262 index 643b96c..ef55a9c 100644
60263 --- a/include/linux/proc_fs.h
60264 +++ b/include/linux/proc_fs.h
60265 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
60266 return proc_create_data(name, mode, parent, proc_fops, NULL);
60267 }
60268
60269 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
60270 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
60271 +{
60272 +#ifdef CONFIG_GRKERNSEC_PROC_USER
60273 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
60274 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60275 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
60276 +#else
60277 + return proc_create_data(name, mode, parent, proc_fops, NULL);
60278 +#endif
60279 +}
60280 +
60281 +
60282 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
60283 mode_t mode, struct proc_dir_entry *base,
60284 read_proc_t *read_proc, void * data)
60285 @@ -258,7 +271,7 @@ union proc_op {
60286 int (*proc_show)(struct seq_file *m,
60287 struct pid_namespace *ns, struct pid *pid,
60288 struct task_struct *task);
60289 -};
60290 +} __no_const;
60291
60292 struct ctl_table_header;
60293 struct ctl_table;
60294 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
60295 index 800f113..e9ee2e3 100644
60296 --- a/include/linux/ptrace.h
60297 +++ b/include/linux/ptrace.h
60298 @@ -129,10 +129,12 @@ extern void __ptrace_unlink(struct task_struct *child);
60299 extern void exit_ptrace(struct task_struct *tracer);
60300 #define PTRACE_MODE_READ 1
60301 #define PTRACE_MODE_ATTACH 2
60302 -/* Returns 0 on success, -errno on denial. */
60303 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
60304 /* Returns true on success, false on denial. */
60305 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
60306 +/* Returns true on success, false on denial. */
60307 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
60308 +/* Returns true on success, false on denial. */
60309 +extern bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode);
60310
60311 static inline int ptrace_reparented(struct task_struct *child)
60312 {
60313 diff --git a/include/linux/random.h b/include/linux/random.h
60314 index 8f74538..02a1012 100644
60315 --- a/include/linux/random.h
60316 +++ b/include/linux/random.h
60317 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
60318
60319 u32 prandom32(struct rnd_state *);
60320
60321 +static inline unsigned long pax_get_random_long(void)
60322 +{
60323 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
60324 +}
60325 +
60326 /*
60327 * Handle minimum values for seeds
60328 */
60329 static inline u32 __seed(u32 x, u32 m)
60330 {
60331 - return (x < m) ? x + m : x;
60332 + return (x <= m) ? x + m + 1 : x;
60333 }
60334
60335 /**
60336 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
60337 index e0879a7..a12f962 100644
60338 --- a/include/linux/reboot.h
60339 +++ b/include/linux/reboot.h
60340 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
60341 * Architecture-specific implementations of sys_reboot commands.
60342 */
60343
60344 -extern void machine_restart(char *cmd);
60345 -extern void machine_halt(void);
60346 -extern void machine_power_off(void);
60347 +extern void machine_restart(char *cmd) __noreturn;
60348 +extern void machine_halt(void) __noreturn;
60349 +extern void machine_power_off(void) __noreturn;
60350
60351 extern void machine_shutdown(void);
60352 struct pt_regs;
60353 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
60354 */
60355
60356 extern void kernel_restart_prepare(char *cmd);
60357 -extern void kernel_restart(char *cmd);
60358 -extern void kernel_halt(void);
60359 -extern void kernel_power_off(void);
60360 +extern void kernel_restart(char *cmd) __noreturn;
60361 +extern void kernel_halt(void) __noreturn;
60362 +extern void kernel_power_off(void) __noreturn;
60363
60364 extern int C_A_D; /* for sysctl */
60365 void ctrl_alt_del(void);
60366 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
60367 * Emergency restart, callable from an interrupt handler.
60368 */
60369
60370 -extern void emergency_restart(void);
60371 +extern void emergency_restart(void) __noreturn;
60372 #include <asm/emergency-restart.h>
60373
60374 #endif
60375 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
60376 index 96d465f..b084e05 100644
60377 --- a/include/linux/reiserfs_fs.h
60378 +++ b/include/linux/reiserfs_fs.h
60379 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60380 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60381
60382 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60383 -#define get_generation(s) atomic_read (&fs_generation(s))
60384 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60385 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60386 #define __fs_changed(gen,s) (gen != get_generation (s))
60387 #define fs_changed(gen,s) \
60388 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
60389 index 52c83b6..18ed7eb 100644
60390 --- a/include/linux/reiserfs_fs_sb.h
60391 +++ b/include/linux/reiserfs_fs_sb.h
60392 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
60393 /* Comment? -Hans */
60394 wait_queue_head_t s_wait;
60395 /* To be obsoleted soon by per buffer seals.. -Hans */
60396 - atomic_t s_generation_counter; // increased by one every time the
60397 + atomic_unchecked_t s_generation_counter; // increased by one every time the
60398 // tree gets re-balanced
60399 unsigned long s_properties; /* File system properties. Currently holds
60400 on-disk FS format */
60401 diff --git a/include/linux/relay.h b/include/linux/relay.h
60402 index 14a86bc..17d0700 100644
60403 --- a/include/linux/relay.h
60404 +++ b/include/linux/relay.h
60405 @@ -159,7 +159,7 @@ struct rchan_callbacks
60406 * The callback should return 0 if successful, negative if not.
60407 */
60408 int (*remove_buf_file)(struct dentry *dentry);
60409 -};
60410 +} __no_const;
60411
60412 /*
60413 * CONFIG_RELAY kernel API, kernel/relay.c
60414 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
60415 index c6c6084..5bf1212 100644
60416 --- a/include/linux/rfkill.h
60417 +++ b/include/linux/rfkill.h
60418 @@ -147,6 +147,7 @@ struct rfkill_ops {
60419 void (*query)(struct rfkill *rfkill, void *data);
60420 int (*set_block)(void *data, bool blocked);
60421 };
60422 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
60423
60424 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
60425 /**
60426 diff --git a/include/linux/rio.h b/include/linux/rio.h
60427 index 4d50611..c6858a2 100644
60428 --- a/include/linux/rio.h
60429 +++ b/include/linux/rio.h
60430 @@ -315,7 +315,7 @@ struct rio_ops {
60431 int mbox, void *buffer, size_t len);
60432 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
60433 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
60434 -};
60435 +} __no_const;
60436
60437 #define RIO_RESOURCE_MEM 0x00000100
60438 #define RIO_RESOURCE_DOORBELL 0x00000200
60439 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
60440 index 2148b12..519b820 100644
60441 --- a/include/linux/rmap.h
60442 +++ b/include/linux/rmap.h
60443 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
60444 void anon_vma_init(void); /* create anon_vma_cachep */
60445 int anon_vma_prepare(struct vm_area_struct *);
60446 void unlink_anon_vmas(struct vm_area_struct *);
60447 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
60448 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
60449 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
60450 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
60451 void __anon_vma_link(struct vm_area_struct *);
60452
60453 static inline void anon_vma_merge(struct vm_area_struct *vma,
60454 diff --git a/include/linux/sched.h b/include/linux/sched.h
60455 index 1c4f3e9..e96dced 100644
60456 --- a/include/linux/sched.h
60457 +++ b/include/linux/sched.h
60458 @@ -101,6 +101,7 @@ struct bio_list;
60459 struct fs_struct;
60460 struct perf_event_context;
60461 struct blk_plug;
60462 +struct linux_binprm;
60463
60464 /*
60465 * List of flags we want to share for kernel threads,
60466 @@ -380,10 +381,13 @@ struct user_namespace;
60467 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
60468
60469 extern int sysctl_max_map_count;
60470 +extern unsigned long sysctl_heap_stack_gap;
60471
60472 #include <linux/aio.h>
60473
60474 #ifdef CONFIG_MMU
60475 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
60476 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
60477 extern void arch_pick_mmap_layout(struct mm_struct *mm);
60478 extern unsigned long
60479 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
60480 @@ -629,6 +633,17 @@ struct signal_struct {
60481 #ifdef CONFIG_TASKSTATS
60482 struct taskstats *stats;
60483 #endif
60484 +
60485 +#ifdef CONFIG_GRKERNSEC
60486 + u32 curr_ip;
60487 + u32 saved_ip;
60488 + u32 gr_saddr;
60489 + u32 gr_daddr;
60490 + u16 gr_sport;
60491 + u16 gr_dport;
60492 + u8 used_accept:1;
60493 +#endif
60494 +
60495 #ifdef CONFIG_AUDIT
60496 unsigned audit_tty;
60497 struct tty_audit_buf *tty_audit_buf;
60498 @@ -710,6 +725,11 @@ struct user_struct {
60499 struct key *session_keyring; /* UID's default session keyring */
60500 #endif
60501
60502 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60503 + unsigned int banned;
60504 + unsigned long ban_expires;
60505 +#endif
60506 +
60507 /* Hash table maintenance information */
60508 struct hlist_node uidhash_node;
60509 uid_t uid;
60510 @@ -1337,8 +1357,8 @@ struct task_struct {
60511 struct list_head thread_group;
60512
60513 struct completion *vfork_done; /* for vfork() */
60514 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
60515 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60516 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
60517 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60518
60519 cputime_t utime, stime, utimescaled, stimescaled;
60520 cputime_t gtime;
60521 @@ -1354,13 +1374,6 @@ struct task_struct {
60522 struct task_cputime cputime_expires;
60523 struct list_head cpu_timers[3];
60524
60525 -/* process credentials */
60526 - const struct cred __rcu *real_cred; /* objective and real subjective task
60527 - * credentials (COW) */
60528 - const struct cred __rcu *cred; /* effective (overridable) subjective task
60529 - * credentials (COW) */
60530 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60531 -
60532 char comm[TASK_COMM_LEN]; /* executable name excluding path
60533 - access with [gs]et_task_comm (which lock
60534 it with task_lock())
60535 @@ -1377,8 +1390,16 @@ struct task_struct {
60536 #endif
60537 /* CPU-specific state of this task */
60538 struct thread_struct thread;
60539 +/* thread_info moved to task_struct */
60540 +#ifdef CONFIG_X86
60541 + struct thread_info tinfo;
60542 +#endif
60543 /* filesystem information */
60544 struct fs_struct *fs;
60545 +
60546 + const struct cred __rcu *cred; /* effective (overridable) subjective task
60547 + * credentials (COW) */
60548 +
60549 /* open file information */
60550 struct files_struct *files;
60551 /* namespaces */
60552 @@ -1425,6 +1446,11 @@ struct task_struct {
60553 struct rt_mutex_waiter *pi_blocked_on;
60554 #endif
60555
60556 +/* process credentials */
60557 + const struct cred __rcu *real_cred; /* objective and real subjective task
60558 + * credentials (COW) */
60559 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60560 +
60561 #ifdef CONFIG_DEBUG_MUTEXES
60562 /* mutex deadlock detection */
60563 struct mutex_waiter *blocked_on;
60564 @@ -1540,6 +1566,22 @@ struct task_struct {
60565 unsigned long default_timer_slack_ns;
60566
60567 struct list_head *scm_work_list;
60568 +
60569 +#ifdef CONFIG_GRKERNSEC
60570 + /* grsecurity */
60571 + const struct cred *delayed_cred;
60572 + struct dentry *gr_chroot_dentry;
60573 + struct acl_subject_label *acl;
60574 + struct acl_role_label *role;
60575 + struct file *exec_file;
60576 + u16 acl_role_id;
60577 + /* is this the task that authenticated to the special role */
60578 + u8 acl_sp_role;
60579 + u8 is_writable;
60580 + u8 brute;
60581 + u8 gr_is_chrooted;
60582 +#endif
60583 +
60584 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
60585 /* Index of current stored address in ret_stack */
60586 int curr_ret_stack;
60587 @@ -1574,6 +1616,51 @@ struct task_struct {
60588 #endif
60589 };
60590
60591 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
60592 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
60593 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
60594 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
60595 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
60596 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
60597 +
60598 +#ifdef CONFIG_PAX_SOFTMODE
60599 +extern int pax_softmode;
60600 +#endif
60601 +
60602 +extern int pax_check_flags(unsigned long *);
60603 +
60604 +/* if tsk != current then task_lock must be held on it */
60605 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60606 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
60607 +{
60608 + if (likely(tsk->mm))
60609 + return tsk->mm->pax_flags;
60610 + else
60611 + return 0UL;
60612 +}
60613 +
60614 +/* if tsk != current then task_lock must be held on it */
60615 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
60616 +{
60617 + if (likely(tsk->mm)) {
60618 + tsk->mm->pax_flags = flags;
60619 + return 0;
60620 + }
60621 + return -EINVAL;
60622 +}
60623 +#endif
60624 +
60625 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60626 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
60627 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60628 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60629 +#endif
60630 +
60631 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
60632 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
60633 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
60634 +extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
60635 +
60636 /* Future-safe accessor for struct task_struct's cpus_allowed. */
60637 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
60638
60639 @@ -2081,7 +2168,9 @@ void yield(void);
60640 extern struct exec_domain default_exec_domain;
60641
60642 union thread_union {
60643 +#ifndef CONFIG_X86
60644 struct thread_info thread_info;
60645 +#endif
60646 unsigned long stack[THREAD_SIZE/sizeof(long)];
60647 };
60648
60649 @@ -2114,6 +2203,7 @@ extern struct pid_namespace init_pid_ns;
60650 */
60651
60652 extern struct task_struct *find_task_by_vpid(pid_t nr);
60653 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
60654 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
60655 struct pid_namespace *ns);
60656
60657 @@ -2251,7 +2341,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
60658 extern void exit_itimers(struct signal_struct *);
60659 extern void flush_itimer_signals(void);
60660
60661 -extern NORET_TYPE void do_group_exit(int);
60662 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
60663
60664 extern void daemonize(const char *, ...);
60665 extern int allow_signal(int);
60666 @@ -2416,13 +2506,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
60667
60668 #endif
60669
60670 -static inline int object_is_on_stack(void *obj)
60671 +static inline int object_starts_on_stack(void *obj)
60672 {
60673 - void *stack = task_stack_page(current);
60674 + const void *stack = task_stack_page(current);
60675
60676 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
60677 }
60678
60679 +#ifdef CONFIG_PAX_USERCOPY
60680 +extern int object_is_on_stack(const void *obj, unsigned long len);
60681 +#endif
60682 +
60683 extern void thread_info_cache_init(void);
60684
60685 #ifdef CONFIG_DEBUG_STACK_USAGE
60686 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
60687 index 899fbb4..1cb4138 100644
60688 --- a/include/linux/screen_info.h
60689 +++ b/include/linux/screen_info.h
60690 @@ -43,7 +43,8 @@ struct screen_info {
60691 __u16 pages; /* 0x32 */
60692 __u16 vesa_attributes; /* 0x34 */
60693 __u32 capabilities; /* 0x36 */
60694 - __u8 _reserved[6]; /* 0x3a */
60695 + __u16 vesapm_size; /* 0x3a */
60696 + __u8 _reserved[4]; /* 0x3c */
60697 } __attribute__((packed));
60698
60699 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
60700 diff --git a/include/linux/security.h b/include/linux/security.h
60701 index e8c619d..e0cbd1c 100644
60702 --- a/include/linux/security.h
60703 +++ b/include/linux/security.h
60704 @@ -37,6 +37,7 @@
60705 #include <linux/xfrm.h>
60706 #include <linux/slab.h>
60707 #include <linux/xattr.h>
60708 +#include <linux/grsecurity.h>
60709 #include <net/flow.h>
60710
60711 /* Maximum number of letters for an LSM name string */
60712 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
60713 index 0b69a46..e9e5538 100644
60714 --- a/include/linux/seq_file.h
60715 +++ b/include/linux/seq_file.h
60716 @@ -33,6 +33,7 @@ struct seq_operations {
60717 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
60718 int (*show) (struct seq_file *m, void *v);
60719 };
60720 +typedef struct seq_operations __no_const seq_operations_no_const;
60721
60722 #define SEQ_SKIP 1
60723
60724 diff --git a/include/linux/shm.h b/include/linux/shm.h
60725 index 92808b8..c28cac4 100644
60726 --- a/include/linux/shm.h
60727 +++ b/include/linux/shm.h
60728 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
60729
60730 /* The task created the shm object. NULL if the task is dead. */
60731 struct task_struct *shm_creator;
60732 +#ifdef CONFIG_GRKERNSEC
60733 + time_t shm_createtime;
60734 + pid_t shm_lapid;
60735 +#endif
60736 };
60737
60738 /* shm_mode upper byte flags */
60739 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
60740 index fe86488..1563c1c 100644
60741 --- a/include/linux/skbuff.h
60742 +++ b/include/linux/skbuff.h
60743 @@ -642,7 +642,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
60744 */
60745 static inline int skb_queue_empty(const struct sk_buff_head *list)
60746 {
60747 - return list->next == (struct sk_buff *)list;
60748 + return list->next == (const struct sk_buff *)list;
60749 }
60750
60751 /**
60752 @@ -655,7 +655,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
60753 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
60754 const struct sk_buff *skb)
60755 {
60756 - return skb->next == (struct sk_buff *)list;
60757 + return skb->next == (const struct sk_buff *)list;
60758 }
60759
60760 /**
60761 @@ -668,7 +668,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
60762 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
60763 const struct sk_buff *skb)
60764 {
60765 - return skb->prev == (struct sk_buff *)list;
60766 + return skb->prev == (const struct sk_buff *)list;
60767 }
60768
60769 /**
60770 @@ -1523,7 +1523,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
60771 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
60772 */
60773 #ifndef NET_SKB_PAD
60774 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
60775 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
60776 #endif
60777
60778 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
60779 diff --git a/include/linux/slab.h b/include/linux/slab.h
60780 index 573c809..e84c132 100644
60781 --- a/include/linux/slab.h
60782 +++ b/include/linux/slab.h
60783 @@ -11,12 +11,20 @@
60784
60785 #include <linux/gfp.h>
60786 #include <linux/types.h>
60787 +#include <linux/err.h>
60788
60789 /*
60790 * Flags to pass to kmem_cache_create().
60791 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
60792 */
60793 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
60794 +
60795 +#ifdef CONFIG_PAX_USERCOPY
60796 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
60797 +#else
60798 +#define SLAB_USERCOPY 0x00000000UL
60799 +#endif
60800 +
60801 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
60802 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
60803 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
60804 @@ -87,10 +95,13 @@
60805 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
60806 * Both make kfree a no-op.
60807 */
60808 -#define ZERO_SIZE_PTR ((void *)16)
60809 +#define ZERO_SIZE_PTR \
60810 +({ \
60811 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
60812 + (void *)(-MAX_ERRNO-1L); \
60813 +})
60814
60815 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
60816 - (unsigned long)ZERO_SIZE_PTR)
60817 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
60818
60819 /*
60820 * struct kmem_cache related prototypes
60821 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
60822 void kfree(const void *);
60823 void kzfree(const void *);
60824 size_t ksize(const void *);
60825 +void check_object_size(const void *ptr, unsigned long n, bool to);
60826
60827 /*
60828 * Allocator specific definitions. These are mainly used to establish optimized
60829 @@ -353,4 +365,59 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
60830
60831 void __init kmem_cache_init_late(void);
60832
60833 +#define kmalloc(x, y) \
60834 +({ \
60835 + void *___retval; \
60836 + intoverflow_t ___x = (intoverflow_t)x; \
60837 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
60838 + ___retval = NULL; \
60839 + else \
60840 + ___retval = kmalloc((size_t)___x, (y)); \
60841 + ___retval; \
60842 +})
60843 +
60844 +#define kmalloc_node(x, y, z) \
60845 +({ \
60846 + void *___retval; \
60847 + intoverflow_t ___x = (intoverflow_t)x; \
60848 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
60849 + ___retval = NULL; \
60850 + else \
60851 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
60852 + ___retval; \
60853 +})
60854 +
60855 +#define kzalloc(x, y) \
60856 +({ \
60857 + void *___retval; \
60858 + intoverflow_t ___x = (intoverflow_t)x; \
60859 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
60860 + ___retval = NULL; \
60861 + else \
60862 + ___retval = kzalloc((size_t)___x, (y)); \
60863 + ___retval; \
60864 +})
60865 +
60866 +#define __krealloc(x, y, z) \
60867 +({ \
60868 + void *___retval; \
60869 + intoverflow_t ___y = (intoverflow_t)y; \
60870 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
60871 + ___retval = NULL; \
60872 + else \
60873 + ___retval = __krealloc((x), (size_t)___y, (z)); \
60874 + ___retval; \
60875 +})
60876 +
60877 +#define krealloc(x, y, z) \
60878 +({ \
60879 + void *___retval; \
60880 + intoverflow_t ___y = (intoverflow_t)y; \
60881 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
60882 + ___retval = NULL; \
60883 + else \
60884 + ___retval = krealloc((x), (size_t)___y, (z)); \
60885 + ___retval; \
60886 +})
60887 +
60888 #endif /* _LINUX_SLAB_H */
60889 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
60890 index d00e0ba..1b3bf7b 100644
60891 --- a/include/linux/slab_def.h
60892 +++ b/include/linux/slab_def.h
60893 @@ -68,10 +68,10 @@ struct kmem_cache {
60894 unsigned long node_allocs;
60895 unsigned long node_frees;
60896 unsigned long node_overflow;
60897 - atomic_t allochit;
60898 - atomic_t allocmiss;
60899 - atomic_t freehit;
60900 - atomic_t freemiss;
60901 + atomic_unchecked_t allochit;
60902 + atomic_unchecked_t allocmiss;
60903 + atomic_unchecked_t freehit;
60904 + atomic_unchecked_t freemiss;
60905
60906 /*
60907 * If debugging is enabled, then the allocator can add additional
60908 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
60909 index a32bcfd..53b71f4 100644
60910 --- a/include/linux/slub_def.h
60911 +++ b/include/linux/slub_def.h
60912 @@ -89,7 +89,7 @@ struct kmem_cache {
60913 struct kmem_cache_order_objects max;
60914 struct kmem_cache_order_objects min;
60915 gfp_t allocflags; /* gfp flags to use on each alloc */
60916 - int refcount; /* Refcount for slab cache destroy */
60917 + atomic_t refcount; /* Refcount for slab cache destroy */
60918 void (*ctor)(void *);
60919 int inuse; /* Offset to metadata */
60920 int align; /* Alignment */
60921 @@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
60922 }
60923
60924 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
60925 -void *__kmalloc(size_t size, gfp_t flags);
60926 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
60927
60928 static __always_inline void *
60929 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
60930 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
60931 index de8832d..0147b46 100644
60932 --- a/include/linux/sonet.h
60933 +++ b/include/linux/sonet.h
60934 @@ -61,7 +61,7 @@ struct sonet_stats {
60935 #include <linux/atomic.h>
60936
60937 struct k_sonet_stats {
60938 -#define __HANDLE_ITEM(i) atomic_t i
60939 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60940 __SONET_ITEMS
60941 #undef __HANDLE_ITEM
60942 };
60943 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
60944 index 3d8f9c4..69f1c0a 100644
60945 --- a/include/linux/sunrpc/clnt.h
60946 +++ b/include/linux/sunrpc/clnt.h
60947 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
60948 {
60949 switch (sap->sa_family) {
60950 case AF_INET:
60951 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
60952 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
60953 case AF_INET6:
60954 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
60955 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
60956 }
60957 return 0;
60958 }
60959 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
60960 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
60961 const struct sockaddr *src)
60962 {
60963 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
60964 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
60965 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
60966
60967 dsin->sin_family = ssin->sin_family;
60968 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
60969 if (sa->sa_family != AF_INET6)
60970 return 0;
60971
60972 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
60973 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
60974 }
60975
60976 #endif /* __KERNEL__ */
60977 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
60978 index e775689..9e206d9 100644
60979 --- a/include/linux/sunrpc/sched.h
60980 +++ b/include/linux/sunrpc/sched.h
60981 @@ -105,6 +105,7 @@ struct rpc_call_ops {
60982 void (*rpc_call_done)(struct rpc_task *, void *);
60983 void (*rpc_release)(void *);
60984 };
60985 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
60986
60987 struct rpc_task_setup {
60988 struct rpc_task *task;
60989 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
60990 index c14fe86..393245e 100644
60991 --- a/include/linux/sunrpc/svc_rdma.h
60992 +++ b/include/linux/sunrpc/svc_rdma.h
60993 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
60994 extern unsigned int svcrdma_max_requests;
60995 extern unsigned int svcrdma_max_req_size;
60996
60997 -extern atomic_t rdma_stat_recv;
60998 -extern atomic_t rdma_stat_read;
60999 -extern atomic_t rdma_stat_write;
61000 -extern atomic_t rdma_stat_sq_starve;
61001 -extern atomic_t rdma_stat_rq_starve;
61002 -extern atomic_t rdma_stat_rq_poll;
61003 -extern atomic_t rdma_stat_rq_prod;
61004 -extern atomic_t rdma_stat_sq_poll;
61005 -extern atomic_t rdma_stat_sq_prod;
61006 +extern atomic_unchecked_t rdma_stat_recv;
61007 +extern atomic_unchecked_t rdma_stat_read;
61008 +extern atomic_unchecked_t rdma_stat_write;
61009 +extern atomic_unchecked_t rdma_stat_sq_starve;
61010 +extern atomic_unchecked_t rdma_stat_rq_starve;
61011 +extern atomic_unchecked_t rdma_stat_rq_poll;
61012 +extern atomic_unchecked_t rdma_stat_rq_prod;
61013 +extern atomic_unchecked_t rdma_stat_sq_poll;
61014 +extern atomic_unchecked_t rdma_stat_sq_prod;
61015
61016 #define RPCRDMA_VERSION 1
61017
61018 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
61019 index 703cfa3..0b8ca72ac 100644
61020 --- a/include/linux/sysctl.h
61021 +++ b/include/linux/sysctl.h
61022 @@ -155,7 +155,11 @@ enum
61023 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
61024 };
61025
61026 -
61027 +#ifdef CONFIG_PAX_SOFTMODE
61028 +enum {
61029 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
61030 +};
61031 +#endif
61032
61033 /* CTL_VM names: */
61034 enum
61035 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
61036
61037 extern int proc_dostring(struct ctl_table *, int,
61038 void __user *, size_t *, loff_t *);
61039 +extern int proc_dostring_modpriv(struct ctl_table *, int,
61040 + void __user *, size_t *, loff_t *);
61041 extern int proc_dointvec(struct ctl_table *, int,
61042 void __user *, size_t *, loff_t *);
61043 extern int proc_dointvec_minmax(struct ctl_table *, int,
61044 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
61045 index ff7dc08..893e1bd 100644
61046 --- a/include/linux/tty_ldisc.h
61047 +++ b/include/linux/tty_ldisc.h
61048 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
61049
61050 struct module *owner;
61051
61052 - int refcount;
61053 + atomic_t refcount;
61054 };
61055
61056 struct tty_ldisc {
61057 diff --git a/include/linux/types.h b/include/linux/types.h
61058 index 57a9723..dbe234a 100644
61059 --- a/include/linux/types.h
61060 +++ b/include/linux/types.h
61061 @@ -213,10 +213,26 @@ typedef struct {
61062 int counter;
61063 } atomic_t;
61064
61065 +#ifdef CONFIG_PAX_REFCOUNT
61066 +typedef struct {
61067 + int counter;
61068 +} atomic_unchecked_t;
61069 +#else
61070 +typedef atomic_t atomic_unchecked_t;
61071 +#endif
61072 +
61073 #ifdef CONFIG_64BIT
61074 typedef struct {
61075 long counter;
61076 } atomic64_t;
61077 +
61078 +#ifdef CONFIG_PAX_REFCOUNT
61079 +typedef struct {
61080 + long counter;
61081 +} atomic64_unchecked_t;
61082 +#else
61083 +typedef atomic64_t atomic64_unchecked_t;
61084 +#endif
61085 #endif
61086
61087 struct list_head {
61088 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
61089 index 5ca0951..ab496a5 100644
61090 --- a/include/linux/uaccess.h
61091 +++ b/include/linux/uaccess.h
61092 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
61093 long ret; \
61094 mm_segment_t old_fs = get_fs(); \
61095 \
61096 - set_fs(KERNEL_DS); \
61097 pagefault_disable(); \
61098 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
61099 - pagefault_enable(); \
61100 + set_fs(KERNEL_DS); \
61101 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
61102 set_fs(old_fs); \
61103 + pagefault_enable(); \
61104 ret; \
61105 })
61106
61107 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
61108 index 99c1b4d..bb94261 100644
61109 --- a/include/linux/unaligned/access_ok.h
61110 +++ b/include/linux/unaligned/access_ok.h
61111 @@ -6,32 +6,32 @@
61112
61113 static inline u16 get_unaligned_le16(const void *p)
61114 {
61115 - return le16_to_cpup((__le16 *)p);
61116 + return le16_to_cpup((const __le16 *)p);
61117 }
61118
61119 static inline u32 get_unaligned_le32(const void *p)
61120 {
61121 - return le32_to_cpup((__le32 *)p);
61122 + return le32_to_cpup((const __le32 *)p);
61123 }
61124
61125 static inline u64 get_unaligned_le64(const void *p)
61126 {
61127 - return le64_to_cpup((__le64 *)p);
61128 + return le64_to_cpup((const __le64 *)p);
61129 }
61130
61131 static inline u16 get_unaligned_be16(const void *p)
61132 {
61133 - return be16_to_cpup((__be16 *)p);
61134 + return be16_to_cpup((const __be16 *)p);
61135 }
61136
61137 static inline u32 get_unaligned_be32(const void *p)
61138 {
61139 - return be32_to_cpup((__be32 *)p);
61140 + return be32_to_cpup((const __be32 *)p);
61141 }
61142
61143 static inline u64 get_unaligned_be64(const void *p)
61144 {
61145 - return be64_to_cpup((__be64 *)p);
61146 + return be64_to_cpup((const __be64 *)p);
61147 }
61148
61149 static inline void put_unaligned_le16(u16 val, void *p)
61150 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
61151 index e5a40c3..20ab0f6 100644
61152 --- a/include/linux/usb/renesas_usbhs.h
61153 +++ b/include/linux/usb/renesas_usbhs.h
61154 @@ -39,7 +39,7 @@ enum {
61155 */
61156 struct renesas_usbhs_driver_callback {
61157 int (*notify_hotplug)(struct platform_device *pdev);
61158 -};
61159 +} __no_const;
61160
61161 /*
61162 * callback functions for platform
61163 @@ -89,7 +89,7 @@ struct renesas_usbhs_platform_callback {
61164 * VBUS control is needed for Host
61165 */
61166 int (*set_vbus)(struct platform_device *pdev, int enable);
61167 -};
61168 +} __no_const;
61169
61170 /*
61171 * parameters for renesas usbhs
61172 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
61173 index 6f8fbcf..8259001 100644
61174 --- a/include/linux/vermagic.h
61175 +++ b/include/linux/vermagic.h
61176 @@ -25,9 +25,35 @@
61177 #define MODULE_ARCH_VERMAGIC ""
61178 #endif
61179
61180 +#ifdef CONFIG_PAX_REFCOUNT
61181 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
61182 +#else
61183 +#define MODULE_PAX_REFCOUNT ""
61184 +#endif
61185 +
61186 +#ifdef CONSTIFY_PLUGIN
61187 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
61188 +#else
61189 +#define MODULE_CONSTIFY_PLUGIN ""
61190 +#endif
61191 +
61192 +#ifdef STACKLEAK_PLUGIN
61193 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
61194 +#else
61195 +#define MODULE_STACKLEAK_PLUGIN ""
61196 +#endif
61197 +
61198 +#ifdef CONFIG_GRKERNSEC
61199 +#define MODULE_GRSEC "GRSEC "
61200 +#else
61201 +#define MODULE_GRSEC ""
61202 +#endif
61203 +
61204 #define VERMAGIC_STRING \
61205 UTS_RELEASE " " \
61206 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
61207 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
61208 - MODULE_ARCH_VERMAGIC
61209 + MODULE_ARCH_VERMAGIC \
61210 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
61211 + MODULE_GRSEC
61212
61213 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
61214 index 4bde182..aec92c1 100644
61215 --- a/include/linux/vmalloc.h
61216 +++ b/include/linux/vmalloc.h
61217 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
61218 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
61219 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
61220 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
61221 +
61222 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
61223 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
61224 +#endif
61225 +
61226 /* bits [20..32] reserved for arch specific ioremap internals */
61227
61228 /*
61229 @@ -156,4 +161,103 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
61230 # endif
61231 #endif
61232
61233 +#define vmalloc(x) \
61234 +({ \
61235 + void *___retval; \
61236 + intoverflow_t ___x = (intoverflow_t)x; \
61237 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
61238 + ___retval = NULL; \
61239 + else \
61240 + ___retval = vmalloc((unsigned long)___x); \
61241 + ___retval; \
61242 +})
61243 +
61244 +#define vzalloc(x) \
61245 +({ \
61246 + void *___retval; \
61247 + intoverflow_t ___x = (intoverflow_t)x; \
61248 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
61249 + ___retval = NULL; \
61250 + else \
61251 + ___retval = vzalloc((unsigned long)___x); \
61252 + ___retval; \
61253 +})
61254 +
61255 +#define __vmalloc(x, y, z) \
61256 +({ \
61257 + void *___retval; \
61258 + intoverflow_t ___x = (intoverflow_t)x; \
61259 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
61260 + ___retval = NULL; \
61261 + else \
61262 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
61263 + ___retval; \
61264 +})
61265 +
61266 +#define vmalloc_user(x) \
61267 +({ \
61268 + void *___retval; \
61269 + intoverflow_t ___x = (intoverflow_t)x; \
61270 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
61271 + ___retval = NULL; \
61272 + else \
61273 + ___retval = vmalloc_user((unsigned long)___x); \
61274 + ___retval; \
61275 +})
61276 +
61277 +#define vmalloc_exec(x) \
61278 +({ \
61279 + void *___retval; \
61280 + intoverflow_t ___x = (intoverflow_t)x; \
61281 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
61282 + ___retval = NULL; \
61283 + else \
61284 + ___retval = vmalloc_exec((unsigned long)___x); \
61285 + ___retval; \
61286 +})
61287 +
61288 +#define vmalloc_node(x, y) \
61289 +({ \
61290 + void *___retval; \
61291 + intoverflow_t ___x = (intoverflow_t)x; \
61292 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
61293 + ___retval = NULL; \
61294 + else \
61295 + ___retval = vmalloc_node((unsigned long)___x, (y));\
61296 + ___retval; \
61297 +})
61298 +
61299 +#define vzalloc_node(x, y) \
61300 +({ \
61301 + void *___retval; \
61302 + intoverflow_t ___x = (intoverflow_t)x; \
61303 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
61304 + ___retval = NULL; \
61305 + else \
61306 + ___retval = vzalloc_node((unsigned long)___x, (y));\
61307 + ___retval; \
61308 +})
61309 +
61310 +#define vmalloc_32(x) \
61311 +({ \
61312 + void *___retval; \
61313 + intoverflow_t ___x = (intoverflow_t)x; \
61314 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
61315 + ___retval = NULL; \
61316 + else \
61317 + ___retval = vmalloc_32((unsigned long)___x); \
61318 + ___retval; \
61319 +})
61320 +
61321 +#define vmalloc_32_user(x) \
61322 +({ \
61323 +void *___retval; \
61324 + intoverflow_t ___x = (intoverflow_t)x; \
61325 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
61326 + ___retval = NULL; \
61327 + else \
61328 + ___retval = vmalloc_32_user((unsigned long)___x);\
61329 + ___retval; \
61330 +})
61331 +
61332 #endif /* _LINUX_VMALLOC_H */
61333 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
61334 index 65efb92..137adbb 100644
61335 --- a/include/linux/vmstat.h
61336 +++ b/include/linux/vmstat.h
61337 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
61338 /*
61339 * Zone based page accounting with per cpu differentials.
61340 */
61341 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61342 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61343
61344 static inline void zone_page_state_add(long x, struct zone *zone,
61345 enum zone_stat_item item)
61346 {
61347 - atomic_long_add(x, &zone->vm_stat[item]);
61348 - atomic_long_add(x, &vm_stat[item]);
61349 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
61350 + atomic_long_add_unchecked(x, &vm_stat[item]);
61351 }
61352
61353 static inline unsigned long global_page_state(enum zone_stat_item item)
61354 {
61355 - long x = atomic_long_read(&vm_stat[item]);
61356 + long x = atomic_long_read_unchecked(&vm_stat[item]);
61357 #ifdef CONFIG_SMP
61358 if (x < 0)
61359 x = 0;
61360 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
61361 static inline unsigned long zone_page_state(struct zone *zone,
61362 enum zone_stat_item item)
61363 {
61364 - long x = atomic_long_read(&zone->vm_stat[item]);
61365 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61366 #ifdef CONFIG_SMP
61367 if (x < 0)
61368 x = 0;
61369 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
61370 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
61371 enum zone_stat_item item)
61372 {
61373 - long x = atomic_long_read(&zone->vm_stat[item]);
61374 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61375
61376 #ifdef CONFIG_SMP
61377 int cpu;
61378 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
61379
61380 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
61381 {
61382 - atomic_long_inc(&zone->vm_stat[item]);
61383 - atomic_long_inc(&vm_stat[item]);
61384 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
61385 + atomic_long_inc_unchecked(&vm_stat[item]);
61386 }
61387
61388 static inline void __inc_zone_page_state(struct page *page,
61389 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
61390
61391 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
61392 {
61393 - atomic_long_dec(&zone->vm_stat[item]);
61394 - atomic_long_dec(&vm_stat[item]);
61395 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
61396 + atomic_long_dec_unchecked(&vm_stat[item]);
61397 }
61398
61399 static inline void __dec_zone_page_state(struct page *page,
61400 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
61401 index e5d1220..ef6e406 100644
61402 --- a/include/linux/xattr.h
61403 +++ b/include/linux/xattr.h
61404 @@ -57,6 +57,11 @@
61405 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
61406 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
61407
61408 +/* User namespace */
61409 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
61410 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
61411 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
61412 +
61413 #ifdef __KERNEL__
61414
61415 #include <linux/types.h>
61416 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
61417 index 4aeff96..b378cdc 100644
61418 --- a/include/media/saa7146_vv.h
61419 +++ b/include/media/saa7146_vv.h
61420 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
61421 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
61422
61423 /* the extension can override this */
61424 - struct v4l2_ioctl_ops ops;
61425 + v4l2_ioctl_ops_no_const ops;
61426 /* pointer to the saa7146 core ops */
61427 const struct v4l2_ioctl_ops *core_ops;
61428
61429 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
61430 index c7c40f1..4f01585 100644
61431 --- a/include/media/v4l2-dev.h
61432 +++ b/include/media/v4l2-dev.h
61433 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
61434
61435
61436 struct v4l2_file_operations {
61437 - struct module *owner;
61438 + struct module * const owner;
61439 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
61440 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
61441 unsigned int (*poll) (struct file *, struct poll_table_struct *);
61442 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
61443 int (*open) (struct file *);
61444 int (*release) (struct file *);
61445 };
61446 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
61447
61448 /*
61449 * Newer version of video_device, handled by videodev2.c
61450 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
61451 index 4d1c74a..65e1221 100644
61452 --- a/include/media/v4l2-ioctl.h
61453 +++ b/include/media/v4l2-ioctl.h
61454 @@ -274,7 +274,7 @@ struct v4l2_ioctl_ops {
61455 long (*vidioc_default) (struct file *file, void *fh,
61456 bool valid_prio, int cmd, void *arg);
61457 };
61458 -
61459 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
61460
61461 /* v4l debugging and diagnostics */
61462
61463 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
61464 index 8d55251..dfe5b0a 100644
61465 --- a/include/net/caif/caif_hsi.h
61466 +++ b/include/net/caif/caif_hsi.h
61467 @@ -98,7 +98,7 @@ struct cfhsi_drv {
61468 void (*rx_done_cb) (struct cfhsi_drv *drv);
61469 void (*wake_up_cb) (struct cfhsi_drv *drv);
61470 void (*wake_down_cb) (struct cfhsi_drv *drv);
61471 -};
61472 +} __no_const;
61473
61474 /* Structure implemented by HSI device. */
61475 struct cfhsi_dev {
61476 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
61477 index 9e5425b..8136ffc 100644
61478 --- a/include/net/caif/cfctrl.h
61479 +++ b/include/net/caif/cfctrl.h
61480 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
61481 void (*radioset_rsp)(void);
61482 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
61483 struct cflayer *client_layer);
61484 -};
61485 +} __no_const;
61486
61487 /* Link Setup Parameters for CAIF-Links. */
61488 struct cfctrl_link_param {
61489 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
61490 struct cfctrl {
61491 struct cfsrvl serv;
61492 struct cfctrl_rsp res;
61493 - atomic_t req_seq_no;
61494 - atomic_t rsp_seq_no;
61495 + atomic_unchecked_t req_seq_no;
61496 + atomic_unchecked_t rsp_seq_no;
61497 struct list_head list;
61498 /* Protects from simultaneous access to first_req list */
61499 spinlock_t info_list_lock;
61500 diff --git a/include/net/flow.h b/include/net/flow.h
61501 index 57f15a7..0de26c6 100644
61502 --- a/include/net/flow.h
61503 +++ b/include/net/flow.h
61504 @@ -208,6 +208,6 @@ extern struct flow_cache_object *flow_cache_lookup(
61505
61506 extern void flow_cache_flush(void);
61507 extern void flow_cache_flush_deferred(void);
61508 -extern atomic_t flow_cache_genid;
61509 +extern atomic_unchecked_t flow_cache_genid;
61510
61511 #endif
61512 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
61513 index e9ff3fc..9d3e5c7 100644
61514 --- a/include/net/inetpeer.h
61515 +++ b/include/net/inetpeer.h
61516 @@ -48,8 +48,8 @@ struct inet_peer {
61517 */
61518 union {
61519 struct {
61520 - atomic_t rid; /* Frag reception counter */
61521 - atomic_t ip_id_count; /* IP ID for the next packet */
61522 + atomic_unchecked_t rid; /* Frag reception counter */
61523 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
61524 __u32 tcp_ts;
61525 __u32 tcp_ts_stamp;
61526 };
61527 @@ -113,11 +113,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
61528 more++;
61529 inet_peer_refcheck(p);
61530 do {
61531 - old = atomic_read(&p->ip_id_count);
61532 + old = atomic_read_unchecked(&p->ip_id_count);
61533 new = old + more;
61534 if (!new)
61535 new = 1;
61536 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
61537 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
61538 return new;
61539 }
61540
61541 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
61542 index 10422ef..662570f 100644
61543 --- a/include/net/ip_fib.h
61544 +++ b/include/net/ip_fib.h
61545 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
61546
61547 #define FIB_RES_SADDR(net, res) \
61548 ((FIB_RES_NH(res).nh_saddr_genid == \
61549 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
61550 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
61551 FIB_RES_NH(res).nh_saddr : \
61552 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
61553 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
61554 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
61555 index e5a7b9a..f4fc44b 100644
61556 --- a/include/net/ip_vs.h
61557 +++ b/include/net/ip_vs.h
61558 @@ -509,7 +509,7 @@ struct ip_vs_conn {
61559 struct ip_vs_conn *control; /* Master control connection */
61560 atomic_t n_control; /* Number of controlled ones */
61561 struct ip_vs_dest *dest; /* real server */
61562 - atomic_t in_pkts; /* incoming packet counter */
61563 + atomic_unchecked_t in_pkts; /* incoming packet counter */
61564
61565 /* packet transmitter for different forwarding methods. If it
61566 mangles the packet, it must return NF_DROP or better NF_STOLEN,
61567 @@ -647,7 +647,7 @@ struct ip_vs_dest {
61568 __be16 port; /* port number of the server */
61569 union nf_inet_addr addr; /* IP address of the server */
61570 volatile unsigned flags; /* dest status flags */
61571 - atomic_t conn_flags; /* flags to copy to conn */
61572 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
61573 atomic_t weight; /* server weight */
61574
61575 atomic_t refcnt; /* reference counter */
61576 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
61577 index 69b610a..fe3962c 100644
61578 --- a/include/net/irda/ircomm_core.h
61579 +++ b/include/net/irda/ircomm_core.h
61580 @@ -51,7 +51,7 @@ typedef struct {
61581 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
61582 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
61583 struct ircomm_info *);
61584 -} call_t;
61585 +} __no_const call_t;
61586
61587 struct ircomm_cb {
61588 irda_queue_t queue;
61589 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
61590 index 59ba38bc..d515662 100644
61591 --- a/include/net/irda/ircomm_tty.h
61592 +++ b/include/net/irda/ircomm_tty.h
61593 @@ -35,6 +35,7 @@
61594 #include <linux/termios.h>
61595 #include <linux/timer.h>
61596 #include <linux/tty.h> /* struct tty_struct */
61597 +#include <asm/local.h>
61598
61599 #include <net/irda/irias_object.h>
61600 #include <net/irda/ircomm_core.h>
61601 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
61602 unsigned short close_delay;
61603 unsigned short closing_wait; /* time to wait before closing */
61604
61605 - int open_count;
61606 - int blocked_open; /* # of blocked opens */
61607 + local_t open_count;
61608 + local_t blocked_open; /* # of blocked opens */
61609
61610 /* Protect concurent access to :
61611 * o self->open_count
61612 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
61613 index f2419cf..473679f 100644
61614 --- a/include/net/iucv/af_iucv.h
61615 +++ b/include/net/iucv/af_iucv.h
61616 @@ -139,7 +139,7 @@ struct iucv_sock {
61617 struct iucv_sock_list {
61618 struct hlist_head head;
61619 rwlock_t lock;
61620 - atomic_t autobind_name;
61621 + atomic_unchecked_t autobind_name;
61622 };
61623
61624 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
61625 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
61626 index 2720884..3aa5c25 100644
61627 --- a/include/net/neighbour.h
61628 +++ b/include/net/neighbour.h
61629 @@ -122,7 +122,7 @@ struct neigh_ops {
61630 void (*error_report)(struct neighbour *, struct sk_buff *);
61631 int (*output)(struct neighbour *, struct sk_buff *);
61632 int (*connected_output)(struct neighbour *, struct sk_buff *);
61633 -};
61634 +} __do_const;
61635
61636 struct pneigh_entry {
61637 struct pneigh_entry *next;
61638 diff --git a/include/net/netlink.h b/include/net/netlink.h
61639 index cb1f350..3279d2c 100644
61640 --- a/include/net/netlink.h
61641 +++ b/include/net/netlink.h
61642 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
61643 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
61644 {
61645 if (mark)
61646 - skb_trim(skb, (unsigned char *) mark - skb->data);
61647 + skb_trim(skb, (const unsigned char *) mark - skb->data);
61648 }
61649
61650 /**
61651 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
61652 index d786b4f..4c3dd41 100644
61653 --- a/include/net/netns/ipv4.h
61654 +++ b/include/net/netns/ipv4.h
61655 @@ -56,8 +56,8 @@ struct netns_ipv4 {
61656
61657 unsigned int sysctl_ping_group_range[2];
61658
61659 - atomic_t rt_genid;
61660 - atomic_t dev_addr_genid;
61661 + atomic_unchecked_t rt_genid;
61662 + atomic_unchecked_t dev_addr_genid;
61663
61664 #ifdef CONFIG_IP_MROUTE
61665 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
61666 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
61667 index 6a72a58..e6a127d 100644
61668 --- a/include/net/sctp/sctp.h
61669 +++ b/include/net/sctp/sctp.h
61670 @@ -318,9 +318,9 @@ do { \
61671
61672 #else /* SCTP_DEBUG */
61673
61674 -#define SCTP_DEBUG_PRINTK(whatever...)
61675 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
61676 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
61677 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
61678 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
61679 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
61680 #define SCTP_ENABLE_DEBUG
61681 #define SCTP_DISABLE_DEBUG
61682 #define SCTP_ASSERT(expr, str, func)
61683 diff --git a/include/net/sock.h b/include/net/sock.h
61684 index 32e3937..87a1dbc 100644
61685 --- a/include/net/sock.h
61686 +++ b/include/net/sock.h
61687 @@ -277,7 +277,7 @@ struct sock {
61688 #ifdef CONFIG_RPS
61689 __u32 sk_rxhash;
61690 #endif
61691 - atomic_t sk_drops;
61692 + atomic_unchecked_t sk_drops;
61693 int sk_rcvbuf;
61694
61695 struct sk_filter __rcu *sk_filter;
61696 @@ -1402,7 +1402,7 @@ static inline void sk_nocaps_add(struct sock *sk, int flags)
61697 }
61698
61699 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
61700 - char __user *from, char *to,
61701 + char __user *from, unsigned char *to,
61702 int copy, int offset)
61703 {
61704 if (skb->ip_summed == CHECKSUM_NONE) {
61705 diff --git a/include/net/tcp.h b/include/net/tcp.h
61706 index bb18c4d..bb87972 100644
61707 --- a/include/net/tcp.h
61708 +++ b/include/net/tcp.h
61709 @@ -1409,7 +1409,7 @@ struct tcp_seq_afinfo {
61710 char *name;
61711 sa_family_t family;
61712 const struct file_operations *seq_fops;
61713 - struct seq_operations seq_ops;
61714 + seq_operations_no_const seq_ops;
61715 };
61716
61717 struct tcp_iter_state {
61718 diff --git a/include/net/udp.h b/include/net/udp.h
61719 index 3b285f4..0219639 100644
61720 --- a/include/net/udp.h
61721 +++ b/include/net/udp.h
61722 @@ -237,7 +237,7 @@ struct udp_seq_afinfo {
61723 sa_family_t family;
61724 struct udp_table *udp_table;
61725 const struct file_operations *seq_fops;
61726 - struct seq_operations seq_ops;
61727 + seq_operations_no_const seq_ops;
61728 };
61729
61730 struct udp_iter_state {
61731 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
61732 index b203e14..1df3991 100644
61733 --- a/include/net/xfrm.h
61734 +++ b/include/net/xfrm.h
61735 @@ -505,7 +505,7 @@ struct xfrm_policy {
61736 struct timer_list timer;
61737
61738 struct flow_cache_object flo;
61739 - atomic_t genid;
61740 + atomic_unchecked_t genid;
61741 u32 priority;
61742 u32 index;
61743 struct xfrm_mark mark;
61744 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
61745 index 1a046b1..ee0bef0 100644
61746 --- a/include/rdma/iw_cm.h
61747 +++ b/include/rdma/iw_cm.h
61748 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
61749 int backlog);
61750
61751 int (*destroy_listen)(struct iw_cm_id *cm_id);
61752 -};
61753 +} __no_const;
61754
61755 /**
61756 * iw_create_cm_id - Create an IW CM identifier.
61757 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
61758 index 5d1a758..1dbf795 100644
61759 --- a/include/scsi/libfc.h
61760 +++ b/include/scsi/libfc.h
61761 @@ -748,6 +748,7 @@ struct libfc_function_template {
61762 */
61763 void (*disc_stop_final) (struct fc_lport *);
61764 };
61765 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
61766
61767 /**
61768 * struct fc_disc - Discovery context
61769 @@ -851,7 +852,7 @@ struct fc_lport {
61770 struct fc_vport *vport;
61771
61772 /* Operational Information */
61773 - struct libfc_function_template tt;
61774 + libfc_function_template_no_const tt;
61775 u8 link_up;
61776 u8 qfull;
61777 enum fc_lport_state state;
61778 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
61779 index 5591ed5..13eb457 100644
61780 --- a/include/scsi/scsi_device.h
61781 +++ b/include/scsi/scsi_device.h
61782 @@ -161,9 +161,9 @@ struct scsi_device {
61783 unsigned int max_device_blocked; /* what device_blocked counts down from */
61784 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
61785
61786 - atomic_t iorequest_cnt;
61787 - atomic_t iodone_cnt;
61788 - atomic_t ioerr_cnt;
61789 + atomic_unchecked_t iorequest_cnt;
61790 + atomic_unchecked_t iodone_cnt;
61791 + atomic_unchecked_t ioerr_cnt;
61792
61793 struct device sdev_gendev,
61794 sdev_dev;
61795 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
61796 index 2a65167..91e01f8 100644
61797 --- a/include/scsi/scsi_transport_fc.h
61798 +++ b/include/scsi/scsi_transport_fc.h
61799 @@ -711,7 +711,7 @@ struct fc_function_template {
61800 unsigned long show_host_system_hostname:1;
61801
61802 unsigned long disable_target_scan:1;
61803 -};
61804 +} __do_const;
61805
61806
61807 /**
61808 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
61809 index 030b87c..98a6954 100644
61810 --- a/include/sound/ak4xxx-adda.h
61811 +++ b/include/sound/ak4xxx-adda.h
61812 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
61813 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
61814 unsigned char val);
61815 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
61816 -};
61817 +} __no_const;
61818
61819 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
61820
61821 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
61822 index 8c05e47..2b5df97 100644
61823 --- a/include/sound/hwdep.h
61824 +++ b/include/sound/hwdep.h
61825 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
61826 struct snd_hwdep_dsp_status *status);
61827 int (*dsp_load)(struct snd_hwdep *hw,
61828 struct snd_hwdep_dsp_image *image);
61829 -};
61830 +} __no_const;
61831
61832 struct snd_hwdep {
61833 struct snd_card *card;
61834 diff --git a/include/sound/info.h b/include/sound/info.h
61835 index 5492cc4..1a65278 100644
61836 --- a/include/sound/info.h
61837 +++ b/include/sound/info.h
61838 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
61839 struct snd_info_buffer *buffer);
61840 void (*write)(struct snd_info_entry *entry,
61841 struct snd_info_buffer *buffer);
61842 -};
61843 +} __no_const;
61844
61845 struct snd_info_entry_ops {
61846 int (*open)(struct snd_info_entry *entry,
61847 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
61848 index 0cf91b2..b70cae4 100644
61849 --- a/include/sound/pcm.h
61850 +++ b/include/sound/pcm.h
61851 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
61852 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
61853 int (*ack)(struct snd_pcm_substream *substream);
61854 };
61855 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
61856
61857 /*
61858 *
61859 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
61860 index af1b49e..a5d55a5 100644
61861 --- a/include/sound/sb16_csp.h
61862 +++ b/include/sound/sb16_csp.h
61863 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
61864 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
61865 int (*csp_stop) (struct snd_sb_csp * p);
61866 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
61867 -};
61868 +} __no_const;
61869
61870 /*
61871 * CSP private data
61872 diff --git a/include/sound/soc.h b/include/sound/soc.h
61873 index 11cfb59..e3f93f4 100644
61874 --- a/include/sound/soc.h
61875 +++ b/include/sound/soc.h
61876 @@ -683,7 +683,7 @@ struct snd_soc_platform_driver {
61877 /* platform IO - used for platform DAPM */
61878 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
61879 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
61880 -};
61881 +} __do_const;
61882
61883 struct snd_soc_platform {
61884 const char *name;
61885 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
61886 index 444cd6b..3327cc5 100644
61887 --- a/include/sound/ymfpci.h
61888 +++ b/include/sound/ymfpci.h
61889 @@ -358,7 +358,7 @@ struct snd_ymfpci {
61890 spinlock_t reg_lock;
61891 spinlock_t voice_lock;
61892 wait_queue_head_t interrupt_sleep;
61893 - atomic_t interrupt_sleep_count;
61894 + atomic_unchecked_t interrupt_sleep_count;
61895 struct snd_info_entry *proc_entry;
61896 const struct firmware *dsp_microcode;
61897 const struct firmware *controller_microcode;
61898 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
61899 index 6873c7d..b1e8009 100644
61900 --- a/include/target/target_core_base.h
61901 +++ b/include/target/target_core_base.h
61902 @@ -345,7 +345,7 @@ struct t10_reservation_ops {
61903 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
61904 int (*t10_pr_register)(struct se_cmd *);
61905 int (*t10_pr_clear)(struct se_cmd *);
61906 -};
61907 +} __no_const;
61908
61909 struct t10_reservation {
61910 /* Reservation effects all target ports */
61911 @@ -464,8 +464,8 @@ struct se_cmd {
61912 atomic_t t_se_count;
61913 atomic_t t_task_cdbs_left;
61914 atomic_t t_task_cdbs_ex_left;
61915 - atomic_t t_task_cdbs_sent;
61916 - atomic_t t_transport_aborted;
61917 + atomic_unchecked_t t_task_cdbs_sent;
61918 + atomic_unchecked_t t_transport_aborted;
61919 atomic_t t_transport_active;
61920 atomic_t t_transport_complete;
61921 atomic_t t_transport_queue_active;
61922 @@ -703,7 +703,7 @@ struct se_device {
61923 /* Active commands on this virtual SE device */
61924 atomic_t simple_cmds;
61925 atomic_t depth_left;
61926 - atomic_t dev_ordered_id;
61927 + atomic_unchecked_t dev_ordered_id;
61928 atomic_t execute_tasks;
61929 atomic_t dev_ordered_sync;
61930 atomic_t dev_qf_count;
61931 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
61932 index 1c09820..7f5ec79 100644
61933 --- a/include/trace/events/irq.h
61934 +++ b/include/trace/events/irq.h
61935 @@ -36,7 +36,7 @@ struct softirq_action;
61936 */
61937 TRACE_EVENT(irq_handler_entry,
61938
61939 - TP_PROTO(int irq, struct irqaction *action),
61940 + TP_PROTO(int irq, const struct irqaction *action),
61941
61942 TP_ARGS(irq, action),
61943
61944 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
61945 */
61946 TRACE_EVENT(irq_handler_exit,
61947
61948 - TP_PROTO(int irq, struct irqaction *action, int ret),
61949 + TP_PROTO(int irq, const struct irqaction *action, int ret),
61950
61951 TP_ARGS(irq, action, ret),
61952
61953 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
61954 index c41f308..6918de3 100644
61955 --- a/include/video/udlfb.h
61956 +++ b/include/video/udlfb.h
61957 @@ -52,10 +52,10 @@ struct dlfb_data {
61958 u32 pseudo_palette[256];
61959 int blank_mode; /*one of FB_BLANK_ */
61960 /* blit-only rendering path metrics, exposed through sysfs */
61961 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
61962 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
61963 - atomic_t bytes_sent; /* to usb, after compression including overhead */
61964 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
61965 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
61966 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
61967 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
61968 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
61969 };
61970
61971 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
61972 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
61973 index 0993a22..32ba2fe 100644
61974 --- a/include/video/uvesafb.h
61975 +++ b/include/video/uvesafb.h
61976 @@ -177,6 +177,7 @@ struct uvesafb_par {
61977 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
61978 u8 pmi_setpal; /* PMI for palette changes */
61979 u16 *pmi_base; /* protected mode interface location */
61980 + u8 *pmi_code; /* protected mode code location */
61981 void *pmi_start;
61982 void *pmi_pal;
61983 u8 *vbe_state_orig; /*
61984 diff --git a/init/Kconfig b/init/Kconfig
61985 index 43298f9..2f56c12 100644
61986 --- a/init/Kconfig
61987 +++ b/init/Kconfig
61988 @@ -1214,7 +1214,7 @@ config SLUB_DEBUG
61989
61990 config COMPAT_BRK
61991 bool "Disable heap randomization"
61992 - default y
61993 + default n
61994 help
61995 Randomizing heap placement makes heap exploits harder, but it
61996 also breaks ancient binaries (including anything libc5 based).
61997 diff --git a/init/do_mounts.c b/init/do_mounts.c
61998 index 0f6e1d9..89d0af4 100644
61999 --- a/init/do_mounts.c
62000 +++ b/init/do_mounts.c
62001 @@ -325,11 +325,11 @@ static void __init get_fs_names(char *page)
62002
62003 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
62004 {
62005 - int err = sys_mount(name, "/root", fs, flags, data);
62006 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
62007 if (err)
62008 return err;
62009
62010 - sys_chdir((const char __user __force *)"/root");
62011 + sys_chdir((const char __force_user*)"/root");
62012 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
62013 printk(KERN_INFO
62014 "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
62015 @@ -421,18 +421,18 @@ void __init change_floppy(char *fmt, ...)
62016 va_start(args, fmt);
62017 vsprintf(buf, fmt, args);
62018 va_end(args);
62019 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
62020 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
62021 if (fd >= 0) {
62022 sys_ioctl(fd, FDEJECT, 0);
62023 sys_close(fd);
62024 }
62025 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
62026 - fd = sys_open("/dev/console", O_RDWR, 0);
62027 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
62028 if (fd >= 0) {
62029 sys_ioctl(fd, TCGETS, (long)&termios);
62030 termios.c_lflag &= ~ICANON;
62031 sys_ioctl(fd, TCSETSF, (long)&termios);
62032 - sys_read(fd, &c, 1);
62033 + sys_read(fd, (char __user *)&c, 1);
62034 termios.c_lflag |= ICANON;
62035 sys_ioctl(fd, TCSETSF, (long)&termios);
62036 sys_close(fd);
62037 @@ -526,6 +526,6 @@ void __init prepare_namespace(void)
62038 mount_root();
62039 out:
62040 devtmpfs_mount("dev");
62041 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
62042 - sys_chroot((const char __user __force *)".");
62043 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
62044 + sys_chroot((const char __force_user *)".");
62045 }
62046 diff --git a/init/do_mounts.h b/init/do_mounts.h
62047 index f5b978a..69dbfe8 100644
62048 --- a/init/do_mounts.h
62049 +++ b/init/do_mounts.h
62050 @@ -15,15 +15,15 @@ extern int root_mountflags;
62051
62052 static inline int create_dev(char *name, dev_t dev)
62053 {
62054 - sys_unlink(name);
62055 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
62056 + sys_unlink((char __force_user *)name);
62057 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
62058 }
62059
62060 #if BITS_PER_LONG == 32
62061 static inline u32 bstat(char *name)
62062 {
62063 struct stat64 stat;
62064 - if (sys_stat64(name, &stat) != 0)
62065 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
62066 return 0;
62067 if (!S_ISBLK(stat.st_mode))
62068 return 0;
62069 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
62070 static inline u32 bstat(char *name)
62071 {
62072 struct stat stat;
62073 - if (sys_newstat(name, &stat) != 0)
62074 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
62075 return 0;
62076 if (!S_ISBLK(stat.st_mode))
62077 return 0;
62078 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
62079 index 3098a38..253064e 100644
62080 --- a/init/do_mounts_initrd.c
62081 +++ b/init/do_mounts_initrd.c
62082 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
62083 create_dev("/dev/root.old", Root_RAM0);
62084 /* mount initrd on rootfs' /root */
62085 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
62086 - sys_mkdir("/old", 0700);
62087 - root_fd = sys_open("/", 0, 0);
62088 - old_fd = sys_open("/old", 0, 0);
62089 + sys_mkdir((const char __force_user *)"/old", 0700);
62090 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
62091 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
62092 /* move initrd over / and chdir/chroot in initrd root */
62093 - sys_chdir("/root");
62094 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
62095 - sys_chroot(".");
62096 + sys_chdir((const char __force_user *)"/root");
62097 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
62098 + sys_chroot((const char __force_user *)".");
62099
62100 /*
62101 * In case that a resume from disk is carried out by linuxrc or one of
62102 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
62103
62104 /* move initrd to rootfs' /old */
62105 sys_fchdir(old_fd);
62106 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
62107 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
62108 /* switch root and cwd back to / of rootfs */
62109 sys_fchdir(root_fd);
62110 - sys_chroot(".");
62111 + sys_chroot((const char __force_user *)".");
62112 sys_close(old_fd);
62113 sys_close(root_fd);
62114
62115 if (new_decode_dev(real_root_dev) == Root_RAM0) {
62116 - sys_chdir("/old");
62117 + sys_chdir((const char __force_user *)"/old");
62118 return;
62119 }
62120
62121 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
62122 mount_root();
62123
62124 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
62125 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
62126 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
62127 if (!error)
62128 printk("okay\n");
62129 else {
62130 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
62131 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
62132 if (error == -ENOENT)
62133 printk("/initrd does not exist. Ignored.\n");
62134 else
62135 printk("failed\n");
62136 printk(KERN_NOTICE "Unmounting old root\n");
62137 - sys_umount("/old", MNT_DETACH);
62138 + sys_umount((char __force_user *)"/old", MNT_DETACH);
62139 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
62140 if (fd < 0) {
62141 error = fd;
62142 @@ -116,11 +116,11 @@ int __init initrd_load(void)
62143 * mounted in the normal path.
62144 */
62145 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
62146 - sys_unlink("/initrd.image");
62147 + sys_unlink((const char __force_user *)"/initrd.image");
62148 handle_initrd();
62149 return 1;
62150 }
62151 }
62152 - sys_unlink("/initrd.image");
62153 + sys_unlink((const char __force_user *)"/initrd.image");
62154 return 0;
62155 }
62156 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
62157 index 32c4799..c27ee74 100644
62158 --- a/init/do_mounts_md.c
62159 +++ b/init/do_mounts_md.c
62160 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
62161 partitioned ? "_d" : "", minor,
62162 md_setup_args[ent].device_names);
62163
62164 - fd = sys_open(name, 0, 0);
62165 + fd = sys_open((char __force_user *)name, 0, 0);
62166 if (fd < 0) {
62167 printk(KERN_ERR "md: open failed - cannot start "
62168 "array %s\n", name);
62169 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
62170 * array without it
62171 */
62172 sys_close(fd);
62173 - fd = sys_open(name, 0, 0);
62174 + fd = sys_open((char __force_user *)name, 0, 0);
62175 sys_ioctl(fd, BLKRRPART, 0);
62176 }
62177 sys_close(fd);
62178 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
62179
62180 wait_for_device_probe();
62181
62182 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
62183 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
62184 if (fd >= 0) {
62185 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
62186 sys_close(fd);
62187 diff --git a/init/initramfs.c b/init/initramfs.c
62188 index 2531811..040d4d4 100644
62189 --- a/init/initramfs.c
62190 +++ b/init/initramfs.c
62191 @@ -74,7 +74,7 @@ static void __init free_hash(void)
62192 }
62193 }
62194
62195 -static long __init do_utime(char __user *filename, time_t mtime)
62196 +static long __init do_utime(__force char __user *filename, time_t mtime)
62197 {
62198 struct timespec t[2];
62199
62200 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
62201 struct dir_entry *de, *tmp;
62202 list_for_each_entry_safe(de, tmp, &dir_list, list) {
62203 list_del(&de->list);
62204 - do_utime(de->name, de->mtime);
62205 + do_utime((char __force_user *)de->name, de->mtime);
62206 kfree(de->name);
62207 kfree(de);
62208 }
62209 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
62210 if (nlink >= 2) {
62211 char *old = find_link(major, minor, ino, mode, collected);
62212 if (old)
62213 - return (sys_link(old, collected) < 0) ? -1 : 1;
62214 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
62215 }
62216 return 0;
62217 }
62218 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
62219 {
62220 struct stat st;
62221
62222 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
62223 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
62224 if (S_ISDIR(st.st_mode))
62225 - sys_rmdir(path);
62226 + sys_rmdir((char __force_user *)path);
62227 else
62228 - sys_unlink(path);
62229 + sys_unlink((char __force_user *)path);
62230 }
62231 }
62232
62233 @@ -305,7 +305,7 @@ static int __init do_name(void)
62234 int openflags = O_WRONLY|O_CREAT;
62235 if (ml != 1)
62236 openflags |= O_TRUNC;
62237 - wfd = sys_open(collected, openflags, mode);
62238 + wfd = sys_open((char __force_user *)collected, openflags, mode);
62239
62240 if (wfd >= 0) {
62241 sys_fchown(wfd, uid, gid);
62242 @@ -317,17 +317,17 @@ static int __init do_name(void)
62243 }
62244 }
62245 } else if (S_ISDIR(mode)) {
62246 - sys_mkdir(collected, mode);
62247 - sys_chown(collected, uid, gid);
62248 - sys_chmod(collected, mode);
62249 + sys_mkdir((char __force_user *)collected, mode);
62250 + sys_chown((char __force_user *)collected, uid, gid);
62251 + sys_chmod((char __force_user *)collected, mode);
62252 dir_add(collected, mtime);
62253 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
62254 S_ISFIFO(mode) || S_ISSOCK(mode)) {
62255 if (maybe_link() == 0) {
62256 - sys_mknod(collected, mode, rdev);
62257 - sys_chown(collected, uid, gid);
62258 - sys_chmod(collected, mode);
62259 - do_utime(collected, mtime);
62260 + sys_mknod((char __force_user *)collected, mode, rdev);
62261 + sys_chown((char __force_user *)collected, uid, gid);
62262 + sys_chmod((char __force_user *)collected, mode);
62263 + do_utime((char __force_user *)collected, mtime);
62264 }
62265 }
62266 return 0;
62267 @@ -336,15 +336,15 @@ static int __init do_name(void)
62268 static int __init do_copy(void)
62269 {
62270 if (count >= body_len) {
62271 - sys_write(wfd, victim, body_len);
62272 + sys_write(wfd, (char __force_user *)victim, body_len);
62273 sys_close(wfd);
62274 - do_utime(vcollected, mtime);
62275 + do_utime((char __force_user *)vcollected, mtime);
62276 kfree(vcollected);
62277 eat(body_len);
62278 state = SkipIt;
62279 return 0;
62280 } else {
62281 - sys_write(wfd, victim, count);
62282 + sys_write(wfd, (char __force_user *)victim, count);
62283 body_len -= count;
62284 eat(count);
62285 return 1;
62286 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
62287 {
62288 collected[N_ALIGN(name_len) + body_len] = '\0';
62289 clean_path(collected, 0);
62290 - sys_symlink(collected + N_ALIGN(name_len), collected);
62291 - sys_lchown(collected, uid, gid);
62292 - do_utime(collected, mtime);
62293 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
62294 + sys_lchown((char __force_user *)collected, uid, gid);
62295 + do_utime((char __force_user *)collected, mtime);
62296 state = SkipIt;
62297 next_state = Reset;
62298 return 0;
62299 diff --git a/init/main.c b/init/main.c
62300 index 217ed23..32e5731 100644
62301 --- a/init/main.c
62302 +++ b/init/main.c
62303 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
62304 extern void tc_init(void);
62305 #endif
62306
62307 +extern void grsecurity_init(void);
62308 +
62309 /*
62310 * Debug helper: via this flag we know that we are in 'early bootup code'
62311 * where only the boot processor is running with IRQ disabled. This means
62312 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
62313
62314 __setup("reset_devices", set_reset_devices);
62315
62316 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
62317 +extern char pax_enter_kernel_user[];
62318 +extern char pax_exit_kernel_user[];
62319 +extern pgdval_t clone_pgd_mask;
62320 +#endif
62321 +
62322 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
62323 +static int __init setup_pax_nouderef(char *str)
62324 +{
62325 +#ifdef CONFIG_X86_32
62326 + unsigned int cpu;
62327 + struct desc_struct *gdt;
62328 +
62329 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
62330 + gdt = get_cpu_gdt_table(cpu);
62331 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
62332 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
62333 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
62334 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
62335 + }
62336 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
62337 +#else
62338 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
62339 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
62340 + clone_pgd_mask = ~(pgdval_t)0UL;
62341 +#endif
62342 +
62343 + return 0;
62344 +}
62345 +early_param("pax_nouderef", setup_pax_nouderef);
62346 +#endif
62347 +
62348 +#ifdef CONFIG_PAX_SOFTMODE
62349 +int pax_softmode;
62350 +
62351 +static int __init setup_pax_softmode(char *str)
62352 +{
62353 + get_option(&str, &pax_softmode);
62354 + return 1;
62355 +}
62356 +__setup("pax_softmode=", setup_pax_softmode);
62357 +#endif
62358 +
62359 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
62360 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
62361 static const char *panic_later, *panic_param;
62362 @@ -681,6 +726,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
62363 {
62364 int count = preempt_count();
62365 int ret;
62366 + const char *msg1 = "", *msg2 = "";
62367
62368 if (initcall_debug)
62369 ret = do_one_initcall_debug(fn);
62370 @@ -693,15 +739,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
62371 sprintf(msgbuf, "error code %d ", ret);
62372
62373 if (preempt_count() != count) {
62374 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
62375 + msg1 = " preemption imbalance";
62376 preempt_count() = count;
62377 }
62378 if (irqs_disabled()) {
62379 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
62380 + msg2 = " disabled interrupts";
62381 local_irq_enable();
62382 }
62383 - if (msgbuf[0]) {
62384 - printk("initcall %pF returned with %s\n", fn, msgbuf);
62385 + if (msgbuf[0] || *msg1 || *msg2) {
62386 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
62387 }
62388
62389 return ret;
62390 @@ -820,7 +866,7 @@ static int __init kernel_init(void * unused)
62391 do_basic_setup();
62392
62393 /* Open the /dev/console on the rootfs, this should never fail */
62394 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
62395 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
62396 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
62397
62398 (void) sys_dup(0);
62399 @@ -833,11 +879,13 @@ static int __init kernel_init(void * unused)
62400 if (!ramdisk_execute_command)
62401 ramdisk_execute_command = "/init";
62402
62403 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
62404 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
62405 ramdisk_execute_command = NULL;
62406 prepare_namespace();
62407 }
62408
62409 + grsecurity_init();
62410 +
62411 /*
62412 * Ok, we have completed the initial bootup, and
62413 * we're essentially up and running. Get rid of the
62414 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
62415 index 5b4293d..f179875 100644
62416 --- a/ipc/mqueue.c
62417 +++ b/ipc/mqueue.c
62418 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
62419 mq_bytes = (mq_msg_tblsz +
62420 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
62421
62422 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
62423 spin_lock(&mq_lock);
62424 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
62425 u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
62426 diff --git a/ipc/msg.c b/ipc/msg.c
62427 index 7385de2..a8180e0 100644
62428 --- a/ipc/msg.c
62429 +++ b/ipc/msg.c
62430 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
62431 return security_msg_queue_associate(msq, msgflg);
62432 }
62433
62434 +static struct ipc_ops msg_ops = {
62435 + .getnew = newque,
62436 + .associate = msg_security,
62437 + .more_checks = NULL
62438 +};
62439 +
62440 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
62441 {
62442 struct ipc_namespace *ns;
62443 - struct ipc_ops msg_ops;
62444 struct ipc_params msg_params;
62445
62446 ns = current->nsproxy->ipc_ns;
62447
62448 - msg_ops.getnew = newque;
62449 - msg_ops.associate = msg_security;
62450 - msg_ops.more_checks = NULL;
62451 -
62452 msg_params.key = key;
62453 msg_params.flg = msgflg;
62454
62455 diff --git a/ipc/sem.c b/ipc/sem.c
62456 index 5215a81..cfc0cac 100644
62457 --- a/ipc/sem.c
62458 +++ b/ipc/sem.c
62459 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
62460 return 0;
62461 }
62462
62463 +static struct ipc_ops sem_ops = {
62464 + .getnew = newary,
62465 + .associate = sem_security,
62466 + .more_checks = sem_more_checks
62467 +};
62468 +
62469 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
62470 {
62471 struct ipc_namespace *ns;
62472 - struct ipc_ops sem_ops;
62473 struct ipc_params sem_params;
62474
62475 ns = current->nsproxy->ipc_ns;
62476 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
62477 if (nsems < 0 || nsems > ns->sc_semmsl)
62478 return -EINVAL;
62479
62480 - sem_ops.getnew = newary;
62481 - sem_ops.associate = sem_security;
62482 - sem_ops.more_checks = sem_more_checks;
62483 -
62484 sem_params.key = key;
62485 sem_params.flg = semflg;
62486 sem_params.u.nsems = nsems;
62487 diff --git a/ipc/shm.c b/ipc/shm.c
62488 index 02ecf2c..be05b1e 100644
62489 --- a/ipc/shm.c
62490 +++ b/ipc/shm.c
62491 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
62492 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
62493 #endif
62494
62495 +#ifdef CONFIG_GRKERNSEC
62496 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62497 + const time_t shm_createtime, const uid_t cuid,
62498 + const int shmid);
62499 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62500 + const time_t shm_createtime);
62501 +#endif
62502 +
62503 void shm_init_ns(struct ipc_namespace *ns)
62504 {
62505 ns->shm_ctlmax = SHMMAX;
62506 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
62507 shp->shm_lprid = 0;
62508 shp->shm_atim = shp->shm_dtim = 0;
62509 shp->shm_ctim = get_seconds();
62510 +#ifdef CONFIG_GRKERNSEC
62511 + {
62512 + struct timespec timeval;
62513 + do_posix_clock_monotonic_gettime(&timeval);
62514 +
62515 + shp->shm_createtime = timeval.tv_sec;
62516 + }
62517 +#endif
62518 shp->shm_segsz = size;
62519 shp->shm_nattch = 0;
62520 shp->shm_file = file;
62521 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
62522 return 0;
62523 }
62524
62525 +static struct ipc_ops shm_ops = {
62526 + .getnew = newseg,
62527 + .associate = shm_security,
62528 + .more_checks = shm_more_checks
62529 +};
62530 +
62531 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
62532 {
62533 struct ipc_namespace *ns;
62534 - struct ipc_ops shm_ops;
62535 struct ipc_params shm_params;
62536
62537 ns = current->nsproxy->ipc_ns;
62538
62539 - shm_ops.getnew = newseg;
62540 - shm_ops.associate = shm_security;
62541 - shm_ops.more_checks = shm_more_checks;
62542 -
62543 shm_params.key = key;
62544 shm_params.flg = shmflg;
62545 shm_params.u.size = size;
62546 @@ -870,8 +887,6 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
62547 case SHM_LOCK:
62548 case SHM_UNLOCK:
62549 {
62550 - struct file *uninitialized_var(shm_file);
62551 -
62552 lru_add_drain_all(); /* drain pagevecs to lru lists */
62553
62554 shp = shm_lock_check(ns, shmid);
62555 @@ -981,6 +996,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
62556 f_mode = FMODE_READ | FMODE_WRITE;
62557 }
62558 if (shmflg & SHM_EXEC) {
62559 +
62560 +#ifdef CONFIG_PAX_MPROTECT
62561 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
62562 + goto out;
62563 +#endif
62564 +
62565 prot |= PROT_EXEC;
62566 acc_mode |= S_IXUGO;
62567 }
62568 @@ -1004,9 +1025,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
62569 if (err)
62570 goto out_unlock;
62571
62572 +#ifdef CONFIG_GRKERNSEC
62573 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
62574 + shp->shm_perm.cuid, shmid) ||
62575 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
62576 + err = -EACCES;
62577 + goto out_unlock;
62578 + }
62579 +#endif
62580 +
62581 path = shp->shm_file->f_path;
62582 path_get(&path);
62583 shp->shm_nattch++;
62584 +#ifdef CONFIG_GRKERNSEC
62585 + shp->shm_lapid = current->pid;
62586 +#endif
62587 size = i_size_read(path.dentry->d_inode);
62588 shm_unlock(shp);
62589
62590 diff --git a/kernel/acct.c b/kernel/acct.c
62591 index fa7eb3d..7faf116 100644
62592 --- a/kernel/acct.c
62593 +++ b/kernel/acct.c
62594 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
62595 */
62596 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
62597 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
62598 - file->f_op->write(file, (char *)&ac,
62599 + file->f_op->write(file, (char __force_user *)&ac,
62600 sizeof(acct_t), &file->f_pos);
62601 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
62602 set_fs(fs);
62603 diff --git a/kernel/audit.c b/kernel/audit.c
62604 index 09fae26..ed71d5b 100644
62605 --- a/kernel/audit.c
62606 +++ b/kernel/audit.c
62607 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
62608 3) suppressed due to audit_rate_limit
62609 4) suppressed due to audit_backlog_limit
62610 */
62611 -static atomic_t audit_lost = ATOMIC_INIT(0);
62612 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
62613
62614 /* The netlink socket. */
62615 static struct sock *audit_sock;
62616 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
62617 unsigned long now;
62618 int print;
62619
62620 - atomic_inc(&audit_lost);
62621 + atomic_inc_unchecked(&audit_lost);
62622
62623 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
62624
62625 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
62626 printk(KERN_WARNING
62627 "audit: audit_lost=%d audit_rate_limit=%d "
62628 "audit_backlog_limit=%d\n",
62629 - atomic_read(&audit_lost),
62630 + atomic_read_unchecked(&audit_lost),
62631 audit_rate_limit,
62632 audit_backlog_limit);
62633 audit_panic(message);
62634 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
62635 status_set.pid = audit_pid;
62636 status_set.rate_limit = audit_rate_limit;
62637 status_set.backlog_limit = audit_backlog_limit;
62638 - status_set.lost = atomic_read(&audit_lost);
62639 + status_set.lost = atomic_read_unchecked(&audit_lost);
62640 status_set.backlog = skb_queue_len(&audit_skb_queue);
62641 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
62642 &status_set, sizeof(status_set));
62643 @@ -1260,12 +1260,13 @@ static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
62644 avail = audit_expand(ab,
62645 max_t(unsigned, AUDIT_BUFSIZ, 1+len-avail));
62646 if (!avail)
62647 - goto out;
62648 + goto out_va_end;
62649 len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2);
62650 }
62651 - va_end(args2);
62652 if (len > 0)
62653 skb_put(skb, len);
62654 +out_va_end:
62655 + va_end(args2);
62656 out:
62657 return;
62658 }
62659 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
62660 index 47b7fc1..c003c33 100644
62661 --- a/kernel/auditsc.c
62662 +++ b/kernel/auditsc.c
62663 @@ -1166,8 +1166,8 @@ static void audit_log_execve_info(struct audit_context *context,
62664 struct audit_buffer **ab,
62665 struct audit_aux_data_execve *axi)
62666 {
62667 - int i;
62668 - size_t len, len_sent = 0;
62669 + int i, len;
62670 + size_t len_sent = 0;
62671 const char __user *p;
62672 char *buf;
62673
62674 @@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
62675 }
62676
62677 /* global counter which is incremented every time something logs in */
62678 -static atomic_t session_id = ATOMIC_INIT(0);
62679 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
62680
62681 /**
62682 * audit_set_loginuid - set a task's audit_context loginuid
62683 @@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
62684 */
62685 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
62686 {
62687 - unsigned int sessionid = atomic_inc_return(&session_id);
62688 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
62689 struct audit_context *context = task->audit_context;
62690
62691 if (context && context->in_syscall) {
62692 diff --git a/kernel/capability.c b/kernel/capability.c
62693 index b463871..fa3ea1f 100644
62694 --- a/kernel/capability.c
62695 +++ b/kernel/capability.c
62696 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
62697 * before modification is attempted and the application
62698 * fails.
62699 */
62700 + if (tocopy > ARRAY_SIZE(kdata))
62701 + return -EFAULT;
62702 +
62703 if (copy_to_user(dataptr, kdata, tocopy
62704 * sizeof(struct __user_cap_data_struct))) {
62705 return -EFAULT;
62706 @@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
62707 BUG();
62708 }
62709
62710 - if (security_capable(ns, current_cred(), cap) == 0) {
62711 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
62712 current->flags |= PF_SUPERPRIV;
62713 return true;
62714 }
62715 @@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *ns, int cap)
62716 }
62717 EXPORT_SYMBOL(ns_capable);
62718
62719 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
62720 +{
62721 + if (unlikely(!cap_valid(cap))) {
62722 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
62723 + BUG();
62724 + }
62725 +
62726 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
62727 + current->flags |= PF_SUPERPRIV;
62728 + return true;
62729 + }
62730 + return false;
62731 +}
62732 +EXPORT_SYMBOL(ns_capable_nolog);
62733 +
62734 +bool capable_nolog(int cap)
62735 +{
62736 + return ns_capable_nolog(&init_user_ns, cap);
62737 +}
62738 +EXPORT_SYMBOL(capable_nolog);
62739 +
62740 /**
62741 * task_ns_capable - Determine whether current task has a superior
62742 * capability targeted at a specific task's user namespace.
62743 @@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct *t, int cap)
62744 }
62745 EXPORT_SYMBOL(task_ns_capable);
62746
62747 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
62748 +{
62749 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
62750 +}
62751 +EXPORT_SYMBOL(task_ns_capable_nolog);
62752 +
62753 /**
62754 * nsown_capable - Check superior capability to one's own user_ns
62755 * @cap: The capability in question
62756 diff --git a/kernel/compat.c b/kernel/compat.c
62757 index f346ced..aa2b1f4 100644
62758 --- a/kernel/compat.c
62759 +++ b/kernel/compat.c
62760 @@ -13,6 +13,7 @@
62761
62762 #include <linux/linkage.h>
62763 #include <linux/compat.h>
62764 +#include <linux/module.h>
62765 #include <linux/errno.h>
62766 #include <linux/time.h>
62767 #include <linux/signal.h>
62768 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
62769 mm_segment_t oldfs;
62770 long ret;
62771
62772 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
62773 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
62774 oldfs = get_fs();
62775 set_fs(KERNEL_DS);
62776 ret = hrtimer_nanosleep_restart(restart);
62777 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
62778 oldfs = get_fs();
62779 set_fs(KERNEL_DS);
62780 ret = hrtimer_nanosleep(&tu,
62781 - rmtp ? (struct timespec __user *)&rmt : NULL,
62782 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
62783 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
62784 set_fs(oldfs);
62785
62786 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
62787 mm_segment_t old_fs = get_fs();
62788
62789 set_fs(KERNEL_DS);
62790 - ret = sys_sigpending((old_sigset_t __user *) &s);
62791 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
62792 set_fs(old_fs);
62793 if (ret == 0)
62794 ret = put_user(s, set);
62795 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
62796 old_fs = get_fs();
62797 set_fs(KERNEL_DS);
62798 ret = sys_sigprocmask(how,
62799 - set ? (old_sigset_t __user *) &s : NULL,
62800 - oset ? (old_sigset_t __user *) &s : NULL);
62801 + set ? (old_sigset_t __force_user *) &s : NULL,
62802 + oset ? (old_sigset_t __force_user *) &s : NULL);
62803 set_fs(old_fs);
62804 if (ret == 0)
62805 if (oset)
62806 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
62807 mm_segment_t old_fs = get_fs();
62808
62809 set_fs(KERNEL_DS);
62810 - ret = sys_old_getrlimit(resource, &r);
62811 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
62812 set_fs(old_fs);
62813
62814 if (!ret) {
62815 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
62816 mm_segment_t old_fs = get_fs();
62817
62818 set_fs(KERNEL_DS);
62819 - ret = sys_getrusage(who, (struct rusage __user *) &r);
62820 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
62821 set_fs(old_fs);
62822
62823 if (ret)
62824 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
62825 set_fs (KERNEL_DS);
62826 ret = sys_wait4(pid,
62827 (stat_addr ?
62828 - (unsigned int __user *) &status : NULL),
62829 - options, (struct rusage __user *) &r);
62830 + (unsigned int __force_user *) &status : NULL),
62831 + options, (struct rusage __force_user *) &r);
62832 set_fs (old_fs);
62833
62834 if (ret > 0) {
62835 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
62836 memset(&info, 0, sizeof(info));
62837
62838 set_fs(KERNEL_DS);
62839 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
62840 - uru ? (struct rusage __user *)&ru : NULL);
62841 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
62842 + uru ? (struct rusage __force_user *)&ru : NULL);
62843 set_fs(old_fs);
62844
62845 if ((ret < 0) || (info.si_signo == 0))
62846 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
62847 oldfs = get_fs();
62848 set_fs(KERNEL_DS);
62849 err = sys_timer_settime(timer_id, flags,
62850 - (struct itimerspec __user *) &newts,
62851 - (struct itimerspec __user *) &oldts);
62852 + (struct itimerspec __force_user *) &newts,
62853 + (struct itimerspec __force_user *) &oldts);
62854 set_fs(oldfs);
62855 if (!err && old && put_compat_itimerspec(old, &oldts))
62856 return -EFAULT;
62857 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
62858 oldfs = get_fs();
62859 set_fs(KERNEL_DS);
62860 err = sys_timer_gettime(timer_id,
62861 - (struct itimerspec __user *) &ts);
62862 + (struct itimerspec __force_user *) &ts);
62863 set_fs(oldfs);
62864 if (!err && put_compat_itimerspec(setting, &ts))
62865 return -EFAULT;
62866 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
62867 oldfs = get_fs();
62868 set_fs(KERNEL_DS);
62869 err = sys_clock_settime(which_clock,
62870 - (struct timespec __user *) &ts);
62871 + (struct timespec __force_user *) &ts);
62872 set_fs(oldfs);
62873 return err;
62874 }
62875 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
62876 oldfs = get_fs();
62877 set_fs(KERNEL_DS);
62878 err = sys_clock_gettime(which_clock,
62879 - (struct timespec __user *) &ts);
62880 + (struct timespec __force_user *) &ts);
62881 set_fs(oldfs);
62882 if (!err && put_compat_timespec(&ts, tp))
62883 return -EFAULT;
62884 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
62885
62886 oldfs = get_fs();
62887 set_fs(KERNEL_DS);
62888 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
62889 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
62890 set_fs(oldfs);
62891
62892 err = compat_put_timex(utp, &txc);
62893 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
62894 oldfs = get_fs();
62895 set_fs(KERNEL_DS);
62896 err = sys_clock_getres(which_clock,
62897 - (struct timespec __user *) &ts);
62898 + (struct timespec __force_user *) &ts);
62899 set_fs(oldfs);
62900 if (!err && tp && put_compat_timespec(&ts, tp))
62901 return -EFAULT;
62902 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
62903 long err;
62904 mm_segment_t oldfs;
62905 struct timespec tu;
62906 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
62907 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
62908
62909 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
62910 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
62911 oldfs = get_fs();
62912 set_fs(KERNEL_DS);
62913 err = clock_nanosleep_restart(restart);
62914 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
62915 oldfs = get_fs();
62916 set_fs(KERNEL_DS);
62917 err = sys_clock_nanosleep(which_clock, flags,
62918 - (struct timespec __user *) &in,
62919 - (struct timespec __user *) &out);
62920 + (struct timespec __force_user *) &in,
62921 + (struct timespec __force_user *) &out);
62922 set_fs(oldfs);
62923
62924 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
62925 diff --git a/kernel/configs.c b/kernel/configs.c
62926 index 42e8fa0..9e7406b 100644
62927 --- a/kernel/configs.c
62928 +++ b/kernel/configs.c
62929 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
62930 struct proc_dir_entry *entry;
62931
62932 /* create the current config file */
62933 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
62934 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
62935 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
62936 + &ikconfig_file_ops);
62937 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62938 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
62939 + &ikconfig_file_ops);
62940 +#endif
62941 +#else
62942 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
62943 &ikconfig_file_ops);
62944 +#endif
62945 +
62946 if (!entry)
62947 return -ENOMEM;
62948
62949 diff --git a/kernel/cred.c b/kernel/cred.c
62950 index 5791612..a3c04dc 100644
62951 --- a/kernel/cred.c
62952 +++ b/kernel/cred.c
62953 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
62954 validate_creds(cred);
62955 put_cred(cred);
62956 }
62957 +
62958 +#ifdef CONFIG_GRKERNSEC_SETXID
62959 + cred = (struct cred *) tsk->delayed_cred;
62960 + if (cred) {
62961 + tsk->delayed_cred = NULL;
62962 + validate_creds(cred);
62963 + put_cred(cred);
62964 + }
62965 +#endif
62966 }
62967
62968 /**
62969 @@ -470,7 +479,7 @@ error_put:
62970 * Always returns 0 thus allowing this function to be tail-called at the end
62971 * of, say, sys_setgid().
62972 */
62973 -int commit_creds(struct cred *new)
62974 +static int __commit_creds(struct cred *new)
62975 {
62976 struct task_struct *task = current;
62977 const struct cred *old = task->real_cred;
62978 @@ -489,6 +498,8 @@ int commit_creds(struct cred *new)
62979
62980 get_cred(new); /* we will require a ref for the subj creds too */
62981
62982 + gr_set_role_label(task, new->uid, new->gid);
62983 +
62984 /* dumpability changes */
62985 if (old->euid != new->euid ||
62986 old->egid != new->egid ||
62987 @@ -538,6 +549,92 @@ int commit_creds(struct cred *new)
62988 put_cred(old);
62989 return 0;
62990 }
62991 +#ifdef CONFIG_GRKERNSEC_SETXID
62992 +extern int set_user(struct cred *new);
62993 +
62994 +void gr_delayed_cred_worker(void)
62995 +{
62996 + const struct cred *new = current->delayed_cred;
62997 + struct cred *ncred;
62998 +
62999 + current->delayed_cred = NULL;
63000 +
63001 + if (current_uid() && new != NULL) {
63002 + // from doing get_cred on it when queueing this
63003 + put_cred(new);
63004 + return;
63005 + } else if (new == NULL)
63006 + return;
63007 +
63008 + ncred = prepare_creds();
63009 + if (!ncred)
63010 + goto die;
63011 + // uids
63012 + ncred->uid = new->uid;
63013 + ncred->euid = new->euid;
63014 + ncred->suid = new->suid;
63015 + ncred->fsuid = new->fsuid;
63016 + // gids
63017 + ncred->gid = new->gid;
63018 + ncred->egid = new->egid;
63019 + ncred->sgid = new->sgid;
63020 + ncred->fsgid = new->fsgid;
63021 + // groups
63022 + if (set_groups(ncred, new->group_info) < 0) {
63023 + abort_creds(ncred);
63024 + goto die;
63025 + }
63026 + // caps
63027 + ncred->securebits = new->securebits;
63028 + ncred->cap_inheritable = new->cap_inheritable;
63029 + ncred->cap_permitted = new->cap_permitted;
63030 + ncred->cap_effective = new->cap_effective;
63031 + ncred->cap_bset = new->cap_bset;
63032 +
63033 + if (set_user(ncred)) {
63034 + abort_creds(ncred);
63035 + goto die;
63036 + }
63037 +
63038 + // from doing get_cred on it when queueing this
63039 + put_cred(new);
63040 +
63041 + __commit_creds(ncred);
63042 + return;
63043 +die:
63044 + // from doing get_cred on it when queueing this
63045 + put_cred(new);
63046 + do_group_exit(SIGKILL);
63047 +}
63048 +#endif
63049 +
63050 +int commit_creds(struct cred *new)
63051 +{
63052 +#ifdef CONFIG_GRKERNSEC_SETXID
63053 + struct task_struct *t;
63054 +
63055 + /* we won't get called with tasklist_lock held for writing
63056 + and interrupts disabled as the cred struct in that case is
63057 + init_cred
63058 + */
63059 + if (grsec_enable_setxid && !current_is_single_threaded() &&
63060 + !current_uid() && new->uid) {
63061 + rcu_read_lock();
63062 + read_lock(&tasklist_lock);
63063 + for (t = next_thread(current); t != current;
63064 + t = next_thread(t)) {
63065 + if (t->delayed_cred == NULL) {
63066 + t->delayed_cred = get_cred(new);
63067 + set_tsk_need_resched(t);
63068 + }
63069 + }
63070 + read_unlock(&tasklist_lock);
63071 + rcu_read_unlock();
63072 + }
63073 +#endif
63074 + return __commit_creds(new);
63075 +}
63076 +
63077 EXPORT_SYMBOL(commit_creds);
63078
63079 /**
63080 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
63081 index 0d7c087..01b8cef 100644
63082 --- a/kernel/debug/debug_core.c
63083 +++ b/kernel/debug/debug_core.c
63084 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
63085 */
63086 static atomic_t masters_in_kgdb;
63087 static atomic_t slaves_in_kgdb;
63088 -static atomic_t kgdb_break_tasklet_var;
63089 +static atomic_unchecked_t kgdb_break_tasklet_var;
63090 atomic_t kgdb_setting_breakpoint;
63091
63092 struct task_struct *kgdb_usethread;
63093 @@ -129,7 +129,7 @@ int kgdb_single_step;
63094 static pid_t kgdb_sstep_pid;
63095
63096 /* to keep track of the CPU which is doing the single stepping*/
63097 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63098 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63099
63100 /*
63101 * If you are debugging a problem where roundup (the collection of
63102 @@ -542,7 +542,7 @@ return_normal:
63103 * kernel will only try for the value of sstep_tries before
63104 * giving up and continuing on.
63105 */
63106 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
63107 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
63108 (kgdb_info[cpu].task &&
63109 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
63110 atomic_set(&kgdb_active, -1);
63111 @@ -636,8 +636,8 @@ cpu_master_loop:
63112 }
63113
63114 kgdb_restore:
63115 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
63116 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
63117 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
63118 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
63119 if (kgdb_info[sstep_cpu].task)
63120 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
63121 else
63122 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
63123 static void kgdb_tasklet_bpt(unsigned long ing)
63124 {
63125 kgdb_breakpoint();
63126 - atomic_set(&kgdb_break_tasklet_var, 0);
63127 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
63128 }
63129
63130 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
63131
63132 void kgdb_schedule_breakpoint(void)
63133 {
63134 - if (atomic_read(&kgdb_break_tasklet_var) ||
63135 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
63136 atomic_read(&kgdb_active) != -1 ||
63137 atomic_read(&kgdb_setting_breakpoint))
63138 return;
63139 - atomic_inc(&kgdb_break_tasklet_var);
63140 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
63141 tasklet_schedule(&kgdb_tasklet_breakpoint);
63142 }
63143 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
63144 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
63145 index 63786e7..0780cac 100644
63146 --- a/kernel/debug/kdb/kdb_main.c
63147 +++ b/kernel/debug/kdb/kdb_main.c
63148 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
63149 list_for_each_entry(mod, kdb_modules, list) {
63150
63151 kdb_printf("%-20s%8u 0x%p ", mod->name,
63152 - mod->core_size, (void *)mod);
63153 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
63154 #ifdef CONFIG_MODULE_UNLOAD
63155 kdb_printf("%4d ", module_refcount(mod));
63156 #endif
63157 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
63158 kdb_printf(" (Loading)");
63159 else
63160 kdb_printf(" (Live)");
63161 - kdb_printf(" 0x%p", mod->module_core);
63162 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
63163
63164 #ifdef CONFIG_MODULE_UNLOAD
63165 {
63166 diff --git a/kernel/events/core.c b/kernel/events/core.c
63167 index 58690af..d903d75 100644
63168 --- a/kernel/events/core.c
63169 +++ b/kernel/events/core.c
63170 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
63171 return 0;
63172 }
63173
63174 -static atomic64_t perf_event_id;
63175 +static atomic64_unchecked_t perf_event_id;
63176
63177 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
63178 enum event_type_t event_type);
63179 @@ -2540,7 +2540,7 @@ static void __perf_event_read(void *info)
63180
63181 static inline u64 perf_event_count(struct perf_event *event)
63182 {
63183 - return local64_read(&event->count) + atomic64_read(&event->child_count);
63184 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
63185 }
63186
63187 static u64 perf_event_read(struct perf_event *event)
63188 @@ -3065,9 +3065,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
63189 mutex_lock(&event->child_mutex);
63190 total += perf_event_read(event);
63191 *enabled += event->total_time_enabled +
63192 - atomic64_read(&event->child_total_time_enabled);
63193 + atomic64_read_unchecked(&event->child_total_time_enabled);
63194 *running += event->total_time_running +
63195 - atomic64_read(&event->child_total_time_running);
63196 + atomic64_read_unchecked(&event->child_total_time_running);
63197
63198 list_for_each_entry(child, &event->child_list, child_list) {
63199 total += perf_event_read(child);
63200 @@ -3474,10 +3474,10 @@ void perf_event_update_userpage(struct perf_event *event)
63201 userpg->offset -= local64_read(&event->hw.prev_count);
63202
63203 userpg->time_enabled = enabled +
63204 - atomic64_read(&event->child_total_time_enabled);
63205 + atomic64_read_unchecked(&event->child_total_time_enabled);
63206
63207 userpg->time_running = running +
63208 - atomic64_read(&event->child_total_time_running);
63209 + atomic64_read_unchecked(&event->child_total_time_running);
63210
63211 barrier();
63212 ++userpg->lock;
63213 @@ -3906,11 +3906,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
63214 values[n++] = perf_event_count(event);
63215 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
63216 values[n++] = enabled +
63217 - atomic64_read(&event->child_total_time_enabled);
63218 + atomic64_read_unchecked(&event->child_total_time_enabled);
63219 }
63220 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
63221 values[n++] = running +
63222 - atomic64_read(&event->child_total_time_running);
63223 + atomic64_read_unchecked(&event->child_total_time_running);
63224 }
63225 if (read_format & PERF_FORMAT_ID)
63226 values[n++] = primary_event_id(event);
63227 @@ -4561,12 +4561,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
63228 * need to add enough zero bytes after the string to handle
63229 * the 64bit alignment we do later.
63230 */
63231 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
63232 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
63233 if (!buf) {
63234 name = strncpy(tmp, "//enomem", sizeof(tmp));
63235 goto got_name;
63236 }
63237 - name = d_path(&file->f_path, buf, PATH_MAX);
63238 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
63239 if (IS_ERR(name)) {
63240 name = strncpy(tmp, "//toolong", sizeof(tmp));
63241 goto got_name;
63242 @@ -5921,7 +5921,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
63243 event->parent = parent_event;
63244
63245 event->ns = get_pid_ns(current->nsproxy->pid_ns);
63246 - event->id = atomic64_inc_return(&perf_event_id);
63247 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
63248
63249 event->state = PERF_EVENT_STATE_INACTIVE;
63250
63251 @@ -6443,10 +6443,10 @@ static void sync_child_event(struct perf_event *child_event,
63252 /*
63253 * Add back the child's count to the parent's count:
63254 */
63255 - atomic64_add(child_val, &parent_event->child_count);
63256 - atomic64_add(child_event->total_time_enabled,
63257 + atomic64_add_unchecked(child_val, &parent_event->child_count);
63258 + atomic64_add_unchecked(child_event->total_time_enabled,
63259 &parent_event->child_total_time_enabled);
63260 - atomic64_add(child_event->total_time_running,
63261 + atomic64_add_unchecked(child_event->total_time_running,
63262 &parent_event->child_total_time_running);
63263
63264 /*
63265 diff --git a/kernel/exit.c b/kernel/exit.c
63266 index e6e01b9..619f837 100644
63267 --- a/kernel/exit.c
63268 +++ b/kernel/exit.c
63269 @@ -57,6 +57,10 @@
63270 #include <asm/pgtable.h>
63271 #include <asm/mmu_context.h>
63272
63273 +#ifdef CONFIG_GRKERNSEC
63274 +extern rwlock_t grsec_exec_file_lock;
63275 +#endif
63276 +
63277 static void exit_mm(struct task_struct * tsk);
63278
63279 static void __unhash_process(struct task_struct *p, bool group_dead)
63280 @@ -168,6 +172,10 @@ void release_task(struct task_struct * p)
63281 struct task_struct *leader;
63282 int zap_leader;
63283 repeat:
63284 +#ifdef CONFIG_NET
63285 + gr_del_task_from_ip_table(p);
63286 +#endif
63287 +
63288 /* don't need to get the RCU readlock here - the process is dead and
63289 * can't be modifying its own credentials. But shut RCU-lockdep up */
63290 rcu_read_lock();
63291 @@ -380,7 +388,7 @@ int allow_signal(int sig)
63292 * know it'll be handled, so that they don't get converted to
63293 * SIGKILL or just silently dropped.
63294 */
63295 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
63296 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
63297 recalc_sigpending();
63298 spin_unlock_irq(&current->sighand->siglock);
63299 return 0;
63300 @@ -416,6 +424,17 @@ void daemonize(const char *name, ...)
63301 vsnprintf(current->comm, sizeof(current->comm), name, args);
63302 va_end(args);
63303
63304 +#ifdef CONFIG_GRKERNSEC
63305 + write_lock(&grsec_exec_file_lock);
63306 + if (current->exec_file) {
63307 + fput(current->exec_file);
63308 + current->exec_file = NULL;
63309 + }
63310 + write_unlock(&grsec_exec_file_lock);
63311 +#endif
63312 +
63313 + gr_set_kernel_label(current);
63314 +
63315 /*
63316 * If we were started as result of loading a module, close all of the
63317 * user space pages. We don't need them, and if we didn't close them
63318 @@ -893,6 +912,8 @@ NORET_TYPE void do_exit(long code)
63319 struct task_struct *tsk = current;
63320 int group_dead;
63321
63322 + set_fs(USER_DS);
63323 +
63324 profile_task_exit(tsk);
63325
63326 WARN_ON(blk_needs_flush_plug(tsk));
63327 @@ -909,7 +930,6 @@ NORET_TYPE void do_exit(long code)
63328 * mm_release()->clear_child_tid() from writing to a user-controlled
63329 * kernel address.
63330 */
63331 - set_fs(USER_DS);
63332
63333 ptrace_event(PTRACE_EVENT_EXIT, code);
63334
63335 @@ -971,6 +991,9 @@ NORET_TYPE void do_exit(long code)
63336 tsk->exit_code = code;
63337 taskstats_exit(tsk, group_dead);
63338
63339 + gr_acl_handle_psacct(tsk, code);
63340 + gr_acl_handle_exit();
63341 +
63342 exit_mm(tsk);
63343
63344 if (group_dead)
63345 diff --git a/kernel/fork.c b/kernel/fork.c
63346 index da4a6a1..c04943c 100644
63347 --- a/kernel/fork.c
63348 +++ b/kernel/fork.c
63349 @@ -280,7 +280,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
63350 *stackend = STACK_END_MAGIC; /* for overflow detection */
63351
63352 #ifdef CONFIG_CC_STACKPROTECTOR
63353 - tsk->stack_canary = get_random_int();
63354 + tsk->stack_canary = pax_get_random_long();
63355 #endif
63356
63357 /*
63358 @@ -304,13 +304,77 @@ out:
63359 }
63360
63361 #ifdef CONFIG_MMU
63362 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
63363 +{
63364 + struct vm_area_struct *tmp;
63365 + unsigned long charge;
63366 + struct mempolicy *pol;
63367 + struct file *file;
63368 +
63369 + charge = 0;
63370 + if (mpnt->vm_flags & VM_ACCOUNT) {
63371 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
63372 + if (security_vm_enough_memory(len))
63373 + goto fail_nomem;
63374 + charge = len;
63375 + }
63376 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
63377 + if (!tmp)
63378 + goto fail_nomem;
63379 + *tmp = *mpnt;
63380 + tmp->vm_mm = mm;
63381 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
63382 + pol = mpol_dup(vma_policy(mpnt));
63383 + if (IS_ERR(pol))
63384 + goto fail_nomem_policy;
63385 + vma_set_policy(tmp, pol);
63386 + if (anon_vma_fork(tmp, mpnt))
63387 + goto fail_nomem_anon_vma_fork;
63388 + tmp->vm_flags &= ~VM_LOCKED;
63389 + tmp->vm_next = tmp->vm_prev = NULL;
63390 + tmp->vm_mirror = NULL;
63391 + file = tmp->vm_file;
63392 + if (file) {
63393 + struct inode *inode = file->f_path.dentry->d_inode;
63394 + struct address_space *mapping = file->f_mapping;
63395 +
63396 + get_file(file);
63397 + if (tmp->vm_flags & VM_DENYWRITE)
63398 + atomic_dec(&inode->i_writecount);
63399 + mutex_lock(&mapping->i_mmap_mutex);
63400 + if (tmp->vm_flags & VM_SHARED)
63401 + mapping->i_mmap_writable++;
63402 + flush_dcache_mmap_lock(mapping);
63403 + /* insert tmp into the share list, just after mpnt */
63404 + vma_prio_tree_add(tmp, mpnt);
63405 + flush_dcache_mmap_unlock(mapping);
63406 + mutex_unlock(&mapping->i_mmap_mutex);
63407 + }
63408 +
63409 + /*
63410 + * Clear hugetlb-related page reserves for children. This only
63411 + * affects MAP_PRIVATE mappings. Faults generated by the child
63412 + * are not guaranteed to succeed, even if read-only
63413 + */
63414 + if (is_vm_hugetlb_page(tmp))
63415 + reset_vma_resv_huge_pages(tmp);
63416 +
63417 + return tmp;
63418 +
63419 +fail_nomem_anon_vma_fork:
63420 + mpol_put(pol);
63421 +fail_nomem_policy:
63422 + kmem_cache_free(vm_area_cachep, tmp);
63423 +fail_nomem:
63424 + vm_unacct_memory(charge);
63425 + return NULL;
63426 +}
63427 +
63428 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63429 {
63430 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
63431 struct rb_node **rb_link, *rb_parent;
63432 int retval;
63433 - unsigned long charge;
63434 - struct mempolicy *pol;
63435
63436 down_write(&oldmm->mmap_sem);
63437 flush_cache_dup_mm(oldmm);
63438 @@ -322,8 +386,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63439 mm->locked_vm = 0;
63440 mm->mmap = NULL;
63441 mm->mmap_cache = NULL;
63442 - mm->free_area_cache = oldmm->mmap_base;
63443 - mm->cached_hole_size = ~0UL;
63444 + mm->free_area_cache = oldmm->free_area_cache;
63445 + mm->cached_hole_size = oldmm->cached_hole_size;
63446 mm->map_count = 0;
63447 cpumask_clear(mm_cpumask(mm));
63448 mm->mm_rb = RB_ROOT;
63449 @@ -339,8 +403,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63450
63451 prev = NULL;
63452 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
63453 - struct file *file;
63454 -
63455 if (mpnt->vm_flags & VM_DONTCOPY) {
63456 long pages = vma_pages(mpnt);
63457 mm->total_vm -= pages;
63458 @@ -348,53 +410,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63459 -pages);
63460 continue;
63461 }
63462 - charge = 0;
63463 - if (mpnt->vm_flags & VM_ACCOUNT) {
63464 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
63465 - if (security_vm_enough_memory(len))
63466 - goto fail_nomem;
63467 - charge = len;
63468 + tmp = dup_vma(mm, mpnt);
63469 + if (!tmp) {
63470 + retval = -ENOMEM;
63471 + goto out;
63472 }
63473 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
63474 - if (!tmp)
63475 - goto fail_nomem;
63476 - *tmp = *mpnt;
63477 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
63478 - pol = mpol_dup(vma_policy(mpnt));
63479 - retval = PTR_ERR(pol);
63480 - if (IS_ERR(pol))
63481 - goto fail_nomem_policy;
63482 - vma_set_policy(tmp, pol);
63483 - tmp->vm_mm = mm;
63484 - if (anon_vma_fork(tmp, mpnt))
63485 - goto fail_nomem_anon_vma_fork;
63486 - tmp->vm_flags &= ~VM_LOCKED;
63487 - tmp->vm_next = tmp->vm_prev = NULL;
63488 - file = tmp->vm_file;
63489 - if (file) {
63490 - struct inode *inode = file->f_path.dentry->d_inode;
63491 - struct address_space *mapping = file->f_mapping;
63492 -
63493 - get_file(file);
63494 - if (tmp->vm_flags & VM_DENYWRITE)
63495 - atomic_dec(&inode->i_writecount);
63496 - mutex_lock(&mapping->i_mmap_mutex);
63497 - if (tmp->vm_flags & VM_SHARED)
63498 - mapping->i_mmap_writable++;
63499 - flush_dcache_mmap_lock(mapping);
63500 - /* insert tmp into the share list, just after mpnt */
63501 - vma_prio_tree_add(tmp, mpnt);
63502 - flush_dcache_mmap_unlock(mapping);
63503 - mutex_unlock(&mapping->i_mmap_mutex);
63504 - }
63505 -
63506 - /*
63507 - * Clear hugetlb-related page reserves for children. This only
63508 - * affects MAP_PRIVATE mappings. Faults generated by the child
63509 - * are not guaranteed to succeed, even if read-only
63510 - */
63511 - if (is_vm_hugetlb_page(tmp))
63512 - reset_vma_resv_huge_pages(tmp);
63513
63514 /*
63515 * Link in the new vma and copy the page table entries.
63516 @@ -417,6 +437,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63517 if (retval)
63518 goto out;
63519 }
63520 +
63521 +#ifdef CONFIG_PAX_SEGMEXEC
63522 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
63523 + struct vm_area_struct *mpnt_m;
63524 +
63525 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
63526 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
63527 +
63528 + if (!mpnt->vm_mirror)
63529 + continue;
63530 +
63531 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
63532 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
63533 + mpnt->vm_mirror = mpnt_m;
63534 + } else {
63535 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
63536 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
63537 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
63538 + mpnt->vm_mirror->vm_mirror = mpnt;
63539 + }
63540 + }
63541 + BUG_ON(mpnt_m);
63542 + }
63543 +#endif
63544 +
63545 /* a new mm has just been created */
63546 arch_dup_mmap(oldmm, mm);
63547 retval = 0;
63548 @@ -425,14 +470,6 @@ out:
63549 flush_tlb_mm(oldmm);
63550 up_write(&oldmm->mmap_sem);
63551 return retval;
63552 -fail_nomem_anon_vma_fork:
63553 - mpol_put(pol);
63554 -fail_nomem_policy:
63555 - kmem_cache_free(vm_area_cachep, tmp);
63556 -fail_nomem:
63557 - retval = -ENOMEM;
63558 - vm_unacct_memory(charge);
63559 - goto out;
63560 }
63561
63562 static inline int mm_alloc_pgd(struct mm_struct *mm)
63563 @@ -829,13 +866,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
63564 spin_unlock(&fs->lock);
63565 return -EAGAIN;
63566 }
63567 - fs->users++;
63568 + atomic_inc(&fs->users);
63569 spin_unlock(&fs->lock);
63570 return 0;
63571 }
63572 tsk->fs = copy_fs_struct(fs);
63573 if (!tsk->fs)
63574 return -ENOMEM;
63575 + gr_set_chroot_entries(tsk, &tsk->fs->root);
63576 return 0;
63577 }
63578
63579 @@ -1097,6 +1135,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
63580 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
63581 #endif
63582 retval = -EAGAIN;
63583 +
63584 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
63585 +
63586 if (atomic_read(&p->real_cred->user->processes) >=
63587 task_rlimit(p, RLIMIT_NPROC)) {
63588 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
63589 @@ -1256,6 +1297,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
63590 if (clone_flags & CLONE_THREAD)
63591 p->tgid = current->tgid;
63592
63593 + gr_copy_label(p);
63594 +
63595 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
63596 /*
63597 * Clear TID on mm_release()?
63598 @@ -1418,6 +1461,8 @@ bad_fork_cleanup_count:
63599 bad_fork_free:
63600 free_task(p);
63601 fork_out:
63602 + gr_log_forkfail(retval);
63603 +
63604 return ERR_PTR(retval);
63605 }
63606
63607 @@ -1518,6 +1563,8 @@ long do_fork(unsigned long clone_flags,
63608 if (clone_flags & CLONE_PARENT_SETTID)
63609 put_user(nr, parent_tidptr);
63610
63611 + gr_handle_brute_check();
63612 +
63613 if (clone_flags & CLONE_VFORK) {
63614 p->vfork_done = &vfork;
63615 init_completion(&vfork);
63616 @@ -1627,7 +1674,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
63617 return 0;
63618
63619 /* don't need lock here; in the worst case we'll do useless copy */
63620 - if (fs->users == 1)
63621 + if (atomic_read(&fs->users) == 1)
63622 return 0;
63623
63624 *new_fsp = copy_fs_struct(fs);
63625 @@ -1716,7 +1763,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
63626 fs = current->fs;
63627 spin_lock(&fs->lock);
63628 current->fs = new_fs;
63629 - if (--fs->users)
63630 + gr_set_chroot_entries(current, &current->fs->root);
63631 + if (atomic_dec_return(&fs->users))
63632 new_fs = NULL;
63633 else
63634 new_fs = fs;
63635 diff --git a/kernel/futex.c b/kernel/futex.c
63636 index 1614be2..37abc7e 100644
63637 --- a/kernel/futex.c
63638 +++ b/kernel/futex.c
63639 @@ -54,6 +54,7 @@
63640 #include <linux/mount.h>
63641 #include <linux/pagemap.h>
63642 #include <linux/syscalls.h>
63643 +#include <linux/ptrace.h>
63644 #include <linux/signal.h>
63645 #include <linux/export.h>
63646 #include <linux/magic.h>
63647 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
63648 struct page *page, *page_head;
63649 int err, ro = 0;
63650
63651 +#ifdef CONFIG_PAX_SEGMEXEC
63652 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
63653 + return -EFAULT;
63654 +#endif
63655 +
63656 /*
63657 * The futex address must be "naturally" aligned.
63658 */
63659 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
63660 if (!p)
63661 goto err_unlock;
63662 ret = -EPERM;
63663 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63664 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
63665 + goto err_unlock;
63666 +#endif
63667 pcred = __task_cred(p);
63668 /* If victim is in different user_ns, then uids are not
63669 comparable, so we must have CAP_SYS_PTRACE */
63670 @@ -2724,6 +2734,7 @@ static int __init futex_init(void)
63671 {
63672 u32 curval;
63673 int i;
63674 + mm_segment_t oldfs;
63675
63676 /*
63677 * This will fail and we want it. Some arch implementations do
63678 @@ -2735,8 +2746,11 @@ static int __init futex_init(void)
63679 * implementation, the non-functional ones will return
63680 * -ENOSYS.
63681 */
63682 + oldfs = get_fs();
63683 + set_fs(USER_DS);
63684 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
63685 futex_cmpxchg_enabled = 1;
63686 + set_fs(oldfs);
63687
63688 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
63689 plist_head_init(&futex_queues[i].chain);
63690 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
63691 index 5f9e689..582d46d 100644
63692 --- a/kernel/futex_compat.c
63693 +++ b/kernel/futex_compat.c
63694 @@ -10,6 +10,7 @@
63695 #include <linux/compat.h>
63696 #include <linux/nsproxy.h>
63697 #include <linux/futex.h>
63698 +#include <linux/ptrace.h>
63699
63700 #include <asm/uaccess.h>
63701
63702 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
63703 {
63704 struct compat_robust_list_head __user *head;
63705 unsigned long ret;
63706 - const struct cred *cred = current_cred(), *pcred;
63707 + const struct cred *cred = current_cred();
63708 + const struct cred *pcred;
63709
63710 if (!futex_cmpxchg_enabled)
63711 return -ENOSYS;
63712 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
63713 if (!p)
63714 goto err_unlock;
63715 ret = -EPERM;
63716 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63717 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
63718 + goto err_unlock;
63719 +#endif
63720 pcred = __task_cred(p);
63721 /* If victim is in different user_ns, then uids are not
63722 comparable, so we must have CAP_SYS_PTRACE */
63723 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
63724 index 9b22d03..6295b62 100644
63725 --- a/kernel/gcov/base.c
63726 +++ b/kernel/gcov/base.c
63727 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
63728 }
63729
63730 #ifdef CONFIG_MODULES
63731 -static inline int within(void *addr, void *start, unsigned long size)
63732 -{
63733 - return ((addr >= start) && (addr < start + size));
63734 -}
63735 -
63736 /* Update list and generate events when modules are unloaded. */
63737 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
63738 void *data)
63739 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
63740 prev = NULL;
63741 /* Remove entries located in module from linked list. */
63742 for (info = gcov_info_head; info; info = info->next) {
63743 - if (within(info, mod->module_core, mod->core_size)) {
63744 + if (within_module_core_rw((unsigned long)info, mod)) {
63745 if (prev)
63746 prev->next = info->next;
63747 else
63748 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
63749 index ae34bf5..4e2f3d0 100644
63750 --- a/kernel/hrtimer.c
63751 +++ b/kernel/hrtimer.c
63752 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
63753 local_irq_restore(flags);
63754 }
63755
63756 -static void run_hrtimer_softirq(struct softirq_action *h)
63757 +static void run_hrtimer_softirq(void)
63758 {
63759 hrtimer_peek_ahead_timers();
63760 }
63761 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
63762 index 66ff710..05a5128 100644
63763 --- a/kernel/jump_label.c
63764 +++ b/kernel/jump_label.c
63765 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
63766
63767 size = (((unsigned long)stop - (unsigned long)start)
63768 / sizeof(struct jump_entry));
63769 + pax_open_kernel();
63770 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
63771 + pax_close_kernel();
63772 }
63773
63774 static void jump_label_update(struct jump_label_key *key, int enable);
63775 @@ -303,10 +305,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
63776 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
63777 struct jump_entry *iter;
63778
63779 + pax_open_kernel();
63780 for (iter = iter_start; iter < iter_stop; iter++) {
63781 if (within_module_init(iter->code, mod))
63782 iter->code = 0;
63783 }
63784 + pax_close_kernel();
63785 }
63786
63787 static int
63788 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
63789 index 079f1d3..a407562 100644
63790 --- a/kernel/kallsyms.c
63791 +++ b/kernel/kallsyms.c
63792 @@ -11,6 +11,9 @@
63793 * Changed the compression method from stem compression to "table lookup"
63794 * compression (see scripts/kallsyms.c for a more complete description)
63795 */
63796 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63797 +#define __INCLUDED_BY_HIDESYM 1
63798 +#endif
63799 #include <linux/kallsyms.h>
63800 #include <linux/module.h>
63801 #include <linux/init.h>
63802 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
63803
63804 static inline int is_kernel_inittext(unsigned long addr)
63805 {
63806 + if (system_state != SYSTEM_BOOTING)
63807 + return 0;
63808 +
63809 if (addr >= (unsigned long)_sinittext
63810 && addr <= (unsigned long)_einittext)
63811 return 1;
63812 return 0;
63813 }
63814
63815 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63816 +#ifdef CONFIG_MODULES
63817 +static inline int is_module_text(unsigned long addr)
63818 +{
63819 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
63820 + return 1;
63821 +
63822 + addr = ktla_ktva(addr);
63823 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
63824 +}
63825 +#else
63826 +static inline int is_module_text(unsigned long addr)
63827 +{
63828 + return 0;
63829 +}
63830 +#endif
63831 +#endif
63832 +
63833 static inline int is_kernel_text(unsigned long addr)
63834 {
63835 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
63836 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
63837
63838 static inline int is_kernel(unsigned long addr)
63839 {
63840 +
63841 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63842 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
63843 + return 1;
63844 +
63845 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
63846 +#else
63847 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
63848 +#endif
63849 +
63850 return 1;
63851 return in_gate_area_no_mm(addr);
63852 }
63853
63854 static int is_ksym_addr(unsigned long addr)
63855 {
63856 +
63857 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63858 + if (is_module_text(addr))
63859 + return 0;
63860 +#endif
63861 +
63862 if (all_var)
63863 return is_kernel(addr);
63864
63865 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
63866
63867 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
63868 {
63869 - iter->name[0] = '\0';
63870 iter->nameoff = get_symbol_offset(new_pos);
63871 iter->pos = new_pos;
63872 }
63873 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
63874 {
63875 struct kallsym_iter *iter = m->private;
63876
63877 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63878 + if (current_uid())
63879 + return 0;
63880 +#endif
63881 +
63882 /* Some debugging symbols have no name. Ignore them. */
63883 if (!iter->name[0])
63884 return 0;
63885 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
63886 struct kallsym_iter *iter;
63887 int ret;
63888
63889 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
63890 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
63891 if (!iter)
63892 return -ENOMEM;
63893 reset_iter(iter, 0);
63894 diff --git a/kernel/kexec.c b/kernel/kexec.c
63895 index dc7bc08..4601964 100644
63896 --- a/kernel/kexec.c
63897 +++ b/kernel/kexec.c
63898 @@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
63899 unsigned long flags)
63900 {
63901 struct compat_kexec_segment in;
63902 - struct kexec_segment out, __user *ksegments;
63903 + struct kexec_segment out;
63904 + struct kexec_segment __user *ksegments;
63905 unsigned long i, result;
63906
63907 /* Don't allow clients that don't understand the native
63908 diff --git a/kernel/kmod.c b/kernel/kmod.c
63909 index a4bea97..7a1ae9a 100644
63910 --- a/kernel/kmod.c
63911 +++ b/kernel/kmod.c
63912 @@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
63913 * If module auto-loading support is disabled then this function
63914 * becomes a no-operation.
63915 */
63916 -int __request_module(bool wait, const char *fmt, ...)
63917 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
63918 {
63919 - va_list args;
63920 char module_name[MODULE_NAME_LEN];
63921 unsigned int max_modprobes;
63922 int ret;
63923 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
63924 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
63925 static char *envp[] = { "HOME=/",
63926 "TERM=linux",
63927 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
63928 @@ -88,9 +87,7 @@ int __request_module(bool wait, const char *fmt, ...)
63929 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
63930 static int kmod_loop_msg;
63931
63932 - va_start(args, fmt);
63933 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
63934 - va_end(args);
63935 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
63936 if (ret >= MODULE_NAME_LEN)
63937 return -ENAMETOOLONG;
63938
63939 @@ -98,6 +95,20 @@ int __request_module(bool wait, const char *fmt, ...)
63940 if (ret)
63941 return ret;
63942
63943 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
63944 + if (!current_uid()) {
63945 + /* hack to workaround consolekit/udisks stupidity */
63946 + read_lock(&tasklist_lock);
63947 + if (!strcmp(current->comm, "mount") &&
63948 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
63949 + read_unlock(&tasklist_lock);
63950 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
63951 + return -EPERM;
63952 + }
63953 + read_unlock(&tasklist_lock);
63954 + }
63955 +#endif
63956 +
63957 /* If modprobe needs a service that is in a module, we get a recursive
63958 * loop. Limit the number of running kmod threads to max_threads/2 or
63959 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
63960 @@ -133,6 +144,47 @@ int __request_module(bool wait, const char *fmt, ...)
63961 atomic_dec(&kmod_concurrent);
63962 return ret;
63963 }
63964 +
63965 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
63966 +{
63967 + va_list args;
63968 + int ret;
63969 +
63970 + va_start(args, fmt);
63971 + ret = ____request_module(wait, module_param, fmt, args);
63972 + va_end(args);
63973 +
63974 + return ret;
63975 +}
63976 +
63977 +int __request_module(bool wait, const char *fmt, ...)
63978 +{
63979 + va_list args;
63980 + int ret;
63981 +
63982 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
63983 + if (current_uid()) {
63984 + char module_param[MODULE_NAME_LEN];
63985 +
63986 + memset(module_param, 0, sizeof(module_param));
63987 +
63988 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
63989 +
63990 + va_start(args, fmt);
63991 + ret = ____request_module(wait, module_param, fmt, args);
63992 + va_end(args);
63993 +
63994 + return ret;
63995 + }
63996 +#endif
63997 +
63998 + va_start(args, fmt);
63999 + ret = ____request_module(wait, NULL, fmt, args);
64000 + va_end(args);
64001 +
64002 + return ret;
64003 +}
64004 +
64005 EXPORT_SYMBOL(__request_module);
64006 #endif /* CONFIG_MODULES */
64007
64008 @@ -222,7 +274,7 @@ static int wait_for_helper(void *data)
64009 *
64010 * Thus the __user pointer cast is valid here.
64011 */
64012 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
64013 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
64014
64015 /*
64016 * If ret is 0, either ____call_usermodehelper failed and the
64017 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
64018 index e5d8464..4cc8cf0 100644
64019 --- a/kernel/kprobes.c
64020 +++ b/kernel/kprobes.c
64021 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
64022 * kernel image and loaded module images reside. This is required
64023 * so x86_64 can correctly handle the %rip-relative fixups.
64024 */
64025 - kip->insns = module_alloc(PAGE_SIZE);
64026 + kip->insns = module_alloc_exec(PAGE_SIZE);
64027 if (!kip->insns) {
64028 kfree(kip);
64029 return NULL;
64030 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
64031 */
64032 if (!list_is_singular(&kip->list)) {
64033 list_del(&kip->list);
64034 - module_free(NULL, kip->insns);
64035 + module_free_exec(NULL, kip->insns);
64036 kfree(kip);
64037 }
64038 return 1;
64039 @@ -1949,7 +1949,7 @@ static int __init init_kprobes(void)
64040 {
64041 int i, err = 0;
64042 unsigned long offset = 0, size = 0;
64043 - char *modname, namebuf[128];
64044 + char *modname, namebuf[KSYM_NAME_LEN];
64045 const char *symbol_name;
64046 void *addr;
64047 struct kprobe_blackpoint *kb;
64048 @@ -2075,7 +2075,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
64049 const char *sym = NULL;
64050 unsigned int i = *(loff_t *) v;
64051 unsigned long offset = 0;
64052 - char *modname, namebuf[128];
64053 + char *modname, namebuf[KSYM_NAME_LEN];
64054
64055 head = &kprobe_table[i];
64056 preempt_disable();
64057 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
64058 index b2e08c9..01d8049 100644
64059 --- a/kernel/lockdep.c
64060 +++ b/kernel/lockdep.c
64061 @@ -592,6 +592,10 @@ static int static_obj(void *obj)
64062 end = (unsigned long) &_end,
64063 addr = (unsigned long) obj;
64064
64065 +#ifdef CONFIG_PAX_KERNEXEC
64066 + start = ktla_ktva(start);
64067 +#endif
64068 +
64069 /*
64070 * static variable?
64071 */
64072 @@ -731,6 +735,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
64073 if (!static_obj(lock->key)) {
64074 debug_locks_off();
64075 printk("INFO: trying to register non-static key.\n");
64076 + printk("lock:%pS key:%pS.\n", lock, lock->key);
64077 printk("the code is fine but needs lockdep annotation.\n");
64078 printk("turning off the locking correctness validator.\n");
64079 dump_stack();
64080 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
64081 if (!class)
64082 return 0;
64083 }
64084 - atomic_inc((atomic_t *)&class->ops);
64085 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
64086 if (very_verbose(class)) {
64087 printk("\nacquire class [%p] %s", class->key, class->name);
64088 if (class->name_version > 1)
64089 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
64090 index 91c32a0..b2c71c5 100644
64091 --- a/kernel/lockdep_proc.c
64092 +++ b/kernel/lockdep_proc.c
64093 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
64094
64095 static void print_name(struct seq_file *m, struct lock_class *class)
64096 {
64097 - char str[128];
64098 + char str[KSYM_NAME_LEN];
64099 const char *name = class->name;
64100
64101 if (!name) {
64102 diff --git a/kernel/module.c b/kernel/module.c
64103 index 178333c..04e3408 100644
64104 --- a/kernel/module.c
64105 +++ b/kernel/module.c
64106 @@ -58,6 +58,7 @@
64107 #include <linux/jump_label.h>
64108 #include <linux/pfn.h>
64109 #include <linux/bsearch.h>
64110 +#include <linux/grsecurity.h>
64111
64112 #define CREATE_TRACE_POINTS
64113 #include <trace/events/module.h>
64114 @@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
64115
64116 /* Bounds of module allocation, for speeding __module_address.
64117 * Protected by module_mutex. */
64118 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
64119 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
64120 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
64121
64122 int register_module_notifier(struct notifier_block * nb)
64123 {
64124 @@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
64125 return true;
64126
64127 list_for_each_entry_rcu(mod, &modules, list) {
64128 - struct symsearch arr[] = {
64129 + struct symsearch modarr[] = {
64130 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
64131 NOT_GPL_ONLY, false },
64132 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
64133 @@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
64134 #endif
64135 };
64136
64137 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
64138 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
64139 return true;
64140 }
64141 return false;
64142 @@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
64143 static int percpu_modalloc(struct module *mod,
64144 unsigned long size, unsigned long align)
64145 {
64146 - if (align > PAGE_SIZE) {
64147 + if (align-1 >= PAGE_SIZE) {
64148 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
64149 mod->name, align, PAGE_SIZE);
64150 align = PAGE_SIZE;
64151 @@ -1183,7 +1185,7 @@ resolve_symbol_wait(struct module *mod,
64152 */
64153 #ifdef CONFIG_SYSFS
64154
64155 -#ifdef CONFIG_KALLSYMS
64156 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64157 static inline bool sect_empty(const Elf_Shdr *sect)
64158 {
64159 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
64160 @@ -1649,21 +1651,21 @@ static void set_section_ro_nx(void *base,
64161
64162 static void unset_module_core_ro_nx(struct module *mod)
64163 {
64164 - set_page_attributes(mod->module_core + mod->core_text_size,
64165 - mod->module_core + mod->core_size,
64166 + set_page_attributes(mod->module_core_rw,
64167 + mod->module_core_rw + mod->core_size_rw,
64168 set_memory_x);
64169 - set_page_attributes(mod->module_core,
64170 - mod->module_core + mod->core_ro_size,
64171 + set_page_attributes(mod->module_core_rx,
64172 + mod->module_core_rx + mod->core_size_rx,
64173 set_memory_rw);
64174 }
64175
64176 static void unset_module_init_ro_nx(struct module *mod)
64177 {
64178 - set_page_attributes(mod->module_init + mod->init_text_size,
64179 - mod->module_init + mod->init_size,
64180 + set_page_attributes(mod->module_init_rw,
64181 + mod->module_init_rw + mod->init_size_rw,
64182 set_memory_x);
64183 - set_page_attributes(mod->module_init,
64184 - mod->module_init + mod->init_ro_size,
64185 + set_page_attributes(mod->module_init_rx,
64186 + mod->module_init_rx + mod->init_size_rx,
64187 set_memory_rw);
64188 }
64189
64190 @@ -1674,14 +1676,14 @@ void set_all_modules_text_rw(void)
64191
64192 mutex_lock(&module_mutex);
64193 list_for_each_entry_rcu(mod, &modules, list) {
64194 - if ((mod->module_core) && (mod->core_text_size)) {
64195 - set_page_attributes(mod->module_core,
64196 - mod->module_core + mod->core_text_size,
64197 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
64198 + set_page_attributes(mod->module_core_rx,
64199 + mod->module_core_rx + mod->core_size_rx,
64200 set_memory_rw);
64201 }
64202 - if ((mod->module_init) && (mod->init_text_size)) {
64203 - set_page_attributes(mod->module_init,
64204 - mod->module_init + mod->init_text_size,
64205 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
64206 + set_page_attributes(mod->module_init_rx,
64207 + mod->module_init_rx + mod->init_size_rx,
64208 set_memory_rw);
64209 }
64210 }
64211 @@ -1695,14 +1697,14 @@ void set_all_modules_text_ro(void)
64212
64213 mutex_lock(&module_mutex);
64214 list_for_each_entry_rcu(mod, &modules, list) {
64215 - if ((mod->module_core) && (mod->core_text_size)) {
64216 - set_page_attributes(mod->module_core,
64217 - mod->module_core + mod->core_text_size,
64218 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
64219 + set_page_attributes(mod->module_core_rx,
64220 + mod->module_core_rx + mod->core_size_rx,
64221 set_memory_ro);
64222 }
64223 - if ((mod->module_init) && (mod->init_text_size)) {
64224 - set_page_attributes(mod->module_init,
64225 - mod->module_init + mod->init_text_size,
64226 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
64227 + set_page_attributes(mod->module_init_rx,
64228 + mod->module_init_rx + mod->init_size_rx,
64229 set_memory_ro);
64230 }
64231 }
64232 @@ -1748,16 +1750,19 @@ static void free_module(struct module *mod)
64233
64234 /* This may be NULL, but that's OK */
64235 unset_module_init_ro_nx(mod);
64236 - module_free(mod, mod->module_init);
64237 + module_free(mod, mod->module_init_rw);
64238 + module_free_exec(mod, mod->module_init_rx);
64239 kfree(mod->args);
64240 percpu_modfree(mod);
64241
64242 /* Free lock-classes: */
64243 - lockdep_free_key_range(mod->module_core, mod->core_size);
64244 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
64245 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
64246
64247 /* Finally, free the core (containing the module structure) */
64248 unset_module_core_ro_nx(mod);
64249 - module_free(mod, mod->module_core);
64250 + module_free_exec(mod, mod->module_core_rx);
64251 + module_free(mod, mod->module_core_rw);
64252
64253 #ifdef CONFIG_MPU
64254 update_protections(current->mm);
64255 @@ -1826,10 +1831,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64256 unsigned int i;
64257 int ret = 0;
64258 const struct kernel_symbol *ksym;
64259 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64260 + int is_fs_load = 0;
64261 + int register_filesystem_found = 0;
64262 + char *p;
64263 +
64264 + p = strstr(mod->args, "grsec_modharden_fs");
64265 + if (p) {
64266 + char *endptr = p + strlen("grsec_modharden_fs");
64267 + /* copy \0 as well */
64268 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
64269 + is_fs_load = 1;
64270 + }
64271 +#endif
64272
64273 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
64274 const char *name = info->strtab + sym[i].st_name;
64275
64276 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64277 + /* it's a real shame this will never get ripped and copied
64278 + upstream! ;(
64279 + */
64280 + if (is_fs_load && !strcmp(name, "register_filesystem"))
64281 + register_filesystem_found = 1;
64282 +#endif
64283 +
64284 switch (sym[i].st_shndx) {
64285 case SHN_COMMON:
64286 /* We compiled with -fno-common. These are not
64287 @@ -1850,7 +1876,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64288 ksym = resolve_symbol_wait(mod, info, name);
64289 /* Ok if resolved. */
64290 if (ksym && !IS_ERR(ksym)) {
64291 + pax_open_kernel();
64292 sym[i].st_value = ksym->value;
64293 + pax_close_kernel();
64294 break;
64295 }
64296
64297 @@ -1869,11 +1897,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64298 secbase = (unsigned long)mod_percpu(mod);
64299 else
64300 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
64301 + pax_open_kernel();
64302 sym[i].st_value += secbase;
64303 + pax_close_kernel();
64304 break;
64305 }
64306 }
64307
64308 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64309 + if (is_fs_load && !register_filesystem_found) {
64310 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
64311 + ret = -EPERM;
64312 + }
64313 +#endif
64314 +
64315 return ret;
64316 }
64317
64318 @@ -1977,22 +2014,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
64319 || s->sh_entsize != ~0UL
64320 || strstarts(sname, ".init"))
64321 continue;
64322 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
64323 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
64324 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
64325 + else
64326 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
64327 DEBUGP("\t%s\n", name);
64328 }
64329 - switch (m) {
64330 - case 0: /* executable */
64331 - mod->core_size = debug_align(mod->core_size);
64332 - mod->core_text_size = mod->core_size;
64333 - break;
64334 - case 1: /* RO: text and ro-data */
64335 - mod->core_size = debug_align(mod->core_size);
64336 - mod->core_ro_size = mod->core_size;
64337 - break;
64338 - case 3: /* whole core */
64339 - mod->core_size = debug_align(mod->core_size);
64340 - break;
64341 - }
64342 }
64343
64344 DEBUGP("Init section allocation order:\n");
64345 @@ -2006,23 +2033,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
64346 || s->sh_entsize != ~0UL
64347 || !strstarts(sname, ".init"))
64348 continue;
64349 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
64350 - | INIT_OFFSET_MASK);
64351 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
64352 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
64353 + else
64354 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
64355 + s->sh_entsize |= INIT_OFFSET_MASK;
64356 DEBUGP("\t%s\n", sname);
64357 }
64358 - switch (m) {
64359 - case 0: /* executable */
64360 - mod->init_size = debug_align(mod->init_size);
64361 - mod->init_text_size = mod->init_size;
64362 - break;
64363 - case 1: /* RO: text and ro-data */
64364 - mod->init_size = debug_align(mod->init_size);
64365 - mod->init_ro_size = mod->init_size;
64366 - break;
64367 - case 3: /* whole init */
64368 - mod->init_size = debug_align(mod->init_size);
64369 - break;
64370 - }
64371 }
64372 }
64373
64374 @@ -2187,7 +2204,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
64375
64376 /* Put symbol section at end of init part of module. */
64377 symsect->sh_flags |= SHF_ALLOC;
64378 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
64379 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
64380 info->index.sym) | INIT_OFFSET_MASK;
64381 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
64382
64383 @@ -2204,19 +2221,19 @@ static void layout_symtab(struct module *mod, struct load_info *info)
64384 }
64385
64386 /* Append room for core symbols at end of core part. */
64387 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
64388 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
64389 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
64390 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
64391
64392 /* Put string table section at end of init part of module. */
64393 strsect->sh_flags |= SHF_ALLOC;
64394 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
64395 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
64396 info->index.str) | INIT_OFFSET_MASK;
64397 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
64398
64399 /* Append room for core symbols' strings at end of core part. */
64400 - info->stroffs = mod->core_size;
64401 + info->stroffs = mod->core_size_rx;
64402 __set_bit(0, info->strmap);
64403 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
64404 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
64405 }
64406
64407 static void add_kallsyms(struct module *mod, const struct load_info *info)
64408 @@ -2232,11 +2249,13 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
64409 /* Make sure we get permanent strtab: don't use info->strtab. */
64410 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
64411
64412 + pax_open_kernel();
64413 +
64414 /* Set types up while we still have access to sections. */
64415 for (i = 0; i < mod->num_symtab; i++)
64416 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
64417
64418 - mod->core_symtab = dst = mod->module_core + info->symoffs;
64419 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
64420 src = mod->symtab;
64421 *dst = *src;
64422 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
64423 @@ -2249,10 +2268,12 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
64424 }
64425 mod->core_num_syms = ndst;
64426
64427 - mod->core_strtab = s = mod->module_core + info->stroffs;
64428 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
64429 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
64430 if (test_bit(i, info->strmap))
64431 *++s = mod->strtab[i];
64432 +
64433 + pax_close_kernel();
64434 }
64435 #else
64436 static inline void layout_symtab(struct module *mod, struct load_info *info)
64437 @@ -2286,17 +2307,33 @@ void * __weak module_alloc(unsigned long size)
64438 return size == 0 ? NULL : vmalloc_exec(size);
64439 }
64440
64441 -static void *module_alloc_update_bounds(unsigned long size)
64442 +static void *module_alloc_update_bounds_rw(unsigned long size)
64443 {
64444 void *ret = module_alloc(size);
64445
64446 if (ret) {
64447 mutex_lock(&module_mutex);
64448 /* Update module bounds. */
64449 - if ((unsigned long)ret < module_addr_min)
64450 - module_addr_min = (unsigned long)ret;
64451 - if ((unsigned long)ret + size > module_addr_max)
64452 - module_addr_max = (unsigned long)ret + size;
64453 + if ((unsigned long)ret < module_addr_min_rw)
64454 + module_addr_min_rw = (unsigned long)ret;
64455 + if ((unsigned long)ret + size > module_addr_max_rw)
64456 + module_addr_max_rw = (unsigned long)ret + size;
64457 + mutex_unlock(&module_mutex);
64458 + }
64459 + return ret;
64460 +}
64461 +
64462 +static void *module_alloc_update_bounds_rx(unsigned long size)
64463 +{
64464 + void *ret = module_alloc_exec(size);
64465 +
64466 + if (ret) {
64467 + mutex_lock(&module_mutex);
64468 + /* Update module bounds. */
64469 + if ((unsigned long)ret < module_addr_min_rx)
64470 + module_addr_min_rx = (unsigned long)ret;
64471 + if ((unsigned long)ret + size > module_addr_max_rx)
64472 + module_addr_max_rx = (unsigned long)ret + size;
64473 mutex_unlock(&module_mutex);
64474 }
64475 return ret;
64476 @@ -2474,8 +2511,14 @@ static struct module *setup_load_info(struct load_info *info)
64477 static int check_modinfo(struct module *mod, struct load_info *info)
64478 {
64479 const char *modmagic = get_modinfo(info, "vermagic");
64480 + const char *license = get_modinfo(info, "license");
64481 int err;
64482
64483 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
64484 + if (!license || !license_is_gpl_compatible(license))
64485 + return -ENOEXEC;
64486 +#endif
64487 +
64488 /* This is allowed: modprobe --force will invalidate it. */
64489 if (!modmagic) {
64490 err = try_to_force_load(mod, "bad vermagic");
64491 @@ -2498,7 +2541,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
64492 }
64493
64494 /* Set up license info based on the info section */
64495 - set_license(mod, get_modinfo(info, "license"));
64496 + set_license(mod, license);
64497
64498 return 0;
64499 }
64500 @@ -2592,7 +2635,7 @@ static int move_module(struct module *mod, struct load_info *info)
64501 void *ptr;
64502
64503 /* Do the allocs. */
64504 - ptr = module_alloc_update_bounds(mod->core_size);
64505 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
64506 /*
64507 * The pointer to this block is stored in the module structure
64508 * which is inside the block. Just mark it as not being a
64509 @@ -2602,23 +2645,50 @@ static int move_module(struct module *mod, struct load_info *info)
64510 if (!ptr)
64511 return -ENOMEM;
64512
64513 - memset(ptr, 0, mod->core_size);
64514 - mod->module_core = ptr;
64515 + memset(ptr, 0, mod->core_size_rw);
64516 + mod->module_core_rw = ptr;
64517
64518 - ptr = module_alloc_update_bounds(mod->init_size);
64519 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
64520 /*
64521 * The pointer to this block is stored in the module structure
64522 * which is inside the block. This block doesn't need to be
64523 * scanned as it contains data and code that will be freed
64524 * after the module is initialized.
64525 */
64526 - kmemleak_ignore(ptr);
64527 - if (!ptr && mod->init_size) {
64528 - module_free(mod, mod->module_core);
64529 + kmemleak_not_leak(ptr);
64530 + if (!ptr && mod->init_size_rw) {
64531 + module_free(mod, mod->module_core_rw);
64532 return -ENOMEM;
64533 }
64534 - memset(ptr, 0, mod->init_size);
64535 - mod->module_init = ptr;
64536 + memset(ptr, 0, mod->init_size_rw);
64537 + mod->module_init_rw = ptr;
64538 +
64539 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
64540 + kmemleak_not_leak(ptr);
64541 + if (!ptr) {
64542 + module_free(mod, mod->module_init_rw);
64543 + module_free(mod, mod->module_core_rw);
64544 + return -ENOMEM;
64545 + }
64546 +
64547 + pax_open_kernel();
64548 + memset(ptr, 0, mod->core_size_rx);
64549 + pax_close_kernel();
64550 + mod->module_core_rx = ptr;
64551 +
64552 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
64553 + kmemleak_not_leak(ptr);
64554 + if (!ptr && mod->init_size_rx) {
64555 + module_free_exec(mod, mod->module_core_rx);
64556 + module_free(mod, mod->module_init_rw);
64557 + module_free(mod, mod->module_core_rw);
64558 + return -ENOMEM;
64559 + }
64560 +
64561 + pax_open_kernel();
64562 + memset(ptr, 0, mod->init_size_rx);
64563 + pax_close_kernel();
64564 + mod->module_init_rx = ptr;
64565
64566 /* Transfer each section which specifies SHF_ALLOC */
64567 DEBUGP("final section addresses:\n");
64568 @@ -2629,16 +2699,45 @@ static int move_module(struct module *mod, struct load_info *info)
64569 if (!(shdr->sh_flags & SHF_ALLOC))
64570 continue;
64571
64572 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
64573 - dest = mod->module_init
64574 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64575 - else
64576 - dest = mod->module_core + shdr->sh_entsize;
64577 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
64578 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
64579 + dest = mod->module_init_rw
64580 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64581 + else
64582 + dest = mod->module_init_rx
64583 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64584 + } else {
64585 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
64586 + dest = mod->module_core_rw + shdr->sh_entsize;
64587 + else
64588 + dest = mod->module_core_rx + shdr->sh_entsize;
64589 + }
64590 +
64591 + if (shdr->sh_type != SHT_NOBITS) {
64592 +
64593 +#ifdef CONFIG_PAX_KERNEXEC
64594 +#ifdef CONFIG_X86_64
64595 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
64596 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
64597 +#endif
64598 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
64599 + pax_open_kernel();
64600 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
64601 + pax_close_kernel();
64602 + } else
64603 +#endif
64604
64605 - if (shdr->sh_type != SHT_NOBITS)
64606 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
64607 + }
64608 /* Update sh_addr to point to copy in image. */
64609 - shdr->sh_addr = (unsigned long)dest;
64610 +
64611 +#ifdef CONFIG_PAX_KERNEXEC
64612 + if (shdr->sh_flags & SHF_EXECINSTR)
64613 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
64614 + else
64615 +#endif
64616 +
64617 + shdr->sh_addr = (unsigned long)dest;
64618 DEBUGP("\t0x%lx %s\n",
64619 shdr->sh_addr, info->secstrings + shdr->sh_name);
64620 }
64621 @@ -2689,12 +2788,12 @@ static void flush_module_icache(const struct module *mod)
64622 * Do it before processing of module parameters, so the module
64623 * can provide parameter accessor functions of its own.
64624 */
64625 - if (mod->module_init)
64626 - flush_icache_range((unsigned long)mod->module_init,
64627 - (unsigned long)mod->module_init
64628 - + mod->init_size);
64629 - flush_icache_range((unsigned long)mod->module_core,
64630 - (unsigned long)mod->module_core + mod->core_size);
64631 + if (mod->module_init_rx)
64632 + flush_icache_range((unsigned long)mod->module_init_rx,
64633 + (unsigned long)mod->module_init_rx
64634 + + mod->init_size_rx);
64635 + flush_icache_range((unsigned long)mod->module_core_rx,
64636 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
64637
64638 set_fs(old_fs);
64639 }
64640 @@ -2774,8 +2873,10 @@ static void module_deallocate(struct module *mod, struct load_info *info)
64641 {
64642 kfree(info->strmap);
64643 percpu_modfree(mod);
64644 - module_free(mod, mod->module_init);
64645 - module_free(mod, mod->module_core);
64646 + module_free_exec(mod, mod->module_init_rx);
64647 + module_free_exec(mod, mod->module_core_rx);
64648 + module_free(mod, mod->module_init_rw);
64649 + module_free(mod, mod->module_core_rw);
64650 }
64651
64652 int __weak module_finalize(const Elf_Ehdr *hdr,
64653 @@ -2839,9 +2940,38 @@ static struct module *load_module(void __user *umod,
64654 if (err)
64655 goto free_unload;
64656
64657 + /* Now copy in args */
64658 + mod->args = strndup_user(uargs, ~0UL >> 1);
64659 + if (IS_ERR(mod->args)) {
64660 + err = PTR_ERR(mod->args);
64661 + goto free_unload;
64662 + }
64663 +
64664 /* Set up MODINFO_ATTR fields */
64665 setup_modinfo(mod, &info);
64666
64667 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64668 + {
64669 + char *p, *p2;
64670 +
64671 + if (strstr(mod->args, "grsec_modharden_netdev")) {
64672 + printk(KERN_ALERT "grsec: denied auto-loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%.64s instead.", mod->name);
64673 + err = -EPERM;
64674 + goto free_modinfo;
64675 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
64676 + p += strlen("grsec_modharden_normal");
64677 + p2 = strstr(p, "_");
64678 + if (p2) {
64679 + *p2 = '\0';
64680 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
64681 + *p2 = '_';
64682 + }
64683 + err = -EPERM;
64684 + goto free_modinfo;
64685 + }
64686 + }
64687 +#endif
64688 +
64689 /* Fix up syms, so that st_value is a pointer to location. */
64690 err = simplify_symbols(mod, &info);
64691 if (err < 0)
64692 @@ -2857,13 +2987,6 @@ static struct module *load_module(void __user *umod,
64693
64694 flush_module_icache(mod);
64695
64696 - /* Now copy in args */
64697 - mod->args = strndup_user(uargs, ~0UL >> 1);
64698 - if (IS_ERR(mod->args)) {
64699 - err = PTR_ERR(mod->args);
64700 - goto free_arch_cleanup;
64701 - }
64702 -
64703 /* Mark state as coming so strong_try_module_get() ignores us. */
64704 mod->state = MODULE_STATE_COMING;
64705
64706 @@ -2921,11 +3044,10 @@ static struct module *load_module(void __user *umod,
64707 unlock:
64708 mutex_unlock(&module_mutex);
64709 synchronize_sched();
64710 - kfree(mod->args);
64711 - free_arch_cleanup:
64712 module_arch_cleanup(mod);
64713 free_modinfo:
64714 free_modinfo(mod);
64715 + kfree(mod->args);
64716 free_unload:
64717 module_unload_free(mod);
64718 free_module:
64719 @@ -2966,16 +3088,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
64720 MODULE_STATE_COMING, mod);
64721
64722 /* Set RO and NX regions for core */
64723 - set_section_ro_nx(mod->module_core,
64724 - mod->core_text_size,
64725 - mod->core_ro_size,
64726 - mod->core_size);
64727 + set_section_ro_nx(mod->module_core_rx,
64728 + mod->core_size_rx,
64729 + mod->core_size_rx,
64730 + mod->core_size_rx);
64731
64732 /* Set RO and NX regions for init */
64733 - set_section_ro_nx(mod->module_init,
64734 - mod->init_text_size,
64735 - mod->init_ro_size,
64736 - mod->init_size);
64737 + set_section_ro_nx(mod->module_init_rx,
64738 + mod->init_size_rx,
64739 + mod->init_size_rx,
64740 + mod->init_size_rx);
64741
64742 do_mod_ctors(mod);
64743 /* Start the module */
64744 @@ -3021,11 +3143,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
64745 mod->strtab = mod->core_strtab;
64746 #endif
64747 unset_module_init_ro_nx(mod);
64748 - module_free(mod, mod->module_init);
64749 - mod->module_init = NULL;
64750 - mod->init_size = 0;
64751 - mod->init_ro_size = 0;
64752 - mod->init_text_size = 0;
64753 + module_free(mod, mod->module_init_rw);
64754 + module_free_exec(mod, mod->module_init_rx);
64755 + mod->module_init_rw = NULL;
64756 + mod->module_init_rx = NULL;
64757 + mod->init_size_rw = 0;
64758 + mod->init_size_rx = 0;
64759 mutex_unlock(&module_mutex);
64760
64761 return 0;
64762 @@ -3056,10 +3179,16 @@ static const char *get_ksymbol(struct module *mod,
64763 unsigned long nextval;
64764
64765 /* At worse, next value is at end of module */
64766 - if (within_module_init(addr, mod))
64767 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
64768 + if (within_module_init_rx(addr, mod))
64769 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
64770 + else if (within_module_init_rw(addr, mod))
64771 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
64772 + else if (within_module_core_rx(addr, mod))
64773 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
64774 + else if (within_module_core_rw(addr, mod))
64775 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
64776 else
64777 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
64778 + return NULL;
64779
64780 /* Scan for closest preceding symbol, and next symbol. (ELF
64781 starts real symbols at 1). */
64782 @@ -3307,7 +3436,7 @@ static int m_show(struct seq_file *m, void *p)
64783 char buf[8];
64784
64785 seq_printf(m, "%s %u",
64786 - mod->name, mod->init_size + mod->core_size);
64787 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
64788 print_unload_info(m, mod);
64789
64790 /* Informative for users. */
64791 @@ -3316,7 +3445,7 @@ static int m_show(struct seq_file *m, void *p)
64792 mod->state == MODULE_STATE_COMING ? "Loading":
64793 "Live");
64794 /* Used by oprofile and other similar tools. */
64795 - seq_printf(m, " 0x%pK", mod->module_core);
64796 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
64797
64798 /* Taints info */
64799 if (mod->taints)
64800 @@ -3352,7 +3481,17 @@ static const struct file_operations proc_modules_operations = {
64801
64802 static int __init proc_modules_init(void)
64803 {
64804 +#ifndef CONFIG_GRKERNSEC_HIDESYM
64805 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64806 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
64807 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64808 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
64809 +#else
64810 proc_create("modules", 0, NULL, &proc_modules_operations);
64811 +#endif
64812 +#else
64813 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
64814 +#endif
64815 return 0;
64816 }
64817 module_init(proc_modules_init);
64818 @@ -3411,12 +3550,12 @@ struct module *__module_address(unsigned long addr)
64819 {
64820 struct module *mod;
64821
64822 - if (addr < module_addr_min || addr > module_addr_max)
64823 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
64824 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
64825 return NULL;
64826
64827 list_for_each_entry_rcu(mod, &modules, list)
64828 - if (within_module_core(addr, mod)
64829 - || within_module_init(addr, mod))
64830 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
64831 return mod;
64832 return NULL;
64833 }
64834 @@ -3450,11 +3589,20 @@ bool is_module_text_address(unsigned long addr)
64835 */
64836 struct module *__module_text_address(unsigned long addr)
64837 {
64838 - struct module *mod = __module_address(addr);
64839 + struct module *mod;
64840 +
64841 +#ifdef CONFIG_X86_32
64842 + addr = ktla_ktva(addr);
64843 +#endif
64844 +
64845 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
64846 + return NULL;
64847 +
64848 + mod = __module_address(addr);
64849 +
64850 if (mod) {
64851 /* Make sure it's within the text section. */
64852 - if (!within(addr, mod->module_init, mod->init_text_size)
64853 - && !within(addr, mod->module_core, mod->core_text_size))
64854 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
64855 mod = NULL;
64856 }
64857 return mod;
64858 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
64859 index 7e3443f..b2a1e6b 100644
64860 --- a/kernel/mutex-debug.c
64861 +++ b/kernel/mutex-debug.c
64862 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
64863 }
64864
64865 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64866 - struct thread_info *ti)
64867 + struct task_struct *task)
64868 {
64869 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
64870
64871 /* Mark the current thread as blocked on the lock: */
64872 - ti->task->blocked_on = waiter;
64873 + task->blocked_on = waiter;
64874 }
64875
64876 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64877 - struct thread_info *ti)
64878 + struct task_struct *task)
64879 {
64880 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
64881 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
64882 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
64883 - ti->task->blocked_on = NULL;
64884 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
64885 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
64886 + task->blocked_on = NULL;
64887
64888 list_del_init(&waiter->list);
64889 waiter->task = NULL;
64890 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
64891 index 0799fd3..d06ae3b 100644
64892 --- a/kernel/mutex-debug.h
64893 +++ b/kernel/mutex-debug.h
64894 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
64895 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
64896 extern void debug_mutex_add_waiter(struct mutex *lock,
64897 struct mutex_waiter *waiter,
64898 - struct thread_info *ti);
64899 + struct task_struct *task);
64900 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64901 - struct thread_info *ti);
64902 + struct task_struct *task);
64903 extern void debug_mutex_unlock(struct mutex *lock);
64904 extern void debug_mutex_init(struct mutex *lock, const char *name,
64905 struct lock_class_key *key);
64906 diff --git a/kernel/mutex.c b/kernel/mutex.c
64907 index 89096dd..f91ebc5 100644
64908 --- a/kernel/mutex.c
64909 +++ b/kernel/mutex.c
64910 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
64911 spin_lock_mutex(&lock->wait_lock, flags);
64912
64913 debug_mutex_lock_common(lock, &waiter);
64914 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
64915 + debug_mutex_add_waiter(lock, &waiter, task);
64916
64917 /* add waiting tasks to the end of the waitqueue (FIFO): */
64918 list_add_tail(&waiter.list, &lock->wait_list);
64919 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
64920 * TASK_UNINTERRUPTIBLE case.)
64921 */
64922 if (unlikely(signal_pending_state(state, task))) {
64923 - mutex_remove_waiter(lock, &waiter,
64924 - task_thread_info(task));
64925 + mutex_remove_waiter(lock, &waiter, task);
64926 mutex_release(&lock->dep_map, 1, ip);
64927 spin_unlock_mutex(&lock->wait_lock, flags);
64928
64929 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
64930 done:
64931 lock_acquired(&lock->dep_map, ip);
64932 /* got the lock - rejoice! */
64933 - mutex_remove_waiter(lock, &waiter, current_thread_info());
64934 + mutex_remove_waiter(lock, &waiter, task);
64935 mutex_set_owner(lock);
64936
64937 /* set it to 0 if there are no waiters left: */
64938 diff --git a/kernel/padata.c b/kernel/padata.c
64939 index b452599..5d68f4e 100644
64940 --- a/kernel/padata.c
64941 +++ b/kernel/padata.c
64942 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
64943 padata->pd = pd;
64944 padata->cb_cpu = cb_cpu;
64945
64946 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
64947 - atomic_set(&pd->seq_nr, -1);
64948 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
64949 + atomic_set_unchecked(&pd->seq_nr, -1);
64950
64951 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
64952 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
64953
64954 target_cpu = padata_cpu_hash(padata);
64955 queue = per_cpu_ptr(pd->pqueue, target_cpu);
64956 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
64957 padata_init_pqueues(pd);
64958 padata_init_squeues(pd);
64959 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
64960 - atomic_set(&pd->seq_nr, -1);
64961 + atomic_set_unchecked(&pd->seq_nr, -1);
64962 atomic_set(&pd->reorder_objects, 0);
64963 atomic_set(&pd->refcnt, 0);
64964 pd->pinst = pinst;
64965 diff --git a/kernel/panic.c b/kernel/panic.c
64966 index b2659360..5972a0f 100644
64967 --- a/kernel/panic.c
64968 +++ b/kernel/panic.c
64969 @@ -78,7 +78,11 @@ NORET_TYPE void panic(const char * fmt, ...)
64970 va_end(args);
64971 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
64972 #ifdef CONFIG_DEBUG_BUGVERBOSE
64973 - dump_stack();
64974 + /*
64975 + * Avoid nested stack-dumping if a panic occurs during oops processing
64976 + */
64977 + if (!oops_in_progress)
64978 + dump_stack();
64979 #endif
64980
64981 /*
64982 @@ -373,7 +377,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
64983 const char *board;
64984
64985 printk(KERN_WARNING "------------[ cut here ]------------\n");
64986 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
64987 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
64988 board = dmi_get_system_info(DMI_PRODUCT_NAME);
64989 if (board)
64990 printk(KERN_WARNING "Hardware name: %s\n", board);
64991 @@ -428,7 +432,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
64992 */
64993 void __stack_chk_fail(void)
64994 {
64995 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
64996 + dump_stack();
64997 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
64998 __builtin_return_address(0));
64999 }
65000 EXPORT_SYMBOL(__stack_chk_fail);
65001 diff --git a/kernel/pid.c b/kernel/pid.c
65002 index fa5f722..0c93e57 100644
65003 --- a/kernel/pid.c
65004 +++ b/kernel/pid.c
65005 @@ -33,6 +33,7 @@
65006 #include <linux/rculist.h>
65007 #include <linux/bootmem.h>
65008 #include <linux/hash.h>
65009 +#include <linux/security.h>
65010 #include <linux/pid_namespace.h>
65011 #include <linux/init_task.h>
65012 #include <linux/syscalls.h>
65013 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
65014
65015 int pid_max = PID_MAX_DEFAULT;
65016
65017 -#define RESERVED_PIDS 300
65018 +#define RESERVED_PIDS 500
65019
65020 int pid_max_min = RESERVED_PIDS + 1;
65021 int pid_max_max = PID_MAX_LIMIT;
65022 @@ -418,10 +419,18 @@ EXPORT_SYMBOL(pid_task);
65023 */
65024 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
65025 {
65026 + struct task_struct *task;
65027 +
65028 rcu_lockdep_assert(rcu_read_lock_held(),
65029 "find_task_by_pid_ns() needs rcu_read_lock()"
65030 " protection");
65031 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
65032 +
65033 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
65034 +
65035 + if (gr_pid_is_chrooted(task))
65036 + return NULL;
65037 +
65038 + return task;
65039 }
65040
65041 struct task_struct *find_task_by_vpid(pid_t vnr)
65042 @@ -429,6 +438,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
65043 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
65044 }
65045
65046 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
65047 +{
65048 + rcu_lockdep_assert(rcu_read_lock_held(),
65049 + "find_task_by_pid_ns() needs rcu_read_lock()"
65050 + " protection");
65051 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
65052 +}
65053 +
65054 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
65055 {
65056 struct pid *pid;
65057 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
65058 index e7cb76d..75eceb3 100644
65059 --- a/kernel/posix-cpu-timers.c
65060 +++ b/kernel/posix-cpu-timers.c
65061 @@ -6,6 +6,7 @@
65062 #include <linux/posix-timers.h>
65063 #include <linux/errno.h>
65064 #include <linux/math64.h>
65065 +#include <linux/security.h>
65066 #include <asm/uaccess.h>
65067 #include <linux/kernel_stat.h>
65068 #include <trace/events/timer.h>
65069 @@ -1606,14 +1607,14 @@ struct k_clock clock_posix_cpu = {
65070
65071 static __init int init_posix_cpu_timers(void)
65072 {
65073 - struct k_clock process = {
65074 + static struct k_clock process = {
65075 .clock_getres = process_cpu_clock_getres,
65076 .clock_get = process_cpu_clock_get,
65077 .timer_create = process_cpu_timer_create,
65078 .nsleep = process_cpu_nsleep,
65079 .nsleep_restart = process_cpu_nsleep_restart,
65080 };
65081 - struct k_clock thread = {
65082 + static struct k_clock thread = {
65083 .clock_getres = thread_cpu_clock_getres,
65084 .clock_get = thread_cpu_clock_get,
65085 .timer_create = thread_cpu_timer_create,
65086 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
65087 index 69185ae..cc2847a 100644
65088 --- a/kernel/posix-timers.c
65089 +++ b/kernel/posix-timers.c
65090 @@ -43,6 +43,7 @@
65091 #include <linux/idr.h>
65092 #include <linux/posix-clock.h>
65093 #include <linux/posix-timers.h>
65094 +#include <linux/grsecurity.h>
65095 #include <linux/syscalls.h>
65096 #include <linux/wait.h>
65097 #include <linux/workqueue.h>
65098 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
65099 * which we beg off on and pass to do_sys_settimeofday().
65100 */
65101
65102 -static struct k_clock posix_clocks[MAX_CLOCKS];
65103 +static struct k_clock *posix_clocks[MAX_CLOCKS];
65104
65105 /*
65106 * These ones are defined below.
65107 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
65108 */
65109 static __init int init_posix_timers(void)
65110 {
65111 - struct k_clock clock_realtime = {
65112 + static struct k_clock clock_realtime = {
65113 .clock_getres = hrtimer_get_res,
65114 .clock_get = posix_clock_realtime_get,
65115 .clock_set = posix_clock_realtime_set,
65116 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
65117 .timer_get = common_timer_get,
65118 .timer_del = common_timer_del,
65119 };
65120 - struct k_clock clock_monotonic = {
65121 + static struct k_clock clock_monotonic = {
65122 .clock_getres = hrtimer_get_res,
65123 .clock_get = posix_ktime_get_ts,
65124 .nsleep = common_nsleep,
65125 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
65126 .timer_get = common_timer_get,
65127 .timer_del = common_timer_del,
65128 };
65129 - struct k_clock clock_monotonic_raw = {
65130 + static struct k_clock clock_monotonic_raw = {
65131 .clock_getres = hrtimer_get_res,
65132 .clock_get = posix_get_monotonic_raw,
65133 };
65134 - struct k_clock clock_realtime_coarse = {
65135 + static struct k_clock clock_realtime_coarse = {
65136 .clock_getres = posix_get_coarse_res,
65137 .clock_get = posix_get_realtime_coarse,
65138 };
65139 - struct k_clock clock_monotonic_coarse = {
65140 + static struct k_clock clock_monotonic_coarse = {
65141 .clock_getres = posix_get_coarse_res,
65142 .clock_get = posix_get_monotonic_coarse,
65143 };
65144 - struct k_clock clock_boottime = {
65145 + static struct k_clock clock_boottime = {
65146 .clock_getres = hrtimer_get_res,
65147 .clock_get = posix_get_boottime,
65148 .nsleep = common_nsleep,
65149 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
65150 return;
65151 }
65152
65153 - posix_clocks[clock_id] = *new_clock;
65154 + posix_clocks[clock_id] = new_clock;
65155 }
65156 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
65157
65158 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
65159 return (id & CLOCKFD_MASK) == CLOCKFD ?
65160 &clock_posix_dynamic : &clock_posix_cpu;
65161
65162 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
65163 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
65164 return NULL;
65165 - return &posix_clocks[id];
65166 + return posix_clocks[id];
65167 }
65168
65169 static int common_timer_create(struct k_itimer *new_timer)
65170 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
65171 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
65172 return -EFAULT;
65173
65174 + /* only the CLOCK_REALTIME clock can be set, all other clocks
65175 + have their clock_set fptr set to a nosettime dummy function
65176 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
65177 + call common_clock_set, which calls do_sys_settimeofday, which
65178 + we hook
65179 + */
65180 +
65181 return kc->clock_set(which_clock, &new_tp);
65182 }
65183
65184 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
65185 index d523593..68197a4 100644
65186 --- a/kernel/power/poweroff.c
65187 +++ b/kernel/power/poweroff.c
65188 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
65189 .enable_mask = SYSRQ_ENABLE_BOOT,
65190 };
65191
65192 -static int pm_sysrq_init(void)
65193 +static int __init pm_sysrq_init(void)
65194 {
65195 register_sysrq_key('o', &sysrq_poweroff_op);
65196 return 0;
65197 diff --git a/kernel/power/process.c b/kernel/power/process.c
65198 index addbbe5..f9e32e0 100644
65199 --- a/kernel/power/process.c
65200 +++ b/kernel/power/process.c
65201 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_only)
65202 u64 elapsed_csecs64;
65203 unsigned int elapsed_csecs;
65204 bool wakeup = false;
65205 + bool timedout = false;
65206
65207 do_gettimeofday(&start);
65208
65209 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_only)
65210
65211 while (true) {
65212 todo = 0;
65213 + if (time_after(jiffies, end_time))
65214 + timedout = true;
65215 read_lock(&tasklist_lock);
65216 do_each_thread(g, p) {
65217 if (frozen(p) || !freezable(p))
65218 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_only)
65219 * try_to_stop() after schedule() in ptrace/signal
65220 * stop sees TIF_FREEZE.
65221 */
65222 - if (!task_is_stopped_or_traced(p) &&
65223 - !freezer_should_skip(p))
65224 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
65225 todo++;
65226 + if (timedout) {
65227 + printk(KERN_ERR "Task refusing to freeze:\n");
65228 + sched_show_task(p);
65229 + }
65230 + }
65231 } while_each_thread(g, p);
65232 read_unlock(&tasklist_lock);
65233
65234 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_only)
65235 todo += wq_busy;
65236 }
65237
65238 - if (!todo || time_after(jiffies, end_time))
65239 + if (!todo || timedout)
65240 break;
65241
65242 if (pm_wakeup_pending()) {
65243 diff --git a/kernel/printk.c b/kernel/printk.c
65244 index 7982a0a..2095fdc 100644
65245 --- a/kernel/printk.c
65246 +++ b/kernel/printk.c
65247 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
65248 if (from_file && type != SYSLOG_ACTION_OPEN)
65249 return 0;
65250
65251 +#ifdef CONFIG_GRKERNSEC_DMESG
65252 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
65253 + return -EPERM;
65254 +#endif
65255 +
65256 if (syslog_action_restricted(type)) {
65257 if (capable(CAP_SYSLOG))
65258 return 0;
65259 diff --git a/kernel/profile.c b/kernel/profile.c
65260 index 76b8e77..a2930e8 100644
65261 --- a/kernel/profile.c
65262 +++ b/kernel/profile.c
65263 @@ -39,7 +39,7 @@ struct profile_hit {
65264 /* Oprofile timer tick hook */
65265 static int (*timer_hook)(struct pt_regs *) __read_mostly;
65266
65267 -static atomic_t *prof_buffer;
65268 +static atomic_unchecked_t *prof_buffer;
65269 static unsigned long prof_len, prof_shift;
65270
65271 int prof_on __read_mostly;
65272 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
65273 hits[i].pc = 0;
65274 continue;
65275 }
65276 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
65277 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
65278 hits[i].hits = hits[i].pc = 0;
65279 }
65280 }
65281 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
65282 * Add the current hit(s) and flush the write-queue out
65283 * to the global buffer:
65284 */
65285 - atomic_add(nr_hits, &prof_buffer[pc]);
65286 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
65287 for (i = 0; i < NR_PROFILE_HIT; ++i) {
65288 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
65289 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
65290 hits[i].pc = hits[i].hits = 0;
65291 }
65292 out:
65293 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
65294 {
65295 unsigned long pc;
65296 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
65297 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
65298 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
65299 }
65300 #endif /* !CONFIG_SMP */
65301
65302 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
65303 return -EFAULT;
65304 buf++; p++; count--; read++;
65305 }
65306 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
65307 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
65308 if (copy_to_user(buf, (void *)pnt, count))
65309 return -EFAULT;
65310 read += count;
65311 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
65312 }
65313 #endif
65314 profile_discard_flip_buffers();
65315 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
65316 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
65317 return count;
65318 }
65319
65320 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
65321 index 78ab24a..332c915 100644
65322 --- a/kernel/ptrace.c
65323 +++ b/kernel/ptrace.c
65324 @@ -172,7 +172,8 @@ int ptrace_check_attach(struct task_struct *child, bool ignore_state)
65325 return ret;
65326 }
65327
65328 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
65329 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
65330 + unsigned int log)
65331 {
65332 const struct cred *cred = current_cred(), *tcred;
65333
65334 @@ -198,7 +199,8 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
65335 cred->gid == tcred->sgid &&
65336 cred->gid == tcred->gid))
65337 goto ok;
65338 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
65339 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
65340 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
65341 goto ok;
65342 rcu_read_unlock();
65343 return -EPERM;
65344 @@ -207,7 +209,9 @@ ok:
65345 smp_rmb();
65346 if (task->mm)
65347 dumpable = get_dumpable(task->mm);
65348 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
65349 + if (!dumpable &&
65350 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
65351 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
65352 return -EPERM;
65353
65354 return security_ptrace_access_check(task, mode);
65355 @@ -217,7 +221,21 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
65356 {
65357 int err;
65358 task_lock(task);
65359 - err = __ptrace_may_access(task, mode);
65360 + err = __ptrace_may_access(task, mode, 0);
65361 + task_unlock(task);
65362 + return !err;
65363 +}
65364 +
65365 +bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode)
65366 +{
65367 + return __ptrace_may_access(task, mode, 0);
65368 +}
65369 +
65370 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
65371 +{
65372 + int err;
65373 + task_lock(task);
65374 + err = __ptrace_may_access(task, mode, 1);
65375 task_unlock(task);
65376 return !err;
65377 }
65378 @@ -262,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
65379 goto out;
65380
65381 task_lock(task);
65382 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
65383 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
65384 task_unlock(task);
65385 if (retval)
65386 goto unlock_creds;
65387 @@ -277,7 +295,7 @@ static int ptrace_attach(struct task_struct *task, long request,
65388 task->ptrace = PT_PTRACED;
65389 if (seize)
65390 task->ptrace |= PT_SEIZED;
65391 - if (task_ns_capable(task, CAP_SYS_PTRACE))
65392 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
65393 task->ptrace |= PT_PTRACE_CAP;
65394
65395 __ptrace_link(task, current);
65396 @@ -483,7 +501,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
65397 break;
65398 return -EIO;
65399 }
65400 - if (copy_to_user(dst, buf, retval))
65401 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
65402 return -EFAULT;
65403 copied += retval;
65404 src += retval;
65405 @@ -680,7 +698,7 @@ int ptrace_request(struct task_struct *child, long request,
65406 bool seized = child->ptrace & PT_SEIZED;
65407 int ret = -EIO;
65408 siginfo_t siginfo, *si;
65409 - void __user *datavp = (void __user *) data;
65410 + void __user *datavp = (__force void __user *) data;
65411 unsigned long __user *datalp = datavp;
65412 unsigned long flags;
65413
65414 @@ -882,14 +900,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
65415 goto out;
65416 }
65417
65418 + if (gr_handle_ptrace(child, request)) {
65419 + ret = -EPERM;
65420 + goto out_put_task_struct;
65421 + }
65422 +
65423 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65424 ret = ptrace_attach(child, request, data);
65425 /*
65426 * Some architectures need to do book-keeping after
65427 * a ptrace attach.
65428 */
65429 - if (!ret)
65430 + if (!ret) {
65431 arch_ptrace_attach(child);
65432 + gr_audit_ptrace(child);
65433 + }
65434 goto out_put_task_struct;
65435 }
65436
65437 @@ -915,7 +940,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
65438 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
65439 if (copied != sizeof(tmp))
65440 return -EIO;
65441 - return put_user(tmp, (unsigned long __user *)data);
65442 + return put_user(tmp, (__force unsigned long __user *)data);
65443 }
65444
65445 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
65446 @@ -1025,14 +1050,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
65447 goto out;
65448 }
65449
65450 + if (gr_handle_ptrace(child, request)) {
65451 + ret = -EPERM;
65452 + goto out_put_task_struct;
65453 + }
65454 +
65455 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65456 ret = ptrace_attach(child, request, data);
65457 /*
65458 * Some architectures need to do book-keeping after
65459 * a ptrace attach.
65460 */
65461 - if (!ret)
65462 + if (!ret) {
65463 arch_ptrace_attach(child);
65464 + gr_audit_ptrace(child);
65465 + }
65466 goto out_put_task_struct;
65467 }
65468
65469 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
65470 index 764825c..3aa6ac4 100644
65471 --- a/kernel/rcutorture.c
65472 +++ b/kernel/rcutorture.c
65473 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
65474 { 0 };
65475 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
65476 { 0 };
65477 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65478 -static atomic_t n_rcu_torture_alloc;
65479 -static atomic_t n_rcu_torture_alloc_fail;
65480 -static atomic_t n_rcu_torture_free;
65481 -static atomic_t n_rcu_torture_mberror;
65482 -static atomic_t n_rcu_torture_error;
65483 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65484 +static atomic_unchecked_t n_rcu_torture_alloc;
65485 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
65486 +static atomic_unchecked_t n_rcu_torture_free;
65487 +static atomic_unchecked_t n_rcu_torture_mberror;
65488 +static atomic_unchecked_t n_rcu_torture_error;
65489 static long n_rcu_torture_boost_ktrerror;
65490 static long n_rcu_torture_boost_rterror;
65491 static long n_rcu_torture_boost_failure;
65492 @@ -223,11 +223,11 @@ rcu_torture_alloc(void)
65493
65494 spin_lock_bh(&rcu_torture_lock);
65495 if (list_empty(&rcu_torture_freelist)) {
65496 - atomic_inc(&n_rcu_torture_alloc_fail);
65497 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
65498 spin_unlock_bh(&rcu_torture_lock);
65499 return NULL;
65500 }
65501 - atomic_inc(&n_rcu_torture_alloc);
65502 + atomic_inc_unchecked(&n_rcu_torture_alloc);
65503 p = rcu_torture_freelist.next;
65504 list_del_init(p);
65505 spin_unlock_bh(&rcu_torture_lock);
65506 @@ -240,7 +240,7 @@ rcu_torture_alloc(void)
65507 static void
65508 rcu_torture_free(struct rcu_torture *p)
65509 {
65510 - atomic_inc(&n_rcu_torture_free);
65511 + atomic_inc_unchecked(&n_rcu_torture_free);
65512 spin_lock_bh(&rcu_torture_lock);
65513 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
65514 spin_unlock_bh(&rcu_torture_lock);
65515 @@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
65516 i = rp->rtort_pipe_count;
65517 if (i > RCU_TORTURE_PIPE_LEN)
65518 i = RCU_TORTURE_PIPE_LEN;
65519 - atomic_inc(&rcu_torture_wcount[i]);
65520 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65521 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65522 rp->rtort_mbtest = 0;
65523 rcu_torture_free(rp);
65524 @@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
65525 i = rp->rtort_pipe_count;
65526 if (i > RCU_TORTURE_PIPE_LEN)
65527 i = RCU_TORTURE_PIPE_LEN;
65528 - atomic_inc(&rcu_torture_wcount[i]);
65529 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65530 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65531 rp->rtort_mbtest = 0;
65532 list_del(&rp->rtort_free);
65533 @@ -872,7 +872,7 @@ rcu_torture_writer(void *arg)
65534 i = old_rp->rtort_pipe_count;
65535 if (i > RCU_TORTURE_PIPE_LEN)
65536 i = RCU_TORTURE_PIPE_LEN;
65537 - atomic_inc(&rcu_torture_wcount[i]);
65538 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65539 old_rp->rtort_pipe_count++;
65540 cur_ops->deferred_free(old_rp);
65541 }
65542 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
65543 return;
65544 }
65545 if (p->rtort_mbtest == 0)
65546 - atomic_inc(&n_rcu_torture_mberror);
65547 + atomic_inc_unchecked(&n_rcu_torture_mberror);
65548 spin_lock(&rand_lock);
65549 cur_ops->read_delay(&rand);
65550 n_rcu_torture_timers++;
65551 @@ -1001,7 +1001,7 @@ rcu_torture_reader(void *arg)
65552 continue;
65553 }
65554 if (p->rtort_mbtest == 0)
65555 - atomic_inc(&n_rcu_torture_mberror);
65556 + atomic_inc_unchecked(&n_rcu_torture_mberror);
65557 cur_ops->read_delay(&rand);
65558 preempt_disable();
65559 pipe_count = p->rtort_pipe_count;
65560 @@ -1060,16 +1060,16 @@ rcu_torture_printk(char *page)
65561 rcu_torture_current,
65562 rcu_torture_current_version,
65563 list_empty(&rcu_torture_freelist),
65564 - atomic_read(&n_rcu_torture_alloc),
65565 - atomic_read(&n_rcu_torture_alloc_fail),
65566 - atomic_read(&n_rcu_torture_free),
65567 - atomic_read(&n_rcu_torture_mberror),
65568 + atomic_read_unchecked(&n_rcu_torture_alloc),
65569 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
65570 + atomic_read_unchecked(&n_rcu_torture_free),
65571 + atomic_read_unchecked(&n_rcu_torture_mberror),
65572 n_rcu_torture_boost_ktrerror,
65573 n_rcu_torture_boost_rterror,
65574 n_rcu_torture_boost_failure,
65575 n_rcu_torture_boosts,
65576 n_rcu_torture_timers);
65577 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
65578 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
65579 n_rcu_torture_boost_ktrerror != 0 ||
65580 n_rcu_torture_boost_rterror != 0 ||
65581 n_rcu_torture_boost_failure != 0)
65582 @@ -1077,7 +1077,7 @@ rcu_torture_printk(char *page)
65583 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
65584 if (i > 1) {
65585 cnt += sprintf(&page[cnt], "!!! ");
65586 - atomic_inc(&n_rcu_torture_error);
65587 + atomic_inc_unchecked(&n_rcu_torture_error);
65588 WARN_ON_ONCE(1);
65589 }
65590 cnt += sprintf(&page[cnt], "Reader Pipe: ");
65591 @@ -1091,7 +1091,7 @@ rcu_torture_printk(char *page)
65592 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
65593 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65594 cnt += sprintf(&page[cnt], " %d",
65595 - atomic_read(&rcu_torture_wcount[i]));
65596 + atomic_read_unchecked(&rcu_torture_wcount[i]));
65597 }
65598 cnt += sprintf(&page[cnt], "\n");
65599 if (cur_ops->stats)
65600 @@ -1401,7 +1401,7 @@ rcu_torture_cleanup(void)
65601
65602 if (cur_ops->cleanup)
65603 cur_ops->cleanup();
65604 - if (atomic_read(&n_rcu_torture_error))
65605 + if (atomic_read_unchecked(&n_rcu_torture_error))
65606 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
65607 else
65608 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
65609 @@ -1465,17 +1465,17 @@ rcu_torture_init(void)
65610
65611 rcu_torture_current = NULL;
65612 rcu_torture_current_version = 0;
65613 - atomic_set(&n_rcu_torture_alloc, 0);
65614 - atomic_set(&n_rcu_torture_alloc_fail, 0);
65615 - atomic_set(&n_rcu_torture_free, 0);
65616 - atomic_set(&n_rcu_torture_mberror, 0);
65617 - atomic_set(&n_rcu_torture_error, 0);
65618 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
65619 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
65620 + atomic_set_unchecked(&n_rcu_torture_free, 0);
65621 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
65622 + atomic_set_unchecked(&n_rcu_torture_error, 0);
65623 n_rcu_torture_boost_ktrerror = 0;
65624 n_rcu_torture_boost_rterror = 0;
65625 n_rcu_torture_boost_failure = 0;
65626 n_rcu_torture_boosts = 0;
65627 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
65628 - atomic_set(&rcu_torture_wcount[i], 0);
65629 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
65630 for_each_possible_cpu(cpu) {
65631 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65632 per_cpu(rcu_torture_count, cpu)[i] = 0;
65633 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
65634 index 6b76d81..7afc1b3 100644
65635 --- a/kernel/rcutree.c
65636 +++ b/kernel/rcutree.c
65637 @@ -367,9 +367,9 @@ void rcu_enter_nohz(void)
65638 trace_rcu_dyntick("Start");
65639 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
65640 smp_mb__before_atomic_inc(); /* See above. */
65641 - atomic_inc(&rdtp->dynticks);
65642 + atomic_inc_unchecked(&rdtp->dynticks);
65643 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
65644 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
65645 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
65646 local_irq_restore(flags);
65647 }
65648
65649 @@ -391,10 +391,10 @@ void rcu_exit_nohz(void)
65650 return;
65651 }
65652 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
65653 - atomic_inc(&rdtp->dynticks);
65654 + atomic_inc_unchecked(&rdtp->dynticks);
65655 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
65656 smp_mb__after_atomic_inc(); /* See above. */
65657 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
65658 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
65659 trace_rcu_dyntick("End");
65660 local_irq_restore(flags);
65661 }
65662 @@ -411,14 +411,14 @@ void rcu_nmi_enter(void)
65663 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
65664
65665 if (rdtp->dynticks_nmi_nesting == 0 &&
65666 - (atomic_read(&rdtp->dynticks) & 0x1))
65667 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
65668 return;
65669 rdtp->dynticks_nmi_nesting++;
65670 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
65671 - atomic_inc(&rdtp->dynticks);
65672 + atomic_inc_unchecked(&rdtp->dynticks);
65673 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
65674 smp_mb__after_atomic_inc(); /* See above. */
65675 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
65676 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
65677 }
65678
65679 /**
65680 @@ -437,9 +437,9 @@ void rcu_nmi_exit(void)
65681 return;
65682 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
65683 smp_mb__before_atomic_inc(); /* See above. */
65684 - atomic_inc(&rdtp->dynticks);
65685 + atomic_inc_unchecked(&rdtp->dynticks);
65686 smp_mb__after_atomic_inc(); /* Force delay to next write. */
65687 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
65688 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
65689 }
65690
65691 /**
65692 @@ -474,7 +474,7 @@ void rcu_irq_exit(void)
65693 */
65694 static int dyntick_save_progress_counter(struct rcu_data *rdp)
65695 {
65696 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
65697 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
65698 return 0;
65699 }
65700
65701 @@ -489,7 +489,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
65702 unsigned int curr;
65703 unsigned int snap;
65704
65705 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
65706 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
65707 snap = (unsigned int)rdp->dynticks_snap;
65708
65709 /*
65710 @@ -1552,7 +1552,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
65711 /*
65712 * Do RCU core processing for the current CPU.
65713 */
65714 -static void rcu_process_callbacks(struct softirq_action *unused)
65715 +static void rcu_process_callbacks(void)
65716 {
65717 trace_rcu_utilization("Start RCU core");
65718 __rcu_process_callbacks(&rcu_sched_state,
65719 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
65720 index 849ce9e..74bc9de 100644
65721 --- a/kernel/rcutree.h
65722 +++ b/kernel/rcutree.h
65723 @@ -86,7 +86,7 @@
65724 struct rcu_dynticks {
65725 int dynticks_nesting; /* Track irq/process nesting level. */
65726 int dynticks_nmi_nesting; /* Track NMI nesting level. */
65727 - atomic_t dynticks; /* Even value for dynticks-idle, else odd. */
65728 + atomic_unchecked_t dynticks; /* Even value for dynticks-idle, else odd. */
65729 };
65730
65731 /* RCU's kthread states for tracing. */
65732 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
65733 index 4b9b9f8..2326053 100644
65734 --- a/kernel/rcutree_plugin.h
65735 +++ b/kernel/rcutree_plugin.h
65736 @@ -842,7 +842,7 @@ void synchronize_rcu_expedited(void)
65737
65738 /* Clean up and exit. */
65739 smp_mb(); /* ensure expedited GP seen before counter increment. */
65740 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
65741 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
65742 unlock_mb_ret:
65743 mutex_unlock(&sync_rcu_preempt_exp_mutex);
65744 mb_ret:
65745 @@ -1815,8 +1815,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
65746
65747 #else /* #ifndef CONFIG_SMP */
65748
65749 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
65750 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
65751 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
65752 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
65753
65754 static int synchronize_sched_expedited_cpu_stop(void *data)
65755 {
65756 @@ -1871,7 +1871,7 @@ void synchronize_sched_expedited(void)
65757 int firstsnap, s, snap, trycount = 0;
65758
65759 /* Note that atomic_inc_return() implies full memory barrier. */
65760 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
65761 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
65762 get_online_cpus();
65763
65764 /*
65765 @@ -1892,7 +1892,7 @@ void synchronize_sched_expedited(void)
65766 }
65767
65768 /* Check to see if someone else did our work for us. */
65769 - s = atomic_read(&sync_sched_expedited_done);
65770 + s = atomic_read_unchecked(&sync_sched_expedited_done);
65771 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
65772 smp_mb(); /* ensure test happens before caller kfree */
65773 return;
65774 @@ -1907,7 +1907,7 @@ void synchronize_sched_expedited(void)
65775 * grace period works for us.
65776 */
65777 get_online_cpus();
65778 - snap = atomic_read(&sync_sched_expedited_started) - 1;
65779 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
65780 smp_mb(); /* ensure read is before try_stop_cpus(). */
65781 }
65782
65783 @@ -1918,12 +1918,12 @@ void synchronize_sched_expedited(void)
65784 * than we did beat us to the punch.
65785 */
65786 do {
65787 - s = atomic_read(&sync_sched_expedited_done);
65788 + s = atomic_read_unchecked(&sync_sched_expedited_done);
65789 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
65790 smp_mb(); /* ensure test happens before caller kfree */
65791 break;
65792 }
65793 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
65794 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
65795
65796 put_online_cpus();
65797 }
65798 @@ -1985,7 +1985,7 @@ int rcu_needs_cpu(int cpu)
65799 for_each_online_cpu(thatcpu) {
65800 if (thatcpu == cpu)
65801 continue;
65802 - snap = atomic_add_return(0, &per_cpu(rcu_dynticks,
65803 + snap = atomic_add_return_unchecked(0, &per_cpu(rcu_dynticks,
65804 thatcpu).dynticks);
65805 smp_mb(); /* Order sampling of snap with end of grace period. */
65806 if ((snap & 0x1) != 0) {
65807 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
65808 index 9feffa4..54058df 100644
65809 --- a/kernel/rcutree_trace.c
65810 +++ b/kernel/rcutree_trace.c
65811 @@ -69,7 +69,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
65812 rdp->qs_pending);
65813 #ifdef CONFIG_NO_HZ
65814 seq_printf(m, " dt=%d/%d/%d df=%lu",
65815 - atomic_read(&rdp->dynticks->dynticks),
65816 + atomic_read_unchecked(&rdp->dynticks->dynticks),
65817 rdp->dynticks->dynticks_nesting,
65818 rdp->dynticks->dynticks_nmi_nesting,
65819 rdp->dynticks_fqs);
65820 @@ -143,7 +143,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
65821 rdp->qs_pending);
65822 #ifdef CONFIG_NO_HZ
65823 seq_printf(m, ",%d,%d,%d,%lu",
65824 - atomic_read(&rdp->dynticks->dynticks),
65825 + atomic_read_unchecked(&rdp->dynticks->dynticks),
65826 rdp->dynticks->dynticks_nesting,
65827 rdp->dynticks->dynticks_nmi_nesting,
65828 rdp->dynticks_fqs);
65829 diff --git a/kernel/resource.c b/kernel/resource.c
65830 index 7640b3a..5879283 100644
65831 --- a/kernel/resource.c
65832 +++ b/kernel/resource.c
65833 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
65834
65835 static int __init ioresources_init(void)
65836 {
65837 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
65838 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65839 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
65840 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
65841 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65842 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
65843 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
65844 +#endif
65845 +#else
65846 proc_create("ioports", 0, NULL, &proc_ioports_operations);
65847 proc_create("iomem", 0, NULL, &proc_iomem_operations);
65848 +#endif
65849 return 0;
65850 }
65851 __initcall(ioresources_init);
65852 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
65853 index 3d9f31c..7fefc9e 100644
65854 --- a/kernel/rtmutex-tester.c
65855 +++ b/kernel/rtmutex-tester.c
65856 @@ -20,7 +20,7 @@
65857 #define MAX_RT_TEST_MUTEXES 8
65858
65859 static spinlock_t rttest_lock;
65860 -static atomic_t rttest_event;
65861 +static atomic_unchecked_t rttest_event;
65862
65863 struct test_thread_data {
65864 int opcode;
65865 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
65866
65867 case RTTEST_LOCKCONT:
65868 td->mutexes[td->opdata] = 1;
65869 - td->event = atomic_add_return(1, &rttest_event);
65870 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65871 return 0;
65872
65873 case RTTEST_RESET:
65874 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
65875 return 0;
65876
65877 case RTTEST_RESETEVENT:
65878 - atomic_set(&rttest_event, 0);
65879 + atomic_set_unchecked(&rttest_event, 0);
65880 return 0;
65881
65882 default:
65883 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
65884 return ret;
65885
65886 td->mutexes[id] = 1;
65887 - td->event = atomic_add_return(1, &rttest_event);
65888 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65889 rt_mutex_lock(&mutexes[id]);
65890 - td->event = atomic_add_return(1, &rttest_event);
65891 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65892 td->mutexes[id] = 4;
65893 return 0;
65894
65895 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
65896 return ret;
65897
65898 td->mutexes[id] = 1;
65899 - td->event = atomic_add_return(1, &rttest_event);
65900 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65901 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
65902 - td->event = atomic_add_return(1, &rttest_event);
65903 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65904 td->mutexes[id] = ret ? 0 : 4;
65905 return ret ? -EINTR : 0;
65906
65907 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
65908 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
65909 return ret;
65910
65911 - td->event = atomic_add_return(1, &rttest_event);
65912 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65913 rt_mutex_unlock(&mutexes[id]);
65914 - td->event = atomic_add_return(1, &rttest_event);
65915 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65916 td->mutexes[id] = 0;
65917 return 0;
65918
65919 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
65920 break;
65921
65922 td->mutexes[dat] = 2;
65923 - td->event = atomic_add_return(1, &rttest_event);
65924 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65925 break;
65926
65927 default:
65928 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
65929 return;
65930
65931 td->mutexes[dat] = 3;
65932 - td->event = atomic_add_return(1, &rttest_event);
65933 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65934 break;
65935
65936 case RTTEST_LOCKNOWAIT:
65937 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
65938 return;
65939
65940 td->mutexes[dat] = 1;
65941 - td->event = atomic_add_return(1, &rttest_event);
65942 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65943 return;
65944
65945 default:
65946 diff --git a/kernel/sched.c b/kernel/sched.c
65947 index d6b149c..896cbb8 100644
65948 --- a/kernel/sched.c
65949 +++ b/kernel/sched.c
65950 @@ -4389,6 +4389,19 @@ pick_next_task(struct rq *rq)
65951 BUG(); /* the idle class will always have a runnable task */
65952 }
65953
65954 +#ifdef CONFIG_GRKERNSEC_SETXID
65955 +extern void gr_delayed_cred_worker(void);
65956 +static inline void gr_cred_schedule(void)
65957 +{
65958 + if (unlikely(current->delayed_cred))
65959 + gr_delayed_cred_worker();
65960 +}
65961 +#else
65962 +static inline void gr_cred_schedule(void)
65963 +{
65964 +}
65965 +#endif
65966 +
65967 /*
65968 * __schedule() is the main scheduler function.
65969 */
65970 @@ -4408,6 +4421,8 @@ need_resched:
65971
65972 schedule_debug(prev);
65973
65974 + gr_cred_schedule();
65975 +
65976 if (sched_feat(HRTICK))
65977 hrtick_clear(rq);
65978
65979 @@ -5098,6 +5113,8 @@ int can_nice(const struct task_struct *p, const int nice)
65980 /* convert nice value [19,-20] to rlimit style value [1,40] */
65981 int nice_rlim = 20 - nice;
65982
65983 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
65984 +
65985 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
65986 capable(CAP_SYS_NICE));
65987 }
65988 @@ -5131,7 +5148,8 @@ SYSCALL_DEFINE1(nice, int, increment)
65989 if (nice > 19)
65990 nice = 19;
65991
65992 - if (increment < 0 && !can_nice(current, nice))
65993 + if (increment < 0 && (!can_nice(current, nice) ||
65994 + gr_handle_chroot_nice()))
65995 return -EPERM;
65996
65997 retval = security_task_setnice(current, nice);
65998 @@ -5288,6 +5306,7 @@ recheck:
65999 unsigned long rlim_rtprio =
66000 task_rlimit(p, RLIMIT_RTPRIO);
66001
66002 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
66003 /* can't set/change the rt policy */
66004 if (policy != p->policy && !rlim_rtprio)
66005 return -EPERM;
66006 diff --git a/kernel/sched_autogroup.c b/kernel/sched_autogroup.c
66007 index 429242f..d7cca82 100644
66008 --- a/kernel/sched_autogroup.c
66009 +++ b/kernel/sched_autogroup.c
66010 @@ -7,7 +7,7 @@
66011
66012 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
66013 static struct autogroup autogroup_default;
66014 -static atomic_t autogroup_seq_nr;
66015 +static atomic_unchecked_t autogroup_seq_nr;
66016
66017 static void __init autogroup_init(struct task_struct *init_task)
66018 {
66019 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
66020
66021 kref_init(&ag->kref);
66022 init_rwsem(&ag->lock);
66023 - ag->id = atomic_inc_return(&autogroup_seq_nr);
66024 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
66025 ag->tg = tg;
66026 #ifdef CONFIG_RT_GROUP_SCHED
66027 /*
66028 diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
66029 index 8a39fa3..34f3dbc 100644
66030 --- a/kernel/sched_fair.c
66031 +++ b/kernel/sched_fair.c
66032 @@ -4801,7 +4801,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
66033 * run_rebalance_domains is triggered when needed from the scheduler tick.
66034 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
66035 */
66036 -static void run_rebalance_domains(struct softirq_action *h)
66037 +static void run_rebalance_domains(void)
66038 {
66039 int this_cpu = smp_processor_id();
66040 struct rq *this_rq = cpu_rq(this_cpu);
66041 diff --git a/kernel/signal.c b/kernel/signal.c
66042 index 2065515..aed2987 100644
66043 --- a/kernel/signal.c
66044 +++ b/kernel/signal.c
66045 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cachep;
66046
66047 int print_fatal_signals __read_mostly;
66048
66049 -static void __user *sig_handler(struct task_struct *t, int sig)
66050 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
66051 {
66052 return t->sighand->action[sig - 1].sa.sa_handler;
66053 }
66054
66055 -static int sig_handler_ignored(void __user *handler, int sig)
66056 +static int sig_handler_ignored(__sighandler_t handler, int sig)
66057 {
66058 /* Is it explicitly or implicitly ignored? */
66059 return handler == SIG_IGN ||
66060 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
66061 static int sig_task_ignored(struct task_struct *t, int sig,
66062 int from_ancestor_ns)
66063 {
66064 - void __user *handler;
66065 + __sighandler_t handler;
66066
66067 handler = sig_handler(t, sig);
66068
66069 @@ -364,6 +364,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
66070 atomic_inc(&user->sigpending);
66071 rcu_read_unlock();
66072
66073 + if (!override_rlimit)
66074 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
66075 +
66076 if (override_rlimit ||
66077 atomic_read(&user->sigpending) <=
66078 task_rlimit(t, RLIMIT_SIGPENDING)) {
66079 @@ -488,7 +491,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
66080
66081 int unhandled_signal(struct task_struct *tsk, int sig)
66082 {
66083 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
66084 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
66085 if (is_global_init(tsk))
66086 return 1;
66087 if (handler != SIG_IGN && handler != SIG_DFL)
66088 @@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
66089 }
66090 }
66091
66092 + /* allow glibc communication via tgkill to other threads in our
66093 + thread group */
66094 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
66095 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
66096 + && gr_handle_signal(t, sig))
66097 + return -EPERM;
66098 +
66099 return security_task_kill(t, info, sig, 0);
66100 }
66101
66102 @@ -1165,7 +1175,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
66103 return send_signal(sig, info, p, 1);
66104 }
66105
66106 -static int
66107 +int
66108 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66109 {
66110 return send_signal(sig, info, t, 0);
66111 @@ -1202,6 +1212,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66112 unsigned long int flags;
66113 int ret, blocked, ignored;
66114 struct k_sigaction *action;
66115 + int is_unhandled = 0;
66116
66117 spin_lock_irqsave(&t->sighand->siglock, flags);
66118 action = &t->sighand->action[sig-1];
66119 @@ -1216,9 +1227,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66120 }
66121 if (action->sa.sa_handler == SIG_DFL)
66122 t->signal->flags &= ~SIGNAL_UNKILLABLE;
66123 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
66124 + is_unhandled = 1;
66125 ret = specific_send_sig_info(sig, info, t);
66126 spin_unlock_irqrestore(&t->sighand->siglock, flags);
66127
66128 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
66129 + normal operation */
66130 + if (is_unhandled) {
66131 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
66132 + gr_handle_crash(t, sig);
66133 + }
66134 +
66135 return ret;
66136 }
66137
66138 @@ -1285,8 +1305,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
66139 ret = check_kill_permission(sig, info, p);
66140 rcu_read_unlock();
66141
66142 - if (!ret && sig)
66143 + if (!ret && sig) {
66144 ret = do_send_sig_info(sig, info, p, true);
66145 + if (!ret)
66146 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
66147 + }
66148
66149 return ret;
66150 }
66151 @@ -2754,7 +2777,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
66152 int error = -ESRCH;
66153
66154 rcu_read_lock();
66155 - p = find_task_by_vpid(pid);
66156 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66157 + /* allow glibc communication via tgkill to other threads in our
66158 + thread group */
66159 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
66160 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
66161 + p = find_task_by_vpid_unrestricted(pid);
66162 + else
66163 +#endif
66164 + p = find_task_by_vpid(pid);
66165 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
66166 error = check_kill_permission(sig, info, p);
66167 /*
66168 diff --git a/kernel/smp.c b/kernel/smp.c
66169 index db197d6..17aef0b 100644
66170 --- a/kernel/smp.c
66171 +++ b/kernel/smp.c
66172 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
66173 }
66174 EXPORT_SYMBOL(smp_call_function);
66175
66176 -void ipi_call_lock(void)
66177 +void ipi_call_lock(void) __acquires(call_function.lock)
66178 {
66179 raw_spin_lock(&call_function.lock);
66180 }
66181
66182 -void ipi_call_unlock(void)
66183 +void ipi_call_unlock(void) __releases(call_function.lock)
66184 {
66185 raw_spin_unlock(&call_function.lock);
66186 }
66187
66188 -void ipi_call_lock_irq(void)
66189 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
66190 {
66191 raw_spin_lock_irq(&call_function.lock);
66192 }
66193
66194 -void ipi_call_unlock_irq(void)
66195 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
66196 {
66197 raw_spin_unlock_irq(&call_function.lock);
66198 }
66199 diff --git a/kernel/softirq.c b/kernel/softirq.c
66200 index 2c71d91..1021f81 100644
66201 --- a/kernel/softirq.c
66202 +++ b/kernel/softirq.c
66203 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
66204
66205 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
66206
66207 -char *softirq_to_name[NR_SOFTIRQS] = {
66208 +const char * const softirq_to_name[NR_SOFTIRQS] = {
66209 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
66210 "TASKLET", "SCHED", "HRTIMER", "RCU"
66211 };
66212 @@ -235,7 +235,7 @@ restart:
66213 kstat_incr_softirqs_this_cpu(vec_nr);
66214
66215 trace_softirq_entry(vec_nr);
66216 - h->action(h);
66217 + h->action();
66218 trace_softirq_exit(vec_nr);
66219 if (unlikely(prev_count != preempt_count())) {
66220 printk(KERN_ERR "huh, entered softirq %u %s %p"
66221 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
66222 local_irq_restore(flags);
66223 }
66224
66225 -void open_softirq(int nr, void (*action)(struct softirq_action *))
66226 +void open_softirq(int nr, void (*action)(void))
66227 {
66228 - softirq_vec[nr].action = action;
66229 + pax_open_kernel();
66230 + *(void **)&softirq_vec[nr].action = action;
66231 + pax_close_kernel();
66232 }
66233
66234 /*
66235 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
66236
66237 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
66238
66239 -static void tasklet_action(struct softirq_action *a)
66240 +static void tasklet_action(void)
66241 {
66242 struct tasklet_struct *list;
66243
66244 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
66245 }
66246 }
66247
66248 -static void tasklet_hi_action(struct softirq_action *a)
66249 +static void tasklet_hi_action(void)
66250 {
66251 struct tasklet_struct *list;
66252
66253 diff --git a/kernel/sys.c b/kernel/sys.c
66254 index 481611f..0754d86 100644
66255 --- a/kernel/sys.c
66256 +++ b/kernel/sys.c
66257 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
66258 error = -EACCES;
66259 goto out;
66260 }
66261 +
66262 + if (gr_handle_chroot_setpriority(p, niceval)) {
66263 + error = -EACCES;
66264 + goto out;
66265 + }
66266 +
66267 no_nice = security_task_setnice(p, niceval);
66268 if (no_nice) {
66269 error = no_nice;
66270 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
66271 goto error;
66272 }
66273
66274 + if (gr_check_group_change(new->gid, new->egid, -1))
66275 + goto error;
66276 +
66277 if (rgid != (gid_t) -1 ||
66278 (egid != (gid_t) -1 && egid != old->gid))
66279 new->sgid = new->egid;
66280 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
66281 old = current_cred();
66282
66283 retval = -EPERM;
66284 +
66285 + if (gr_check_group_change(gid, gid, gid))
66286 + goto error;
66287 +
66288 if (nsown_capable(CAP_SETGID))
66289 new->gid = new->egid = new->sgid = new->fsgid = gid;
66290 else if (gid == old->gid || gid == old->sgid)
66291 @@ -618,7 +631,7 @@ error:
66292 /*
66293 * change the user struct in a credentials set to match the new UID
66294 */
66295 -static int set_user(struct cred *new)
66296 +int set_user(struct cred *new)
66297 {
66298 struct user_struct *new_user;
66299
66300 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
66301 goto error;
66302 }
66303
66304 + if (gr_check_user_change(new->uid, new->euid, -1))
66305 + goto error;
66306 +
66307 if (new->uid != old->uid) {
66308 retval = set_user(new);
66309 if (retval < 0)
66310 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
66311 old = current_cred();
66312
66313 retval = -EPERM;
66314 +
66315 + if (gr_check_crash_uid(uid))
66316 + goto error;
66317 + if (gr_check_user_change(uid, uid, uid))
66318 + goto error;
66319 +
66320 if (nsown_capable(CAP_SETUID)) {
66321 new->suid = new->uid = uid;
66322 if (uid != old->uid) {
66323 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
66324 goto error;
66325 }
66326
66327 + if (gr_check_user_change(ruid, euid, -1))
66328 + goto error;
66329 +
66330 if (ruid != (uid_t) -1) {
66331 new->uid = ruid;
66332 if (ruid != old->uid) {
66333 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
66334 goto error;
66335 }
66336
66337 + if (gr_check_group_change(rgid, egid, -1))
66338 + goto error;
66339 +
66340 if (rgid != (gid_t) -1)
66341 new->gid = rgid;
66342 if (egid != (gid_t) -1)
66343 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
66344 old = current_cred();
66345 old_fsuid = old->fsuid;
66346
66347 + if (gr_check_user_change(-1, -1, uid))
66348 + goto error;
66349 +
66350 if (uid == old->uid || uid == old->euid ||
66351 uid == old->suid || uid == old->fsuid ||
66352 nsown_capable(CAP_SETUID)) {
66353 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
66354 }
66355 }
66356
66357 +error:
66358 abort_creds(new);
66359 return old_fsuid;
66360
66361 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
66362 if (gid == old->gid || gid == old->egid ||
66363 gid == old->sgid || gid == old->fsgid ||
66364 nsown_capable(CAP_SETGID)) {
66365 + if (gr_check_group_change(-1, -1, gid))
66366 + goto error;
66367 +
66368 if (gid != old_fsgid) {
66369 new->fsgid = gid;
66370 goto change_okay;
66371 }
66372 }
66373
66374 +error:
66375 abort_creds(new);
66376 return old_fsgid;
66377
66378 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
66379 }
66380 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
66381 snprintf(buf, len, "2.6.%u%s", v, rest);
66382 - ret = copy_to_user(release, buf, len);
66383 + if (len > sizeof(buf))
66384 + ret = -EFAULT;
66385 + else
66386 + ret = copy_to_user(release, buf, len);
66387 }
66388 return ret;
66389 }
66390 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
66391 return -EFAULT;
66392
66393 down_read(&uts_sem);
66394 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
66395 + error = __copy_to_user(name->sysname, &utsname()->sysname,
66396 __OLD_UTS_LEN);
66397 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
66398 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
66399 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
66400 __OLD_UTS_LEN);
66401 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
66402 - error |= __copy_to_user(&name->release, &utsname()->release,
66403 + error |= __copy_to_user(name->release, &utsname()->release,
66404 __OLD_UTS_LEN);
66405 error |= __put_user(0, name->release + __OLD_UTS_LEN);
66406 - error |= __copy_to_user(&name->version, &utsname()->version,
66407 + error |= __copy_to_user(name->version, &utsname()->version,
66408 __OLD_UTS_LEN);
66409 error |= __put_user(0, name->version + __OLD_UTS_LEN);
66410 - error |= __copy_to_user(&name->machine, &utsname()->machine,
66411 + error |= __copy_to_user(name->machine, &utsname()->machine,
66412 __OLD_UTS_LEN);
66413 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
66414 up_read(&uts_sem);
66415 @@ -1720,7 +1759,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
66416 error = get_dumpable(me->mm);
66417 break;
66418 case PR_SET_DUMPABLE:
66419 - if (arg2 < 0 || arg2 > 1) {
66420 + if (arg2 > 1) {
66421 error = -EINVAL;
66422 break;
66423 }
66424 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
66425 index ae27196..7506d69 100644
66426 --- a/kernel/sysctl.c
66427 +++ b/kernel/sysctl.c
66428 @@ -86,6 +86,13 @@
66429
66430
66431 #if defined(CONFIG_SYSCTL)
66432 +#include <linux/grsecurity.h>
66433 +#include <linux/grinternal.h>
66434 +
66435 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
66436 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66437 + const int op);
66438 +extern int gr_handle_chroot_sysctl(const int op);
66439
66440 /* External variables not in a header file. */
66441 extern int sysctl_overcommit_memory;
66442 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
66443 }
66444
66445 #endif
66446 +extern struct ctl_table grsecurity_table[];
66447
66448 static struct ctl_table root_table[];
66449 static struct ctl_table_root sysctl_table_root;
66450 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
66451 int sysctl_legacy_va_layout;
66452 #endif
66453
66454 +#ifdef CONFIG_PAX_SOFTMODE
66455 +static ctl_table pax_table[] = {
66456 + {
66457 + .procname = "softmode",
66458 + .data = &pax_softmode,
66459 + .maxlen = sizeof(unsigned int),
66460 + .mode = 0600,
66461 + .proc_handler = &proc_dointvec,
66462 + },
66463 +
66464 + { }
66465 +};
66466 +#endif
66467 +
66468 /* The default sysctl tables: */
66469
66470 static struct ctl_table root_table[] = {
66471 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
66472 #endif
66473
66474 static struct ctl_table kern_table[] = {
66475 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66476 + {
66477 + .procname = "grsecurity",
66478 + .mode = 0500,
66479 + .child = grsecurity_table,
66480 + },
66481 +#endif
66482 +
66483 +#ifdef CONFIG_PAX_SOFTMODE
66484 + {
66485 + .procname = "pax",
66486 + .mode = 0500,
66487 + .child = pax_table,
66488 + },
66489 +#endif
66490 +
66491 {
66492 .procname = "sched_child_runs_first",
66493 .data = &sysctl_sched_child_runs_first,
66494 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
66495 .data = &modprobe_path,
66496 .maxlen = KMOD_PATH_LEN,
66497 .mode = 0644,
66498 - .proc_handler = proc_dostring,
66499 + .proc_handler = proc_dostring_modpriv,
66500 },
66501 {
66502 .procname = "modules_disabled",
66503 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
66504 .extra1 = &zero,
66505 .extra2 = &one,
66506 },
66507 +#endif
66508 {
66509 .procname = "kptr_restrict",
66510 .data = &kptr_restrict,
66511 .maxlen = sizeof(int),
66512 .mode = 0644,
66513 .proc_handler = proc_dmesg_restrict,
66514 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66515 + .extra1 = &two,
66516 +#else
66517 .extra1 = &zero,
66518 +#endif
66519 .extra2 = &two,
66520 },
66521 -#endif
66522 {
66523 .procname = "ngroups_max",
66524 .data = &ngroups_max,
66525 @@ -1216,6 +1258,13 @@ static struct ctl_table vm_table[] = {
66526 .proc_handler = proc_dointvec_minmax,
66527 .extra1 = &zero,
66528 },
66529 + {
66530 + .procname = "heap_stack_gap",
66531 + .data = &sysctl_heap_stack_gap,
66532 + .maxlen = sizeof(sysctl_heap_stack_gap),
66533 + .mode = 0644,
66534 + .proc_handler = proc_doulongvec_minmax,
66535 + },
66536 #else
66537 {
66538 .procname = "nr_trim_pages",
66539 @@ -1720,6 +1769,17 @@ static int test_perm(int mode, int op)
66540 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
66541 {
66542 int mode;
66543 + int error;
66544 +
66545 + if (table->parent != NULL && table->parent->procname != NULL &&
66546 + table->procname != NULL &&
66547 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
66548 + return -EACCES;
66549 + if (gr_handle_chroot_sysctl(op))
66550 + return -EACCES;
66551 + error = gr_handle_sysctl(table, op);
66552 + if (error)
66553 + return error;
66554
66555 if (root->permissions)
66556 mode = root->permissions(root, current->nsproxy, table);
66557 @@ -2124,6 +2184,16 @@ int proc_dostring(struct ctl_table *table, int write,
66558 buffer, lenp, ppos);
66559 }
66560
66561 +int proc_dostring_modpriv(struct ctl_table *table, int write,
66562 + void __user *buffer, size_t *lenp, loff_t *ppos)
66563 +{
66564 + if (write && !capable(CAP_SYS_MODULE))
66565 + return -EPERM;
66566 +
66567 + return _proc_do_string(table->data, table->maxlen, write,
66568 + buffer, lenp, ppos);
66569 +}
66570 +
66571 static size_t proc_skip_spaces(char **buf)
66572 {
66573 size_t ret;
66574 @@ -2229,6 +2299,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
66575 len = strlen(tmp);
66576 if (len > *size)
66577 len = *size;
66578 + if (len > sizeof(tmp))
66579 + len = sizeof(tmp);
66580 if (copy_to_user(*buf, tmp, len))
66581 return -EFAULT;
66582 *size -= len;
66583 @@ -2545,8 +2617,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
66584 *i = val;
66585 } else {
66586 val = convdiv * (*i) / convmul;
66587 - if (!first)
66588 + if (!first) {
66589 err = proc_put_char(&buffer, &left, '\t');
66590 + if (err)
66591 + break;
66592 + }
66593 err = proc_put_long(&buffer, &left, val, false);
66594 if (err)
66595 break;
66596 @@ -2941,6 +3016,12 @@ int proc_dostring(struct ctl_table *table, int write,
66597 return -ENOSYS;
66598 }
66599
66600 +int proc_dostring_modpriv(struct ctl_table *table, int write,
66601 + void __user *buffer, size_t *lenp, loff_t *ppos)
66602 +{
66603 + return -ENOSYS;
66604 +}
66605 +
66606 int proc_dointvec(struct ctl_table *table, int write,
66607 void __user *buffer, size_t *lenp, loff_t *ppos)
66608 {
66609 @@ -2997,6 +3078,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
66610 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
66611 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
66612 EXPORT_SYMBOL(proc_dostring);
66613 +EXPORT_SYMBOL(proc_dostring_modpriv);
66614 EXPORT_SYMBOL(proc_doulongvec_minmax);
66615 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
66616 EXPORT_SYMBOL(register_sysctl_table);
66617 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
66618 index a650694..aaeeb20 100644
66619 --- a/kernel/sysctl_binary.c
66620 +++ b/kernel/sysctl_binary.c
66621 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
66622 int i;
66623
66624 set_fs(KERNEL_DS);
66625 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
66626 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
66627 set_fs(old_fs);
66628 if (result < 0)
66629 goto out_kfree;
66630 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
66631 }
66632
66633 set_fs(KERNEL_DS);
66634 - result = vfs_write(file, buffer, str - buffer, &pos);
66635 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
66636 set_fs(old_fs);
66637 if (result < 0)
66638 goto out_kfree;
66639 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
66640 int i;
66641
66642 set_fs(KERNEL_DS);
66643 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
66644 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
66645 set_fs(old_fs);
66646 if (result < 0)
66647 goto out_kfree;
66648 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
66649 }
66650
66651 set_fs(KERNEL_DS);
66652 - result = vfs_write(file, buffer, str - buffer, &pos);
66653 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
66654 set_fs(old_fs);
66655 if (result < 0)
66656 goto out_kfree;
66657 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
66658 int i;
66659
66660 set_fs(KERNEL_DS);
66661 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
66662 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
66663 set_fs(old_fs);
66664 if (result < 0)
66665 goto out;
66666 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
66667 __le16 dnaddr;
66668
66669 set_fs(KERNEL_DS);
66670 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
66671 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
66672 set_fs(old_fs);
66673 if (result < 0)
66674 goto out;
66675 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
66676 le16_to_cpu(dnaddr) & 0x3ff);
66677
66678 set_fs(KERNEL_DS);
66679 - result = vfs_write(file, buf, len, &pos);
66680 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
66681 set_fs(old_fs);
66682 if (result < 0)
66683 goto out;
66684 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
66685 index 362da65..ab8ef8c 100644
66686 --- a/kernel/sysctl_check.c
66687 +++ b/kernel/sysctl_check.c
66688 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
66689 set_fail(&fail, table, "Directory with extra2");
66690 } else {
66691 if ((table->proc_handler == proc_dostring) ||
66692 + (table->proc_handler == proc_dostring_modpriv) ||
66693 (table->proc_handler == proc_dointvec) ||
66694 (table->proc_handler == proc_dointvec_minmax) ||
66695 (table->proc_handler == proc_dointvec_jiffies) ||
66696 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
66697 index e660464..c8b9e67 100644
66698 --- a/kernel/taskstats.c
66699 +++ b/kernel/taskstats.c
66700 @@ -27,9 +27,12 @@
66701 #include <linux/cgroup.h>
66702 #include <linux/fs.h>
66703 #include <linux/file.h>
66704 +#include <linux/grsecurity.h>
66705 #include <net/genetlink.h>
66706 #include <linux/atomic.h>
66707
66708 +extern int gr_is_taskstats_denied(int pid);
66709 +
66710 /*
66711 * Maximum length of a cpumask that can be specified in
66712 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
66713 @@ -556,6 +559,9 @@ err:
66714
66715 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
66716 {
66717 + if (gr_is_taskstats_denied(current->pid))
66718 + return -EACCES;
66719 +
66720 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
66721 return cmd_attr_register_cpumask(info);
66722 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
66723 diff --git a/kernel/time.c b/kernel/time.c
66724 index 73e416d..cfc6f69 100644
66725 --- a/kernel/time.c
66726 +++ b/kernel/time.c
66727 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
66728 return error;
66729
66730 if (tz) {
66731 + /* we log in do_settimeofday called below, so don't log twice
66732 + */
66733 + if (!tv)
66734 + gr_log_timechange();
66735 +
66736 /* SMP safe, global irq locking makes it work. */
66737 sys_tz = *tz;
66738 update_vsyscall_tz();
66739 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
66740 index 8a46f5d..bbe6f9c 100644
66741 --- a/kernel/time/alarmtimer.c
66742 +++ b/kernel/time/alarmtimer.c
66743 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
66744 struct platform_device *pdev;
66745 int error = 0;
66746 int i;
66747 - struct k_clock alarm_clock = {
66748 + static struct k_clock alarm_clock = {
66749 .clock_getres = alarm_clock_getres,
66750 .clock_get = alarm_clock_get,
66751 .timer_create = alarm_timer_create,
66752 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
66753 index fd4a7b1..fae5c2a 100644
66754 --- a/kernel/time/tick-broadcast.c
66755 +++ b/kernel/time/tick-broadcast.c
66756 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
66757 * then clear the broadcast bit.
66758 */
66759 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
66760 - int cpu = smp_processor_id();
66761 + cpu = smp_processor_id();
66762
66763 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
66764 tick_broadcast_clear_oneshot(cpu);
66765 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
66766 index 2378413..be455fd 100644
66767 --- a/kernel/time/timekeeping.c
66768 +++ b/kernel/time/timekeeping.c
66769 @@ -14,6 +14,7 @@
66770 #include <linux/init.h>
66771 #include <linux/mm.h>
66772 #include <linux/sched.h>
66773 +#include <linux/grsecurity.h>
66774 #include <linux/syscore_ops.h>
66775 #include <linux/clocksource.h>
66776 #include <linux/jiffies.h>
66777 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
66778 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
66779 return -EINVAL;
66780
66781 + gr_log_timechange();
66782 +
66783 write_seqlock_irqsave(&xtime_lock, flags);
66784
66785 timekeeping_forward_now();
66786 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
66787 index 3258455..f35227d 100644
66788 --- a/kernel/time/timer_list.c
66789 +++ b/kernel/time/timer_list.c
66790 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
66791
66792 static void print_name_offset(struct seq_file *m, void *sym)
66793 {
66794 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66795 + SEQ_printf(m, "<%p>", NULL);
66796 +#else
66797 char symname[KSYM_NAME_LEN];
66798
66799 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
66800 SEQ_printf(m, "<%pK>", sym);
66801 else
66802 SEQ_printf(m, "%s", symname);
66803 +#endif
66804 }
66805
66806 static void
66807 @@ -112,7 +116,11 @@ next_one:
66808 static void
66809 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
66810 {
66811 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66812 + SEQ_printf(m, " .base: %p\n", NULL);
66813 +#else
66814 SEQ_printf(m, " .base: %pK\n", base);
66815 +#endif
66816 SEQ_printf(m, " .index: %d\n",
66817 base->index);
66818 SEQ_printf(m, " .resolution: %Lu nsecs\n",
66819 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
66820 {
66821 struct proc_dir_entry *pe;
66822
66823 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66824 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
66825 +#else
66826 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
66827 +#endif
66828 if (!pe)
66829 return -ENOMEM;
66830 return 0;
66831 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
66832 index 0b537f2..9e71eca 100644
66833 --- a/kernel/time/timer_stats.c
66834 +++ b/kernel/time/timer_stats.c
66835 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
66836 static unsigned long nr_entries;
66837 static struct entry entries[MAX_ENTRIES];
66838
66839 -static atomic_t overflow_count;
66840 +static atomic_unchecked_t overflow_count;
66841
66842 /*
66843 * The entries are in a hash-table, for fast lookup:
66844 @@ -140,7 +140,7 @@ static void reset_entries(void)
66845 nr_entries = 0;
66846 memset(entries, 0, sizeof(entries));
66847 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
66848 - atomic_set(&overflow_count, 0);
66849 + atomic_set_unchecked(&overflow_count, 0);
66850 }
66851
66852 static struct entry *alloc_entry(void)
66853 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
66854 if (likely(entry))
66855 entry->count++;
66856 else
66857 - atomic_inc(&overflow_count);
66858 + atomic_inc_unchecked(&overflow_count);
66859
66860 out_unlock:
66861 raw_spin_unlock_irqrestore(lock, flags);
66862 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
66863
66864 static void print_name_offset(struct seq_file *m, unsigned long addr)
66865 {
66866 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66867 + seq_printf(m, "<%p>", NULL);
66868 +#else
66869 char symname[KSYM_NAME_LEN];
66870
66871 if (lookup_symbol_name(addr, symname) < 0)
66872 seq_printf(m, "<%p>", (void *)addr);
66873 else
66874 seq_printf(m, "%s", symname);
66875 +#endif
66876 }
66877
66878 static int tstats_show(struct seq_file *m, void *v)
66879 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
66880
66881 seq_puts(m, "Timer Stats Version: v0.2\n");
66882 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
66883 - if (atomic_read(&overflow_count))
66884 + if (atomic_read_unchecked(&overflow_count))
66885 seq_printf(m, "Overflow: %d entries\n",
66886 - atomic_read(&overflow_count));
66887 + atomic_read_unchecked(&overflow_count));
66888
66889 for (i = 0; i < nr_entries; i++) {
66890 entry = entries + i;
66891 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
66892 {
66893 struct proc_dir_entry *pe;
66894
66895 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66896 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
66897 +#else
66898 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
66899 +#endif
66900 if (!pe)
66901 return -ENOMEM;
66902 return 0;
66903 diff --git a/kernel/timer.c b/kernel/timer.c
66904 index 9c3c62b..441690e 100644
66905 --- a/kernel/timer.c
66906 +++ b/kernel/timer.c
66907 @@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
66908 /*
66909 * This function runs timers and the timer-tq in bottom half context.
66910 */
66911 -static void run_timer_softirq(struct softirq_action *h)
66912 +static void run_timer_softirq(void)
66913 {
66914 struct tvec_base *base = __this_cpu_read(tvec_bases);
66915
66916 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
66917 index 16fc34a..efd8bb8 100644
66918 --- a/kernel/trace/blktrace.c
66919 +++ b/kernel/trace/blktrace.c
66920 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
66921 struct blk_trace *bt = filp->private_data;
66922 char buf[16];
66923
66924 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
66925 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
66926
66927 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
66928 }
66929 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
66930 return 1;
66931
66932 bt = buf->chan->private_data;
66933 - atomic_inc(&bt->dropped);
66934 + atomic_inc_unchecked(&bt->dropped);
66935 return 0;
66936 }
66937
66938 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
66939
66940 bt->dir = dir;
66941 bt->dev = dev;
66942 - atomic_set(&bt->dropped, 0);
66943 + atomic_set_unchecked(&bt->dropped, 0);
66944
66945 ret = -EIO;
66946 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
66947 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
66948 index b1e8943..369e4ff 100644
66949 --- a/kernel/trace/ftrace.c
66950 +++ b/kernel/trace/ftrace.c
66951 @@ -1587,12 +1587,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
66952 if (unlikely(ftrace_disabled))
66953 return 0;
66954
66955 + ret = ftrace_arch_code_modify_prepare();
66956 + FTRACE_WARN_ON(ret);
66957 + if (ret)
66958 + return 0;
66959 +
66960 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
66961 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
66962 if (ret) {
66963 ftrace_bug(ret, ip);
66964 - return 0;
66965 }
66966 - return 1;
66967 + return ret ? 0 : 1;
66968 }
66969
66970 /*
66971 @@ -2609,7 +2614,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
66972
66973 int
66974 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
66975 - void *data)
66976 + void *data)
66977 {
66978 struct ftrace_func_probe *entry;
66979 struct ftrace_page *pg;
66980 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
66981 index f2bd275..adaf3a2 100644
66982 --- a/kernel/trace/trace.c
66983 +++ b/kernel/trace/trace.c
66984 @@ -4201,10 +4201,9 @@ static const struct file_operations tracing_dyn_info_fops = {
66985 };
66986 #endif
66987
66988 -static struct dentry *d_tracer;
66989 -
66990 struct dentry *tracing_init_dentry(void)
66991 {
66992 + static struct dentry *d_tracer;
66993 static int once;
66994
66995 if (d_tracer)
66996 @@ -4224,10 +4223,9 @@ struct dentry *tracing_init_dentry(void)
66997 return d_tracer;
66998 }
66999
67000 -static struct dentry *d_percpu;
67001 -
67002 struct dentry *tracing_dentry_percpu(void)
67003 {
67004 + static struct dentry *d_percpu;
67005 static int once;
67006 struct dentry *d_tracer;
67007
67008 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
67009 index c212a7f..7b02394 100644
67010 --- a/kernel/trace/trace_events.c
67011 +++ b/kernel/trace/trace_events.c
67012 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
67013 struct ftrace_module_file_ops {
67014 struct list_head list;
67015 struct module *mod;
67016 - struct file_operations id;
67017 - struct file_operations enable;
67018 - struct file_operations format;
67019 - struct file_operations filter;
67020 };
67021
67022 static struct ftrace_module_file_ops *
67023 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
67024
67025 file_ops->mod = mod;
67026
67027 - file_ops->id = ftrace_event_id_fops;
67028 - file_ops->id.owner = mod;
67029 -
67030 - file_ops->enable = ftrace_enable_fops;
67031 - file_ops->enable.owner = mod;
67032 -
67033 - file_ops->filter = ftrace_event_filter_fops;
67034 - file_ops->filter.owner = mod;
67035 -
67036 - file_ops->format = ftrace_event_format_fops;
67037 - file_ops->format.owner = mod;
67038 + pax_open_kernel();
67039 + *(void **)&mod->trace_id.owner = mod;
67040 + *(void **)&mod->trace_enable.owner = mod;
67041 + *(void **)&mod->trace_filter.owner = mod;
67042 + *(void **)&mod->trace_format.owner = mod;
67043 + pax_close_kernel();
67044
67045 list_add(&file_ops->list, &ftrace_module_file_list);
67046
67047 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
67048
67049 for_each_event(call, start, end) {
67050 __trace_add_event_call(*call, mod,
67051 - &file_ops->id, &file_ops->enable,
67052 - &file_ops->filter, &file_ops->format);
67053 + &mod->trace_id, &mod->trace_enable,
67054 + &mod->trace_filter, &mod->trace_format);
67055 }
67056 }
67057
67058 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
67059 index 00d527c..7c5b1a3 100644
67060 --- a/kernel/trace/trace_kprobe.c
67061 +++ b/kernel/trace/trace_kprobe.c
67062 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67063 long ret;
67064 int maxlen = get_rloc_len(*(u32 *)dest);
67065 u8 *dst = get_rloc_data(dest);
67066 - u8 *src = addr;
67067 + const u8 __user *src = (const u8 __force_user *)addr;
67068 mm_segment_t old_fs = get_fs();
67069 if (!maxlen)
67070 return;
67071 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67072 pagefault_disable();
67073 do
67074 ret = __copy_from_user_inatomic(dst++, src++, 1);
67075 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
67076 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
67077 dst[-1] = '\0';
67078 pagefault_enable();
67079 set_fs(old_fs);
67080 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67081 ((u8 *)get_rloc_data(dest))[0] = '\0';
67082 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
67083 } else
67084 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
67085 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
67086 get_rloc_offs(*(u32 *)dest));
67087 }
67088 /* Return the length of string -- including null terminal byte */
67089 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
67090 set_fs(KERNEL_DS);
67091 pagefault_disable();
67092 do {
67093 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
67094 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
67095 len++;
67096 } while (c && ret == 0 && len < MAX_STRING_SIZE);
67097 pagefault_enable();
67098 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
67099 index fd3c8aa..5f324a6 100644
67100 --- a/kernel/trace/trace_mmiotrace.c
67101 +++ b/kernel/trace/trace_mmiotrace.c
67102 @@ -24,7 +24,7 @@ struct header_iter {
67103 static struct trace_array *mmio_trace_array;
67104 static bool overrun_detected;
67105 static unsigned long prev_overruns;
67106 -static atomic_t dropped_count;
67107 +static atomic_unchecked_t dropped_count;
67108
67109 static void mmio_reset_data(struct trace_array *tr)
67110 {
67111 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
67112
67113 static unsigned long count_overruns(struct trace_iterator *iter)
67114 {
67115 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
67116 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
67117 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
67118
67119 if (over > prev_overruns)
67120 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
67121 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
67122 sizeof(*entry), 0, pc);
67123 if (!event) {
67124 - atomic_inc(&dropped_count);
67125 + atomic_inc_unchecked(&dropped_count);
67126 return;
67127 }
67128 entry = ring_buffer_event_data(event);
67129 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
67130 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
67131 sizeof(*entry), 0, pc);
67132 if (!event) {
67133 - atomic_inc(&dropped_count);
67134 + atomic_inc_unchecked(&dropped_count);
67135 return;
67136 }
67137 entry = ring_buffer_event_data(event);
67138 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
67139 index 5199930..26c73a0 100644
67140 --- a/kernel/trace/trace_output.c
67141 +++ b/kernel/trace/trace_output.c
67142 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
67143
67144 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
67145 if (!IS_ERR(p)) {
67146 - p = mangle_path(s->buffer + s->len, p, "\n");
67147 + p = mangle_path(s->buffer + s->len, p, "\n\\");
67148 if (p) {
67149 s->len = p - s->buffer;
67150 return 1;
67151 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
67152 index 77575b3..6e623d1 100644
67153 --- a/kernel/trace/trace_stack.c
67154 +++ b/kernel/trace/trace_stack.c
67155 @@ -50,7 +50,7 @@ static inline void check_stack(void)
67156 return;
67157
67158 /* we do not handle interrupt stacks yet */
67159 - if (!object_is_on_stack(&this_size))
67160 + if (!object_starts_on_stack(&this_size))
67161 return;
67162
67163 local_irq_save(flags);
67164 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
67165 index 209b379..7f76423 100644
67166 --- a/kernel/trace/trace_workqueue.c
67167 +++ b/kernel/trace/trace_workqueue.c
67168 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
67169 int cpu;
67170 pid_t pid;
67171 /* Can be inserted from interrupt or user context, need to be atomic */
67172 - atomic_t inserted;
67173 + atomic_unchecked_t inserted;
67174 /*
67175 * Don't need to be atomic, works are serialized in a single workqueue thread
67176 * on a single CPU.
67177 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
67178 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
67179 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
67180 if (node->pid == wq_thread->pid) {
67181 - atomic_inc(&node->inserted);
67182 + atomic_inc_unchecked(&node->inserted);
67183 goto found;
67184 }
67185 }
67186 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
67187 tsk = get_pid_task(pid, PIDTYPE_PID);
67188 if (tsk) {
67189 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
67190 - atomic_read(&cws->inserted), cws->executed,
67191 + atomic_read_unchecked(&cws->inserted), cws->executed,
67192 tsk->comm);
67193 put_task_struct(tsk);
67194 }
67195 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
67196 index 82928f5..92da771 100644
67197 --- a/lib/Kconfig.debug
67198 +++ b/lib/Kconfig.debug
67199 @@ -1103,6 +1103,7 @@ config LATENCYTOP
67200 depends on DEBUG_KERNEL
67201 depends on STACKTRACE_SUPPORT
67202 depends on PROC_FS
67203 + depends on !GRKERNSEC_HIDESYM
67204 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
67205 select KALLSYMS
67206 select KALLSYMS_ALL
67207 diff --git a/lib/bitmap.c b/lib/bitmap.c
67208 index 0d4a127..33a06c7 100644
67209 --- a/lib/bitmap.c
67210 +++ b/lib/bitmap.c
67211 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
67212 {
67213 int c, old_c, totaldigits, ndigits, nchunks, nbits;
67214 u32 chunk;
67215 - const char __user __force *ubuf = (const char __user __force *)buf;
67216 + const char __user *ubuf = (const char __force_user *)buf;
67217
67218 bitmap_zero(maskp, nmaskbits);
67219
67220 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
67221 {
67222 if (!access_ok(VERIFY_READ, ubuf, ulen))
67223 return -EFAULT;
67224 - return __bitmap_parse((const char __force *)ubuf,
67225 + return __bitmap_parse((const char __force_kernel *)ubuf,
67226 ulen, 1, maskp, nmaskbits);
67227
67228 }
67229 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
67230 {
67231 unsigned a, b;
67232 int c, old_c, totaldigits;
67233 - const char __user __force *ubuf = (const char __user __force *)buf;
67234 + const char __user *ubuf = (const char __force_user *)buf;
67235 int exp_digit, in_range;
67236
67237 totaldigits = c = 0;
67238 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
67239 {
67240 if (!access_ok(VERIFY_READ, ubuf, ulen))
67241 return -EFAULT;
67242 - return __bitmap_parselist((const char __force *)ubuf,
67243 + return __bitmap_parselist((const char __force_kernel *)ubuf,
67244 ulen, 1, maskp, nmaskbits);
67245 }
67246 EXPORT_SYMBOL(bitmap_parselist_user);
67247 diff --git a/lib/bug.c b/lib/bug.c
67248 index 1955209..cbbb2ad 100644
67249 --- a/lib/bug.c
67250 +++ b/lib/bug.c
67251 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
67252 return BUG_TRAP_TYPE_NONE;
67253
67254 bug = find_bug(bugaddr);
67255 + if (!bug)
67256 + return BUG_TRAP_TYPE_NONE;
67257
67258 file = NULL;
67259 line = 0;
67260 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
67261 index a78b7c6..2c73084 100644
67262 --- a/lib/debugobjects.c
67263 +++ b/lib/debugobjects.c
67264 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
67265 if (limit > 4)
67266 return;
67267
67268 - is_on_stack = object_is_on_stack(addr);
67269 + is_on_stack = object_starts_on_stack(addr);
67270 if (is_on_stack == onstack)
67271 return;
67272
67273 diff --git a/lib/devres.c b/lib/devres.c
67274 index 7c0e953..f642b5c 100644
67275 --- a/lib/devres.c
67276 +++ b/lib/devres.c
67277 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
67278 void devm_iounmap(struct device *dev, void __iomem *addr)
67279 {
67280 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
67281 - (void *)addr));
67282 + (void __force *)addr));
67283 iounmap(addr);
67284 }
67285 EXPORT_SYMBOL(devm_iounmap);
67286 @@ -141,7 +141,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
67287 {
67288 ioport_unmap(addr);
67289 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
67290 - devm_ioport_map_match, (void *)addr));
67291 + devm_ioport_map_match, (void __force *)addr));
67292 }
67293 EXPORT_SYMBOL(devm_ioport_unmap);
67294
67295 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
67296 index fea790a..ebb0e82 100644
67297 --- a/lib/dma-debug.c
67298 +++ b/lib/dma-debug.c
67299 @@ -925,7 +925,7 @@ out:
67300
67301 static void check_for_stack(struct device *dev, void *addr)
67302 {
67303 - if (object_is_on_stack(addr))
67304 + if (object_starts_on_stack(addr))
67305 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
67306 "stack [addr=%p]\n", addr);
67307 }
67308 diff --git a/lib/extable.c b/lib/extable.c
67309 index 4cac81e..63e9b8f 100644
67310 --- a/lib/extable.c
67311 +++ b/lib/extable.c
67312 @@ -13,6 +13,7 @@
67313 #include <linux/init.h>
67314 #include <linux/sort.h>
67315 #include <asm/uaccess.h>
67316 +#include <asm/pgtable.h>
67317
67318 #ifndef ARCH_HAS_SORT_EXTABLE
67319 /*
67320 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
67321 void sort_extable(struct exception_table_entry *start,
67322 struct exception_table_entry *finish)
67323 {
67324 + pax_open_kernel();
67325 sort(start, finish - start, sizeof(struct exception_table_entry),
67326 cmp_ex, NULL);
67327 + pax_close_kernel();
67328 }
67329
67330 #ifdef CONFIG_MODULES
67331 diff --git a/lib/inflate.c b/lib/inflate.c
67332 index 013a761..c28f3fc 100644
67333 --- a/lib/inflate.c
67334 +++ b/lib/inflate.c
67335 @@ -269,7 +269,7 @@ static void free(void *where)
67336 malloc_ptr = free_mem_ptr;
67337 }
67338 #else
67339 -#define malloc(a) kmalloc(a, GFP_KERNEL)
67340 +#define malloc(a) kmalloc((a), GFP_KERNEL)
67341 #define free(a) kfree(a)
67342 #endif
67343
67344 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
67345 index bd2bea9..6b3c95e 100644
67346 --- a/lib/is_single_threaded.c
67347 +++ b/lib/is_single_threaded.c
67348 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
67349 struct task_struct *p, *t;
67350 bool ret;
67351
67352 + if (!mm)
67353 + return true;
67354 +
67355 if (atomic_read(&task->signal->live) != 1)
67356 return false;
67357
67358 diff --git a/lib/kref.c b/lib/kref.c
67359 index 3efb882..8492f4c 100644
67360 --- a/lib/kref.c
67361 +++ b/lib/kref.c
67362 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
67363 */
67364 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
67365 {
67366 - WARN_ON(release == NULL);
67367 + BUG_ON(release == NULL);
67368 WARN_ON(release == (void (*)(struct kref *))kfree);
67369
67370 if (atomic_dec_and_test(&kref->refcount)) {
67371 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
67372 index d9df745..e73c2fe 100644
67373 --- a/lib/radix-tree.c
67374 +++ b/lib/radix-tree.c
67375 @@ -80,7 +80,7 @@ struct radix_tree_preload {
67376 int nr;
67377 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
67378 };
67379 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
67380 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
67381
67382 static inline void *ptr_to_indirect(void *ptr)
67383 {
67384 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
67385 index 993599e..84dc70e 100644
67386 --- a/lib/vsprintf.c
67387 +++ b/lib/vsprintf.c
67388 @@ -16,6 +16,9 @@
67389 * - scnprintf and vscnprintf
67390 */
67391
67392 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67393 +#define __INCLUDED_BY_HIDESYM 1
67394 +#endif
67395 #include <stdarg.h>
67396 #include <linux/module.h>
67397 #include <linux/types.h>
67398 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
67399 char sym[KSYM_SYMBOL_LEN];
67400 if (ext == 'B')
67401 sprint_backtrace(sym, value);
67402 - else if (ext != 'f' && ext != 's')
67403 + else if (ext != 'f' && ext != 's' && ext != 'a')
67404 sprint_symbol(sym, value);
67405 else
67406 kallsyms_lookup(value, NULL, NULL, NULL, sym);
67407 @@ -777,7 +780,11 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
67408 return string(buf, end, uuid, spec);
67409 }
67410
67411 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67412 +int kptr_restrict __read_mostly = 2;
67413 +#else
67414 int kptr_restrict __read_mostly;
67415 +#endif
67416
67417 /*
67418 * Show a '%p' thing. A kernel extension is that the '%p' is followed
67419 @@ -791,6 +798,8 @@ int kptr_restrict __read_mostly;
67420 * - 'S' For symbolic direct pointers with offset
67421 * - 's' For symbolic direct pointers without offset
67422 * - 'B' For backtraced symbolic direct pointers with offset
67423 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
67424 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
67425 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
67426 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
67427 * - 'M' For a 6-byte MAC address, it prints the address in the
67428 @@ -835,12 +844,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
67429 {
67430 if (!ptr && *fmt != 'K') {
67431 /*
67432 - * Print (null) with the same width as a pointer so it makes
67433 + * Print (nil) with the same width as a pointer so it makes
67434 * tabular output look nice.
67435 */
67436 if (spec.field_width == -1)
67437 spec.field_width = 2 * sizeof(void *);
67438 - return string(buf, end, "(null)", spec);
67439 + return string(buf, end, "(nil)", spec);
67440 }
67441
67442 switch (*fmt) {
67443 @@ -850,6 +859,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
67444 /* Fallthrough */
67445 case 'S':
67446 case 's':
67447 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67448 + break;
67449 +#else
67450 + return symbol_string(buf, end, ptr, spec, *fmt);
67451 +#endif
67452 + case 'A':
67453 + case 'a':
67454 case 'B':
67455 return symbol_string(buf, end, ptr, spec, *fmt);
67456 case 'R':
67457 @@ -1608,11 +1624,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
67458 typeof(type) value; \
67459 if (sizeof(type) == 8) { \
67460 args = PTR_ALIGN(args, sizeof(u32)); \
67461 - *(u32 *)&value = *(u32 *)args; \
67462 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
67463 + *(u32 *)&value = *(const u32 *)args; \
67464 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
67465 } else { \
67466 args = PTR_ALIGN(args, sizeof(type)); \
67467 - value = *(typeof(type) *)args; \
67468 + value = *(const typeof(type) *)args; \
67469 } \
67470 args += sizeof(type); \
67471 value; \
67472 @@ -1675,7 +1691,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
67473 case FORMAT_TYPE_STR: {
67474 const char *str_arg = args;
67475 args += strlen(str_arg) + 1;
67476 - str = string(str, end, (char *)str_arg, spec);
67477 + str = string(str, end, str_arg, spec);
67478 break;
67479 }
67480
67481 diff --git a/localversion-grsec b/localversion-grsec
67482 new file mode 100644
67483 index 0000000..7cd6065
67484 --- /dev/null
67485 +++ b/localversion-grsec
67486 @@ -0,0 +1 @@
67487 +-grsec
67488 diff --git a/mm/Kconfig b/mm/Kconfig
67489 index 011b110..b492af2 100644
67490 --- a/mm/Kconfig
67491 +++ b/mm/Kconfig
67492 @@ -241,10 +241,10 @@ config KSM
67493 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
67494
67495 config DEFAULT_MMAP_MIN_ADDR
67496 - int "Low address space to protect from user allocation"
67497 + int "Low address space to protect from user allocation"
67498 depends on MMU
67499 - default 4096
67500 - help
67501 + default 65536
67502 + help
67503 This is the portion of low virtual memory which should be protected
67504 from userspace allocation. Keeping a user from writing to low pages
67505 can help reduce the impact of kernel NULL pointer bugs.
67506 diff --git a/mm/filemap.c b/mm/filemap.c
67507 index 5f0a3c9..4f87f0c 100644
67508 --- a/mm/filemap.c
67509 +++ b/mm/filemap.c
67510 @@ -1784,7 +1784,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
67511 struct address_space *mapping = file->f_mapping;
67512
67513 if (!mapping->a_ops->readpage)
67514 - return -ENOEXEC;
67515 + return -ENODEV;
67516 file_accessed(file);
67517 vma->vm_ops = &generic_file_vm_ops;
67518 vma->vm_flags |= VM_CAN_NONLINEAR;
67519 @@ -2190,6 +2190,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
67520 *pos = i_size_read(inode);
67521
67522 if (limit != RLIM_INFINITY) {
67523 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
67524 if (*pos >= limit) {
67525 send_sig(SIGXFSZ, current, 0);
67526 return -EFBIG;
67527 diff --git a/mm/fremap.c b/mm/fremap.c
67528 index 9ed4fd4..c42648d 100644
67529 --- a/mm/fremap.c
67530 +++ b/mm/fremap.c
67531 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
67532 retry:
67533 vma = find_vma(mm, start);
67534
67535 +#ifdef CONFIG_PAX_SEGMEXEC
67536 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
67537 + goto out;
67538 +#endif
67539 +
67540 /*
67541 * Make sure the vma is shared, that it supports prefaulting,
67542 * and that the remapped range is valid and fully within
67543 diff --git a/mm/highmem.c b/mm/highmem.c
67544 index 57d82c6..e9e0552 100644
67545 --- a/mm/highmem.c
67546 +++ b/mm/highmem.c
67547 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
67548 * So no dangers, even with speculative execution.
67549 */
67550 page = pte_page(pkmap_page_table[i]);
67551 + pax_open_kernel();
67552 pte_clear(&init_mm, (unsigned long)page_address(page),
67553 &pkmap_page_table[i]);
67554 -
67555 + pax_close_kernel();
67556 set_page_address(page, NULL);
67557 need_flush = 1;
67558 }
67559 @@ -186,9 +187,11 @@ start:
67560 }
67561 }
67562 vaddr = PKMAP_ADDR(last_pkmap_nr);
67563 +
67564 + pax_open_kernel();
67565 set_pte_at(&init_mm, vaddr,
67566 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
67567 -
67568 + pax_close_kernel();
67569 pkmap_count[last_pkmap_nr] = 1;
67570 set_page_address(page, (void *)vaddr);
67571
67572 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
67573 index 36b3d98..584cb54 100644
67574 --- a/mm/huge_memory.c
67575 +++ b/mm/huge_memory.c
67576 @@ -703,7 +703,7 @@ out:
67577 * run pte_offset_map on the pmd, if an huge pmd could
67578 * materialize from under us from a different thread.
67579 */
67580 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
67581 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
67582 return VM_FAULT_OOM;
67583 /* if an huge pmd materialized from under us just retry later */
67584 if (unlikely(pmd_trans_huge(*pmd)))
67585 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
67586 index 2316840..b418671 100644
67587 --- a/mm/hugetlb.c
67588 +++ b/mm/hugetlb.c
67589 @@ -2347,6 +2347,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
67590 return 1;
67591 }
67592
67593 +#ifdef CONFIG_PAX_SEGMEXEC
67594 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
67595 +{
67596 + struct mm_struct *mm = vma->vm_mm;
67597 + struct vm_area_struct *vma_m;
67598 + unsigned long address_m;
67599 + pte_t *ptep_m;
67600 +
67601 + vma_m = pax_find_mirror_vma(vma);
67602 + if (!vma_m)
67603 + return;
67604 +
67605 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
67606 + address_m = address + SEGMEXEC_TASK_SIZE;
67607 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
67608 + get_page(page_m);
67609 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
67610 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
67611 +}
67612 +#endif
67613 +
67614 /*
67615 * Hugetlb_cow() should be called with page lock of the original hugepage held.
67616 */
67617 @@ -2450,6 +2471,11 @@ retry_avoidcopy:
67618 make_huge_pte(vma, new_page, 1));
67619 page_remove_rmap(old_page);
67620 hugepage_add_new_anon_rmap(new_page, vma, address);
67621 +
67622 +#ifdef CONFIG_PAX_SEGMEXEC
67623 + pax_mirror_huge_pte(vma, address, new_page);
67624 +#endif
67625 +
67626 /* Make the old page be freed below */
67627 new_page = old_page;
67628 mmu_notifier_invalidate_range_end(mm,
67629 @@ -2601,6 +2627,10 @@ retry:
67630 && (vma->vm_flags & VM_SHARED)));
67631 set_huge_pte_at(mm, address, ptep, new_pte);
67632
67633 +#ifdef CONFIG_PAX_SEGMEXEC
67634 + pax_mirror_huge_pte(vma, address, page);
67635 +#endif
67636 +
67637 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
67638 /* Optimization, do the COW without a second fault */
67639 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
67640 @@ -2630,6 +2660,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
67641 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
67642 struct hstate *h = hstate_vma(vma);
67643
67644 +#ifdef CONFIG_PAX_SEGMEXEC
67645 + struct vm_area_struct *vma_m;
67646 +#endif
67647 +
67648 ptep = huge_pte_offset(mm, address);
67649 if (ptep) {
67650 entry = huge_ptep_get(ptep);
67651 @@ -2641,6 +2675,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
67652 VM_FAULT_SET_HINDEX(h - hstates);
67653 }
67654
67655 +#ifdef CONFIG_PAX_SEGMEXEC
67656 + vma_m = pax_find_mirror_vma(vma);
67657 + if (vma_m) {
67658 + unsigned long address_m;
67659 +
67660 + if (vma->vm_start > vma_m->vm_start) {
67661 + address_m = address;
67662 + address -= SEGMEXEC_TASK_SIZE;
67663 + vma = vma_m;
67664 + h = hstate_vma(vma);
67665 + } else
67666 + address_m = address + SEGMEXEC_TASK_SIZE;
67667 +
67668 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
67669 + return VM_FAULT_OOM;
67670 + address_m &= HPAGE_MASK;
67671 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
67672 + }
67673 +#endif
67674 +
67675 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
67676 if (!ptep)
67677 return VM_FAULT_OOM;
67678 diff --git a/mm/internal.h b/mm/internal.h
67679 index 2189af4..f2ca332 100644
67680 --- a/mm/internal.h
67681 +++ b/mm/internal.h
67682 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
67683 * in mm/page_alloc.c
67684 */
67685 extern void __free_pages_bootmem(struct page *page, unsigned int order);
67686 +extern void free_compound_page(struct page *page);
67687 extern void prep_compound_page(struct page *page, unsigned long order);
67688 #ifdef CONFIG_MEMORY_FAILURE
67689 extern bool is_free_buddy_page(struct page *page);
67690 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
67691 index f3b2a00..61da94d 100644
67692 --- a/mm/kmemleak.c
67693 +++ b/mm/kmemleak.c
67694 @@ -357,7 +357,7 @@ static void print_unreferenced(struct seq_file *seq,
67695
67696 for (i = 0; i < object->trace_len; i++) {
67697 void *ptr = (void *)object->trace[i];
67698 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
67699 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
67700 }
67701 }
67702
67703 diff --git a/mm/maccess.c b/mm/maccess.c
67704 index d53adf9..03a24bf 100644
67705 --- a/mm/maccess.c
67706 +++ b/mm/maccess.c
67707 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
67708 set_fs(KERNEL_DS);
67709 pagefault_disable();
67710 ret = __copy_from_user_inatomic(dst,
67711 - (__force const void __user *)src, size);
67712 + (const void __force_user *)src, size);
67713 pagefault_enable();
67714 set_fs(old_fs);
67715
67716 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
67717
67718 set_fs(KERNEL_DS);
67719 pagefault_disable();
67720 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
67721 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
67722 pagefault_enable();
67723 set_fs(old_fs);
67724
67725 diff --git a/mm/madvise.c b/mm/madvise.c
67726 index 74bf193..feb6fd3 100644
67727 --- a/mm/madvise.c
67728 +++ b/mm/madvise.c
67729 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
67730 pgoff_t pgoff;
67731 unsigned long new_flags = vma->vm_flags;
67732
67733 +#ifdef CONFIG_PAX_SEGMEXEC
67734 + struct vm_area_struct *vma_m;
67735 +#endif
67736 +
67737 switch (behavior) {
67738 case MADV_NORMAL:
67739 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
67740 @@ -110,6 +114,13 @@ success:
67741 /*
67742 * vm_flags is protected by the mmap_sem held in write mode.
67743 */
67744 +
67745 +#ifdef CONFIG_PAX_SEGMEXEC
67746 + vma_m = pax_find_mirror_vma(vma);
67747 + if (vma_m)
67748 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
67749 +#endif
67750 +
67751 vma->vm_flags = new_flags;
67752
67753 out:
67754 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
67755 struct vm_area_struct ** prev,
67756 unsigned long start, unsigned long end)
67757 {
67758 +
67759 +#ifdef CONFIG_PAX_SEGMEXEC
67760 + struct vm_area_struct *vma_m;
67761 +#endif
67762 +
67763 *prev = vma;
67764 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
67765 return -EINVAL;
67766 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
67767 zap_page_range(vma, start, end - start, &details);
67768 } else
67769 zap_page_range(vma, start, end - start, NULL);
67770 +
67771 +#ifdef CONFIG_PAX_SEGMEXEC
67772 + vma_m = pax_find_mirror_vma(vma);
67773 + if (vma_m) {
67774 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
67775 + struct zap_details details = {
67776 + .nonlinear_vma = vma_m,
67777 + .last_index = ULONG_MAX,
67778 + };
67779 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
67780 + } else
67781 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
67782 + }
67783 +#endif
67784 +
67785 return 0;
67786 }
67787
67788 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
67789 if (end < start)
67790 goto out;
67791
67792 +#ifdef CONFIG_PAX_SEGMEXEC
67793 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
67794 + if (end > SEGMEXEC_TASK_SIZE)
67795 + goto out;
67796 + } else
67797 +#endif
67798 +
67799 + if (end > TASK_SIZE)
67800 + goto out;
67801 +
67802 error = 0;
67803 if (end == start)
67804 goto out;
67805 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
67806 index 06d3479..0778eef 100644
67807 --- a/mm/memory-failure.c
67808 +++ b/mm/memory-failure.c
67809 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
67810
67811 int sysctl_memory_failure_recovery __read_mostly = 1;
67812
67813 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
67814 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
67815
67816 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
67817
67818 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
67819 si.si_signo = SIGBUS;
67820 si.si_errno = 0;
67821 si.si_code = BUS_MCEERR_AO;
67822 - si.si_addr = (void *)addr;
67823 + si.si_addr = (void __user *)addr;
67824 #ifdef __ARCH_SI_TRAPNO
67825 si.si_trapno = trapno;
67826 #endif
67827 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
67828 }
67829
67830 nr_pages = 1 << compound_trans_order(hpage);
67831 - atomic_long_add(nr_pages, &mce_bad_pages);
67832 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
67833
67834 /*
67835 * We need/can do nothing about count=0 pages.
67836 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
67837 if (!PageHWPoison(hpage)
67838 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
67839 || (p != hpage && TestSetPageHWPoison(hpage))) {
67840 - atomic_long_sub(nr_pages, &mce_bad_pages);
67841 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
67842 return 0;
67843 }
67844 set_page_hwpoison_huge_page(hpage);
67845 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
67846 }
67847 if (hwpoison_filter(p)) {
67848 if (TestClearPageHWPoison(p))
67849 - atomic_long_sub(nr_pages, &mce_bad_pages);
67850 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
67851 unlock_page(hpage);
67852 put_page(hpage);
67853 return 0;
67854 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
67855 return 0;
67856 }
67857 if (TestClearPageHWPoison(p))
67858 - atomic_long_sub(nr_pages, &mce_bad_pages);
67859 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
67860 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
67861 return 0;
67862 }
67863 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
67864 */
67865 if (TestClearPageHWPoison(page)) {
67866 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
67867 - atomic_long_sub(nr_pages, &mce_bad_pages);
67868 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
67869 freeit = 1;
67870 if (PageHuge(page))
67871 clear_page_hwpoison_huge_page(page);
67872 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
67873 }
67874 done:
67875 if (!PageHWPoison(hpage))
67876 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
67877 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
67878 set_page_hwpoison_huge_page(hpage);
67879 dequeue_hwpoisoned_huge_page(hpage);
67880 /* keep elevated page count for bad page */
67881 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
67882 return ret;
67883
67884 done:
67885 - atomic_long_add(1, &mce_bad_pages);
67886 + atomic_long_add_unchecked(1, &mce_bad_pages);
67887 SetPageHWPoison(page);
67888 /* keep elevated page count for bad page */
67889 return ret;
67890 diff --git a/mm/memory.c b/mm/memory.c
67891 index 829d437..3d3926a 100644
67892 --- a/mm/memory.c
67893 +++ b/mm/memory.c
67894 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
67895 return;
67896
67897 pmd = pmd_offset(pud, start);
67898 +
67899 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
67900 pud_clear(pud);
67901 pmd_free_tlb(tlb, pmd, start);
67902 +#endif
67903 +
67904 }
67905
67906 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
67907 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
67908 if (end - 1 > ceiling - 1)
67909 return;
67910
67911 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
67912 pud = pud_offset(pgd, start);
67913 pgd_clear(pgd);
67914 pud_free_tlb(tlb, pud, start);
67915 +#endif
67916 +
67917 }
67918
67919 /*
67920 @@ -1566,12 +1573,6 @@ no_page_table:
67921 return page;
67922 }
67923
67924 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
67925 -{
67926 - return stack_guard_page_start(vma, addr) ||
67927 - stack_guard_page_end(vma, addr+PAGE_SIZE);
67928 -}
67929 -
67930 /**
67931 * __get_user_pages() - pin user pages in memory
67932 * @tsk: task_struct of target task
67933 @@ -1644,10 +1645,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
67934 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
67935 i = 0;
67936
67937 - do {
67938 + while (nr_pages) {
67939 struct vm_area_struct *vma;
67940
67941 - vma = find_extend_vma(mm, start);
67942 + vma = find_vma(mm, start);
67943 if (!vma && in_gate_area(mm, start)) {
67944 unsigned long pg = start & PAGE_MASK;
67945 pgd_t *pgd;
67946 @@ -1695,7 +1696,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
67947 goto next_page;
67948 }
67949
67950 - if (!vma ||
67951 + if (!vma || start < vma->vm_start ||
67952 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
67953 !(vm_flags & vma->vm_flags))
67954 return i ? : -EFAULT;
67955 @@ -1722,11 +1723,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
67956 int ret;
67957 unsigned int fault_flags = 0;
67958
67959 - /* For mlock, just skip the stack guard page. */
67960 - if (foll_flags & FOLL_MLOCK) {
67961 - if (stack_guard_page(vma, start))
67962 - goto next_page;
67963 - }
67964 if (foll_flags & FOLL_WRITE)
67965 fault_flags |= FAULT_FLAG_WRITE;
67966 if (nonblocking)
67967 @@ -1800,7 +1796,7 @@ next_page:
67968 start += PAGE_SIZE;
67969 nr_pages--;
67970 } while (nr_pages && start < vma->vm_end);
67971 - } while (nr_pages);
67972 + }
67973 return i;
67974 }
67975 EXPORT_SYMBOL(__get_user_pages);
67976 @@ -2007,6 +2003,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
67977 page_add_file_rmap(page);
67978 set_pte_at(mm, addr, pte, mk_pte(page, prot));
67979
67980 +#ifdef CONFIG_PAX_SEGMEXEC
67981 + pax_mirror_file_pte(vma, addr, page, ptl);
67982 +#endif
67983 +
67984 retval = 0;
67985 pte_unmap_unlock(pte, ptl);
67986 return retval;
67987 @@ -2041,10 +2041,22 @@ out:
67988 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
67989 struct page *page)
67990 {
67991 +
67992 +#ifdef CONFIG_PAX_SEGMEXEC
67993 + struct vm_area_struct *vma_m;
67994 +#endif
67995 +
67996 if (addr < vma->vm_start || addr >= vma->vm_end)
67997 return -EFAULT;
67998 if (!page_count(page))
67999 return -EINVAL;
68000 +
68001 +#ifdef CONFIG_PAX_SEGMEXEC
68002 + vma_m = pax_find_mirror_vma(vma);
68003 + if (vma_m)
68004 + vma_m->vm_flags |= VM_INSERTPAGE;
68005 +#endif
68006 +
68007 vma->vm_flags |= VM_INSERTPAGE;
68008 return insert_page(vma, addr, page, vma->vm_page_prot);
68009 }
68010 @@ -2130,6 +2142,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
68011 unsigned long pfn)
68012 {
68013 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
68014 + BUG_ON(vma->vm_mirror);
68015
68016 if (addr < vma->vm_start || addr >= vma->vm_end)
68017 return -EFAULT;
68018 @@ -2445,6 +2458,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
68019 copy_user_highpage(dst, src, va, vma);
68020 }
68021
68022 +#ifdef CONFIG_PAX_SEGMEXEC
68023 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
68024 +{
68025 + struct mm_struct *mm = vma->vm_mm;
68026 + spinlock_t *ptl;
68027 + pte_t *pte, entry;
68028 +
68029 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
68030 + entry = *pte;
68031 + if (!pte_present(entry)) {
68032 + if (!pte_none(entry)) {
68033 + BUG_ON(pte_file(entry));
68034 + free_swap_and_cache(pte_to_swp_entry(entry));
68035 + pte_clear_not_present_full(mm, address, pte, 0);
68036 + }
68037 + } else {
68038 + struct page *page;
68039 +
68040 + flush_cache_page(vma, address, pte_pfn(entry));
68041 + entry = ptep_clear_flush(vma, address, pte);
68042 + BUG_ON(pte_dirty(entry));
68043 + page = vm_normal_page(vma, address, entry);
68044 + if (page) {
68045 + update_hiwater_rss(mm);
68046 + if (PageAnon(page))
68047 + dec_mm_counter_fast(mm, MM_ANONPAGES);
68048 + else
68049 + dec_mm_counter_fast(mm, MM_FILEPAGES);
68050 + page_remove_rmap(page);
68051 + page_cache_release(page);
68052 + }
68053 + }
68054 + pte_unmap_unlock(pte, ptl);
68055 +}
68056 +
68057 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
68058 + *
68059 + * the ptl of the lower mapped page is held on entry and is not released on exit
68060 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
68061 + */
68062 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
68063 +{
68064 + struct mm_struct *mm = vma->vm_mm;
68065 + unsigned long address_m;
68066 + spinlock_t *ptl_m;
68067 + struct vm_area_struct *vma_m;
68068 + pmd_t *pmd_m;
68069 + pte_t *pte_m, entry_m;
68070 +
68071 + BUG_ON(!page_m || !PageAnon(page_m));
68072 +
68073 + vma_m = pax_find_mirror_vma(vma);
68074 + if (!vma_m)
68075 + return;
68076 +
68077 + BUG_ON(!PageLocked(page_m));
68078 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68079 + address_m = address + SEGMEXEC_TASK_SIZE;
68080 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68081 + pte_m = pte_offset_map(pmd_m, address_m);
68082 + ptl_m = pte_lockptr(mm, pmd_m);
68083 + if (ptl != ptl_m) {
68084 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68085 + if (!pte_none(*pte_m))
68086 + goto out;
68087 + }
68088 +
68089 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
68090 + page_cache_get(page_m);
68091 + page_add_anon_rmap(page_m, vma_m, address_m);
68092 + inc_mm_counter_fast(mm, MM_ANONPAGES);
68093 + set_pte_at(mm, address_m, pte_m, entry_m);
68094 + update_mmu_cache(vma_m, address_m, entry_m);
68095 +out:
68096 + if (ptl != ptl_m)
68097 + spin_unlock(ptl_m);
68098 + pte_unmap(pte_m);
68099 + unlock_page(page_m);
68100 +}
68101 +
68102 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
68103 +{
68104 + struct mm_struct *mm = vma->vm_mm;
68105 + unsigned long address_m;
68106 + spinlock_t *ptl_m;
68107 + struct vm_area_struct *vma_m;
68108 + pmd_t *pmd_m;
68109 + pte_t *pte_m, entry_m;
68110 +
68111 + BUG_ON(!page_m || PageAnon(page_m));
68112 +
68113 + vma_m = pax_find_mirror_vma(vma);
68114 + if (!vma_m)
68115 + return;
68116 +
68117 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68118 + address_m = address + SEGMEXEC_TASK_SIZE;
68119 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68120 + pte_m = pte_offset_map(pmd_m, address_m);
68121 + ptl_m = pte_lockptr(mm, pmd_m);
68122 + if (ptl != ptl_m) {
68123 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68124 + if (!pte_none(*pte_m))
68125 + goto out;
68126 + }
68127 +
68128 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
68129 + page_cache_get(page_m);
68130 + page_add_file_rmap(page_m);
68131 + inc_mm_counter_fast(mm, MM_FILEPAGES);
68132 + set_pte_at(mm, address_m, pte_m, entry_m);
68133 + update_mmu_cache(vma_m, address_m, entry_m);
68134 +out:
68135 + if (ptl != ptl_m)
68136 + spin_unlock(ptl_m);
68137 + pte_unmap(pte_m);
68138 +}
68139 +
68140 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
68141 +{
68142 + struct mm_struct *mm = vma->vm_mm;
68143 + unsigned long address_m;
68144 + spinlock_t *ptl_m;
68145 + struct vm_area_struct *vma_m;
68146 + pmd_t *pmd_m;
68147 + pte_t *pte_m, entry_m;
68148 +
68149 + vma_m = pax_find_mirror_vma(vma);
68150 + if (!vma_m)
68151 + return;
68152 +
68153 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68154 + address_m = address + SEGMEXEC_TASK_SIZE;
68155 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68156 + pte_m = pte_offset_map(pmd_m, address_m);
68157 + ptl_m = pte_lockptr(mm, pmd_m);
68158 + if (ptl != ptl_m) {
68159 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68160 + if (!pte_none(*pte_m))
68161 + goto out;
68162 + }
68163 +
68164 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
68165 + set_pte_at(mm, address_m, pte_m, entry_m);
68166 +out:
68167 + if (ptl != ptl_m)
68168 + spin_unlock(ptl_m);
68169 + pte_unmap(pte_m);
68170 +}
68171 +
68172 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
68173 +{
68174 + struct page *page_m;
68175 + pte_t entry;
68176 +
68177 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
68178 + goto out;
68179 +
68180 + entry = *pte;
68181 + page_m = vm_normal_page(vma, address, entry);
68182 + if (!page_m)
68183 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
68184 + else if (PageAnon(page_m)) {
68185 + if (pax_find_mirror_vma(vma)) {
68186 + pte_unmap_unlock(pte, ptl);
68187 + lock_page(page_m);
68188 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
68189 + if (pte_same(entry, *pte))
68190 + pax_mirror_anon_pte(vma, address, page_m, ptl);
68191 + else
68192 + unlock_page(page_m);
68193 + }
68194 + } else
68195 + pax_mirror_file_pte(vma, address, page_m, ptl);
68196 +
68197 +out:
68198 + pte_unmap_unlock(pte, ptl);
68199 +}
68200 +#endif
68201 +
68202 /*
68203 * This routine handles present pages, when users try to write
68204 * to a shared page. It is done by copying the page to a new address
68205 @@ -2656,6 +2849,12 @@ gotten:
68206 */
68207 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
68208 if (likely(pte_same(*page_table, orig_pte))) {
68209 +
68210 +#ifdef CONFIG_PAX_SEGMEXEC
68211 + if (pax_find_mirror_vma(vma))
68212 + BUG_ON(!trylock_page(new_page));
68213 +#endif
68214 +
68215 if (old_page) {
68216 if (!PageAnon(old_page)) {
68217 dec_mm_counter_fast(mm, MM_FILEPAGES);
68218 @@ -2707,6 +2906,10 @@ gotten:
68219 page_remove_rmap(old_page);
68220 }
68221
68222 +#ifdef CONFIG_PAX_SEGMEXEC
68223 + pax_mirror_anon_pte(vma, address, new_page, ptl);
68224 +#endif
68225 +
68226 /* Free the old page.. */
68227 new_page = old_page;
68228 ret |= VM_FAULT_WRITE;
68229 @@ -2986,6 +3189,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
68230 swap_free(entry);
68231 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
68232 try_to_free_swap(page);
68233 +
68234 +#ifdef CONFIG_PAX_SEGMEXEC
68235 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
68236 +#endif
68237 +
68238 unlock_page(page);
68239 if (swapcache) {
68240 /*
68241 @@ -3009,6 +3217,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
68242
68243 /* No need to invalidate - it was non-present before */
68244 update_mmu_cache(vma, address, page_table);
68245 +
68246 +#ifdef CONFIG_PAX_SEGMEXEC
68247 + pax_mirror_anon_pte(vma, address, page, ptl);
68248 +#endif
68249 +
68250 unlock:
68251 pte_unmap_unlock(page_table, ptl);
68252 out:
68253 @@ -3028,40 +3241,6 @@ out_release:
68254 }
68255
68256 /*
68257 - * This is like a special single-page "expand_{down|up}wards()",
68258 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
68259 - * doesn't hit another vma.
68260 - */
68261 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
68262 -{
68263 - address &= PAGE_MASK;
68264 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
68265 - struct vm_area_struct *prev = vma->vm_prev;
68266 -
68267 - /*
68268 - * Is there a mapping abutting this one below?
68269 - *
68270 - * That's only ok if it's the same stack mapping
68271 - * that has gotten split..
68272 - */
68273 - if (prev && prev->vm_end == address)
68274 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
68275 -
68276 - expand_downwards(vma, address - PAGE_SIZE);
68277 - }
68278 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
68279 - struct vm_area_struct *next = vma->vm_next;
68280 -
68281 - /* As VM_GROWSDOWN but s/below/above/ */
68282 - if (next && next->vm_start == address + PAGE_SIZE)
68283 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
68284 -
68285 - expand_upwards(vma, address + PAGE_SIZE);
68286 - }
68287 - return 0;
68288 -}
68289 -
68290 -/*
68291 * We enter with non-exclusive mmap_sem (to exclude vma changes,
68292 * but allow concurrent faults), and pte mapped but not yet locked.
68293 * We return with mmap_sem still held, but pte unmapped and unlocked.
68294 @@ -3070,27 +3249,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
68295 unsigned long address, pte_t *page_table, pmd_t *pmd,
68296 unsigned int flags)
68297 {
68298 - struct page *page;
68299 + struct page *page = NULL;
68300 spinlock_t *ptl;
68301 pte_t entry;
68302
68303 - pte_unmap(page_table);
68304 -
68305 - /* Check if we need to add a guard page to the stack */
68306 - if (check_stack_guard_page(vma, address) < 0)
68307 - return VM_FAULT_SIGBUS;
68308 -
68309 - /* Use the zero-page for reads */
68310 if (!(flags & FAULT_FLAG_WRITE)) {
68311 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
68312 vma->vm_page_prot));
68313 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
68314 + ptl = pte_lockptr(mm, pmd);
68315 + spin_lock(ptl);
68316 if (!pte_none(*page_table))
68317 goto unlock;
68318 goto setpte;
68319 }
68320
68321 /* Allocate our own private page. */
68322 + pte_unmap(page_table);
68323 +
68324 if (unlikely(anon_vma_prepare(vma)))
68325 goto oom;
68326 page = alloc_zeroed_user_highpage_movable(vma, address);
68327 @@ -3109,6 +3284,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
68328 if (!pte_none(*page_table))
68329 goto release;
68330
68331 +#ifdef CONFIG_PAX_SEGMEXEC
68332 + if (pax_find_mirror_vma(vma))
68333 + BUG_ON(!trylock_page(page));
68334 +#endif
68335 +
68336 inc_mm_counter_fast(mm, MM_ANONPAGES);
68337 page_add_new_anon_rmap(page, vma, address);
68338 setpte:
68339 @@ -3116,6 +3296,12 @@ setpte:
68340
68341 /* No need to invalidate - it was non-present before */
68342 update_mmu_cache(vma, address, page_table);
68343 +
68344 +#ifdef CONFIG_PAX_SEGMEXEC
68345 + if (page)
68346 + pax_mirror_anon_pte(vma, address, page, ptl);
68347 +#endif
68348 +
68349 unlock:
68350 pte_unmap_unlock(page_table, ptl);
68351 return 0;
68352 @@ -3259,6 +3445,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68353 */
68354 /* Only go through if we didn't race with anybody else... */
68355 if (likely(pte_same(*page_table, orig_pte))) {
68356 +
68357 +#ifdef CONFIG_PAX_SEGMEXEC
68358 + if (anon && pax_find_mirror_vma(vma))
68359 + BUG_ON(!trylock_page(page));
68360 +#endif
68361 +
68362 flush_icache_page(vma, page);
68363 entry = mk_pte(page, vma->vm_page_prot);
68364 if (flags & FAULT_FLAG_WRITE)
68365 @@ -3278,6 +3470,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68366
68367 /* no need to invalidate: a not-present page won't be cached */
68368 update_mmu_cache(vma, address, page_table);
68369 +
68370 +#ifdef CONFIG_PAX_SEGMEXEC
68371 + if (anon)
68372 + pax_mirror_anon_pte(vma, address, page, ptl);
68373 + else
68374 + pax_mirror_file_pte(vma, address, page, ptl);
68375 +#endif
68376 +
68377 } else {
68378 if (cow_page)
68379 mem_cgroup_uncharge_page(cow_page);
68380 @@ -3431,6 +3631,12 @@ int handle_pte_fault(struct mm_struct *mm,
68381 if (flags & FAULT_FLAG_WRITE)
68382 flush_tlb_fix_spurious_fault(vma, address);
68383 }
68384 +
68385 +#ifdef CONFIG_PAX_SEGMEXEC
68386 + pax_mirror_pte(vma, address, pte, pmd, ptl);
68387 + return 0;
68388 +#endif
68389 +
68390 unlock:
68391 pte_unmap_unlock(pte, ptl);
68392 return 0;
68393 @@ -3447,6 +3653,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68394 pmd_t *pmd;
68395 pte_t *pte;
68396
68397 +#ifdef CONFIG_PAX_SEGMEXEC
68398 + struct vm_area_struct *vma_m;
68399 +#endif
68400 +
68401 __set_current_state(TASK_RUNNING);
68402
68403 count_vm_event(PGFAULT);
68404 @@ -3458,6 +3668,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68405 if (unlikely(is_vm_hugetlb_page(vma)))
68406 return hugetlb_fault(mm, vma, address, flags);
68407
68408 +#ifdef CONFIG_PAX_SEGMEXEC
68409 + vma_m = pax_find_mirror_vma(vma);
68410 + if (vma_m) {
68411 + unsigned long address_m;
68412 + pgd_t *pgd_m;
68413 + pud_t *pud_m;
68414 + pmd_t *pmd_m;
68415 +
68416 + if (vma->vm_start > vma_m->vm_start) {
68417 + address_m = address;
68418 + address -= SEGMEXEC_TASK_SIZE;
68419 + vma = vma_m;
68420 + } else
68421 + address_m = address + SEGMEXEC_TASK_SIZE;
68422 +
68423 + pgd_m = pgd_offset(mm, address_m);
68424 + pud_m = pud_alloc(mm, pgd_m, address_m);
68425 + if (!pud_m)
68426 + return VM_FAULT_OOM;
68427 + pmd_m = pmd_alloc(mm, pud_m, address_m);
68428 + if (!pmd_m)
68429 + return VM_FAULT_OOM;
68430 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
68431 + return VM_FAULT_OOM;
68432 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
68433 + }
68434 +#endif
68435 +
68436 pgd = pgd_offset(mm, address);
68437 pud = pud_alloc(mm, pgd, address);
68438 if (!pud)
68439 @@ -3487,7 +3725,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68440 * run pte_offset_map on the pmd, if an huge pmd could
68441 * materialize from under us from a different thread.
68442 */
68443 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
68444 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
68445 return VM_FAULT_OOM;
68446 /* if an huge pmd materialized from under us just retry later */
68447 if (unlikely(pmd_trans_huge(*pmd)))
68448 @@ -3591,7 +3829,7 @@ static int __init gate_vma_init(void)
68449 gate_vma.vm_start = FIXADDR_USER_START;
68450 gate_vma.vm_end = FIXADDR_USER_END;
68451 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
68452 - gate_vma.vm_page_prot = __P101;
68453 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
68454 /*
68455 * Make sure the vDSO gets into every core dump.
68456 * Dumping its contents makes post-mortem fully interpretable later
68457 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
68458 index c3fdbcb..2e8ef90 100644
68459 --- a/mm/mempolicy.c
68460 +++ b/mm/mempolicy.c
68461 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
68462 unsigned long vmstart;
68463 unsigned long vmend;
68464
68465 +#ifdef CONFIG_PAX_SEGMEXEC
68466 + struct vm_area_struct *vma_m;
68467 +#endif
68468 +
68469 vma = find_vma_prev(mm, start, &prev);
68470 if (!vma || vma->vm_start > start)
68471 return -EFAULT;
68472 @@ -678,6 +682,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
68473 err = policy_vma(vma, new_pol);
68474 if (err)
68475 goto out;
68476 +
68477 +#ifdef CONFIG_PAX_SEGMEXEC
68478 + vma_m = pax_find_mirror_vma(vma);
68479 + if (vma_m) {
68480 + err = policy_vma(vma_m, new_pol);
68481 + if (err)
68482 + goto out;
68483 + }
68484 +#endif
68485 +
68486 }
68487
68488 out:
68489 @@ -1111,6 +1125,17 @@ static long do_mbind(unsigned long start, unsigned long len,
68490
68491 if (end < start)
68492 return -EINVAL;
68493 +
68494 +#ifdef CONFIG_PAX_SEGMEXEC
68495 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
68496 + if (end > SEGMEXEC_TASK_SIZE)
68497 + return -EINVAL;
68498 + } else
68499 +#endif
68500 +
68501 + if (end > TASK_SIZE)
68502 + return -EINVAL;
68503 +
68504 if (end == start)
68505 return 0;
68506
68507 @@ -1329,6 +1354,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
68508 if (!mm)
68509 goto out;
68510
68511 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68512 + if (mm != current->mm &&
68513 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
68514 + err = -EPERM;
68515 + goto out;
68516 + }
68517 +#endif
68518 +
68519 /*
68520 * Check if this process has the right to modify the specified
68521 * process. The right exists if the process has administrative
68522 @@ -1338,8 +1371,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
68523 rcu_read_lock();
68524 tcred = __task_cred(task);
68525 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
68526 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
68527 - !capable(CAP_SYS_NICE)) {
68528 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
68529 rcu_read_unlock();
68530 err = -EPERM;
68531 goto out;
68532 diff --git a/mm/migrate.c b/mm/migrate.c
68533 index 177aca4..ab3a744 100644
68534 --- a/mm/migrate.c
68535 +++ b/mm/migrate.c
68536 @@ -1313,6 +1313,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
68537 if (!mm)
68538 return -EINVAL;
68539
68540 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68541 + if (mm != current->mm &&
68542 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
68543 + err = -EPERM;
68544 + goto out;
68545 + }
68546 +#endif
68547 +
68548 /*
68549 * Check if this process has the right to modify the specified
68550 * process. The right exists if the process has administrative
68551 @@ -1322,8 +1330,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
68552 rcu_read_lock();
68553 tcred = __task_cred(task);
68554 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
68555 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
68556 - !capable(CAP_SYS_NICE)) {
68557 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
68558 rcu_read_unlock();
68559 err = -EPERM;
68560 goto out;
68561 diff --git a/mm/mlock.c b/mm/mlock.c
68562 index 4f4f53b..9511904 100644
68563 --- a/mm/mlock.c
68564 +++ b/mm/mlock.c
68565 @@ -13,6 +13,7 @@
68566 #include <linux/pagemap.h>
68567 #include <linux/mempolicy.h>
68568 #include <linux/syscalls.h>
68569 +#include <linux/security.h>
68570 #include <linux/sched.h>
68571 #include <linux/export.h>
68572 #include <linux/rmap.h>
68573 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
68574 return -EINVAL;
68575 if (end == start)
68576 return 0;
68577 + if (end > TASK_SIZE)
68578 + return -EINVAL;
68579 +
68580 vma = find_vma_prev(current->mm, start, &prev);
68581 if (!vma || vma->vm_start > start)
68582 return -ENOMEM;
68583 @@ -395,6 +399,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
68584 for (nstart = start ; ; ) {
68585 vm_flags_t newflags;
68586
68587 +#ifdef CONFIG_PAX_SEGMEXEC
68588 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
68589 + break;
68590 +#endif
68591 +
68592 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
68593
68594 newflags = vma->vm_flags | VM_LOCKED;
68595 @@ -500,6 +509,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
68596 lock_limit >>= PAGE_SHIFT;
68597
68598 /* check against resource limits */
68599 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
68600 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
68601 error = do_mlock(start, len, 1);
68602 up_write(&current->mm->mmap_sem);
68603 @@ -523,17 +533,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
68604 static int do_mlockall(int flags)
68605 {
68606 struct vm_area_struct * vma, * prev = NULL;
68607 - unsigned int def_flags = 0;
68608
68609 if (flags & MCL_FUTURE)
68610 - def_flags = VM_LOCKED;
68611 - current->mm->def_flags = def_flags;
68612 + current->mm->def_flags |= VM_LOCKED;
68613 + else
68614 + current->mm->def_flags &= ~VM_LOCKED;
68615 if (flags == MCL_FUTURE)
68616 goto out;
68617
68618 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
68619 vm_flags_t newflags;
68620
68621 +#ifdef CONFIG_PAX_SEGMEXEC
68622 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
68623 + break;
68624 +#endif
68625 +
68626 + BUG_ON(vma->vm_end > TASK_SIZE);
68627 newflags = vma->vm_flags | VM_LOCKED;
68628 if (!(flags & MCL_CURRENT))
68629 newflags &= ~VM_LOCKED;
68630 @@ -566,6 +582,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
68631 lock_limit >>= PAGE_SHIFT;
68632
68633 ret = -ENOMEM;
68634 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
68635 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
68636 capable(CAP_IPC_LOCK))
68637 ret = do_mlockall(flags);
68638 diff --git a/mm/mmap.c b/mm/mmap.c
68639 index eae90af..51ca80b 100644
68640 --- a/mm/mmap.c
68641 +++ b/mm/mmap.c
68642 @@ -46,6 +46,16 @@
68643 #define arch_rebalance_pgtables(addr, len) (addr)
68644 #endif
68645
68646 +static inline void verify_mm_writelocked(struct mm_struct *mm)
68647 +{
68648 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
68649 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
68650 + up_read(&mm->mmap_sem);
68651 + BUG();
68652 + }
68653 +#endif
68654 +}
68655 +
68656 static void unmap_region(struct mm_struct *mm,
68657 struct vm_area_struct *vma, struct vm_area_struct *prev,
68658 unsigned long start, unsigned long end);
68659 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
68660 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
68661 *
68662 */
68663 -pgprot_t protection_map[16] = {
68664 +pgprot_t protection_map[16] __read_only = {
68665 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
68666 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
68667 };
68668
68669 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
68670 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
68671 {
68672 - return __pgprot(pgprot_val(protection_map[vm_flags &
68673 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
68674 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
68675 pgprot_val(arch_vm_get_page_prot(vm_flags)));
68676 +
68677 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68678 + if (!(__supported_pte_mask & _PAGE_NX) &&
68679 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
68680 + (vm_flags & (VM_READ | VM_WRITE)))
68681 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
68682 +#endif
68683 +
68684 + return prot;
68685 }
68686 EXPORT_SYMBOL(vm_get_page_prot);
68687
68688 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
68689 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
68690 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
68691 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
68692 /*
68693 * Make sure vm_committed_as in one cacheline and not cacheline shared with
68694 * other variables. It can be updated by several CPUs frequently.
68695 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
68696 struct vm_area_struct *next = vma->vm_next;
68697
68698 might_sleep();
68699 + BUG_ON(vma->vm_mirror);
68700 if (vma->vm_ops && vma->vm_ops->close)
68701 vma->vm_ops->close(vma);
68702 if (vma->vm_file) {
68703 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
68704 * not page aligned -Ram Gupta
68705 */
68706 rlim = rlimit(RLIMIT_DATA);
68707 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
68708 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
68709 (mm->end_data - mm->start_data) > rlim)
68710 goto out;
68711 @@ -689,6 +711,12 @@ static int
68712 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
68713 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
68714 {
68715 +
68716 +#ifdef CONFIG_PAX_SEGMEXEC
68717 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
68718 + return 0;
68719 +#endif
68720 +
68721 if (is_mergeable_vma(vma, file, vm_flags) &&
68722 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
68723 if (vma->vm_pgoff == vm_pgoff)
68724 @@ -708,6 +736,12 @@ static int
68725 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
68726 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
68727 {
68728 +
68729 +#ifdef CONFIG_PAX_SEGMEXEC
68730 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
68731 + return 0;
68732 +#endif
68733 +
68734 if (is_mergeable_vma(vma, file, vm_flags) &&
68735 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
68736 pgoff_t vm_pglen;
68737 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
68738 struct vm_area_struct *vma_merge(struct mm_struct *mm,
68739 struct vm_area_struct *prev, unsigned long addr,
68740 unsigned long end, unsigned long vm_flags,
68741 - struct anon_vma *anon_vma, struct file *file,
68742 + struct anon_vma *anon_vma, struct file *file,
68743 pgoff_t pgoff, struct mempolicy *policy)
68744 {
68745 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
68746 struct vm_area_struct *area, *next;
68747 int err;
68748
68749 +#ifdef CONFIG_PAX_SEGMEXEC
68750 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
68751 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
68752 +
68753 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
68754 +#endif
68755 +
68756 /*
68757 * We later require that vma->vm_flags == vm_flags,
68758 * so this tests vma->vm_flags & VM_SPECIAL, too.
68759 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
68760 if (next && next->vm_end == end) /* cases 6, 7, 8 */
68761 next = next->vm_next;
68762
68763 +#ifdef CONFIG_PAX_SEGMEXEC
68764 + if (prev)
68765 + prev_m = pax_find_mirror_vma(prev);
68766 + if (area)
68767 + area_m = pax_find_mirror_vma(area);
68768 + if (next)
68769 + next_m = pax_find_mirror_vma(next);
68770 +#endif
68771 +
68772 /*
68773 * Can it merge with the predecessor?
68774 */
68775 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
68776 /* cases 1, 6 */
68777 err = vma_adjust(prev, prev->vm_start,
68778 next->vm_end, prev->vm_pgoff, NULL);
68779 - } else /* cases 2, 5, 7 */
68780 +
68781 +#ifdef CONFIG_PAX_SEGMEXEC
68782 + if (!err && prev_m)
68783 + err = vma_adjust(prev_m, prev_m->vm_start,
68784 + next_m->vm_end, prev_m->vm_pgoff, NULL);
68785 +#endif
68786 +
68787 + } else { /* cases 2, 5, 7 */
68788 err = vma_adjust(prev, prev->vm_start,
68789 end, prev->vm_pgoff, NULL);
68790 +
68791 +#ifdef CONFIG_PAX_SEGMEXEC
68792 + if (!err && prev_m)
68793 + err = vma_adjust(prev_m, prev_m->vm_start,
68794 + end_m, prev_m->vm_pgoff, NULL);
68795 +#endif
68796 +
68797 + }
68798 if (err)
68799 return NULL;
68800 khugepaged_enter_vma_merge(prev);
68801 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
68802 mpol_equal(policy, vma_policy(next)) &&
68803 can_vma_merge_before(next, vm_flags,
68804 anon_vma, file, pgoff+pglen)) {
68805 - if (prev && addr < prev->vm_end) /* case 4 */
68806 + if (prev && addr < prev->vm_end) { /* case 4 */
68807 err = vma_adjust(prev, prev->vm_start,
68808 addr, prev->vm_pgoff, NULL);
68809 - else /* cases 3, 8 */
68810 +
68811 +#ifdef CONFIG_PAX_SEGMEXEC
68812 + if (!err && prev_m)
68813 + err = vma_adjust(prev_m, prev_m->vm_start,
68814 + addr_m, prev_m->vm_pgoff, NULL);
68815 +#endif
68816 +
68817 + } else { /* cases 3, 8 */
68818 err = vma_adjust(area, addr, next->vm_end,
68819 next->vm_pgoff - pglen, NULL);
68820 +
68821 +#ifdef CONFIG_PAX_SEGMEXEC
68822 + if (!err && area_m)
68823 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
68824 + next_m->vm_pgoff - pglen, NULL);
68825 +#endif
68826 +
68827 + }
68828 if (err)
68829 return NULL;
68830 khugepaged_enter_vma_merge(area);
68831 @@ -921,14 +1001,11 @@ none:
68832 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
68833 struct file *file, long pages)
68834 {
68835 - const unsigned long stack_flags
68836 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
68837 -
68838 if (file) {
68839 mm->shared_vm += pages;
68840 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
68841 mm->exec_vm += pages;
68842 - } else if (flags & stack_flags)
68843 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
68844 mm->stack_vm += pages;
68845 if (flags & (VM_RESERVED|VM_IO))
68846 mm->reserved_vm += pages;
68847 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
68848 * (the exception is when the underlying filesystem is noexec
68849 * mounted, in which case we dont add PROT_EXEC.)
68850 */
68851 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
68852 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
68853 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
68854 prot |= PROT_EXEC;
68855
68856 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
68857 /* Obtain the address to map to. we verify (or select) it and ensure
68858 * that it represents a valid section of the address space.
68859 */
68860 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
68861 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
68862 if (addr & ~PAGE_MASK)
68863 return addr;
68864
68865 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
68866 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
68867 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
68868
68869 +#ifdef CONFIG_PAX_MPROTECT
68870 + if (mm->pax_flags & MF_PAX_MPROTECT) {
68871 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
68872 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
68873 + gr_log_rwxmmap(file);
68874 +
68875 +#ifdef CONFIG_PAX_EMUPLT
68876 + vm_flags &= ~VM_EXEC;
68877 +#else
68878 + return -EPERM;
68879 +#endif
68880 +
68881 + }
68882 +
68883 + if (!(vm_flags & VM_EXEC))
68884 + vm_flags &= ~VM_MAYEXEC;
68885 +#else
68886 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
68887 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
68888 +#endif
68889 + else
68890 + vm_flags &= ~VM_MAYWRITE;
68891 + }
68892 +#endif
68893 +
68894 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68895 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
68896 + vm_flags &= ~VM_PAGEEXEC;
68897 +#endif
68898 +
68899 if (flags & MAP_LOCKED)
68900 if (!can_do_mlock())
68901 return -EPERM;
68902 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
68903 locked += mm->locked_vm;
68904 lock_limit = rlimit(RLIMIT_MEMLOCK);
68905 lock_limit >>= PAGE_SHIFT;
68906 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
68907 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
68908 return -EAGAIN;
68909 }
68910 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
68911 if (error)
68912 return error;
68913
68914 + if (!gr_acl_handle_mmap(file, prot))
68915 + return -EACCES;
68916 +
68917 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
68918 }
68919 EXPORT_SYMBOL(do_mmap_pgoff);
68920 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
68921 vm_flags_t vm_flags = vma->vm_flags;
68922
68923 /* If it was private or non-writable, the write bit is already clear */
68924 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
68925 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
68926 return 0;
68927
68928 /* The backer wishes to know when pages are first written to? */
68929 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
68930 unsigned long charged = 0;
68931 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
68932
68933 +#ifdef CONFIG_PAX_SEGMEXEC
68934 + struct vm_area_struct *vma_m = NULL;
68935 +#endif
68936 +
68937 + /*
68938 + * mm->mmap_sem is required to protect against another thread
68939 + * changing the mappings in case we sleep.
68940 + */
68941 + verify_mm_writelocked(mm);
68942 +
68943 /* Clear old maps */
68944 error = -ENOMEM;
68945 -munmap_back:
68946 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
68947 if (vma && vma->vm_start < addr + len) {
68948 if (do_munmap(mm, addr, len))
68949 return -ENOMEM;
68950 - goto munmap_back;
68951 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
68952 + BUG_ON(vma && vma->vm_start < addr + len);
68953 }
68954
68955 /* Check against address space limit. */
68956 @@ -1258,6 +1379,16 @@ munmap_back:
68957 goto unacct_error;
68958 }
68959
68960 +#ifdef CONFIG_PAX_SEGMEXEC
68961 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
68962 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
68963 + if (!vma_m) {
68964 + error = -ENOMEM;
68965 + goto free_vma;
68966 + }
68967 + }
68968 +#endif
68969 +
68970 vma->vm_mm = mm;
68971 vma->vm_start = addr;
68972 vma->vm_end = addr + len;
68973 @@ -1281,6 +1412,19 @@ munmap_back:
68974 error = file->f_op->mmap(file, vma);
68975 if (error)
68976 goto unmap_and_free_vma;
68977 +
68978 +#ifdef CONFIG_PAX_SEGMEXEC
68979 + if (vma_m && (vm_flags & VM_EXECUTABLE))
68980 + added_exe_file_vma(mm);
68981 +#endif
68982 +
68983 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68984 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
68985 + vma->vm_flags |= VM_PAGEEXEC;
68986 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
68987 + }
68988 +#endif
68989 +
68990 if (vm_flags & VM_EXECUTABLE)
68991 added_exe_file_vma(mm);
68992
68993 @@ -1316,6 +1460,11 @@ munmap_back:
68994 vma_link(mm, vma, prev, rb_link, rb_parent);
68995 file = vma->vm_file;
68996
68997 +#ifdef CONFIG_PAX_SEGMEXEC
68998 + if (vma_m)
68999 + BUG_ON(pax_mirror_vma(vma_m, vma));
69000 +#endif
69001 +
69002 /* Once vma denies write, undo our temporary denial count */
69003 if (correct_wcount)
69004 atomic_inc(&inode->i_writecount);
69005 @@ -1324,6 +1473,7 @@ out:
69006
69007 mm->total_vm += len >> PAGE_SHIFT;
69008 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
69009 + track_exec_limit(mm, addr, addr + len, vm_flags);
69010 if (vm_flags & VM_LOCKED) {
69011 if (!mlock_vma_pages_range(vma, addr, addr + len))
69012 mm->locked_vm += (len >> PAGE_SHIFT);
69013 @@ -1341,6 +1491,12 @@ unmap_and_free_vma:
69014 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
69015 charged = 0;
69016 free_vma:
69017 +
69018 +#ifdef CONFIG_PAX_SEGMEXEC
69019 + if (vma_m)
69020 + kmem_cache_free(vm_area_cachep, vma_m);
69021 +#endif
69022 +
69023 kmem_cache_free(vm_area_cachep, vma);
69024 unacct_error:
69025 if (charged)
69026 @@ -1348,6 +1504,44 @@ unacct_error:
69027 return error;
69028 }
69029
69030 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
69031 +{
69032 + if (!vma) {
69033 +#ifdef CONFIG_STACK_GROWSUP
69034 + if (addr > sysctl_heap_stack_gap)
69035 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
69036 + else
69037 + vma = find_vma(current->mm, 0);
69038 + if (vma && (vma->vm_flags & VM_GROWSUP))
69039 + return false;
69040 +#endif
69041 + return true;
69042 + }
69043 +
69044 + if (addr + len > vma->vm_start)
69045 + return false;
69046 +
69047 + if (vma->vm_flags & VM_GROWSDOWN)
69048 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
69049 +#ifdef CONFIG_STACK_GROWSUP
69050 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
69051 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
69052 +#endif
69053 +
69054 + return true;
69055 +}
69056 +
69057 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
69058 +{
69059 + if (vma->vm_start < len)
69060 + return -ENOMEM;
69061 + if (!(vma->vm_flags & VM_GROWSDOWN))
69062 + return vma->vm_start - len;
69063 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
69064 + return vma->vm_start - len - sysctl_heap_stack_gap;
69065 + return -ENOMEM;
69066 +}
69067 +
69068 /* Get an address range which is currently unmapped.
69069 * For shmat() with addr=0.
69070 *
69071 @@ -1374,18 +1568,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
69072 if (flags & MAP_FIXED)
69073 return addr;
69074
69075 +#ifdef CONFIG_PAX_RANDMMAP
69076 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
69077 +#endif
69078 +
69079 if (addr) {
69080 addr = PAGE_ALIGN(addr);
69081 - vma = find_vma(mm, addr);
69082 - if (TASK_SIZE - len >= addr &&
69083 - (!vma || addr + len <= vma->vm_start))
69084 - return addr;
69085 + if (TASK_SIZE - len >= addr) {
69086 + vma = find_vma(mm, addr);
69087 + if (check_heap_stack_gap(vma, addr, len))
69088 + return addr;
69089 + }
69090 }
69091 if (len > mm->cached_hole_size) {
69092 - start_addr = addr = mm->free_area_cache;
69093 + start_addr = addr = mm->free_area_cache;
69094 } else {
69095 - start_addr = addr = TASK_UNMAPPED_BASE;
69096 - mm->cached_hole_size = 0;
69097 + start_addr = addr = mm->mmap_base;
69098 + mm->cached_hole_size = 0;
69099 }
69100
69101 full_search:
69102 @@ -1396,34 +1595,40 @@ full_search:
69103 * Start a new search - just in case we missed
69104 * some holes.
69105 */
69106 - if (start_addr != TASK_UNMAPPED_BASE) {
69107 - addr = TASK_UNMAPPED_BASE;
69108 - start_addr = addr;
69109 + if (start_addr != mm->mmap_base) {
69110 + start_addr = addr = mm->mmap_base;
69111 mm->cached_hole_size = 0;
69112 goto full_search;
69113 }
69114 return -ENOMEM;
69115 }
69116 - if (!vma || addr + len <= vma->vm_start) {
69117 - /*
69118 - * Remember the place where we stopped the search:
69119 - */
69120 - mm->free_area_cache = addr + len;
69121 - return addr;
69122 - }
69123 + if (check_heap_stack_gap(vma, addr, len))
69124 + break;
69125 if (addr + mm->cached_hole_size < vma->vm_start)
69126 mm->cached_hole_size = vma->vm_start - addr;
69127 addr = vma->vm_end;
69128 }
69129 +
69130 + /*
69131 + * Remember the place where we stopped the search:
69132 + */
69133 + mm->free_area_cache = addr + len;
69134 + return addr;
69135 }
69136 #endif
69137
69138 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
69139 {
69140 +
69141 +#ifdef CONFIG_PAX_SEGMEXEC
69142 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
69143 + return;
69144 +#endif
69145 +
69146 /*
69147 * Is this a new hole at the lowest possible address?
69148 */
69149 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
69150 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
69151 mm->free_area_cache = addr;
69152 mm->cached_hole_size = ~0UL;
69153 }
69154 @@ -1441,7 +1646,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69155 {
69156 struct vm_area_struct *vma;
69157 struct mm_struct *mm = current->mm;
69158 - unsigned long addr = addr0;
69159 + unsigned long base = mm->mmap_base, addr = addr0;
69160
69161 /* requested length too big for entire address space */
69162 if (len > TASK_SIZE)
69163 @@ -1450,13 +1655,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69164 if (flags & MAP_FIXED)
69165 return addr;
69166
69167 +#ifdef CONFIG_PAX_RANDMMAP
69168 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
69169 +#endif
69170 +
69171 /* requesting a specific address */
69172 if (addr) {
69173 addr = PAGE_ALIGN(addr);
69174 - vma = find_vma(mm, addr);
69175 - if (TASK_SIZE - len >= addr &&
69176 - (!vma || addr + len <= vma->vm_start))
69177 - return addr;
69178 + if (TASK_SIZE - len >= addr) {
69179 + vma = find_vma(mm, addr);
69180 + if (check_heap_stack_gap(vma, addr, len))
69181 + return addr;
69182 + }
69183 }
69184
69185 /* check if free_area_cache is useful for us */
69186 @@ -1471,7 +1681,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69187 /* make sure it can fit in the remaining address space */
69188 if (addr > len) {
69189 vma = find_vma(mm, addr-len);
69190 - if (!vma || addr <= vma->vm_start)
69191 + if (check_heap_stack_gap(vma, addr - len, len))
69192 /* remember the address as a hint for next time */
69193 return (mm->free_area_cache = addr-len);
69194 }
69195 @@ -1488,7 +1698,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69196 * return with success:
69197 */
69198 vma = find_vma(mm, addr);
69199 - if (!vma || addr+len <= vma->vm_start)
69200 + if (check_heap_stack_gap(vma, addr, len))
69201 /* remember the address as a hint for next time */
69202 return (mm->free_area_cache = addr);
69203
69204 @@ -1497,8 +1707,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69205 mm->cached_hole_size = vma->vm_start - addr;
69206
69207 /* try just below the current vma->vm_start */
69208 - addr = vma->vm_start-len;
69209 - } while (len < vma->vm_start);
69210 + addr = skip_heap_stack_gap(vma, len);
69211 + } while (!IS_ERR_VALUE(addr));
69212
69213 bottomup:
69214 /*
69215 @@ -1507,13 +1717,21 @@ bottomup:
69216 * can happen with large stack limits and large mmap()
69217 * allocations.
69218 */
69219 + mm->mmap_base = TASK_UNMAPPED_BASE;
69220 +
69221 +#ifdef CONFIG_PAX_RANDMMAP
69222 + if (mm->pax_flags & MF_PAX_RANDMMAP)
69223 + mm->mmap_base += mm->delta_mmap;
69224 +#endif
69225 +
69226 + mm->free_area_cache = mm->mmap_base;
69227 mm->cached_hole_size = ~0UL;
69228 - mm->free_area_cache = TASK_UNMAPPED_BASE;
69229 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
69230 /*
69231 * Restore the topdown base:
69232 */
69233 - mm->free_area_cache = mm->mmap_base;
69234 + mm->mmap_base = base;
69235 + mm->free_area_cache = base;
69236 mm->cached_hole_size = ~0UL;
69237
69238 return addr;
69239 @@ -1522,6 +1740,12 @@ bottomup:
69240
69241 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
69242 {
69243 +
69244 +#ifdef CONFIG_PAX_SEGMEXEC
69245 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
69246 + return;
69247 +#endif
69248 +
69249 /*
69250 * Is this a new hole at the highest possible address?
69251 */
69252 @@ -1529,8 +1753,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
69253 mm->free_area_cache = addr;
69254
69255 /* dont allow allocations above current base */
69256 - if (mm->free_area_cache > mm->mmap_base)
69257 + if (mm->free_area_cache > mm->mmap_base) {
69258 mm->free_area_cache = mm->mmap_base;
69259 + mm->cached_hole_size = ~0UL;
69260 + }
69261 }
69262
69263 unsigned long
69264 @@ -1638,6 +1864,28 @@ out:
69265 return prev ? prev->vm_next : vma;
69266 }
69267
69268 +#ifdef CONFIG_PAX_SEGMEXEC
69269 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
69270 +{
69271 + struct vm_area_struct *vma_m;
69272 +
69273 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
69274 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
69275 + BUG_ON(vma->vm_mirror);
69276 + return NULL;
69277 + }
69278 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
69279 + vma_m = vma->vm_mirror;
69280 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
69281 + BUG_ON(vma->vm_file != vma_m->vm_file);
69282 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
69283 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
69284 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
69285 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
69286 + return vma_m;
69287 +}
69288 +#endif
69289 +
69290 /*
69291 * Verify that the stack growth is acceptable and
69292 * update accounting. This is shared with both the
69293 @@ -1654,6 +1902,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69294 return -ENOMEM;
69295
69296 /* Stack limit test */
69297 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
69298 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
69299 return -ENOMEM;
69300
69301 @@ -1664,6 +1913,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69302 locked = mm->locked_vm + grow;
69303 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
69304 limit >>= PAGE_SHIFT;
69305 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
69306 if (locked > limit && !capable(CAP_IPC_LOCK))
69307 return -ENOMEM;
69308 }
69309 @@ -1694,37 +1944,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69310 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
69311 * vma is the last one with address > vma->vm_end. Have to extend vma.
69312 */
69313 +#ifndef CONFIG_IA64
69314 +static
69315 +#endif
69316 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
69317 {
69318 int error;
69319 + bool locknext;
69320
69321 if (!(vma->vm_flags & VM_GROWSUP))
69322 return -EFAULT;
69323
69324 + /* Also guard against wrapping around to address 0. */
69325 + if (address < PAGE_ALIGN(address+1))
69326 + address = PAGE_ALIGN(address+1);
69327 + else
69328 + return -ENOMEM;
69329 +
69330 /*
69331 * We must make sure the anon_vma is allocated
69332 * so that the anon_vma locking is not a noop.
69333 */
69334 if (unlikely(anon_vma_prepare(vma)))
69335 return -ENOMEM;
69336 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
69337 + if (locknext && anon_vma_prepare(vma->vm_next))
69338 + return -ENOMEM;
69339 vma_lock_anon_vma(vma);
69340 + if (locknext)
69341 + vma_lock_anon_vma(vma->vm_next);
69342
69343 /*
69344 * vma->vm_start/vm_end cannot change under us because the caller
69345 * is required to hold the mmap_sem in read mode. We need the
69346 - * anon_vma lock to serialize against concurrent expand_stacks.
69347 - * Also guard against wrapping around to address 0.
69348 + * anon_vma locks to serialize against concurrent expand_stacks
69349 + * and expand_upwards.
69350 */
69351 - if (address < PAGE_ALIGN(address+4))
69352 - address = PAGE_ALIGN(address+4);
69353 - else {
69354 - vma_unlock_anon_vma(vma);
69355 - return -ENOMEM;
69356 - }
69357 error = 0;
69358
69359 /* Somebody else might have raced and expanded it already */
69360 - if (address > vma->vm_end) {
69361 + if (vma->vm_next && (vma->vm_next->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && vma->vm_next->vm_start - address < sysctl_heap_stack_gap)
69362 + error = -ENOMEM;
69363 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
69364 unsigned long size, grow;
69365
69366 size = address - vma->vm_start;
69367 @@ -1739,6 +2000,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
69368 }
69369 }
69370 }
69371 + if (locknext)
69372 + vma_unlock_anon_vma(vma->vm_next);
69373 vma_unlock_anon_vma(vma);
69374 khugepaged_enter_vma_merge(vma);
69375 return error;
69376 @@ -1752,6 +2015,8 @@ int expand_downwards(struct vm_area_struct *vma,
69377 unsigned long address)
69378 {
69379 int error;
69380 + bool lockprev = false;
69381 + struct vm_area_struct *prev;
69382
69383 /*
69384 * We must make sure the anon_vma is allocated
69385 @@ -1765,6 +2030,15 @@ int expand_downwards(struct vm_area_struct *vma,
69386 if (error)
69387 return error;
69388
69389 + prev = vma->vm_prev;
69390 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
69391 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
69392 +#endif
69393 + if (lockprev && anon_vma_prepare(prev))
69394 + return -ENOMEM;
69395 + if (lockprev)
69396 + vma_lock_anon_vma(prev);
69397 +
69398 vma_lock_anon_vma(vma);
69399
69400 /*
69401 @@ -1774,9 +2048,17 @@ int expand_downwards(struct vm_area_struct *vma,
69402 */
69403
69404 /* Somebody else might have raced and expanded it already */
69405 - if (address < vma->vm_start) {
69406 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
69407 + error = -ENOMEM;
69408 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
69409 unsigned long size, grow;
69410
69411 +#ifdef CONFIG_PAX_SEGMEXEC
69412 + struct vm_area_struct *vma_m;
69413 +
69414 + vma_m = pax_find_mirror_vma(vma);
69415 +#endif
69416 +
69417 size = vma->vm_end - address;
69418 grow = (vma->vm_start - address) >> PAGE_SHIFT;
69419
69420 @@ -1786,11 +2068,22 @@ int expand_downwards(struct vm_area_struct *vma,
69421 if (!error) {
69422 vma->vm_start = address;
69423 vma->vm_pgoff -= grow;
69424 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
69425 +
69426 +#ifdef CONFIG_PAX_SEGMEXEC
69427 + if (vma_m) {
69428 + vma_m->vm_start -= grow << PAGE_SHIFT;
69429 + vma_m->vm_pgoff -= grow;
69430 + }
69431 +#endif
69432 +
69433 perf_event_mmap(vma);
69434 }
69435 }
69436 }
69437 vma_unlock_anon_vma(vma);
69438 + if (lockprev)
69439 + vma_unlock_anon_vma(prev);
69440 khugepaged_enter_vma_merge(vma);
69441 return error;
69442 }
69443 @@ -1860,6 +2153,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
69444 do {
69445 long nrpages = vma_pages(vma);
69446
69447 +#ifdef CONFIG_PAX_SEGMEXEC
69448 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
69449 + vma = remove_vma(vma);
69450 + continue;
69451 + }
69452 +#endif
69453 +
69454 mm->total_vm -= nrpages;
69455 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
69456 vma = remove_vma(vma);
69457 @@ -1905,6 +2205,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
69458 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
69459 vma->vm_prev = NULL;
69460 do {
69461 +
69462 +#ifdef CONFIG_PAX_SEGMEXEC
69463 + if (vma->vm_mirror) {
69464 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
69465 + vma->vm_mirror->vm_mirror = NULL;
69466 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
69467 + vma->vm_mirror = NULL;
69468 + }
69469 +#endif
69470 +
69471 rb_erase(&vma->vm_rb, &mm->mm_rb);
69472 mm->map_count--;
69473 tail_vma = vma;
69474 @@ -1933,14 +2243,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69475 struct vm_area_struct *new;
69476 int err = -ENOMEM;
69477
69478 +#ifdef CONFIG_PAX_SEGMEXEC
69479 + struct vm_area_struct *vma_m, *new_m = NULL;
69480 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
69481 +#endif
69482 +
69483 if (is_vm_hugetlb_page(vma) && (addr &
69484 ~(huge_page_mask(hstate_vma(vma)))))
69485 return -EINVAL;
69486
69487 +#ifdef CONFIG_PAX_SEGMEXEC
69488 + vma_m = pax_find_mirror_vma(vma);
69489 +#endif
69490 +
69491 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69492 if (!new)
69493 goto out_err;
69494
69495 +#ifdef CONFIG_PAX_SEGMEXEC
69496 + if (vma_m) {
69497 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69498 + if (!new_m) {
69499 + kmem_cache_free(vm_area_cachep, new);
69500 + goto out_err;
69501 + }
69502 + }
69503 +#endif
69504 +
69505 /* most fields are the same, copy all, and then fixup */
69506 *new = *vma;
69507
69508 @@ -1953,6 +2282,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69509 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
69510 }
69511
69512 +#ifdef CONFIG_PAX_SEGMEXEC
69513 + if (vma_m) {
69514 + *new_m = *vma_m;
69515 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
69516 + new_m->vm_mirror = new;
69517 + new->vm_mirror = new_m;
69518 +
69519 + if (new_below)
69520 + new_m->vm_end = addr_m;
69521 + else {
69522 + new_m->vm_start = addr_m;
69523 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
69524 + }
69525 + }
69526 +#endif
69527 +
69528 pol = mpol_dup(vma_policy(vma));
69529 if (IS_ERR(pol)) {
69530 err = PTR_ERR(pol);
69531 @@ -1978,6 +2323,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69532 else
69533 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
69534
69535 +#ifdef CONFIG_PAX_SEGMEXEC
69536 + if (!err && vma_m) {
69537 + if (anon_vma_clone(new_m, vma_m))
69538 + goto out_free_mpol;
69539 +
69540 + mpol_get(pol);
69541 + vma_set_policy(new_m, pol);
69542 +
69543 + if (new_m->vm_file) {
69544 + get_file(new_m->vm_file);
69545 + if (vma_m->vm_flags & VM_EXECUTABLE)
69546 + added_exe_file_vma(mm);
69547 + }
69548 +
69549 + if (new_m->vm_ops && new_m->vm_ops->open)
69550 + new_m->vm_ops->open(new_m);
69551 +
69552 + if (new_below)
69553 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
69554 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
69555 + else
69556 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
69557 +
69558 + if (err) {
69559 + if (new_m->vm_ops && new_m->vm_ops->close)
69560 + new_m->vm_ops->close(new_m);
69561 + if (new_m->vm_file) {
69562 + if (vma_m->vm_flags & VM_EXECUTABLE)
69563 + removed_exe_file_vma(mm);
69564 + fput(new_m->vm_file);
69565 + }
69566 + mpol_put(pol);
69567 + }
69568 + }
69569 +#endif
69570 +
69571 /* Success. */
69572 if (!err)
69573 return 0;
69574 @@ -1990,10 +2371,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69575 removed_exe_file_vma(mm);
69576 fput(new->vm_file);
69577 }
69578 - unlink_anon_vmas(new);
69579 out_free_mpol:
69580 mpol_put(pol);
69581 out_free_vma:
69582 +
69583 +#ifdef CONFIG_PAX_SEGMEXEC
69584 + if (new_m) {
69585 + unlink_anon_vmas(new_m);
69586 + kmem_cache_free(vm_area_cachep, new_m);
69587 + }
69588 +#endif
69589 +
69590 + unlink_anon_vmas(new);
69591 kmem_cache_free(vm_area_cachep, new);
69592 out_err:
69593 return err;
69594 @@ -2006,6 +2395,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69595 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
69596 unsigned long addr, int new_below)
69597 {
69598 +
69599 +#ifdef CONFIG_PAX_SEGMEXEC
69600 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
69601 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
69602 + if (mm->map_count >= sysctl_max_map_count-1)
69603 + return -ENOMEM;
69604 + } else
69605 +#endif
69606 +
69607 if (mm->map_count >= sysctl_max_map_count)
69608 return -ENOMEM;
69609
69610 @@ -2017,11 +2415,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
69611 * work. This now handles partial unmappings.
69612 * Jeremy Fitzhardinge <jeremy@goop.org>
69613 */
69614 +#ifdef CONFIG_PAX_SEGMEXEC
69615 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69616 {
69617 + int ret = __do_munmap(mm, start, len);
69618 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
69619 + return ret;
69620 +
69621 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
69622 +}
69623 +
69624 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69625 +#else
69626 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69627 +#endif
69628 +{
69629 unsigned long end;
69630 struct vm_area_struct *vma, *prev, *last;
69631
69632 + /*
69633 + * mm->mmap_sem is required to protect against another thread
69634 + * changing the mappings in case we sleep.
69635 + */
69636 + verify_mm_writelocked(mm);
69637 +
69638 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
69639 return -EINVAL;
69640
69641 @@ -2096,6 +2513,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69642 /* Fix up all other VM information */
69643 remove_vma_list(mm, vma);
69644
69645 + track_exec_limit(mm, start, end, 0UL);
69646 +
69647 return 0;
69648 }
69649
69650 @@ -2108,22 +2527,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
69651
69652 profile_munmap(addr);
69653
69654 +#ifdef CONFIG_PAX_SEGMEXEC
69655 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
69656 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
69657 + return -EINVAL;
69658 +#endif
69659 +
69660 down_write(&mm->mmap_sem);
69661 ret = do_munmap(mm, addr, len);
69662 up_write(&mm->mmap_sem);
69663 return ret;
69664 }
69665
69666 -static inline void verify_mm_writelocked(struct mm_struct *mm)
69667 -{
69668 -#ifdef CONFIG_DEBUG_VM
69669 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
69670 - WARN_ON(1);
69671 - up_read(&mm->mmap_sem);
69672 - }
69673 -#endif
69674 -}
69675 -
69676 /*
69677 * this is really a simplified "do_mmap". it only handles
69678 * anonymous maps. eventually we may be able to do some
69679 @@ -2137,6 +2552,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69680 struct rb_node ** rb_link, * rb_parent;
69681 pgoff_t pgoff = addr >> PAGE_SHIFT;
69682 int error;
69683 + unsigned long charged;
69684
69685 len = PAGE_ALIGN(len);
69686 if (!len)
69687 @@ -2148,16 +2564,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69688
69689 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
69690
69691 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
69692 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
69693 + flags &= ~VM_EXEC;
69694 +
69695 +#ifdef CONFIG_PAX_MPROTECT
69696 + if (mm->pax_flags & MF_PAX_MPROTECT)
69697 + flags &= ~VM_MAYEXEC;
69698 +#endif
69699 +
69700 + }
69701 +#endif
69702 +
69703 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
69704 if (error & ~PAGE_MASK)
69705 return error;
69706
69707 + charged = len >> PAGE_SHIFT;
69708 +
69709 /*
69710 * mlock MCL_FUTURE?
69711 */
69712 if (mm->def_flags & VM_LOCKED) {
69713 unsigned long locked, lock_limit;
69714 - locked = len >> PAGE_SHIFT;
69715 + locked = charged;
69716 locked += mm->locked_vm;
69717 lock_limit = rlimit(RLIMIT_MEMLOCK);
69718 lock_limit >>= PAGE_SHIFT;
69719 @@ -2174,22 +2604,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69720 /*
69721 * Clear old maps. this also does some error checking for us
69722 */
69723 - munmap_back:
69724 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69725 if (vma && vma->vm_start < addr + len) {
69726 if (do_munmap(mm, addr, len))
69727 return -ENOMEM;
69728 - goto munmap_back;
69729 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69730 + BUG_ON(vma && vma->vm_start < addr + len);
69731 }
69732
69733 /* Check against address space limits *after* clearing old maps... */
69734 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
69735 + if (!may_expand_vm(mm, charged))
69736 return -ENOMEM;
69737
69738 if (mm->map_count > sysctl_max_map_count)
69739 return -ENOMEM;
69740
69741 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
69742 + if (security_vm_enough_memory(charged))
69743 return -ENOMEM;
69744
69745 /* Can we just expand an old private anonymous mapping? */
69746 @@ -2203,7 +2633,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69747 */
69748 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69749 if (!vma) {
69750 - vm_unacct_memory(len >> PAGE_SHIFT);
69751 + vm_unacct_memory(charged);
69752 return -ENOMEM;
69753 }
69754
69755 @@ -2217,11 +2647,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69756 vma_link(mm, vma, prev, rb_link, rb_parent);
69757 out:
69758 perf_event_mmap(vma);
69759 - mm->total_vm += len >> PAGE_SHIFT;
69760 + mm->total_vm += charged;
69761 if (flags & VM_LOCKED) {
69762 if (!mlock_vma_pages_range(vma, addr, addr + len))
69763 - mm->locked_vm += (len >> PAGE_SHIFT);
69764 + mm->locked_vm += charged;
69765 }
69766 + track_exec_limit(mm, addr, addr + len, flags);
69767 return addr;
69768 }
69769
69770 @@ -2268,8 +2699,10 @@ void exit_mmap(struct mm_struct *mm)
69771 * Walk the list again, actually closing and freeing it,
69772 * with preemption enabled, without holding any MM locks.
69773 */
69774 - while (vma)
69775 + while (vma) {
69776 + vma->vm_mirror = NULL;
69777 vma = remove_vma(vma);
69778 + }
69779
69780 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
69781 }
69782 @@ -2283,6 +2716,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
69783 struct vm_area_struct * __vma, * prev;
69784 struct rb_node ** rb_link, * rb_parent;
69785
69786 +#ifdef CONFIG_PAX_SEGMEXEC
69787 + struct vm_area_struct *vma_m = NULL;
69788 +#endif
69789 +
69790 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
69791 + return -EPERM;
69792 +
69793 /*
69794 * The vm_pgoff of a purely anonymous vma should be irrelevant
69795 * until its first write fault, when page's anon_vma and index
69796 @@ -2305,7 +2745,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
69797 if ((vma->vm_flags & VM_ACCOUNT) &&
69798 security_vm_enough_memory_mm(mm, vma_pages(vma)))
69799 return -ENOMEM;
69800 +
69801 +#ifdef CONFIG_PAX_SEGMEXEC
69802 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
69803 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69804 + if (!vma_m)
69805 + return -ENOMEM;
69806 + }
69807 +#endif
69808 +
69809 vma_link(mm, vma, prev, rb_link, rb_parent);
69810 +
69811 +#ifdef CONFIG_PAX_SEGMEXEC
69812 + if (vma_m)
69813 + BUG_ON(pax_mirror_vma(vma_m, vma));
69814 +#endif
69815 +
69816 return 0;
69817 }
69818
69819 @@ -2323,6 +2778,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
69820 struct rb_node **rb_link, *rb_parent;
69821 struct mempolicy *pol;
69822
69823 + BUG_ON(vma->vm_mirror);
69824 +
69825 /*
69826 * If anonymous vma has not yet been faulted, update new pgoff
69827 * to match new location, to increase its chance of merging.
69828 @@ -2373,6 +2830,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
69829 return NULL;
69830 }
69831
69832 +#ifdef CONFIG_PAX_SEGMEXEC
69833 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
69834 +{
69835 + struct vm_area_struct *prev_m;
69836 + struct rb_node **rb_link_m, *rb_parent_m;
69837 + struct mempolicy *pol_m;
69838 +
69839 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
69840 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
69841 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
69842 + *vma_m = *vma;
69843 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
69844 + if (anon_vma_clone(vma_m, vma))
69845 + return -ENOMEM;
69846 + pol_m = vma_policy(vma_m);
69847 + mpol_get(pol_m);
69848 + vma_set_policy(vma_m, pol_m);
69849 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
69850 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
69851 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
69852 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
69853 + if (vma_m->vm_file)
69854 + get_file(vma_m->vm_file);
69855 + if (vma_m->vm_ops && vma_m->vm_ops->open)
69856 + vma_m->vm_ops->open(vma_m);
69857 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
69858 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
69859 + vma_m->vm_mirror = vma;
69860 + vma->vm_mirror = vma_m;
69861 + return 0;
69862 +}
69863 +#endif
69864 +
69865 /*
69866 * Return true if the calling process may expand its vm space by the passed
69867 * number of pages
69868 @@ -2383,7 +2873,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
69869 unsigned long lim;
69870
69871 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
69872 -
69873 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
69874 if (cur + npages > lim)
69875 return 0;
69876 return 1;
69877 @@ -2454,6 +2944,22 @@ int install_special_mapping(struct mm_struct *mm,
69878 vma->vm_start = addr;
69879 vma->vm_end = addr + len;
69880
69881 +#ifdef CONFIG_PAX_MPROTECT
69882 + if (mm->pax_flags & MF_PAX_MPROTECT) {
69883 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
69884 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
69885 + return -EPERM;
69886 + if (!(vm_flags & VM_EXEC))
69887 + vm_flags &= ~VM_MAYEXEC;
69888 +#else
69889 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
69890 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
69891 +#endif
69892 + else
69893 + vm_flags &= ~VM_MAYWRITE;
69894 + }
69895 +#endif
69896 +
69897 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
69898 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
69899
69900 diff --git a/mm/mprotect.c b/mm/mprotect.c
69901 index 5a688a2..27e031c 100644
69902 --- a/mm/mprotect.c
69903 +++ b/mm/mprotect.c
69904 @@ -23,10 +23,16 @@
69905 #include <linux/mmu_notifier.h>
69906 #include <linux/migrate.h>
69907 #include <linux/perf_event.h>
69908 +
69909 +#ifdef CONFIG_PAX_MPROTECT
69910 +#include <linux/elf.h>
69911 +#endif
69912 +
69913 #include <asm/uaccess.h>
69914 #include <asm/pgtable.h>
69915 #include <asm/cacheflush.h>
69916 #include <asm/tlbflush.h>
69917 +#include <asm/mmu_context.h>
69918
69919 #ifndef pgprot_modify
69920 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
69921 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
69922 flush_tlb_range(vma, start, end);
69923 }
69924
69925 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
69926 +/* called while holding the mmap semaphor for writing except stack expansion */
69927 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
69928 +{
69929 + unsigned long oldlimit, newlimit = 0UL;
69930 +
69931 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
69932 + return;
69933 +
69934 + spin_lock(&mm->page_table_lock);
69935 + oldlimit = mm->context.user_cs_limit;
69936 + if ((prot & VM_EXEC) && oldlimit < end)
69937 + /* USER_CS limit moved up */
69938 + newlimit = end;
69939 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
69940 + /* USER_CS limit moved down */
69941 + newlimit = start;
69942 +
69943 + if (newlimit) {
69944 + mm->context.user_cs_limit = newlimit;
69945 +
69946 +#ifdef CONFIG_SMP
69947 + wmb();
69948 + cpus_clear(mm->context.cpu_user_cs_mask);
69949 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
69950 +#endif
69951 +
69952 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
69953 + }
69954 + spin_unlock(&mm->page_table_lock);
69955 + if (newlimit == end) {
69956 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
69957 +
69958 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
69959 + if (is_vm_hugetlb_page(vma))
69960 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
69961 + else
69962 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
69963 + }
69964 +}
69965 +#endif
69966 +
69967 int
69968 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
69969 unsigned long start, unsigned long end, unsigned long newflags)
69970 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
69971 int error;
69972 int dirty_accountable = 0;
69973
69974 +#ifdef CONFIG_PAX_SEGMEXEC
69975 + struct vm_area_struct *vma_m = NULL;
69976 + unsigned long start_m, end_m;
69977 +
69978 + start_m = start + SEGMEXEC_TASK_SIZE;
69979 + end_m = end + SEGMEXEC_TASK_SIZE;
69980 +#endif
69981 +
69982 if (newflags == oldflags) {
69983 *pprev = vma;
69984 return 0;
69985 }
69986
69987 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
69988 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
69989 +
69990 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
69991 + return -ENOMEM;
69992 +
69993 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
69994 + return -ENOMEM;
69995 + }
69996 +
69997 /*
69998 * If we make a private mapping writable we increase our commit;
69999 * but (without finer accounting) cannot reduce our commit if we
70000 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70001 }
70002 }
70003
70004 +#ifdef CONFIG_PAX_SEGMEXEC
70005 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
70006 + if (start != vma->vm_start) {
70007 + error = split_vma(mm, vma, start, 1);
70008 + if (error)
70009 + goto fail;
70010 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
70011 + *pprev = (*pprev)->vm_next;
70012 + }
70013 +
70014 + if (end != vma->vm_end) {
70015 + error = split_vma(mm, vma, end, 0);
70016 + if (error)
70017 + goto fail;
70018 + }
70019 +
70020 + if (pax_find_mirror_vma(vma)) {
70021 + error = __do_munmap(mm, start_m, end_m - start_m);
70022 + if (error)
70023 + goto fail;
70024 + } else {
70025 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70026 + if (!vma_m) {
70027 + error = -ENOMEM;
70028 + goto fail;
70029 + }
70030 + vma->vm_flags = newflags;
70031 + error = pax_mirror_vma(vma_m, vma);
70032 + if (error) {
70033 + vma->vm_flags = oldflags;
70034 + goto fail;
70035 + }
70036 + }
70037 + }
70038 +#endif
70039 +
70040 /*
70041 * First try to merge with previous and/or next vma.
70042 */
70043 @@ -204,9 +306,21 @@ success:
70044 * vm_flags and vm_page_prot are protected by the mmap_sem
70045 * held in write mode.
70046 */
70047 +
70048 +#ifdef CONFIG_PAX_SEGMEXEC
70049 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
70050 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
70051 +#endif
70052 +
70053 vma->vm_flags = newflags;
70054 +
70055 +#ifdef CONFIG_PAX_MPROTECT
70056 + if (mm->binfmt && mm->binfmt->handle_mprotect)
70057 + mm->binfmt->handle_mprotect(vma, newflags);
70058 +#endif
70059 +
70060 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
70061 - vm_get_page_prot(newflags));
70062 + vm_get_page_prot(vma->vm_flags));
70063
70064 if (vma_wants_writenotify(vma)) {
70065 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
70066 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70067 end = start + len;
70068 if (end <= start)
70069 return -ENOMEM;
70070 +
70071 +#ifdef CONFIG_PAX_SEGMEXEC
70072 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70073 + if (end > SEGMEXEC_TASK_SIZE)
70074 + return -EINVAL;
70075 + } else
70076 +#endif
70077 +
70078 + if (end > TASK_SIZE)
70079 + return -EINVAL;
70080 +
70081 if (!arch_validate_prot(prot))
70082 return -EINVAL;
70083
70084 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70085 /*
70086 * Does the application expect PROT_READ to imply PROT_EXEC:
70087 */
70088 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70089 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70090 prot |= PROT_EXEC;
70091
70092 vm_flags = calc_vm_prot_bits(prot);
70093 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70094 if (start > vma->vm_start)
70095 prev = vma;
70096
70097 +#ifdef CONFIG_PAX_MPROTECT
70098 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
70099 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
70100 +#endif
70101 +
70102 for (nstart = start ; ; ) {
70103 unsigned long newflags;
70104
70105 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70106
70107 /* newflags >> 4 shift VM_MAY% in place of VM_% */
70108 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
70109 + if (prot & (PROT_WRITE | PROT_EXEC))
70110 + gr_log_rwxmprotect(vma->vm_file);
70111 +
70112 + error = -EACCES;
70113 + goto out;
70114 + }
70115 +
70116 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
70117 error = -EACCES;
70118 goto out;
70119 }
70120 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70121 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
70122 if (error)
70123 goto out;
70124 +
70125 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
70126 +
70127 nstart = tmp;
70128
70129 if (nstart < prev->vm_end)
70130 diff --git a/mm/mremap.c b/mm/mremap.c
70131 index d6959cb..18a402a 100644
70132 --- a/mm/mremap.c
70133 +++ b/mm/mremap.c
70134 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
70135 continue;
70136 pte = ptep_get_and_clear(mm, old_addr, old_pte);
70137 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
70138 +
70139 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70140 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
70141 + pte = pte_exprotect(pte);
70142 +#endif
70143 +
70144 set_pte_at(mm, new_addr, new_pte, pte);
70145 }
70146
70147 @@ -290,6 +296,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
70148 if (is_vm_hugetlb_page(vma))
70149 goto Einval;
70150
70151 +#ifdef CONFIG_PAX_SEGMEXEC
70152 + if (pax_find_mirror_vma(vma))
70153 + goto Einval;
70154 +#endif
70155 +
70156 /* We can't remap across vm area boundaries */
70157 if (old_len > vma->vm_end - addr)
70158 goto Efault;
70159 @@ -346,20 +357,25 @@ static unsigned long mremap_to(unsigned long addr,
70160 unsigned long ret = -EINVAL;
70161 unsigned long charged = 0;
70162 unsigned long map_flags;
70163 + unsigned long pax_task_size = TASK_SIZE;
70164
70165 if (new_addr & ~PAGE_MASK)
70166 goto out;
70167
70168 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
70169 +#ifdef CONFIG_PAX_SEGMEXEC
70170 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
70171 + pax_task_size = SEGMEXEC_TASK_SIZE;
70172 +#endif
70173 +
70174 + pax_task_size -= PAGE_SIZE;
70175 +
70176 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
70177 goto out;
70178
70179 /* Check if the location we're moving into overlaps the
70180 * old location at all, and fail if it does.
70181 */
70182 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
70183 - goto out;
70184 -
70185 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
70186 + if (addr + old_len > new_addr && new_addr + new_len > addr)
70187 goto out;
70188
70189 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
70190 @@ -431,6 +447,7 @@ unsigned long do_mremap(unsigned long addr,
70191 struct vm_area_struct *vma;
70192 unsigned long ret = -EINVAL;
70193 unsigned long charged = 0;
70194 + unsigned long pax_task_size = TASK_SIZE;
70195
70196 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
70197 goto out;
70198 @@ -449,6 +466,17 @@ unsigned long do_mremap(unsigned long addr,
70199 if (!new_len)
70200 goto out;
70201
70202 +#ifdef CONFIG_PAX_SEGMEXEC
70203 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
70204 + pax_task_size = SEGMEXEC_TASK_SIZE;
70205 +#endif
70206 +
70207 + pax_task_size -= PAGE_SIZE;
70208 +
70209 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
70210 + old_len > pax_task_size || addr > pax_task_size-old_len)
70211 + goto out;
70212 +
70213 if (flags & MREMAP_FIXED) {
70214 if (flags & MREMAP_MAYMOVE)
70215 ret = mremap_to(addr, old_len, new_addr, new_len);
70216 @@ -498,6 +526,7 @@ unsigned long do_mremap(unsigned long addr,
70217 addr + new_len);
70218 }
70219 ret = addr;
70220 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
70221 goto out;
70222 }
70223 }
70224 @@ -524,7 +553,13 @@ unsigned long do_mremap(unsigned long addr,
70225 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
70226 if (ret)
70227 goto out;
70228 +
70229 + map_flags = vma->vm_flags;
70230 ret = move_vma(vma, addr, old_len, new_len, new_addr);
70231 + if (!(ret & ~PAGE_MASK)) {
70232 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
70233 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
70234 + }
70235 }
70236 out:
70237 if (ret & ~PAGE_MASK)
70238 diff --git a/mm/nobootmem.c b/mm/nobootmem.c
70239 index 7fa41b4..6087460 100644
70240 --- a/mm/nobootmem.c
70241 +++ b/mm/nobootmem.c
70242 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
70243 unsigned long __init free_all_memory_core_early(int nodeid)
70244 {
70245 int i;
70246 - u64 start, end;
70247 + u64 start, end, startrange, endrange;
70248 unsigned long count = 0;
70249 - struct range *range = NULL;
70250 + struct range *range = NULL, rangerange = { 0, 0 };
70251 int nr_range;
70252
70253 nr_range = get_free_all_memory_range(&range, nodeid);
70254 + startrange = __pa(range) >> PAGE_SHIFT;
70255 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
70256
70257 for (i = 0; i < nr_range; i++) {
70258 start = range[i].start;
70259 end = range[i].end;
70260 + if (start <= endrange && startrange < end) {
70261 + BUG_ON(rangerange.start | rangerange.end);
70262 + rangerange = range[i];
70263 + continue;
70264 + }
70265 count += end - start;
70266 __free_pages_memory(start, end);
70267 }
70268 + start = rangerange.start;
70269 + end = rangerange.end;
70270 + count += end - start;
70271 + __free_pages_memory(start, end);
70272
70273 return count;
70274 }
70275 diff --git a/mm/nommu.c b/mm/nommu.c
70276 index b982290..7d73f53 100644
70277 --- a/mm/nommu.c
70278 +++ b/mm/nommu.c
70279 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
70280 int sysctl_overcommit_ratio = 50; /* default is 50% */
70281 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
70282 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
70283 -int heap_stack_gap = 0;
70284
70285 atomic_long_t mmap_pages_allocated;
70286
70287 @@ -825,15 +824,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
70288 EXPORT_SYMBOL(find_vma);
70289
70290 /*
70291 - * find a VMA
70292 - * - we don't extend stack VMAs under NOMMU conditions
70293 - */
70294 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
70295 -{
70296 - return find_vma(mm, addr);
70297 -}
70298 -
70299 -/*
70300 * expand a stack to a given address
70301 * - not supported under NOMMU conditions
70302 */
70303 @@ -1553,6 +1543,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
70304
70305 /* most fields are the same, copy all, and then fixup */
70306 *new = *vma;
70307 + INIT_LIST_HEAD(&new->anon_vma_chain);
70308 *region = *vma->vm_region;
70309 new->vm_region = region;
70310
70311 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
70312 index 2b8ba3a..386d603 100644
70313 --- a/mm/page_alloc.c
70314 +++ b/mm/page_alloc.c
70315 @@ -341,7 +341,7 @@ out:
70316 * This usage means that zero-order pages may not be compound.
70317 */
70318
70319 -static void free_compound_page(struct page *page)
70320 +void free_compound_page(struct page *page)
70321 {
70322 __free_pages_ok(page, compound_order(page));
70323 }
70324 @@ -654,6 +654,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
70325 int i;
70326 int bad = 0;
70327
70328 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
70329 + unsigned long index = 1UL << order;
70330 +#endif
70331 +
70332 trace_mm_page_free_direct(page, order);
70333 kmemcheck_free_shadow(page, order);
70334
70335 @@ -669,6 +673,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
70336 debug_check_no_obj_freed(page_address(page),
70337 PAGE_SIZE << order);
70338 }
70339 +
70340 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
70341 + for (; index; --index)
70342 + sanitize_highpage(page + index - 1);
70343 +#endif
70344 +
70345 arch_free_page(page, order);
70346 kernel_map_pages(page, 1 << order, 0);
70347
70348 @@ -784,8 +794,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
70349 arch_alloc_page(page, order);
70350 kernel_map_pages(page, 1 << order, 1);
70351
70352 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
70353 if (gfp_flags & __GFP_ZERO)
70354 prep_zero_page(page, order, gfp_flags);
70355 +#endif
70356
70357 if (order && (gfp_flags & __GFP_COMP))
70358 prep_compound_page(page, order);
70359 @@ -3357,7 +3369,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
70360 unsigned long pfn;
70361
70362 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
70363 +#ifdef CONFIG_X86_32
70364 + /* boot failures in VMware 8 on 32bit vanilla since
70365 + this change */
70366 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
70367 +#else
70368 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
70369 +#endif
70370 return 1;
70371 }
70372 return 0;
70373 diff --git a/mm/percpu.c b/mm/percpu.c
70374 index 716eb4a..8d10419 100644
70375 --- a/mm/percpu.c
70376 +++ b/mm/percpu.c
70377 @@ -121,7 +121,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
70378 static unsigned int pcpu_high_unit_cpu __read_mostly;
70379
70380 /* the address of the first chunk which starts with the kernel static area */
70381 -void *pcpu_base_addr __read_mostly;
70382 +void *pcpu_base_addr __read_only;
70383 EXPORT_SYMBOL_GPL(pcpu_base_addr);
70384
70385 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
70386 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
70387 index e920aa3..c19184f0 100644
70388 --- a/mm/process_vm_access.c
70389 +++ b/mm/process_vm_access.c
70390 @@ -13,6 +13,7 @@
70391 #include <linux/uio.h>
70392 #include <linux/sched.h>
70393 #include <linux/highmem.h>
70394 +#include <linux/security.h>
70395 #include <linux/ptrace.h>
70396 #include <linux/slab.h>
70397 #include <linux/syscalls.h>
70398 @@ -264,13 +265,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
70399 */
70400 for (i = 0; i < riovcnt; i++) {
70401 iov_len = rvec[i].iov_len;
70402 - if (iov_len > 0) {
70403 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
70404 - + iov_len)
70405 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
70406 - / PAGE_SIZE + 1;
70407 - nr_pages = max(nr_pages, nr_pages_iov);
70408 - }
70409 + if (iov_len <= 0)
70410 + continue;
70411 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
70412 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
70413 + nr_pages = max(nr_pages, nr_pages_iov);
70414 }
70415
70416 if (nr_pages == 0)
70417 @@ -298,8 +297,13 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
70418 goto free_proc_pages;
70419 }
70420
70421 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
70422 + rc = -EPERM;
70423 + goto put_task_struct;
70424 + }
70425 +
70426 task_lock(task);
70427 - if (__ptrace_may_access(task, PTRACE_MODE_ATTACH)) {
70428 + if (ptrace_may_access_nolock(task, PTRACE_MODE_ATTACH)) {
70429 task_unlock(task);
70430 rc = -EPERM;
70431 goto put_task_struct;
70432 diff --git a/mm/rmap.c b/mm/rmap.c
70433 index a4fd368..e0ffec7 100644
70434 --- a/mm/rmap.c
70435 +++ b/mm/rmap.c
70436 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70437 struct anon_vma *anon_vma = vma->anon_vma;
70438 struct anon_vma_chain *avc;
70439
70440 +#ifdef CONFIG_PAX_SEGMEXEC
70441 + struct anon_vma_chain *avc_m = NULL;
70442 +#endif
70443 +
70444 might_sleep();
70445 if (unlikely(!anon_vma)) {
70446 struct mm_struct *mm = vma->vm_mm;
70447 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70448 if (!avc)
70449 goto out_enomem;
70450
70451 +#ifdef CONFIG_PAX_SEGMEXEC
70452 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
70453 + if (!avc_m)
70454 + goto out_enomem_free_avc;
70455 +#endif
70456 +
70457 anon_vma = find_mergeable_anon_vma(vma);
70458 allocated = NULL;
70459 if (!anon_vma) {
70460 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70461 /* page_table_lock to protect against threads */
70462 spin_lock(&mm->page_table_lock);
70463 if (likely(!vma->anon_vma)) {
70464 +
70465 +#ifdef CONFIG_PAX_SEGMEXEC
70466 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
70467 +
70468 + if (vma_m) {
70469 + BUG_ON(vma_m->anon_vma);
70470 + vma_m->anon_vma = anon_vma;
70471 + avc_m->anon_vma = anon_vma;
70472 + avc_m->vma = vma;
70473 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
70474 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
70475 + avc_m = NULL;
70476 + }
70477 +#endif
70478 +
70479 vma->anon_vma = anon_vma;
70480 avc->anon_vma = anon_vma;
70481 avc->vma = vma;
70482 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70483
70484 if (unlikely(allocated))
70485 put_anon_vma(allocated);
70486 +
70487 +#ifdef CONFIG_PAX_SEGMEXEC
70488 + if (unlikely(avc_m))
70489 + anon_vma_chain_free(avc_m);
70490 +#endif
70491 +
70492 if (unlikely(avc))
70493 anon_vma_chain_free(avc);
70494 }
70495 return 0;
70496
70497 out_enomem_free_avc:
70498 +
70499 +#ifdef CONFIG_PAX_SEGMEXEC
70500 + if (avc_m)
70501 + anon_vma_chain_free(avc_m);
70502 +#endif
70503 +
70504 anon_vma_chain_free(avc);
70505 out_enomem:
70506 return -ENOMEM;
70507 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
70508 * Attach the anon_vmas from src to dst.
70509 * Returns 0 on success, -ENOMEM on failure.
70510 */
70511 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
70512 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
70513 {
70514 struct anon_vma_chain *avc, *pavc;
70515 struct anon_vma *root = NULL;
70516 @@ -276,7 +313,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
70517 * the corresponding VMA in the parent process is attached to.
70518 * Returns 0 on success, non-zero on failure.
70519 */
70520 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
70521 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
70522 {
70523 struct anon_vma_chain *avc;
70524 struct anon_vma *anon_vma;
70525 diff --git a/mm/shmem.c b/mm/shmem.c
70526 index d672250..2b233c1 100644
70527 --- a/mm/shmem.c
70528 +++ b/mm/shmem.c
70529 @@ -31,7 +31,7 @@
70530 #include <linux/export.h>
70531 #include <linux/swap.h>
70532
70533 -static struct vfsmount *shm_mnt;
70534 +struct vfsmount *shm_mnt;
70535
70536 #ifdef CONFIG_SHMEM
70537 /*
70538 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
70539 #define BOGO_DIRENT_SIZE 20
70540
70541 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
70542 -#define SHORT_SYMLINK_LEN 128
70543 +#define SHORT_SYMLINK_LEN 64
70544
70545 struct shmem_xattr {
70546 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
70547 @@ -2155,8 +2155,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
70548 int err = -ENOMEM;
70549
70550 /* Round up to L1_CACHE_BYTES to resist false sharing */
70551 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
70552 - L1_CACHE_BYTES), GFP_KERNEL);
70553 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
70554 if (!sbinfo)
70555 return -ENOMEM;
70556
70557 diff --git a/mm/slab.c b/mm/slab.c
70558 index 83311c9a..fcf8f86 100644
70559 --- a/mm/slab.c
70560 +++ b/mm/slab.c
70561 @@ -151,7 +151,7 @@
70562
70563 /* Legal flag mask for kmem_cache_create(). */
70564 #if DEBUG
70565 -# define CREATE_MASK (SLAB_RED_ZONE | \
70566 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
70567 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
70568 SLAB_CACHE_DMA | \
70569 SLAB_STORE_USER | \
70570 @@ -159,7 +159,7 @@
70571 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
70572 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
70573 #else
70574 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
70575 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
70576 SLAB_CACHE_DMA | \
70577 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
70578 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
70579 @@ -288,7 +288,7 @@ struct kmem_list3 {
70580 * Need this for bootstrapping a per node allocator.
70581 */
70582 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
70583 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
70584 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
70585 #define CACHE_CACHE 0
70586 #define SIZE_AC MAX_NUMNODES
70587 #define SIZE_L3 (2 * MAX_NUMNODES)
70588 @@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
70589 if ((x)->max_freeable < i) \
70590 (x)->max_freeable = i; \
70591 } while (0)
70592 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
70593 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
70594 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
70595 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
70596 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
70597 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
70598 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
70599 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
70600 #else
70601 #define STATS_INC_ACTIVE(x) do { } while (0)
70602 #define STATS_DEC_ACTIVE(x) do { } while (0)
70603 @@ -538,7 +538,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
70604 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
70605 */
70606 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
70607 - const struct slab *slab, void *obj)
70608 + const struct slab *slab, const void *obj)
70609 {
70610 u32 offset = (obj - slab->s_mem);
70611 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
70612 @@ -564,7 +564,7 @@ struct cache_names {
70613 static struct cache_names __initdata cache_names[] = {
70614 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
70615 #include <linux/kmalloc_sizes.h>
70616 - {NULL,}
70617 + {NULL}
70618 #undef CACHE
70619 };
70620
70621 @@ -1572,7 +1572,7 @@ void __init kmem_cache_init(void)
70622 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
70623 sizes[INDEX_AC].cs_size,
70624 ARCH_KMALLOC_MINALIGN,
70625 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70626 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70627 NULL);
70628
70629 if (INDEX_AC != INDEX_L3) {
70630 @@ -1580,7 +1580,7 @@ void __init kmem_cache_init(void)
70631 kmem_cache_create(names[INDEX_L3].name,
70632 sizes[INDEX_L3].cs_size,
70633 ARCH_KMALLOC_MINALIGN,
70634 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70635 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70636 NULL);
70637 }
70638
70639 @@ -1598,7 +1598,7 @@ void __init kmem_cache_init(void)
70640 sizes->cs_cachep = kmem_cache_create(names->name,
70641 sizes->cs_size,
70642 ARCH_KMALLOC_MINALIGN,
70643 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70644 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70645 NULL);
70646 }
70647 #ifdef CONFIG_ZONE_DMA
70648 @@ -4322,10 +4322,10 @@ static int s_show(struct seq_file *m, void *p)
70649 }
70650 /* cpu stats */
70651 {
70652 - unsigned long allochit = atomic_read(&cachep->allochit);
70653 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
70654 - unsigned long freehit = atomic_read(&cachep->freehit);
70655 - unsigned long freemiss = atomic_read(&cachep->freemiss);
70656 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
70657 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
70658 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
70659 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
70660
70661 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
70662 allochit, allocmiss, freehit, freemiss);
70663 @@ -4584,13 +4584,62 @@ static int __init slab_proc_init(void)
70664 {
70665 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
70666 #ifdef CONFIG_DEBUG_SLAB_LEAK
70667 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
70668 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
70669 #endif
70670 return 0;
70671 }
70672 module_init(slab_proc_init);
70673 #endif
70674
70675 +void check_object_size(const void *ptr, unsigned long n, bool to)
70676 +{
70677 +
70678 +#ifdef CONFIG_PAX_USERCOPY
70679 + struct page *page;
70680 + struct kmem_cache *cachep = NULL;
70681 + struct slab *slabp;
70682 + unsigned int objnr;
70683 + unsigned long offset;
70684 + const char *type;
70685 +
70686 + if (!n)
70687 + return;
70688 +
70689 + type = "<null>";
70690 + if (ZERO_OR_NULL_PTR(ptr))
70691 + goto report;
70692 +
70693 + if (!virt_addr_valid(ptr))
70694 + return;
70695 +
70696 + page = virt_to_head_page(ptr);
70697 +
70698 + type = "<process stack>";
70699 + if (!PageSlab(page)) {
70700 + if (object_is_on_stack(ptr, n) == -1)
70701 + goto report;
70702 + return;
70703 + }
70704 +
70705 + cachep = page_get_cache(page);
70706 + type = cachep->name;
70707 + if (!(cachep->flags & SLAB_USERCOPY))
70708 + goto report;
70709 +
70710 + slabp = page_get_slab(page);
70711 + objnr = obj_to_index(cachep, slabp, ptr);
70712 + BUG_ON(objnr >= cachep->num);
70713 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
70714 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
70715 + return;
70716 +
70717 +report:
70718 + pax_report_usercopy(ptr, n, to, type);
70719 +#endif
70720 +
70721 +}
70722 +EXPORT_SYMBOL(check_object_size);
70723 +
70724 /**
70725 * ksize - get the actual amount of memory allocated for a given object
70726 * @objp: Pointer to the object
70727 diff --git a/mm/slob.c b/mm/slob.c
70728 index 8105be4..579da9d 100644
70729 --- a/mm/slob.c
70730 +++ b/mm/slob.c
70731 @@ -29,7 +29,7 @@
70732 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
70733 * alloc_pages() directly, allocating compound pages so the page order
70734 * does not have to be separately tracked, and also stores the exact
70735 - * allocation size in page->private so that it can be used to accurately
70736 + * allocation size in slob_page->size so that it can be used to accurately
70737 * provide ksize(). These objects are detected in kfree() because slob_page()
70738 * is false for them.
70739 *
70740 @@ -58,6 +58,7 @@
70741 */
70742
70743 #include <linux/kernel.h>
70744 +#include <linux/sched.h>
70745 #include <linux/slab.h>
70746 #include <linux/mm.h>
70747 #include <linux/swap.h> /* struct reclaim_state */
70748 @@ -102,7 +103,8 @@ struct slob_page {
70749 unsigned long flags; /* mandatory */
70750 atomic_t _count; /* mandatory */
70751 slobidx_t units; /* free units left in page */
70752 - unsigned long pad[2];
70753 + unsigned long pad[1];
70754 + unsigned long size; /* size when >=PAGE_SIZE */
70755 slob_t *free; /* first free slob_t in page */
70756 struct list_head list; /* linked list of free pages */
70757 };
70758 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
70759 */
70760 static inline int is_slob_page(struct slob_page *sp)
70761 {
70762 - return PageSlab((struct page *)sp);
70763 + return PageSlab((struct page *)sp) && !sp->size;
70764 }
70765
70766 static inline void set_slob_page(struct slob_page *sp)
70767 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
70768
70769 static inline struct slob_page *slob_page(const void *addr)
70770 {
70771 - return (struct slob_page *)virt_to_page(addr);
70772 + return (struct slob_page *)virt_to_head_page(addr);
70773 }
70774
70775 /*
70776 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
70777 /*
70778 * Return the size of a slob block.
70779 */
70780 -static slobidx_t slob_units(slob_t *s)
70781 +static slobidx_t slob_units(const slob_t *s)
70782 {
70783 if (s->units > 0)
70784 return s->units;
70785 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
70786 /*
70787 * Return the next free slob block pointer after this one.
70788 */
70789 -static slob_t *slob_next(slob_t *s)
70790 +static slob_t *slob_next(const slob_t *s)
70791 {
70792 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
70793 slobidx_t next;
70794 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
70795 /*
70796 * Returns true if s is the last free block in its page.
70797 */
70798 -static int slob_last(slob_t *s)
70799 +static int slob_last(const slob_t *s)
70800 {
70801 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
70802 }
70803 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
70804 if (!page)
70805 return NULL;
70806
70807 + set_slob_page(page);
70808 return page_address(page);
70809 }
70810
70811 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
70812 if (!b)
70813 return NULL;
70814 sp = slob_page(b);
70815 - set_slob_page(sp);
70816
70817 spin_lock_irqsave(&slob_lock, flags);
70818 sp->units = SLOB_UNITS(PAGE_SIZE);
70819 sp->free = b;
70820 + sp->size = 0;
70821 INIT_LIST_HEAD(&sp->list);
70822 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
70823 set_slob_page_free(sp, slob_list);
70824 @@ -476,10 +479,9 @@ out:
70825 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
70826 */
70827
70828 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70829 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
70830 {
70831 - unsigned int *m;
70832 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70833 + slob_t *m;
70834 void *ret;
70835
70836 gfp &= gfp_allowed_mask;
70837 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70838
70839 if (!m)
70840 return NULL;
70841 - *m = size;
70842 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
70843 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
70844 + m[0].units = size;
70845 + m[1].units = align;
70846 ret = (void *)m + align;
70847
70848 trace_kmalloc_node(_RET_IP_, ret,
70849 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70850 gfp |= __GFP_COMP;
70851 ret = slob_new_pages(gfp, order, node);
70852 if (ret) {
70853 - struct page *page;
70854 - page = virt_to_page(ret);
70855 - page->private = size;
70856 + struct slob_page *sp;
70857 + sp = slob_page(ret);
70858 + sp->size = size;
70859 }
70860
70861 trace_kmalloc_node(_RET_IP_, ret,
70862 size, PAGE_SIZE << order, gfp, node);
70863 }
70864
70865 - kmemleak_alloc(ret, size, 1, gfp);
70866 + return ret;
70867 +}
70868 +
70869 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70870 +{
70871 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70872 + void *ret = __kmalloc_node_align(size, gfp, node, align);
70873 +
70874 + if (!ZERO_OR_NULL_PTR(ret))
70875 + kmemleak_alloc(ret, size, 1, gfp);
70876 return ret;
70877 }
70878 EXPORT_SYMBOL(__kmalloc_node);
70879 @@ -533,13 +547,92 @@ void kfree(const void *block)
70880 sp = slob_page(block);
70881 if (is_slob_page(sp)) {
70882 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70883 - unsigned int *m = (unsigned int *)(block - align);
70884 - slob_free(m, *m + align);
70885 - } else
70886 + slob_t *m = (slob_t *)(block - align);
70887 + slob_free(m, m[0].units + align);
70888 + } else {
70889 + clear_slob_page(sp);
70890 + free_slob_page(sp);
70891 + sp->size = 0;
70892 put_page(&sp->page);
70893 + }
70894 }
70895 EXPORT_SYMBOL(kfree);
70896
70897 +void check_object_size(const void *ptr, unsigned long n, bool to)
70898 +{
70899 +
70900 +#ifdef CONFIG_PAX_USERCOPY
70901 + struct slob_page *sp;
70902 + const slob_t *free;
70903 + const void *base;
70904 + unsigned long flags;
70905 + const char *type;
70906 +
70907 + if (!n)
70908 + return;
70909 +
70910 + type = "<null>";
70911 + if (ZERO_OR_NULL_PTR(ptr))
70912 + goto report;
70913 +
70914 + if (!virt_addr_valid(ptr))
70915 + return;
70916 +
70917 + type = "<process stack>";
70918 + sp = slob_page(ptr);
70919 + if (!PageSlab((struct page*)sp)) {
70920 + if (object_is_on_stack(ptr, n) == -1)
70921 + goto report;
70922 + return;
70923 + }
70924 +
70925 + type = "<slob>";
70926 + if (sp->size) {
70927 + base = page_address(&sp->page);
70928 + if (base <= ptr && n <= sp->size - (ptr - base))
70929 + return;
70930 + goto report;
70931 + }
70932 +
70933 + /* some tricky double walking to find the chunk */
70934 + spin_lock_irqsave(&slob_lock, flags);
70935 + base = (void *)((unsigned long)ptr & PAGE_MASK);
70936 + free = sp->free;
70937 +
70938 + while (!slob_last(free) && (void *)free <= ptr) {
70939 + base = free + slob_units(free);
70940 + free = slob_next(free);
70941 + }
70942 +
70943 + while (base < (void *)free) {
70944 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
70945 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
70946 + int offset;
70947 +
70948 + if (ptr < base + align)
70949 + break;
70950 +
70951 + offset = ptr - base - align;
70952 + if (offset >= m) {
70953 + base += size;
70954 + continue;
70955 + }
70956 +
70957 + if (n > m - offset)
70958 + break;
70959 +
70960 + spin_unlock_irqrestore(&slob_lock, flags);
70961 + return;
70962 + }
70963 +
70964 + spin_unlock_irqrestore(&slob_lock, flags);
70965 +report:
70966 + pax_report_usercopy(ptr, n, to, type);
70967 +#endif
70968 +
70969 +}
70970 +EXPORT_SYMBOL(check_object_size);
70971 +
70972 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
70973 size_t ksize(const void *block)
70974 {
70975 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
70976 sp = slob_page(block);
70977 if (is_slob_page(sp)) {
70978 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70979 - unsigned int *m = (unsigned int *)(block - align);
70980 - return SLOB_UNITS(*m) * SLOB_UNIT;
70981 + slob_t *m = (slob_t *)(block - align);
70982 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
70983 } else
70984 - return sp->page.private;
70985 + return sp->size;
70986 }
70987 EXPORT_SYMBOL(ksize);
70988
70989 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
70990 {
70991 struct kmem_cache *c;
70992
70993 +#ifdef CONFIG_PAX_USERCOPY
70994 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
70995 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
70996 +#else
70997 c = slob_alloc(sizeof(struct kmem_cache),
70998 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
70999 +#endif
71000
71001 if (c) {
71002 c->name = name;
71003 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
71004
71005 lockdep_trace_alloc(flags);
71006
71007 +#ifdef CONFIG_PAX_USERCOPY
71008 + b = __kmalloc_node_align(c->size, flags, node, c->align);
71009 +#else
71010 if (c->size < PAGE_SIZE) {
71011 b = slob_alloc(c->size, flags, c->align, node);
71012 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
71013 SLOB_UNITS(c->size) * SLOB_UNIT,
71014 flags, node);
71015 } else {
71016 + struct slob_page *sp;
71017 +
71018 b = slob_new_pages(flags, get_order(c->size), node);
71019 + sp = slob_page(b);
71020 + sp->size = c->size;
71021 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
71022 PAGE_SIZE << get_order(c->size),
71023 flags, node);
71024 }
71025 +#endif
71026
71027 if (c->ctor)
71028 c->ctor(b);
71029 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
71030
71031 static void __kmem_cache_free(void *b, int size)
71032 {
71033 - if (size < PAGE_SIZE)
71034 + struct slob_page *sp = slob_page(b);
71035 +
71036 + if (is_slob_page(sp))
71037 slob_free(b, size);
71038 - else
71039 + else {
71040 + clear_slob_page(sp);
71041 + free_slob_page(sp);
71042 + sp->size = 0;
71043 slob_free_pages(b, get_order(size));
71044 + }
71045 }
71046
71047 static void kmem_rcu_free(struct rcu_head *head)
71048 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
71049
71050 void kmem_cache_free(struct kmem_cache *c, void *b)
71051 {
71052 + int size = c->size;
71053 +
71054 +#ifdef CONFIG_PAX_USERCOPY
71055 + if (size + c->align < PAGE_SIZE) {
71056 + size += c->align;
71057 + b -= c->align;
71058 + }
71059 +#endif
71060 +
71061 kmemleak_free_recursive(b, c->flags);
71062 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
71063 struct slob_rcu *slob_rcu;
71064 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
71065 - slob_rcu->size = c->size;
71066 + slob_rcu = b + (size - sizeof(struct slob_rcu));
71067 + slob_rcu->size = size;
71068 call_rcu(&slob_rcu->head, kmem_rcu_free);
71069 } else {
71070 - __kmem_cache_free(b, c->size);
71071 + __kmem_cache_free(b, size);
71072 }
71073
71074 +#ifdef CONFIG_PAX_USERCOPY
71075 + trace_kfree(_RET_IP_, b);
71076 +#else
71077 trace_kmem_cache_free(_RET_IP_, b);
71078 +#endif
71079 +
71080 }
71081 EXPORT_SYMBOL(kmem_cache_free);
71082
71083 diff --git a/mm/slub.c b/mm/slub.c
71084 index ed3334d..1739c9b 100644
71085 --- a/mm/slub.c
71086 +++ b/mm/slub.c
71087 @@ -208,7 +208,7 @@ struct track {
71088
71089 enum track_item { TRACK_ALLOC, TRACK_FREE };
71090
71091 -#ifdef CONFIG_SYSFS
71092 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71093 static int sysfs_slab_add(struct kmem_cache *);
71094 static int sysfs_slab_alias(struct kmem_cache *, const char *);
71095 static void sysfs_slab_remove(struct kmem_cache *);
71096 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
71097 if (!t->addr)
71098 return;
71099
71100 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
71101 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
71102 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
71103 #ifdef CONFIG_STACKTRACE
71104 {
71105 @@ -2166,6 +2166,11 @@ redo:
71106 goto new_slab;
71107 }
71108
71109 + /* must check again c->freelist in case of cpu migration or IRQ */
71110 + object = c->freelist;
71111 + if (object)
71112 + goto load_freelist;
71113 +
71114 stat(s, ALLOC_SLOWPATH);
71115
71116 do {
71117 @@ -2554,6 +2559,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
71118
71119 page = virt_to_head_page(x);
71120
71121 + BUG_ON(!PageSlab(page));
71122 +
71123 slab_free(s, page, x, _RET_IP_);
71124
71125 trace_kmem_cache_free(_RET_IP_, x);
71126 @@ -2587,7 +2594,7 @@ static int slub_min_objects;
71127 * Merge control. If this is set then no merging of slab caches will occur.
71128 * (Could be removed. This was introduced to pacify the merge skeptics.)
71129 */
71130 -static int slub_nomerge;
71131 +static int slub_nomerge = 1;
71132
71133 /*
71134 * Calculate the order of allocation given an slab object size.
71135 @@ -3037,7 +3044,7 @@ static int kmem_cache_open(struct kmem_cache *s,
71136 else
71137 s->cpu_partial = 30;
71138
71139 - s->refcount = 1;
71140 + atomic_set(&s->refcount, 1);
71141 #ifdef CONFIG_NUMA
71142 s->remote_node_defrag_ratio = 1000;
71143 #endif
71144 @@ -3141,8 +3148,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
71145 void kmem_cache_destroy(struct kmem_cache *s)
71146 {
71147 down_write(&slub_lock);
71148 - s->refcount--;
71149 - if (!s->refcount) {
71150 + if (atomic_dec_and_test(&s->refcount)) {
71151 list_del(&s->list);
71152 up_write(&slub_lock);
71153 if (kmem_cache_close(s)) {
71154 @@ -3353,6 +3359,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
71155 EXPORT_SYMBOL(__kmalloc_node);
71156 #endif
71157
71158 +void check_object_size(const void *ptr, unsigned long n, bool to)
71159 +{
71160 +
71161 +#ifdef CONFIG_PAX_USERCOPY
71162 + struct page *page;
71163 + struct kmem_cache *s = NULL;
71164 + unsigned long offset;
71165 + const char *type;
71166 +
71167 + if (!n)
71168 + return;
71169 +
71170 + type = "<null>";
71171 + if (ZERO_OR_NULL_PTR(ptr))
71172 + goto report;
71173 +
71174 + if (!virt_addr_valid(ptr))
71175 + return;
71176 +
71177 + page = virt_to_head_page(ptr);
71178 +
71179 + type = "<process stack>";
71180 + if (!PageSlab(page)) {
71181 + if (object_is_on_stack(ptr, n) == -1)
71182 + goto report;
71183 + return;
71184 + }
71185 +
71186 + s = page->slab;
71187 + type = s->name;
71188 + if (!(s->flags & SLAB_USERCOPY))
71189 + goto report;
71190 +
71191 + offset = (ptr - page_address(page)) % s->size;
71192 + if (offset <= s->objsize && n <= s->objsize - offset)
71193 + return;
71194 +
71195 +report:
71196 + pax_report_usercopy(ptr, n, to, type);
71197 +#endif
71198 +
71199 +}
71200 +EXPORT_SYMBOL(check_object_size);
71201 +
71202 size_t ksize(const void *object)
71203 {
71204 struct page *page;
71205 @@ -3627,7 +3677,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
71206 int node;
71207
71208 list_add(&s->list, &slab_caches);
71209 - s->refcount = -1;
71210 + atomic_set(&s->refcount, -1);
71211
71212 for_each_node_state(node, N_NORMAL_MEMORY) {
71213 struct kmem_cache_node *n = get_node(s, node);
71214 @@ -3744,17 +3794,17 @@ void __init kmem_cache_init(void)
71215
71216 /* Caches that are not of the two-to-the-power-of size */
71217 if (KMALLOC_MIN_SIZE <= 32) {
71218 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
71219 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
71220 caches++;
71221 }
71222
71223 if (KMALLOC_MIN_SIZE <= 64) {
71224 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
71225 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
71226 caches++;
71227 }
71228
71229 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
71230 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
71231 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
71232 caches++;
71233 }
71234
71235 @@ -3822,7 +3872,7 @@ static int slab_unmergeable(struct kmem_cache *s)
71236 /*
71237 * We may have set a slab to be unmergeable during bootstrap.
71238 */
71239 - if (s->refcount < 0)
71240 + if (atomic_read(&s->refcount) < 0)
71241 return 1;
71242
71243 return 0;
71244 @@ -3881,7 +3931,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71245 down_write(&slub_lock);
71246 s = find_mergeable(size, align, flags, name, ctor);
71247 if (s) {
71248 - s->refcount++;
71249 + atomic_inc(&s->refcount);
71250 /*
71251 * Adjust the object sizes so that we clear
71252 * the complete object on kzalloc.
71253 @@ -3890,7 +3940,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71254 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
71255
71256 if (sysfs_slab_alias(s, name)) {
71257 - s->refcount--;
71258 + atomic_dec(&s->refcount);
71259 goto err;
71260 }
71261 up_write(&slub_lock);
71262 @@ -4018,7 +4068,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
71263 }
71264 #endif
71265
71266 -#ifdef CONFIG_SYSFS
71267 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71268 static int count_inuse(struct page *page)
71269 {
71270 return page->inuse;
71271 @@ -4405,12 +4455,12 @@ static void resiliency_test(void)
71272 validate_slab_cache(kmalloc_caches[9]);
71273 }
71274 #else
71275 -#ifdef CONFIG_SYSFS
71276 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71277 static void resiliency_test(void) {};
71278 #endif
71279 #endif
71280
71281 -#ifdef CONFIG_SYSFS
71282 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71283 enum slab_stat_type {
71284 SL_ALL, /* All slabs */
71285 SL_PARTIAL, /* Only partially allocated slabs */
71286 @@ -4651,7 +4701,7 @@ SLAB_ATTR_RO(ctor);
71287
71288 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
71289 {
71290 - return sprintf(buf, "%d\n", s->refcount - 1);
71291 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
71292 }
71293 SLAB_ATTR_RO(aliases);
71294
71295 @@ -5218,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
71296 return name;
71297 }
71298
71299 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71300 static int sysfs_slab_add(struct kmem_cache *s)
71301 {
71302 int err;
71303 @@ -5280,6 +5331,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
71304 kobject_del(&s->kobj);
71305 kobject_put(&s->kobj);
71306 }
71307 +#endif
71308
71309 /*
71310 * Need to buffer aliases during bootup until sysfs becomes
71311 @@ -5293,6 +5345,7 @@ struct saved_alias {
71312
71313 static struct saved_alias *alias_list;
71314
71315 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71316 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
71317 {
71318 struct saved_alias *al;
71319 @@ -5315,6 +5368,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
71320 alias_list = al;
71321 return 0;
71322 }
71323 +#endif
71324
71325 static int __init slab_sysfs_init(void)
71326 {
71327 diff --git a/mm/swap.c b/mm/swap.c
71328 index a91caf7..b887e735 100644
71329 --- a/mm/swap.c
71330 +++ b/mm/swap.c
71331 @@ -31,6 +31,7 @@
71332 #include <linux/backing-dev.h>
71333 #include <linux/memcontrol.h>
71334 #include <linux/gfp.h>
71335 +#include <linux/hugetlb.h>
71336
71337 #include "internal.h"
71338
71339 @@ -71,6 +72,8 @@ static void __put_compound_page(struct page *page)
71340
71341 __page_cache_release(page);
71342 dtor = get_compound_page_dtor(page);
71343 + if (!PageHuge(page))
71344 + BUG_ON(dtor != free_compound_page);
71345 (*dtor)(page);
71346 }
71347
71348 diff --git a/mm/swapfile.c b/mm/swapfile.c
71349 index b1cd120..aaae885 100644
71350 --- a/mm/swapfile.c
71351 +++ b/mm/swapfile.c
71352 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
71353
71354 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
71355 /* Activity counter to indicate that a swapon or swapoff has occurred */
71356 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
71357 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
71358
71359 static inline unsigned char swap_count(unsigned char ent)
71360 {
71361 @@ -1670,7 +1670,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
71362 }
71363 filp_close(swap_file, NULL);
71364 err = 0;
71365 - atomic_inc(&proc_poll_event);
71366 + atomic_inc_unchecked(&proc_poll_event);
71367 wake_up_interruptible(&proc_poll_wait);
71368
71369 out_dput:
71370 @@ -1686,8 +1686,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
71371
71372 poll_wait(file, &proc_poll_wait, wait);
71373
71374 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
71375 - seq->poll_event = atomic_read(&proc_poll_event);
71376 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
71377 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
71378 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
71379 }
71380
71381 @@ -1785,7 +1785,7 @@ static int swaps_open(struct inode *inode, struct file *file)
71382 return ret;
71383
71384 seq = file->private_data;
71385 - seq->poll_event = atomic_read(&proc_poll_event);
71386 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
71387 return 0;
71388 }
71389
71390 @@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
71391 (p->flags & SWP_DISCARDABLE) ? "D" : "");
71392
71393 mutex_unlock(&swapon_mutex);
71394 - atomic_inc(&proc_poll_event);
71395 + atomic_inc_unchecked(&proc_poll_event);
71396 wake_up_interruptible(&proc_poll_wait);
71397
71398 if (S_ISREG(inode->i_mode))
71399 diff --git a/mm/util.c b/mm/util.c
71400 index 136ac4f..5117eef 100644
71401 --- a/mm/util.c
71402 +++ b/mm/util.c
71403 @@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
71404 * allocated buffer. Use this if you don't want to free the buffer immediately
71405 * like, for example, with RCU.
71406 */
71407 +#undef __krealloc
71408 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
71409 {
71410 void *ret;
71411 @@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
71412 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
71413 * %NULL pointer, the object pointed to is freed.
71414 */
71415 +#undef krealloc
71416 void *krealloc(const void *p, size_t new_size, gfp_t flags)
71417 {
71418 void *ret;
71419 @@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
71420 void arch_pick_mmap_layout(struct mm_struct *mm)
71421 {
71422 mm->mmap_base = TASK_UNMAPPED_BASE;
71423 +
71424 +#ifdef CONFIG_PAX_RANDMMAP
71425 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71426 + mm->mmap_base += mm->delta_mmap;
71427 +#endif
71428 +
71429 mm->get_unmapped_area = arch_get_unmapped_area;
71430 mm->unmap_area = arch_unmap_area;
71431 }
71432 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
71433 index 27be2f0..0aef2c2 100644
71434 --- a/mm/vmalloc.c
71435 +++ b/mm/vmalloc.c
71436 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
71437
71438 pte = pte_offset_kernel(pmd, addr);
71439 do {
71440 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
71441 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
71442 +
71443 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71444 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
71445 + BUG_ON(!pte_exec(*pte));
71446 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
71447 + continue;
71448 + }
71449 +#endif
71450 +
71451 + {
71452 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
71453 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
71454 + }
71455 } while (pte++, addr += PAGE_SIZE, addr != end);
71456 }
71457
71458 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
71459 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
71460 {
71461 pte_t *pte;
71462 + int ret = -ENOMEM;
71463
71464 /*
71465 * nr is a running index into the array which helps higher level
71466 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
71467 pte = pte_alloc_kernel(pmd, addr);
71468 if (!pte)
71469 return -ENOMEM;
71470 +
71471 + pax_open_kernel();
71472 do {
71473 struct page *page = pages[*nr];
71474
71475 - if (WARN_ON(!pte_none(*pte)))
71476 - return -EBUSY;
71477 - if (WARN_ON(!page))
71478 - return -ENOMEM;
71479 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71480 + if (pgprot_val(prot) & _PAGE_NX)
71481 +#endif
71482 +
71483 + if (WARN_ON(!pte_none(*pte))) {
71484 + ret = -EBUSY;
71485 + goto out;
71486 + }
71487 + if (WARN_ON(!page)) {
71488 + ret = -ENOMEM;
71489 + goto out;
71490 + }
71491 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
71492 (*nr)++;
71493 } while (pte++, addr += PAGE_SIZE, addr != end);
71494 - return 0;
71495 + ret = 0;
71496 +out:
71497 + pax_close_kernel();
71498 + return ret;
71499 }
71500
71501 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
71502 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
71503 * and fall back on vmalloc() if that fails. Others
71504 * just put it in the vmalloc space.
71505 */
71506 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
71507 +#ifdef CONFIG_MODULES
71508 +#ifdef MODULES_VADDR
71509 unsigned long addr = (unsigned long)x;
71510 if (addr >= MODULES_VADDR && addr < MODULES_END)
71511 return 1;
71512 #endif
71513 +
71514 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71515 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
71516 + return 1;
71517 +#endif
71518 +
71519 +#endif
71520 +
71521 return is_vmalloc_addr(x);
71522 }
71523
71524 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
71525
71526 if (!pgd_none(*pgd)) {
71527 pud_t *pud = pud_offset(pgd, addr);
71528 +#ifdef CONFIG_X86
71529 + if (!pud_large(*pud))
71530 +#endif
71531 if (!pud_none(*pud)) {
71532 pmd_t *pmd = pmd_offset(pud, addr);
71533 +#ifdef CONFIG_X86
71534 + if (!pmd_large(*pmd))
71535 +#endif
71536 if (!pmd_none(*pmd)) {
71537 pte_t *ptep, pte;
71538
71539 @@ -1294,6 +1334,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
71540 struct vm_struct *area;
71541
71542 BUG_ON(in_interrupt());
71543 +
71544 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71545 + if (flags & VM_KERNEXEC) {
71546 + if (start != VMALLOC_START || end != VMALLOC_END)
71547 + return NULL;
71548 + start = (unsigned long)MODULES_EXEC_VADDR;
71549 + end = (unsigned long)MODULES_EXEC_END;
71550 + }
71551 +#endif
71552 +
71553 if (flags & VM_IOREMAP) {
71554 int bit = fls(size);
71555
71556 @@ -1526,6 +1576,11 @@ void *vmap(struct page **pages, unsigned int count,
71557 if (count > totalram_pages)
71558 return NULL;
71559
71560 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71561 + if (!(pgprot_val(prot) & _PAGE_NX))
71562 + flags |= VM_KERNEXEC;
71563 +#endif
71564 +
71565 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
71566 __builtin_return_address(0));
71567 if (!area)
71568 @@ -1627,6 +1682,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
71569 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
71570 goto fail;
71571
71572 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71573 + if (!(pgprot_val(prot) & _PAGE_NX))
71574 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
71575 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
71576 + else
71577 +#endif
71578 +
71579 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
71580 start, end, node, gfp_mask, caller);
71581 if (!area)
71582 @@ -1679,6 +1741,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
71583 gfp_mask, prot, node, caller);
71584 }
71585
71586 +#undef __vmalloc
71587 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
71588 {
71589 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
71590 @@ -1702,6 +1765,7 @@ static inline void *__vmalloc_node_flags(unsigned long size,
71591 * For tight control over page level allocator and protection flags
71592 * use __vmalloc() instead.
71593 */
71594 +#undef vmalloc
71595 void *vmalloc(unsigned long size)
71596 {
71597 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
71598 @@ -1718,6 +1782,7 @@ EXPORT_SYMBOL(vmalloc);
71599 * For tight control over page level allocator and protection flags
71600 * use __vmalloc() instead.
71601 */
71602 +#undef vzalloc
71603 void *vzalloc(unsigned long size)
71604 {
71605 return __vmalloc_node_flags(size, -1,
71606 @@ -1732,6 +1797,7 @@ EXPORT_SYMBOL(vzalloc);
71607 * The resulting memory area is zeroed so it can be mapped to userspace
71608 * without leaking data.
71609 */
71610 +#undef vmalloc_user
71611 void *vmalloc_user(unsigned long size)
71612 {
71613 struct vm_struct *area;
71614 @@ -1759,6 +1825,7 @@ EXPORT_SYMBOL(vmalloc_user);
71615 * For tight control over page level allocator and protection flags
71616 * use __vmalloc() instead.
71617 */
71618 +#undef vmalloc_node
71619 void *vmalloc_node(unsigned long size, int node)
71620 {
71621 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
71622 @@ -1778,6 +1845,7 @@ EXPORT_SYMBOL(vmalloc_node);
71623 * For tight control over page level allocator and protection flags
71624 * use __vmalloc_node() instead.
71625 */
71626 +#undef vzalloc_node
71627 void *vzalloc_node(unsigned long size, int node)
71628 {
71629 return __vmalloc_node_flags(size, node,
71630 @@ -1800,10 +1868,10 @@ EXPORT_SYMBOL(vzalloc_node);
71631 * For tight control over page level allocator and protection flags
71632 * use __vmalloc() instead.
71633 */
71634 -
71635 +#undef vmalloc_exec
71636 void *vmalloc_exec(unsigned long size)
71637 {
71638 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
71639 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
71640 -1, __builtin_return_address(0));
71641 }
71642
71643 @@ -1822,6 +1890,7 @@ void *vmalloc_exec(unsigned long size)
71644 * Allocate enough 32bit PA addressable pages to cover @size from the
71645 * page level allocator and map them into contiguous kernel virtual space.
71646 */
71647 +#undef vmalloc_32
71648 void *vmalloc_32(unsigned long size)
71649 {
71650 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
71651 @@ -1836,6 +1905,7 @@ EXPORT_SYMBOL(vmalloc_32);
71652 * The resulting memory area is 32bit addressable and zeroed so it can be
71653 * mapped to userspace without leaking data.
71654 */
71655 +#undef vmalloc_32_user
71656 void *vmalloc_32_user(unsigned long size)
71657 {
71658 struct vm_struct *area;
71659 @@ -2098,6 +2168,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
71660 unsigned long uaddr = vma->vm_start;
71661 unsigned long usize = vma->vm_end - vma->vm_start;
71662
71663 + BUG_ON(vma->vm_mirror);
71664 +
71665 if ((PAGE_SIZE-1) & (unsigned long)addr)
71666 return -EINVAL;
71667
71668 diff --git a/mm/vmstat.c b/mm/vmstat.c
71669 index 8fd603b..cf0d930 100644
71670 --- a/mm/vmstat.c
71671 +++ b/mm/vmstat.c
71672 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
71673 *
71674 * vm_stat contains the global counters
71675 */
71676 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
71677 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
71678 EXPORT_SYMBOL(vm_stat);
71679
71680 #ifdef CONFIG_SMP
71681 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
71682 v = p->vm_stat_diff[i];
71683 p->vm_stat_diff[i] = 0;
71684 local_irq_restore(flags);
71685 - atomic_long_add(v, &zone->vm_stat[i]);
71686 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
71687 global_diff[i] += v;
71688 #ifdef CONFIG_NUMA
71689 /* 3 seconds idle till flush */
71690 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
71691
71692 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
71693 if (global_diff[i])
71694 - atomic_long_add(global_diff[i], &vm_stat[i]);
71695 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
71696 }
71697
71698 #endif
71699 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
71700 start_cpu_timer(cpu);
71701 #endif
71702 #ifdef CONFIG_PROC_FS
71703 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
71704 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
71705 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
71706 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
71707 + {
71708 + mode_t gr_mode = S_IRUGO;
71709 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71710 + gr_mode = S_IRUSR;
71711 +#endif
71712 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
71713 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
71714 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
71715 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
71716 +#else
71717 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
71718 +#endif
71719 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
71720 + }
71721 #endif
71722 return 0;
71723 }
71724 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
71725 index 5471628..cef8398 100644
71726 --- a/net/8021q/vlan.c
71727 +++ b/net/8021q/vlan.c
71728 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
71729 err = -EPERM;
71730 if (!capable(CAP_NET_ADMIN))
71731 break;
71732 - if ((args.u.name_type >= 0) &&
71733 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
71734 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
71735 struct vlan_net *vn;
71736
71737 vn = net_generic(net, vlan_net_id);
71738 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
71739 index fdfdb57..38d368c 100644
71740 --- a/net/9p/trans_fd.c
71741 +++ b/net/9p/trans_fd.c
71742 @@ -423,7 +423,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
71743 oldfs = get_fs();
71744 set_fs(get_ds());
71745 /* The cast to a user pointer is valid due to the set_fs() */
71746 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
71747 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
71748 set_fs(oldfs);
71749
71750 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
71751 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
71752 index f41f026..fe76ea8 100644
71753 --- a/net/atm/atm_misc.c
71754 +++ b/net/atm/atm_misc.c
71755 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
71756 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
71757 return 1;
71758 atm_return(vcc, truesize);
71759 - atomic_inc(&vcc->stats->rx_drop);
71760 + atomic_inc_unchecked(&vcc->stats->rx_drop);
71761 return 0;
71762 }
71763 EXPORT_SYMBOL(atm_charge);
71764 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
71765 }
71766 }
71767 atm_return(vcc, guess);
71768 - atomic_inc(&vcc->stats->rx_drop);
71769 + atomic_inc_unchecked(&vcc->stats->rx_drop);
71770 return NULL;
71771 }
71772 EXPORT_SYMBOL(atm_alloc_charge);
71773 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
71774
71775 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
71776 {
71777 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
71778 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
71779 __SONET_ITEMS
71780 #undef __HANDLE_ITEM
71781 }
71782 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
71783
71784 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
71785 {
71786 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
71787 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
71788 __SONET_ITEMS
71789 #undef __HANDLE_ITEM
71790 }
71791 diff --git a/net/atm/lec.h b/net/atm/lec.h
71792 index dfc0719..47c5322 100644
71793 --- a/net/atm/lec.h
71794 +++ b/net/atm/lec.h
71795 @@ -48,7 +48,7 @@ struct lane2_ops {
71796 const u8 *tlvs, u32 sizeoftlvs);
71797 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
71798 const u8 *tlvs, u32 sizeoftlvs);
71799 -};
71800 +} __no_const;
71801
71802 /*
71803 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
71804 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
71805 index 0919a88..a23d54e 100644
71806 --- a/net/atm/mpc.h
71807 +++ b/net/atm/mpc.h
71808 @@ -33,7 +33,7 @@ struct mpoa_client {
71809 struct mpc_parameters parameters; /* parameters for this client */
71810
71811 const struct net_device_ops *old_ops;
71812 - struct net_device_ops new_ops;
71813 + net_device_ops_no_const new_ops;
71814 };
71815
71816
71817 diff --git a/net/atm/proc.c b/net/atm/proc.c
71818 index 0d020de..011c7bb 100644
71819 --- a/net/atm/proc.c
71820 +++ b/net/atm/proc.c
71821 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
71822 const struct k_atm_aal_stats *stats)
71823 {
71824 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
71825 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
71826 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
71827 - atomic_read(&stats->rx_drop));
71828 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
71829 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
71830 + atomic_read_unchecked(&stats->rx_drop));
71831 }
71832
71833 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
71834 diff --git a/net/atm/resources.c b/net/atm/resources.c
71835 index 23f45ce..c748f1a 100644
71836 --- a/net/atm/resources.c
71837 +++ b/net/atm/resources.c
71838 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
71839 static void copy_aal_stats(struct k_atm_aal_stats *from,
71840 struct atm_aal_stats *to)
71841 {
71842 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
71843 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
71844 __AAL_STAT_ITEMS
71845 #undef __HANDLE_ITEM
71846 }
71847 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
71848 static void subtract_aal_stats(struct k_atm_aal_stats *from,
71849 struct atm_aal_stats *to)
71850 {
71851 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
71852 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
71853 __AAL_STAT_ITEMS
71854 #undef __HANDLE_ITEM
71855 }
71856 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
71857 index 3512e25..2b33401 100644
71858 --- a/net/batman-adv/bat_iv_ogm.c
71859 +++ b/net/batman-adv/bat_iv_ogm.c
71860 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
71861
71862 /* change sequence number to network order */
71863 batman_ogm_packet->seqno =
71864 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
71865 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
71866
71867 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
71868 batman_ogm_packet->tt_crc = htons((uint16_t)
71869 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
71870 else
71871 batman_ogm_packet->gw_flags = NO_FLAGS;
71872
71873 - atomic_inc(&hard_iface->seqno);
71874 + atomic_inc_unchecked(&hard_iface->seqno);
71875
71876 slide_own_bcast_window(hard_iface);
71877 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
71878 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
71879 return;
71880
71881 /* could be changed by schedule_own_packet() */
71882 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
71883 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
71884
71885 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
71886
71887 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
71888 index 7704df4..beb4e16 100644
71889 --- a/net/batman-adv/hard-interface.c
71890 +++ b/net/batman-adv/hard-interface.c
71891 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
71892 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
71893 dev_add_pack(&hard_iface->batman_adv_ptype);
71894
71895 - atomic_set(&hard_iface->seqno, 1);
71896 - atomic_set(&hard_iface->frag_seqno, 1);
71897 + atomic_set_unchecked(&hard_iface->seqno, 1);
71898 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
71899 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
71900 hard_iface->net_dev->name);
71901
71902 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
71903 index f9cc957..efd9dae 100644
71904 --- a/net/batman-adv/soft-interface.c
71905 +++ b/net/batman-adv/soft-interface.c
71906 @@ -634,7 +634,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
71907
71908 /* set broadcast sequence number */
71909 bcast_packet->seqno =
71910 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
71911 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
71912
71913 add_bcast_packet_to_list(bat_priv, skb, 1);
71914
71915 @@ -828,7 +828,7 @@ struct net_device *softif_create(const char *name)
71916 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
71917
71918 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
71919 - atomic_set(&bat_priv->bcast_seqno, 1);
71920 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
71921 atomic_set(&bat_priv->ttvn, 0);
71922 atomic_set(&bat_priv->tt_local_changes, 0);
71923 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
71924 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
71925 index ab8d0fe..ceba3fd 100644
71926 --- a/net/batman-adv/types.h
71927 +++ b/net/batman-adv/types.h
71928 @@ -38,8 +38,8 @@ struct hard_iface {
71929 int16_t if_num;
71930 char if_status;
71931 struct net_device *net_dev;
71932 - atomic_t seqno;
71933 - atomic_t frag_seqno;
71934 + atomic_unchecked_t seqno;
71935 + atomic_unchecked_t frag_seqno;
71936 unsigned char *packet_buff;
71937 int packet_len;
71938 struct kobject *hardif_obj;
71939 @@ -154,7 +154,7 @@ struct bat_priv {
71940 atomic_t orig_interval; /* uint */
71941 atomic_t hop_penalty; /* uint */
71942 atomic_t log_level; /* uint */
71943 - atomic_t bcast_seqno;
71944 + atomic_unchecked_t bcast_seqno;
71945 atomic_t bcast_queue_left;
71946 atomic_t batman_queue_left;
71947 atomic_t ttvn; /* translation table version number */
71948 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
71949 index 07d1c1d..7e9bea9 100644
71950 --- a/net/batman-adv/unicast.c
71951 +++ b/net/batman-adv/unicast.c
71952 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
71953 frag1->flags = UNI_FRAG_HEAD | large_tail;
71954 frag2->flags = large_tail;
71955
71956 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
71957 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
71958 frag1->seqno = htons(seqno - 1);
71959 frag2->seqno = htons(seqno);
71960
71961 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
71962 index c1c597e..05ebb40 100644
71963 --- a/net/bluetooth/hci_conn.c
71964 +++ b/net/bluetooth/hci_conn.c
71965 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
71966 memset(&cp, 0, sizeof(cp));
71967
71968 cp.handle = cpu_to_le16(conn->handle);
71969 - memcpy(cp.ltk, ltk, sizeof(ltk));
71970 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
71971
71972 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
71973 }
71974 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
71975 index 17b5b1c..826d872 100644
71976 --- a/net/bluetooth/l2cap_core.c
71977 +++ b/net/bluetooth/l2cap_core.c
71978 @@ -2176,8 +2176,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
71979 break;
71980
71981 case L2CAP_CONF_RFC:
71982 - if (olen == sizeof(rfc))
71983 - memcpy(&rfc, (void *)val, olen);
71984 + if (olen != sizeof(rfc))
71985 + break;
71986 +
71987 + memcpy(&rfc, (void *)val, olen);
71988
71989 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
71990 rfc.mode != chan->mode)
71991 @@ -2265,8 +2267,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
71992
71993 switch (type) {
71994 case L2CAP_CONF_RFC:
71995 - if (olen == sizeof(rfc))
71996 - memcpy(&rfc, (void *)val, olen);
71997 + if (olen != sizeof(rfc))
71998 + break;
71999 +
72000 + memcpy(&rfc, (void *)val, olen);
72001 goto done;
72002 }
72003 }
72004 diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
72005 index a5f4e57..910ee6d 100644
72006 --- a/net/bridge/br_multicast.c
72007 +++ b/net/bridge/br_multicast.c
72008 @@ -1485,7 +1485,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
72009 nexthdr = ip6h->nexthdr;
72010 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
72011
72012 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
72013 + if (nexthdr != IPPROTO_ICMPV6)
72014 return 0;
72015
72016 /* Okay, we found ICMPv6 header */
72017 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
72018 index 5864cc4..121f3a3 100644
72019 --- a/net/bridge/netfilter/ebtables.c
72020 +++ b/net/bridge/netfilter/ebtables.c
72021 @@ -1513,7 +1513,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
72022 tmp.valid_hooks = t->table->valid_hooks;
72023 }
72024 mutex_unlock(&ebt_mutex);
72025 - if (copy_to_user(user, &tmp, *len) != 0){
72026 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
72027 BUGPRINT("c2u Didn't work\n");
72028 ret = -EFAULT;
72029 break;
72030 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
72031 index a986280..13444a1 100644
72032 --- a/net/caif/caif_socket.c
72033 +++ b/net/caif/caif_socket.c
72034 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
72035 #ifdef CONFIG_DEBUG_FS
72036 struct debug_fs_counter {
72037 atomic_t caif_nr_socks;
72038 - atomic_t caif_sock_create;
72039 - atomic_t num_connect_req;
72040 - atomic_t num_connect_resp;
72041 - atomic_t num_connect_fail_resp;
72042 - atomic_t num_disconnect;
72043 - atomic_t num_remote_shutdown_ind;
72044 - atomic_t num_tx_flow_off_ind;
72045 - atomic_t num_tx_flow_on_ind;
72046 - atomic_t num_rx_flow_off;
72047 - atomic_t num_rx_flow_on;
72048 + atomic_unchecked_t caif_sock_create;
72049 + atomic_unchecked_t num_connect_req;
72050 + atomic_unchecked_t num_connect_resp;
72051 + atomic_unchecked_t num_connect_fail_resp;
72052 + atomic_unchecked_t num_disconnect;
72053 + atomic_unchecked_t num_remote_shutdown_ind;
72054 + atomic_unchecked_t num_tx_flow_off_ind;
72055 + atomic_unchecked_t num_tx_flow_on_ind;
72056 + atomic_unchecked_t num_rx_flow_off;
72057 + atomic_unchecked_t num_rx_flow_on;
72058 };
72059 static struct debug_fs_counter cnt;
72060 #define dbfs_atomic_inc(v) atomic_inc_return(v)
72061 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
72062 #define dbfs_atomic_dec(v) atomic_dec_return(v)
72063 #else
72064 #define dbfs_atomic_inc(v) 0
72065 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72066 atomic_read(&cf_sk->sk.sk_rmem_alloc),
72067 sk_rcvbuf_lowwater(cf_sk));
72068 set_rx_flow_off(cf_sk);
72069 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
72070 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
72071 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
72072 }
72073
72074 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72075 set_rx_flow_off(cf_sk);
72076 if (net_ratelimit())
72077 pr_debug("sending flow OFF due to rmem_schedule\n");
72078 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
72079 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
72080 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
72081 }
72082 skb->dev = NULL;
72083 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
72084 switch (flow) {
72085 case CAIF_CTRLCMD_FLOW_ON_IND:
72086 /* OK from modem to start sending again */
72087 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
72088 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
72089 set_tx_flow_on(cf_sk);
72090 cf_sk->sk.sk_state_change(&cf_sk->sk);
72091 break;
72092
72093 case CAIF_CTRLCMD_FLOW_OFF_IND:
72094 /* Modem asks us to shut up */
72095 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
72096 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
72097 set_tx_flow_off(cf_sk);
72098 cf_sk->sk.sk_state_change(&cf_sk->sk);
72099 break;
72100 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72101 /* We're now connected */
72102 caif_client_register_refcnt(&cf_sk->layer,
72103 cfsk_hold, cfsk_put);
72104 - dbfs_atomic_inc(&cnt.num_connect_resp);
72105 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
72106 cf_sk->sk.sk_state = CAIF_CONNECTED;
72107 set_tx_flow_on(cf_sk);
72108 cf_sk->sk.sk_state_change(&cf_sk->sk);
72109 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72110
72111 case CAIF_CTRLCMD_INIT_FAIL_RSP:
72112 /* Connect request failed */
72113 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
72114 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
72115 cf_sk->sk.sk_err = ECONNREFUSED;
72116 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
72117 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
72118 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72119
72120 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
72121 /* Modem has closed this connection, or device is down. */
72122 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
72123 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
72124 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
72125 cf_sk->sk.sk_err = ECONNRESET;
72126 set_rx_flow_on(cf_sk);
72127 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
72128 return;
72129
72130 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
72131 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
72132 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
72133 set_rx_flow_on(cf_sk);
72134 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
72135 }
72136 @@ -854,7 +855,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
72137 /*ifindex = id of the interface.*/
72138 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
72139
72140 - dbfs_atomic_inc(&cnt.num_connect_req);
72141 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
72142 cf_sk->layer.receive = caif_sktrecv_cb;
72143
72144 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
72145 @@ -943,7 +944,7 @@ static int caif_release(struct socket *sock)
72146 spin_unlock_bh(&sk->sk_receive_queue.lock);
72147 sock->sk = NULL;
72148
72149 - dbfs_atomic_inc(&cnt.num_disconnect);
72150 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
72151
72152 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
72153 if (cf_sk->debugfs_socket_dir != NULL)
72154 @@ -1122,7 +1123,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
72155 cf_sk->conn_req.protocol = protocol;
72156 /* Increase the number of sockets created. */
72157 dbfs_atomic_inc(&cnt.caif_nr_socks);
72158 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
72159 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
72160 #ifdef CONFIG_DEBUG_FS
72161 if (!IS_ERR(debugfsdir)) {
72162
72163 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
72164 index 5cf5222..6f704ad 100644
72165 --- a/net/caif/cfctrl.c
72166 +++ b/net/caif/cfctrl.c
72167 @@ -9,6 +9,7 @@
72168 #include <linux/stddef.h>
72169 #include <linux/spinlock.h>
72170 #include <linux/slab.h>
72171 +#include <linux/sched.h>
72172 #include <net/caif/caif_layer.h>
72173 #include <net/caif/cfpkt.h>
72174 #include <net/caif/cfctrl.h>
72175 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
72176 memset(&dev_info, 0, sizeof(dev_info));
72177 dev_info.id = 0xff;
72178 cfsrvl_init(&this->serv, 0, &dev_info, false);
72179 - atomic_set(&this->req_seq_no, 1);
72180 - atomic_set(&this->rsp_seq_no, 1);
72181 + atomic_set_unchecked(&this->req_seq_no, 1);
72182 + atomic_set_unchecked(&this->rsp_seq_no, 1);
72183 this->serv.layer.receive = cfctrl_recv;
72184 sprintf(this->serv.layer.name, "ctrl");
72185 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
72186 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
72187 struct cfctrl_request_info *req)
72188 {
72189 spin_lock_bh(&ctrl->info_list_lock);
72190 - atomic_inc(&ctrl->req_seq_no);
72191 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
72192 + atomic_inc_unchecked(&ctrl->req_seq_no);
72193 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
72194 list_add_tail(&req->list, &ctrl->list);
72195 spin_unlock_bh(&ctrl->info_list_lock);
72196 }
72197 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
72198 if (p != first)
72199 pr_warn("Requests are not received in order\n");
72200
72201 - atomic_set(&ctrl->rsp_seq_no,
72202 + atomic_set_unchecked(&ctrl->rsp_seq_no,
72203 p->sequence_no);
72204 list_del(&p->list);
72205 goto out;
72206 diff --git a/net/can/gw.c b/net/can/gw.c
72207 index 3d79b12..8de85fa 100644
72208 --- a/net/can/gw.c
72209 +++ b/net/can/gw.c
72210 @@ -96,7 +96,7 @@ struct cf_mod {
72211 struct {
72212 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
72213 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
72214 - } csumfunc;
72215 + } __no_const csumfunc;
72216 };
72217
72218
72219 diff --git a/net/compat.c b/net/compat.c
72220 index 6def90e..c6992fa 100644
72221 --- a/net/compat.c
72222 +++ b/net/compat.c
72223 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
72224 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
72225 __get_user(kmsg->msg_flags, &umsg->msg_flags))
72226 return -EFAULT;
72227 - kmsg->msg_name = compat_ptr(tmp1);
72228 - kmsg->msg_iov = compat_ptr(tmp2);
72229 - kmsg->msg_control = compat_ptr(tmp3);
72230 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
72231 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
72232 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
72233 return 0;
72234 }
72235
72236 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72237
72238 if (kern_msg->msg_namelen) {
72239 if (mode == VERIFY_READ) {
72240 - int err = move_addr_to_kernel(kern_msg->msg_name,
72241 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
72242 kern_msg->msg_namelen,
72243 kern_address);
72244 if (err < 0)
72245 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72246 kern_msg->msg_name = NULL;
72247
72248 tot_len = iov_from_user_compat_to_kern(kern_iov,
72249 - (struct compat_iovec __user *)kern_msg->msg_iov,
72250 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
72251 kern_msg->msg_iovlen);
72252 if (tot_len >= 0)
72253 kern_msg->msg_iov = kern_iov;
72254 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72255
72256 #define CMSG_COMPAT_FIRSTHDR(msg) \
72257 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
72258 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
72259 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
72260 (struct compat_cmsghdr __user *)NULL)
72261
72262 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
72263 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
72264 (ucmlen) <= (unsigned long) \
72265 ((mhdr)->msg_controllen - \
72266 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
72267 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
72268
72269 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
72270 struct compat_cmsghdr __user *cmsg, int cmsg_len)
72271 {
72272 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
72273 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
72274 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
72275 msg->msg_controllen)
72276 return NULL;
72277 return (struct compat_cmsghdr __user *)ptr;
72278 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
72279 {
72280 struct compat_timeval ctv;
72281 struct compat_timespec cts[3];
72282 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
72283 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
72284 struct compat_cmsghdr cmhdr;
72285 int cmlen;
72286
72287 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
72288
72289 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
72290 {
72291 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
72292 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
72293 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
72294 int fdnum = scm->fp->count;
72295 struct file **fp = scm->fp->fp;
72296 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
72297 return -EFAULT;
72298 old_fs = get_fs();
72299 set_fs(KERNEL_DS);
72300 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
72301 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
72302 set_fs(old_fs);
72303
72304 return err;
72305 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
72306 len = sizeof(ktime);
72307 old_fs = get_fs();
72308 set_fs(KERNEL_DS);
72309 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
72310 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
72311 set_fs(old_fs);
72312
72313 if (!err) {
72314 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72315 case MCAST_JOIN_GROUP:
72316 case MCAST_LEAVE_GROUP:
72317 {
72318 - struct compat_group_req __user *gr32 = (void *)optval;
72319 + struct compat_group_req __user *gr32 = (void __user *)optval;
72320 struct group_req __user *kgr =
72321 compat_alloc_user_space(sizeof(struct group_req));
72322 u32 interface;
72323 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72324 case MCAST_BLOCK_SOURCE:
72325 case MCAST_UNBLOCK_SOURCE:
72326 {
72327 - struct compat_group_source_req __user *gsr32 = (void *)optval;
72328 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
72329 struct group_source_req __user *kgsr = compat_alloc_user_space(
72330 sizeof(struct group_source_req));
72331 u32 interface;
72332 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72333 }
72334 case MCAST_MSFILTER:
72335 {
72336 - struct compat_group_filter __user *gf32 = (void *)optval;
72337 + struct compat_group_filter __user *gf32 = (void __user *)optval;
72338 struct group_filter __user *kgf;
72339 u32 interface, fmode, numsrc;
72340
72341 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
72342 char __user *optval, int __user *optlen,
72343 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
72344 {
72345 - struct compat_group_filter __user *gf32 = (void *)optval;
72346 + struct compat_group_filter __user *gf32 = (void __user *)optval;
72347 struct group_filter __user *kgf;
72348 int __user *koptlen;
72349 u32 interface, fmode, numsrc;
72350 diff --git a/net/core/datagram.c b/net/core/datagram.c
72351 index 68bbf9f..5ef0d12 100644
72352 --- a/net/core/datagram.c
72353 +++ b/net/core/datagram.c
72354 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
72355 }
72356
72357 kfree_skb(skb);
72358 - atomic_inc(&sk->sk_drops);
72359 + atomic_inc_unchecked(&sk->sk_drops);
72360 sk_mem_reclaim_partial(sk);
72361
72362 return err;
72363 diff --git a/net/core/dev.c b/net/core/dev.c
72364 index 5a13edf..1bc016b 100644
72365 --- a/net/core/dev.c
72366 +++ b/net/core/dev.c
72367 @@ -1139,10 +1139,14 @@ void dev_load(struct net *net, const char *name)
72368 if (no_module && capable(CAP_NET_ADMIN))
72369 no_module = request_module("netdev-%s", name);
72370 if (no_module && capable(CAP_SYS_MODULE)) {
72371 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
72372 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
72373 +#else
72374 if (!request_module("%s", name))
72375 pr_err("Loading kernel module for a network device "
72376 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
72377 "instead\n", name);
72378 +#endif
72379 }
72380 }
72381 EXPORT_SYMBOL(dev_load);
72382 @@ -2036,7 +2040,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
72383
72384 struct dev_gso_cb {
72385 void (*destructor)(struct sk_buff *skb);
72386 -};
72387 +} __no_const;
72388
72389 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
72390
72391 @@ -3044,7 +3048,7 @@ int netif_rx_ni(struct sk_buff *skb)
72392 }
72393 EXPORT_SYMBOL(netif_rx_ni);
72394
72395 -static void net_tx_action(struct softirq_action *h)
72396 +static void net_tx_action(void)
72397 {
72398 struct softnet_data *sd = &__get_cpu_var(softnet_data);
72399
72400 @@ -3891,7 +3895,7 @@ void netif_napi_del(struct napi_struct *napi)
72401 }
72402 EXPORT_SYMBOL(netif_napi_del);
72403
72404 -static void net_rx_action(struct softirq_action *h)
72405 +static void net_rx_action(void)
72406 {
72407 struct softnet_data *sd = &__get_cpu_var(softnet_data);
72408 unsigned long time_limit = jiffies + 2;
72409 diff --git a/net/core/flow.c b/net/core/flow.c
72410 index e318c7e..168b1d0 100644
72411 --- a/net/core/flow.c
72412 +++ b/net/core/flow.c
72413 @@ -61,7 +61,7 @@ struct flow_cache {
72414 struct timer_list rnd_timer;
72415 };
72416
72417 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
72418 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
72419 EXPORT_SYMBOL(flow_cache_genid);
72420 static struct flow_cache flow_cache_global;
72421 static struct kmem_cache *flow_cachep __read_mostly;
72422 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
72423
72424 static int flow_entry_valid(struct flow_cache_entry *fle)
72425 {
72426 - if (atomic_read(&flow_cache_genid) != fle->genid)
72427 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
72428 return 0;
72429 if (fle->object && !fle->object->ops->check(fle->object))
72430 return 0;
72431 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
72432 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
72433 fcp->hash_count++;
72434 }
72435 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
72436 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
72437 flo = fle->object;
72438 if (!flo)
72439 goto ret_object;
72440 @@ -280,7 +280,7 @@ nocache:
72441 }
72442 flo = resolver(net, key, family, dir, flo, ctx);
72443 if (fle) {
72444 - fle->genid = atomic_read(&flow_cache_genid);
72445 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
72446 if (!IS_ERR(flo))
72447 fle->object = flo;
72448 else
72449 diff --git a/net/core/iovec.c b/net/core/iovec.c
72450 index c40f27e..7f49254 100644
72451 --- a/net/core/iovec.c
72452 +++ b/net/core/iovec.c
72453 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
72454 if (m->msg_namelen) {
72455 if (mode == VERIFY_READ) {
72456 void __user *namep;
72457 - namep = (void __user __force *) m->msg_name;
72458 + namep = (void __force_user *) m->msg_name;
72459 err = move_addr_to_kernel(namep, m->msg_namelen,
72460 address);
72461 if (err < 0)
72462 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
72463 }
72464
72465 size = m->msg_iovlen * sizeof(struct iovec);
72466 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
72467 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
72468 return -EFAULT;
72469
72470 m->msg_iov = iov;
72471 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
72472 index 9083e82..1673203 100644
72473 --- a/net/core/rtnetlink.c
72474 +++ b/net/core/rtnetlink.c
72475 @@ -57,7 +57,7 @@ struct rtnl_link {
72476 rtnl_doit_func doit;
72477 rtnl_dumpit_func dumpit;
72478 rtnl_calcit_func calcit;
72479 -};
72480 +} __no_const;
72481
72482 static DEFINE_MUTEX(rtnl_mutex);
72483 static u16 min_ifinfo_dump_size;
72484 diff --git a/net/core/scm.c b/net/core/scm.c
72485 index ff52ad0..aff1c0f 100644
72486 --- a/net/core/scm.c
72487 +++ b/net/core/scm.c
72488 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
72489 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
72490 {
72491 struct cmsghdr __user *cm
72492 - = (__force struct cmsghdr __user *)msg->msg_control;
72493 + = (struct cmsghdr __force_user *)msg->msg_control;
72494 struct cmsghdr cmhdr;
72495 int cmlen = CMSG_LEN(len);
72496 int err;
72497 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
72498 err = -EFAULT;
72499 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
72500 goto out;
72501 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
72502 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
72503 goto out;
72504 cmlen = CMSG_SPACE(len);
72505 if (msg->msg_controllen < cmlen)
72506 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
72507 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
72508 {
72509 struct cmsghdr __user *cm
72510 - = (__force struct cmsghdr __user*)msg->msg_control;
72511 + = (struct cmsghdr __force_user *)msg->msg_control;
72512
72513 int fdmax = 0;
72514 int fdnum = scm->fp->count;
72515 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
72516 if (fdnum < fdmax)
72517 fdmax = fdnum;
72518
72519 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
72520 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
72521 i++, cmfptr++)
72522 {
72523 int new_fd;
72524 diff --git a/net/core/sock.c b/net/core/sock.c
72525 index b23f174..b9a0d26 100644
72526 --- a/net/core/sock.c
72527 +++ b/net/core/sock.c
72528 @@ -289,7 +289,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72529 struct sk_buff_head *list = &sk->sk_receive_queue;
72530
72531 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
72532 - atomic_inc(&sk->sk_drops);
72533 + atomic_inc_unchecked(&sk->sk_drops);
72534 trace_sock_rcvqueue_full(sk, skb);
72535 return -ENOMEM;
72536 }
72537 @@ -299,7 +299,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72538 return err;
72539
72540 if (!sk_rmem_schedule(sk, skb->truesize)) {
72541 - atomic_inc(&sk->sk_drops);
72542 + atomic_inc_unchecked(&sk->sk_drops);
72543 return -ENOBUFS;
72544 }
72545
72546 @@ -319,7 +319,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72547 skb_dst_force(skb);
72548
72549 spin_lock_irqsave(&list->lock, flags);
72550 - skb->dropcount = atomic_read(&sk->sk_drops);
72551 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
72552 __skb_queue_tail(list, skb);
72553 spin_unlock_irqrestore(&list->lock, flags);
72554
72555 @@ -339,7 +339,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
72556 skb->dev = NULL;
72557
72558 if (sk_rcvqueues_full(sk, skb)) {
72559 - atomic_inc(&sk->sk_drops);
72560 + atomic_inc_unchecked(&sk->sk_drops);
72561 goto discard_and_relse;
72562 }
72563 if (nested)
72564 @@ -357,7 +357,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
72565 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
72566 } else if (sk_add_backlog(sk, skb)) {
72567 bh_unlock_sock(sk);
72568 - atomic_inc(&sk->sk_drops);
72569 + atomic_inc_unchecked(&sk->sk_drops);
72570 goto discard_and_relse;
72571 }
72572
72573 @@ -917,7 +917,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
72574 if (len > sizeof(peercred))
72575 len = sizeof(peercred);
72576 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
72577 - if (copy_to_user(optval, &peercred, len))
72578 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
72579 return -EFAULT;
72580 goto lenout;
72581 }
72582 @@ -930,7 +930,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
72583 return -ENOTCONN;
72584 if (lv < len)
72585 return -EINVAL;
72586 - if (copy_to_user(optval, address, len))
72587 + if (len > sizeof(address) || copy_to_user(optval, address, len))
72588 return -EFAULT;
72589 goto lenout;
72590 }
72591 @@ -963,7 +963,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
72592
72593 if (len > lv)
72594 len = lv;
72595 - if (copy_to_user(optval, &v, len))
72596 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
72597 return -EFAULT;
72598 lenout:
72599 if (put_user(len, optlen))
72600 @@ -2020,7 +2020,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
72601 */
72602 smp_wmb();
72603 atomic_set(&sk->sk_refcnt, 1);
72604 - atomic_set(&sk->sk_drops, 0);
72605 + atomic_set_unchecked(&sk->sk_drops, 0);
72606 }
72607 EXPORT_SYMBOL(sock_init_data);
72608
72609 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
72610 index 02e75d1..9a57a7c 100644
72611 --- a/net/decnet/sysctl_net_decnet.c
72612 +++ b/net/decnet/sysctl_net_decnet.c
72613 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
72614
72615 if (len > *lenp) len = *lenp;
72616
72617 - if (copy_to_user(buffer, addr, len))
72618 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
72619 return -EFAULT;
72620
72621 *lenp = len;
72622 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
72623
72624 if (len > *lenp) len = *lenp;
72625
72626 - if (copy_to_user(buffer, devname, len))
72627 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
72628 return -EFAULT;
72629
72630 *lenp = len;
72631 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
72632 index 39a2d29..f39c0fe 100644
72633 --- a/net/econet/Kconfig
72634 +++ b/net/econet/Kconfig
72635 @@ -4,7 +4,7 @@
72636
72637 config ECONET
72638 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
72639 - depends on EXPERIMENTAL && INET
72640 + depends on EXPERIMENTAL && INET && BROKEN
72641 ---help---
72642 Econet is a fairly old and slow networking protocol mainly used by
72643 Acorn computers to access file and print servers. It uses native
72644 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
72645 index 92fc5f6..b790d91 100644
72646 --- a/net/ipv4/fib_frontend.c
72647 +++ b/net/ipv4/fib_frontend.c
72648 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
72649 #ifdef CONFIG_IP_ROUTE_MULTIPATH
72650 fib_sync_up(dev);
72651 #endif
72652 - atomic_inc(&net->ipv4.dev_addr_genid);
72653 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
72654 rt_cache_flush(dev_net(dev), -1);
72655 break;
72656 case NETDEV_DOWN:
72657 fib_del_ifaddr(ifa, NULL);
72658 - atomic_inc(&net->ipv4.dev_addr_genid);
72659 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
72660 if (ifa->ifa_dev->ifa_list == NULL) {
72661 /* Last address was deleted from this interface.
72662 * Disable IP.
72663 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
72664 #ifdef CONFIG_IP_ROUTE_MULTIPATH
72665 fib_sync_up(dev);
72666 #endif
72667 - atomic_inc(&net->ipv4.dev_addr_genid);
72668 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
72669 rt_cache_flush(dev_net(dev), -1);
72670 break;
72671 case NETDEV_DOWN:
72672 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
72673 index 80106d8..232e898 100644
72674 --- a/net/ipv4/fib_semantics.c
72675 +++ b/net/ipv4/fib_semantics.c
72676 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
72677 nh->nh_saddr = inet_select_addr(nh->nh_dev,
72678 nh->nh_gw,
72679 nh->nh_parent->fib_scope);
72680 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
72681 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
72682
72683 return nh->nh_saddr;
72684 }
72685 diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
72686 index ccee270..db23c3c 100644
72687 --- a/net/ipv4/inet_diag.c
72688 +++ b/net/ipv4/inet_diag.c
72689 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct sock *sk,
72690 r->idiag_retrans = 0;
72691
72692 r->id.idiag_if = sk->sk_bound_dev_if;
72693 +
72694 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72695 + r->id.idiag_cookie[0] = 0;
72696 + r->id.idiag_cookie[1] = 0;
72697 +#else
72698 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
72699 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
72700 +#endif
72701
72702 r->id.idiag_sport = inet->inet_sport;
72703 r->id.idiag_dport = inet->inet_dport;
72704 @@ -210,8 +216,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
72705 r->idiag_family = tw->tw_family;
72706 r->idiag_retrans = 0;
72707 r->id.idiag_if = tw->tw_bound_dev_if;
72708 +
72709 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72710 + r->id.idiag_cookie[0] = 0;
72711 + r->id.idiag_cookie[1] = 0;
72712 +#else
72713 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
72714 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
72715 +#endif
72716 +
72717 r->id.idiag_sport = tw->tw_sport;
72718 r->id.idiag_dport = tw->tw_dport;
72719 r->id.idiag_src[0] = tw->tw_rcv_saddr;
72720 @@ -294,12 +307,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
72721 if (sk == NULL)
72722 goto unlock;
72723
72724 +#ifndef CONFIG_GRKERNSEC_HIDESYM
72725 err = -ESTALE;
72726 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
72727 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
72728 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
72729 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
72730 goto out;
72731 +#endif
72732
72733 err = -ENOMEM;
72734 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
72735 @@ -589,8 +604,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
72736 r->idiag_retrans = req->retrans;
72737
72738 r->id.idiag_if = sk->sk_bound_dev_if;
72739 +
72740 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72741 + r->id.idiag_cookie[0] = 0;
72742 + r->id.idiag_cookie[1] = 0;
72743 +#else
72744 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
72745 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
72746 +#endif
72747
72748 tmo = req->expires - jiffies;
72749 if (tmo < 0)
72750 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
72751 index 984ec65..97ac518 100644
72752 --- a/net/ipv4/inet_hashtables.c
72753 +++ b/net/ipv4/inet_hashtables.c
72754 @@ -18,12 +18,15 @@
72755 #include <linux/sched.h>
72756 #include <linux/slab.h>
72757 #include <linux/wait.h>
72758 +#include <linux/security.h>
72759
72760 #include <net/inet_connection_sock.h>
72761 #include <net/inet_hashtables.h>
72762 #include <net/secure_seq.h>
72763 #include <net/ip.h>
72764
72765 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
72766 +
72767 /*
72768 * Allocate and initialize a new local port bind bucket.
72769 * The bindhash mutex for snum's hash chain must be held here.
72770 @@ -530,6 +533,8 @@ ok:
72771 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
72772 spin_unlock(&head->lock);
72773
72774 + gr_update_task_in_ip_table(current, inet_sk(sk));
72775 +
72776 if (tw) {
72777 inet_twsk_deschedule(tw, death_row);
72778 while (twrefcnt) {
72779 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
72780 index 86f13c67..59a35b5 100644
72781 --- a/net/ipv4/inetpeer.c
72782 +++ b/net/ipv4/inetpeer.c
72783 @@ -436,8 +436,8 @@ relookup:
72784 if (p) {
72785 p->daddr = *daddr;
72786 atomic_set(&p->refcnt, 1);
72787 - atomic_set(&p->rid, 0);
72788 - atomic_set(&p->ip_id_count,
72789 + atomic_set_unchecked(&p->rid, 0);
72790 + atomic_set_unchecked(&p->ip_id_count,
72791 (daddr->family == AF_INET) ?
72792 secure_ip_id(daddr->addr.a4) :
72793 secure_ipv6_id(daddr->addr.a6));
72794 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
72795 index fdaabf2..0ec3205 100644
72796 --- a/net/ipv4/ip_fragment.c
72797 +++ b/net/ipv4/ip_fragment.c
72798 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
72799 return 0;
72800
72801 start = qp->rid;
72802 - end = atomic_inc_return(&peer->rid);
72803 + end = atomic_inc_return_unchecked(&peer->rid);
72804 qp->rid = end;
72805
72806 rc = qp->q.fragments && (end - start) > max;
72807 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
72808 index 09ff51b..d3968eb 100644
72809 --- a/net/ipv4/ip_sockglue.c
72810 +++ b/net/ipv4/ip_sockglue.c
72811 @@ -1111,7 +1111,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
72812 len = min_t(unsigned int, len, opt->optlen);
72813 if (put_user(len, optlen))
72814 return -EFAULT;
72815 - if (copy_to_user(optval, opt->__data, len))
72816 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
72817 + copy_to_user(optval, opt->__data, len))
72818 return -EFAULT;
72819 return 0;
72820 }
72821 @@ -1239,7 +1240,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
72822 if (sk->sk_type != SOCK_STREAM)
72823 return -ENOPROTOOPT;
72824
72825 - msg.msg_control = optval;
72826 + msg.msg_control = (void __force_kernel *)optval;
72827 msg.msg_controllen = len;
72828 msg.msg_flags = flags;
72829
72830 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
72831 index 99ec116..c5628fe 100644
72832 --- a/net/ipv4/ipconfig.c
72833 +++ b/net/ipv4/ipconfig.c
72834 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
72835
72836 mm_segment_t oldfs = get_fs();
72837 set_fs(get_ds());
72838 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
72839 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
72840 set_fs(oldfs);
72841 return res;
72842 }
72843 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
72844
72845 mm_segment_t oldfs = get_fs();
72846 set_fs(get_ds());
72847 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
72848 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
72849 set_fs(oldfs);
72850 return res;
72851 }
72852 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
72853
72854 mm_segment_t oldfs = get_fs();
72855 set_fs(get_ds());
72856 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
72857 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
72858 set_fs(oldfs);
72859 return res;
72860 }
72861 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
72862 index 2133c30..5c4b40b 100644
72863 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
72864 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
72865 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
72866
72867 *len = 0;
72868
72869 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
72870 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
72871 if (*octets == NULL)
72872 return 0;
72873
72874 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
72875 index 43d4c3b..1914409 100644
72876 --- a/net/ipv4/ping.c
72877 +++ b/net/ipv4/ping.c
72878 @@ -836,7 +836,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
72879 sk_rmem_alloc_get(sp),
72880 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
72881 atomic_read(&sp->sk_refcnt), sp,
72882 - atomic_read(&sp->sk_drops), len);
72883 + atomic_read_unchecked(&sp->sk_drops), len);
72884 }
72885
72886 static int ping_seq_show(struct seq_file *seq, void *v)
72887 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
72888 index 007e2eb..85a18a0 100644
72889 --- a/net/ipv4/raw.c
72890 +++ b/net/ipv4/raw.c
72891 @@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
72892 int raw_rcv(struct sock *sk, struct sk_buff *skb)
72893 {
72894 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
72895 - atomic_inc(&sk->sk_drops);
72896 + atomic_inc_unchecked(&sk->sk_drops);
72897 kfree_skb(skb);
72898 return NET_RX_DROP;
72899 }
72900 @@ -738,16 +738,20 @@ static int raw_init(struct sock *sk)
72901
72902 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
72903 {
72904 + struct icmp_filter filter;
72905 +
72906 if (optlen > sizeof(struct icmp_filter))
72907 optlen = sizeof(struct icmp_filter);
72908 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
72909 + if (copy_from_user(&filter, optval, optlen))
72910 return -EFAULT;
72911 + raw_sk(sk)->filter = filter;
72912 return 0;
72913 }
72914
72915 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
72916 {
72917 int len, ret = -EFAULT;
72918 + struct icmp_filter filter;
72919
72920 if (get_user(len, optlen))
72921 goto out;
72922 @@ -757,8 +761,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
72923 if (len > sizeof(struct icmp_filter))
72924 len = sizeof(struct icmp_filter);
72925 ret = -EFAULT;
72926 - if (put_user(len, optlen) ||
72927 - copy_to_user(optval, &raw_sk(sk)->filter, len))
72928 + filter = raw_sk(sk)->filter;
72929 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
72930 goto out;
72931 ret = 0;
72932 out: return ret;
72933 @@ -986,7 +990,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
72934 sk_wmem_alloc_get(sp),
72935 sk_rmem_alloc_get(sp),
72936 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
72937 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
72938 + atomic_read(&sp->sk_refcnt),
72939 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72940 + NULL,
72941 +#else
72942 + sp,
72943 +#endif
72944 + atomic_read_unchecked(&sp->sk_drops));
72945 }
72946
72947 static int raw_seq_show(struct seq_file *seq, void *v)
72948 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
72949 index 94cdbc5..0cb0063 100644
72950 --- a/net/ipv4/route.c
72951 +++ b/net/ipv4/route.c
72952 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
72953
72954 static inline int rt_genid(struct net *net)
72955 {
72956 - return atomic_read(&net->ipv4.rt_genid);
72957 + return atomic_read_unchecked(&net->ipv4.rt_genid);
72958 }
72959
72960 #ifdef CONFIG_PROC_FS
72961 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
72962 unsigned char shuffle;
72963
72964 get_random_bytes(&shuffle, sizeof(shuffle));
72965 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
72966 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
72967 redirect_genid++;
72968 }
72969
72970 @@ -3022,7 +3022,7 @@ static int rt_fill_info(struct net *net,
72971 error = rt->dst.error;
72972 if (peer) {
72973 inet_peer_refcheck(rt->peer);
72974 - id = atomic_read(&peer->ip_id_count) & 0xffff;
72975 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
72976 if (peer->tcp_ts_stamp) {
72977 ts = peer->tcp_ts;
72978 tsage = get_seconds() - peer->tcp_ts_stamp;
72979 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
72980 index a9db4b1..3c03301 100644
72981 --- a/net/ipv4/tcp_ipv4.c
72982 +++ b/net/ipv4/tcp_ipv4.c
72983 @@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
72984 int sysctl_tcp_low_latency __read_mostly;
72985 EXPORT_SYMBOL(sysctl_tcp_low_latency);
72986
72987 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72988 +extern int grsec_enable_blackhole;
72989 +#endif
72990
72991 #ifdef CONFIG_TCP_MD5SIG
72992 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
72993 @@ -1627,6 +1630,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
72994 return 0;
72995
72996 reset:
72997 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72998 + if (!grsec_enable_blackhole)
72999 +#endif
73000 tcp_v4_send_reset(rsk, skb);
73001 discard:
73002 kfree_skb(skb);
73003 @@ -1689,12 +1695,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
73004 TCP_SKB_CB(skb)->sacked = 0;
73005
73006 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
73007 - if (!sk)
73008 + if (!sk) {
73009 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73010 + ret = 1;
73011 +#endif
73012 goto no_tcp_socket;
73013 -
73014 + }
73015 process:
73016 - if (sk->sk_state == TCP_TIME_WAIT)
73017 + if (sk->sk_state == TCP_TIME_WAIT) {
73018 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73019 + ret = 2;
73020 +#endif
73021 goto do_time_wait;
73022 + }
73023
73024 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
73025 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
73026 @@ -1744,6 +1757,10 @@ no_tcp_socket:
73027 bad_packet:
73028 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
73029 } else {
73030 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73031 + if (!grsec_enable_blackhole || (ret == 1 &&
73032 + (skb->dev->flags & IFF_LOOPBACK)))
73033 +#endif
73034 tcp_v4_send_reset(NULL, skb);
73035 }
73036
73037 @@ -2404,7 +2421,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
73038 0, /* non standard timer */
73039 0, /* open_requests have no inode */
73040 atomic_read(&sk->sk_refcnt),
73041 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73042 + NULL,
73043 +#else
73044 req,
73045 +#endif
73046 len);
73047 }
73048
73049 @@ -2454,7 +2475,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
73050 sock_i_uid(sk),
73051 icsk->icsk_probes_out,
73052 sock_i_ino(sk),
73053 - atomic_read(&sk->sk_refcnt), sk,
73054 + atomic_read(&sk->sk_refcnt),
73055 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73056 + NULL,
73057 +#else
73058 + sk,
73059 +#endif
73060 jiffies_to_clock_t(icsk->icsk_rto),
73061 jiffies_to_clock_t(icsk->icsk_ack.ato),
73062 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
73063 @@ -2482,7 +2508,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
73064 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
73065 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
73066 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
73067 - atomic_read(&tw->tw_refcnt), tw, len);
73068 + atomic_read(&tw->tw_refcnt),
73069 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73070 + NULL,
73071 +#else
73072 + tw,
73073 +#endif
73074 + len);
73075 }
73076
73077 #define TMPSZ 150
73078 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
73079 index 66363b6..b0654a3 100644
73080 --- a/net/ipv4/tcp_minisocks.c
73081 +++ b/net/ipv4/tcp_minisocks.c
73082 @@ -27,6 +27,10 @@
73083 #include <net/inet_common.h>
73084 #include <net/xfrm.h>
73085
73086 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73087 +extern int grsec_enable_blackhole;
73088 +#endif
73089 +
73090 int sysctl_tcp_syncookies __read_mostly = 1;
73091 EXPORT_SYMBOL(sysctl_tcp_syncookies);
73092
73093 @@ -751,6 +755,10 @@ listen_overflow:
73094
73095 embryonic_reset:
73096 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
73097 +
73098 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73099 + if (!grsec_enable_blackhole)
73100 +#endif
73101 if (!(flg & TCP_FLAG_RST))
73102 req->rsk_ops->send_reset(sk, skb);
73103
73104 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
73105 index 85ee7eb..53277ab 100644
73106 --- a/net/ipv4/tcp_probe.c
73107 +++ b/net/ipv4/tcp_probe.c
73108 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
73109 if (cnt + width >= len)
73110 break;
73111
73112 - if (copy_to_user(buf + cnt, tbuf, width))
73113 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
73114 return -EFAULT;
73115 cnt += width;
73116 }
73117 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
73118 index 2e0f0af..e2948bf 100644
73119 --- a/net/ipv4/tcp_timer.c
73120 +++ b/net/ipv4/tcp_timer.c
73121 @@ -22,6 +22,10 @@
73122 #include <linux/gfp.h>
73123 #include <net/tcp.h>
73124
73125 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73126 +extern int grsec_lastack_retries;
73127 +#endif
73128 +
73129 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
73130 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
73131 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
73132 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock *sk)
73133 }
73134 }
73135
73136 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73137 + if ((sk->sk_state == TCP_LAST_ACK) &&
73138 + (grsec_lastack_retries > 0) &&
73139 + (grsec_lastack_retries < retry_until))
73140 + retry_until = grsec_lastack_retries;
73141 +#endif
73142 +
73143 if (retransmits_timed_out(sk, retry_until,
73144 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
73145 /* Has it gone just too far? */
73146 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
73147 index 5a65eea..bd913a1 100644
73148 --- a/net/ipv4/udp.c
73149 +++ b/net/ipv4/udp.c
73150 @@ -86,6 +86,7 @@
73151 #include <linux/types.h>
73152 #include <linux/fcntl.h>
73153 #include <linux/module.h>
73154 +#include <linux/security.h>
73155 #include <linux/socket.h>
73156 #include <linux/sockios.h>
73157 #include <linux/igmp.h>
73158 @@ -108,6 +109,10 @@
73159 #include <trace/events/udp.h>
73160 #include "udp_impl.h"
73161
73162 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73163 +extern int grsec_enable_blackhole;
73164 +#endif
73165 +
73166 struct udp_table udp_table __read_mostly;
73167 EXPORT_SYMBOL(udp_table);
73168
73169 @@ -565,6 +570,9 @@ found:
73170 return s;
73171 }
73172
73173 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
73174 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
73175 +
73176 /*
73177 * This routine is called by the ICMP module when it gets some
73178 * sort of error condition. If err < 0 then the socket should
73179 @@ -856,9 +864,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
73180 dport = usin->sin_port;
73181 if (dport == 0)
73182 return -EINVAL;
73183 +
73184 + err = gr_search_udp_sendmsg(sk, usin);
73185 + if (err)
73186 + return err;
73187 } else {
73188 if (sk->sk_state != TCP_ESTABLISHED)
73189 return -EDESTADDRREQ;
73190 +
73191 + err = gr_search_udp_sendmsg(sk, NULL);
73192 + if (err)
73193 + return err;
73194 +
73195 daddr = inet->inet_daddr;
73196 dport = inet->inet_dport;
73197 /* Open fast path for connected socket.
73198 @@ -1099,7 +1116,7 @@ static unsigned int first_packet_length(struct sock *sk)
73199 udp_lib_checksum_complete(skb)) {
73200 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
73201 IS_UDPLITE(sk));
73202 - atomic_inc(&sk->sk_drops);
73203 + atomic_inc_unchecked(&sk->sk_drops);
73204 __skb_unlink(skb, rcvq);
73205 __skb_queue_tail(&list_kill, skb);
73206 }
73207 @@ -1185,6 +1202,10 @@ try_again:
73208 if (!skb)
73209 goto out;
73210
73211 + err = gr_search_udp_recvmsg(sk, skb);
73212 + if (err)
73213 + goto out_free;
73214 +
73215 ulen = skb->len - sizeof(struct udphdr);
73216 copied = len;
73217 if (copied > ulen)
73218 @@ -1487,7 +1508,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73219
73220 drop:
73221 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
73222 - atomic_inc(&sk->sk_drops);
73223 + atomic_inc_unchecked(&sk->sk_drops);
73224 kfree_skb(skb);
73225 return -1;
73226 }
73227 @@ -1506,7 +1527,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
73228 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
73229
73230 if (!skb1) {
73231 - atomic_inc(&sk->sk_drops);
73232 + atomic_inc_unchecked(&sk->sk_drops);
73233 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
73234 IS_UDPLITE(sk));
73235 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
73236 @@ -1675,6 +1696,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
73237 goto csum_error;
73238
73239 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
73240 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73241 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
73242 +#endif
73243 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
73244
73245 /*
73246 @@ -2098,8 +2122,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
73247 sk_wmem_alloc_get(sp),
73248 sk_rmem_alloc_get(sp),
73249 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
73250 - atomic_read(&sp->sk_refcnt), sp,
73251 - atomic_read(&sp->sk_drops), len);
73252 + atomic_read(&sp->sk_refcnt),
73253 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73254 + NULL,
73255 +#else
73256 + sp,
73257 +#endif
73258 + atomic_read_unchecked(&sp->sk_drops), len);
73259 }
73260
73261 int udp4_seq_show(struct seq_file *seq, void *v)
73262 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
73263 index 36806de..b86f74c 100644
73264 --- a/net/ipv6/addrconf.c
73265 +++ b/net/ipv6/addrconf.c
73266 @@ -2149,7 +2149,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
73267 p.iph.ihl = 5;
73268 p.iph.protocol = IPPROTO_IPV6;
73269 p.iph.ttl = 64;
73270 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
73271 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
73272
73273 if (ops->ndo_do_ioctl) {
73274 mm_segment_t oldfs = get_fs();
73275 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
73276 index 1567fb1..29af910 100644
73277 --- a/net/ipv6/inet6_connection_sock.c
73278 +++ b/net/ipv6/inet6_connection_sock.c
73279 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
73280 #ifdef CONFIG_XFRM
73281 {
73282 struct rt6_info *rt = (struct rt6_info *)dst;
73283 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
73284 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
73285 }
73286 #endif
73287 }
73288 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
73289 #ifdef CONFIG_XFRM
73290 if (dst) {
73291 struct rt6_info *rt = (struct rt6_info *)dst;
73292 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
73293 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
73294 __sk_dst_reset(sk);
73295 dst = NULL;
73296 }
73297 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
73298 index 26cb08c..8af9877 100644
73299 --- a/net/ipv6/ipv6_sockglue.c
73300 +++ b/net/ipv6/ipv6_sockglue.c
73301 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
73302 if (sk->sk_type != SOCK_STREAM)
73303 return -ENOPROTOOPT;
73304
73305 - msg.msg_control = optval;
73306 + msg.msg_control = (void __force_kernel *)optval;
73307 msg.msg_controllen = len;
73308 msg.msg_flags = flags;
73309
73310 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
73311 index 331af3b..7789844 100644
73312 --- a/net/ipv6/raw.c
73313 +++ b/net/ipv6/raw.c
73314 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
73315 {
73316 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
73317 skb_checksum_complete(skb)) {
73318 - atomic_inc(&sk->sk_drops);
73319 + atomic_inc_unchecked(&sk->sk_drops);
73320 kfree_skb(skb);
73321 return NET_RX_DROP;
73322 }
73323 @@ -404,7 +404,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
73324 struct raw6_sock *rp = raw6_sk(sk);
73325
73326 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
73327 - atomic_inc(&sk->sk_drops);
73328 + atomic_inc_unchecked(&sk->sk_drops);
73329 kfree_skb(skb);
73330 return NET_RX_DROP;
73331 }
73332 @@ -428,7 +428,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
73333
73334 if (inet->hdrincl) {
73335 if (skb_checksum_complete(skb)) {
73336 - atomic_inc(&sk->sk_drops);
73337 + atomic_inc_unchecked(&sk->sk_drops);
73338 kfree_skb(skb);
73339 return NET_RX_DROP;
73340 }
73341 @@ -601,7 +601,7 @@ out:
73342 return err;
73343 }
73344
73345 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
73346 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
73347 struct flowi6 *fl6, struct dst_entry **dstp,
73348 unsigned int flags)
73349 {
73350 @@ -909,12 +909,15 @@ do_confirm:
73351 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
73352 char __user *optval, int optlen)
73353 {
73354 + struct icmp6_filter filter;
73355 +
73356 switch (optname) {
73357 case ICMPV6_FILTER:
73358 if (optlen > sizeof(struct icmp6_filter))
73359 optlen = sizeof(struct icmp6_filter);
73360 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
73361 + if (copy_from_user(&filter, optval, optlen))
73362 return -EFAULT;
73363 + raw6_sk(sk)->filter = filter;
73364 return 0;
73365 default:
73366 return -ENOPROTOOPT;
73367 @@ -927,6 +930,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
73368 char __user *optval, int __user *optlen)
73369 {
73370 int len;
73371 + struct icmp6_filter filter;
73372
73373 switch (optname) {
73374 case ICMPV6_FILTER:
73375 @@ -938,7 +942,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
73376 len = sizeof(struct icmp6_filter);
73377 if (put_user(len, optlen))
73378 return -EFAULT;
73379 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
73380 + filter = raw6_sk(sk)->filter;
73381 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
73382 return -EFAULT;
73383 return 0;
73384 default:
73385 @@ -1245,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
73386 0, 0L, 0,
73387 sock_i_uid(sp), 0,
73388 sock_i_ino(sp),
73389 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
73390 + atomic_read(&sp->sk_refcnt),
73391 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73392 + NULL,
73393 +#else
73394 + sp,
73395 +#endif
73396 + atomic_read_unchecked(&sp->sk_drops));
73397 }
73398
73399 static int raw6_seq_show(struct seq_file *seq, void *v)
73400 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
73401 index 2dea4bb..dca8ac5 100644
73402 --- a/net/ipv6/tcp_ipv6.c
73403 +++ b/net/ipv6/tcp_ipv6.c
73404 @@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
73405 }
73406 #endif
73407
73408 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73409 +extern int grsec_enable_blackhole;
73410 +#endif
73411 +
73412 static void tcp_v6_hash(struct sock *sk)
73413 {
73414 if (sk->sk_state != TCP_CLOSE) {
73415 @@ -1651,6 +1655,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
73416 return 0;
73417
73418 reset:
73419 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73420 + if (!grsec_enable_blackhole)
73421 +#endif
73422 tcp_v6_send_reset(sk, skb);
73423 discard:
73424 if (opt_skb)
73425 @@ -1730,12 +1737,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
73426 TCP_SKB_CB(skb)->sacked = 0;
73427
73428 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
73429 - if (!sk)
73430 + if (!sk) {
73431 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73432 + ret = 1;
73433 +#endif
73434 goto no_tcp_socket;
73435 + }
73436
73437 process:
73438 - if (sk->sk_state == TCP_TIME_WAIT)
73439 + if (sk->sk_state == TCP_TIME_WAIT) {
73440 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73441 + ret = 2;
73442 +#endif
73443 goto do_time_wait;
73444 + }
73445
73446 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
73447 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
73448 @@ -1783,6 +1798,10 @@ no_tcp_socket:
73449 bad_packet:
73450 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
73451 } else {
73452 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73453 + if (!grsec_enable_blackhole || (ret == 1 &&
73454 + (skb->dev->flags & IFF_LOOPBACK)))
73455 +#endif
73456 tcp_v6_send_reset(NULL, skb);
73457 }
73458
73459 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
73460 uid,
73461 0, /* non standard timer */
73462 0, /* open_requests have no inode */
73463 - 0, req);
73464 + 0,
73465 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73466 + NULL
73467 +#else
73468 + req
73469 +#endif
73470 + );
73471 }
73472
73473 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
73474 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
73475 sock_i_uid(sp),
73476 icsk->icsk_probes_out,
73477 sock_i_ino(sp),
73478 - atomic_read(&sp->sk_refcnt), sp,
73479 + atomic_read(&sp->sk_refcnt),
73480 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73481 + NULL,
73482 +#else
73483 + sp,
73484 +#endif
73485 jiffies_to_clock_t(icsk->icsk_rto),
73486 jiffies_to_clock_t(icsk->icsk_ack.ato),
73487 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
73488 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
73489 dest->s6_addr32[2], dest->s6_addr32[3], destp,
73490 tw->tw_substate, 0, 0,
73491 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
73492 - atomic_read(&tw->tw_refcnt), tw);
73493 + atomic_read(&tw->tw_refcnt),
73494 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73495 + NULL
73496 +#else
73497 + tw
73498 +#endif
73499 + );
73500 }
73501
73502 static int tcp6_seq_show(struct seq_file *seq, void *v)
73503 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
73504 index 8c25419..47a51ae 100644
73505 --- a/net/ipv6/udp.c
73506 +++ b/net/ipv6/udp.c
73507 @@ -50,6 +50,10 @@
73508 #include <linux/seq_file.h>
73509 #include "udp_impl.h"
73510
73511 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73512 +extern int grsec_enable_blackhole;
73513 +#endif
73514 +
73515 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
73516 {
73517 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
73518 @@ -549,7 +553,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
73519
73520 return 0;
73521 drop:
73522 - atomic_inc(&sk->sk_drops);
73523 + atomic_inc_unchecked(&sk->sk_drops);
73524 drop_no_sk_drops_inc:
73525 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
73526 kfree_skb(skb);
73527 @@ -625,7 +629,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
73528 continue;
73529 }
73530 drop:
73531 - atomic_inc(&sk->sk_drops);
73532 + atomic_inc_unchecked(&sk->sk_drops);
73533 UDP6_INC_STATS_BH(sock_net(sk),
73534 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
73535 UDP6_INC_STATS_BH(sock_net(sk),
73536 @@ -780,6 +784,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
73537 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
73538 proto == IPPROTO_UDPLITE);
73539
73540 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73541 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
73542 +#endif
73543 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
73544
73545 kfree_skb(skb);
73546 @@ -796,7 +803,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
73547 if (!sock_owned_by_user(sk))
73548 udpv6_queue_rcv_skb(sk, skb);
73549 else if (sk_add_backlog(sk, skb)) {
73550 - atomic_inc(&sk->sk_drops);
73551 + atomic_inc_unchecked(&sk->sk_drops);
73552 bh_unlock_sock(sk);
73553 sock_put(sk);
73554 goto discard;
73555 @@ -1407,8 +1414,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
73556 0, 0L, 0,
73557 sock_i_uid(sp), 0,
73558 sock_i_ino(sp),
73559 - atomic_read(&sp->sk_refcnt), sp,
73560 - atomic_read(&sp->sk_drops));
73561 + atomic_read(&sp->sk_refcnt),
73562 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73563 + NULL,
73564 +#else
73565 + sp,
73566 +#endif
73567 + atomic_read_unchecked(&sp->sk_drops));
73568 }
73569
73570 int udp6_seq_show(struct seq_file *seq, void *v)
73571 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
73572 index 253695d..9481ce8 100644
73573 --- a/net/irda/ircomm/ircomm_tty.c
73574 +++ b/net/irda/ircomm/ircomm_tty.c
73575 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
73576 add_wait_queue(&self->open_wait, &wait);
73577
73578 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
73579 - __FILE__,__LINE__, tty->driver->name, self->open_count );
73580 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
73581
73582 /* As far as I can see, we protect open_count - Jean II */
73583 spin_lock_irqsave(&self->spinlock, flags);
73584 if (!tty_hung_up_p(filp)) {
73585 extra_count = 1;
73586 - self->open_count--;
73587 + local_dec(&self->open_count);
73588 }
73589 spin_unlock_irqrestore(&self->spinlock, flags);
73590 - self->blocked_open++;
73591 + local_inc(&self->blocked_open);
73592
73593 while (1) {
73594 if (tty->termios->c_cflag & CBAUD) {
73595 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
73596 }
73597
73598 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
73599 - __FILE__,__LINE__, tty->driver->name, self->open_count );
73600 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
73601
73602 schedule();
73603 }
73604 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
73605 if (extra_count) {
73606 /* ++ is not atomic, so this should be protected - Jean II */
73607 spin_lock_irqsave(&self->spinlock, flags);
73608 - self->open_count++;
73609 + local_inc(&self->open_count);
73610 spin_unlock_irqrestore(&self->spinlock, flags);
73611 }
73612 - self->blocked_open--;
73613 + local_dec(&self->blocked_open);
73614
73615 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
73616 - __FILE__,__LINE__, tty->driver->name, self->open_count);
73617 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
73618
73619 if (!retval)
73620 self->flags |= ASYNC_NORMAL_ACTIVE;
73621 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
73622 }
73623 /* ++ is not atomic, so this should be protected - Jean II */
73624 spin_lock_irqsave(&self->spinlock, flags);
73625 - self->open_count++;
73626 + local_inc(&self->open_count);
73627
73628 tty->driver_data = self;
73629 self->tty = tty;
73630 spin_unlock_irqrestore(&self->spinlock, flags);
73631
73632 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
73633 - self->line, self->open_count);
73634 + self->line, local_read(&self->open_count));
73635
73636 /* Not really used by us, but lets do it anyway */
73637 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
73638 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
73639 return;
73640 }
73641
73642 - if ((tty->count == 1) && (self->open_count != 1)) {
73643 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
73644 /*
73645 * Uh, oh. tty->count is 1, which means that the tty
73646 * structure will be freed. state->count should always
73647 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
73648 */
73649 IRDA_DEBUG(0, "%s(), bad serial port count; "
73650 "tty->count is 1, state->count is %d\n", __func__ ,
73651 - self->open_count);
73652 - self->open_count = 1;
73653 + local_read(&self->open_count));
73654 + local_set(&self->open_count, 1);
73655 }
73656
73657 - if (--self->open_count < 0) {
73658 + if (local_dec_return(&self->open_count) < 0) {
73659 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
73660 - __func__, self->line, self->open_count);
73661 - self->open_count = 0;
73662 + __func__, self->line, local_read(&self->open_count));
73663 + local_set(&self->open_count, 0);
73664 }
73665 - if (self->open_count) {
73666 + if (local_read(&self->open_count)) {
73667 spin_unlock_irqrestore(&self->spinlock, flags);
73668
73669 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
73670 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
73671 tty->closing = 0;
73672 self->tty = NULL;
73673
73674 - if (self->blocked_open) {
73675 + if (local_read(&self->blocked_open)) {
73676 if (self->close_delay)
73677 schedule_timeout_interruptible(self->close_delay);
73678 wake_up_interruptible(&self->open_wait);
73679 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
73680 spin_lock_irqsave(&self->spinlock, flags);
73681 self->flags &= ~ASYNC_NORMAL_ACTIVE;
73682 self->tty = NULL;
73683 - self->open_count = 0;
73684 + local_set(&self->open_count, 0);
73685 spin_unlock_irqrestore(&self->spinlock, flags);
73686
73687 wake_up_interruptible(&self->open_wait);
73688 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
73689 seq_putc(m, '\n');
73690
73691 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
73692 - seq_printf(m, "Open count: %d\n", self->open_count);
73693 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
73694 seq_printf(m, "Max data size: %d\n", self->max_data_size);
73695 seq_printf(m, "Max header size: %d\n", self->max_header_size);
73696
73697 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
73698 index 274d150..656a144 100644
73699 --- a/net/iucv/af_iucv.c
73700 +++ b/net/iucv/af_iucv.c
73701 @@ -787,10 +787,10 @@ static int iucv_sock_autobind(struct sock *sk)
73702
73703 write_lock_bh(&iucv_sk_list.lock);
73704
73705 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
73706 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
73707 while (__iucv_get_sock_by_name(name)) {
73708 sprintf(name, "%08x",
73709 - atomic_inc_return(&iucv_sk_list.autobind_name));
73710 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
73711 }
73712
73713 write_unlock_bh(&iucv_sk_list.lock);
73714 diff --git a/net/key/af_key.c b/net/key/af_key.c
73715 index 1e733e9..3d73c9f 100644
73716 --- a/net/key/af_key.c
73717 +++ b/net/key/af_key.c
73718 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
73719 static u32 get_acqseq(void)
73720 {
73721 u32 res;
73722 - static atomic_t acqseq;
73723 + static atomic_unchecked_t acqseq;
73724
73725 do {
73726 - res = atomic_inc_return(&acqseq);
73727 + res = atomic_inc_return_unchecked(&acqseq);
73728 } while (!res);
73729 return res;
73730 }
73731 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
73732 index ea10a51..9a4f0cc 100644
73733 --- a/net/mac80211/ieee80211_i.h
73734 +++ b/net/mac80211/ieee80211_i.h
73735 @@ -27,6 +27,7 @@
73736 #include <net/ieee80211_radiotap.h>
73737 #include <net/cfg80211.h>
73738 #include <net/mac80211.h>
73739 +#include <asm/local.h>
73740 #include "key.h"
73741 #include "sta_info.h"
73742
73743 @@ -761,7 +762,7 @@ struct ieee80211_local {
73744 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
73745 spinlock_t queue_stop_reason_lock;
73746
73747 - int open_count;
73748 + local_t open_count;
73749 int monitors, cooked_mntrs;
73750 /* number of interfaces with corresponding FIF_ flags */
73751 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
73752 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
73753 index 30d7355..e260095 100644
73754 --- a/net/mac80211/iface.c
73755 +++ b/net/mac80211/iface.c
73756 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
73757 break;
73758 }
73759
73760 - if (local->open_count == 0) {
73761 + if (local_read(&local->open_count) == 0) {
73762 res = drv_start(local);
73763 if (res)
73764 goto err_del_bss;
73765 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
73766 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
73767
73768 if (!is_valid_ether_addr(dev->dev_addr)) {
73769 - if (!local->open_count)
73770 + if (!local_read(&local->open_count))
73771 drv_stop(local);
73772 return -EADDRNOTAVAIL;
73773 }
73774 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
73775 mutex_unlock(&local->mtx);
73776
73777 if (coming_up)
73778 - local->open_count++;
73779 + local_inc(&local->open_count);
73780
73781 if (hw_reconf_flags) {
73782 ieee80211_hw_config(local, hw_reconf_flags);
73783 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
73784 err_del_interface:
73785 drv_remove_interface(local, &sdata->vif);
73786 err_stop:
73787 - if (!local->open_count)
73788 + if (!local_read(&local->open_count))
73789 drv_stop(local);
73790 err_del_bss:
73791 sdata->bss = NULL;
73792 @@ -472,7 +472,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
73793 }
73794
73795 if (going_down)
73796 - local->open_count--;
73797 + local_dec(&local->open_count);
73798
73799 switch (sdata->vif.type) {
73800 case NL80211_IFTYPE_AP_VLAN:
73801 @@ -531,7 +531,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
73802
73803 ieee80211_recalc_ps(local, -1);
73804
73805 - if (local->open_count == 0) {
73806 + if (local_read(&local->open_count) == 0) {
73807 if (local->ops->napi_poll)
73808 napi_disable(&local->napi);
73809 ieee80211_clear_tx_pending(local);
73810 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
73811 index cae4435..76e3372 100644
73812 --- a/net/mac80211/main.c
73813 +++ b/net/mac80211/main.c
73814 @@ -209,7 +209,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
73815 local->hw.conf.power_level = power;
73816 }
73817
73818 - if (changed && local->open_count) {
73819 + if (changed && local_read(&local->open_count)) {
73820 ret = drv_config(local, changed);
73821 /*
73822 * Goal:
73823 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
73824 index 9ee7164..56c5061 100644
73825 --- a/net/mac80211/pm.c
73826 +++ b/net/mac80211/pm.c
73827 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
73828 struct ieee80211_sub_if_data *sdata;
73829 struct sta_info *sta;
73830
73831 - if (!local->open_count)
73832 + if (!local_read(&local->open_count))
73833 goto suspend;
73834
73835 ieee80211_scan_cancel(local);
73836 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
73837 cancel_work_sync(&local->dynamic_ps_enable_work);
73838 del_timer_sync(&local->dynamic_ps_timer);
73839
73840 - local->wowlan = wowlan && local->open_count;
73841 + local->wowlan = wowlan && local_read(&local->open_count);
73842 if (local->wowlan) {
73843 int err = drv_suspend(local, wowlan);
73844 if (err < 0) {
73845 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
73846 }
73847
73848 /* stop hardware - this must stop RX */
73849 - if (local->open_count)
73850 + if (local_read(&local->open_count))
73851 ieee80211_stop_device(local);
73852
73853 suspend:
73854 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
73855 index 5a5a776..9600b11 100644
73856 --- a/net/mac80211/rate.c
73857 +++ b/net/mac80211/rate.c
73858 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
73859
73860 ASSERT_RTNL();
73861
73862 - if (local->open_count)
73863 + if (local_read(&local->open_count))
73864 return -EBUSY;
73865
73866 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
73867 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
73868 index c97a065..ff61928 100644
73869 --- a/net/mac80211/rc80211_pid_debugfs.c
73870 +++ b/net/mac80211/rc80211_pid_debugfs.c
73871 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
73872
73873 spin_unlock_irqrestore(&events->lock, status);
73874
73875 - if (copy_to_user(buf, pb, p))
73876 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
73877 return -EFAULT;
73878
73879 return p;
73880 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
73881 index d5230ec..c604b21 100644
73882 --- a/net/mac80211/util.c
73883 +++ b/net/mac80211/util.c
73884 @@ -1000,7 +1000,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
73885 drv_set_coverage_class(local, hw->wiphy->coverage_class);
73886
73887 /* everything else happens only if HW was up & running */
73888 - if (!local->open_count)
73889 + if (!local_read(&local->open_count))
73890 goto wake_up;
73891
73892 /*
73893 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
73894 index d5597b7..ab6d39c 100644
73895 --- a/net/netfilter/Kconfig
73896 +++ b/net/netfilter/Kconfig
73897 @@ -779,6 +779,16 @@ config NETFILTER_XT_MATCH_ESP
73898
73899 To compile it as a module, choose M here. If unsure, say N.
73900
73901 +config NETFILTER_XT_MATCH_GRADM
73902 + tristate '"gradm" match support'
73903 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
73904 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
73905 + ---help---
73906 + The gradm match allows to match on grsecurity RBAC being enabled.
73907 + It is useful when iptables rules are applied early on bootup to
73908 + prevent connections to the machine (except from a trusted host)
73909 + while the RBAC system is disabled.
73910 +
73911 config NETFILTER_XT_MATCH_HASHLIMIT
73912 tristate '"hashlimit" match support'
73913 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
73914 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
73915 index 1a02853..5d8c22e 100644
73916 --- a/net/netfilter/Makefile
73917 +++ b/net/netfilter/Makefile
73918 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
73919 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
73920 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
73921 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
73922 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
73923 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
73924 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
73925 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
73926 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
73927 index 29fa5ba..8debc79 100644
73928 --- a/net/netfilter/ipvs/ip_vs_conn.c
73929 +++ b/net/netfilter/ipvs/ip_vs_conn.c
73930 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
73931 /* Increase the refcnt counter of the dest */
73932 atomic_inc(&dest->refcnt);
73933
73934 - conn_flags = atomic_read(&dest->conn_flags);
73935 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
73936 if (cp->protocol != IPPROTO_UDP)
73937 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
73938 /* Bind with the destination and its corresponding transmitter */
73939 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
73940 atomic_set(&cp->refcnt, 1);
73941
73942 atomic_set(&cp->n_control, 0);
73943 - atomic_set(&cp->in_pkts, 0);
73944 + atomic_set_unchecked(&cp->in_pkts, 0);
73945
73946 atomic_inc(&ipvs->conn_count);
73947 if (flags & IP_VS_CONN_F_NO_CPORT)
73948 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
73949
73950 /* Don't drop the entry if its number of incoming packets is not
73951 located in [0, 8] */
73952 - i = atomic_read(&cp->in_pkts);
73953 + i = atomic_read_unchecked(&cp->in_pkts);
73954 if (i > 8 || i < 0) return 0;
73955
73956 if (!todrop_rate[i]) return 0;
73957 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
73958 index 093cc32..9209ae1 100644
73959 --- a/net/netfilter/ipvs/ip_vs_core.c
73960 +++ b/net/netfilter/ipvs/ip_vs_core.c
73961 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
73962 ret = cp->packet_xmit(skb, cp, pd->pp);
73963 /* do not touch skb anymore */
73964
73965 - atomic_inc(&cp->in_pkts);
73966 + atomic_inc_unchecked(&cp->in_pkts);
73967 ip_vs_conn_put(cp);
73968 return ret;
73969 }
73970 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
73971 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
73972 pkts = sysctl_sync_threshold(ipvs);
73973 else
73974 - pkts = atomic_add_return(1, &cp->in_pkts);
73975 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
73976
73977 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
73978 cp->protocol == IPPROTO_SCTP) {
73979 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
73980 index e1a66cf..0910076 100644
73981 --- a/net/netfilter/ipvs/ip_vs_ctl.c
73982 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
73983 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
73984 ip_vs_rs_hash(ipvs, dest);
73985 write_unlock_bh(&ipvs->rs_lock);
73986 }
73987 - atomic_set(&dest->conn_flags, conn_flags);
73988 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
73989
73990 /* bind the service */
73991 if (!dest->svc) {
73992 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
73993 " %-7s %-6d %-10d %-10d\n",
73994 &dest->addr.in6,
73995 ntohs(dest->port),
73996 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
73997 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
73998 atomic_read(&dest->weight),
73999 atomic_read(&dest->activeconns),
74000 atomic_read(&dest->inactconns));
74001 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
74002 "%-7s %-6d %-10d %-10d\n",
74003 ntohl(dest->addr.ip),
74004 ntohs(dest->port),
74005 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
74006 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
74007 atomic_read(&dest->weight),
74008 atomic_read(&dest->activeconns),
74009 atomic_read(&dest->inactconns));
74010 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
74011
74012 entry.addr = dest->addr.ip;
74013 entry.port = dest->port;
74014 - entry.conn_flags = atomic_read(&dest->conn_flags);
74015 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
74016 entry.weight = atomic_read(&dest->weight);
74017 entry.u_threshold = dest->u_threshold;
74018 entry.l_threshold = dest->l_threshold;
74019 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
74020 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
74021
74022 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
74023 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
74024 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
74025 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
74026 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
74027 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
74028 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
74029 index 2b6678c0..aaa41fc 100644
74030 --- a/net/netfilter/ipvs/ip_vs_sync.c
74031 +++ b/net/netfilter/ipvs/ip_vs_sync.c
74032 @@ -649,7 +649,7 @@ control:
74033 * i.e only increment in_pkts for Templates.
74034 */
74035 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
74036 - int pkts = atomic_add_return(1, &cp->in_pkts);
74037 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
74038
74039 if (pkts % sysctl_sync_period(ipvs) != 1)
74040 return;
74041 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
74042
74043 if (opt)
74044 memcpy(&cp->in_seq, opt, sizeof(*opt));
74045 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
74046 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
74047 cp->state = state;
74048 cp->old_state = cp->state;
74049 /*
74050 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
74051 index aa2d720..d8aa111 100644
74052 --- a/net/netfilter/ipvs/ip_vs_xmit.c
74053 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
74054 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
74055 else
74056 rc = NF_ACCEPT;
74057 /* do not touch skb anymore */
74058 - atomic_inc(&cp->in_pkts);
74059 + atomic_inc_unchecked(&cp->in_pkts);
74060 goto out;
74061 }
74062
74063 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
74064 else
74065 rc = NF_ACCEPT;
74066 /* do not touch skb anymore */
74067 - atomic_inc(&cp->in_pkts);
74068 + atomic_inc_unchecked(&cp->in_pkts);
74069 goto out;
74070 }
74071
74072 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
74073 index 66b2c54..c7884e3 100644
74074 --- a/net/netfilter/nfnetlink_log.c
74075 +++ b/net/netfilter/nfnetlink_log.c
74076 @@ -70,7 +70,7 @@ struct nfulnl_instance {
74077 };
74078
74079 static DEFINE_SPINLOCK(instances_lock);
74080 -static atomic_t global_seq;
74081 +static atomic_unchecked_t global_seq;
74082
74083 #define INSTANCE_BUCKETS 16
74084 static struct hlist_head instance_table[INSTANCE_BUCKETS];
74085 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
74086 /* global sequence number */
74087 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
74088 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
74089 - htonl(atomic_inc_return(&global_seq)));
74090 + htonl(atomic_inc_return_unchecked(&global_seq)));
74091
74092 if (data_len) {
74093 struct nlattr *nla;
74094 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
74095 new file mode 100644
74096 index 0000000..6905327
74097 --- /dev/null
74098 +++ b/net/netfilter/xt_gradm.c
74099 @@ -0,0 +1,51 @@
74100 +/*
74101 + * gradm match for netfilter
74102 + * Copyright © Zbigniew Krzystolik, 2010
74103 + *
74104 + * This program is free software; you can redistribute it and/or modify
74105 + * it under the terms of the GNU General Public License; either version
74106 + * 2 or 3 as published by the Free Software Foundation.
74107 + */
74108 +#include <linux/module.h>
74109 +#include <linux/moduleparam.h>
74110 +#include <linux/skbuff.h>
74111 +#include <linux/netfilter/x_tables.h>
74112 +#include <linux/grsecurity.h>
74113 +#include <linux/netfilter/xt_gradm.h>
74114 +
74115 +static bool
74116 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
74117 +{
74118 + const struct xt_gradm_mtinfo *info = par->matchinfo;
74119 + bool retval = false;
74120 + if (gr_acl_is_enabled())
74121 + retval = true;
74122 + return retval ^ info->invflags;
74123 +}
74124 +
74125 +static struct xt_match gradm_mt_reg __read_mostly = {
74126 + .name = "gradm",
74127 + .revision = 0,
74128 + .family = NFPROTO_UNSPEC,
74129 + .match = gradm_mt,
74130 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
74131 + .me = THIS_MODULE,
74132 +};
74133 +
74134 +static int __init gradm_mt_init(void)
74135 +{
74136 + return xt_register_match(&gradm_mt_reg);
74137 +}
74138 +
74139 +static void __exit gradm_mt_exit(void)
74140 +{
74141 + xt_unregister_match(&gradm_mt_reg);
74142 +}
74143 +
74144 +module_init(gradm_mt_init);
74145 +module_exit(gradm_mt_exit);
74146 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
74147 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
74148 +MODULE_LICENSE("GPL");
74149 +MODULE_ALIAS("ipt_gradm");
74150 +MODULE_ALIAS("ip6t_gradm");
74151 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
74152 index 4fe4fb4..87a89e5 100644
74153 --- a/net/netfilter/xt_statistic.c
74154 +++ b/net/netfilter/xt_statistic.c
74155 @@ -19,7 +19,7 @@
74156 #include <linux/module.h>
74157
74158 struct xt_statistic_priv {
74159 - atomic_t count;
74160 + atomic_unchecked_t count;
74161 } ____cacheline_aligned_in_smp;
74162
74163 MODULE_LICENSE("GPL");
74164 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
74165 break;
74166 case XT_STATISTIC_MODE_NTH:
74167 do {
74168 - oval = atomic_read(&info->master->count);
74169 + oval = atomic_read_unchecked(&info->master->count);
74170 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
74171 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
74172 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
74173 if (nval == 0)
74174 ret = !ret;
74175 break;
74176 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
74177 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
74178 if (info->master == NULL)
74179 return -ENOMEM;
74180 - atomic_set(&info->master->count, info->u.nth.count);
74181 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
74182
74183 return 0;
74184 }
74185 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
74186 index 1201b6d..bcff8c6 100644
74187 --- a/net/netlink/af_netlink.c
74188 +++ b/net/netlink/af_netlink.c
74189 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock *sk)
74190 sk->sk_error_report(sk);
74191 }
74192 }
74193 - atomic_inc(&sk->sk_drops);
74194 + atomic_inc_unchecked(&sk->sk_drops);
74195 }
74196
74197 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
74198 @@ -1999,7 +1999,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
74199 sk_wmem_alloc_get(s),
74200 nlk->cb,
74201 atomic_read(&s->sk_refcnt),
74202 - atomic_read(&s->sk_drops),
74203 + atomic_read_unchecked(&s->sk_drops),
74204 sock_i_ino(s)
74205 );
74206
74207 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
74208 index 732152f..60bb09e 100644
74209 --- a/net/netrom/af_netrom.c
74210 +++ b/net/netrom/af_netrom.c
74211 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
74212 struct sock *sk = sock->sk;
74213 struct nr_sock *nr = nr_sk(sk);
74214
74215 + memset(sax, 0, sizeof(*sax));
74216 lock_sock(sk);
74217 if (peer != 0) {
74218 if (sk->sk_state != TCP_ESTABLISHED) {
74219 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
74220 *uaddr_len = sizeof(struct full_sockaddr_ax25);
74221 } else {
74222 sax->fsa_ax25.sax25_family = AF_NETROM;
74223 - sax->fsa_ax25.sax25_ndigis = 0;
74224 sax->fsa_ax25.sax25_call = nr->source_addr;
74225 *uaddr_len = sizeof(struct sockaddr_ax25);
74226 }
74227 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
74228 index d9d4970..d5a6a68 100644
74229 --- a/net/packet/af_packet.c
74230 +++ b/net/packet/af_packet.c
74231 @@ -1675,7 +1675,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
74232
74233 spin_lock(&sk->sk_receive_queue.lock);
74234 po->stats.tp_packets++;
74235 - skb->dropcount = atomic_read(&sk->sk_drops);
74236 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74237 __skb_queue_tail(&sk->sk_receive_queue, skb);
74238 spin_unlock(&sk->sk_receive_queue.lock);
74239 sk->sk_data_ready(sk, skb->len);
74240 @@ -1684,7 +1684,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
74241 drop_n_acct:
74242 spin_lock(&sk->sk_receive_queue.lock);
74243 po->stats.tp_drops++;
74244 - atomic_inc(&sk->sk_drops);
74245 + atomic_inc_unchecked(&sk->sk_drops);
74246 spin_unlock(&sk->sk_receive_queue.lock);
74247
74248 drop_n_restore:
74249 @@ -3266,7 +3266,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
74250 case PACKET_HDRLEN:
74251 if (len > sizeof(int))
74252 len = sizeof(int);
74253 - if (copy_from_user(&val, optval, len))
74254 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
74255 return -EFAULT;
74256 switch (val) {
74257 case TPACKET_V1:
74258 @@ -3316,7 +3316,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
74259
74260 if (put_user(len, optlen))
74261 return -EFAULT;
74262 - if (copy_to_user(optval, data, len))
74263 + if (len > sizeof(st) || copy_to_user(optval, data, len))
74264 return -EFAULT;
74265 return 0;
74266 }
74267 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
74268 index bf10ea8..aeb4c3e 100644
74269 --- a/net/phonet/af_phonet.c
74270 +++ b/net/phonet/af_phonet.c
74271 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
74272 {
74273 struct phonet_protocol *pp;
74274
74275 - if (protocol >= PHONET_NPROTO)
74276 + if (protocol < 0 || protocol >= PHONET_NPROTO)
74277 return NULL;
74278
74279 rcu_read_lock();
74280 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
74281 {
74282 int err = 0;
74283
74284 - if (protocol >= PHONET_NPROTO)
74285 + if (protocol < 0 || protocol >= PHONET_NPROTO)
74286 return -EINVAL;
74287
74288 err = proto_register(pp->prot, 1);
74289 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
74290 index 2ba6e9f..409573f 100644
74291 --- a/net/phonet/pep.c
74292 +++ b/net/phonet/pep.c
74293 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
74294
74295 case PNS_PEP_CTRL_REQ:
74296 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
74297 - atomic_inc(&sk->sk_drops);
74298 + atomic_inc_unchecked(&sk->sk_drops);
74299 break;
74300 }
74301 __skb_pull(skb, 4);
74302 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
74303 }
74304
74305 if (pn->rx_credits == 0) {
74306 - atomic_inc(&sk->sk_drops);
74307 + atomic_inc_unchecked(&sk->sk_drops);
74308 err = -ENOBUFS;
74309 break;
74310 }
74311 @@ -557,7 +557,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
74312 }
74313
74314 if (pn->rx_credits == 0) {
74315 - atomic_inc(&sk->sk_drops);
74316 + atomic_inc_unchecked(&sk->sk_drops);
74317 err = NET_RX_DROP;
74318 break;
74319 }
74320 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
74321 index 3f8d0b1..74635e0 100644
74322 --- a/net/phonet/socket.c
74323 +++ b/net/phonet/socket.c
74324 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
74325 pn->resource, sk->sk_state,
74326 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
74327 sock_i_uid(sk), sock_i_ino(sk),
74328 - atomic_read(&sk->sk_refcnt), sk,
74329 - atomic_read(&sk->sk_drops), &len);
74330 + atomic_read(&sk->sk_refcnt),
74331 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74332 + NULL,
74333 +#else
74334 + sk,
74335 +#endif
74336 + atomic_read_unchecked(&sk->sk_drops), &len);
74337 }
74338 seq_printf(seq, "%*s\n", 127 - len, "");
74339 return 0;
74340 diff --git a/net/rds/cong.c b/net/rds/cong.c
74341 index e5b65ac..f3b6fb7 100644
74342 --- a/net/rds/cong.c
74343 +++ b/net/rds/cong.c
74344 @@ -78,7 +78,7 @@
74345 * finds that the saved generation number is smaller than the global generation
74346 * number, it wakes up the process.
74347 */
74348 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
74349 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
74350
74351 /*
74352 * Congestion monitoring
74353 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
74354 rdsdebug("waking map %p for %pI4\n",
74355 map, &map->m_addr);
74356 rds_stats_inc(s_cong_update_received);
74357 - atomic_inc(&rds_cong_generation);
74358 + atomic_inc_unchecked(&rds_cong_generation);
74359 if (waitqueue_active(&map->m_waitq))
74360 wake_up(&map->m_waitq);
74361 if (waitqueue_active(&rds_poll_waitq))
74362 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
74363
74364 int rds_cong_updated_since(unsigned long *recent)
74365 {
74366 - unsigned long gen = atomic_read(&rds_cong_generation);
74367 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
74368
74369 if (likely(*recent == gen))
74370 return 0;
74371 diff --git a/net/rds/ib.h b/net/rds/ib.h
74372 index edfaaaf..8c89879 100644
74373 --- a/net/rds/ib.h
74374 +++ b/net/rds/ib.h
74375 @@ -128,7 +128,7 @@ struct rds_ib_connection {
74376 /* sending acks */
74377 unsigned long i_ack_flags;
74378 #ifdef KERNEL_HAS_ATOMIC64
74379 - atomic64_t i_ack_next; /* next ACK to send */
74380 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
74381 #else
74382 spinlock_t i_ack_lock; /* protect i_ack_next */
74383 u64 i_ack_next; /* next ACK to send */
74384 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
74385 index 51c8689..36c555f 100644
74386 --- a/net/rds/ib_cm.c
74387 +++ b/net/rds/ib_cm.c
74388 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
74389 /* Clear the ACK state */
74390 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
74391 #ifdef KERNEL_HAS_ATOMIC64
74392 - atomic64_set(&ic->i_ack_next, 0);
74393 + atomic64_set_unchecked(&ic->i_ack_next, 0);
74394 #else
74395 ic->i_ack_next = 0;
74396 #endif
74397 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
74398 index e29e0ca..fa3a6a3 100644
74399 --- a/net/rds/ib_recv.c
74400 +++ b/net/rds/ib_recv.c
74401 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
74402 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
74403 int ack_required)
74404 {
74405 - atomic64_set(&ic->i_ack_next, seq);
74406 + atomic64_set_unchecked(&ic->i_ack_next, seq);
74407 if (ack_required) {
74408 smp_mb__before_clear_bit();
74409 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74410 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
74411 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74412 smp_mb__after_clear_bit();
74413
74414 - return atomic64_read(&ic->i_ack_next);
74415 + return atomic64_read_unchecked(&ic->i_ack_next);
74416 }
74417 #endif
74418
74419 diff --git a/net/rds/iw.h b/net/rds/iw.h
74420 index 04ce3b1..48119a6 100644
74421 --- a/net/rds/iw.h
74422 +++ b/net/rds/iw.h
74423 @@ -134,7 +134,7 @@ struct rds_iw_connection {
74424 /* sending acks */
74425 unsigned long i_ack_flags;
74426 #ifdef KERNEL_HAS_ATOMIC64
74427 - atomic64_t i_ack_next; /* next ACK to send */
74428 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
74429 #else
74430 spinlock_t i_ack_lock; /* protect i_ack_next */
74431 u64 i_ack_next; /* next ACK to send */
74432 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
74433 index 9556d28..f046d0e 100644
74434 --- a/net/rds/iw_cm.c
74435 +++ b/net/rds/iw_cm.c
74436 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
74437 /* Clear the ACK state */
74438 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
74439 #ifdef KERNEL_HAS_ATOMIC64
74440 - atomic64_set(&ic->i_ack_next, 0);
74441 + atomic64_set_unchecked(&ic->i_ack_next, 0);
74442 #else
74443 ic->i_ack_next = 0;
74444 #endif
74445 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
74446 index 5e57347..3916042 100644
74447 --- a/net/rds/iw_recv.c
74448 +++ b/net/rds/iw_recv.c
74449 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
74450 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
74451 int ack_required)
74452 {
74453 - atomic64_set(&ic->i_ack_next, seq);
74454 + atomic64_set_unchecked(&ic->i_ack_next, seq);
74455 if (ack_required) {
74456 smp_mb__before_clear_bit();
74457 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74458 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
74459 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74460 smp_mb__after_clear_bit();
74461
74462 - return atomic64_read(&ic->i_ack_next);
74463 + return atomic64_read_unchecked(&ic->i_ack_next);
74464 }
74465 #endif
74466
74467 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
74468 index edac9ef..16bcb98 100644
74469 --- a/net/rds/tcp.c
74470 +++ b/net/rds/tcp.c
74471 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
74472 int val = 1;
74473
74474 set_fs(KERNEL_DS);
74475 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
74476 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
74477 sizeof(val));
74478 set_fs(oldfs);
74479 }
74480 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
74481 index 1b4fd68..2234175 100644
74482 --- a/net/rds/tcp_send.c
74483 +++ b/net/rds/tcp_send.c
74484 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
74485
74486 oldfs = get_fs();
74487 set_fs(KERNEL_DS);
74488 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
74489 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
74490 sizeof(val));
74491 set_fs(oldfs);
74492 }
74493 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
74494 index 74c064c..fdec26f 100644
74495 --- a/net/rxrpc/af_rxrpc.c
74496 +++ b/net/rxrpc/af_rxrpc.c
74497 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
74498 __be32 rxrpc_epoch;
74499
74500 /* current debugging ID */
74501 -atomic_t rxrpc_debug_id;
74502 +atomic_unchecked_t rxrpc_debug_id;
74503
74504 /* count of skbs currently in use */
74505 atomic_t rxrpc_n_skbs;
74506 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
74507 index f99cfce..cc529dd 100644
74508 --- a/net/rxrpc/ar-ack.c
74509 +++ b/net/rxrpc/ar-ack.c
74510 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
74511
74512 _enter("{%d,%d,%d,%d},",
74513 call->acks_hard, call->acks_unacked,
74514 - atomic_read(&call->sequence),
74515 + atomic_read_unchecked(&call->sequence),
74516 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
74517
74518 stop = 0;
74519 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
74520
74521 /* each Tx packet has a new serial number */
74522 sp->hdr.serial =
74523 - htonl(atomic_inc_return(&call->conn->serial));
74524 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
74525
74526 hdr = (struct rxrpc_header *) txb->head;
74527 hdr->serial = sp->hdr.serial;
74528 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
74529 */
74530 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
74531 {
74532 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
74533 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
74534 }
74535
74536 /*
74537 @@ -629,7 +629,7 @@ process_further:
74538
74539 latest = ntohl(sp->hdr.serial);
74540 hard = ntohl(ack.firstPacket);
74541 - tx = atomic_read(&call->sequence);
74542 + tx = atomic_read_unchecked(&call->sequence);
74543
74544 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
74545 latest,
74546 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
74547 goto maybe_reschedule;
74548
74549 send_ACK_with_skew:
74550 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
74551 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
74552 ntohl(ack.serial));
74553 send_ACK:
74554 mtu = call->conn->trans->peer->if_mtu;
74555 @@ -1173,7 +1173,7 @@ send_ACK:
74556 ackinfo.rxMTU = htonl(5692);
74557 ackinfo.jumbo_max = htonl(4);
74558
74559 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
74560 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
74561 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
74562 ntohl(hdr.serial),
74563 ntohs(ack.maxSkew),
74564 @@ -1191,7 +1191,7 @@ send_ACK:
74565 send_message:
74566 _debug("send message");
74567
74568 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
74569 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
74570 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
74571 send_message_2:
74572
74573 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
74574 index bf656c2..48f9d27 100644
74575 --- a/net/rxrpc/ar-call.c
74576 +++ b/net/rxrpc/ar-call.c
74577 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
74578 spin_lock_init(&call->lock);
74579 rwlock_init(&call->state_lock);
74580 atomic_set(&call->usage, 1);
74581 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
74582 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74583 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
74584
74585 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
74586 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
74587 index 4106ca9..a338d7a 100644
74588 --- a/net/rxrpc/ar-connection.c
74589 +++ b/net/rxrpc/ar-connection.c
74590 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
74591 rwlock_init(&conn->lock);
74592 spin_lock_init(&conn->state_lock);
74593 atomic_set(&conn->usage, 1);
74594 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
74595 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74596 conn->avail_calls = RXRPC_MAXCALLS;
74597 conn->size_align = 4;
74598 conn->header_size = sizeof(struct rxrpc_header);
74599 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
74600 index e7ed43a..6afa140 100644
74601 --- a/net/rxrpc/ar-connevent.c
74602 +++ b/net/rxrpc/ar-connevent.c
74603 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
74604
74605 len = iov[0].iov_len + iov[1].iov_len;
74606
74607 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
74608 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
74609 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
74610
74611 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
74612 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
74613 index 1a2b0633..e8d1382 100644
74614 --- a/net/rxrpc/ar-input.c
74615 +++ b/net/rxrpc/ar-input.c
74616 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
74617 /* track the latest serial number on this connection for ACK packet
74618 * information */
74619 serial = ntohl(sp->hdr.serial);
74620 - hi_serial = atomic_read(&call->conn->hi_serial);
74621 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
74622 while (serial > hi_serial)
74623 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
74624 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
74625 serial);
74626
74627 /* request ACK generation for any ACK or DATA packet that requests
74628 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
74629 index 8e22bd3..f66d1c0 100644
74630 --- a/net/rxrpc/ar-internal.h
74631 +++ b/net/rxrpc/ar-internal.h
74632 @@ -272,8 +272,8 @@ struct rxrpc_connection {
74633 int error; /* error code for local abort */
74634 int debug_id; /* debug ID for printks */
74635 unsigned call_counter; /* call ID counter */
74636 - atomic_t serial; /* packet serial number counter */
74637 - atomic_t hi_serial; /* highest serial number received */
74638 + atomic_unchecked_t serial; /* packet serial number counter */
74639 + atomic_unchecked_t hi_serial; /* highest serial number received */
74640 u8 avail_calls; /* number of calls available */
74641 u8 size_align; /* data size alignment (for security) */
74642 u8 header_size; /* rxrpc + security header size */
74643 @@ -346,7 +346,7 @@ struct rxrpc_call {
74644 spinlock_t lock;
74645 rwlock_t state_lock; /* lock for state transition */
74646 atomic_t usage;
74647 - atomic_t sequence; /* Tx data packet sequence counter */
74648 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
74649 u32 abort_code; /* local/remote abort code */
74650 enum { /* current state of call */
74651 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
74652 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
74653 */
74654 extern atomic_t rxrpc_n_skbs;
74655 extern __be32 rxrpc_epoch;
74656 -extern atomic_t rxrpc_debug_id;
74657 +extern atomic_unchecked_t rxrpc_debug_id;
74658 extern struct workqueue_struct *rxrpc_workqueue;
74659
74660 /*
74661 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
74662 index 87f7135..74d3703 100644
74663 --- a/net/rxrpc/ar-local.c
74664 +++ b/net/rxrpc/ar-local.c
74665 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
74666 spin_lock_init(&local->lock);
74667 rwlock_init(&local->services_lock);
74668 atomic_set(&local->usage, 1);
74669 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
74670 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74671 memcpy(&local->srx, srx, sizeof(*srx));
74672 }
74673
74674 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
74675 index 338d793..47391d0 100644
74676 --- a/net/rxrpc/ar-output.c
74677 +++ b/net/rxrpc/ar-output.c
74678 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
74679 sp->hdr.cid = call->cid;
74680 sp->hdr.callNumber = call->call_id;
74681 sp->hdr.seq =
74682 - htonl(atomic_inc_return(&call->sequence));
74683 + htonl(atomic_inc_return_unchecked(&call->sequence));
74684 sp->hdr.serial =
74685 - htonl(atomic_inc_return(&conn->serial));
74686 + htonl(atomic_inc_return_unchecked(&conn->serial));
74687 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
74688 sp->hdr.userStatus = 0;
74689 sp->hdr.securityIndex = conn->security_ix;
74690 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
74691 index 2754f09..b20e38f 100644
74692 --- a/net/rxrpc/ar-peer.c
74693 +++ b/net/rxrpc/ar-peer.c
74694 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
74695 INIT_LIST_HEAD(&peer->error_targets);
74696 spin_lock_init(&peer->lock);
74697 atomic_set(&peer->usage, 1);
74698 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
74699 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74700 memcpy(&peer->srx, srx, sizeof(*srx));
74701
74702 rxrpc_assess_MTU_size(peer);
74703 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
74704 index 38047f7..9f48511 100644
74705 --- a/net/rxrpc/ar-proc.c
74706 +++ b/net/rxrpc/ar-proc.c
74707 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
74708 atomic_read(&conn->usage),
74709 rxrpc_conn_states[conn->state],
74710 key_serial(conn->key),
74711 - atomic_read(&conn->serial),
74712 - atomic_read(&conn->hi_serial));
74713 + atomic_read_unchecked(&conn->serial),
74714 + atomic_read_unchecked(&conn->hi_serial));
74715
74716 return 0;
74717 }
74718 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
74719 index 92df566..87ec1bf 100644
74720 --- a/net/rxrpc/ar-transport.c
74721 +++ b/net/rxrpc/ar-transport.c
74722 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
74723 spin_lock_init(&trans->client_lock);
74724 rwlock_init(&trans->conn_lock);
74725 atomic_set(&trans->usage, 1);
74726 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
74727 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74728
74729 if (peer->srx.transport.family == AF_INET) {
74730 switch (peer->srx.transport_type) {
74731 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
74732 index 7635107..4670276 100644
74733 --- a/net/rxrpc/rxkad.c
74734 +++ b/net/rxrpc/rxkad.c
74735 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
74736
74737 len = iov[0].iov_len + iov[1].iov_len;
74738
74739 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
74740 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
74741 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
74742
74743 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
74744 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
74745
74746 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
74747
74748 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
74749 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
74750 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
74751
74752 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
74753 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
74754 index 1e2eee8..ce3967e 100644
74755 --- a/net/sctp/proc.c
74756 +++ b/net/sctp/proc.c
74757 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
74758 seq_printf(seq,
74759 "%8pK %8pK %-3d %-3d %-2d %-4d "
74760 "%4d %8d %8d %7d %5lu %-5d %5d ",
74761 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
74762 + assoc, sk,
74763 + sctp_sk(sk)->type, sk->sk_state,
74764 assoc->state, hash,
74765 assoc->assoc_id,
74766 assoc->sndbuf_used,
74767 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
74768 index 54a7cd2..944edae 100644
74769 --- a/net/sctp/socket.c
74770 +++ b/net/sctp/socket.c
74771 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
74772 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
74773 if (space_left < addrlen)
74774 return -ENOMEM;
74775 - if (copy_to_user(to, &temp, addrlen))
74776 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
74777 return -EFAULT;
74778 to += addrlen;
74779 cnt++;
74780 diff --git a/net/socket.c b/net/socket.c
74781 index 2877647..08e2fde 100644
74782 --- a/net/socket.c
74783 +++ b/net/socket.c
74784 @@ -88,6 +88,7 @@
74785 #include <linux/nsproxy.h>
74786 #include <linux/magic.h>
74787 #include <linux/slab.h>
74788 +#include <linux/in.h>
74789
74790 #include <asm/uaccess.h>
74791 #include <asm/unistd.h>
74792 @@ -105,6 +106,8 @@
74793 #include <linux/sockios.h>
74794 #include <linux/atalk.h>
74795
74796 +#include <linux/grsock.h>
74797 +
74798 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
74799 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
74800 unsigned long nr_segs, loff_t pos);
74801 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
74802 &sockfs_dentry_operations, SOCKFS_MAGIC);
74803 }
74804
74805 -static struct vfsmount *sock_mnt __read_mostly;
74806 +struct vfsmount *sock_mnt __read_mostly;
74807
74808 static struct file_system_type sock_fs_type = {
74809 .name = "sockfs",
74810 @@ -1187,6 +1190,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
74811 return -EAFNOSUPPORT;
74812 if (type < 0 || type >= SOCK_MAX)
74813 return -EINVAL;
74814 + if (protocol < 0)
74815 + return -EINVAL;
74816
74817 /* Compatibility.
74818
74819 @@ -1319,6 +1324,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
74820 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
74821 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
74822
74823 + if(!gr_search_socket(family, type, protocol)) {
74824 + retval = -EACCES;
74825 + goto out;
74826 + }
74827 +
74828 + if (gr_handle_sock_all(family, type, protocol)) {
74829 + retval = -EACCES;
74830 + goto out;
74831 + }
74832 +
74833 retval = sock_create(family, type, protocol, &sock);
74834 if (retval < 0)
74835 goto out;
74836 @@ -1431,6 +1446,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
74837 if (sock) {
74838 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
74839 if (err >= 0) {
74840 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
74841 + err = -EACCES;
74842 + goto error;
74843 + }
74844 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
74845 + if (err)
74846 + goto error;
74847 +
74848 err = security_socket_bind(sock,
74849 (struct sockaddr *)&address,
74850 addrlen);
74851 @@ -1439,6 +1462,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
74852 (struct sockaddr *)
74853 &address, addrlen);
74854 }
74855 +error:
74856 fput_light(sock->file, fput_needed);
74857 }
74858 return err;
74859 @@ -1462,10 +1486,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
74860 if ((unsigned)backlog > somaxconn)
74861 backlog = somaxconn;
74862
74863 + if (gr_handle_sock_server_other(sock->sk)) {
74864 + err = -EPERM;
74865 + goto error;
74866 + }
74867 +
74868 + err = gr_search_listen(sock);
74869 + if (err)
74870 + goto error;
74871 +
74872 err = security_socket_listen(sock, backlog);
74873 if (!err)
74874 err = sock->ops->listen(sock, backlog);
74875
74876 +error:
74877 fput_light(sock->file, fput_needed);
74878 }
74879 return err;
74880 @@ -1509,6 +1543,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
74881 newsock->type = sock->type;
74882 newsock->ops = sock->ops;
74883
74884 + if (gr_handle_sock_server_other(sock->sk)) {
74885 + err = -EPERM;
74886 + sock_release(newsock);
74887 + goto out_put;
74888 + }
74889 +
74890 + err = gr_search_accept(sock);
74891 + if (err) {
74892 + sock_release(newsock);
74893 + goto out_put;
74894 + }
74895 +
74896 /*
74897 * We don't need try_module_get here, as the listening socket (sock)
74898 * has the protocol module (sock->ops->owner) held.
74899 @@ -1547,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
74900 fd_install(newfd, newfile);
74901 err = newfd;
74902
74903 + gr_attach_curr_ip(newsock->sk);
74904 +
74905 out_put:
74906 fput_light(sock->file, fput_needed);
74907 out:
74908 @@ -1579,6 +1627,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
74909 int, addrlen)
74910 {
74911 struct socket *sock;
74912 + struct sockaddr *sck;
74913 struct sockaddr_storage address;
74914 int err, fput_needed;
74915
74916 @@ -1589,6 +1638,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
74917 if (err < 0)
74918 goto out_put;
74919
74920 + sck = (struct sockaddr *)&address;
74921 +
74922 + if (gr_handle_sock_client(sck)) {
74923 + err = -EACCES;
74924 + goto out_put;
74925 + }
74926 +
74927 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
74928 + if (err)
74929 + goto out_put;
74930 +
74931 err =
74932 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
74933 if (err)
74934 @@ -1950,7 +2010,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
74935 * checking falls down on this.
74936 */
74937 if (copy_from_user(ctl_buf,
74938 - (void __user __force *)msg_sys->msg_control,
74939 + (void __force_user *)msg_sys->msg_control,
74940 ctl_len))
74941 goto out_freectl;
74942 msg_sys->msg_control = ctl_buf;
74943 @@ -2120,7 +2180,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
74944 * kernel msghdr to use the kernel address space)
74945 */
74946
74947 - uaddr = (__force void __user *)msg_sys->msg_name;
74948 + uaddr = (void __force_user *)msg_sys->msg_name;
74949 uaddr_len = COMPAT_NAMELEN(msg);
74950 if (MSG_CMSG_COMPAT & flags) {
74951 err = verify_compat_iovec(msg_sys, iov,
74952 @@ -2748,7 +2808,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
74953 }
74954
74955 ifr = compat_alloc_user_space(buf_size);
74956 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
74957 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
74958
74959 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
74960 return -EFAULT;
74961 @@ -2772,12 +2832,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
74962 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
74963
74964 if (copy_in_user(rxnfc, compat_rxnfc,
74965 - (void *)(&rxnfc->fs.m_ext + 1) -
74966 - (void *)rxnfc) ||
74967 + (void __user *)(&rxnfc->fs.m_ext + 1) -
74968 + (void __user *)rxnfc) ||
74969 copy_in_user(&rxnfc->fs.ring_cookie,
74970 &compat_rxnfc->fs.ring_cookie,
74971 - (void *)(&rxnfc->fs.location + 1) -
74972 - (void *)&rxnfc->fs.ring_cookie) ||
74973 + (void __user *)(&rxnfc->fs.location + 1) -
74974 + (void __user *)&rxnfc->fs.ring_cookie) ||
74975 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
74976 sizeof(rxnfc->rule_cnt)))
74977 return -EFAULT;
74978 @@ -2789,12 +2849,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
74979
74980 if (convert_out) {
74981 if (copy_in_user(compat_rxnfc, rxnfc,
74982 - (const void *)(&rxnfc->fs.m_ext + 1) -
74983 - (const void *)rxnfc) ||
74984 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
74985 + (const void __user *)rxnfc) ||
74986 copy_in_user(&compat_rxnfc->fs.ring_cookie,
74987 &rxnfc->fs.ring_cookie,
74988 - (const void *)(&rxnfc->fs.location + 1) -
74989 - (const void *)&rxnfc->fs.ring_cookie) ||
74990 + (const void __user *)(&rxnfc->fs.location + 1) -
74991 + (const void __user *)&rxnfc->fs.ring_cookie) ||
74992 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
74993 sizeof(rxnfc->rule_cnt)))
74994 return -EFAULT;
74995 @@ -2864,7 +2924,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
74996 old_fs = get_fs();
74997 set_fs(KERNEL_DS);
74998 err = dev_ioctl(net, cmd,
74999 - (struct ifreq __user __force *) &kifr);
75000 + (struct ifreq __force_user *) &kifr);
75001 set_fs(old_fs);
75002
75003 return err;
75004 @@ -2973,7 +3033,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
75005
75006 old_fs = get_fs();
75007 set_fs(KERNEL_DS);
75008 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
75009 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
75010 set_fs(old_fs);
75011
75012 if (cmd == SIOCGIFMAP && !err) {
75013 @@ -3078,7 +3138,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
75014 ret |= __get_user(rtdev, &(ur4->rt_dev));
75015 if (rtdev) {
75016 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
75017 - r4.rt_dev = (char __user __force *)devname;
75018 + r4.rt_dev = (char __force_user *)devname;
75019 devname[15] = 0;
75020 } else
75021 r4.rt_dev = NULL;
75022 @@ -3318,8 +3378,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
75023 int __user *uoptlen;
75024 int err;
75025
75026 - uoptval = (char __user __force *) optval;
75027 - uoptlen = (int __user __force *) optlen;
75028 + uoptval = (char __force_user *) optval;
75029 + uoptlen = (int __force_user *) optlen;
75030
75031 set_fs(KERNEL_DS);
75032 if (level == SOL_SOCKET)
75033 @@ -3339,7 +3399,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
75034 char __user *uoptval;
75035 int err;
75036
75037 - uoptval = (char __user __force *) optval;
75038 + uoptval = (char __force_user *) optval;
75039
75040 set_fs(KERNEL_DS);
75041 if (level == SOL_SOCKET)
75042 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
75043 index 00a1a2a..6a0138a 100644
75044 --- a/net/sunrpc/sched.c
75045 +++ b/net/sunrpc/sched.c
75046 @@ -238,9 +238,9 @@ static int rpc_wait_bit_killable(void *word)
75047 #ifdef RPC_DEBUG
75048 static void rpc_task_set_debuginfo(struct rpc_task *task)
75049 {
75050 - static atomic_t rpc_pid;
75051 + static atomic_unchecked_t rpc_pid;
75052
75053 - task->tk_pid = atomic_inc_return(&rpc_pid);
75054 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
75055 }
75056 #else
75057 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
75058 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
75059 index 71bed1c..5dff36d 100644
75060 --- a/net/sunrpc/svcsock.c
75061 +++ b/net/sunrpc/svcsock.c
75062 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
75063 int buflen, unsigned int base)
75064 {
75065 size_t save_iovlen;
75066 - void __user *save_iovbase;
75067 + void *save_iovbase;
75068 unsigned int i;
75069 int ret;
75070
75071 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
75072 index 09af4fa..77110a9 100644
75073 --- a/net/sunrpc/xprtrdma/svc_rdma.c
75074 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
75075 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
75076 static unsigned int min_max_inline = 4096;
75077 static unsigned int max_max_inline = 65536;
75078
75079 -atomic_t rdma_stat_recv;
75080 -atomic_t rdma_stat_read;
75081 -atomic_t rdma_stat_write;
75082 -atomic_t rdma_stat_sq_starve;
75083 -atomic_t rdma_stat_rq_starve;
75084 -atomic_t rdma_stat_rq_poll;
75085 -atomic_t rdma_stat_rq_prod;
75086 -atomic_t rdma_stat_sq_poll;
75087 -atomic_t rdma_stat_sq_prod;
75088 +atomic_unchecked_t rdma_stat_recv;
75089 +atomic_unchecked_t rdma_stat_read;
75090 +atomic_unchecked_t rdma_stat_write;
75091 +atomic_unchecked_t rdma_stat_sq_starve;
75092 +atomic_unchecked_t rdma_stat_rq_starve;
75093 +atomic_unchecked_t rdma_stat_rq_poll;
75094 +atomic_unchecked_t rdma_stat_rq_prod;
75095 +atomic_unchecked_t rdma_stat_sq_poll;
75096 +atomic_unchecked_t rdma_stat_sq_prod;
75097
75098 /* Temporary NFS request map and context caches */
75099 struct kmem_cache *svc_rdma_map_cachep;
75100 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
75101 len -= *ppos;
75102 if (len > *lenp)
75103 len = *lenp;
75104 - if (len && copy_to_user(buffer, str_buf, len))
75105 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
75106 return -EFAULT;
75107 *lenp = len;
75108 *ppos += len;
75109 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
75110 {
75111 .procname = "rdma_stat_read",
75112 .data = &rdma_stat_read,
75113 - .maxlen = sizeof(atomic_t),
75114 + .maxlen = sizeof(atomic_unchecked_t),
75115 .mode = 0644,
75116 .proc_handler = read_reset_stat,
75117 },
75118 {
75119 .procname = "rdma_stat_recv",
75120 .data = &rdma_stat_recv,
75121 - .maxlen = sizeof(atomic_t),
75122 + .maxlen = sizeof(atomic_unchecked_t),
75123 .mode = 0644,
75124 .proc_handler = read_reset_stat,
75125 },
75126 {
75127 .procname = "rdma_stat_write",
75128 .data = &rdma_stat_write,
75129 - .maxlen = sizeof(atomic_t),
75130 + .maxlen = sizeof(atomic_unchecked_t),
75131 .mode = 0644,
75132 .proc_handler = read_reset_stat,
75133 },
75134 {
75135 .procname = "rdma_stat_sq_starve",
75136 .data = &rdma_stat_sq_starve,
75137 - .maxlen = sizeof(atomic_t),
75138 + .maxlen = sizeof(atomic_unchecked_t),
75139 .mode = 0644,
75140 .proc_handler = read_reset_stat,
75141 },
75142 {
75143 .procname = "rdma_stat_rq_starve",
75144 .data = &rdma_stat_rq_starve,
75145 - .maxlen = sizeof(atomic_t),
75146 + .maxlen = sizeof(atomic_unchecked_t),
75147 .mode = 0644,
75148 .proc_handler = read_reset_stat,
75149 },
75150 {
75151 .procname = "rdma_stat_rq_poll",
75152 .data = &rdma_stat_rq_poll,
75153 - .maxlen = sizeof(atomic_t),
75154 + .maxlen = sizeof(atomic_unchecked_t),
75155 .mode = 0644,
75156 .proc_handler = read_reset_stat,
75157 },
75158 {
75159 .procname = "rdma_stat_rq_prod",
75160 .data = &rdma_stat_rq_prod,
75161 - .maxlen = sizeof(atomic_t),
75162 + .maxlen = sizeof(atomic_unchecked_t),
75163 .mode = 0644,
75164 .proc_handler = read_reset_stat,
75165 },
75166 {
75167 .procname = "rdma_stat_sq_poll",
75168 .data = &rdma_stat_sq_poll,
75169 - .maxlen = sizeof(atomic_t),
75170 + .maxlen = sizeof(atomic_unchecked_t),
75171 .mode = 0644,
75172 .proc_handler = read_reset_stat,
75173 },
75174 {
75175 .procname = "rdma_stat_sq_prod",
75176 .data = &rdma_stat_sq_prod,
75177 - .maxlen = sizeof(atomic_t),
75178 + .maxlen = sizeof(atomic_unchecked_t),
75179 .mode = 0644,
75180 .proc_handler = read_reset_stat,
75181 },
75182 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75183 index df67211..c354b13 100644
75184 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75185 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75186 @@ -499,7 +499,7 @@ next_sge:
75187 svc_rdma_put_context(ctxt, 0);
75188 goto out;
75189 }
75190 - atomic_inc(&rdma_stat_read);
75191 + atomic_inc_unchecked(&rdma_stat_read);
75192
75193 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
75194 chl_map->ch[ch_no].count -= read_wr.num_sge;
75195 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
75196 dto_q);
75197 list_del_init(&ctxt->dto_q);
75198 } else {
75199 - atomic_inc(&rdma_stat_rq_starve);
75200 + atomic_inc_unchecked(&rdma_stat_rq_starve);
75201 clear_bit(XPT_DATA, &xprt->xpt_flags);
75202 ctxt = NULL;
75203 }
75204 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
75205 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
75206 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
75207 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
75208 - atomic_inc(&rdma_stat_recv);
75209 + atomic_inc_unchecked(&rdma_stat_recv);
75210
75211 /* Build up the XDR from the receive buffers. */
75212 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
75213 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75214 index 249a835..fb2794b 100644
75215 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75216 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75217 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
75218 write_wr.wr.rdma.remote_addr = to;
75219
75220 /* Post It */
75221 - atomic_inc(&rdma_stat_write);
75222 + atomic_inc_unchecked(&rdma_stat_write);
75223 if (svc_rdma_send(xprt, &write_wr))
75224 goto err;
75225 return 0;
75226 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
75227 index ba1296d..0fec1a5 100644
75228 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
75229 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
75230 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
75231 return;
75232
75233 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
75234 - atomic_inc(&rdma_stat_rq_poll);
75235 + atomic_inc_unchecked(&rdma_stat_rq_poll);
75236
75237 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
75238 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
75239 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
75240 }
75241
75242 if (ctxt)
75243 - atomic_inc(&rdma_stat_rq_prod);
75244 + atomic_inc_unchecked(&rdma_stat_rq_prod);
75245
75246 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
75247 /*
75248 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
75249 return;
75250
75251 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
75252 - atomic_inc(&rdma_stat_sq_poll);
75253 + atomic_inc_unchecked(&rdma_stat_sq_poll);
75254 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
75255 if (wc.status != IB_WC_SUCCESS)
75256 /* Close the transport */
75257 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
75258 }
75259
75260 if (ctxt)
75261 - atomic_inc(&rdma_stat_sq_prod);
75262 + atomic_inc_unchecked(&rdma_stat_sq_prod);
75263 }
75264
75265 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
75266 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
75267 spin_lock_bh(&xprt->sc_lock);
75268 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
75269 spin_unlock_bh(&xprt->sc_lock);
75270 - atomic_inc(&rdma_stat_sq_starve);
75271 + atomic_inc_unchecked(&rdma_stat_sq_starve);
75272
75273 /* See if we can opportunistically reap SQ WR to make room */
75274 sq_cq_reap(xprt);
75275 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
75276 index e758139..d29ea47 100644
75277 --- a/net/sysctl_net.c
75278 +++ b/net/sysctl_net.c
75279 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
75280 struct ctl_table *table)
75281 {
75282 /* Allow network administrator to have same access as root. */
75283 - if (capable(CAP_NET_ADMIN)) {
75284 + if (capable_nolog(CAP_NET_ADMIN)) {
75285 int mode = (table->mode >> 6) & 7;
75286 return (mode << 6) | (mode << 3) | mode;
75287 }
75288 diff --git a/net/tipc/link.c b/net/tipc/link.c
75289 index ae98a72..7bb6056 100644
75290 --- a/net/tipc/link.c
75291 +++ b/net/tipc/link.c
75292 @@ -1203,7 +1203,7 @@ static int link_send_sections_long(struct tipc_port *sender,
75293 struct tipc_msg fragm_hdr;
75294 struct sk_buff *buf, *buf_chain, *prev;
75295 u32 fragm_crs, fragm_rest, hsz, sect_rest;
75296 - const unchar *sect_crs;
75297 + const unchar __user *sect_crs;
75298 int curr_sect;
75299 u32 fragm_no;
75300
75301 @@ -1247,7 +1247,7 @@ again:
75302
75303 if (!sect_rest) {
75304 sect_rest = msg_sect[++curr_sect].iov_len;
75305 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
75306 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
75307 }
75308
75309 if (sect_rest < fragm_rest)
75310 @@ -1266,7 +1266,7 @@ error:
75311 }
75312 } else
75313 skb_copy_to_linear_data_offset(buf, fragm_crs,
75314 - sect_crs, sz);
75315 + (const void __force_kernel *)sect_crs, sz);
75316 sect_crs += sz;
75317 sect_rest -= sz;
75318 fragm_crs += sz;
75319 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
75320 index 83d5096..dcba497 100644
75321 --- a/net/tipc/msg.c
75322 +++ b/net/tipc/msg.c
75323 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
75324 msg_sect[cnt].iov_len);
75325 else
75326 skb_copy_to_linear_data_offset(*buf, pos,
75327 - msg_sect[cnt].iov_base,
75328 + (const void __force_kernel *)msg_sect[cnt].iov_base,
75329 msg_sect[cnt].iov_len);
75330 pos += msg_sect[cnt].iov_len;
75331 }
75332 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
75333 index 1983717..4d6102c 100644
75334 --- a/net/tipc/subscr.c
75335 +++ b/net/tipc/subscr.c
75336 @@ -101,7 +101,7 @@ static void subscr_send_event(struct subscription *sub,
75337 {
75338 struct iovec msg_sect;
75339
75340 - msg_sect.iov_base = (void *)&sub->evt;
75341 + msg_sect.iov_base = (void __force_user *)&sub->evt;
75342 msg_sect.iov_len = sizeof(struct tipc_event);
75343
75344 sub->evt.event = htohl(event, sub->swap);
75345 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
75346 index b595a3d..b1cd354 100644
75347 --- a/net/unix/af_unix.c
75348 +++ b/net/unix/af_unix.c
75349 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(struct net *net,
75350 err = -ECONNREFUSED;
75351 if (!S_ISSOCK(inode->i_mode))
75352 goto put_fail;
75353 +
75354 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
75355 + err = -EACCES;
75356 + goto put_fail;
75357 + }
75358 +
75359 u = unix_find_socket_byinode(inode);
75360 if (!u)
75361 goto put_fail;
75362 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(struct net *net,
75363 if (u) {
75364 struct dentry *dentry;
75365 dentry = unix_sk(u)->dentry;
75366 +
75367 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
75368 + err = -EPERM;
75369 + sock_put(u);
75370 + goto fail;
75371 + }
75372 +
75373 if (dentry)
75374 touch_atime(unix_sk(u)->mnt, dentry);
75375 } else
75376 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
75377 err = security_path_mknod(&path, dentry, mode, 0);
75378 if (err)
75379 goto out_mknod_drop_write;
75380 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
75381 + err = -EACCES;
75382 + goto out_mknod_drop_write;
75383 + }
75384 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
75385 out_mknod_drop_write:
75386 mnt_drop_write(path.mnt);
75387 if (err)
75388 goto out_mknod_dput;
75389 +
75390 + gr_handle_create(dentry, path.mnt);
75391 +
75392 mutex_unlock(&path.dentry->d_inode->i_mutex);
75393 dput(path.dentry);
75394 path.dentry = dentry;
75395 diff --git a/net/wireless/core.h b/net/wireless/core.h
75396 index b9ec306..b4a563e 100644
75397 --- a/net/wireless/core.h
75398 +++ b/net/wireless/core.h
75399 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
75400 struct mutex mtx;
75401
75402 /* rfkill support */
75403 - struct rfkill_ops rfkill_ops;
75404 + rfkill_ops_no_const rfkill_ops;
75405 struct rfkill *rfkill;
75406 struct work_struct rfkill_sync;
75407
75408 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
75409 index 0af7f54..c916d2f 100644
75410 --- a/net/wireless/wext-core.c
75411 +++ b/net/wireless/wext-core.c
75412 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
75413 */
75414
75415 /* Support for very large requests */
75416 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
75417 - (user_length > descr->max_tokens)) {
75418 + if (user_length > descr->max_tokens) {
75419 /* Allow userspace to GET more than max so
75420 * we can support any size GET requests.
75421 * There is still a limit : -ENOMEM.
75422 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
75423 }
75424 }
75425
75426 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
75427 - /*
75428 - * If this is a GET, but not NOMAX, it means that the extra
75429 - * data is not bounded by userspace, but by max_tokens. Thus
75430 - * set the length to max_tokens. This matches the extra data
75431 - * allocation.
75432 - * The driver should fill it with the number of tokens it
75433 - * provided, and it may check iwp->length rather than having
75434 - * knowledge of max_tokens. If the driver doesn't change the
75435 - * iwp->length, this ioctl just copies back max_token tokens
75436 - * filled with zeroes. Hopefully the driver isn't claiming
75437 - * them to be valid data.
75438 - */
75439 - iwp->length = descr->max_tokens;
75440 - }
75441 -
75442 err = handler(dev, info, (union iwreq_data *) iwp, extra);
75443
75444 iwp->length += essid_compat;
75445 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
75446 index 9049a5c..cfa6f5c 100644
75447 --- a/net/xfrm/xfrm_policy.c
75448 +++ b/net/xfrm/xfrm_policy.c
75449 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
75450 {
75451 policy->walk.dead = 1;
75452
75453 - atomic_inc(&policy->genid);
75454 + atomic_inc_unchecked(&policy->genid);
75455
75456 if (del_timer(&policy->timer))
75457 xfrm_pol_put(policy);
75458 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
75459 hlist_add_head(&policy->bydst, chain);
75460 xfrm_pol_hold(policy);
75461 net->xfrm.policy_count[dir]++;
75462 - atomic_inc(&flow_cache_genid);
75463 + atomic_inc_unchecked(&flow_cache_genid);
75464 if (delpol)
75465 __xfrm_policy_unlink(delpol, dir);
75466 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
75467 @@ -1530,7 +1530,7 @@ free_dst:
75468 goto out;
75469 }
75470
75471 -static int inline
75472 +static inline int
75473 xfrm_dst_alloc_copy(void **target, const void *src, int size)
75474 {
75475 if (!*target) {
75476 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
75477 return 0;
75478 }
75479
75480 -static int inline
75481 +static inline int
75482 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
75483 {
75484 #ifdef CONFIG_XFRM_SUB_POLICY
75485 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
75486 #endif
75487 }
75488
75489 -static int inline
75490 +static inline int
75491 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
75492 {
75493 #ifdef CONFIG_XFRM_SUB_POLICY
75494 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
75495
75496 xdst->num_pols = num_pols;
75497 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
75498 - xdst->policy_genid = atomic_read(&pols[0]->genid);
75499 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
75500
75501 return xdst;
75502 }
75503 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
75504 if (xdst->xfrm_genid != dst->xfrm->genid)
75505 return 0;
75506 if (xdst->num_pols > 0 &&
75507 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
75508 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
75509 return 0;
75510
75511 mtu = dst_mtu(dst->child);
75512 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
75513 sizeof(pol->xfrm_vec[i].saddr));
75514 pol->xfrm_vec[i].encap_family = mp->new_family;
75515 /* flush bundles */
75516 - atomic_inc(&pol->genid);
75517 + atomic_inc_unchecked(&pol->genid);
75518 }
75519 }
75520
75521 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
75522 index d2b366c..51ff91e 100644
75523 --- a/scripts/Makefile.build
75524 +++ b/scripts/Makefile.build
75525 @@ -109,7 +109,7 @@ endif
75526 endif
75527
75528 # Do not include host rules unless needed
75529 -ifneq ($(hostprogs-y)$(hostprogs-m),)
75530 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
75531 include scripts/Makefile.host
75532 endif
75533
75534 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
75535 index 686cb0d..9d653bf 100644
75536 --- a/scripts/Makefile.clean
75537 +++ b/scripts/Makefile.clean
75538 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
75539 __clean-files := $(extra-y) $(always) \
75540 $(targets) $(clean-files) \
75541 $(host-progs) \
75542 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
75543 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
75544 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
75545
75546 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
75547
75548 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
75549 index 1ac414f..a1c1451 100644
75550 --- a/scripts/Makefile.host
75551 +++ b/scripts/Makefile.host
75552 @@ -31,6 +31,7 @@
75553 # Note: Shared libraries consisting of C++ files are not supported
75554
75555 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
75556 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
75557
75558 # C code
75559 # Executables compiled from a single .c file
75560 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
75561 # Shared libaries (only .c supported)
75562 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
75563 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
75564 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
75565 # Remove .so files from "xxx-objs"
75566 host-cobjs := $(filter-out %.so,$(host-cobjs))
75567
75568 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
75569 index cb1f50c..cef2a7c 100644
75570 --- a/scripts/basic/fixdep.c
75571 +++ b/scripts/basic/fixdep.c
75572 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
75573 /*
75574 * Lookup a value in the configuration string.
75575 */
75576 -static int is_defined_config(const char *name, int len, unsigned int hash)
75577 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
75578 {
75579 struct item *aux;
75580
75581 @@ -211,10 +211,10 @@ static void clear_config(void)
75582 /*
75583 * Record the use of a CONFIG_* word.
75584 */
75585 -static void use_config(const char *m, int slen)
75586 +static void use_config(const char *m, unsigned int slen)
75587 {
75588 unsigned int hash = strhash(m, slen);
75589 - int c, i;
75590 + unsigned int c, i;
75591
75592 if (is_defined_config(m, slen, hash))
75593 return;
75594 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
75595
75596 static void parse_config_file(const char *map, size_t len)
75597 {
75598 - const int *end = (const int *) (map + len);
75599 + const unsigned int *end = (const unsigned int *) (map + len);
75600 /* start at +1, so that p can never be < map */
75601 - const int *m = (const int *) map + 1;
75602 + const unsigned int *m = (const unsigned int *) map + 1;
75603 const char *p, *q;
75604
75605 for (; m < end; m++) {
75606 @@ -406,7 +406,7 @@ static void print_deps(void)
75607 static void traps(void)
75608 {
75609 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
75610 - int *p = (int *)test;
75611 + unsigned int *p = (unsigned int *)test;
75612
75613 if (*p != INT_CONF) {
75614 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
75615 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
75616 new file mode 100644
75617 index 0000000..8729101
75618 --- /dev/null
75619 +++ b/scripts/gcc-plugin.sh
75620 @@ -0,0 +1,2 @@
75621 +#!/bin/sh
75622 +echo -e "#include \"gcc-plugin.h\"\n#include \"tree.h\"\n#include \"tm.h\"\n#include \"rtl.h\"" | $1 -x c -shared - -o /dev/null -I`$2 -print-file-name=plugin`/include >/dev/null 2>&1 && echo "y"
75623 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
75624 index f936d1f..a66d95f 100644
75625 --- a/scripts/mod/file2alias.c
75626 +++ b/scripts/mod/file2alias.c
75627 @@ -72,7 +72,7 @@ static void device_id_check(const char *modname, const char *device_id,
75628 unsigned long size, unsigned long id_size,
75629 void *symval)
75630 {
75631 - int i;
75632 + unsigned int i;
75633
75634 if (size % id_size || size < id_size) {
75635 if (cross_build != 0)
75636 @@ -102,7 +102,7 @@ static void device_id_check(const char *modname, const char *device_id,
75637 /* USB is special because the bcdDevice can be matched against a numeric range */
75638 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
75639 static void do_usb_entry(struct usb_device_id *id,
75640 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
75641 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
75642 unsigned char range_lo, unsigned char range_hi,
75643 unsigned char max, struct module *mod)
75644 {
75645 @@ -203,7 +203,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
75646 {
75647 unsigned int devlo, devhi;
75648 unsigned char chi, clo, max;
75649 - int ndigits;
75650 + unsigned int ndigits;
75651
75652 id->match_flags = TO_NATIVE(id->match_flags);
75653 id->idVendor = TO_NATIVE(id->idVendor);
75654 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
75655 for (i = 0; i < count; i++) {
75656 const char *id = (char *)devs[i].id;
75657 char acpi_id[sizeof(devs[0].id)];
75658 - int j;
75659 + unsigned int j;
75660
75661 buf_printf(&mod->dev_table_buf,
75662 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
75663 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
75664
75665 for (j = 0; j < PNP_MAX_DEVICES; j++) {
75666 const char *id = (char *)card->devs[j].id;
75667 - int i2, j2;
75668 + unsigned int i2, j2;
75669 int dup = 0;
75670
75671 if (!id[0])
75672 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
75673 /* add an individual alias for every device entry */
75674 if (!dup) {
75675 char acpi_id[sizeof(card->devs[0].id)];
75676 - int k;
75677 + unsigned int k;
75678
75679 buf_printf(&mod->dev_table_buf,
75680 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
75681 @@ -807,7 +807,7 @@ static void dmi_ascii_filter(char *d, const char *s)
75682 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
75683 char *alias)
75684 {
75685 - int i, j;
75686 + unsigned int i, j;
75687
75688 sprintf(alias, "dmi*");
75689
75690 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
75691 index 2bd594e..d43245e 100644
75692 --- a/scripts/mod/modpost.c
75693 +++ b/scripts/mod/modpost.c
75694 @@ -919,6 +919,7 @@ enum mismatch {
75695 ANY_INIT_TO_ANY_EXIT,
75696 ANY_EXIT_TO_ANY_INIT,
75697 EXPORT_TO_INIT_EXIT,
75698 + DATA_TO_TEXT
75699 };
75700
75701 struct sectioncheck {
75702 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
75703 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
75704 .mismatch = EXPORT_TO_INIT_EXIT,
75705 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
75706 +},
75707 +/* Do not reference code from writable data */
75708 +{
75709 + .fromsec = { DATA_SECTIONS, NULL },
75710 + .tosec = { TEXT_SECTIONS, NULL },
75711 + .mismatch = DATA_TO_TEXT
75712 }
75713 };
75714
75715 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
75716 continue;
75717 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
75718 continue;
75719 - if (sym->st_value == addr)
75720 - return sym;
75721 /* Find a symbol nearby - addr are maybe negative */
75722 d = sym->st_value - addr;
75723 + if (d == 0)
75724 + return sym;
75725 if (d < 0)
75726 d = addr - sym->st_value;
75727 if (d < distance) {
75728 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
75729 tosym, prl_to, prl_to, tosym);
75730 free(prl_to);
75731 break;
75732 + case DATA_TO_TEXT:
75733 +/*
75734 + fprintf(stderr,
75735 + "The variable %s references\n"
75736 + "the %s %s%s%s\n",
75737 + fromsym, to, sec2annotation(tosec), tosym, to_p);
75738 +*/
75739 + break;
75740 }
75741 fprintf(stderr, "\n");
75742 }
75743 @@ -1656,7 +1671,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
75744 static void check_sec_ref(struct module *mod, const char *modname,
75745 struct elf_info *elf)
75746 {
75747 - int i;
75748 + unsigned int i;
75749 Elf_Shdr *sechdrs = elf->sechdrs;
75750
75751 /* Walk through all sections */
75752 @@ -1754,7 +1769,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
75753 va_end(ap);
75754 }
75755
75756 -void buf_write(struct buffer *buf, const char *s, int len)
75757 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
75758 {
75759 if (buf->size - buf->pos < len) {
75760 buf->size += len + SZ;
75761 @@ -1972,7 +1987,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
75762 if (fstat(fileno(file), &st) < 0)
75763 goto close_write;
75764
75765 - if (st.st_size != b->pos)
75766 + if (st.st_size != (off_t)b->pos)
75767 goto close_write;
75768
75769 tmp = NOFAIL(malloc(b->pos));
75770 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
75771 index 2031119..b5433af 100644
75772 --- a/scripts/mod/modpost.h
75773 +++ b/scripts/mod/modpost.h
75774 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
75775
75776 struct buffer {
75777 char *p;
75778 - int pos;
75779 - int size;
75780 + unsigned int pos;
75781 + unsigned int size;
75782 };
75783
75784 void __attribute__((format(printf, 2, 3)))
75785 buf_printf(struct buffer *buf, const char *fmt, ...);
75786
75787 void
75788 -buf_write(struct buffer *buf, const char *s, int len);
75789 +buf_write(struct buffer *buf, const char *s, unsigned int len);
75790
75791 struct module {
75792 struct module *next;
75793 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
75794 index 9dfcd6d..099068e 100644
75795 --- a/scripts/mod/sumversion.c
75796 +++ b/scripts/mod/sumversion.c
75797 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
75798 goto out;
75799 }
75800
75801 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
75802 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
75803 warn("writing sum in %s failed: %s\n",
75804 filename, strerror(errno));
75805 goto out;
75806 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
75807 index 5c11312..72742b5 100644
75808 --- a/scripts/pnmtologo.c
75809 +++ b/scripts/pnmtologo.c
75810 @@ -237,14 +237,14 @@ static void write_header(void)
75811 fprintf(out, " * Linux logo %s\n", logoname);
75812 fputs(" */\n\n", out);
75813 fputs("#include <linux/linux_logo.h>\n\n", out);
75814 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
75815 + fprintf(out, "static unsigned char %s_data[] = {\n",
75816 logoname);
75817 }
75818
75819 static void write_footer(void)
75820 {
75821 fputs("\n};\n\n", out);
75822 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
75823 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
75824 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
75825 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
75826 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
75827 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
75828 fputs("\n};\n\n", out);
75829
75830 /* write logo clut */
75831 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
75832 + fprintf(out, "static unsigned char %s_clut[] = {\n",
75833 logoname);
75834 write_hex_cnt = 0;
75835 for (i = 0; i < logo_clutsize; i++) {
75836 diff --git a/security/Kconfig b/security/Kconfig
75837 index 51bd5a0..8465ae6 100644
75838 --- a/security/Kconfig
75839 +++ b/security/Kconfig
75840 @@ -4,6 +4,626 @@
75841
75842 menu "Security options"
75843
75844 +source grsecurity/Kconfig
75845 +
75846 +menu "PaX"
75847 +
75848 + config ARCH_TRACK_EXEC_LIMIT
75849 + bool
75850 +
75851 + config PAX_KERNEXEC_PLUGIN
75852 + bool
75853 +
75854 + config PAX_PER_CPU_PGD
75855 + bool
75856 +
75857 + config TASK_SIZE_MAX_SHIFT
75858 + int
75859 + depends on X86_64
75860 + default 47 if !PAX_PER_CPU_PGD
75861 + default 42 if PAX_PER_CPU_PGD
75862 +
75863 + config PAX_ENABLE_PAE
75864 + bool
75865 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
75866 +
75867 +config PAX
75868 + bool "Enable various PaX features"
75869 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
75870 + help
75871 + This allows you to enable various PaX features. PaX adds
75872 + intrusion prevention mechanisms to the kernel that reduce
75873 + the risks posed by exploitable memory corruption bugs.
75874 +
75875 +menu "PaX Control"
75876 + depends on PAX
75877 +
75878 +config PAX_SOFTMODE
75879 + bool 'Support soft mode'
75880 + help
75881 + Enabling this option will allow you to run PaX in soft mode, that
75882 + is, PaX features will not be enforced by default, only on executables
75883 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
75884 + support as they are the only way to mark executables for soft mode use.
75885 +
75886 + Soft mode can be activated by using the "pax_softmode=1" kernel command
75887 + line option on boot. Furthermore you can control various PaX features
75888 + at runtime via the entries in /proc/sys/kernel/pax.
75889 +
75890 +config PAX_EI_PAX
75891 + bool 'Use legacy ELF header marking'
75892 + help
75893 + Enabling this option will allow you to control PaX features on
75894 + a per executable basis via the 'chpax' utility available at
75895 + http://pax.grsecurity.net/. The control flags will be read from
75896 + an otherwise reserved part of the ELF header. This marking has
75897 + numerous drawbacks (no support for soft-mode, toolchain does not
75898 + know about the non-standard use of the ELF header) therefore it
75899 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
75900 + support.
75901 +
75902 + If you have applications not marked by the PT_PAX_FLAGS ELF program
75903 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
75904 + option otherwise they will not get any protection.
75905 +
75906 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
75907 + support as well, they will override the legacy EI_PAX marks.
75908 +
75909 +config PAX_PT_PAX_FLAGS
75910 + bool 'Use ELF program header marking'
75911 + help
75912 + Enabling this option will allow you to control PaX features on
75913 + a per executable basis via the 'paxctl' utility available at
75914 + http://pax.grsecurity.net/. The control flags will be read from
75915 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
75916 + has the benefits of supporting both soft mode and being fully
75917 + integrated into the toolchain (the binutils patch is available
75918 + from http://pax.grsecurity.net).
75919 +
75920 + If you have applications not marked by the PT_PAX_FLAGS ELF program
75921 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
75922 + support otherwise they will not get any protection.
75923 +
75924 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
75925 + must make sure that the marks are the same if a binary has both marks.
75926 +
75927 + Note that if you enable the legacy EI_PAX marking support as well,
75928 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
75929 +
75930 +config PAX_XATTR_PAX_FLAGS
75931 + bool 'Use filesystem extended attributes marking'
75932 + depends on EXPERT
75933 + select CIFS_XATTR if CIFS
75934 + select EXT2_FS_XATTR if EXT2_FS
75935 + select EXT3_FS_XATTR if EXT3_FS
75936 + select EXT4_FS_XATTR if EXT4_FS
75937 + select JFFS2_FS_XATTR if JFFS2_FS
75938 + select REISERFS_FS_XATTR if REISERFS_FS
75939 + select SQUASHFS_XATTR if SQUASHFS
75940 + select TMPFS_XATTR if TMPFS
75941 + select UBIFS_FS_XATTR if UBIFS_FS
75942 + help
75943 + Enabling this option will allow you to control PaX features on
75944 + a per executable basis via the 'setfattr' utility. The control
75945 + flags will be read from the user.pax.flags extended attribute of
75946 + the file. This marking has the benefit of supporting binary-only
75947 + applications that self-check themselves (e.g., skype) and would
75948 + not tolerate chpax/paxctl changes. The main drawback is that
75949 + extended attributes are not supported by some filesystems (e.g.,
75950 + isofs, udf, vfat) so copying files through such filesystems will
75951 + lose the extended attributes and these PaX markings.
75952 +
75953 + If you have applications not marked by the PT_PAX_FLAGS ELF program
75954 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
75955 + support otherwise they will not get any protection.
75956 +
75957 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
75958 + must make sure that the marks are the same if a binary has both marks.
75959 +
75960 + Note that if you enable the legacy EI_PAX marking support as well,
75961 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
75962 +
75963 +choice
75964 + prompt 'MAC system integration'
75965 + default PAX_HAVE_ACL_FLAGS
75966 + help
75967 + Mandatory Access Control systems have the option of controlling
75968 + PaX flags on a per executable basis, choose the method supported
75969 + by your particular system.
75970 +
75971 + - "none": if your MAC system does not interact with PaX,
75972 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
75973 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
75974 +
75975 + NOTE: this option is for developers/integrators only.
75976 +
75977 + config PAX_NO_ACL_FLAGS
75978 + bool 'none'
75979 +
75980 + config PAX_HAVE_ACL_FLAGS
75981 + bool 'direct'
75982 +
75983 + config PAX_HOOK_ACL_FLAGS
75984 + bool 'hook'
75985 +endchoice
75986 +
75987 +endmenu
75988 +
75989 +menu "Non-executable pages"
75990 + depends on PAX
75991 +
75992 +config PAX_NOEXEC
75993 + bool "Enforce non-executable pages"
75994 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
75995 + help
75996 + By design some architectures do not allow for protecting memory
75997 + pages against execution or even if they do, Linux does not make
75998 + use of this feature. In practice this means that if a page is
75999 + readable (such as the stack or heap) it is also executable.
76000 +
76001 + There is a well known exploit technique that makes use of this
76002 + fact and a common programming mistake where an attacker can
76003 + introduce code of his choice somewhere in the attacked program's
76004 + memory (typically the stack or the heap) and then execute it.
76005 +
76006 + If the attacked program was running with different (typically
76007 + higher) privileges than that of the attacker, then he can elevate
76008 + his own privilege level (e.g. get a root shell, write to files for
76009 + which he does not have write access to, etc).
76010 +
76011 + Enabling this option will let you choose from various features
76012 + that prevent the injection and execution of 'foreign' code in
76013 + a program.
76014 +
76015 + This will also break programs that rely on the old behaviour and
76016 + expect that dynamically allocated memory via the malloc() family
76017 + of functions is executable (which it is not). Notable examples
76018 + are the XFree86 4.x server, the java runtime and wine.
76019 +
76020 +config PAX_PAGEEXEC
76021 + bool "Paging based non-executable pages"
76022 + depends on PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MATOM || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
76023 + select S390_SWITCH_AMODE if S390
76024 + select S390_EXEC_PROTECT if S390
76025 + select ARCH_TRACK_EXEC_LIMIT if X86_32
76026 + help
76027 + This implementation is based on the paging feature of the CPU.
76028 + On i386 without hardware non-executable bit support there is a
76029 + variable but usually low performance impact, however on Intel's
76030 + P4 core based CPUs it is very high so you should not enable this
76031 + for kernels meant to be used on such CPUs.
76032 +
76033 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
76034 + with hardware non-executable bit support there is no performance
76035 + impact, on ppc the impact is negligible.
76036 +
76037 + Note that several architectures require various emulations due to
76038 + badly designed userland ABIs, this will cause a performance impact
76039 + but will disappear as soon as userland is fixed. For example, ppc
76040 + userland MUST have been built with secure-plt by a recent toolchain.
76041 +
76042 +config PAX_SEGMEXEC
76043 + bool "Segmentation based non-executable pages"
76044 + depends on PAX_NOEXEC && X86_32
76045 + help
76046 + This implementation is based on the segmentation feature of the
76047 + CPU and has a very small performance impact, however applications
76048 + will be limited to a 1.5 GB address space instead of the normal
76049 + 3 GB.
76050 +
76051 +config PAX_EMUTRAMP
76052 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
76053 + default y if PARISC
76054 + help
76055 + There are some programs and libraries that for one reason or
76056 + another attempt to execute special small code snippets from
76057 + non-executable memory pages. Most notable examples are the
76058 + signal handler return code generated by the kernel itself and
76059 + the GCC trampolines.
76060 +
76061 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
76062 + such programs will no longer work under your kernel.
76063 +
76064 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
76065 + utilities to enable trampoline emulation for the affected programs
76066 + yet still have the protection provided by the non-executable pages.
76067 +
76068 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
76069 + your system will not even boot.
76070 +
76071 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
76072 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
76073 + for the affected files.
76074 +
76075 + NOTE: enabling this feature *may* open up a loophole in the
76076 + protection provided by non-executable pages that an attacker
76077 + could abuse. Therefore the best solution is to not have any
76078 + files on your system that would require this option. This can
76079 + be achieved by not using libc5 (which relies on the kernel
76080 + signal handler return code) and not using or rewriting programs
76081 + that make use of the nested function implementation of GCC.
76082 + Skilled users can just fix GCC itself so that it implements
76083 + nested function calls in a way that does not interfere with PaX.
76084 +
76085 +config PAX_EMUSIGRT
76086 + bool "Automatically emulate sigreturn trampolines"
76087 + depends on PAX_EMUTRAMP && PARISC
76088 + default y
76089 + help
76090 + Enabling this option will have the kernel automatically detect
76091 + and emulate signal return trampolines executing on the stack
76092 + that would otherwise lead to task termination.
76093 +
76094 + This solution is intended as a temporary one for users with
76095 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
76096 + Modula-3 runtime, etc) or executables linked to such, basically
76097 + everything that does not specify its own SA_RESTORER function in
76098 + normal executable memory like glibc 2.1+ does.
76099 +
76100 + On parisc you MUST enable this option, otherwise your system will
76101 + not even boot.
76102 +
76103 + NOTE: this feature cannot be disabled on a per executable basis
76104 + and since it *does* open up a loophole in the protection provided
76105 + by non-executable pages, the best solution is to not have any
76106 + files on your system that would require this option.
76107 +
76108 +config PAX_MPROTECT
76109 + bool "Restrict mprotect()"
76110 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
76111 + help
76112 + Enabling this option will prevent programs from
76113 + - changing the executable status of memory pages that were
76114 + not originally created as executable,
76115 + - making read-only executable pages writable again,
76116 + - creating executable pages from anonymous memory,
76117 + - making read-only-after-relocations (RELRO) data pages writable again.
76118 +
76119 + You should say Y here to complete the protection provided by
76120 + the enforcement of non-executable pages.
76121 +
76122 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
76123 + this feature on a per file basis.
76124 +
76125 +config PAX_MPROTECT_COMPAT
76126 + bool "Use legacy/compat protection demoting (read help)"
76127 + depends on PAX_MPROTECT
76128 + default n
76129 + help
76130 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
76131 + by sending the proper error code to the application. For some broken
76132 + userland, this can cause problems with Python or other applications. The
76133 + current implementation however allows for applications like clamav to
76134 + detect if JIT compilation/execution is allowed and to fall back gracefully
76135 + to an interpreter-based mode if it does not. While we encourage everyone
76136 + to use the current implementation as-is and push upstream to fix broken
76137 + userland (note that the RWX logging option can assist with this), in some
76138 + environments this may not be possible. Having to disable MPROTECT
76139 + completely on certain binaries reduces the security benefit of PaX,
76140 + so this option is provided for those environments to revert to the old
76141 + behavior.
76142 +
76143 +config PAX_ELFRELOCS
76144 + bool "Allow ELF text relocations (read help)"
76145 + depends on PAX_MPROTECT
76146 + default n
76147 + help
76148 + Non-executable pages and mprotect() restrictions are effective
76149 + in preventing the introduction of new executable code into an
76150 + attacked task's address space. There remain only two venues
76151 + for this kind of attack: if the attacker can execute already
76152 + existing code in the attacked task then he can either have it
76153 + create and mmap() a file containing his code or have it mmap()
76154 + an already existing ELF library that does not have position
76155 + independent code in it and use mprotect() on it to make it
76156 + writable and copy his code there. While protecting against
76157 + the former approach is beyond PaX, the latter can be prevented
76158 + by having only PIC ELF libraries on one's system (which do not
76159 + need to relocate their code). If you are sure this is your case,
76160 + as is the case with all modern Linux distributions, then leave
76161 + this option disabled. You should say 'n' here.
76162 +
76163 +config PAX_ETEXECRELOCS
76164 + bool "Allow ELF ET_EXEC text relocations"
76165 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
76166 + select PAX_ELFRELOCS
76167 + default y
76168 + help
76169 + On some architectures there are incorrectly created applications
76170 + that require text relocations and would not work without enabling
76171 + this option. If you are an alpha, ia64 or parisc user, you should
76172 + enable this option and disable it once you have made sure that
76173 + none of your applications need it.
76174 +
76175 +config PAX_EMUPLT
76176 + bool "Automatically emulate ELF PLT"
76177 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
76178 + default y
76179 + help
76180 + Enabling this option will have the kernel automatically detect
76181 + and emulate the Procedure Linkage Table entries in ELF files.
76182 + On some architectures such entries are in writable memory, and
76183 + become non-executable leading to task termination. Therefore
76184 + it is mandatory that you enable this option on alpha, parisc,
76185 + sparc and sparc64, otherwise your system would not even boot.
76186 +
76187 + NOTE: this feature *does* open up a loophole in the protection
76188 + provided by the non-executable pages, therefore the proper
76189 + solution is to modify the toolchain to produce a PLT that does
76190 + not need to be writable.
76191 +
76192 +config PAX_DLRESOLVE
76193 + bool 'Emulate old glibc resolver stub'
76194 + depends on PAX_EMUPLT && SPARC
76195 + default n
76196 + help
76197 + This option is needed if userland has an old glibc (before 2.4)
76198 + that puts a 'save' instruction into the runtime generated resolver
76199 + stub that needs special emulation.
76200 +
76201 +config PAX_KERNEXEC
76202 + bool "Enforce non-executable kernel pages"
76203 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
76204 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
76205 + select PAX_KERNEXEC_PLUGIN if X86_64
76206 + help
76207 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
76208 + that is, enabling this option will make it harder to inject
76209 + and execute 'foreign' code in kernel memory itself.
76210 +
76211 + Note that on x86_64 kernels there is a known regression when
76212 + this feature and KVM/VMX are both enabled in the host kernel.
76213 +
76214 +choice
76215 + prompt "Return Address Instrumentation Method"
76216 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
76217 + depends on PAX_KERNEXEC_PLUGIN
76218 + help
76219 + Select the method used to instrument function pointer dereferences.
76220 + Note that binary modules cannot be instrumented by this approach.
76221 +
76222 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
76223 + bool "bts"
76224 + help
76225 + This method is compatible with binary only modules but has
76226 + a higher runtime overhead.
76227 +
76228 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
76229 + bool "or"
76230 + depends on !PARAVIRT
76231 + help
76232 + This method is incompatible with binary only modules but has
76233 + a lower runtime overhead.
76234 +endchoice
76235 +
76236 +config PAX_KERNEXEC_PLUGIN_METHOD
76237 + string
76238 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
76239 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
76240 + default ""
76241 +
76242 +config PAX_KERNEXEC_MODULE_TEXT
76243 + int "Minimum amount of memory reserved for module code"
76244 + default "4"
76245 + depends on PAX_KERNEXEC && X86_32 && MODULES
76246 + help
76247 + Due to implementation details the kernel must reserve a fixed
76248 + amount of memory for module code at compile time that cannot be
76249 + changed at runtime. Here you can specify the minimum amount
76250 + in MB that will be reserved. Due to the same implementation
76251 + details this size will always be rounded up to the next 2/4 MB
76252 + boundary (depends on PAE) so the actually available memory for
76253 + module code will usually be more than this minimum.
76254 +
76255 + The default 4 MB should be enough for most users but if you have
76256 + an excessive number of modules (e.g., most distribution configs
76257 + compile many drivers as modules) or use huge modules such as
76258 + nvidia's kernel driver, you will need to adjust this amount.
76259 + A good rule of thumb is to look at your currently loaded kernel
76260 + modules and add up their sizes.
76261 +
76262 +endmenu
76263 +
76264 +menu "Address Space Layout Randomization"
76265 + depends on PAX
76266 +
76267 +config PAX_ASLR
76268 + bool "Address Space Layout Randomization"
76269 + help
76270 + Many if not most exploit techniques rely on the knowledge of
76271 + certain addresses in the attacked program. The following options
76272 + will allow the kernel to apply a certain amount of randomization
76273 + to specific parts of the program thereby forcing an attacker to
76274 + guess them in most cases. Any failed guess will most likely crash
76275 + the attacked program which allows the kernel to detect such attempts
76276 + and react on them. PaX itself provides no reaction mechanisms,
76277 + instead it is strongly encouraged that you make use of Nergal's
76278 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
76279 + (http://www.grsecurity.net/) built-in crash detection features or
76280 + develop one yourself.
76281 +
76282 + By saying Y here you can choose to randomize the following areas:
76283 + - top of the task's kernel stack
76284 + - top of the task's userland stack
76285 + - base address for mmap() requests that do not specify one
76286 + (this includes all libraries)
76287 + - base address of the main executable
76288 +
76289 + It is strongly recommended to say Y here as address space layout
76290 + randomization has negligible impact on performance yet it provides
76291 + a very effective protection.
76292 +
76293 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
76294 + this feature on a per file basis.
76295 +
76296 +config PAX_RANDKSTACK
76297 + bool "Randomize kernel stack base"
76298 + depends on X86_TSC && X86
76299 + help
76300 + By saying Y here the kernel will randomize every task's kernel
76301 + stack on every system call. This will not only force an attacker
76302 + to guess it but also prevent him from making use of possible
76303 + leaked information about it.
76304 +
76305 + Since the kernel stack is a rather scarce resource, randomization
76306 + may cause unexpected stack overflows, therefore you should very
76307 + carefully test your system. Note that once enabled in the kernel
76308 + configuration, this feature cannot be disabled on a per file basis.
76309 +
76310 +config PAX_RANDUSTACK
76311 + bool "Randomize user stack base"
76312 + depends on PAX_ASLR
76313 + help
76314 + By saying Y here the kernel will randomize every task's userland
76315 + stack. The randomization is done in two steps where the second
76316 + one may apply a big amount of shift to the top of the stack and
76317 + cause problems for programs that want to use lots of memory (more
76318 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
76319 + For this reason the second step can be controlled by 'chpax' or
76320 + 'paxctl' on a per file basis.
76321 +
76322 +config PAX_RANDMMAP
76323 + bool "Randomize mmap() base"
76324 + depends on PAX_ASLR
76325 + help
76326 + By saying Y here the kernel will use a randomized base address for
76327 + mmap() requests that do not specify one themselves. As a result
76328 + all dynamically loaded libraries will appear at random addresses
76329 + and therefore be harder to exploit by a technique where an attacker
76330 + attempts to execute library code for his purposes (e.g. spawn a
76331 + shell from an exploited program that is running at an elevated
76332 + privilege level).
76333 +
76334 + Furthermore, if a program is relinked as a dynamic ELF file, its
76335 + base address will be randomized as well, completing the full
76336 + randomization of the address space layout. Attacking such programs
76337 + becomes a guess game. You can find an example of doing this at
76338 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
76339 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
76340 +
76341 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
76342 + feature on a per file basis.
76343 +
76344 +endmenu
76345 +
76346 +menu "Miscellaneous hardening features"
76347 +
76348 +config PAX_MEMORY_SANITIZE
76349 + bool "Sanitize all freed memory"
76350 + help
76351 + By saying Y here the kernel will erase memory pages as soon as they
76352 + are freed. This in turn reduces the lifetime of data stored in the
76353 + pages, making it less likely that sensitive information such as
76354 + passwords, cryptographic secrets, etc stay in memory for too long.
76355 +
76356 + This is especially useful for programs whose runtime is short, long
76357 + lived processes and the kernel itself benefit from this as long as
76358 + they operate on whole memory pages and ensure timely freeing of pages
76359 + that may hold sensitive information.
76360 +
76361 + The tradeoff is performance impact, on a single CPU system kernel
76362 + compilation sees a 3% slowdown, other systems and workloads may vary
76363 + and you are advised to test this feature on your expected workload
76364 + before deploying it.
76365 +
76366 + Note that this feature does not protect data stored in live pages,
76367 + e.g., process memory swapped to disk may stay there for a long time.
76368 +
76369 +config PAX_MEMORY_STACKLEAK
76370 + bool "Sanitize kernel stack"
76371 + depends on X86
76372 + help
76373 + By saying Y here the kernel will erase the kernel stack before it
76374 + returns from a system call. This in turn reduces the information
76375 + that a kernel stack leak bug can reveal.
76376 +
76377 + Note that such a bug can still leak information that was put on
76378 + the stack by the current system call (the one eventually triggering
76379 + the bug) but traces of earlier system calls on the kernel stack
76380 + cannot leak anymore.
76381 +
76382 + The tradeoff is performance impact: on a single CPU system kernel
76383 + compilation sees a 1% slowdown, other systems and workloads may vary
76384 + and you are advised to test this feature on your expected workload
76385 + before deploying it.
76386 +
76387 + Note: full support for this feature requires gcc with plugin support
76388 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
76389 + versions means that functions with large enough stack frames may
76390 + leave uninitialized memory behind that may be exposed to a later
76391 + syscall leaking the stack.
76392 +
76393 +config PAX_MEMORY_UDEREF
76394 + bool "Prevent invalid userland pointer dereference"
76395 + depends on X86 && !UML_X86 && !XEN
76396 + select PAX_PER_CPU_PGD if X86_64
76397 + help
76398 + By saying Y here the kernel will be prevented from dereferencing
76399 + userland pointers in contexts where the kernel expects only kernel
76400 + pointers. This is both a useful runtime debugging feature and a
76401 + security measure that prevents exploiting a class of kernel bugs.
76402 +
76403 + The tradeoff is that some virtualization solutions may experience
76404 + a huge slowdown and therefore you should not enable this feature
76405 + for kernels meant to run in such environments. Whether a given VM
76406 + solution is affected or not is best determined by simply trying it
76407 + out, the performance impact will be obvious right on boot as this
76408 + mechanism engages from very early on. A good rule of thumb is that
76409 + VMs running on CPUs without hardware virtualization support (i.e.,
76410 + the majority of IA-32 CPUs) will likely experience the slowdown.
76411 +
76412 +config PAX_REFCOUNT
76413 + bool "Prevent various kernel object reference counter overflows"
76414 + depends on GRKERNSEC && (X86 || SPARC64)
76415 + help
76416 + By saying Y here the kernel will detect and prevent overflowing
76417 + various (but not all) kinds of object reference counters. Such
76418 + overflows can normally occur due to bugs only and are often, if
76419 + not always, exploitable.
76420 +
76421 + The tradeoff is that data structures protected by an overflowed
76422 + refcount will never be freed and therefore will leak memory. Note
76423 + that this leak also happens even without this protection but in
76424 + that case the overflow can eventually trigger the freeing of the
76425 + data structure while it is still being used elsewhere, resulting
76426 + in the exploitable situation that this feature prevents.
76427 +
76428 + Since this has a negligible performance impact, you should enable
76429 + this feature.
76430 +
76431 +config PAX_USERCOPY
76432 + bool "Harden heap object copies between kernel and userland"
76433 + depends on X86 || PPC || SPARC || ARM
76434 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
76435 + help
76436 + By saying Y here the kernel will enforce the size of heap objects
76437 + when they are copied in either direction between the kernel and
76438 + userland, even if only a part of the heap object is copied.
76439 +
76440 + Specifically, this checking prevents information leaking from the
76441 + kernel heap during kernel to userland copies (if the kernel heap
76442 + object is otherwise fully initialized) and prevents kernel heap
76443 + overflows during userland to kernel copies.
76444 +
76445 + Note that the current implementation provides the strictest bounds
76446 + checks for the SLUB allocator.
76447 +
76448 + Enabling this option also enables per-slab cache protection against
76449 + data in a given cache being copied into/out of via userland
76450 + accessors. Though the whitelist of regions will be reduced over
76451 + time, it notably protects important data structures like task structs.
76452 +
76453 + If frame pointers are enabled on x86, this option will also restrict
76454 + copies into and out of the kernel stack to local variables within a
76455 + single frame.
76456 +
76457 + Since this has a negligible performance impact, you should enable
76458 + this feature.
76459 +
76460 +endmenu
76461 +
76462 +endmenu
76463 +
76464 config KEYS
76465 bool "Enable access key retention support"
76466 help
76467 @@ -169,7 +789,7 @@ config INTEL_TXT
76468 config LSM_MMAP_MIN_ADDR
76469 int "Low address space for LSM to protect from user allocation"
76470 depends on SECURITY && SECURITY_SELINUX
76471 - default 32768 if ARM
76472 + default 32768 if ALPHA || ARM || PARISC || SPARC32
76473 default 65536
76474 help
76475 This is the portion of low virtual memory which should be protected
76476 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
76477 index 3783202..1852837 100644
76478 --- a/security/apparmor/lsm.c
76479 +++ b/security/apparmor/lsm.c
76480 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
76481 return error;
76482 }
76483
76484 -static struct security_operations apparmor_ops = {
76485 +static struct security_operations apparmor_ops __read_only = {
76486 .name = "apparmor",
76487
76488 .ptrace_access_check = apparmor_ptrace_access_check,
76489 diff --git a/security/commoncap.c b/security/commoncap.c
76490 index ee4f848..a320c64 100644
76491 --- a/security/commoncap.c
76492 +++ b/security/commoncap.c
76493 @@ -28,6 +28,7 @@
76494 #include <linux/prctl.h>
76495 #include <linux/securebits.h>
76496 #include <linux/user_namespace.h>
76497 +#include <net/sock.h>
76498
76499 /*
76500 * If a non-root user executes a setuid-root binary in
76501 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
76502
76503 int cap_netlink_recv(struct sk_buff *skb, int cap)
76504 {
76505 - if (!cap_raised(current_cap(), cap))
76506 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
76507 return -EPERM;
76508 return 0;
76509 }
76510 @@ -579,6 +580,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
76511 {
76512 const struct cred *cred = current_cred();
76513
76514 + if (gr_acl_enable_at_secure())
76515 + return 1;
76516 +
76517 if (cred->uid != 0) {
76518 if (bprm->cap_effective)
76519 return 1;
76520 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
76521 index 3ccf7ac..d73ad64 100644
76522 --- a/security/integrity/ima/ima.h
76523 +++ b/security/integrity/ima/ima.h
76524 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
76525 extern spinlock_t ima_queue_lock;
76526
76527 struct ima_h_table {
76528 - atomic_long_t len; /* number of stored measurements in the list */
76529 - atomic_long_t violations;
76530 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
76531 + atomic_long_unchecked_t violations;
76532 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
76533 };
76534 extern struct ima_h_table ima_htable;
76535 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
76536 index 0d50df0..e94dd2a 100644
76537 --- a/security/integrity/ima/ima_api.c
76538 +++ b/security/integrity/ima/ima_api.c
76539 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
76540 int result;
76541
76542 /* can overflow, only indicator */
76543 - atomic_long_inc(&ima_htable.violations);
76544 + atomic_long_inc_unchecked(&ima_htable.violations);
76545
76546 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
76547 if (!entry) {
76548 diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c
76549 index c5c5a72..2ad942f 100644
76550 --- a/security/integrity/ima/ima_audit.c
76551 +++ b/security/integrity/ima/ima_audit.c
76552 @@ -56,9 +56,11 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
76553 audit_log_format(ab, " name=");
76554 audit_log_untrustedstring(ab, fname);
76555 }
76556 - if (inode)
76557 - audit_log_format(ab, " dev=%s ino=%lu",
76558 - inode->i_sb->s_id, inode->i_ino);
76559 + if (inode) {
76560 + audit_log_format(ab, " dev=");
76561 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
76562 + audit_log_format(ab, " ino=%lu", inode->i_ino);
76563 + }
76564 audit_log_format(ab, " res=%d", !result ? 0 : 1);
76565 audit_log_end(ab);
76566 }
76567 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
76568 index e1aa2b4..52027bf 100644
76569 --- a/security/integrity/ima/ima_fs.c
76570 +++ b/security/integrity/ima/ima_fs.c
76571 @@ -28,12 +28,12 @@
76572 static int valid_policy = 1;
76573 #define TMPBUFLEN 12
76574 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
76575 - loff_t *ppos, atomic_long_t *val)
76576 + loff_t *ppos, atomic_long_unchecked_t *val)
76577 {
76578 char tmpbuf[TMPBUFLEN];
76579 ssize_t len;
76580
76581 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
76582 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
76583 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
76584 }
76585
76586 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
76587 index 8e28f04..d5951b1 100644
76588 --- a/security/integrity/ima/ima_queue.c
76589 +++ b/security/integrity/ima/ima_queue.c
76590 @@ -79,7 +79,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
76591 INIT_LIST_HEAD(&qe->later);
76592 list_add_tail_rcu(&qe->later, &ima_measurements);
76593
76594 - atomic_long_inc(&ima_htable.len);
76595 + atomic_long_inc_unchecked(&ima_htable.len);
76596 key = ima_hash_key(entry->digest);
76597 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
76598 return 0;
76599 diff --git a/security/keys/compat.c b/security/keys/compat.c
76600 index 4c48e13..7abdac9 100644
76601 --- a/security/keys/compat.c
76602 +++ b/security/keys/compat.c
76603 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
76604 if (ret == 0)
76605 goto no_payload_free;
76606
76607 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
76608 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
76609
76610 if (iov != iovstack)
76611 kfree(iov);
76612 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
76613 index 0b3f5d7..892c8a6 100644
76614 --- a/security/keys/keyctl.c
76615 +++ b/security/keys/keyctl.c
76616 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
76617 /*
76618 * Copy the iovec data from userspace
76619 */
76620 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
76621 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
76622 unsigned ioc)
76623 {
76624 for (; ioc > 0; ioc--) {
76625 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
76626 * If successful, 0 will be returned.
76627 */
76628 long keyctl_instantiate_key_common(key_serial_t id,
76629 - const struct iovec *payload_iov,
76630 + const struct iovec __user *payload_iov,
76631 unsigned ioc,
76632 size_t plen,
76633 key_serial_t ringid)
76634 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
76635 [0].iov_len = plen
76636 };
76637
76638 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
76639 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
76640 }
76641
76642 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
76643 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
76644 if (ret == 0)
76645 goto no_payload_free;
76646
76647 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
76648 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
76649
76650 if (iov != iovstack)
76651 kfree(iov);
76652 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
76653 index 37a7f3b..86dc19f 100644
76654 --- a/security/keys/keyring.c
76655 +++ b/security/keys/keyring.c
76656 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
76657 ret = -EFAULT;
76658
76659 for (loop = 0; loop < klist->nkeys; loop++) {
76660 + key_serial_t serial;
76661 key = klist->keys[loop];
76662 + serial = key->serial;
76663
76664 tmp = sizeof(key_serial_t);
76665 if (tmp > buflen)
76666 tmp = buflen;
76667
76668 - if (copy_to_user(buffer,
76669 - &key->serial,
76670 - tmp) != 0)
76671 + if (copy_to_user(buffer, &serial, tmp))
76672 goto error;
76673
76674 buflen -= tmp;
76675 diff --git a/security/lsm_audit.c b/security/lsm_audit.c
76676 index 893af8a..ba9237c 100644
76677 --- a/security/lsm_audit.c
76678 +++ b/security/lsm_audit.c
76679 @@ -234,10 +234,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
76680 audit_log_d_path(ab, "path=", &a->u.path);
76681
76682 inode = a->u.path.dentry->d_inode;
76683 - if (inode)
76684 - audit_log_format(ab, " dev=%s ino=%lu",
76685 - inode->i_sb->s_id,
76686 - inode->i_ino);
76687 + if (inode) {
76688 + audit_log_format(ab, " dev=");
76689 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
76690 + audit_log_format(ab, " ino=%lu", inode->i_ino);
76691 + }
76692 break;
76693 }
76694 case LSM_AUDIT_DATA_DENTRY: {
76695 @@ -247,10 +248,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
76696 audit_log_untrustedstring(ab, a->u.dentry->d_name.name);
76697
76698 inode = a->u.dentry->d_inode;
76699 - if (inode)
76700 - audit_log_format(ab, " dev=%s ino=%lu",
76701 - inode->i_sb->s_id,
76702 - inode->i_ino);
76703 + if (inode) {
76704 + audit_log_format(ab, " dev=");
76705 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
76706 + audit_log_format(ab, " ino=%lu", inode->i_ino);
76707 + }
76708 break;
76709 }
76710 case LSM_AUDIT_DATA_INODE: {
76711 @@ -265,8 +267,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
76712 dentry->d_name.name);
76713 dput(dentry);
76714 }
76715 - audit_log_format(ab, " dev=%s ino=%lu", inode->i_sb->s_id,
76716 - inode->i_ino);
76717 + audit_log_format(ab, " dev=");
76718 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
76719 + audit_log_format(ab, " ino=%lu", inode->i_ino);
76720 break;
76721 }
76722 case LSM_AUDIT_DATA_TASK:
76723 diff --git a/security/min_addr.c b/security/min_addr.c
76724 index f728728..6457a0c 100644
76725 --- a/security/min_addr.c
76726 +++ b/security/min_addr.c
76727 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
76728 */
76729 static void update_mmap_min_addr(void)
76730 {
76731 +#ifndef SPARC
76732 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
76733 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
76734 mmap_min_addr = dac_mmap_min_addr;
76735 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
76736 #else
76737 mmap_min_addr = dac_mmap_min_addr;
76738 #endif
76739 +#endif
76740 }
76741
76742 /*
76743 diff --git a/security/security.c b/security/security.c
76744 index e2f684a..8d62ef5 100644
76745 --- a/security/security.c
76746 +++ b/security/security.c
76747 @@ -26,8 +26,8 @@
76748 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
76749 CONFIG_DEFAULT_SECURITY;
76750
76751 -static struct security_operations *security_ops;
76752 -static struct security_operations default_security_ops = {
76753 +static struct security_operations *security_ops __read_only;
76754 +static struct security_operations default_security_ops __read_only = {
76755 .name = "default",
76756 };
76757
76758 @@ -68,7 +68,9 @@ int __init security_init(void)
76759
76760 void reset_security_ops(void)
76761 {
76762 + pax_open_kernel();
76763 security_ops = &default_security_ops;
76764 + pax_close_kernel();
76765 }
76766
76767 /* Save user chosen LSM */
76768 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
76769 index 1126c10..effb32b 100644
76770 --- a/security/selinux/hooks.c
76771 +++ b/security/selinux/hooks.c
76772 @@ -94,8 +94,6 @@
76773
76774 #define NUM_SEL_MNT_OPTS 5
76775
76776 -extern struct security_operations *security_ops;
76777 -
76778 /* SECMARK reference count */
76779 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
76780
76781 @@ -5449,7 +5447,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
76782
76783 #endif
76784
76785 -static struct security_operations selinux_ops = {
76786 +static struct security_operations selinux_ops __read_only = {
76787 .name = "selinux",
76788
76789 .ptrace_access_check = selinux_ptrace_access_check,
76790 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
76791 index b43813c..74be837 100644
76792 --- a/security/selinux/include/xfrm.h
76793 +++ b/security/selinux/include/xfrm.h
76794 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
76795
76796 static inline void selinux_xfrm_notify_policyload(void)
76797 {
76798 - atomic_inc(&flow_cache_genid);
76799 + atomic_inc_unchecked(&flow_cache_genid);
76800 }
76801 #else
76802 static inline int selinux_xfrm_enabled(void)
76803 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
76804 index 7db62b4..ee4d949 100644
76805 --- a/security/smack/smack_lsm.c
76806 +++ b/security/smack/smack_lsm.c
76807 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
76808 return 0;
76809 }
76810
76811 -struct security_operations smack_ops = {
76812 +struct security_operations smack_ops __read_only = {
76813 .name = "smack",
76814
76815 .ptrace_access_check = smack_ptrace_access_check,
76816 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
76817 index 4b327b6..646c57a 100644
76818 --- a/security/tomoyo/tomoyo.c
76819 +++ b/security/tomoyo/tomoyo.c
76820 @@ -504,7 +504,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
76821 * tomoyo_security_ops is a "struct security_operations" which is used for
76822 * registering TOMOYO.
76823 */
76824 -static struct security_operations tomoyo_security_ops = {
76825 +static struct security_operations tomoyo_security_ops __read_only = {
76826 .name = "tomoyo",
76827 .cred_alloc_blank = tomoyo_cred_alloc_blank,
76828 .cred_prepare = tomoyo_cred_prepare,
76829 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
76830 index 762af68..7103453 100644
76831 --- a/sound/aoa/codecs/onyx.c
76832 +++ b/sound/aoa/codecs/onyx.c
76833 @@ -54,7 +54,7 @@ struct onyx {
76834 spdif_locked:1,
76835 analog_locked:1,
76836 original_mute:2;
76837 - int open_count;
76838 + local_t open_count;
76839 struct codec_info *codec_info;
76840
76841 /* mutex serializes concurrent access to the device
76842 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
76843 struct onyx *onyx = cii->codec_data;
76844
76845 mutex_lock(&onyx->mutex);
76846 - onyx->open_count++;
76847 + local_inc(&onyx->open_count);
76848 mutex_unlock(&onyx->mutex);
76849
76850 return 0;
76851 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
76852 struct onyx *onyx = cii->codec_data;
76853
76854 mutex_lock(&onyx->mutex);
76855 - onyx->open_count--;
76856 - if (!onyx->open_count)
76857 + if (local_dec_and_test(&onyx->open_count))
76858 onyx->spdif_locked = onyx->analog_locked = 0;
76859 mutex_unlock(&onyx->mutex);
76860
76861 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
76862 index ffd2025..df062c9 100644
76863 --- a/sound/aoa/codecs/onyx.h
76864 +++ b/sound/aoa/codecs/onyx.h
76865 @@ -11,6 +11,7 @@
76866 #include <linux/i2c.h>
76867 #include <asm/pmac_low_i2c.h>
76868 #include <asm/prom.h>
76869 +#include <asm/local.h>
76870
76871 /* PCM3052 register definitions */
76872
76873 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
76874 index 3cc4b86..af0a951 100644
76875 --- a/sound/core/oss/pcm_oss.c
76876 +++ b/sound/core/oss/pcm_oss.c
76877 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
76878 if (in_kernel) {
76879 mm_segment_t fs;
76880 fs = snd_enter_user();
76881 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
76882 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
76883 snd_leave_user(fs);
76884 } else {
76885 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
76886 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
76887 }
76888 if (ret != -EPIPE && ret != -ESTRPIPE)
76889 break;
76890 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
76891 if (in_kernel) {
76892 mm_segment_t fs;
76893 fs = snd_enter_user();
76894 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
76895 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
76896 snd_leave_user(fs);
76897 } else {
76898 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
76899 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
76900 }
76901 if (ret == -EPIPE) {
76902 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
76903 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
76904 struct snd_pcm_plugin_channel *channels;
76905 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
76906 if (!in_kernel) {
76907 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
76908 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
76909 return -EFAULT;
76910 buf = runtime->oss.buffer;
76911 }
76912 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
76913 }
76914 } else {
76915 tmp = snd_pcm_oss_write2(substream,
76916 - (const char __force *)buf,
76917 + (const char __force_kernel *)buf,
76918 runtime->oss.period_bytes, 0);
76919 if (tmp <= 0)
76920 goto err;
76921 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
76922 struct snd_pcm_runtime *runtime = substream->runtime;
76923 snd_pcm_sframes_t frames, frames1;
76924 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
76925 - char __user *final_dst = (char __force __user *)buf;
76926 + char __user *final_dst = (char __force_user *)buf;
76927 if (runtime->oss.plugin_first) {
76928 struct snd_pcm_plugin_channel *channels;
76929 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
76930 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
76931 xfer += tmp;
76932 runtime->oss.buffer_used -= tmp;
76933 } else {
76934 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
76935 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
76936 runtime->oss.period_bytes, 0);
76937 if (tmp <= 0)
76938 goto err;
76939 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
76940 size1);
76941 size1 /= runtime->channels; /* frames */
76942 fs = snd_enter_user();
76943 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
76944 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
76945 snd_leave_user(fs);
76946 }
76947 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
76948 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
76949 index 91cdf94..4085161 100644
76950 --- a/sound/core/pcm_compat.c
76951 +++ b/sound/core/pcm_compat.c
76952 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
76953 int err;
76954
76955 fs = snd_enter_user();
76956 - err = snd_pcm_delay(substream, &delay);
76957 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
76958 snd_leave_user(fs);
76959 if (err < 0)
76960 return err;
76961 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
76962 index 25ed9fe..24c46e9 100644
76963 --- a/sound/core/pcm_native.c
76964 +++ b/sound/core/pcm_native.c
76965 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
76966 switch (substream->stream) {
76967 case SNDRV_PCM_STREAM_PLAYBACK:
76968 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
76969 - (void __user *)arg);
76970 + (void __force_user *)arg);
76971 break;
76972 case SNDRV_PCM_STREAM_CAPTURE:
76973 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
76974 - (void __user *)arg);
76975 + (void __force_user *)arg);
76976 break;
76977 default:
76978 result = -EINVAL;
76979 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
76980 index 5cf8d65..912a79c 100644
76981 --- a/sound/core/seq/seq_device.c
76982 +++ b/sound/core/seq/seq_device.c
76983 @@ -64,7 +64,7 @@ struct ops_list {
76984 int argsize; /* argument size */
76985
76986 /* operators */
76987 - struct snd_seq_dev_ops ops;
76988 + struct snd_seq_dev_ops *ops;
76989
76990 /* registred devices */
76991 struct list_head dev_list; /* list of devices */
76992 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
76993
76994 mutex_lock(&ops->reg_mutex);
76995 /* copy driver operators */
76996 - ops->ops = *entry;
76997 + ops->ops = entry;
76998 ops->driver |= DRIVER_LOADED;
76999 ops->argsize = argsize;
77000
77001 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
77002 dev->name, ops->id, ops->argsize, dev->argsize);
77003 return -EINVAL;
77004 }
77005 - if (ops->ops.init_device(dev) >= 0) {
77006 + if (ops->ops->init_device(dev) >= 0) {
77007 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
77008 ops->num_init_devices++;
77009 } else {
77010 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
77011 dev->name, ops->id, ops->argsize, dev->argsize);
77012 return -EINVAL;
77013 }
77014 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
77015 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
77016 dev->status = SNDRV_SEQ_DEVICE_FREE;
77017 dev->driver_data = NULL;
77018 ops->num_init_devices--;
77019 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
77020 index f24bf9a..1f7b67c 100644
77021 --- a/sound/drivers/mts64.c
77022 +++ b/sound/drivers/mts64.c
77023 @@ -29,6 +29,7 @@
77024 #include <sound/initval.h>
77025 #include <sound/rawmidi.h>
77026 #include <sound/control.h>
77027 +#include <asm/local.h>
77028
77029 #define CARD_NAME "Miditerminal 4140"
77030 #define DRIVER_NAME "MTS64"
77031 @@ -67,7 +68,7 @@ struct mts64 {
77032 struct pardevice *pardev;
77033 int pardev_claimed;
77034
77035 - int open_count;
77036 + local_t open_count;
77037 int current_midi_output_port;
77038 int current_midi_input_port;
77039 u8 mode[MTS64_NUM_INPUT_PORTS];
77040 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
77041 {
77042 struct mts64 *mts = substream->rmidi->private_data;
77043
77044 - if (mts->open_count == 0) {
77045 + if (local_read(&mts->open_count) == 0) {
77046 /* We don't need a spinlock here, because this is just called
77047 if the device has not been opened before.
77048 So there aren't any IRQs from the device */
77049 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
77050
77051 msleep(50);
77052 }
77053 - ++(mts->open_count);
77054 + local_inc(&mts->open_count);
77055
77056 return 0;
77057 }
77058 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
77059 struct mts64 *mts = substream->rmidi->private_data;
77060 unsigned long flags;
77061
77062 - --(mts->open_count);
77063 - if (mts->open_count == 0) {
77064 + if (local_dec_return(&mts->open_count) == 0) {
77065 /* We need the spinlock_irqsave here because we can still
77066 have IRQs at this point */
77067 spin_lock_irqsave(&mts->lock, flags);
77068 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
77069
77070 msleep(500);
77071
77072 - } else if (mts->open_count < 0)
77073 - mts->open_count = 0;
77074 + } else if (local_read(&mts->open_count) < 0)
77075 + local_set(&mts->open_count, 0);
77076
77077 return 0;
77078 }
77079 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
77080 index b953fb4..1999c01 100644
77081 --- a/sound/drivers/opl4/opl4_lib.c
77082 +++ b/sound/drivers/opl4/opl4_lib.c
77083 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
77084 MODULE_DESCRIPTION("OPL4 driver");
77085 MODULE_LICENSE("GPL");
77086
77087 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
77088 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
77089 {
77090 int timeout = 10;
77091 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
77092 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
77093 index f664823..590c745 100644
77094 --- a/sound/drivers/portman2x4.c
77095 +++ b/sound/drivers/portman2x4.c
77096 @@ -48,6 +48,7 @@
77097 #include <sound/initval.h>
77098 #include <sound/rawmidi.h>
77099 #include <sound/control.h>
77100 +#include <asm/local.h>
77101
77102 #define CARD_NAME "Portman 2x4"
77103 #define DRIVER_NAME "portman"
77104 @@ -85,7 +86,7 @@ struct portman {
77105 struct pardevice *pardev;
77106 int pardev_claimed;
77107
77108 - int open_count;
77109 + local_t open_count;
77110 int mode[PORTMAN_NUM_INPUT_PORTS];
77111 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
77112 };
77113 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
77114 index 87657dd..a8268d4 100644
77115 --- a/sound/firewire/amdtp.c
77116 +++ b/sound/firewire/amdtp.c
77117 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
77118 ptr = s->pcm_buffer_pointer + data_blocks;
77119 if (ptr >= pcm->runtime->buffer_size)
77120 ptr -= pcm->runtime->buffer_size;
77121 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
77122 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
77123
77124 s->pcm_period_pointer += data_blocks;
77125 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
77126 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
77127 */
77128 void amdtp_out_stream_update(struct amdtp_out_stream *s)
77129 {
77130 - ACCESS_ONCE(s->source_node_id_field) =
77131 + ACCESS_ONCE_RW(s->source_node_id_field) =
77132 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
77133 }
77134 EXPORT_SYMBOL(amdtp_out_stream_update);
77135 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
77136 index 537a9cb..8e8c8e9 100644
77137 --- a/sound/firewire/amdtp.h
77138 +++ b/sound/firewire/amdtp.h
77139 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
77140 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
77141 struct snd_pcm_substream *pcm)
77142 {
77143 - ACCESS_ONCE(s->pcm) = pcm;
77144 + ACCESS_ONCE_RW(s->pcm) = pcm;
77145 }
77146
77147 /**
77148 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
77149 index cd094ec..eca1277 100644
77150 --- a/sound/firewire/isight.c
77151 +++ b/sound/firewire/isight.c
77152 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
77153 ptr += count;
77154 if (ptr >= runtime->buffer_size)
77155 ptr -= runtime->buffer_size;
77156 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
77157 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
77158
77159 isight->period_counter += count;
77160 if (isight->period_counter >= runtime->period_size) {
77161 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
77162 if (err < 0)
77163 return err;
77164
77165 - ACCESS_ONCE(isight->pcm_active) = true;
77166 + ACCESS_ONCE_RW(isight->pcm_active) = true;
77167
77168 return 0;
77169 }
77170 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
77171 {
77172 struct isight *isight = substream->private_data;
77173
77174 - ACCESS_ONCE(isight->pcm_active) = false;
77175 + ACCESS_ONCE_RW(isight->pcm_active) = false;
77176
77177 mutex_lock(&isight->mutex);
77178 isight_stop_streaming(isight);
77179 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
77180
77181 switch (cmd) {
77182 case SNDRV_PCM_TRIGGER_START:
77183 - ACCESS_ONCE(isight->pcm_running) = true;
77184 + ACCESS_ONCE_RW(isight->pcm_running) = true;
77185 break;
77186 case SNDRV_PCM_TRIGGER_STOP:
77187 - ACCESS_ONCE(isight->pcm_running) = false;
77188 + ACCESS_ONCE_RW(isight->pcm_running) = false;
77189 break;
77190 default:
77191 return -EINVAL;
77192 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
77193 index c94578d..0794ac1 100644
77194 --- a/sound/isa/cmi8330.c
77195 +++ b/sound/isa/cmi8330.c
77196 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
77197
77198 struct snd_pcm *pcm;
77199 struct snd_cmi8330_stream {
77200 - struct snd_pcm_ops ops;
77201 + snd_pcm_ops_no_const ops;
77202 snd_pcm_open_callback_t open;
77203 void *private_data; /* sb or wss */
77204 } streams[2];
77205 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
77206 index 733b014..56ce96f 100644
77207 --- a/sound/oss/sb_audio.c
77208 +++ b/sound/oss/sb_audio.c
77209 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
77210 buf16 = (signed short *)(localbuf + localoffs);
77211 while (c)
77212 {
77213 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
77214 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
77215 if (copy_from_user(lbuf8,
77216 userbuf+useroffs + p,
77217 locallen))
77218 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
77219 index 09d4648..cf234c7 100644
77220 --- a/sound/oss/swarm_cs4297a.c
77221 +++ b/sound/oss/swarm_cs4297a.c
77222 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
77223 {
77224 struct cs4297a_state *s;
77225 u32 pwr, id;
77226 - mm_segment_t fs;
77227 int rval;
77228 #ifndef CONFIG_BCM_CS4297A_CSWARM
77229 u64 cfg;
77230 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
77231 if (!rval) {
77232 char *sb1250_duart_present;
77233
77234 +#if 0
77235 + mm_segment_t fs;
77236 fs = get_fs();
77237 set_fs(KERNEL_DS);
77238 -#if 0
77239 val = SOUND_MASK_LINE;
77240 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
77241 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
77242 val = initvol[i].vol;
77243 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
77244 }
77245 + set_fs(fs);
77246 // cs4297a_write_ac97(s, 0x18, 0x0808);
77247 #else
77248 // cs4297a_write_ac97(s, 0x5e, 0x180);
77249 cs4297a_write_ac97(s, 0x02, 0x0808);
77250 cs4297a_write_ac97(s, 0x18, 0x0808);
77251 #endif
77252 - set_fs(fs);
77253
77254 list_add(&s->list, &cs4297a_devs);
77255
77256 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
77257 index 5644711..a2aebc1 100644
77258 --- a/sound/pci/hda/hda_codec.h
77259 +++ b/sound/pci/hda/hda_codec.h
77260 @@ -611,7 +611,7 @@ struct hda_bus_ops {
77261 /* notify power-up/down from codec to controller */
77262 void (*pm_notify)(struct hda_bus *bus);
77263 #endif
77264 -};
77265 +} __no_const;
77266
77267 /* template to pass to the bus constructor */
77268 struct hda_bus_template {
77269 @@ -713,6 +713,7 @@ struct hda_codec_ops {
77270 #endif
77271 void (*reboot_notify)(struct hda_codec *codec);
77272 };
77273 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
77274
77275 /* record for amp information cache */
77276 struct hda_cache_head {
77277 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
77278 struct snd_pcm_substream *substream);
77279 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
77280 struct snd_pcm_substream *substream);
77281 -};
77282 +} __no_const;
77283
77284 /* PCM information for each substream */
77285 struct hda_pcm_stream {
77286 @@ -801,7 +802,7 @@ struct hda_codec {
77287 const char *modelname; /* model name for preset */
77288
77289 /* set by patch */
77290 - struct hda_codec_ops patch_ops;
77291 + hda_codec_ops_no_const patch_ops;
77292
77293 /* PCM to create, set by patch_ops.build_pcms callback */
77294 unsigned int num_pcms;
77295 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
77296 index 0da778a..bc38b84 100644
77297 --- a/sound/pci/ice1712/ice1712.h
77298 +++ b/sound/pci/ice1712/ice1712.h
77299 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
77300 unsigned int mask_flags; /* total mask bits */
77301 struct snd_akm4xxx_ops {
77302 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
77303 - } ops;
77304 + } __no_const ops;
77305 };
77306
77307 struct snd_ice1712_spdif {
77308 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
77309 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77310 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77311 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77312 - } ops;
77313 + } __no_const ops;
77314 };
77315
77316
77317 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
77318 index 03ee4e3..be86b46 100644
77319 --- a/sound/pci/ymfpci/ymfpci_main.c
77320 +++ b/sound/pci/ymfpci/ymfpci_main.c
77321 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
77322 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
77323 break;
77324 }
77325 - if (atomic_read(&chip->interrupt_sleep_count)) {
77326 - atomic_set(&chip->interrupt_sleep_count, 0);
77327 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
77328 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77329 wake_up(&chip->interrupt_sleep);
77330 }
77331 __end:
77332 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
77333 continue;
77334 init_waitqueue_entry(&wait, current);
77335 add_wait_queue(&chip->interrupt_sleep, &wait);
77336 - atomic_inc(&chip->interrupt_sleep_count);
77337 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
77338 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
77339 remove_wait_queue(&chip->interrupt_sleep, &wait);
77340 }
77341 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
77342 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
77343 spin_unlock(&chip->reg_lock);
77344
77345 - if (atomic_read(&chip->interrupt_sleep_count)) {
77346 - atomic_set(&chip->interrupt_sleep_count, 0);
77347 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
77348 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77349 wake_up(&chip->interrupt_sleep);
77350 }
77351 }
77352 @@ -2382,7 +2382,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
77353 spin_lock_init(&chip->reg_lock);
77354 spin_lock_init(&chip->voice_lock);
77355 init_waitqueue_head(&chip->interrupt_sleep);
77356 - atomic_set(&chip->interrupt_sleep_count, 0);
77357 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77358 chip->card = card;
77359 chip->pci = pci;
77360 chip->irq = -1;
77361 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
77362 index ee15337..e2187a6 100644
77363 --- a/sound/soc/soc-pcm.c
77364 +++ b/sound/soc/soc-pcm.c
77365 @@ -583,7 +583,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
77366 }
77367
77368 /* ASoC PCM operations */
77369 -static struct snd_pcm_ops soc_pcm_ops = {
77370 +static snd_pcm_ops_no_const soc_pcm_ops = {
77371 .open = soc_pcm_open,
77372 .close = soc_pcm_close,
77373 .hw_params = soc_pcm_hw_params,
77374 diff --git a/sound/usb/card.h b/sound/usb/card.h
77375 index a39edcc..1014050 100644
77376 --- a/sound/usb/card.h
77377 +++ b/sound/usb/card.h
77378 @@ -44,6 +44,7 @@ struct snd_urb_ops {
77379 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
77380 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
77381 };
77382 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
77383
77384 struct snd_usb_substream {
77385 struct snd_usb_stream *stream;
77386 @@ -93,7 +94,7 @@ struct snd_usb_substream {
77387 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
77388 spinlock_t lock;
77389
77390 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
77391 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
77392 int last_frame_number; /* stored frame number */
77393 int last_delay; /* stored delay */
77394 };
77395 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
77396 new file mode 100644
77397 index 0000000..b044b80
77398 --- /dev/null
77399 +++ b/tools/gcc/Makefile
77400 @@ -0,0 +1,21 @@
77401 +#CC := gcc
77402 +#PLUGIN_SOURCE_FILES := pax_plugin.c
77403 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
77404 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
77405 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W
77406 +
77407 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include
77408 +
77409 +hostlibs-y := constify_plugin.so
77410 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
77411 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
77412 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
77413 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
77414 +
77415 +always := $(hostlibs-y)
77416 +
77417 +constify_plugin-objs := constify_plugin.o
77418 +stackleak_plugin-objs := stackleak_plugin.o
77419 +kallocstat_plugin-objs := kallocstat_plugin.o
77420 +kernexec_plugin-objs := kernexec_plugin.o
77421 +checker_plugin-objs := checker_plugin.o
77422 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
77423 new file mode 100644
77424 index 0000000..d41b5af
77425 --- /dev/null
77426 +++ b/tools/gcc/checker_plugin.c
77427 @@ -0,0 +1,171 @@
77428 +/*
77429 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
77430 + * Licensed under the GPL v2
77431 + *
77432 + * Note: the choice of the license means that the compilation process is
77433 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
77434 + * but for the kernel it doesn't matter since it doesn't link against
77435 + * any of the gcc libraries
77436 + *
77437 + * gcc plugin to implement various sparse (source code checker) features
77438 + *
77439 + * TODO:
77440 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
77441 + *
77442 + * BUGS:
77443 + * - none known
77444 + */
77445 +#include "gcc-plugin.h"
77446 +#include "config.h"
77447 +#include "system.h"
77448 +#include "coretypes.h"
77449 +#include "tree.h"
77450 +#include "tree-pass.h"
77451 +#include "flags.h"
77452 +#include "intl.h"
77453 +#include "toplev.h"
77454 +#include "plugin.h"
77455 +//#include "expr.h" where are you...
77456 +#include "diagnostic.h"
77457 +#include "plugin-version.h"
77458 +#include "tm.h"
77459 +#include "function.h"
77460 +#include "basic-block.h"
77461 +#include "gimple.h"
77462 +#include "rtl.h"
77463 +#include "emit-rtl.h"
77464 +#include "tree-flow.h"
77465 +#include "target.h"
77466 +
77467 +extern void c_register_addr_space (const char *str, addr_space_t as);
77468 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
77469 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
77470 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
77471 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
77472 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
77473 +
77474 +extern void print_gimple_stmt(FILE *, gimple, int, int);
77475 +extern rtx emit_move_insn(rtx x, rtx y);
77476 +
77477 +int plugin_is_GPL_compatible;
77478 +
77479 +static struct plugin_info checker_plugin_info = {
77480 + .version = "201111150100",
77481 +};
77482 +
77483 +#define ADDR_SPACE_KERNEL 0
77484 +#define ADDR_SPACE_FORCE_KERNEL 1
77485 +#define ADDR_SPACE_USER 2
77486 +#define ADDR_SPACE_FORCE_USER 3
77487 +#define ADDR_SPACE_IOMEM 0
77488 +#define ADDR_SPACE_FORCE_IOMEM 0
77489 +#define ADDR_SPACE_PERCPU 0
77490 +#define ADDR_SPACE_FORCE_PERCPU 0
77491 +#define ADDR_SPACE_RCU 0
77492 +#define ADDR_SPACE_FORCE_RCU 0
77493 +
77494 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
77495 +{
77496 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
77497 +}
77498 +
77499 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
77500 +{
77501 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
77502 +}
77503 +
77504 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
77505 +{
77506 + return default_addr_space_valid_pointer_mode(mode, as);
77507 +}
77508 +
77509 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
77510 +{
77511 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
77512 +}
77513 +
77514 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
77515 +{
77516 + return default_addr_space_legitimize_address(x, oldx, mode, as);
77517 +}
77518 +
77519 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
77520 +{
77521 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
77522 + return true;
77523 +
77524 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
77525 + return true;
77526 +
77527 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
77528 + return true;
77529 +
77530 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
77531 + return true;
77532 +
77533 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
77534 + return true;
77535 +
77536 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
77537 + return true;
77538 +
77539 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
77540 + return true;
77541 +
77542 + return subset == superset;
77543 +}
77544 +
77545 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
77546 +{
77547 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
77548 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
77549 +
77550 + return op;
77551 +}
77552 +
77553 +static void register_checker_address_spaces(void *event_data, void *data)
77554 +{
77555 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
77556 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
77557 + c_register_addr_space("__user", ADDR_SPACE_USER);
77558 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
77559 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
77560 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
77561 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
77562 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
77563 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
77564 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
77565 +
77566 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
77567 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
77568 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
77569 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
77570 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
77571 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
77572 + targetm.addr_space.convert = checker_addr_space_convert;
77573 +}
77574 +
77575 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
77576 +{
77577 + const char * const plugin_name = plugin_info->base_name;
77578 + const int argc = plugin_info->argc;
77579 + const struct plugin_argument * const argv = plugin_info->argv;
77580 + int i;
77581 +
77582 + if (!plugin_default_version_check(version, &gcc_version)) {
77583 + error(G_("incompatible gcc/plugin versions"));
77584 + return 1;
77585 + }
77586 +
77587 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
77588 +
77589 + for (i = 0; i < argc; ++i)
77590 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
77591 +
77592 + if (TARGET_64BIT == 0)
77593 + return 0;
77594 +
77595 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
77596 +
77597 + return 0;
77598 +}
77599 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
77600 new file mode 100644
77601 index 0000000..704a564
77602 --- /dev/null
77603 +++ b/tools/gcc/constify_plugin.c
77604 @@ -0,0 +1,303 @@
77605 +/*
77606 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
77607 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
77608 + * Licensed under the GPL v2, or (at your option) v3
77609 + *
77610 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
77611 + *
77612 + * Homepage:
77613 + * http://www.grsecurity.net/~ephox/const_plugin/
77614 + *
77615 + * Usage:
77616 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
77617 + * $ gcc -fplugin=constify_plugin.so test.c -O2
77618 + */
77619 +
77620 +#include "gcc-plugin.h"
77621 +#include "config.h"
77622 +#include "system.h"
77623 +#include "coretypes.h"
77624 +#include "tree.h"
77625 +#include "tree-pass.h"
77626 +#include "flags.h"
77627 +#include "intl.h"
77628 +#include "toplev.h"
77629 +#include "plugin.h"
77630 +#include "diagnostic.h"
77631 +#include "plugin-version.h"
77632 +#include "tm.h"
77633 +#include "function.h"
77634 +#include "basic-block.h"
77635 +#include "gimple.h"
77636 +#include "rtl.h"
77637 +#include "emit-rtl.h"
77638 +#include "tree-flow.h"
77639 +
77640 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
77641 +
77642 +int plugin_is_GPL_compatible;
77643 +
77644 +static struct plugin_info const_plugin_info = {
77645 + .version = "201111150100",
77646 + .help = "no-constify\tturn off constification\n",
77647 +};
77648 +
77649 +static void constify_type(tree type);
77650 +static bool walk_struct(tree node);
77651 +
77652 +static tree deconstify_type(tree old_type)
77653 +{
77654 + tree new_type, field;
77655 +
77656 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
77657 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
77658 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
77659 + DECL_FIELD_CONTEXT(field) = new_type;
77660 + TYPE_READONLY(new_type) = 0;
77661 + C_TYPE_FIELDS_READONLY(new_type) = 0;
77662 + return new_type;
77663 +}
77664 +
77665 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
77666 +{
77667 + tree type;
77668 +
77669 + *no_add_attrs = true;
77670 + if (TREE_CODE(*node) == FUNCTION_DECL) {
77671 + error("%qE attribute does not apply to functions", name);
77672 + return NULL_TREE;
77673 + }
77674 +
77675 + if (TREE_CODE(*node) == VAR_DECL) {
77676 + error("%qE attribute does not apply to variables", name);
77677 + return NULL_TREE;
77678 + }
77679 +
77680 + if (TYPE_P(*node)) {
77681 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
77682 + *no_add_attrs = false;
77683 + else
77684 + error("%qE attribute applies to struct and union types only", name);
77685 + return NULL_TREE;
77686 + }
77687 +
77688 + type = TREE_TYPE(*node);
77689 +
77690 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
77691 + error("%qE attribute applies to struct and union types only", name);
77692 + return NULL_TREE;
77693 + }
77694 +
77695 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
77696 + error("%qE attribute is already applied to the type", name);
77697 + return NULL_TREE;
77698 + }
77699 +
77700 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
77701 + error("%qE attribute used on type that is not constified", name);
77702 + return NULL_TREE;
77703 + }
77704 +
77705 + if (TREE_CODE(*node) == TYPE_DECL) {
77706 + TREE_TYPE(*node) = deconstify_type(type);
77707 + TREE_READONLY(*node) = 0;
77708 + return NULL_TREE;
77709 + }
77710 +
77711 + return NULL_TREE;
77712 +}
77713 +
77714 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
77715 +{
77716 + *no_add_attrs = true;
77717 + if (!TYPE_P(*node)) {
77718 + error("%qE attribute applies to types only", name);
77719 + return NULL_TREE;
77720 + }
77721 +
77722 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
77723 + error("%qE attribute applies to struct and union types only", name);
77724 + return NULL_TREE;
77725 + }
77726 +
77727 + *no_add_attrs = false;
77728 + constify_type(*node);
77729 + return NULL_TREE;
77730 +}
77731 +
77732 +static struct attribute_spec no_const_attr = {
77733 + .name = "no_const",
77734 + .min_length = 0,
77735 + .max_length = 0,
77736 + .decl_required = false,
77737 + .type_required = false,
77738 + .function_type_required = false,
77739 + .handler = handle_no_const_attribute,
77740 +#if BUILDING_GCC_VERSION >= 4007
77741 + .affects_type_identity = true
77742 +#endif
77743 +};
77744 +
77745 +static struct attribute_spec do_const_attr = {
77746 + .name = "do_const",
77747 + .min_length = 0,
77748 + .max_length = 0,
77749 + .decl_required = false,
77750 + .type_required = false,
77751 + .function_type_required = false,
77752 + .handler = handle_do_const_attribute,
77753 +#if BUILDING_GCC_VERSION >= 4007
77754 + .affects_type_identity = true
77755 +#endif
77756 +};
77757 +
77758 +static void register_attributes(void *event_data, void *data)
77759 +{
77760 + register_attribute(&no_const_attr);
77761 + register_attribute(&do_const_attr);
77762 +}
77763 +
77764 +static void constify_type(tree type)
77765 +{
77766 + TYPE_READONLY(type) = 1;
77767 + C_TYPE_FIELDS_READONLY(type) = 1;
77768 +}
77769 +
77770 +static bool is_fptr(tree field)
77771 +{
77772 + tree ptr = TREE_TYPE(field);
77773 +
77774 + if (TREE_CODE(ptr) != POINTER_TYPE)
77775 + return false;
77776 +
77777 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
77778 +}
77779 +
77780 +static bool walk_struct(tree node)
77781 +{
77782 + tree field;
77783 +
77784 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
77785 + return false;
77786 +
77787 + if (TYPE_FIELDS(node) == NULL_TREE)
77788 + return false;
77789 +
77790 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
77791 + tree type = TREE_TYPE(field);
77792 + enum tree_code code = TREE_CODE(type);
77793 + if (code == RECORD_TYPE || code == UNION_TYPE) {
77794 + if (!(walk_struct(type)))
77795 + return false;
77796 + } else if (!is_fptr(field) && !TREE_READONLY(field))
77797 + return false;
77798 + }
77799 + return true;
77800 +}
77801 +
77802 +static void finish_type(void *event_data, void *data)
77803 +{
77804 + tree type = (tree)event_data;
77805 +
77806 + if (type == NULL_TREE)
77807 + return;
77808 +
77809 + if (TYPE_READONLY(type))
77810 + return;
77811 +
77812 + if (walk_struct(type))
77813 + constify_type(type);
77814 +}
77815 +
77816 +static unsigned int check_local_variables(void);
77817 +
77818 +struct gimple_opt_pass pass_local_variable = {
77819 + {
77820 + .type = GIMPLE_PASS,
77821 + .name = "check_local_variables",
77822 + .gate = NULL,
77823 + .execute = check_local_variables,
77824 + .sub = NULL,
77825 + .next = NULL,
77826 + .static_pass_number = 0,
77827 + .tv_id = TV_NONE,
77828 + .properties_required = 0,
77829 + .properties_provided = 0,
77830 + .properties_destroyed = 0,
77831 + .todo_flags_start = 0,
77832 + .todo_flags_finish = 0
77833 + }
77834 +};
77835 +
77836 +static unsigned int check_local_variables(void)
77837 +{
77838 + tree var;
77839 + referenced_var_iterator rvi;
77840 +
77841 +#if BUILDING_GCC_VERSION == 4005
77842 + FOR_EACH_REFERENCED_VAR(var, rvi) {
77843 +#else
77844 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
77845 +#endif
77846 + tree type = TREE_TYPE(var);
77847 +
77848 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
77849 + continue;
77850 +
77851 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
77852 + continue;
77853 +
77854 + if (!TYPE_READONLY(type))
77855 + continue;
77856 +
77857 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
77858 +// continue;
77859 +
77860 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
77861 +// continue;
77862 +
77863 + if (walk_struct(type)) {
77864 + error("constified variable %qE cannot be local", var);
77865 + return 1;
77866 + }
77867 + }
77868 + return 0;
77869 +}
77870 +
77871 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
77872 +{
77873 + const char * const plugin_name = plugin_info->base_name;
77874 + const int argc = plugin_info->argc;
77875 + const struct plugin_argument * const argv = plugin_info->argv;
77876 + int i;
77877 + bool constify = true;
77878 +
77879 + struct register_pass_info local_variable_pass_info = {
77880 + .pass = &pass_local_variable.pass,
77881 + .reference_pass_name = "*referenced_vars",
77882 + .ref_pass_instance_number = 0,
77883 + .pos_op = PASS_POS_INSERT_AFTER
77884 + };
77885 +
77886 + if (!plugin_default_version_check(version, &gcc_version)) {
77887 + error(G_("incompatible gcc/plugin versions"));
77888 + return 1;
77889 + }
77890 +
77891 + for (i = 0; i < argc; ++i) {
77892 + if (!(strcmp(argv[i].key, "no-constify"))) {
77893 + constify = false;
77894 + continue;
77895 + }
77896 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
77897 + }
77898 +
77899 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
77900 + if (constify) {
77901 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
77902 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
77903 + }
77904 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
77905 +
77906 + return 0;
77907 +}
77908 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
77909 new file mode 100644
77910 index 0000000..a5eabce
77911 --- /dev/null
77912 +++ b/tools/gcc/kallocstat_plugin.c
77913 @@ -0,0 +1,167 @@
77914 +/*
77915 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
77916 + * Licensed under the GPL v2
77917 + *
77918 + * Note: the choice of the license means that the compilation process is
77919 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
77920 + * but for the kernel it doesn't matter since it doesn't link against
77921 + * any of the gcc libraries
77922 + *
77923 + * gcc plugin to find the distribution of k*alloc sizes
77924 + *
77925 + * TODO:
77926 + *
77927 + * BUGS:
77928 + * - none known
77929 + */
77930 +#include "gcc-plugin.h"
77931 +#include "config.h"
77932 +#include "system.h"
77933 +#include "coretypes.h"
77934 +#include "tree.h"
77935 +#include "tree-pass.h"
77936 +#include "flags.h"
77937 +#include "intl.h"
77938 +#include "toplev.h"
77939 +#include "plugin.h"
77940 +//#include "expr.h" where are you...
77941 +#include "diagnostic.h"
77942 +#include "plugin-version.h"
77943 +#include "tm.h"
77944 +#include "function.h"
77945 +#include "basic-block.h"
77946 +#include "gimple.h"
77947 +#include "rtl.h"
77948 +#include "emit-rtl.h"
77949 +
77950 +extern void print_gimple_stmt(FILE *, gimple, int, int);
77951 +
77952 +int plugin_is_GPL_compatible;
77953 +
77954 +static const char * const kalloc_functions[] = {
77955 + "__kmalloc",
77956 + "kmalloc",
77957 + "kmalloc_large",
77958 + "kmalloc_node",
77959 + "kmalloc_order",
77960 + "kmalloc_order_trace",
77961 + "kmalloc_slab",
77962 + "kzalloc",
77963 + "kzalloc_node",
77964 +};
77965 +
77966 +static struct plugin_info kallocstat_plugin_info = {
77967 + .version = "201111150100",
77968 +};
77969 +
77970 +static unsigned int execute_kallocstat(void);
77971 +
77972 +static struct gimple_opt_pass kallocstat_pass = {
77973 + .pass = {
77974 + .type = GIMPLE_PASS,
77975 + .name = "kallocstat",
77976 + .gate = NULL,
77977 + .execute = execute_kallocstat,
77978 + .sub = NULL,
77979 + .next = NULL,
77980 + .static_pass_number = 0,
77981 + .tv_id = TV_NONE,
77982 + .properties_required = 0,
77983 + .properties_provided = 0,
77984 + .properties_destroyed = 0,
77985 + .todo_flags_start = 0,
77986 + .todo_flags_finish = 0
77987 + }
77988 +};
77989 +
77990 +static bool is_kalloc(const char *fnname)
77991 +{
77992 + size_t i;
77993 +
77994 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
77995 + if (!strcmp(fnname, kalloc_functions[i]))
77996 + return true;
77997 + return false;
77998 +}
77999 +
78000 +static unsigned int execute_kallocstat(void)
78001 +{
78002 + basic_block bb;
78003 +
78004 + // 1. loop through BBs and GIMPLE statements
78005 + FOR_EACH_BB(bb) {
78006 + gimple_stmt_iterator gsi;
78007 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78008 + // gimple match:
78009 + tree fndecl, size;
78010 + gimple call_stmt;
78011 + const char *fnname;
78012 +
78013 + // is it a call
78014 + call_stmt = gsi_stmt(gsi);
78015 + if (!is_gimple_call(call_stmt))
78016 + continue;
78017 + fndecl = gimple_call_fndecl(call_stmt);
78018 + if (fndecl == NULL_TREE)
78019 + continue;
78020 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
78021 + continue;
78022 +
78023 + // is it a call to k*alloc
78024 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
78025 + if (!is_kalloc(fnname))
78026 + continue;
78027 +
78028 + // is the size arg the result of a simple const assignment
78029 + size = gimple_call_arg(call_stmt, 0);
78030 + while (true) {
78031 + gimple def_stmt;
78032 + expanded_location xloc;
78033 + size_t size_val;
78034 +
78035 + if (TREE_CODE(size) != SSA_NAME)
78036 + break;
78037 + def_stmt = SSA_NAME_DEF_STMT(size);
78038 + if (!def_stmt || !is_gimple_assign(def_stmt))
78039 + break;
78040 + if (gimple_num_ops(def_stmt) != 2)
78041 + break;
78042 + size = gimple_assign_rhs1(def_stmt);
78043 + if (!TREE_CONSTANT(size))
78044 + continue;
78045 + xloc = expand_location(gimple_location(def_stmt));
78046 + if (!xloc.file)
78047 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
78048 + size_val = TREE_INT_CST_LOW(size);
78049 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
78050 + break;
78051 + }
78052 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
78053 +//debug_tree(gimple_call_fn(call_stmt));
78054 +//print_node(stderr, "pax", fndecl, 4);
78055 + }
78056 + }
78057 +
78058 + return 0;
78059 +}
78060 +
78061 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78062 +{
78063 + const char * const plugin_name = plugin_info->base_name;
78064 + struct register_pass_info kallocstat_pass_info = {
78065 + .pass = &kallocstat_pass.pass,
78066 + .reference_pass_name = "ssa",
78067 + .ref_pass_instance_number = 0,
78068 + .pos_op = PASS_POS_INSERT_AFTER
78069 + };
78070 +
78071 + if (!plugin_default_version_check(version, &gcc_version)) {
78072 + error(G_("incompatible gcc/plugin versions"));
78073 + return 1;
78074 + }
78075 +
78076 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
78077 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
78078 +
78079 + return 0;
78080 +}
78081 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
78082 new file mode 100644
78083 index 0000000..51f747e
78084 --- /dev/null
78085 +++ b/tools/gcc/kernexec_plugin.c
78086 @@ -0,0 +1,348 @@
78087 +/*
78088 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78089 + * Licensed under the GPL v2
78090 + *
78091 + * Note: the choice of the license means that the compilation process is
78092 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78093 + * but for the kernel it doesn't matter since it doesn't link against
78094 + * any of the gcc libraries
78095 + *
78096 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
78097 + *
78098 + * TODO:
78099 + *
78100 + * BUGS:
78101 + * - none known
78102 + */
78103 +#include "gcc-plugin.h"
78104 +#include "config.h"
78105 +#include "system.h"
78106 +#include "coretypes.h"
78107 +#include "tree.h"
78108 +#include "tree-pass.h"
78109 +#include "flags.h"
78110 +#include "intl.h"
78111 +#include "toplev.h"
78112 +#include "plugin.h"
78113 +//#include "expr.h" where are you...
78114 +#include "diagnostic.h"
78115 +#include "plugin-version.h"
78116 +#include "tm.h"
78117 +#include "function.h"
78118 +#include "basic-block.h"
78119 +#include "gimple.h"
78120 +#include "rtl.h"
78121 +#include "emit-rtl.h"
78122 +#include "tree-flow.h"
78123 +
78124 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78125 +extern rtx emit_move_insn(rtx x, rtx y);
78126 +
78127 +int plugin_is_GPL_compatible;
78128 +
78129 +static struct plugin_info kernexec_plugin_info = {
78130 + .version = "201111291120",
78131 + .help = "method=[bts|or]\tinstrumentation method\n"
78132 +};
78133 +
78134 +static unsigned int execute_kernexec_fptr(void);
78135 +static unsigned int execute_kernexec_retaddr(void);
78136 +static bool kernexec_cmodel_check(void);
78137 +
78138 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator);
78139 +static void (*kernexec_instrument_retaddr)(rtx);
78140 +
78141 +static struct gimple_opt_pass kernexec_fptr_pass = {
78142 + .pass = {
78143 + .type = GIMPLE_PASS,
78144 + .name = "kernexec_fptr",
78145 + .gate = kernexec_cmodel_check,
78146 + .execute = execute_kernexec_fptr,
78147 + .sub = NULL,
78148 + .next = NULL,
78149 + .static_pass_number = 0,
78150 + .tv_id = TV_NONE,
78151 + .properties_required = 0,
78152 + .properties_provided = 0,
78153 + .properties_destroyed = 0,
78154 + .todo_flags_start = 0,
78155 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
78156 + }
78157 +};
78158 +
78159 +static struct rtl_opt_pass kernexec_retaddr_pass = {
78160 + .pass = {
78161 + .type = RTL_PASS,
78162 + .name = "kernexec_retaddr",
78163 + .gate = kernexec_cmodel_check,
78164 + .execute = execute_kernexec_retaddr,
78165 + .sub = NULL,
78166 + .next = NULL,
78167 + .static_pass_number = 0,
78168 + .tv_id = TV_NONE,
78169 + .properties_required = 0,
78170 + .properties_provided = 0,
78171 + .properties_destroyed = 0,
78172 + .todo_flags_start = 0,
78173 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
78174 + }
78175 +};
78176 +
78177 +static bool kernexec_cmodel_check(void)
78178 +{
78179 + tree section;
78180 +
78181 + if (ix86_cmodel != CM_KERNEL)
78182 + return false;
78183 +
78184 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
78185 + if (!section || !TREE_VALUE(section))
78186 + return true;
78187 +
78188 + section = TREE_VALUE(TREE_VALUE(section));
78189 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
78190 + return true;
78191 +
78192 + return false;
78193 +}
78194 +
78195 +/*
78196 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
78197 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
78198 + */
78199 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator gsi)
78200 +{
78201 + gimple assign_intptr, assign_new_fptr, call_stmt;
78202 + tree intptr, old_fptr, new_fptr, kernexec_mask;
78203 +
78204 + call_stmt = gsi_stmt(gsi);
78205 + old_fptr = gimple_call_fn(call_stmt);
78206 +
78207 + // create temporary unsigned long variable used for bitops and cast fptr to it
78208 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
78209 + add_referenced_var(intptr);
78210 + mark_sym_for_renaming(intptr);
78211 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
78212 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
78213 + update_stmt(assign_intptr);
78214 +
78215 + // apply logical or to temporary unsigned long and bitmask
78216 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
78217 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
78218 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
78219 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
78220 + update_stmt(assign_intptr);
78221 +
78222 + // cast temporary unsigned long back to a temporary fptr variable
78223 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
78224 + add_referenced_var(new_fptr);
78225 + mark_sym_for_renaming(new_fptr);
78226 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
78227 + gsi_insert_before(&gsi, assign_new_fptr, GSI_SAME_STMT);
78228 + update_stmt(assign_new_fptr);
78229 +
78230 + // replace call stmt fn with the new fptr
78231 + gimple_call_set_fn(call_stmt, new_fptr);
78232 + update_stmt(call_stmt);
78233 +}
78234 +
78235 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator gsi)
78236 +{
78237 + gimple asm_or_stmt, call_stmt;
78238 + tree old_fptr, new_fptr, input, output;
78239 + VEC(tree, gc) *inputs = NULL;
78240 + VEC(tree, gc) *outputs = NULL;
78241 +
78242 + call_stmt = gsi_stmt(gsi);
78243 + old_fptr = gimple_call_fn(call_stmt);
78244 +
78245 + // create temporary fptr variable
78246 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
78247 + add_referenced_var(new_fptr);
78248 + mark_sym_for_renaming(new_fptr);
78249 +
78250 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
78251 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
78252 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
78253 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
78254 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
78255 + VEC_safe_push(tree, gc, inputs, input);
78256 + VEC_safe_push(tree, gc, outputs, output);
78257 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
78258 + gimple_asm_set_volatile(asm_or_stmt, true);
78259 + gsi_insert_before(&gsi, asm_or_stmt, GSI_SAME_STMT);
78260 + update_stmt(asm_or_stmt);
78261 +
78262 + // replace call stmt fn with the new fptr
78263 + gimple_call_set_fn(call_stmt, new_fptr);
78264 + update_stmt(call_stmt);
78265 +}
78266 +
78267 +/*
78268 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
78269 + */
78270 +static unsigned int execute_kernexec_fptr(void)
78271 +{
78272 + basic_block bb;
78273 + gimple_stmt_iterator gsi;
78274 +
78275 + // 1. loop through BBs and GIMPLE statements
78276 + FOR_EACH_BB(bb) {
78277 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78278 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
78279 + tree fn;
78280 + gimple call_stmt;
78281 +
78282 + // is it a call ...
78283 + call_stmt = gsi_stmt(gsi);
78284 + if (!is_gimple_call(call_stmt))
78285 + continue;
78286 + fn = gimple_call_fn(call_stmt);
78287 + if (TREE_CODE(fn) == ADDR_EXPR)
78288 + continue;
78289 + if (TREE_CODE(fn) != SSA_NAME)
78290 + gcc_unreachable();
78291 +
78292 + // ... through a function pointer
78293 + fn = SSA_NAME_VAR(fn);
78294 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
78295 + continue;
78296 + fn = TREE_TYPE(fn);
78297 + if (TREE_CODE(fn) != POINTER_TYPE)
78298 + continue;
78299 + fn = TREE_TYPE(fn);
78300 + if (TREE_CODE(fn) != FUNCTION_TYPE)
78301 + continue;
78302 +
78303 + kernexec_instrument_fptr(gsi);
78304 +
78305 +//debug_tree(gimple_call_fn(call_stmt));
78306 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
78307 + }
78308 + }
78309 +
78310 + return 0;
78311 +}
78312 +
78313 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
78314 +static void kernexec_instrument_retaddr_bts(rtx insn)
78315 +{
78316 + rtx btsq;
78317 + rtvec argvec, constraintvec, labelvec;
78318 + int line;
78319 +
78320 + // create asm volatile("btsq $63,(%%rsp)":::)
78321 + argvec = rtvec_alloc(0);
78322 + constraintvec = rtvec_alloc(0);
78323 + labelvec = rtvec_alloc(0);
78324 + line = expand_location(RTL_LOCATION(insn)).line;
78325 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
78326 + MEM_VOLATILE_P(btsq) = 1;
78327 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
78328 + emit_insn_before(btsq, insn);
78329 +}
78330 +
78331 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
78332 +static void kernexec_instrument_retaddr_or(rtx insn)
78333 +{
78334 + rtx orq;
78335 + rtvec argvec, constraintvec, labelvec;
78336 + int line;
78337 +
78338 + // create asm volatile("orq %%r10,(%%rsp)":::)
78339 + argvec = rtvec_alloc(0);
78340 + constraintvec = rtvec_alloc(0);
78341 + labelvec = rtvec_alloc(0);
78342 + line = expand_location(RTL_LOCATION(insn)).line;
78343 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
78344 + MEM_VOLATILE_P(orq) = 1;
78345 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
78346 + emit_insn_before(orq, insn);
78347 +}
78348 +
78349 +/*
78350 + * find all asm level function returns and forcibly set the highest bit of the return address
78351 + */
78352 +static unsigned int execute_kernexec_retaddr(void)
78353 +{
78354 + rtx insn;
78355 +
78356 + // 1. find function returns
78357 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
78358 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
78359 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
78360 + rtx body;
78361 +
78362 + // is it a retn
78363 + if (!JUMP_P(insn))
78364 + continue;
78365 + body = PATTERN(insn);
78366 + if (GET_CODE(body) == PARALLEL)
78367 + body = XVECEXP(body, 0, 0);
78368 + if (GET_CODE(body) != RETURN)
78369 + continue;
78370 + kernexec_instrument_retaddr(insn);
78371 + }
78372 +
78373 +// print_simple_rtl(stderr, get_insns());
78374 +// print_rtl(stderr, get_insns());
78375 +
78376 + return 0;
78377 +}
78378 +
78379 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78380 +{
78381 + const char * const plugin_name = plugin_info->base_name;
78382 + const int argc = plugin_info->argc;
78383 + const struct plugin_argument * const argv = plugin_info->argv;
78384 + int i;
78385 + struct register_pass_info kernexec_fptr_pass_info = {
78386 + .pass = &kernexec_fptr_pass.pass,
78387 + .reference_pass_name = "ssa",
78388 + .ref_pass_instance_number = 0,
78389 + .pos_op = PASS_POS_INSERT_AFTER
78390 + };
78391 + struct register_pass_info kernexec_retaddr_pass_info = {
78392 + .pass = &kernexec_retaddr_pass.pass,
78393 + .reference_pass_name = "pro_and_epilogue",
78394 + .ref_pass_instance_number = 0,
78395 + .pos_op = PASS_POS_INSERT_AFTER
78396 + };
78397 +
78398 + if (!plugin_default_version_check(version, &gcc_version)) {
78399 + error(G_("incompatible gcc/plugin versions"));
78400 + return 1;
78401 + }
78402 +
78403 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
78404 +
78405 + if (TARGET_64BIT == 0)
78406 + return 0;
78407 +
78408 + for (i = 0; i < argc; ++i) {
78409 + if (!strcmp(argv[i].key, "method")) {
78410 + if (!argv[i].value) {
78411 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78412 + continue;
78413 + }
78414 + if (!strcmp(argv[i].value, "bts")) {
78415 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
78416 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
78417 + } else if (!strcmp(argv[i].value, "or")) {
78418 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
78419 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
78420 + fix_register("r10", 1, 1);
78421 + } else
78422 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
78423 + continue;
78424 + }
78425 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78426 + }
78427 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
78428 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
78429 +
78430 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
78431 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
78432 +
78433 + return 0;
78434 +}
78435 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
78436 new file mode 100644
78437 index 0000000..d44f37c
78438 --- /dev/null
78439 +++ b/tools/gcc/stackleak_plugin.c
78440 @@ -0,0 +1,291 @@
78441 +/*
78442 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78443 + * Licensed under the GPL v2
78444 + *
78445 + * Note: the choice of the license means that the compilation process is
78446 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78447 + * but for the kernel it doesn't matter since it doesn't link against
78448 + * any of the gcc libraries
78449 + *
78450 + * gcc plugin to help implement various PaX features
78451 + *
78452 + * - track lowest stack pointer
78453 + *
78454 + * TODO:
78455 + * - initialize all local variables
78456 + *
78457 + * BUGS:
78458 + * - none known
78459 + */
78460 +#include "gcc-plugin.h"
78461 +#include "config.h"
78462 +#include "system.h"
78463 +#include "coretypes.h"
78464 +#include "tree.h"
78465 +#include "tree-pass.h"
78466 +#include "flags.h"
78467 +#include "intl.h"
78468 +#include "toplev.h"
78469 +#include "plugin.h"
78470 +//#include "expr.h" where are you...
78471 +#include "diagnostic.h"
78472 +#include "plugin-version.h"
78473 +#include "tm.h"
78474 +#include "function.h"
78475 +#include "basic-block.h"
78476 +#include "gimple.h"
78477 +#include "rtl.h"
78478 +#include "emit-rtl.h"
78479 +
78480 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78481 +
78482 +int plugin_is_GPL_compatible;
78483 +
78484 +static int track_frame_size = -1;
78485 +static const char track_function[] = "pax_track_stack";
78486 +static const char check_function[] = "pax_check_alloca";
78487 +static bool init_locals;
78488 +
78489 +static struct plugin_info stackleak_plugin_info = {
78490 + .version = "201111150100",
78491 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
78492 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
78493 +};
78494 +
78495 +static bool gate_stackleak_track_stack(void);
78496 +static unsigned int execute_stackleak_tree_instrument(void);
78497 +static unsigned int execute_stackleak_final(void);
78498 +
78499 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
78500 + .pass = {
78501 + .type = GIMPLE_PASS,
78502 + .name = "stackleak_tree_instrument",
78503 + .gate = gate_stackleak_track_stack,
78504 + .execute = execute_stackleak_tree_instrument,
78505 + .sub = NULL,
78506 + .next = NULL,
78507 + .static_pass_number = 0,
78508 + .tv_id = TV_NONE,
78509 + .properties_required = PROP_gimple_leh | PROP_cfg,
78510 + .properties_provided = 0,
78511 + .properties_destroyed = 0,
78512 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
78513 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
78514 + }
78515 +};
78516 +
78517 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
78518 + .pass = {
78519 + .type = RTL_PASS,
78520 + .name = "stackleak_final",
78521 + .gate = gate_stackleak_track_stack,
78522 + .execute = execute_stackleak_final,
78523 + .sub = NULL,
78524 + .next = NULL,
78525 + .static_pass_number = 0,
78526 + .tv_id = TV_NONE,
78527 + .properties_required = 0,
78528 + .properties_provided = 0,
78529 + .properties_destroyed = 0,
78530 + .todo_flags_start = 0,
78531 + .todo_flags_finish = TODO_dump_func
78532 + }
78533 +};
78534 +
78535 +static bool gate_stackleak_track_stack(void)
78536 +{
78537 + return track_frame_size >= 0;
78538 +}
78539 +
78540 +static void stackleak_check_alloca(gimple_stmt_iterator gsi)
78541 +{
78542 + gimple check_alloca;
78543 + tree fndecl, fntype, alloca_size;
78544 +
78545 + // insert call to void pax_check_alloca(unsigned long size)
78546 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
78547 + fndecl = build_fn_decl(check_function, fntype);
78548 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
78549 + alloca_size = gimple_call_arg(gsi_stmt(gsi), 0);
78550 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
78551 + gsi_insert_before(&gsi, check_alloca, GSI_CONTINUE_LINKING);
78552 +}
78553 +
78554 +static void stackleak_add_instrumentation(gimple_stmt_iterator gsi)
78555 +{
78556 + gimple track_stack;
78557 + tree fndecl, fntype;
78558 +
78559 + // insert call to void pax_track_stack(void)
78560 + fntype = build_function_type_list(void_type_node, NULL_TREE);
78561 + fndecl = build_fn_decl(track_function, fntype);
78562 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
78563 + track_stack = gimple_build_call(fndecl, 0);
78564 + gsi_insert_after(&gsi, track_stack, GSI_CONTINUE_LINKING);
78565 +}
78566 +
78567 +#if BUILDING_GCC_VERSION == 4005
78568 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
78569 +{
78570 + tree fndecl;
78571 +
78572 + if (!is_gimple_call(stmt))
78573 + return false;
78574 + fndecl = gimple_call_fndecl(stmt);
78575 + if (!fndecl)
78576 + return false;
78577 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
78578 + return false;
78579 +// print_node(stderr, "pax", fndecl, 4);
78580 + return DECL_FUNCTION_CODE(fndecl) == code;
78581 +}
78582 +#endif
78583 +
78584 +static bool is_alloca(gimple stmt)
78585 +{
78586 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
78587 + return true;
78588 +
78589 +#if BUILDING_GCC_VERSION >= 4007
78590 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
78591 + return true;
78592 +#endif
78593 +
78594 + return false;
78595 +}
78596 +
78597 +static unsigned int execute_stackleak_tree_instrument(void)
78598 +{
78599 + basic_block bb, entry_bb;
78600 + bool prologue_instrumented = false;
78601 +
78602 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
78603 +
78604 + // 1. loop through BBs and GIMPLE statements
78605 + FOR_EACH_BB(bb) {
78606 + gimple_stmt_iterator gsi;
78607 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78608 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
78609 + if (!is_alloca(gsi_stmt(gsi)))
78610 + continue;
78611 +
78612 + // 2. insert stack overflow check before each __builtin_alloca call
78613 + stackleak_check_alloca(gsi);
78614 +
78615 + // 3. insert track call after each __builtin_alloca call
78616 + stackleak_add_instrumentation(gsi);
78617 + if (bb == entry_bb)
78618 + prologue_instrumented = true;
78619 + }
78620 + }
78621 +
78622 + // 4. insert track call at the beginning
78623 + if (!prologue_instrumented) {
78624 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
78625 + if (dom_info_available_p(CDI_DOMINATORS))
78626 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
78627 + stackleak_add_instrumentation(gsi_start_bb(bb));
78628 + }
78629 +
78630 + return 0;
78631 +}
78632 +
78633 +static unsigned int execute_stackleak_final(void)
78634 +{
78635 + rtx insn;
78636 +
78637 + if (cfun->calls_alloca)
78638 + return 0;
78639 +
78640 + // keep calls only if function frame is big enough
78641 + if (get_frame_size() >= track_frame_size)
78642 + return 0;
78643 +
78644 + // 1. find pax_track_stack calls
78645 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
78646 + // rtl match: (call_insn 8 7 9 3 (call (mem (symbol_ref ("pax_track_stack") [flags 0x41] <function_decl 0xb7470e80 pax_track_stack>) [0 S1 A8]) (4)) -1 (nil) (nil))
78647 + rtx body;
78648 +
78649 + if (!CALL_P(insn))
78650 + continue;
78651 + body = PATTERN(insn);
78652 + if (GET_CODE(body) != CALL)
78653 + continue;
78654 + body = XEXP(body, 0);
78655 + if (GET_CODE(body) != MEM)
78656 + continue;
78657 + body = XEXP(body, 0);
78658 + if (GET_CODE(body) != SYMBOL_REF)
78659 + continue;
78660 + if (strcmp(XSTR(body, 0), track_function))
78661 + continue;
78662 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
78663 + // 2. delete call
78664 + insn = delete_insn_and_edges(insn);
78665 +#if BUILDING_GCC_VERSION >= 4007
78666 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
78667 + insn = delete_insn_and_edges(insn);
78668 +#endif
78669 + }
78670 +
78671 +// print_simple_rtl(stderr, get_insns());
78672 +// print_rtl(stderr, get_insns());
78673 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
78674 +
78675 + return 0;
78676 +}
78677 +
78678 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78679 +{
78680 + const char * const plugin_name = plugin_info->base_name;
78681 + const int argc = plugin_info->argc;
78682 + const struct plugin_argument * const argv = plugin_info->argv;
78683 + int i;
78684 + struct register_pass_info stackleak_tree_instrument_pass_info = {
78685 + .pass = &stackleak_tree_instrument_pass.pass,
78686 +// .reference_pass_name = "tree_profile",
78687 + .reference_pass_name = "optimized",
78688 + .ref_pass_instance_number = 0,
78689 + .pos_op = PASS_POS_INSERT_AFTER
78690 + };
78691 + struct register_pass_info stackleak_final_pass_info = {
78692 + .pass = &stackleak_final_rtl_opt_pass.pass,
78693 + .reference_pass_name = "final",
78694 + .ref_pass_instance_number = 0,
78695 + .pos_op = PASS_POS_INSERT_BEFORE
78696 + };
78697 +
78698 + if (!plugin_default_version_check(version, &gcc_version)) {
78699 + error(G_("incompatible gcc/plugin versions"));
78700 + return 1;
78701 + }
78702 +
78703 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
78704 +
78705 + for (i = 0; i < argc; ++i) {
78706 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
78707 + if (!argv[i].value) {
78708 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78709 + continue;
78710 + }
78711 + track_frame_size = atoi(argv[i].value);
78712 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
78713 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
78714 + continue;
78715 + }
78716 + if (!strcmp(argv[i].key, "initialize-locals")) {
78717 + if (argv[i].value) {
78718 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
78719 + continue;
78720 + }
78721 + init_locals = true;
78722 + continue;
78723 + }
78724 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78725 + }
78726 +
78727 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
78728 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
78729 +
78730 + return 0;
78731 +}
78732 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
78733 index 6789d78..4afd019 100644
78734 --- a/tools/perf/util/include/asm/alternative-asm.h
78735 +++ b/tools/perf/util/include/asm/alternative-asm.h
78736 @@ -5,4 +5,7 @@
78737
78738 #define altinstruction_entry #
78739
78740 + .macro pax_force_retaddr rip=0, reload=0
78741 + .endm
78742 +
78743 #endif
78744 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
78745 index af0f22f..9a7d479 100644
78746 --- a/usr/gen_init_cpio.c
78747 +++ b/usr/gen_init_cpio.c
78748 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
78749 int retval;
78750 int rc = -1;
78751 int namesize;
78752 - int i;
78753 + unsigned int i;
78754
78755 mode |= S_IFREG;
78756
78757 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
78758 *env_var = *expanded = '\0';
78759 strncat(env_var, start + 2, end - start - 2);
78760 strncat(expanded, new_location, start - new_location);
78761 - strncat(expanded, getenv(env_var), PATH_MAX);
78762 - strncat(expanded, end + 1, PATH_MAX);
78763 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
78764 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
78765 strncpy(new_location, expanded, PATH_MAX);
78766 + new_location[PATH_MAX] = 0;
78767 } else
78768 break;
78769 }
78770 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
78771 index d9cfb78..4f27c10 100644
78772 --- a/virt/kvm/kvm_main.c
78773 +++ b/virt/kvm/kvm_main.c
78774 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
78775
78776 static cpumask_var_t cpus_hardware_enabled;
78777 static int kvm_usage_count = 0;
78778 -static atomic_t hardware_enable_failed;
78779 +static atomic_unchecked_t hardware_enable_failed;
78780
78781 struct kmem_cache *kvm_vcpu_cache;
78782 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
78783 @@ -2268,7 +2268,7 @@ static void hardware_enable_nolock(void *junk)
78784
78785 if (r) {
78786 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
78787 - atomic_inc(&hardware_enable_failed);
78788 + atomic_inc_unchecked(&hardware_enable_failed);
78789 printk(KERN_INFO "kvm: enabling virtualization on "
78790 "CPU%d failed\n", cpu);
78791 }
78792 @@ -2322,10 +2322,10 @@ static int hardware_enable_all(void)
78793
78794 kvm_usage_count++;
78795 if (kvm_usage_count == 1) {
78796 - atomic_set(&hardware_enable_failed, 0);
78797 + atomic_set_unchecked(&hardware_enable_failed, 0);
78798 on_each_cpu(hardware_enable_nolock, NULL, 1);
78799
78800 - if (atomic_read(&hardware_enable_failed)) {
78801 + if (atomic_read_unchecked(&hardware_enable_failed)) {
78802 hardware_disable_all_nolock();
78803 r = -EBUSY;
78804 }
78805 @@ -2676,7 +2676,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
78806 kvm_arch_vcpu_put(vcpu);
78807 }
78808
78809 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78810 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78811 struct module *module)
78812 {
78813 int r;
78814 @@ -2739,7 +2739,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78815 if (!vcpu_align)
78816 vcpu_align = __alignof__(struct kvm_vcpu);
78817 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
78818 - 0, NULL);
78819 + SLAB_USERCOPY, NULL);
78820 if (!kvm_vcpu_cache) {
78821 r = -ENOMEM;
78822 goto out_free_3;
78823 @@ -2749,9 +2749,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78824 if (r)
78825 goto out_free;
78826
78827 - kvm_chardev_ops.owner = module;
78828 - kvm_vm_fops.owner = module;
78829 - kvm_vcpu_fops.owner = module;
78830 + pax_open_kernel();
78831 + *(void **)&kvm_chardev_ops.owner = module;
78832 + *(void **)&kvm_vm_fops.owner = module;
78833 + *(void **)&kvm_vcpu_fops.owner = module;
78834 + pax_close_kernel();
78835
78836 r = misc_register(&kvm_dev);
78837 if (r) {