]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.2.2-3.2.5-201202121700.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-3.2.5-201202121700.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 e9dd0ff..e4c0733 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..0b22b53 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..0882b0a 100644
12227 --- a/arch/x86/kernel/cpu/mcheck/p5.c
12228 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
12229 @@ -12,6 +12,7 @@
12230 #include <asm/system.h>
12231 #include <asm/mce.h>
12232 #include <asm/msr.h>
12233 +#include <asm/pgtable.h>
12234
12235 /* By default disabled */
12236 int mce_p5_enabled __read_mostly;
12237 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
12238 if (!cpu_has(c, X86_FEATURE_MCE))
12239 return;
12240
12241 + pax_open_kernel();
12242 machine_check_vector = pentium_machine_check;
12243 + pax_close_kernel();
12244 /* Make sure the vector pointer is visible before we enable MCEs: */
12245 wmb();
12246
12247 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
12248 index 54060f5..c1a7577 100644
12249 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
12250 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
12251 @@ -11,6 +11,7 @@
12252 #include <asm/system.h>
12253 #include <asm/mce.h>
12254 #include <asm/msr.h>
12255 +#include <asm/pgtable.h>
12256
12257 /* Machine check handler for WinChip C6: */
12258 static void winchip_machine_check(struct pt_regs *regs, long error_code)
12259 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
12260 {
12261 u32 lo, hi;
12262
12263 + pax_open_kernel();
12264 machine_check_vector = winchip_machine_check;
12265 + pax_close_kernel();
12266 /* Make sure the vector pointer is visible before we enable MCEs: */
12267 wmb();
12268
12269 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
12270 index 6b96110..0da73eb 100644
12271 --- a/arch/x86/kernel/cpu/mtrr/main.c
12272 +++ b/arch/x86/kernel/cpu/mtrr/main.c
12273 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
12274 u64 size_or_mask, size_and_mask;
12275 static bool mtrr_aps_delayed_init;
12276
12277 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
12278 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
12279
12280 const struct mtrr_ops *mtrr_if;
12281
12282 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
12283 index df5e41f..816c719 100644
12284 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
12285 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
12286 @@ -25,7 +25,7 @@ struct mtrr_ops {
12287 int (*validate_add_page)(unsigned long base, unsigned long size,
12288 unsigned int type);
12289 int (*have_wrcomb)(void);
12290 -};
12291 +} __do_const;
12292
12293 extern int generic_get_free_region(unsigned long base, unsigned long size,
12294 int replace_reg);
12295 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
12296 index 2bda212..78cc605 100644
12297 --- a/arch/x86/kernel/cpu/perf_event.c
12298 +++ b/arch/x86/kernel/cpu/perf_event.c
12299 @@ -1529,7 +1529,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
12300 break;
12301
12302 perf_callchain_store(entry, frame.return_address);
12303 - fp = frame.next_frame;
12304 + fp = (const void __force_user *)frame.next_frame;
12305 }
12306 }
12307
12308 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
12309 index 13ad899..f642b9a 100644
12310 --- a/arch/x86/kernel/crash.c
12311 +++ b/arch/x86/kernel/crash.c
12312 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
12313 {
12314 #ifdef CONFIG_X86_32
12315 struct pt_regs fixed_regs;
12316 -#endif
12317
12318 -#ifdef CONFIG_X86_32
12319 - if (!user_mode_vm(regs)) {
12320 + if (!user_mode(regs)) {
12321 crash_fixup_ss_esp(&fixed_regs, regs);
12322 regs = &fixed_regs;
12323 }
12324 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
12325 index 37250fe..bf2ec74 100644
12326 --- a/arch/x86/kernel/doublefault_32.c
12327 +++ b/arch/x86/kernel/doublefault_32.c
12328 @@ -11,7 +11,7 @@
12329
12330 #define DOUBLEFAULT_STACKSIZE (1024)
12331 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
12332 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
12333 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
12334
12335 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
12336
12337 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
12338 unsigned long gdt, tss;
12339
12340 store_gdt(&gdt_desc);
12341 - gdt = gdt_desc.address;
12342 + gdt = (unsigned long)gdt_desc.address;
12343
12344 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
12345
12346 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
12347 /* 0x2 bit is always set */
12348 .flags = X86_EFLAGS_SF | 0x2,
12349 .sp = STACK_START,
12350 - .es = __USER_DS,
12351 + .es = __KERNEL_DS,
12352 .cs = __KERNEL_CS,
12353 .ss = __KERNEL_DS,
12354 - .ds = __USER_DS,
12355 + .ds = __KERNEL_DS,
12356 .fs = __KERNEL_PERCPU,
12357
12358 .__cr3 = __pa_nodebug(swapper_pg_dir),
12359 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
12360 index 1aae78f..aab3a3d 100644
12361 --- a/arch/x86/kernel/dumpstack.c
12362 +++ b/arch/x86/kernel/dumpstack.c
12363 @@ -2,6 +2,9 @@
12364 * Copyright (C) 1991, 1992 Linus Torvalds
12365 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
12366 */
12367 +#ifdef CONFIG_GRKERNSEC_HIDESYM
12368 +#define __INCLUDED_BY_HIDESYM 1
12369 +#endif
12370 #include <linux/kallsyms.h>
12371 #include <linux/kprobes.h>
12372 #include <linux/uaccess.h>
12373 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
12374 static void
12375 print_ftrace_graph_addr(unsigned long addr, void *data,
12376 const struct stacktrace_ops *ops,
12377 - struct thread_info *tinfo, int *graph)
12378 + struct task_struct *task, int *graph)
12379 {
12380 - struct task_struct *task = tinfo->task;
12381 unsigned long ret_addr;
12382 int index = task->curr_ret_stack;
12383
12384 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
12385 static inline void
12386 print_ftrace_graph_addr(unsigned long addr, void *data,
12387 const struct stacktrace_ops *ops,
12388 - struct thread_info *tinfo, int *graph)
12389 + struct task_struct *task, int *graph)
12390 { }
12391 #endif
12392
12393 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
12394 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
12395 */
12396
12397 -static inline int valid_stack_ptr(struct thread_info *tinfo,
12398 - void *p, unsigned int size, void *end)
12399 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
12400 {
12401 - void *t = tinfo;
12402 if (end) {
12403 if (p < end && p >= (end-THREAD_SIZE))
12404 return 1;
12405 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
12406 }
12407
12408 unsigned long
12409 -print_context_stack(struct thread_info *tinfo,
12410 +print_context_stack(struct task_struct *task, void *stack_start,
12411 unsigned long *stack, unsigned long bp,
12412 const struct stacktrace_ops *ops, void *data,
12413 unsigned long *end, int *graph)
12414 {
12415 struct stack_frame *frame = (struct stack_frame *)bp;
12416
12417 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
12418 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
12419 unsigned long addr;
12420
12421 addr = *stack;
12422 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
12423 } else {
12424 ops->address(data, addr, 0);
12425 }
12426 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12427 + print_ftrace_graph_addr(addr, data, ops, task, graph);
12428 }
12429 stack++;
12430 }
12431 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
12432 EXPORT_SYMBOL_GPL(print_context_stack);
12433
12434 unsigned long
12435 -print_context_stack_bp(struct thread_info *tinfo,
12436 +print_context_stack_bp(struct task_struct *task, void *stack_start,
12437 unsigned long *stack, unsigned long bp,
12438 const struct stacktrace_ops *ops, void *data,
12439 unsigned long *end, int *graph)
12440 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
12441 struct stack_frame *frame = (struct stack_frame *)bp;
12442 unsigned long *ret_addr = &frame->return_address;
12443
12444 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
12445 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
12446 unsigned long addr = *ret_addr;
12447
12448 if (!__kernel_text_address(addr))
12449 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
12450 ops->address(data, addr, 1);
12451 frame = frame->next_frame;
12452 ret_addr = &frame->return_address;
12453 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12454 + print_ftrace_graph_addr(addr, data, ops, task, graph);
12455 }
12456
12457 return (unsigned long)frame;
12458 @@ -186,7 +186,7 @@ void dump_stack(void)
12459
12460 bp = stack_frame(current, NULL);
12461 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
12462 - current->pid, current->comm, print_tainted(),
12463 + task_pid_nr(current), current->comm, print_tainted(),
12464 init_utsname()->release,
12465 (int)strcspn(init_utsname()->version, " "),
12466 init_utsname()->version);
12467 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
12468 }
12469 EXPORT_SYMBOL_GPL(oops_begin);
12470
12471 +extern void gr_handle_kernel_exploit(void);
12472 +
12473 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12474 {
12475 if (regs && kexec_should_crash(current))
12476 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12477 panic("Fatal exception in interrupt");
12478 if (panic_on_oops)
12479 panic("Fatal exception");
12480 - do_exit(signr);
12481 +
12482 + gr_handle_kernel_exploit();
12483 +
12484 + do_group_exit(signr);
12485 }
12486
12487 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12488 @@ -269,7 +274,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12489
12490 show_registers(regs);
12491 #ifdef CONFIG_X86_32
12492 - if (user_mode_vm(regs)) {
12493 + if (user_mode(regs)) {
12494 sp = regs->sp;
12495 ss = regs->ss & 0xffff;
12496 } else {
12497 @@ -297,7 +302,7 @@ void die(const char *str, struct pt_regs *regs, long err)
12498 unsigned long flags = oops_begin();
12499 int sig = SIGSEGV;
12500
12501 - if (!user_mode_vm(regs))
12502 + if (!user_mode(regs))
12503 report_bug(regs->ip, regs);
12504
12505 if (__die(str, regs, err))
12506 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
12507 index c99f9ed..2a15d80 100644
12508 --- a/arch/x86/kernel/dumpstack_32.c
12509 +++ b/arch/x86/kernel/dumpstack_32.c
12510 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12511 bp = stack_frame(task, regs);
12512
12513 for (;;) {
12514 - struct thread_info *context;
12515 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12516
12517 - context = (struct thread_info *)
12518 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
12519 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
12520 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12521
12522 - stack = (unsigned long *)context->previous_esp;
12523 - if (!stack)
12524 + if (stack_start == task_stack_page(task))
12525 break;
12526 + stack = *(unsigned long **)stack_start;
12527 if (ops->stack(data, "IRQ") < 0)
12528 break;
12529 touch_nmi_watchdog();
12530 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
12531 * When in-kernel, we also print out the stack and code at the
12532 * time of the fault..
12533 */
12534 - if (!user_mode_vm(regs)) {
12535 + if (!user_mode(regs)) {
12536 unsigned int code_prologue = code_bytes * 43 / 64;
12537 unsigned int code_len = code_bytes;
12538 unsigned char c;
12539 u8 *ip;
12540 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
12541
12542 printk(KERN_EMERG "Stack:\n");
12543 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
12544
12545 printk(KERN_EMERG "Code: ");
12546
12547 - ip = (u8 *)regs->ip - code_prologue;
12548 + ip = (u8 *)regs->ip - code_prologue + cs_base;
12549 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
12550 /* try starting at IP */
12551 - ip = (u8 *)regs->ip;
12552 + ip = (u8 *)regs->ip + cs_base;
12553 code_len = code_len - code_prologue + 1;
12554 }
12555 for (i = 0; i < code_len; i++, ip++) {
12556 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
12557 printk(KERN_CONT " Bad EIP value.");
12558 break;
12559 }
12560 - if (ip == (u8 *)regs->ip)
12561 + if (ip == (u8 *)regs->ip + cs_base)
12562 printk(KERN_CONT "<%02x> ", c);
12563 else
12564 printk(KERN_CONT "%02x ", c);
12565 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
12566 {
12567 unsigned short ud2;
12568
12569 + ip = ktla_ktva(ip);
12570 if (ip < PAGE_OFFSET)
12571 return 0;
12572 if (probe_kernel_address((unsigned short *)ip, ud2))
12573 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
12574
12575 return ud2 == 0x0b0f;
12576 }
12577 +
12578 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12579 +void pax_check_alloca(unsigned long size)
12580 +{
12581 + unsigned long sp = (unsigned long)&sp, stack_left;
12582 +
12583 + /* all kernel stacks are of the same size */
12584 + stack_left = sp & (THREAD_SIZE - 1);
12585 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12586 +}
12587 +EXPORT_SYMBOL(pax_check_alloca);
12588 +#endif
12589 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
12590 index 6d728d9..279514e 100644
12591 --- a/arch/x86/kernel/dumpstack_64.c
12592 +++ b/arch/x86/kernel/dumpstack_64.c
12593 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12594 unsigned long *irq_stack_end =
12595 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
12596 unsigned used = 0;
12597 - struct thread_info *tinfo;
12598 int graph = 0;
12599 unsigned long dummy;
12600 + void *stack_start;
12601
12602 if (!task)
12603 task = current;
12604 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12605 * current stack address. If the stacks consist of nested
12606 * exceptions
12607 */
12608 - tinfo = task_thread_info(task);
12609 for (;;) {
12610 char *id;
12611 unsigned long *estack_end;
12612 +
12613 estack_end = in_exception_stack(cpu, (unsigned long)stack,
12614 &used, &id);
12615
12616 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12617 if (ops->stack(data, id) < 0)
12618 break;
12619
12620 - bp = ops->walk_stack(tinfo, stack, bp, ops,
12621 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
12622 data, estack_end, &graph);
12623 ops->stack(data, "<EOE>");
12624 /*
12625 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12626 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
12627 if (ops->stack(data, "IRQ") < 0)
12628 break;
12629 - bp = ops->walk_stack(tinfo, stack, bp,
12630 + bp = ops->walk_stack(task, irq_stack, stack, bp,
12631 ops, data, irq_stack_end, &graph);
12632 /*
12633 * We link to the next stack (which would be
12634 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12635 /*
12636 * This handles the process stack:
12637 */
12638 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
12639 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12640 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12641 put_cpu();
12642 }
12643 EXPORT_SYMBOL(dump_trace);
12644 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
12645
12646 return ud2 == 0x0b0f;
12647 }
12648 +
12649 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12650 +void pax_check_alloca(unsigned long size)
12651 +{
12652 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
12653 + unsigned cpu, used;
12654 + char *id;
12655 +
12656 + /* check the process stack first */
12657 + stack_start = (unsigned long)task_stack_page(current);
12658 + stack_end = stack_start + THREAD_SIZE;
12659 + if (likely(stack_start <= sp && sp < stack_end)) {
12660 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
12661 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12662 + return;
12663 + }
12664 +
12665 + cpu = get_cpu();
12666 +
12667 + /* check the irq stacks */
12668 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
12669 + stack_start = stack_end - IRQ_STACK_SIZE;
12670 + if (stack_start <= sp && sp < stack_end) {
12671 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
12672 + put_cpu();
12673 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12674 + return;
12675 + }
12676 +
12677 + /* check the exception stacks */
12678 + used = 0;
12679 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
12680 + stack_start = stack_end - EXCEPTION_STKSZ;
12681 + if (stack_end && stack_start <= sp && sp < stack_end) {
12682 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
12683 + put_cpu();
12684 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12685 + return;
12686 + }
12687 +
12688 + put_cpu();
12689 +
12690 + /* unknown stack */
12691 + BUG();
12692 +}
12693 +EXPORT_SYMBOL(pax_check_alloca);
12694 +#endif
12695 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
12696 index cd28a35..c72ed9a 100644
12697 --- a/arch/x86/kernel/early_printk.c
12698 +++ b/arch/x86/kernel/early_printk.c
12699 @@ -7,6 +7,7 @@
12700 #include <linux/pci_regs.h>
12701 #include <linux/pci_ids.h>
12702 #include <linux/errno.h>
12703 +#include <linux/sched.h>
12704 #include <asm/io.h>
12705 #include <asm/processor.h>
12706 #include <asm/fcntl.h>
12707 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
12708 index f3f6f53..0841b66 100644
12709 --- a/arch/x86/kernel/entry_32.S
12710 +++ b/arch/x86/kernel/entry_32.S
12711 @@ -186,13 +186,146 @@
12712 /*CFI_REL_OFFSET gs, PT_GS*/
12713 .endm
12714 .macro SET_KERNEL_GS reg
12715 +
12716 +#ifdef CONFIG_CC_STACKPROTECTOR
12717 movl $(__KERNEL_STACK_CANARY), \reg
12718 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
12719 + movl $(__USER_DS), \reg
12720 +#else
12721 + xorl \reg, \reg
12722 +#endif
12723 +
12724 movl \reg, %gs
12725 .endm
12726
12727 #endif /* CONFIG_X86_32_LAZY_GS */
12728
12729 -.macro SAVE_ALL
12730 +.macro pax_enter_kernel
12731 +#ifdef CONFIG_PAX_KERNEXEC
12732 + call pax_enter_kernel
12733 +#endif
12734 +.endm
12735 +
12736 +.macro pax_exit_kernel
12737 +#ifdef CONFIG_PAX_KERNEXEC
12738 + call pax_exit_kernel
12739 +#endif
12740 +.endm
12741 +
12742 +#ifdef CONFIG_PAX_KERNEXEC
12743 +ENTRY(pax_enter_kernel)
12744 +#ifdef CONFIG_PARAVIRT
12745 + pushl %eax
12746 + pushl %ecx
12747 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
12748 + mov %eax, %esi
12749 +#else
12750 + mov %cr0, %esi
12751 +#endif
12752 + bts $16, %esi
12753 + jnc 1f
12754 + mov %cs, %esi
12755 + cmp $__KERNEL_CS, %esi
12756 + jz 3f
12757 + ljmp $__KERNEL_CS, $3f
12758 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
12759 +2:
12760 +#ifdef CONFIG_PARAVIRT
12761 + mov %esi, %eax
12762 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12763 +#else
12764 + mov %esi, %cr0
12765 +#endif
12766 +3:
12767 +#ifdef CONFIG_PARAVIRT
12768 + popl %ecx
12769 + popl %eax
12770 +#endif
12771 + ret
12772 +ENDPROC(pax_enter_kernel)
12773 +
12774 +ENTRY(pax_exit_kernel)
12775 +#ifdef CONFIG_PARAVIRT
12776 + pushl %eax
12777 + pushl %ecx
12778 +#endif
12779 + mov %cs, %esi
12780 + cmp $__KERNEXEC_KERNEL_CS, %esi
12781 + jnz 2f
12782 +#ifdef CONFIG_PARAVIRT
12783 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
12784 + mov %eax, %esi
12785 +#else
12786 + mov %cr0, %esi
12787 +#endif
12788 + btr $16, %esi
12789 + ljmp $__KERNEL_CS, $1f
12790 +1:
12791 +#ifdef CONFIG_PARAVIRT
12792 + mov %esi, %eax
12793 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
12794 +#else
12795 + mov %esi, %cr0
12796 +#endif
12797 +2:
12798 +#ifdef CONFIG_PARAVIRT
12799 + popl %ecx
12800 + popl %eax
12801 +#endif
12802 + ret
12803 +ENDPROC(pax_exit_kernel)
12804 +#endif
12805 +
12806 +.macro pax_erase_kstack
12807 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12808 + call pax_erase_kstack
12809 +#endif
12810 +.endm
12811 +
12812 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12813 +/*
12814 + * ebp: thread_info
12815 + * ecx, edx: can be clobbered
12816 + */
12817 +ENTRY(pax_erase_kstack)
12818 + pushl %edi
12819 + pushl %eax
12820 +
12821 + mov TI_lowest_stack(%ebp), %edi
12822 + mov $-0xBEEF, %eax
12823 + std
12824 +
12825 +1: mov %edi, %ecx
12826 + and $THREAD_SIZE_asm - 1, %ecx
12827 + shr $2, %ecx
12828 + repne scasl
12829 + jecxz 2f
12830 +
12831 + cmp $2*16, %ecx
12832 + jc 2f
12833 +
12834 + mov $2*16, %ecx
12835 + repe scasl
12836 + jecxz 2f
12837 + jne 1b
12838 +
12839 +2: cld
12840 + mov %esp, %ecx
12841 + sub %edi, %ecx
12842 + shr $2, %ecx
12843 + rep stosl
12844 +
12845 + mov TI_task_thread_sp0(%ebp), %edi
12846 + sub $128, %edi
12847 + mov %edi, TI_lowest_stack(%ebp)
12848 +
12849 + popl %eax
12850 + popl %edi
12851 + ret
12852 +ENDPROC(pax_erase_kstack)
12853 +#endif
12854 +
12855 +.macro __SAVE_ALL _DS
12856 cld
12857 PUSH_GS
12858 pushl_cfi %fs
12859 @@ -215,7 +348,7 @@
12860 CFI_REL_OFFSET ecx, 0
12861 pushl_cfi %ebx
12862 CFI_REL_OFFSET ebx, 0
12863 - movl $(__USER_DS), %edx
12864 + movl $\_DS, %edx
12865 movl %edx, %ds
12866 movl %edx, %es
12867 movl $(__KERNEL_PERCPU), %edx
12868 @@ -223,6 +356,15 @@
12869 SET_KERNEL_GS %edx
12870 .endm
12871
12872 +.macro SAVE_ALL
12873 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
12874 + __SAVE_ALL __KERNEL_DS
12875 + pax_enter_kernel
12876 +#else
12877 + __SAVE_ALL __USER_DS
12878 +#endif
12879 +.endm
12880 +
12881 .macro RESTORE_INT_REGS
12882 popl_cfi %ebx
12883 CFI_RESTORE ebx
12884 @@ -308,7 +450,7 @@ ENTRY(ret_from_fork)
12885 popfl_cfi
12886 jmp syscall_exit
12887 CFI_ENDPROC
12888 -END(ret_from_fork)
12889 +ENDPROC(ret_from_fork)
12890
12891 /*
12892 * Interrupt exit functions should be protected against kprobes
12893 @@ -333,7 +475,15 @@ check_userspace:
12894 movb PT_CS(%esp), %al
12895 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
12896 cmpl $USER_RPL, %eax
12897 +
12898 +#ifdef CONFIG_PAX_KERNEXEC
12899 + jae resume_userspace
12900 +
12901 + PAX_EXIT_KERNEL
12902 + jmp resume_kernel
12903 +#else
12904 jb resume_kernel # not returning to v8086 or userspace
12905 +#endif
12906
12907 ENTRY(resume_userspace)
12908 LOCKDEP_SYS_EXIT
12909 @@ -345,8 +495,8 @@ ENTRY(resume_userspace)
12910 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
12911 # int/exception return?
12912 jne work_pending
12913 - jmp restore_all
12914 -END(ret_from_exception)
12915 + jmp restore_all_pax
12916 +ENDPROC(ret_from_exception)
12917
12918 #ifdef CONFIG_PREEMPT
12919 ENTRY(resume_kernel)
12920 @@ -361,7 +511,7 @@ need_resched:
12921 jz restore_all
12922 call preempt_schedule_irq
12923 jmp need_resched
12924 -END(resume_kernel)
12925 +ENDPROC(resume_kernel)
12926 #endif
12927 CFI_ENDPROC
12928 /*
12929 @@ -395,23 +545,34 @@ sysenter_past_esp:
12930 /*CFI_REL_OFFSET cs, 0*/
12931 /*
12932 * Push current_thread_info()->sysenter_return to the stack.
12933 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
12934 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
12935 */
12936 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
12937 + pushl_cfi $0
12938 CFI_REL_OFFSET eip, 0
12939
12940 pushl_cfi %eax
12941 SAVE_ALL
12942 + GET_THREAD_INFO(%ebp)
12943 + movl TI_sysenter_return(%ebp),%ebp
12944 + movl %ebp,PT_EIP(%esp)
12945 ENABLE_INTERRUPTS(CLBR_NONE)
12946
12947 /*
12948 * Load the potential sixth argument from user stack.
12949 * Careful about security.
12950 */
12951 + movl PT_OLDESP(%esp),%ebp
12952 +
12953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12954 + mov PT_OLDSS(%esp),%ds
12955 +1: movl %ds:(%ebp),%ebp
12956 + push %ss
12957 + pop %ds
12958 +#else
12959 cmpl $__PAGE_OFFSET-3,%ebp
12960 jae syscall_fault
12961 1: movl (%ebp),%ebp
12962 +#endif
12963 +
12964 movl %ebp,PT_EBP(%esp)
12965 .section __ex_table,"a"
12966 .align 4
12967 @@ -434,12 +595,24 @@ sysenter_do_call:
12968 testl $_TIF_ALLWORK_MASK, %ecx
12969 jne sysexit_audit
12970 sysenter_exit:
12971 +
12972 +#ifdef CONFIG_PAX_RANDKSTACK
12973 + pushl_cfi %eax
12974 + movl %esp, %eax
12975 + call pax_randomize_kstack
12976 + popl_cfi %eax
12977 +#endif
12978 +
12979 + pax_erase_kstack
12980 +
12981 /* if something modifies registers it must also disable sysexit */
12982 movl PT_EIP(%esp), %edx
12983 movl PT_OLDESP(%esp), %ecx
12984 xorl %ebp,%ebp
12985 TRACE_IRQS_ON
12986 1: mov PT_FS(%esp), %fs
12987 +2: mov PT_DS(%esp), %ds
12988 +3: mov PT_ES(%esp), %es
12989 PTGS_TO_GS
12990 ENABLE_INTERRUPTS_SYSEXIT
12991
12992 @@ -456,6 +629,9 @@ sysenter_audit:
12993 movl %eax,%edx /* 2nd arg: syscall number */
12994 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
12995 call audit_syscall_entry
12996 +
12997 + pax_erase_kstack
12998 +
12999 pushl_cfi %ebx
13000 movl PT_EAX(%esp),%eax /* reload syscall number */
13001 jmp sysenter_do_call
13002 @@ -482,11 +658,17 @@ sysexit_audit:
13003
13004 CFI_ENDPROC
13005 .pushsection .fixup,"ax"
13006 -2: movl $0,PT_FS(%esp)
13007 +4: movl $0,PT_FS(%esp)
13008 + jmp 1b
13009 +5: movl $0,PT_DS(%esp)
13010 + jmp 1b
13011 +6: movl $0,PT_ES(%esp)
13012 jmp 1b
13013 .section __ex_table,"a"
13014 .align 4
13015 - .long 1b,2b
13016 + .long 1b,4b
13017 + .long 2b,5b
13018 + .long 3b,6b
13019 .popsection
13020 PTGS_TO_GS_EX
13021 ENDPROC(ia32_sysenter_target)
13022 @@ -519,6 +701,15 @@ syscall_exit:
13023 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13024 jne syscall_exit_work
13025
13026 +restore_all_pax:
13027 +
13028 +#ifdef CONFIG_PAX_RANDKSTACK
13029 + movl %esp, %eax
13030 + call pax_randomize_kstack
13031 +#endif
13032 +
13033 + pax_erase_kstack
13034 +
13035 restore_all:
13036 TRACE_IRQS_IRET
13037 restore_all_notrace:
13038 @@ -578,14 +769,34 @@ ldt_ss:
13039 * compensating for the offset by changing to the ESPFIX segment with
13040 * a base address that matches for the difference.
13041 */
13042 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
13043 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
13044 mov %esp, %edx /* load kernel esp */
13045 mov PT_OLDESP(%esp), %eax /* load userspace esp */
13046 mov %dx, %ax /* eax: new kernel esp */
13047 sub %eax, %edx /* offset (low word is 0) */
13048 +#ifdef CONFIG_SMP
13049 + movl PER_CPU_VAR(cpu_number), %ebx
13050 + shll $PAGE_SHIFT_asm, %ebx
13051 + addl $cpu_gdt_table, %ebx
13052 +#else
13053 + movl $cpu_gdt_table, %ebx
13054 +#endif
13055 shr $16, %edx
13056 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
13057 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
13058 +
13059 +#ifdef CONFIG_PAX_KERNEXEC
13060 + mov %cr0, %esi
13061 + btr $16, %esi
13062 + mov %esi, %cr0
13063 +#endif
13064 +
13065 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
13066 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
13067 +
13068 +#ifdef CONFIG_PAX_KERNEXEC
13069 + bts $16, %esi
13070 + mov %esi, %cr0
13071 +#endif
13072 +
13073 pushl_cfi $__ESPFIX_SS
13074 pushl_cfi %eax /* new kernel esp */
13075 /* Disable interrupts, but do not irqtrace this section: we
13076 @@ -614,34 +825,28 @@ work_resched:
13077 movl TI_flags(%ebp), %ecx
13078 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
13079 # than syscall tracing?
13080 - jz restore_all
13081 + jz restore_all_pax
13082 testb $_TIF_NEED_RESCHED, %cl
13083 jnz work_resched
13084
13085 work_notifysig: # deal with pending signals and
13086 # notify-resume requests
13087 + movl %esp, %eax
13088 #ifdef CONFIG_VM86
13089 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
13090 - movl %esp, %eax
13091 - jne work_notifysig_v86 # returning to kernel-space or
13092 + jz 1f # returning to kernel-space or
13093 # vm86-space
13094 - xorl %edx, %edx
13095 - call do_notify_resume
13096 - jmp resume_userspace_sig
13097
13098 - ALIGN
13099 -work_notifysig_v86:
13100 pushl_cfi %ecx # save ti_flags for do_notify_resume
13101 call save_v86_state # %eax contains pt_regs pointer
13102 popl_cfi %ecx
13103 movl %eax, %esp
13104 -#else
13105 - movl %esp, %eax
13106 +1:
13107 #endif
13108 xorl %edx, %edx
13109 call do_notify_resume
13110 jmp resume_userspace_sig
13111 -END(work_pending)
13112 +ENDPROC(work_pending)
13113
13114 # perform syscall exit tracing
13115 ALIGN
13116 @@ -649,11 +854,14 @@ syscall_trace_entry:
13117 movl $-ENOSYS,PT_EAX(%esp)
13118 movl %esp, %eax
13119 call syscall_trace_enter
13120 +
13121 + pax_erase_kstack
13122 +
13123 /* What it returned is what we'll actually use. */
13124 cmpl $(nr_syscalls), %eax
13125 jnae syscall_call
13126 jmp syscall_exit
13127 -END(syscall_trace_entry)
13128 +ENDPROC(syscall_trace_entry)
13129
13130 # perform syscall exit tracing
13131 ALIGN
13132 @@ -666,20 +874,24 @@ syscall_exit_work:
13133 movl %esp, %eax
13134 call syscall_trace_leave
13135 jmp resume_userspace
13136 -END(syscall_exit_work)
13137 +ENDPROC(syscall_exit_work)
13138 CFI_ENDPROC
13139
13140 RING0_INT_FRAME # can't unwind into user space anyway
13141 syscall_fault:
13142 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13143 + push %ss
13144 + pop %ds
13145 +#endif
13146 GET_THREAD_INFO(%ebp)
13147 movl $-EFAULT,PT_EAX(%esp)
13148 jmp resume_userspace
13149 -END(syscall_fault)
13150 +ENDPROC(syscall_fault)
13151
13152 syscall_badsys:
13153 movl $-ENOSYS,PT_EAX(%esp)
13154 jmp resume_userspace
13155 -END(syscall_badsys)
13156 +ENDPROC(syscall_badsys)
13157 CFI_ENDPROC
13158 /*
13159 * End of kprobes section
13160 @@ -753,6 +965,36 @@ ptregs_clone:
13161 CFI_ENDPROC
13162 ENDPROC(ptregs_clone)
13163
13164 + ALIGN;
13165 +ENTRY(kernel_execve)
13166 + CFI_STARTPROC
13167 + pushl_cfi %ebp
13168 + sub $PT_OLDSS+4,%esp
13169 + pushl_cfi %edi
13170 + pushl_cfi %ecx
13171 + pushl_cfi %eax
13172 + lea 3*4(%esp),%edi
13173 + mov $PT_OLDSS/4+1,%ecx
13174 + xorl %eax,%eax
13175 + rep stosl
13176 + popl_cfi %eax
13177 + popl_cfi %ecx
13178 + popl_cfi %edi
13179 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
13180 + pushl_cfi %esp
13181 + call sys_execve
13182 + add $4,%esp
13183 + CFI_ADJUST_CFA_OFFSET -4
13184 + GET_THREAD_INFO(%ebp)
13185 + test %eax,%eax
13186 + jz syscall_exit
13187 + add $PT_OLDSS+4,%esp
13188 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
13189 + popl_cfi %ebp
13190 + ret
13191 + CFI_ENDPROC
13192 +ENDPROC(kernel_execve)
13193 +
13194 .macro FIXUP_ESPFIX_STACK
13195 /*
13196 * Switch back for ESPFIX stack to the normal zerobased stack
13197 @@ -762,8 +1004,15 @@ ENDPROC(ptregs_clone)
13198 * normal stack and adjusts ESP with the matching offset.
13199 */
13200 /* fixup the stack */
13201 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
13202 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
13203 +#ifdef CONFIG_SMP
13204 + movl PER_CPU_VAR(cpu_number), %ebx
13205 + shll $PAGE_SHIFT_asm, %ebx
13206 + addl $cpu_gdt_table, %ebx
13207 +#else
13208 + movl $cpu_gdt_table, %ebx
13209 +#endif
13210 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
13211 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
13212 shl $16, %eax
13213 addl %esp, %eax /* the adjusted stack pointer */
13214 pushl_cfi $__KERNEL_DS
13215 @@ -816,7 +1065,7 @@ vector=vector+1
13216 .endr
13217 2: jmp common_interrupt
13218 .endr
13219 -END(irq_entries_start)
13220 +ENDPROC(irq_entries_start)
13221
13222 .previous
13223 END(interrupt)
13224 @@ -864,7 +1113,7 @@ ENTRY(coprocessor_error)
13225 pushl_cfi $do_coprocessor_error
13226 jmp error_code
13227 CFI_ENDPROC
13228 -END(coprocessor_error)
13229 +ENDPROC(coprocessor_error)
13230
13231 ENTRY(simd_coprocessor_error)
13232 RING0_INT_FRAME
13233 @@ -885,7 +1134,7 @@ ENTRY(simd_coprocessor_error)
13234 #endif
13235 jmp error_code
13236 CFI_ENDPROC
13237 -END(simd_coprocessor_error)
13238 +ENDPROC(simd_coprocessor_error)
13239
13240 ENTRY(device_not_available)
13241 RING0_INT_FRAME
13242 @@ -893,7 +1142,7 @@ ENTRY(device_not_available)
13243 pushl_cfi $do_device_not_available
13244 jmp error_code
13245 CFI_ENDPROC
13246 -END(device_not_available)
13247 +ENDPROC(device_not_available)
13248
13249 #ifdef CONFIG_PARAVIRT
13250 ENTRY(native_iret)
13251 @@ -902,12 +1151,12 @@ ENTRY(native_iret)
13252 .align 4
13253 .long native_iret, iret_exc
13254 .previous
13255 -END(native_iret)
13256 +ENDPROC(native_iret)
13257
13258 ENTRY(native_irq_enable_sysexit)
13259 sti
13260 sysexit
13261 -END(native_irq_enable_sysexit)
13262 +ENDPROC(native_irq_enable_sysexit)
13263 #endif
13264
13265 ENTRY(overflow)
13266 @@ -916,7 +1165,7 @@ ENTRY(overflow)
13267 pushl_cfi $do_overflow
13268 jmp error_code
13269 CFI_ENDPROC
13270 -END(overflow)
13271 +ENDPROC(overflow)
13272
13273 ENTRY(bounds)
13274 RING0_INT_FRAME
13275 @@ -924,7 +1173,7 @@ ENTRY(bounds)
13276 pushl_cfi $do_bounds
13277 jmp error_code
13278 CFI_ENDPROC
13279 -END(bounds)
13280 +ENDPROC(bounds)
13281
13282 ENTRY(invalid_op)
13283 RING0_INT_FRAME
13284 @@ -932,7 +1181,7 @@ ENTRY(invalid_op)
13285 pushl_cfi $do_invalid_op
13286 jmp error_code
13287 CFI_ENDPROC
13288 -END(invalid_op)
13289 +ENDPROC(invalid_op)
13290
13291 ENTRY(coprocessor_segment_overrun)
13292 RING0_INT_FRAME
13293 @@ -940,35 +1189,35 @@ ENTRY(coprocessor_segment_overrun)
13294 pushl_cfi $do_coprocessor_segment_overrun
13295 jmp error_code
13296 CFI_ENDPROC
13297 -END(coprocessor_segment_overrun)
13298 +ENDPROC(coprocessor_segment_overrun)
13299
13300 ENTRY(invalid_TSS)
13301 RING0_EC_FRAME
13302 pushl_cfi $do_invalid_TSS
13303 jmp error_code
13304 CFI_ENDPROC
13305 -END(invalid_TSS)
13306 +ENDPROC(invalid_TSS)
13307
13308 ENTRY(segment_not_present)
13309 RING0_EC_FRAME
13310 pushl_cfi $do_segment_not_present
13311 jmp error_code
13312 CFI_ENDPROC
13313 -END(segment_not_present)
13314 +ENDPROC(segment_not_present)
13315
13316 ENTRY(stack_segment)
13317 RING0_EC_FRAME
13318 pushl_cfi $do_stack_segment
13319 jmp error_code
13320 CFI_ENDPROC
13321 -END(stack_segment)
13322 +ENDPROC(stack_segment)
13323
13324 ENTRY(alignment_check)
13325 RING0_EC_FRAME
13326 pushl_cfi $do_alignment_check
13327 jmp error_code
13328 CFI_ENDPROC
13329 -END(alignment_check)
13330 +ENDPROC(alignment_check)
13331
13332 ENTRY(divide_error)
13333 RING0_INT_FRAME
13334 @@ -976,7 +1225,7 @@ ENTRY(divide_error)
13335 pushl_cfi $do_divide_error
13336 jmp error_code
13337 CFI_ENDPROC
13338 -END(divide_error)
13339 +ENDPROC(divide_error)
13340
13341 #ifdef CONFIG_X86_MCE
13342 ENTRY(machine_check)
13343 @@ -985,7 +1234,7 @@ ENTRY(machine_check)
13344 pushl_cfi machine_check_vector
13345 jmp error_code
13346 CFI_ENDPROC
13347 -END(machine_check)
13348 +ENDPROC(machine_check)
13349 #endif
13350
13351 ENTRY(spurious_interrupt_bug)
13352 @@ -994,7 +1243,7 @@ ENTRY(spurious_interrupt_bug)
13353 pushl_cfi $do_spurious_interrupt_bug
13354 jmp error_code
13355 CFI_ENDPROC
13356 -END(spurious_interrupt_bug)
13357 +ENDPROC(spurious_interrupt_bug)
13358 /*
13359 * End of kprobes section
13360 */
13361 @@ -1109,7 +1358,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
13362
13363 ENTRY(mcount)
13364 ret
13365 -END(mcount)
13366 +ENDPROC(mcount)
13367
13368 ENTRY(ftrace_caller)
13369 cmpl $0, function_trace_stop
13370 @@ -1138,7 +1387,7 @@ ftrace_graph_call:
13371 .globl ftrace_stub
13372 ftrace_stub:
13373 ret
13374 -END(ftrace_caller)
13375 +ENDPROC(ftrace_caller)
13376
13377 #else /* ! CONFIG_DYNAMIC_FTRACE */
13378
13379 @@ -1174,7 +1423,7 @@ trace:
13380 popl %ecx
13381 popl %eax
13382 jmp ftrace_stub
13383 -END(mcount)
13384 +ENDPROC(mcount)
13385 #endif /* CONFIG_DYNAMIC_FTRACE */
13386 #endif /* CONFIG_FUNCTION_TRACER */
13387
13388 @@ -1195,7 +1444,7 @@ ENTRY(ftrace_graph_caller)
13389 popl %ecx
13390 popl %eax
13391 ret
13392 -END(ftrace_graph_caller)
13393 +ENDPROC(ftrace_graph_caller)
13394
13395 .globl return_to_handler
13396 return_to_handler:
13397 @@ -1209,7 +1458,6 @@ return_to_handler:
13398 jmp *%ecx
13399 #endif
13400
13401 -.section .rodata,"a"
13402 #include "syscall_table_32.S"
13403
13404 syscall_table_size=(.-sys_call_table)
13405 @@ -1255,15 +1503,18 @@ error_code:
13406 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
13407 REG_TO_PTGS %ecx
13408 SET_KERNEL_GS %ecx
13409 - movl $(__USER_DS), %ecx
13410 + movl $(__KERNEL_DS), %ecx
13411 movl %ecx, %ds
13412 movl %ecx, %es
13413 +
13414 + pax_enter_kernel
13415 +
13416 TRACE_IRQS_OFF
13417 movl %esp,%eax # pt_regs pointer
13418 call *%edi
13419 jmp ret_from_exception
13420 CFI_ENDPROC
13421 -END(page_fault)
13422 +ENDPROC(page_fault)
13423
13424 /*
13425 * Debug traps and NMI can happen at the one SYSENTER instruction
13426 @@ -1305,7 +1556,7 @@ debug_stack_correct:
13427 call do_debug
13428 jmp ret_from_exception
13429 CFI_ENDPROC
13430 -END(debug)
13431 +ENDPROC(debug)
13432
13433 /*
13434 * NMI is doubly nasty. It can happen _while_ we're handling
13435 @@ -1342,6 +1593,9 @@ nmi_stack_correct:
13436 xorl %edx,%edx # zero error code
13437 movl %esp,%eax # pt_regs pointer
13438 call do_nmi
13439 +
13440 + pax_exit_kernel
13441 +
13442 jmp restore_all_notrace
13443 CFI_ENDPROC
13444
13445 @@ -1378,12 +1632,15 @@ nmi_espfix_stack:
13446 FIXUP_ESPFIX_STACK # %eax == %esp
13447 xorl %edx,%edx # zero error code
13448 call do_nmi
13449 +
13450 + pax_exit_kernel
13451 +
13452 RESTORE_REGS
13453 lss 12+4(%esp), %esp # back to espfix stack
13454 CFI_ADJUST_CFA_OFFSET -24
13455 jmp irq_return
13456 CFI_ENDPROC
13457 -END(nmi)
13458 +ENDPROC(nmi)
13459
13460 ENTRY(int3)
13461 RING0_INT_FRAME
13462 @@ -1395,14 +1652,14 @@ ENTRY(int3)
13463 call do_int3
13464 jmp ret_from_exception
13465 CFI_ENDPROC
13466 -END(int3)
13467 +ENDPROC(int3)
13468
13469 ENTRY(general_protection)
13470 RING0_EC_FRAME
13471 pushl_cfi $do_general_protection
13472 jmp error_code
13473 CFI_ENDPROC
13474 -END(general_protection)
13475 +ENDPROC(general_protection)
13476
13477 #ifdef CONFIG_KVM_GUEST
13478 ENTRY(async_page_fault)
13479 @@ -1410,7 +1667,7 @@ ENTRY(async_page_fault)
13480 pushl_cfi $do_async_page_fault
13481 jmp error_code
13482 CFI_ENDPROC
13483 -END(async_page_fault)
13484 +ENDPROC(async_page_fault)
13485 #endif
13486
13487 /*
13488 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
13489 index faf8d5e..4f16a68 100644
13490 --- a/arch/x86/kernel/entry_64.S
13491 +++ b/arch/x86/kernel/entry_64.S
13492 @@ -55,6 +55,8 @@
13493 #include <asm/paravirt.h>
13494 #include <asm/ftrace.h>
13495 #include <asm/percpu.h>
13496 +#include <asm/pgtable.h>
13497 +#include <asm/alternative-asm.h>
13498
13499 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13500 #include <linux/elf-em.h>
13501 @@ -68,8 +70,9 @@
13502 #ifdef CONFIG_FUNCTION_TRACER
13503 #ifdef CONFIG_DYNAMIC_FTRACE
13504 ENTRY(mcount)
13505 + pax_force_retaddr
13506 retq
13507 -END(mcount)
13508 +ENDPROC(mcount)
13509
13510 ENTRY(ftrace_caller)
13511 cmpl $0, function_trace_stop
13512 @@ -92,8 +95,9 @@ GLOBAL(ftrace_graph_call)
13513 #endif
13514
13515 GLOBAL(ftrace_stub)
13516 + pax_force_retaddr
13517 retq
13518 -END(ftrace_caller)
13519 +ENDPROC(ftrace_caller)
13520
13521 #else /* ! CONFIG_DYNAMIC_FTRACE */
13522 ENTRY(mcount)
13523 @@ -112,6 +116,7 @@ ENTRY(mcount)
13524 #endif
13525
13526 GLOBAL(ftrace_stub)
13527 + pax_force_retaddr
13528 retq
13529
13530 trace:
13531 @@ -121,12 +126,13 @@ trace:
13532 movq 8(%rbp), %rsi
13533 subq $MCOUNT_INSN_SIZE, %rdi
13534
13535 + pax_force_fptr ftrace_trace_function
13536 call *ftrace_trace_function
13537
13538 MCOUNT_RESTORE_FRAME
13539
13540 jmp ftrace_stub
13541 -END(mcount)
13542 +ENDPROC(mcount)
13543 #endif /* CONFIG_DYNAMIC_FTRACE */
13544 #endif /* CONFIG_FUNCTION_TRACER */
13545
13546 @@ -146,8 +152,9 @@ ENTRY(ftrace_graph_caller)
13547
13548 MCOUNT_RESTORE_FRAME
13549
13550 + pax_force_retaddr
13551 retq
13552 -END(ftrace_graph_caller)
13553 +ENDPROC(ftrace_graph_caller)
13554
13555 GLOBAL(return_to_handler)
13556 subq $24, %rsp
13557 @@ -163,6 +170,7 @@ GLOBAL(return_to_handler)
13558 movq 8(%rsp), %rdx
13559 movq (%rsp), %rax
13560 addq $24, %rsp
13561 + pax_force_fptr %rdi
13562 jmp *%rdi
13563 #endif
13564
13565 @@ -178,6 +186,282 @@ ENTRY(native_usergs_sysret64)
13566 ENDPROC(native_usergs_sysret64)
13567 #endif /* CONFIG_PARAVIRT */
13568
13569 + .macro ljmpq sel, off
13570 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
13571 + .byte 0x48; ljmp *1234f(%rip)
13572 + .pushsection .rodata
13573 + .align 16
13574 + 1234: .quad \off; .word \sel
13575 + .popsection
13576 +#else
13577 + pushq $\sel
13578 + pushq $\off
13579 + lretq
13580 +#endif
13581 + .endm
13582 +
13583 + .macro pax_enter_kernel
13584 + pax_set_fptr_mask
13585 +#ifdef CONFIG_PAX_KERNEXEC
13586 + call pax_enter_kernel
13587 +#endif
13588 + .endm
13589 +
13590 + .macro pax_exit_kernel
13591 +#ifdef CONFIG_PAX_KERNEXEC
13592 + call pax_exit_kernel
13593 +#endif
13594 + .endm
13595 +
13596 +#ifdef CONFIG_PAX_KERNEXEC
13597 +ENTRY(pax_enter_kernel)
13598 + pushq %rdi
13599 +
13600 +#ifdef CONFIG_PARAVIRT
13601 + PV_SAVE_REGS(CLBR_RDI)
13602 +#endif
13603 +
13604 + GET_CR0_INTO_RDI
13605 + bts $16,%rdi
13606 + jnc 3f
13607 + mov %cs,%edi
13608 + cmp $__KERNEL_CS,%edi
13609 + jnz 2f
13610 +1:
13611 +
13612 +#ifdef CONFIG_PARAVIRT
13613 + PV_RESTORE_REGS(CLBR_RDI)
13614 +#endif
13615 +
13616 + popq %rdi
13617 + pax_force_retaddr
13618 + retq
13619 +
13620 +2: ljmpq __KERNEL_CS,1f
13621 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
13622 +4: SET_RDI_INTO_CR0
13623 + jmp 1b
13624 +ENDPROC(pax_enter_kernel)
13625 +
13626 +ENTRY(pax_exit_kernel)
13627 + pushq %rdi
13628 +
13629 +#ifdef CONFIG_PARAVIRT
13630 + PV_SAVE_REGS(CLBR_RDI)
13631 +#endif
13632 +
13633 + mov %cs,%rdi
13634 + cmp $__KERNEXEC_KERNEL_CS,%edi
13635 + jz 2f
13636 +1:
13637 +
13638 +#ifdef CONFIG_PARAVIRT
13639 + PV_RESTORE_REGS(CLBR_RDI);
13640 +#endif
13641 +
13642 + popq %rdi
13643 + pax_force_retaddr
13644 + retq
13645 +
13646 +2: GET_CR0_INTO_RDI
13647 + btr $16,%rdi
13648 + ljmpq __KERNEL_CS,3f
13649 +3: SET_RDI_INTO_CR0
13650 + jmp 1b
13651 +#ifdef CONFIG_PARAVIRT
13652 + PV_RESTORE_REGS(CLBR_RDI);
13653 +#endif
13654 +
13655 + popq %rdi
13656 + pax_force_retaddr
13657 + retq
13658 +ENDPROC(pax_exit_kernel)
13659 +#endif
13660 +
13661 + .macro pax_enter_kernel_user
13662 + pax_set_fptr_mask
13663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13664 + call pax_enter_kernel_user
13665 +#endif
13666 + .endm
13667 +
13668 + .macro pax_exit_kernel_user
13669 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13670 + call pax_exit_kernel_user
13671 +#endif
13672 +#ifdef CONFIG_PAX_RANDKSTACK
13673 + pushq %rax
13674 + call pax_randomize_kstack
13675 + popq %rax
13676 +#endif
13677 + .endm
13678 +
13679 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13680 +ENTRY(pax_enter_kernel_user)
13681 + pushq %rdi
13682 + pushq %rbx
13683 +
13684 +#ifdef CONFIG_PARAVIRT
13685 + PV_SAVE_REGS(CLBR_RDI)
13686 +#endif
13687 +
13688 + GET_CR3_INTO_RDI
13689 + mov %rdi,%rbx
13690 + add $__START_KERNEL_map,%rbx
13691 + sub phys_base(%rip),%rbx
13692 +
13693 +#ifdef CONFIG_PARAVIRT
13694 + pushq %rdi
13695 + cmpl $0, pv_info+PARAVIRT_enabled
13696 + jz 1f
13697 + i = 0
13698 + .rept USER_PGD_PTRS
13699 + mov i*8(%rbx),%rsi
13700 + mov $0,%sil
13701 + lea i*8(%rbx),%rdi
13702 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
13703 + i = i + 1
13704 + .endr
13705 + jmp 2f
13706 +1:
13707 +#endif
13708 +
13709 + i = 0
13710 + .rept USER_PGD_PTRS
13711 + movb $0,i*8(%rbx)
13712 + i = i + 1
13713 + .endr
13714 +
13715 +#ifdef CONFIG_PARAVIRT
13716 +2: popq %rdi
13717 +#endif
13718 + SET_RDI_INTO_CR3
13719 +
13720 +#ifdef CONFIG_PAX_KERNEXEC
13721 + GET_CR0_INTO_RDI
13722 + bts $16,%rdi
13723 + SET_RDI_INTO_CR0
13724 +#endif
13725 +
13726 +#ifdef CONFIG_PARAVIRT
13727 + PV_RESTORE_REGS(CLBR_RDI)
13728 +#endif
13729 +
13730 + popq %rbx
13731 + popq %rdi
13732 + pax_force_retaddr
13733 + retq
13734 +ENDPROC(pax_enter_kernel_user)
13735 +
13736 +ENTRY(pax_exit_kernel_user)
13737 + push %rdi
13738 +
13739 +#ifdef CONFIG_PARAVIRT
13740 + pushq %rbx
13741 + PV_SAVE_REGS(CLBR_RDI)
13742 +#endif
13743 +
13744 +#ifdef CONFIG_PAX_KERNEXEC
13745 + GET_CR0_INTO_RDI
13746 + btr $16,%rdi
13747 + SET_RDI_INTO_CR0
13748 +#endif
13749 +
13750 + GET_CR3_INTO_RDI
13751 + add $__START_KERNEL_map,%rdi
13752 + sub phys_base(%rip),%rdi
13753 +
13754 +#ifdef CONFIG_PARAVIRT
13755 + cmpl $0, pv_info+PARAVIRT_enabled
13756 + jz 1f
13757 + mov %rdi,%rbx
13758 + i = 0
13759 + .rept USER_PGD_PTRS
13760 + mov i*8(%rbx),%rsi
13761 + mov $0x67,%sil
13762 + lea i*8(%rbx),%rdi
13763 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
13764 + i = i + 1
13765 + .endr
13766 + jmp 2f
13767 +1:
13768 +#endif
13769 +
13770 + i = 0
13771 + .rept USER_PGD_PTRS
13772 + movb $0x67,i*8(%rdi)
13773 + i = i + 1
13774 + .endr
13775 +
13776 +#ifdef CONFIG_PARAVIRT
13777 +2: PV_RESTORE_REGS(CLBR_RDI)
13778 + popq %rbx
13779 +#endif
13780 +
13781 + popq %rdi
13782 + pax_force_retaddr
13783 + retq
13784 +ENDPROC(pax_exit_kernel_user)
13785 +#endif
13786 +
13787 +.macro pax_erase_kstack
13788 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13789 + call pax_erase_kstack
13790 +#endif
13791 +.endm
13792 +
13793 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13794 +/*
13795 + * r11: thread_info
13796 + * rcx, rdx: can be clobbered
13797 + */
13798 +ENTRY(pax_erase_kstack)
13799 + pushq %rdi
13800 + pushq %rax
13801 + pushq %r11
13802 +
13803 + GET_THREAD_INFO(%r11)
13804 + mov TI_lowest_stack(%r11), %rdi
13805 + mov $-0xBEEF, %rax
13806 + std
13807 +
13808 +1: mov %edi, %ecx
13809 + and $THREAD_SIZE_asm - 1, %ecx
13810 + shr $3, %ecx
13811 + repne scasq
13812 + jecxz 2f
13813 +
13814 + cmp $2*8, %ecx
13815 + jc 2f
13816 +
13817 + mov $2*8, %ecx
13818 + repe scasq
13819 + jecxz 2f
13820 + jne 1b
13821 +
13822 +2: cld
13823 + mov %esp, %ecx
13824 + sub %edi, %ecx
13825 +
13826 + cmp $THREAD_SIZE_asm, %rcx
13827 + jb 3f
13828 + ud2
13829 +3:
13830 +
13831 + shr $3, %ecx
13832 + rep stosq
13833 +
13834 + mov TI_task_thread_sp0(%r11), %rdi
13835 + sub $256, %rdi
13836 + mov %rdi, TI_lowest_stack(%r11)
13837 +
13838 + popq %r11
13839 + popq %rax
13840 + popq %rdi
13841 + pax_force_retaddr
13842 + ret
13843 +ENDPROC(pax_erase_kstack)
13844 +#endif
13845
13846 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
13847 #ifdef CONFIG_TRACE_IRQFLAGS
13848 @@ -231,8 +515,8 @@ ENDPROC(native_usergs_sysret64)
13849 .endm
13850
13851 .macro UNFAKE_STACK_FRAME
13852 - addq $8*6, %rsp
13853 - CFI_ADJUST_CFA_OFFSET -(6*8)
13854 + addq $8*6 + ARG_SKIP, %rsp
13855 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
13856 .endm
13857
13858 /*
13859 @@ -319,7 +603,7 @@ ENDPROC(native_usergs_sysret64)
13860 movq %rsp, %rsi
13861
13862 leaq -RBP(%rsp),%rdi /* arg1 for handler */
13863 - testl $3, CS(%rdi)
13864 + testb $3, CS(%rdi)
13865 je 1f
13866 SWAPGS
13867 /*
13868 @@ -355,9 +639,10 @@ ENTRY(save_rest)
13869 movq_cfi r15, R15+16
13870 movq %r11, 8(%rsp) /* return address */
13871 FIXUP_TOP_OF_STACK %r11, 16
13872 + pax_force_retaddr
13873 ret
13874 CFI_ENDPROC
13875 -END(save_rest)
13876 +ENDPROC(save_rest)
13877
13878 /* save complete stack frame */
13879 .pushsection .kprobes.text, "ax"
13880 @@ -386,9 +671,10 @@ ENTRY(save_paranoid)
13881 js 1f /* negative -> in kernel */
13882 SWAPGS
13883 xorl %ebx,%ebx
13884 -1: ret
13885 +1: pax_force_retaddr_bts
13886 + ret
13887 CFI_ENDPROC
13888 -END(save_paranoid)
13889 +ENDPROC(save_paranoid)
13890 .popsection
13891
13892 /*
13893 @@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
13894
13895 RESTORE_REST
13896
13897 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13898 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13899 je int_ret_from_sys_call
13900
13901 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
13902 @@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
13903 jmp ret_from_sys_call # go to the SYSRET fastpath
13904
13905 CFI_ENDPROC
13906 -END(ret_from_fork)
13907 +ENDPROC(ret_from_fork)
13908
13909 /*
13910 * System call entry. Up to 6 arguments in registers are supported.
13911 @@ -456,7 +742,7 @@ END(ret_from_fork)
13912 ENTRY(system_call)
13913 CFI_STARTPROC simple
13914 CFI_SIGNAL_FRAME
13915 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13916 + CFI_DEF_CFA rsp,0
13917 CFI_REGISTER rip,rcx
13918 /*CFI_REGISTER rflags,r11*/
13919 SWAPGS_UNSAFE_STACK
13920 @@ -469,12 +755,13 @@ ENTRY(system_call_after_swapgs)
13921
13922 movq %rsp,PER_CPU_VAR(old_rsp)
13923 movq PER_CPU_VAR(kernel_stack),%rsp
13924 + SAVE_ARGS 8*6,0
13925 + pax_enter_kernel_user
13926 /*
13927 * No need to follow this irqs off/on section - it's straight
13928 * and short:
13929 */
13930 ENABLE_INTERRUPTS(CLBR_NONE)
13931 - SAVE_ARGS 8,0
13932 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13933 movq %rcx,RIP-ARGOFFSET(%rsp)
13934 CFI_REL_OFFSET rip,RIP-ARGOFFSET
13935 @@ -484,7 +771,7 @@ ENTRY(system_call_after_swapgs)
13936 system_call_fastpath:
13937 cmpq $__NR_syscall_max,%rax
13938 ja badsys
13939 - movq %r10,%rcx
13940 + movq R10-ARGOFFSET(%rsp),%rcx
13941 call *sys_call_table(,%rax,8) # XXX: rip relative
13942 movq %rax,RAX-ARGOFFSET(%rsp)
13943 /*
13944 @@ -503,6 +790,8 @@ sysret_check:
13945 andl %edi,%edx
13946 jnz sysret_careful
13947 CFI_REMEMBER_STATE
13948 + pax_exit_kernel_user
13949 + pax_erase_kstack
13950 /*
13951 * sysretq will re-enable interrupts:
13952 */
13953 @@ -554,14 +843,18 @@ badsys:
13954 * jump back to the normal fast path.
13955 */
13956 auditsys:
13957 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
13958 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
13959 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
13960 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
13961 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
13962 movq %rax,%rsi /* 2nd arg: syscall number */
13963 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
13964 call audit_syscall_entry
13965 +
13966 + pax_erase_kstack
13967 +
13968 LOAD_ARGS 0 /* reload call-clobbered registers */
13969 + pax_set_fptr_mask
13970 jmp system_call_fastpath
13971
13972 /*
13973 @@ -591,16 +884,20 @@ tracesys:
13974 FIXUP_TOP_OF_STACK %rdi
13975 movq %rsp,%rdi
13976 call syscall_trace_enter
13977 +
13978 + pax_erase_kstack
13979 +
13980 /*
13981 * Reload arg registers from stack in case ptrace changed them.
13982 * We don't reload %rax because syscall_trace_enter() returned
13983 * the value it wants us to use in the table lookup.
13984 */
13985 LOAD_ARGS ARGOFFSET, 1
13986 + pax_set_fptr_mask
13987 RESTORE_REST
13988 cmpq $__NR_syscall_max,%rax
13989 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
13990 - movq %r10,%rcx /* fixup for C */
13991 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
13992 call *sys_call_table(,%rax,8)
13993 movq %rax,RAX-ARGOFFSET(%rsp)
13994 /* Use IRET because user could have changed frame */
13995 @@ -612,7 +909,7 @@ tracesys:
13996 GLOBAL(int_ret_from_sys_call)
13997 DISABLE_INTERRUPTS(CLBR_NONE)
13998 TRACE_IRQS_OFF
13999 - testl $3,CS-ARGOFFSET(%rsp)
14000 + testb $3,CS-ARGOFFSET(%rsp)
14001 je retint_restore_args
14002 movl $_TIF_ALLWORK_MASK,%edi
14003 /* edi: mask to check */
14004 @@ -623,6 +920,7 @@ GLOBAL(int_with_check)
14005 andl %edi,%edx
14006 jnz int_careful
14007 andl $~TS_COMPAT,TI_status(%rcx)
14008 + pax_erase_kstack
14009 jmp retint_swapgs
14010
14011 /* Either reschedule or signal or syscall exit tracking needed. */
14012 @@ -669,7 +967,7 @@ int_restore_rest:
14013 TRACE_IRQS_OFF
14014 jmp int_with_check
14015 CFI_ENDPROC
14016 -END(system_call)
14017 +ENDPROC(system_call)
14018
14019 /*
14020 * Certain special system calls that need to save a complete full stack frame.
14021 @@ -685,7 +983,7 @@ ENTRY(\label)
14022 call \func
14023 jmp ptregscall_common
14024 CFI_ENDPROC
14025 -END(\label)
14026 +ENDPROC(\label)
14027 .endm
14028
14029 PTREGSCALL stub_clone, sys_clone, %r8
14030 @@ -703,9 +1001,10 @@ ENTRY(ptregscall_common)
14031 movq_cfi_restore R12+8, r12
14032 movq_cfi_restore RBP+8, rbp
14033 movq_cfi_restore RBX+8, rbx
14034 + pax_force_retaddr
14035 ret $REST_SKIP /* pop extended registers */
14036 CFI_ENDPROC
14037 -END(ptregscall_common)
14038 +ENDPROC(ptregscall_common)
14039
14040 ENTRY(stub_execve)
14041 CFI_STARTPROC
14042 @@ -720,7 +1019,7 @@ ENTRY(stub_execve)
14043 RESTORE_REST
14044 jmp int_ret_from_sys_call
14045 CFI_ENDPROC
14046 -END(stub_execve)
14047 +ENDPROC(stub_execve)
14048
14049 /*
14050 * sigreturn is special because it needs to restore all registers on return.
14051 @@ -738,7 +1037,7 @@ ENTRY(stub_rt_sigreturn)
14052 RESTORE_REST
14053 jmp int_ret_from_sys_call
14054 CFI_ENDPROC
14055 -END(stub_rt_sigreturn)
14056 +ENDPROC(stub_rt_sigreturn)
14057
14058 /*
14059 * Build the entry stubs and pointer table with some assembler magic.
14060 @@ -773,7 +1072,7 @@ vector=vector+1
14061 2: jmp common_interrupt
14062 .endr
14063 CFI_ENDPROC
14064 -END(irq_entries_start)
14065 +ENDPROC(irq_entries_start)
14066
14067 .previous
14068 END(interrupt)
14069 @@ -793,6 +1092,16 @@ END(interrupt)
14070 subq $ORIG_RAX-RBP, %rsp
14071 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
14072 SAVE_ARGS_IRQ
14073 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14074 + testb $3, CS(%rdi)
14075 + jnz 1f
14076 + pax_enter_kernel
14077 + jmp 2f
14078 +1: pax_enter_kernel_user
14079 +2:
14080 +#else
14081 + pax_enter_kernel
14082 +#endif
14083 call \func
14084 .endm
14085
14086 @@ -824,7 +1133,7 @@ ret_from_intr:
14087
14088 exit_intr:
14089 GET_THREAD_INFO(%rcx)
14090 - testl $3,CS-ARGOFFSET(%rsp)
14091 + testb $3,CS-ARGOFFSET(%rsp)
14092 je retint_kernel
14093
14094 /* Interrupt came from user space */
14095 @@ -846,12 +1155,15 @@ retint_swapgs: /* return to user-space */
14096 * The iretq could re-enable interrupts:
14097 */
14098 DISABLE_INTERRUPTS(CLBR_ANY)
14099 + pax_exit_kernel_user
14100 TRACE_IRQS_IRETQ
14101 SWAPGS
14102 jmp restore_args
14103
14104 retint_restore_args: /* return to kernel space */
14105 DISABLE_INTERRUPTS(CLBR_ANY)
14106 + pax_exit_kernel
14107 + pax_force_retaddr RIP-ARGOFFSET
14108 /*
14109 * The iretq could re-enable interrupts:
14110 */
14111 @@ -940,7 +1252,7 @@ ENTRY(retint_kernel)
14112 #endif
14113
14114 CFI_ENDPROC
14115 -END(common_interrupt)
14116 +ENDPROC(common_interrupt)
14117 /*
14118 * End of kprobes section
14119 */
14120 @@ -956,7 +1268,7 @@ ENTRY(\sym)
14121 interrupt \do_sym
14122 jmp ret_from_intr
14123 CFI_ENDPROC
14124 -END(\sym)
14125 +ENDPROC(\sym)
14126 .endm
14127
14128 #ifdef CONFIG_SMP
14129 @@ -1021,12 +1333,22 @@ ENTRY(\sym)
14130 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14131 call error_entry
14132 DEFAULT_FRAME 0
14133 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14134 + testb $3, CS(%rsp)
14135 + jnz 1f
14136 + pax_enter_kernel
14137 + jmp 2f
14138 +1: pax_enter_kernel_user
14139 +2:
14140 +#else
14141 + pax_enter_kernel
14142 +#endif
14143 movq %rsp,%rdi /* pt_regs pointer */
14144 xorl %esi,%esi /* no error code */
14145 call \do_sym
14146 jmp error_exit /* %ebx: no swapgs flag */
14147 CFI_ENDPROC
14148 -END(\sym)
14149 +ENDPROC(\sym)
14150 .endm
14151
14152 .macro paranoidzeroentry sym do_sym
14153 @@ -1038,15 +1360,25 @@ ENTRY(\sym)
14154 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14155 call save_paranoid
14156 TRACE_IRQS_OFF
14157 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14158 + testb $3, CS(%rsp)
14159 + jnz 1f
14160 + pax_enter_kernel
14161 + jmp 2f
14162 +1: pax_enter_kernel_user
14163 +2:
14164 +#else
14165 + pax_enter_kernel
14166 +#endif
14167 movq %rsp,%rdi /* pt_regs pointer */
14168 xorl %esi,%esi /* no error code */
14169 call \do_sym
14170 jmp paranoid_exit /* %ebx: no swapgs flag */
14171 CFI_ENDPROC
14172 -END(\sym)
14173 +ENDPROC(\sym)
14174 .endm
14175
14176 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
14177 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
14178 .macro paranoidzeroentry_ist sym do_sym ist
14179 ENTRY(\sym)
14180 INTR_FRAME
14181 @@ -1056,14 +1388,30 @@ ENTRY(\sym)
14182 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14183 call save_paranoid
14184 TRACE_IRQS_OFF
14185 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14186 + testb $3, CS(%rsp)
14187 + jnz 1f
14188 + pax_enter_kernel
14189 + jmp 2f
14190 +1: pax_enter_kernel_user
14191 +2:
14192 +#else
14193 + pax_enter_kernel
14194 +#endif
14195 movq %rsp,%rdi /* pt_regs pointer */
14196 xorl %esi,%esi /* no error code */
14197 +#ifdef CONFIG_SMP
14198 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
14199 + lea init_tss(%r12), %r12
14200 +#else
14201 + lea init_tss(%rip), %r12
14202 +#endif
14203 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14204 call \do_sym
14205 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14206 jmp paranoid_exit /* %ebx: no swapgs flag */
14207 CFI_ENDPROC
14208 -END(\sym)
14209 +ENDPROC(\sym)
14210 .endm
14211
14212 .macro errorentry sym do_sym
14213 @@ -1074,13 +1422,23 @@ ENTRY(\sym)
14214 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14215 call error_entry
14216 DEFAULT_FRAME 0
14217 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14218 + testb $3, CS(%rsp)
14219 + jnz 1f
14220 + pax_enter_kernel
14221 + jmp 2f
14222 +1: pax_enter_kernel_user
14223 +2:
14224 +#else
14225 + pax_enter_kernel
14226 +#endif
14227 movq %rsp,%rdi /* pt_regs pointer */
14228 movq ORIG_RAX(%rsp),%rsi /* get error code */
14229 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14230 call \do_sym
14231 jmp error_exit /* %ebx: no swapgs flag */
14232 CFI_ENDPROC
14233 -END(\sym)
14234 +ENDPROC(\sym)
14235 .endm
14236
14237 /* error code is on the stack already */
14238 @@ -1093,13 +1451,23 @@ ENTRY(\sym)
14239 call save_paranoid
14240 DEFAULT_FRAME 0
14241 TRACE_IRQS_OFF
14242 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14243 + testb $3, CS(%rsp)
14244 + jnz 1f
14245 + pax_enter_kernel
14246 + jmp 2f
14247 +1: pax_enter_kernel_user
14248 +2:
14249 +#else
14250 + pax_enter_kernel
14251 +#endif
14252 movq %rsp,%rdi /* pt_regs pointer */
14253 movq ORIG_RAX(%rsp),%rsi /* get error code */
14254 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14255 call \do_sym
14256 jmp paranoid_exit /* %ebx: no swapgs flag */
14257 CFI_ENDPROC
14258 -END(\sym)
14259 +ENDPROC(\sym)
14260 .endm
14261
14262 zeroentry divide_error do_divide_error
14263 @@ -1129,9 +1497,10 @@ gs_change:
14264 2: mfence /* workaround */
14265 SWAPGS
14266 popfq_cfi
14267 + pax_force_retaddr
14268 ret
14269 CFI_ENDPROC
14270 -END(native_load_gs_index)
14271 +ENDPROC(native_load_gs_index)
14272
14273 .section __ex_table,"a"
14274 .align 8
14275 @@ -1153,13 +1522,14 @@ ENTRY(kernel_thread_helper)
14276 * Here we are in the child and the registers are set as they were
14277 * at kernel_thread() invocation in the parent.
14278 */
14279 + pax_force_fptr %rsi
14280 call *%rsi
14281 # exit
14282 mov %eax, %edi
14283 call do_exit
14284 ud2 # padding for call trace
14285 CFI_ENDPROC
14286 -END(kernel_thread_helper)
14287 +ENDPROC(kernel_thread_helper)
14288
14289 /*
14290 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
14291 @@ -1186,11 +1556,11 @@ ENTRY(kernel_execve)
14292 RESTORE_REST
14293 testq %rax,%rax
14294 je int_ret_from_sys_call
14295 - RESTORE_ARGS
14296 UNFAKE_STACK_FRAME
14297 + pax_force_retaddr
14298 ret
14299 CFI_ENDPROC
14300 -END(kernel_execve)
14301 +ENDPROC(kernel_execve)
14302
14303 /* Call softirq on interrupt stack. Interrupts are off. */
14304 ENTRY(call_softirq)
14305 @@ -1208,9 +1578,10 @@ ENTRY(call_softirq)
14306 CFI_DEF_CFA_REGISTER rsp
14307 CFI_ADJUST_CFA_OFFSET -8
14308 decl PER_CPU_VAR(irq_count)
14309 + pax_force_retaddr
14310 ret
14311 CFI_ENDPROC
14312 -END(call_softirq)
14313 +ENDPROC(call_softirq)
14314
14315 #ifdef CONFIG_XEN
14316 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
14317 @@ -1248,7 +1619,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
14318 decl PER_CPU_VAR(irq_count)
14319 jmp error_exit
14320 CFI_ENDPROC
14321 -END(xen_do_hypervisor_callback)
14322 +ENDPROC(xen_do_hypervisor_callback)
14323
14324 /*
14325 * Hypervisor uses this for application faults while it executes.
14326 @@ -1307,7 +1678,7 @@ ENTRY(xen_failsafe_callback)
14327 SAVE_ALL
14328 jmp error_exit
14329 CFI_ENDPROC
14330 -END(xen_failsafe_callback)
14331 +ENDPROC(xen_failsafe_callback)
14332
14333 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
14334 xen_hvm_callback_vector xen_evtchn_do_upcall
14335 @@ -1356,16 +1727,31 @@ ENTRY(paranoid_exit)
14336 TRACE_IRQS_OFF
14337 testl %ebx,%ebx /* swapgs needed? */
14338 jnz paranoid_restore
14339 - testl $3,CS(%rsp)
14340 + testb $3,CS(%rsp)
14341 jnz paranoid_userspace
14342 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14343 + pax_exit_kernel
14344 + TRACE_IRQS_IRETQ 0
14345 + SWAPGS_UNSAFE_STACK
14346 + RESTORE_ALL 8
14347 + pax_force_retaddr_bts
14348 + jmp irq_return
14349 +#endif
14350 paranoid_swapgs:
14351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14352 + pax_exit_kernel_user
14353 +#else
14354 + pax_exit_kernel
14355 +#endif
14356 TRACE_IRQS_IRETQ 0
14357 SWAPGS_UNSAFE_STACK
14358 RESTORE_ALL 8
14359 jmp irq_return
14360 paranoid_restore:
14361 + pax_exit_kernel
14362 TRACE_IRQS_IRETQ 0
14363 RESTORE_ALL 8
14364 + pax_force_retaddr_bts
14365 jmp irq_return
14366 paranoid_userspace:
14367 GET_THREAD_INFO(%rcx)
14368 @@ -1394,7 +1780,7 @@ paranoid_schedule:
14369 TRACE_IRQS_OFF
14370 jmp paranoid_userspace
14371 CFI_ENDPROC
14372 -END(paranoid_exit)
14373 +ENDPROC(paranoid_exit)
14374
14375 /*
14376 * Exception entry point. This expects an error code/orig_rax on the stack.
14377 @@ -1421,12 +1807,13 @@ ENTRY(error_entry)
14378 movq_cfi r14, R14+8
14379 movq_cfi r15, R15+8
14380 xorl %ebx,%ebx
14381 - testl $3,CS+8(%rsp)
14382 + testb $3,CS+8(%rsp)
14383 je error_kernelspace
14384 error_swapgs:
14385 SWAPGS
14386 error_sti:
14387 TRACE_IRQS_OFF
14388 + pax_force_retaddr_bts
14389 ret
14390
14391 /*
14392 @@ -1453,7 +1840,7 @@ bstep_iret:
14393 movq %rcx,RIP+8(%rsp)
14394 jmp error_swapgs
14395 CFI_ENDPROC
14396 -END(error_entry)
14397 +ENDPROC(error_entry)
14398
14399
14400 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
14401 @@ -1473,7 +1860,7 @@ ENTRY(error_exit)
14402 jnz retint_careful
14403 jmp retint_swapgs
14404 CFI_ENDPROC
14405 -END(error_exit)
14406 +ENDPROC(error_exit)
14407
14408
14409 /* runs on exception stack */
14410 @@ -1485,6 +1872,16 @@ ENTRY(nmi)
14411 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14412 call save_paranoid
14413 DEFAULT_FRAME 0
14414 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14415 + testb $3, CS(%rsp)
14416 + jnz 1f
14417 + pax_enter_kernel
14418 + jmp 2f
14419 +1: pax_enter_kernel_user
14420 +2:
14421 +#else
14422 + pax_enter_kernel
14423 +#endif
14424 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14425 movq %rsp,%rdi
14426 movq $-1,%rsi
14427 @@ -1495,12 +1892,28 @@ ENTRY(nmi)
14428 DISABLE_INTERRUPTS(CLBR_NONE)
14429 testl %ebx,%ebx /* swapgs needed? */
14430 jnz nmi_restore
14431 - testl $3,CS(%rsp)
14432 + testb $3,CS(%rsp)
14433 jnz nmi_userspace
14434 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14435 + pax_exit_kernel
14436 + SWAPGS_UNSAFE_STACK
14437 + RESTORE_ALL 8
14438 + pax_force_retaddr_bts
14439 + jmp irq_return
14440 +#endif
14441 nmi_swapgs:
14442 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14443 + pax_exit_kernel_user
14444 +#else
14445 + pax_exit_kernel
14446 +#endif
14447 SWAPGS_UNSAFE_STACK
14448 + RESTORE_ALL 8
14449 + jmp irq_return
14450 nmi_restore:
14451 + pax_exit_kernel
14452 RESTORE_ALL 8
14453 + pax_force_retaddr_bts
14454 jmp irq_return
14455 nmi_userspace:
14456 GET_THREAD_INFO(%rcx)
14457 @@ -1529,14 +1942,14 @@ nmi_schedule:
14458 jmp paranoid_exit
14459 CFI_ENDPROC
14460 #endif
14461 -END(nmi)
14462 +ENDPROC(nmi)
14463
14464 ENTRY(ignore_sysret)
14465 CFI_STARTPROC
14466 mov $-ENOSYS,%eax
14467 sysret
14468 CFI_ENDPROC
14469 -END(ignore_sysret)
14470 +ENDPROC(ignore_sysret)
14471
14472 /*
14473 * End of kprobes section
14474 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
14475 index c9a281f..ce2f317 100644
14476 --- a/arch/x86/kernel/ftrace.c
14477 +++ b/arch/x86/kernel/ftrace.c
14478 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
14479 static const void *mod_code_newcode; /* holds the text to write to the IP */
14480
14481 static unsigned nmi_wait_count;
14482 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
14483 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14484
14485 int ftrace_arch_read_dyn_info(char *buf, int size)
14486 {
14487 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
14488
14489 r = snprintf(buf, size, "%u %u",
14490 nmi_wait_count,
14491 - atomic_read(&nmi_update_count));
14492 + atomic_read_unchecked(&nmi_update_count));
14493 return r;
14494 }
14495
14496 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
14497
14498 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14499 smp_rmb();
14500 + pax_open_kernel();
14501 ftrace_mod_code();
14502 - atomic_inc(&nmi_update_count);
14503 + pax_close_kernel();
14504 + atomic_inc_unchecked(&nmi_update_count);
14505 }
14506 /* Must have previous changes seen before executions */
14507 smp_mb();
14508 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
14509 {
14510 unsigned char replaced[MCOUNT_INSN_SIZE];
14511
14512 + ip = ktla_ktva(ip);
14513 +
14514 /*
14515 * Note: Due to modules and __init, code can
14516 * disappear and change, we need to protect against faulting
14517 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
14518 unsigned char old[MCOUNT_INSN_SIZE], *new;
14519 int ret;
14520
14521 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14522 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14523 new = ftrace_call_replace(ip, (unsigned long)func);
14524 ret = ftrace_modify_code(ip, old, new);
14525
14526 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
14527 {
14528 unsigned char code[MCOUNT_INSN_SIZE];
14529
14530 + ip = ktla_ktva(ip);
14531 +
14532 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14533 return -EFAULT;
14534
14535 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
14536 index 3bb0850..55a56f4 100644
14537 --- a/arch/x86/kernel/head32.c
14538 +++ b/arch/x86/kernel/head32.c
14539 @@ -19,6 +19,7 @@
14540 #include <asm/io_apic.h>
14541 #include <asm/bios_ebda.h>
14542 #include <asm/tlbflush.h>
14543 +#include <asm/boot.h>
14544
14545 static void __init i386_default_early_setup(void)
14546 {
14547 @@ -33,7 +34,7 @@ void __init i386_start_kernel(void)
14548 {
14549 memblock_init();
14550
14551 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14552 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14553
14554 #ifdef CONFIG_BLK_DEV_INITRD
14555 /* Reserve INITRD */
14556 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
14557 index ce0be7c..c41476e 100644
14558 --- a/arch/x86/kernel/head_32.S
14559 +++ b/arch/x86/kernel/head_32.S
14560 @@ -25,6 +25,12 @@
14561 /* Physical address */
14562 #define pa(X) ((X) - __PAGE_OFFSET)
14563
14564 +#ifdef CONFIG_PAX_KERNEXEC
14565 +#define ta(X) (X)
14566 +#else
14567 +#define ta(X) ((X) - __PAGE_OFFSET)
14568 +#endif
14569 +
14570 /*
14571 * References to members of the new_cpu_data structure.
14572 */
14573 @@ -54,11 +60,7 @@
14574 * and small than max_low_pfn, otherwise will waste some page table entries
14575 */
14576
14577 -#if PTRS_PER_PMD > 1
14578 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14579 -#else
14580 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14581 -#endif
14582 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14583
14584 /* Number of possible pages in the lowmem region */
14585 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
14586 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
14587 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14588
14589 /*
14590 + * Real beginning of normal "text" segment
14591 + */
14592 +ENTRY(stext)
14593 +ENTRY(_stext)
14594 +
14595 +/*
14596 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14597 * %esi points to the real-mode code as a 32-bit pointer.
14598 * CS and DS must be 4 GB flat segments, but we don't depend on
14599 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14600 * can.
14601 */
14602 __HEAD
14603 +
14604 +#ifdef CONFIG_PAX_KERNEXEC
14605 + jmp startup_32
14606 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14607 +.fill PAGE_SIZE-5,1,0xcc
14608 +#endif
14609 +
14610 ENTRY(startup_32)
14611 movl pa(stack_start),%ecx
14612
14613 @@ -105,6 +120,57 @@ ENTRY(startup_32)
14614 2:
14615 leal -__PAGE_OFFSET(%ecx),%esp
14616
14617 +#ifdef CONFIG_SMP
14618 + movl $pa(cpu_gdt_table),%edi
14619 + movl $__per_cpu_load,%eax
14620 + movw %ax,__KERNEL_PERCPU + 2(%edi)
14621 + rorl $16,%eax
14622 + movb %al,__KERNEL_PERCPU + 4(%edi)
14623 + movb %ah,__KERNEL_PERCPU + 7(%edi)
14624 + movl $__per_cpu_end - 1,%eax
14625 + subl $__per_cpu_start,%eax
14626 + movw %ax,__KERNEL_PERCPU + 0(%edi)
14627 +#endif
14628 +
14629 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14630 + movl $NR_CPUS,%ecx
14631 + movl $pa(cpu_gdt_table),%edi
14632 +1:
14633 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14634 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14635 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14636 + addl $PAGE_SIZE_asm,%edi
14637 + loop 1b
14638 +#endif
14639 +
14640 +#ifdef CONFIG_PAX_KERNEXEC
14641 + movl $pa(boot_gdt),%edi
14642 + movl $__LOAD_PHYSICAL_ADDR,%eax
14643 + movw %ax,__BOOT_CS + 2(%edi)
14644 + rorl $16,%eax
14645 + movb %al,__BOOT_CS + 4(%edi)
14646 + movb %ah,__BOOT_CS + 7(%edi)
14647 + rorl $16,%eax
14648 +
14649 + ljmp $(__BOOT_CS),$1f
14650 +1:
14651 +
14652 + movl $NR_CPUS,%ecx
14653 + movl $pa(cpu_gdt_table),%edi
14654 + addl $__PAGE_OFFSET,%eax
14655 +1:
14656 + movw %ax,__KERNEL_CS + 2(%edi)
14657 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14658 + rorl $16,%eax
14659 + movb %al,__KERNEL_CS + 4(%edi)
14660 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14661 + movb %ah,__KERNEL_CS + 7(%edi)
14662 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14663 + rorl $16,%eax
14664 + addl $PAGE_SIZE_asm,%edi
14665 + loop 1b
14666 +#endif
14667 +
14668 /*
14669 * Clear BSS first so that there are no surprises...
14670 */
14671 @@ -195,8 +261,11 @@ ENTRY(startup_32)
14672 movl %eax, pa(max_pfn_mapped)
14673
14674 /* Do early initialization of the fixmap area */
14675 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14676 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
14677 +#ifdef CONFIG_COMPAT_VDSO
14678 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
14679 +#else
14680 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
14681 +#endif
14682 #else /* Not PAE */
14683
14684 page_pde_offset = (__PAGE_OFFSET >> 20);
14685 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14686 movl %eax, pa(max_pfn_mapped)
14687
14688 /* Do early initialization of the fixmap area */
14689 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14690 - movl %eax,pa(initial_page_table+0xffc)
14691 +#ifdef CONFIG_COMPAT_VDSO
14692 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
14693 +#else
14694 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
14695 +#endif
14696 #endif
14697
14698 #ifdef CONFIG_PARAVIRT
14699 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14700 cmpl $num_subarch_entries, %eax
14701 jae bad_subarch
14702
14703 - movl pa(subarch_entries)(,%eax,4), %eax
14704 - subl $__PAGE_OFFSET, %eax
14705 - jmp *%eax
14706 + jmp *pa(subarch_entries)(,%eax,4)
14707
14708 bad_subarch:
14709 WEAK(lguest_entry)
14710 @@ -255,10 +325,10 @@ WEAK(xen_entry)
14711 __INITDATA
14712
14713 subarch_entries:
14714 - .long default_entry /* normal x86/PC */
14715 - .long lguest_entry /* lguest hypervisor */
14716 - .long xen_entry /* Xen hypervisor */
14717 - .long default_entry /* Moorestown MID */
14718 + .long ta(default_entry) /* normal x86/PC */
14719 + .long ta(lguest_entry) /* lguest hypervisor */
14720 + .long ta(xen_entry) /* Xen hypervisor */
14721 + .long ta(default_entry) /* Moorestown MID */
14722 num_subarch_entries = (. - subarch_entries) / 4
14723 .previous
14724 #else
14725 @@ -312,6 +382,7 @@ default_entry:
14726 orl %edx,%eax
14727 movl %eax,%cr4
14728
14729 +#ifdef CONFIG_X86_PAE
14730 testb $X86_CR4_PAE, %al # check if PAE is enabled
14731 jz 6f
14732
14733 @@ -340,6 +411,9 @@ default_entry:
14734 /* Make changes effective */
14735 wrmsr
14736
14737 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
14738 +#endif
14739 +
14740 6:
14741
14742 /*
14743 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
14744 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
14745 movl %eax,%ss # after changing gdt.
14746
14747 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
14748 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
14749 movl %eax,%ds
14750 movl %eax,%es
14751
14752 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
14753 */
14754 cmpb $0,ready
14755 jne 1f
14756 - movl $gdt_page,%eax
14757 + movl $cpu_gdt_table,%eax
14758 movl $stack_canary,%ecx
14759 +#ifdef CONFIG_SMP
14760 + addl $__per_cpu_load,%ecx
14761 +#endif
14762 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
14763 shrl $16, %ecx
14764 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
14765 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
14766 1:
14767 -#endif
14768 movl $(__KERNEL_STACK_CANARY),%eax
14769 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14770 + movl $(__USER_DS),%eax
14771 +#else
14772 + xorl %eax,%eax
14773 +#endif
14774 movl %eax,%gs
14775
14776 xorl %eax,%eax # Clear LDT
14777 @@ -558,22 +639,22 @@ early_page_fault:
14778 jmp early_fault
14779
14780 early_fault:
14781 - cld
14782 #ifdef CONFIG_PRINTK
14783 + cmpl $1,%ss:early_recursion_flag
14784 + je hlt_loop
14785 + incl %ss:early_recursion_flag
14786 + cld
14787 pusha
14788 movl $(__KERNEL_DS),%eax
14789 movl %eax,%ds
14790 movl %eax,%es
14791 - cmpl $2,early_recursion_flag
14792 - je hlt_loop
14793 - incl early_recursion_flag
14794 movl %cr2,%eax
14795 pushl %eax
14796 pushl %edx /* trapno */
14797 pushl $fault_msg
14798 call printk
14799 +; call dump_stack
14800 #endif
14801 - call dump_stack
14802 hlt_loop:
14803 hlt
14804 jmp hlt_loop
14805 @@ -581,8 +662,11 @@ hlt_loop:
14806 /* This is the default interrupt "handler" :-) */
14807 ALIGN
14808 ignore_int:
14809 - cld
14810 #ifdef CONFIG_PRINTK
14811 + cmpl $2,%ss:early_recursion_flag
14812 + je hlt_loop
14813 + incl %ss:early_recursion_flag
14814 + cld
14815 pushl %eax
14816 pushl %ecx
14817 pushl %edx
14818 @@ -591,9 +675,6 @@ ignore_int:
14819 movl $(__KERNEL_DS),%eax
14820 movl %eax,%ds
14821 movl %eax,%es
14822 - cmpl $2,early_recursion_flag
14823 - je hlt_loop
14824 - incl early_recursion_flag
14825 pushl 16(%esp)
14826 pushl 24(%esp)
14827 pushl 32(%esp)
14828 @@ -622,29 +703,43 @@ ENTRY(initial_code)
14829 /*
14830 * BSS section
14831 */
14832 -__PAGE_ALIGNED_BSS
14833 - .align PAGE_SIZE
14834 #ifdef CONFIG_X86_PAE
14835 +.section .initial_pg_pmd,"a",@progbits
14836 initial_pg_pmd:
14837 .fill 1024*KPMDS,4,0
14838 #else
14839 +.section .initial_page_table,"a",@progbits
14840 ENTRY(initial_page_table)
14841 .fill 1024,4,0
14842 #endif
14843 +.section .initial_pg_fixmap,"a",@progbits
14844 initial_pg_fixmap:
14845 .fill 1024,4,0
14846 +.section .empty_zero_page,"a",@progbits
14847 ENTRY(empty_zero_page)
14848 .fill 4096,1,0
14849 +.section .swapper_pg_dir,"a",@progbits
14850 ENTRY(swapper_pg_dir)
14851 +#ifdef CONFIG_X86_PAE
14852 + .fill 4,8,0
14853 +#else
14854 .fill 1024,4,0
14855 +#endif
14856 +
14857 +/*
14858 + * The IDT has to be page-aligned to simplify the Pentium
14859 + * F0 0F bug workaround.. We have a special link segment
14860 + * for this.
14861 + */
14862 +.section .idt,"a",@progbits
14863 +ENTRY(idt_table)
14864 + .fill 256,8,0
14865
14866 /*
14867 * This starts the data section.
14868 */
14869 #ifdef CONFIG_X86_PAE
14870 -__PAGE_ALIGNED_DATA
14871 - /* Page-aligned for the benefit of paravirt? */
14872 - .align PAGE_SIZE
14873 +.section .initial_page_table,"a",@progbits
14874 ENTRY(initial_page_table)
14875 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
14876 # if KPMDS == 3
14877 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
14878 # error "Kernel PMDs should be 1, 2 or 3"
14879 # endif
14880 .align PAGE_SIZE /* needs to be page-sized too */
14881 +
14882 +#ifdef CONFIG_PAX_PER_CPU_PGD
14883 +ENTRY(cpu_pgd)
14884 + .rept NR_CPUS
14885 + .fill 4,8,0
14886 + .endr
14887 +#endif
14888 +
14889 #endif
14890
14891 .data
14892 .balign 4
14893 ENTRY(stack_start)
14894 - .long init_thread_union+THREAD_SIZE
14895 + .long init_thread_union+THREAD_SIZE-8
14896
14897 +ready: .byte 0
14898 +
14899 +.section .rodata,"a",@progbits
14900 early_recursion_flag:
14901 .long 0
14902
14903 -ready: .byte 0
14904 -
14905 int_msg:
14906 .asciz "Unknown interrupt or fault at: %p %p %p\n"
14907
14908 @@ -707,7 +811,7 @@ fault_msg:
14909 .word 0 # 32 bit align gdt_desc.address
14910 boot_gdt_descr:
14911 .word __BOOT_DS+7
14912 - .long boot_gdt - __PAGE_OFFSET
14913 + .long pa(boot_gdt)
14914
14915 .word 0 # 32-bit align idt_desc.address
14916 idt_descr:
14917 @@ -718,7 +822,7 @@ idt_descr:
14918 .word 0 # 32 bit align gdt_desc.address
14919 ENTRY(early_gdt_descr)
14920 .word GDT_ENTRIES*8-1
14921 - .long gdt_page /* Overwritten for secondary CPUs */
14922 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
14923
14924 /*
14925 * The boot_gdt must mirror the equivalent in setup.S and is
14926 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
14927 .align L1_CACHE_BYTES
14928 ENTRY(boot_gdt)
14929 .fill GDT_ENTRY_BOOT_CS,8,0
14930 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
14931 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
14932 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
14933 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
14934 +
14935 + .align PAGE_SIZE_asm
14936 +ENTRY(cpu_gdt_table)
14937 + .rept NR_CPUS
14938 + .quad 0x0000000000000000 /* NULL descriptor */
14939 + .quad 0x0000000000000000 /* 0x0b reserved */
14940 + .quad 0x0000000000000000 /* 0x13 reserved */
14941 + .quad 0x0000000000000000 /* 0x1b reserved */
14942 +
14943 +#ifdef CONFIG_PAX_KERNEXEC
14944 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
14945 +#else
14946 + .quad 0x0000000000000000 /* 0x20 unused */
14947 +#endif
14948 +
14949 + .quad 0x0000000000000000 /* 0x28 unused */
14950 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
14951 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
14952 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
14953 + .quad 0x0000000000000000 /* 0x4b reserved */
14954 + .quad 0x0000000000000000 /* 0x53 reserved */
14955 + .quad 0x0000000000000000 /* 0x5b reserved */
14956 +
14957 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
14958 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
14959 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
14960 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
14961 +
14962 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
14963 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
14964 +
14965 + /*
14966 + * Segments used for calling PnP BIOS have byte granularity.
14967 + * The code segments and data segments have fixed 64k limits,
14968 + * the transfer segment sizes are set at run time.
14969 + */
14970 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
14971 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
14972 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
14973 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
14974 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
14975 +
14976 + /*
14977 + * The APM segments have byte granularity and their bases
14978 + * are set at run time. All have 64k limits.
14979 + */
14980 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
14981 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
14982 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
14983 +
14984 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
14985 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
14986 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
14987 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
14988 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
14989 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
14990 +
14991 + /* Be sure this is zeroed to avoid false validations in Xen */
14992 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
14993 + .endr
14994 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
14995 index e11e394..9aebc5d 100644
14996 --- a/arch/x86/kernel/head_64.S
14997 +++ b/arch/x86/kernel/head_64.S
14998 @@ -19,6 +19,8 @@
14999 #include <asm/cache.h>
15000 #include <asm/processor-flags.h>
15001 #include <asm/percpu.h>
15002 +#include <asm/cpufeature.h>
15003 +#include <asm/alternative-asm.h>
15004
15005 #ifdef CONFIG_PARAVIRT
15006 #include <asm/asm-offsets.h>
15007 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
15008 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
15009 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
15010 L3_START_KERNEL = pud_index(__START_KERNEL_map)
15011 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
15012 +L3_VMALLOC_START = pud_index(VMALLOC_START)
15013 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
15014 +L3_VMALLOC_END = pud_index(VMALLOC_END)
15015 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
15016 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
15017
15018 .text
15019 __HEAD
15020 @@ -85,35 +93,23 @@ startup_64:
15021 */
15022 addq %rbp, init_level4_pgt + 0(%rip)
15023 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
15024 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
15025 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
15026 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
15027 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
15028
15029 addq %rbp, level3_ident_pgt + 0(%rip)
15030 +#ifndef CONFIG_XEN
15031 + addq %rbp, level3_ident_pgt + 8(%rip)
15032 +#endif
15033
15034 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
15035 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
15036 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
15037 +
15038 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
15039 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
15040
15041 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15042 -
15043 - /* Add an Identity mapping if I am above 1G */
15044 - leaq _text(%rip), %rdi
15045 - andq $PMD_PAGE_MASK, %rdi
15046 -
15047 - movq %rdi, %rax
15048 - shrq $PUD_SHIFT, %rax
15049 - andq $(PTRS_PER_PUD - 1), %rax
15050 - jz ident_complete
15051 -
15052 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
15053 - leaq level3_ident_pgt(%rip), %rbx
15054 - movq %rdx, 0(%rbx, %rax, 8)
15055 -
15056 - movq %rdi, %rax
15057 - shrq $PMD_SHIFT, %rax
15058 - andq $(PTRS_PER_PMD - 1), %rax
15059 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15060 - leaq level2_spare_pgt(%rip), %rbx
15061 - movq %rdx, 0(%rbx, %rax, 8)
15062 -ident_complete:
15063 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15064
15065 /*
15066 * Fixup the kernel text+data virtual addresses. Note that
15067 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
15068 * after the boot processor executes this code.
15069 */
15070
15071 - /* Enable PAE mode and PGE */
15072 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15073 + /* Enable PAE mode and PSE/PGE */
15074 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15075 movq %rax, %cr4
15076
15077 /* Setup early boot stage 4 level pagetables. */
15078 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
15079 movl $MSR_EFER, %ecx
15080 rdmsr
15081 btsl $_EFER_SCE, %eax /* Enable System Call */
15082 - btl $20,%edi /* No Execute supported? */
15083 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15084 jnc 1f
15085 btsl $_EFER_NX, %eax
15086 + leaq init_level4_pgt(%rip), %rdi
15087 +#ifndef CONFIG_EFI
15088 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15089 +#endif
15090 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15091 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
15092 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15093 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
15094 1: wrmsr /* Make changes effective */
15095
15096 /* Setup cr0 */
15097 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
15098 * jump. In addition we need to ensure %cs is set so we make this
15099 * a far return.
15100 */
15101 + pax_set_fptr_mask
15102 movq initial_code(%rip),%rax
15103 pushq $0 # fake return address to stop unwinder
15104 pushq $__KERNEL_CS # set correct cs
15105 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
15106 bad_address:
15107 jmp bad_address
15108
15109 - .section ".init.text","ax"
15110 + __INIT
15111 #ifdef CONFIG_EARLY_PRINTK
15112 .globl early_idt_handlers
15113 early_idt_handlers:
15114 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
15115 #endif /* EARLY_PRINTK */
15116 1: hlt
15117 jmp 1b
15118 + .previous
15119
15120 #ifdef CONFIG_EARLY_PRINTK
15121 + __INITDATA
15122 early_recursion_flag:
15123 .long 0
15124 + .previous
15125
15126 + .section .rodata,"a",@progbits
15127 early_idt_msg:
15128 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15129 early_idt_ripmsg:
15130 .asciz "RIP %s\n"
15131 + .previous
15132 #endif /* CONFIG_EARLY_PRINTK */
15133 - .previous
15134
15135 + .section .rodata,"a",@progbits
15136 #define NEXT_PAGE(name) \
15137 .balign PAGE_SIZE; \
15138 ENTRY(name)
15139 @@ -338,7 +348,6 @@ ENTRY(name)
15140 i = i + 1 ; \
15141 .endr
15142
15143 - .data
15144 /*
15145 * This default setting generates an ident mapping at address 0x100000
15146 * and a mapping for the kernel that precisely maps virtual address
15147 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
15148 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15149 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15150 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15151 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
15152 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
15153 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
15154 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
15155 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15156 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15157 .org init_level4_pgt + L4_START_KERNEL*8, 0
15158 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15159 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15160
15161 +#ifdef CONFIG_PAX_PER_CPU_PGD
15162 +NEXT_PAGE(cpu_pgd)
15163 + .rept NR_CPUS
15164 + .fill 512,8,0
15165 + .endr
15166 +#endif
15167 +
15168 NEXT_PAGE(level3_ident_pgt)
15169 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15170 +#ifdef CONFIG_XEN
15171 .fill 511,8,0
15172 +#else
15173 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
15174 + .fill 510,8,0
15175 +#endif
15176 +
15177 +NEXT_PAGE(level3_vmalloc_start_pgt)
15178 + .fill 512,8,0
15179 +
15180 +NEXT_PAGE(level3_vmalloc_end_pgt)
15181 + .fill 512,8,0
15182 +
15183 +NEXT_PAGE(level3_vmemmap_pgt)
15184 + .fill L3_VMEMMAP_START,8,0
15185 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15186
15187 NEXT_PAGE(level3_kernel_pgt)
15188 .fill L3_START_KERNEL,8,0
15189 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
15190 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
15191 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15192
15193 +NEXT_PAGE(level2_vmemmap_pgt)
15194 + .fill 512,8,0
15195 +
15196 NEXT_PAGE(level2_fixmap_pgt)
15197 - .fill 506,8,0
15198 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15199 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
15200 - .fill 5,8,0
15201 + .fill 507,8,0
15202 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
15203 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
15204 + .fill 4,8,0
15205
15206 -NEXT_PAGE(level1_fixmap_pgt)
15207 +NEXT_PAGE(level1_vsyscall_pgt)
15208 .fill 512,8,0
15209
15210 -NEXT_PAGE(level2_ident_pgt)
15211 - /* Since I easily can, map the first 1G.
15212 + /* Since I easily can, map the first 2G.
15213 * Don't set NX because code runs from these pages.
15214 */
15215 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
15216 +NEXT_PAGE(level2_ident_pgt)
15217 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
15218
15219 NEXT_PAGE(level2_kernel_pgt)
15220 /*
15221 @@ -389,33 +429,55 @@ NEXT_PAGE(level2_kernel_pgt)
15222 * If you want to increase this then increase MODULES_VADDR
15223 * too.)
15224 */
15225 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
15226 - KERNEL_IMAGE_SIZE/PMD_SIZE)
15227 -
15228 -NEXT_PAGE(level2_spare_pgt)
15229 - .fill 512, 8, 0
15230 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
15231
15232 #undef PMDS
15233 #undef NEXT_PAGE
15234
15235 - .data
15236 + .align PAGE_SIZE
15237 +ENTRY(cpu_gdt_table)
15238 + .rept NR_CPUS
15239 + .quad 0x0000000000000000 /* NULL descriptor */
15240 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15241 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
15242 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
15243 + .quad 0x00cffb000000ffff /* __USER32_CS */
15244 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15245 + .quad 0x00affb000000ffff /* __USER_CS */
15246 +
15247 +#ifdef CONFIG_PAX_KERNEXEC
15248 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15249 +#else
15250 + .quad 0x0 /* unused */
15251 +#endif
15252 +
15253 + .quad 0,0 /* TSS */
15254 + .quad 0,0 /* LDT */
15255 + .quad 0,0,0 /* three TLS descriptors */
15256 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
15257 + /* asm/segment.h:GDT_ENTRIES must match this */
15258 +
15259 + /* zero the remaining page */
15260 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15261 + .endr
15262 +
15263 .align 16
15264 .globl early_gdt_descr
15265 early_gdt_descr:
15266 .word GDT_ENTRIES*8-1
15267 early_gdt_descr_base:
15268 - .quad INIT_PER_CPU_VAR(gdt_page)
15269 + .quad cpu_gdt_table
15270
15271 ENTRY(phys_base)
15272 /* This must match the first entry in level2_kernel_pgt */
15273 .quad 0x0000000000000000
15274
15275 #include "../../x86/xen/xen-head.S"
15276 -
15277 - .section .bss, "aw", @nobits
15278 +
15279 + .section .rodata,"a",@progbits
15280 .align L1_CACHE_BYTES
15281 ENTRY(idt_table)
15282 - .skip IDT_ENTRIES * 16
15283 + .fill 512,8,0
15284
15285 __PAGE_ALIGNED_BSS
15286 .align PAGE_SIZE
15287 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
15288 index 9c3bd4a..e1d9b35 100644
15289 --- a/arch/x86/kernel/i386_ksyms_32.c
15290 +++ b/arch/x86/kernel/i386_ksyms_32.c
15291 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15292 EXPORT_SYMBOL(cmpxchg8b_emu);
15293 #endif
15294
15295 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
15296 +
15297 /* Networking helper routines. */
15298 EXPORT_SYMBOL(csum_partial_copy_generic);
15299 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15300 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15301
15302 EXPORT_SYMBOL(__get_user_1);
15303 EXPORT_SYMBOL(__get_user_2);
15304 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15305
15306 EXPORT_SYMBOL(csum_partial);
15307 EXPORT_SYMBOL(empty_zero_page);
15308 +
15309 +#ifdef CONFIG_PAX_KERNEXEC
15310 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15311 +#endif
15312 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
15313 index 6104852..6114160 100644
15314 --- a/arch/x86/kernel/i8259.c
15315 +++ b/arch/x86/kernel/i8259.c
15316 @@ -210,7 +210,7 @@ spurious_8259A_irq:
15317 "spurious 8259A interrupt: IRQ%d.\n", irq);
15318 spurious_irq_mask |= irqmask;
15319 }
15320 - atomic_inc(&irq_err_count);
15321 + atomic_inc_unchecked(&irq_err_count);
15322 /*
15323 * Theoretically we do not have to handle this IRQ,
15324 * but in Linux this does not cause problems and is
15325 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
15326 index 43e9ccf..44ccf6f 100644
15327 --- a/arch/x86/kernel/init_task.c
15328 +++ b/arch/x86/kernel/init_task.c
15329 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
15330 * way process stacks are handled. This is done by having a special
15331 * "init_task" linker map entry..
15332 */
15333 -union thread_union init_thread_union __init_task_data =
15334 - { INIT_THREAD_INFO(init_task) };
15335 +union thread_union init_thread_union __init_task_data;
15336
15337 /*
15338 * Initial task structure.
15339 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15340 * section. Since TSS's are completely CPU-local, we want them
15341 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15342 */
15343 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15344 -
15345 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15346 +EXPORT_SYMBOL(init_tss);
15347 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
15348 index 8c96897..be66bfa 100644
15349 --- a/arch/x86/kernel/ioport.c
15350 +++ b/arch/x86/kernel/ioport.c
15351 @@ -6,6 +6,7 @@
15352 #include <linux/sched.h>
15353 #include <linux/kernel.h>
15354 #include <linux/capability.h>
15355 +#include <linux/security.h>
15356 #include <linux/errno.h>
15357 #include <linux/types.h>
15358 #include <linux/ioport.h>
15359 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
15360
15361 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15362 return -EINVAL;
15363 +#ifdef CONFIG_GRKERNSEC_IO
15364 + if (turn_on && grsec_disable_privio) {
15365 + gr_handle_ioperm();
15366 + return -EPERM;
15367 + }
15368 +#endif
15369 if (turn_on && !capable(CAP_SYS_RAWIO))
15370 return -EPERM;
15371
15372 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
15373 * because the ->io_bitmap_max value must match the bitmap
15374 * contents:
15375 */
15376 - tss = &per_cpu(init_tss, get_cpu());
15377 + tss = init_tss + get_cpu();
15378
15379 if (turn_on)
15380 bitmap_clear(t->io_bitmap_ptr, from, num);
15381 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
15382 return -EINVAL;
15383 /* Trying to gain more privileges? */
15384 if (level > old) {
15385 +#ifdef CONFIG_GRKERNSEC_IO
15386 + if (grsec_disable_privio) {
15387 + gr_handle_iopl();
15388 + return -EPERM;
15389 + }
15390 +#endif
15391 if (!capable(CAP_SYS_RAWIO))
15392 return -EPERM;
15393 }
15394 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
15395 index 429e0c9..17b3ece 100644
15396 --- a/arch/x86/kernel/irq.c
15397 +++ b/arch/x86/kernel/irq.c
15398 @@ -18,7 +18,7 @@
15399 #include <asm/mce.h>
15400 #include <asm/hw_irq.h>
15401
15402 -atomic_t irq_err_count;
15403 +atomic_unchecked_t irq_err_count;
15404
15405 /* Function pointer for generic interrupt vector handling */
15406 void (*x86_platform_ipi_callback)(void) = NULL;
15407 @@ -117,9 +117,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
15408 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15409 seq_printf(p, " Machine check polls\n");
15410 #endif
15411 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15412 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15413 #if defined(CONFIG_X86_IO_APIC)
15414 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15415 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15416 #endif
15417 return 0;
15418 }
15419 @@ -159,10 +159,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15420
15421 u64 arch_irq_stat(void)
15422 {
15423 - u64 sum = atomic_read(&irq_err_count);
15424 + u64 sum = atomic_read_unchecked(&irq_err_count);
15425
15426 #ifdef CONFIG_X86_IO_APIC
15427 - sum += atomic_read(&irq_mis_count);
15428 + sum += atomic_read_unchecked(&irq_mis_count);
15429 #endif
15430 return sum;
15431 }
15432 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
15433 index 7209070..cbcd71a 100644
15434 --- a/arch/x86/kernel/irq_32.c
15435 +++ b/arch/x86/kernel/irq_32.c
15436 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
15437 __asm__ __volatile__("andl %%esp,%0" :
15438 "=r" (sp) : "0" (THREAD_SIZE - 1));
15439
15440 - return sp < (sizeof(struct thread_info) + STACK_WARN);
15441 + return sp < STACK_WARN;
15442 }
15443
15444 static void print_stack_overflow(void)
15445 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(void) { }
15446 * per-CPU IRQ handling contexts (thread information and stack)
15447 */
15448 union irq_ctx {
15449 - struct thread_info tinfo;
15450 - u32 stack[THREAD_SIZE/sizeof(u32)];
15451 + unsigned long previous_esp;
15452 + u32 stack[THREAD_SIZE/sizeof(u32)];
15453 } __attribute__((aligned(THREAD_SIZE)));
15454
15455 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15456 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, void *stack)
15457 static inline int
15458 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15459 {
15460 - union irq_ctx *curctx, *irqctx;
15461 + union irq_ctx *irqctx;
15462 u32 *isp, arg1, arg2;
15463
15464 - curctx = (union irq_ctx *) current_thread_info();
15465 irqctx = __this_cpu_read(hardirq_ctx);
15466
15467 /*
15468 @@ -87,21 +86,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15469 * handler) we can't do that and just have to keep using the
15470 * current stack (which is the irq stack already after all)
15471 */
15472 - if (unlikely(curctx == irqctx))
15473 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15474 return 0;
15475
15476 /* build the stack frame on the IRQ stack */
15477 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15478 - irqctx->tinfo.task = curctx->tinfo.task;
15479 - irqctx->tinfo.previous_esp = current_stack_pointer;
15480 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15481 + irqctx->previous_esp = current_stack_pointer;
15482
15483 - /*
15484 - * Copy the softirq bits in preempt_count so that the
15485 - * softirq checks work in the hardirq context.
15486 - */
15487 - irqctx->tinfo.preempt_count =
15488 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15489 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15490 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15491 + __set_fs(MAKE_MM_SEG(0));
15492 +#endif
15493
15494 if (unlikely(overflow))
15495 call_on_stack(print_stack_overflow, isp);
15496 @@ -113,6 +107,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15497 : "0" (irq), "1" (desc), "2" (isp),
15498 "D" (desc->handle_irq)
15499 : "memory", "cc", "ecx");
15500 +
15501 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15502 + __set_fs(current_thread_info()->addr_limit);
15503 +#endif
15504 +
15505 return 1;
15506 }
15507
15508 @@ -121,29 +120,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15509 */
15510 void __cpuinit irq_ctx_init(int cpu)
15511 {
15512 - union irq_ctx *irqctx;
15513 -
15514 if (per_cpu(hardirq_ctx, cpu))
15515 return;
15516
15517 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15518 - THREAD_FLAGS,
15519 - THREAD_ORDER));
15520 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15521 - irqctx->tinfo.cpu = cpu;
15522 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15523 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15524 -
15525 - per_cpu(hardirq_ctx, cpu) = irqctx;
15526 -
15527 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15528 - THREAD_FLAGS,
15529 - THREAD_ORDER));
15530 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15531 - irqctx->tinfo.cpu = cpu;
15532 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15533 -
15534 - per_cpu(softirq_ctx, cpu) = irqctx;
15535 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15536 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15537
15538 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15539 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15540 @@ -152,7 +133,6 @@ void __cpuinit irq_ctx_init(int cpu)
15541 asmlinkage void do_softirq(void)
15542 {
15543 unsigned long flags;
15544 - struct thread_info *curctx;
15545 union irq_ctx *irqctx;
15546 u32 *isp;
15547
15548 @@ -162,15 +142,22 @@ asmlinkage void do_softirq(void)
15549 local_irq_save(flags);
15550
15551 if (local_softirq_pending()) {
15552 - curctx = current_thread_info();
15553 irqctx = __this_cpu_read(softirq_ctx);
15554 - irqctx->tinfo.task = curctx->task;
15555 - irqctx->tinfo.previous_esp = current_stack_pointer;
15556 + irqctx->previous_esp = current_stack_pointer;
15557
15558 /* build the stack frame on the softirq stack */
15559 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15560 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15561 +
15562 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15563 + __set_fs(MAKE_MM_SEG(0));
15564 +#endif
15565
15566 call_on_stack(__do_softirq, isp);
15567 +
15568 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15569 + __set_fs(current_thread_info()->addr_limit);
15570 +#endif
15571 +
15572 /*
15573 * Shouldn't happen, we returned above if in_interrupt():
15574 */
15575 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
15576 index 69bca46..0bac999 100644
15577 --- a/arch/x86/kernel/irq_64.c
15578 +++ b/arch/x86/kernel/irq_64.c
15579 @@ -38,7 +38,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
15580 #ifdef CONFIG_DEBUG_STACKOVERFLOW
15581 u64 curbase = (u64)task_stack_page(current);
15582
15583 - if (user_mode_vm(regs))
15584 + if (user_mode(regs))
15585 return;
15586
15587 WARN_ONCE(regs->sp >= curbase &&
15588 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
15589 index faba577..93b9e71 100644
15590 --- a/arch/x86/kernel/kgdb.c
15591 +++ b/arch/x86/kernel/kgdb.c
15592 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
15593 #ifdef CONFIG_X86_32
15594 switch (regno) {
15595 case GDB_SS:
15596 - if (!user_mode_vm(regs))
15597 + if (!user_mode(regs))
15598 *(unsigned long *)mem = __KERNEL_DS;
15599 break;
15600 case GDB_SP:
15601 - if (!user_mode_vm(regs))
15602 + if (!user_mode(regs))
15603 *(unsigned long *)mem = kernel_stack_pointer(regs);
15604 break;
15605 case GDB_GS:
15606 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
15607 case 'k':
15608 /* clear the trace bit */
15609 linux_regs->flags &= ~X86_EFLAGS_TF;
15610 - atomic_set(&kgdb_cpu_doing_single_step, -1);
15611 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15612
15613 /* set the trace bit if we're stepping */
15614 if (remcomInBuffer[0] == 's') {
15615 linux_regs->flags |= X86_EFLAGS_TF;
15616 - atomic_set(&kgdb_cpu_doing_single_step,
15617 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15618 raw_smp_processor_id());
15619 }
15620
15621 @@ -543,7 +543,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
15622
15623 switch (cmd) {
15624 case DIE_DEBUG:
15625 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
15626 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
15627 if (user_mode(regs))
15628 return single_step_cont(regs, args);
15629 break;
15630 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
15631 index 7da647d..5d3c4c1 100644
15632 --- a/arch/x86/kernel/kprobes.c
15633 +++ b/arch/x86/kernel/kprobes.c
15634 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
15635 } __attribute__((packed)) *insn;
15636
15637 insn = (struct __arch_relative_insn *)from;
15638 +
15639 + pax_open_kernel();
15640 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
15641 insn->op = op;
15642 + pax_close_kernel();
15643 }
15644
15645 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
15646 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
15647 kprobe_opcode_t opcode;
15648 kprobe_opcode_t *orig_opcodes = opcodes;
15649
15650 - if (search_exception_tables((unsigned long)opcodes))
15651 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15652 return 0; /* Page fault may occur on this address. */
15653
15654 retry:
15655 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
15656 }
15657 }
15658 insn_get_length(&insn);
15659 + pax_open_kernel();
15660 memcpy(dest, insn.kaddr, insn.length);
15661 + pax_close_kernel();
15662
15663 #ifdef CONFIG_X86_64
15664 if (insn_rip_relative(&insn)) {
15665 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
15666 (u8 *) dest;
15667 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
15668 disp = (u8 *) dest + insn_offset_displacement(&insn);
15669 + pax_open_kernel();
15670 *(s32 *) disp = (s32) newdisp;
15671 + pax_close_kernel();
15672 }
15673 #endif
15674 return insn.length;
15675 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
15676 */
15677 __copy_instruction(p->ainsn.insn, p->addr, 0);
15678
15679 - if (can_boost(p->addr))
15680 + if (can_boost(ktla_ktva(p->addr)))
15681 p->ainsn.boostable = 0;
15682 else
15683 p->ainsn.boostable = -1;
15684
15685 - p->opcode = *p->addr;
15686 + p->opcode = *(ktla_ktva(p->addr));
15687 }
15688
15689 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15690 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
15691 * nor set current_kprobe, because it doesn't use single
15692 * stepping.
15693 */
15694 - regs->ip = (unsigned long)p->ainsn.insn;
15695 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15696 preempt_enable_no_resched();
15697 return;
15698 }
15699 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
15700 if (p->opcode == BREAKPOINT_INSTRUCTION)
15701 regs->ip = (unsigned long)p->addr;
15702 else
15703 - regs->ip = (unsigned long)p->ainsn.insn;
15704 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15705 }
15706
15707 /*
15708 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
15709 setup_singlestep(p, regs, kcb, 0);
15710 return 1;
15711 }
15712 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
15713 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15714 /*
15715 * The breakpoint instruction was removed right
15716 * after we hit it. Another cpu has removed
15717 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
15718 " movq %rax, 152(%rsp)\n"
15719 RESTORE_REGS_STRING
15720 " popfq\n"
15721 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
15722 + " btsq $63,(%rsp)\n"
15723 +#endif
15724 #else
15725 " pushf\n"
15726 SAVE_REGS_STRING
15727 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
15728 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15729 {
15730 unsigned long *tos = stack_addr(regs);
15731 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15732 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15733 unsigned long orig_ip = (unsigned long)p->addr;
15734 kprobe_opcode_t *insn = p->ainsn.insn;
15735
15736 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
15737 struct die_args *args = data;
15738 int ret = NOTIFY_DONE;
15739
15740 - if (args->regs && user_mode_vm(args->regs))
15741 + if (args->regs && user_mode(args->regs))
15742 return ret;
15743
15744 switch (val) {
15745 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
15746 * Verify if the address gap is in 2GB range, because this uses
15747 * a relative jump.
15748 */
15749 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
15750 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
15751 if (abs(rel) > 0x7fffffff)
15752 return -ERANGE;
15753
15754 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
15755 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
15756
15757 /* Set probe function call */
15758 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
15759 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
15760
15761 /* Set returning jmp instruction at the tail of out-of-line buffer */
15762 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
15763 - (u8 *)op->kp.addr + op->optinsn.size);
15764 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
15765
15766 flush_icache_range((unsigned long) buf,
15767 (unsigned long) buf + TMPL_END_IDX +
15768 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
15769 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
15770
15771 /* Backup instructions which will be replaced by jump address */
15772 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
15773 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
15774 RELATIVE_ADDR_SIZE);
15775
15776 insn_buf[0] = RELATIVEJUMP_OPCODE;
15777 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
15778 index a9c2116..a52d4fc 100644
15779 --- a/arch/x86/kernel/kvm.c
15780 +++ b/arch/x86/kernel/kvm.c
15781 @@ -437,6 +437,7 @@ static void __init paravirt_ops_setup(void)
15782 pv_mmu_ops.set_pud = kvm_set_pud;
15783 #if PAGETABLE_LEVELS == 4
15784 pv_mmu_ops.set_pgd = kvm_set_pgd;
15785 + pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
15786 #endif
15787 #endif
15788 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
15789 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
15790 index ea69726..604d066 100644
15791 --- a/arch/x86/kernel/ldt.c
15792 +++ b/arch/x86/kernel/ldt.c
15793 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
15794 if (reload) {
15795 #ifdef CONFIG_SMP
15796 preempt_disable();
15797 - load_LDT(pc);
15798 + load_LDT_nolock(pc);
15799 if (!cpumask_equal(mm_cpumask(current->mm),
15800 cpumask_of(smp_processor_id())))
15801 smp_call_function(flush_ldt, current->mm, 1);
15802 preempt_enable();
15803 #else
15804 - load_LDT(pc);
15805 + load_LDT_nolock(pc);
15806 #endif
15807 }
15808 if (oldsize) {
15809 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
15810 return err;
15811
15812 for (i = 0; i < old->size; i++)
15813 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
15814 + write_ldt_entry(new->ldt, i, old->ldt + i);
15815 return 0;
15816 }
15817
15818 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
15819 retval = copy_ldt(&mm->context, &old_mm->context);
15820 mutex_unlock(&old_mm->context.lock);
15821 }
15822 +
15823 + if (tsk == current) {
15824 + mm->context.vdso = 0;
15825 +
15826 +#ifdef CONFIG_X86_32
15827 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15828 + mm->context.user_cs_base = 0UL;
15829 + mm->context.user_cs_limit = ~0UL;
15830 +
15831 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15832 + cpus_clear(mm->context.cpu_user_cs_mask);
15833 +#endif
15834 +
15835 +#endif
15836 +#endif
15837 +
15838 + }
15839 +
15840 return retval;
15841 }
15842
15843 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
15844 }
15845 }
15846
15847 +#ifdef CONFIG_PAX_SEGMEXEC
15848 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
15849 + error = -EINVAL;
15850 + goto out_unlock;
15851 + }
15852 +#endif
15853 +
15854 fill_ldt(&ldt, &ldt_info);
15855 if (oldmode)
15856 ldt.avl = 0;
15857 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
15858 index a3fa43b..8966f4c 100644
15859 --- a/arch/x86/kernel/machine_kexec_32.c
15860 +++ b/arch/x86/kernel/machine_kexec_32.c
15861 @@ -27,7 +27,7 @@
15862 #include <asm/cacheflush.h>
15863 #include <asm/debugreg.h>
15864
15865 -static void set_idt(void *newidt, __u16 limit)
15866 +static void set_idt(struct desc_struct *newidt, __u16 limit)
15867 {
15868 struct desc_ptr curidt;
15869
15870 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
15871 }
15872
15873
15874 -static void set_gdt(void *newgdt, __u16 limit)
15875 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
15876 {
15877 struct desc_ptr curgdt;
15878
15879 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
15880 }
15881
15882 control_page = page_address(image->control_code_page);
15883 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
15884 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
15885
15886 relocate_kernel_ptr = control_page;
15887 page_list[PA_CONTROL_PAGE] = __pa(control_page);
15888 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
15889 index 3ca42d0..7cff8cc 100644
15890 --- a/arch/x86/kernel/microcode_intel.c
15891 +++ b/arch/x86/kernel/microcode_intel.c
15892 @@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
15893
15894 static int get_ucode_user(void *to, const void *from, size_t n)
15895 {
15896 - return copy_from_user(to, from, n);
15897 + return copy_from_user(to, (const void __force_user *)from, n);
15898 }
15899
15900 static enum ucode_state
15901 request_microcode_user(int cpu, const void __user *buf, size_t size)
15902 {
15903 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
15904 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
15905 }
15906
15907 static void microcode_fini_cpu(int cpu)
15908 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
15909 index 925179f..267ac7a 100644
15910 --- a/arch/x86/kernel/module.c
15911 +++ b/arch/x86/kernel/module.c
15912 @@ -36,15 +36,60 @@
15913 #define DEBUGP(fmt...)
15914 #endif
15915
15916 -void *module_alloc(unsigned long size)
15917 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
15918 {
15919 - if (PAGE_ALIGN(size) > MODULES_LEN)
15920 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
15921 return NULL;
15922 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
15923 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
15924 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
15925 -1, __builtin_return_address(0));
15926 }
15927
15928 +void *module_alloc(unsigned long size)
15929 +{
15930 +
15931 +#ifdef CONFIG_PAX_KERNEXEC
15932 + return __module_alloc(size, PAGE_KERNEL);
15933 +#else
15934 + return __module_alloc(size, PAGE_KERNEL_EXEC);
15935 +#endif
15936 +
15937 +}
15938 +
15939 +#ifdef CONFIG_PAX_KERNEXEC
15940 +#ifdef CONFIG_X86_32
15941 +void *module_alloc_exec(unsigned long size)
15942 +{
15943 + struct vm_struct *area;
15944 +
15945 + if (size == 0)
15946 + return NULL;
15947 +
15948 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
15949 + return area ? area->addr : NULL;
15950 +}
15951 +EXPORT_SYMBOL(module_alloc_exec);
15952 +
15953 +void module_free_exec(struct module *mod, void *module_region)
15954 +{
15955 + vunmap(module_region);
15956 +}
15957 +EXPORT_SYMBOL(module_free_exec);
15958 +#else
15959 +void module_free_exec(struct module *mod, void *module_region)
15960 +{
15961 + module_free(mod, module_region);
15962 +}
15963 +EXPORT_SYMBOL(module_free_exec);
15964 +
15965 +void *module_alloc_exec(unsigned long size)
15966 +{
15967 + return __module_alloc(size, PAGE_KERNEL_RX);
15968 +}
15969 +EXPORT_SYMBOL(module_alloc_exec);
15970 +#endif
15971 +#endif
15972 +
15973 #ifdef CONFIG_X86_32
15974 int apply_relocate(Elf32_Shdr *sechdrs,
15975 const char *strtab,
15976 @@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15977 unsigned int i;
15978 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
15979 Elf32_Sym *sym;
15980 - uint32_t *location;
15981 + uint32_t *plocation, location;
15982
15983 DEBUGP("Applying relocate section %u to %u\n", relsec,
15984 sechdrs[relsec].sh_info);
15985 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
15986 /* This is where to make the change */
15987 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
15988 - + rel[i].r_offset;
15989 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
15990 + location = (uint32_t)plocation;
15991 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
15992 + plocation = ktla_ktva((void *)plocation);
15993 /* This is the symbol it is referring to. Note that all
15994 undefined symbols have been resolved. */
15995 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
15996 @@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15997 switch (ELF32_R_TYPE(rel[i].r_info)) {
15998 case R_386_32:
15999 /* We add the value into the location given */
16000 - *location += sym->st_value;
16001 + pax_open_kernel();
16002 + *plocation += sym->st_value;
16003 + pax_close_kernel();
16004 break;
16005 case R_386_PC32:
16006 /* Add the value, subtract its postition */
16007 - *location += sym->st_value - (uint32_t)location;
16008 + pax_open_kernel();
16009 + *plocation += sym->st_value - location;
16010 + pax_close_kernel();
16011 break;
16012 default:
16013 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
16014 @@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
16015 case R_X86_64_NONE:
16016 break;
16017 case R_X86_64_64:
16018 + pax_open_kernel();
16019 *(u64 *)loc = val;
16020 + pax_close_kernel();
16021 break;
16022 case R_X86_64_32:
16023 + pax_open_kernel();
16024 *(u32 *)loc = val;
16025 + pax_close_kernel();
16026 if (val != *(u32 *)loc)
16027 goto overflow;
16028 break;
16029 case R_X86_64_32S:
16030 + pax_open_kernel();
16031 *(s32 *)loc = val;
16032 + pax_close_kernel();
16033 if ((s64)val != *(s32 *)loc)
16034 goto overflow;
16035 break;
16036 case R_X86_64_PC32:
16037 val -= (u64)loc;
16038 + pax_open_kernel();
16039 *(u32 *)loc = val;
16040 + pax_close_kernel();
16041 +
16042 #if 0
16043 if ((s64)val != *(s32 *)loc)
16044 goto overflow;
16045 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
16046 index e88f37b..1353db6 100644
16047 --- a/arch/x86/kernel/nmi.c
16048 +++ b/arch/x86/kernel/nmi.c
16049 @@ -408,6 +408,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
16050 dotraplinkage notrace __kprobes void
16051 do_nmi(struct pt_regs *regs, long error_code)
16052 {
16053 +
16054 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16055 + if (!user_mode(regs)) {
16056 + unsigned long cs = regs->cs & 0xFFFF;
16057 + unsigned long ip = ktva_ktla(regs->ip);
16058 +
16059 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
16060 + regs->ip = ip;
16061 + }
16062 +#endif
16063 +
16064 nmi_enter();
16065
16066 inc_irq_stat(__nmi_count);
16067 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
16068 index 676b8c7..870ba04 100644
16069 --- a/arch/x86/kernel/paravirt-spinlocks.c
16070 +++ b/arch/x86/kernel/paravirt-spinlocks.c
16071 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
16072 arch_spin_lock(lock);
16073 }
16074
16075 -struct pv_lock_ops pv_lock_ops = {
16076 +struct pv_lock_ops pv_lock_ops __read_only = {
16077 #ifdef CONFIG_SMP
16078 .spin_is_locked = __ticket_spin_is_locked,
16079 .spin_is_contended = __ticket_spin_is_contended,
16080 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
16081 index d90272e..6bb013b 100644
16082 --- a/arch/x86/kernel/paravirt.c
16083 +++ b/arch/x86/kernel/paravirt.c
16084 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
16085 {
16086 return x;
16087 }
16088 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16089 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
16090 +#endif
16091
16092 void __init default_banner(void)
16093 {
16094 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
16095 if (opfunc == NULL)
16096 /* If there's no function, patch it with a ud2a (BUG) */
16097 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16098 - else if (opfunc == _paravirt_nop)
16099 + else if (opfunc == (void *)_paravirt_nop)
16100 /* If the operation is a nop, then nop the callsite */
16101 ret = paravirt_patch_nop();
16102
16103 /* identity functions just return their single argument */
16104 - else if (opfunc == _paravirt_ident_32)
16105 + else if (opfunc == (void *)_paravirt_ident_32)
16106 ret = paravirt_patch_ident_32(insnbuf, len);
16107 - else if (opfunc == _paravirt_ident_64)
16108 + else if (opfunc == (void *)_paravirt_ident_64)
16109 ret = paravirt_patch_ident_64(insnbuf, len);
16110 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16111 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
16112 + ret = paravirt_patch_ident_64(insnbuf, len);
16113 +#endif
16114
16115 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16116 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
16117 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
16118 if (insn_len > len || start == NULL)
16119 insn_len = len;
16120 else
16121 - memcpy(insnbuf, start, insn_len);
16122 + memcpy(insnbuf, ktla_ktva(start), insn_len);
16123
16124 return insn_len;
16125 }
16126 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
16127 preempt_enable();
16128 }
16129
16130 -struct pv_info pv_info = {
16131 +struct pv_info pv_info __read_only = {
16132 .name = "bare hardware",
16133 .paravirt_enabled = 0,
16134 .kernel_rpl = 0,
16135 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
16136 #endif
16137 };
16138
16139 -struct pv_init_ops pv_init_ops = {
16140 +struct pv_init_ops pv_init_ops __read_only = {
16141 .patch = native_patch,
16142 };
16143
16144 -struct pv_time_ops pv_time_ops = {
16145 +struct pv_time_ops pv_time_ops __read_only = {
16146 .sched_clock = native_sched_clock,
16147 .steal_clock = native_steal_clock,
16148 };
16149
16150 -struct pv_irq_ops pv_irq_ops = {
16151 +struct pv_irq_ops pv_irq_ops __read_only = {
16152 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16153 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16154 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16155 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
16156 #endif
16157 };
16158
16159 -struct pv_cpu_ops pv_cpu_ops = {
16160 +struct pv_cpu_ops pv_cpu_ops __read_only = {
16161 .cpuid = native_cpuid,
16162 .get_debugreg = native_get_debugreg,
16163 .set_debugreg = native_set_debugreg,
16164 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
16165 .end_context_switch = paravirt_nop,
16166 };
16167
16168 -struct pv_apic_ops pv_apic_ops = {
16169 +struct pv_apic_ops pv_apic_ops __read_only = {
16170 #ifdef CONFIG_X86_LOCAL_APIC
16171 .startup_ipi_hook = paravirt_nop,
16172 #endif
16173 };
16174
16175 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
16176 +#ifdef CONFIG_X86_32
16177 +#ifdef CONFIG_X86_PAE
16178 +/* 64-bit pagetable entries */
16179 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
16180 +#else
16181 /* 32-bit pagetable entries */
16182 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
16183 +#endif
16184 #else
16185 /* 64-bit pagetable entries */
16186 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16187 #endif
16188
16189 -struct pv_mmu_ops pv_mmu_ops = {
16190 +struct pv_mmu_ops pv_mmu_ops __read_only = {
16191
16192 .read_cr2 = native_read_cr2,
16193 .write_cr2 = native_write_cr2,
16194 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
16195 .make_pud = PTE_IDENT,
16196
16197 .set_pgd = native_set_pgd,
16198 + .set_pgd_batched = native_set_pgd_batched,
16199 #endif
16200 #endif /* PAGETABLE_LEVELS >= 3 */
16201
16202 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
16203 },
16204
16205 .set_fixmap = native_set_fixmap,
16206 +
16207 +#ifdef CONFIG_PAX_KERNEXEC
16208 + .pax_open_kernel = native_pax_open_kernel,
16209 + .pax_close_kernel = native_pax_close_kernel,
16210 +#endif
16211 +
16212 };
16213
16214 EXPORT_SYMBOL_GPL(pv_time_ops);
16215 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
16216 index 35ccf75..7a15747 100644
16217 --- a/arch/x86/kernel/pci-iommu_table.c
16218 +++ b/arch/x86/kernel/pci-iommu_table.c
16219 @@ -2,7 +2,7 @@
16220 #include <asm/iommu_table.h>
16221 #include <linux/string.h>
16222 #include <linux/kallsyms.h>
16223 -
16224 +#include <linux/sched.h>
16225
16226 #define DEBUG 1
16227
16228 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
16229 index ee5d4fb..426649b 100644
16230 --- a/arch/x86/kernel/process.c
16231 +++ b/arch/x86/kernel/process.c
16232 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
16233
16234 void free_thread_info(struct thread_info *ti)
16235 {
16236 - free_thread_xstate(ti->task);
16237 free_pages((unsigned long)ti, THREAD_ORDER);
16238 }
16239
16240 +static struct kmem_cache *task_struct_cachep;
16241 +
16242 void arch_task_cache_init(void)
16243 {
16244 - task_xstate_cachep =
16245 - kmem_cache_create("task_xstate", xstate_size,
16246 + /* create a slab on which task_structs can be allocated */
16247 + task_struct_cachep =
16248 + kmem_cache_create("task_struct", sizeof(struct task_struct),
16249 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16250 +
16251 + task_xstate_cachep =
16252 + kmem_cache_create("task_xstate", xstate_size,
16253 __alignof__(union thread_xstate),
16254 - SLAB_PANIC | SLAB_NOTRACK, NULL);
16255 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16256 +}
16257 +
16258 +struct task_struct *alloc_task_struct_node(int node)
16259 +{
16260 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
16261 +}
16262 +
16263 +void free_task_struct(struct task_struct *task)
16264 +{
16265 + free_thread_xstate(task);
16266 + kmem_cache_free(task_struct_cachep, task);
16267 }
16268
16269 /*
16270 @@ -70,7 +87,7 @@ void exit_thread(void)
16271 unsigned long *bp = t->io_bitmap_ptr;
16272
16273 if (bp) {
16274 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16275 + struct tss_struct *tss = init_tss + get_cpu();
16276
16277 t->io_bitmap_ptr = NULL;
16278 clear_thread_flag(TIF_IO_BITMAP);
16279 @@ -106,7 +123,7 @@ void show_regs_common(void)
16280
16281 printk(KERN_CONT "\n");
16282 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
16283 - current->pid, current->comm, print_tainted(),
16284 + task_pid_nr(current), current->comm, print_tainted(),
16285 init_utsname()->release,
16286 (int)strcspn(init_utsname()->version, " "),
16287 init_utsname()->version);
16288 @@ -120,6 +137,9 @@ void flush_thread(void)
16289 {
16290 struct task_struct *tsk = current;
16291
16292 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16293 + loadsegment(gs, 0);
16294 +#endif
16295 flush_ptrace_hw_breakpoint(tsk);
16296 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
16297 /*
16298 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
16299 regs.di = (unsigned long) arg;
16300
16301 #ifdef CONFIG_X86_32
16302 - regs.ds = __USER_DS;
16303 - regs.es = __USER_DS;
16304 + regs.ds = __KERNEL_DS;
16305 + regs.es = __KERNEL_DS;
16306 regs.fs = __KERNEL_PERCPU;
16307 - regs.gs = __KERNEL_STACK_CANARY;
16308 + savesegment(gs, regs.gs);
16309 #else
16310 regs.ss = __KERNEL_DS;
16311 #endif
16312 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
16313
16314 return ret;
16315 }
16316 -void stop_this_cpu(void *dummy)
16317 +__noreturn void stop_this_cpu(void *dummy)
16318 {
16319 local_irq_disable();
16320 /*
16321 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
16322 }
16323 early_param("idle", idle_setup);
16324
16325 -unsigned long arch_align_stack(unsigned long sp)
16326 +#ifdef CONFIG_PAX_RANDKSTACK
16327 +void pax_randomize_kstack(struct pt_regs *regs)
16328 {
16329 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16330 - sp -= get_random_int() % 8192;
16331 - return sp & ~0xf;
16332 -}
16333 + struct thread_struct *thread = &current->thread;
16334 + unsigned long time;
16335
16336 -unsigned long arch_randomize_brk(struct mm_struct *mm)
16337 -{
16338 - unsigned long range_end = mm->brk + 0x02000000;
16339 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16340 -}
16341 + if (!randomize_va_space)
16342 + return;
16343 +
16344 + if (v8086_mode(regs))
16345 + return;
16346
16347 + rdtscl(time);
16348 +
16349 + /* P4 seems to return a 0 LSB, ignore it */
16350 +#ifdef CONFIG_MPENTIUM4
16351 + time &= 0x3EUL;
16352 + time <<= 2;
16353 +#elif defined(CONFIG_X86_64)
16354 + time &= 0xFUL;
16355 + time <<= 4;
16356 +#else
16357 + time &= 0x1FUL;
16358 + time <<= 3;
16359 +#endif
16360 +
16361 + thread->sp0 ^= time;
16362 + load_sp0(init_tss + smp_processor_id(), thread);
16363 +
16364 +#ifdef CONFIG_X86_64
16365 + percpu_write(kernel_stack, thread->sp0);
16366 +#endif
16367 +}
16368 +#endif
16369 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
16370 index 795b79f..063767a 100644
16371 --- a/arch/x86/kernel/process_32.c
16372 +++ b/arch/x86/kernel/process_32.c
16373 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
16374 unsigned long thread_saved_pc(struct task_struct *tsk)
16375 {
16376 return ((unsigned long *)tsk->thread.sp)[3];
16377 +//XXX return tsk->thread.eip;
16378 }
16379
16380 #ifndef CONFIG_SMP
16381 @@ -130,15 +131,14 @@ void __show_regs(struct pt_regs *regs, int all)
16382 unsigned long sp;
16383 unsigned short ss, gs;
16384
16385 - if (user_mode_vm(regs)) {
16386 + if (user_mode(regs)) {
16387 sp = regs->sp;
16388 ss = regs->ss & 0xffff;
16389 - gs = get_user_gs(regs);
16390 } else {
16391 sp = kernel_stack_pointer(regs);
16392 savesegment(ss, ss);
16393 - savesegment(gs, gs);
16394 }
16395 + gs = get_user_gs(regs);
16396
16397 show_regs_common();
16398
16399 @@ -200,13 +200,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16400 struct task_struct *tsk;
16401 int err;
16402
16403 - childregs = task_pt_regs(p);
16404 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16405 *childregs = *regs;
16406 childregs->ax = 0;
16407 childregs->sp = sp;
16408
16409 p->thread.sp = (unsigned long) childregs;
16410 p->thread.sp0 = (unsigned long) (childregs+1);
16411 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16412
16413 p->thread.ip = (unsigned long) ret_from_fork;
16414
16415 @@ -296,7 +297,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16416 struct thread_struct *prev = &prev_p->thread,
16417 *next = &next_p->thread;
16418 int cpu = smp_processor_id();
16419 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16420 + struct tss_struct *tss = init_tss + cpu;
16421 bool preload_fpu;
16422
16423 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16424 @@ -331,6 +332,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16425 */
16426 lazy_save_gs(prev->gs);
16427
16428 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16429 + __set_fs(task_thread_info(next_p)->addr_limit);
16430 +#endif
16431 +
16432 /*
16433 * Load the per-thread Thread-Local Storage descriptor.
16434 */
16435 @@ -366,6 +371,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16436 */
16437 arch_end_context_switch(next_p);
16438
16439 + percpu_write(current_task, next_p);
16440 + percpu_write(current_tinfo, &next_p->tinfo);
16441 +
16442 if (preload_fpu)
16443 __math_state_restore();
16444
16445 @@ -375,8 +383,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16446 if (prev->gs | next->gs)
16447 lazy_load_gs(next->gs);
16448
16449 - percpu_write(current_task, next_p);
16450 -
16451 return prev_p;
16452 }
16453
16454 @@ -406,4 +412,3 @@ unsigned long get_wchan(struct task_struct *p)
16455 } while (count++ < 16);
16456 return 0;
16457 }
16458 -
16459 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
16460 index 3bd7e6e..90b2bcf 100644
16461 --- a/arch/x86/kernel/process_64.c
16462 +++ b/arch/x86/kernel/process_64.c
16463 @@ -89,7 +89,7 @@ static void __exit_idle(void)
16464 void exit_idle(void)
16465 {
16466 /* idle loop has pid 0 */
16467 - if (current->pid)
16468 + if (task_pid_nr(current))
16469 return;
16470 __exit_idle();
16471 }
16472 @@ -264,8 +264,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16473 struct pt_regs *childregs;
16474 struct task_struct *me = current;
16475
16476 - childregs = ((struct pt_regs *)
16477 - (THREAD_SIZE + task_stack_page(p))) - 1;
16478 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16479 *childregs = *regs;
16480
16481 childregs->ax = 0;
16482 @@ -277,6 +276,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16483 p->thread.sp = (unsigned long) childregs;
16484 p->thread.sp0 = (unsigned long) (childregs+1);
16485 p->thread.usersp = me->thread.usersp;
16486 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16487
16488 set_tsk_thread_flag(p, TIF_FORK);
16489
16490 @@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16491 struct thread_struct *prev = &prev_p->thread;
16492 struct thread_struct *next = &next_p->thread;
16493 int cpu = smp_processor_id();
16494 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16495 + struct tss_struct *tss = init_tss + cpu;
16496 unsigned fsindex, gsindex;
16497 bool preload_fpu;
16498
16499 @@ -475,10 +475,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16500 prev->usersp = percpu_read(old_rsp);
16501 percpu_write(old_rsp, next->usersp);
16502 percpu_write(current_task, next_p);
16503 + percpu_write(current_tinfo, &next_p->tinfo);
16504
16505 - percpu_write(kernel_stack,
16506 - (unsigned long)task_stack_page(next_p) +
16507 - THREAD_SIZE - KERNEL_STACK_OFFSET);
16508 + percpu_write(kernel_stack, next->sp0);
16509
16510 /*
16511 * Now maybe reload the debug registers and handle I/O bitmaps
16512 @@ -540,12 +539,11 @@ unsigned long get_wchan(struct task_struct *p)
16513 if (!p || p == current || p->state == TASK_RUNNING)
16514 return 0;
16515 stack = (unsigned long)task_stack_page(p);
16516 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16517 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16518 return 0;
16519 fp = *(u64 *)(p->thread.sp);
16520 do {
16521 - if (fp < (unsigned long)stack ||
16522 - fp >= (unsigned long)stack+THREAD_SIZE)
16523 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16524 return 0;
16525 ip = *(u64 *)(fp+8);
16526 if (!in_sched_functions(ip))
16527 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
16528 index 8252879..d3219e0 100644
16529 --- a/arch/x86/kernel/ptrace.c
16530 +++ b/arch/x86/kernel/ptrace.c
16531 @@ -822,7 +822,7 @@ long arch_ptrace(struct task_struct *child, long request,
16532 unsigned long addr, unsigned long data)
16533 {
16534 int ret;
16535 - unsigned long __user *datap = (unsigned long __user *)data;
16536 + unsigned long __user *datap = (__force unsigned long __user *)data;
16537
16538 switch (request) {
16539 /* read the word at location addr in the USER area. */
16540 @@ -907,14 +907,14 @@ long arch_ptrace(struct task_struct *child, long request,
16541 if ((int) addr < 0)
16542 return -EIO;
16543 ret = do_get_thread_area(child, addr,
16544 - (struct user_desc __user *)data);
16545 + (__force struct user_desc __user *) data);
16546 break;
16547
16548 case PTRACE_SET_THREAD_AREA:
16549 if ((int) addr < 0)
16550 return -EIO;
16551 ret = do_set_thread_area(child, addr,
16552 - (struct user_desc __user *)data, 0);
16553 + (__force struct user_desc __user *) data, 0);
16554 break;
16555 #endif
16556
16557 @@ -1331,7 +1331,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
16558 memset(info, 0, sizeof(*info));
16559 info->si_signo = SIGTRAP;
16560 info->si_code = si_code;
16561 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
16562 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
16563 }
16564
16565 void user_single_step_siginfo(struct task_struct *tsk,
16566 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
16567 index 42eb330..139955c 100644
16568 --- a/arch/x86/kernel/pvclock.c
16569 +++ b/arch/x86/kernel/pvclock.c
16570 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
16571 return pv_tsc_khz;
16572 }
16573
16574 -static atomic64_t last_value = ATOMIC64_INIT(0);
16575 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
16576
16577 void pvclock_resume(void)
16578 {
16579 - atomic64_set(&last_value, 0);
16580 + atomic64_set_unchecked(&last_value, 0);
16581 }
16582
16583 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16584 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16585 * updating at the same time, and one of them could be slightly behind,
16586 * making the assumption that last_value always go forward fail to hold.
16587 */
16588 - last = atomic64_read(&last_value);
16589 + last = atomic64_read_unchecked(&last_value);
16590 do {
16591 if (ret < last)
16592 return last;
16593 - last = atomic64_cmpxchg(&last_value, last, ret);
16594 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
16595 } while (unlikely(last != ret));
16596
16597 return ret;
16598 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
16599 index 37a458b..e63d183 100644
16600 --- a/arch/x86/kernel/reboot.c
16601 +++ b/arch/x86/kernel/reboot.c
16602 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
16603 EXPORT_SYMBOL(pm_power_off);
16604
16605 static const struct desc_ptr no_idt = {};
16606 -static int reboot_mode;
16607 +static unsigned short reboot_mode;
16608 enum reboot_type reboot_type = BOOT_ACPI;
16609 int reboot_force;
16610
16611 @@ -324,13 +324,17 @@ core_initcall(reboot_init);
16612 extern const unsigned char machine_real_restart_asm[];
16613 extern const u64 machine_real_restart_gdt[3];
16614
16615 -void machine_real_restart(unsigned int type)
16616 +__noreturn void machine_real_restart(unsigned int type)
16617 {
16618 void *restart_va;
16619 unsigned long restart_pa;
16620 - void (*restart_lowmem)(unsigned int);
16621 + void (* __noreturn restart_lowmem)(unsigned int);
16622 u64 *lowmem_gdt;
16623
16624 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16625 + struct desc_struct *gdt;
16626 +#endif
16627 +
16628 local_irq_disable();
16629
16630 /* Write zero to CMOS register number 0x0f, which the BIOS POST
16631 @@ -356,14 +360,14 @@ void machine_real_restart(unsigned int type)
16632 boot)". This seems like a fairly standard thing that gets set by
16633 REBOOT.COM programs, and the previous reset routine did this
16634 too. */
16635 - *((unsigned short *)0x472) = reboot_mode;
16636 + *(unsigned short *)(__va(0x472)) = reboot_mode;
16637
16638 /* Patch the GDT in the low memory trampoline */
16639 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
16640
16641 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
16642 restart_pa = virt_to_phys(restart_va);
16643 - restart_lowmem = (void (*)(unsigned int))restart_pa;
16644 + restart_lowmem = (void *)restart_pa;
16645
16646 /* GDT[0]: GDT self-pointer */
16647 lowmem_gdt[0] =
16648 @@ -374,7 +378,33 @@ void machine_real_restart(unsigned int type)
16649 GDT_ENTRY(0x009b, restart_pa, 0xffff);
16650
16651 /* Jump to the identity-mapped low memory code */
16652 +
16653 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16654 + gdt = get_cpu_gdt_table(smp_processor_id());
16655 + pax_open_kernel();
16656 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16657 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
16658 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
16659 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
16660 +#endif
16661 +#ifdef CONFIG_PAX_KERNEXEC
16662 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
16663 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
16664 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
16665 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
16666 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
16667 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
16668 +#endif
16669 + pax_close_kernel();
16670 +#endif
16671 +
16672 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16673 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
16674 + unreachable();
16675 +#else
16676 restart_lowmem(type);
16677 +#endif
16678 +
16679 }
16680 #ifdef CONFIG_APM_MODULE
16681 EXPORT_SYMBOL(machine_real_restart);
16682 @@ -540,7 +570,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
16683 * try to force a triple fault and then cycle between hitting the keyboard
16684 * controller and doing that
16685 */
16686 -static void native_machine_emergency_restart(void)
16687 +__noreturn static void native_machine_emergency_restart(void)
16688 {
16689 int i;
16690 int attempt = 0;
16691 @@ -664,13 +694,13 @@ void native_machine_shutdown(void)
16692 #endif
16693 }
16694
16695 -static void __machine_emergency_restart(int emergency)
16696 +static __noreturn void __machine_emergency_restart(int emergency)
16697 {
16698 reboot_emergency = emergency;
16699 machine_ops.emergency_restart();
16700 }
16701
16702 -static void native_machine_restart(char *__unused)
16703 +static __noreturn void native_machine_restart(char *__unused)
16704 {
16705 printk("machine restart\n");
16706
16707 @@ -679,7 +709,7 @@ static void native_machine_restart(char *__unused)
16708 __machine_emergency_restart(0);
16709 }
16710
16711 -static void native_machine_halt(void)
16712 +static __noreturn void native_machine_halt(void)
16713 {
16714 /* stop other cpus and apics */
16715 machine_shutdown();
16716 @@ -690,7 +720,7 @@ static void native_machine_halt(void)
16717 stop_this_cpu(NULL);
16718 }
16719
16720 -static void native_machine_power_off(void)
16721 +__noreturn static void native_machine_power_off(void)
16722 {
16723 if (pm_power_off) {
16724 if (!reboot_force)
16725 @@ -699,6 +729,7 @@ static void native_machine_power_off(void)
16726 }
16727 /* a fallback in case there is no PM info available */
16728 tboot_shutdown(TB_SHUTDOWN_HALT);
16729 + unreachable();
16730 }
16731
16732 struct machine_ops machine_ops = {
16733 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
16734 index 7a6f3b3..bed145d7 100644
16735 --- a/arch/x86/kernel/relocate_kernel_64.S
16736 +++ b/arch/x86/kernel/relocate_kernel_64.S
16737 @@ -11,6 +11,7 @@
16738 #include <asm/kexec.h>
16739 #include <asm/processor-flags.h>
16740 #include <asm/pgtable_types.h>
16741 +#include <asm/alternative-asm.h>
16742
16743 /*
16744 * Must be relocatable PIC code callable as a C function
16745 @@ -160,13 +161,14 @@ identity_mapped:
16746 xorq %rbp, %rbp
16747 xorq %r8, %r8
16748 xorq %r9, %r9
16749 - xorq %r10, %r9
16750 + xorq %r10, %r10
16751 xorq %r11, %r11
16752 xorq %r12, %r12
16753 xorq %r13, %r13
16754 xorq %r14, %r14
16755 xorq %r15, %r15
16756
16757 + pax_force_retaddr 0, 1
16758 ret
16759
16760 1:
16761 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
16762 index cf0ef98..e3f780b 100644
16763 --- a/arch/x86/kernel/setup.c
16764 +++ b/arch/x86/kernel/setup.c
16765 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
16766
16767 switch (data->type) {
16768 case SETUP_E820_EXT:
16769 - parse_e820_ext(data);
16770 + parse_e820_ext((struct setup_data __force_kernel *)data);
16771 break;
16772 case SETUP_DTB:
16773 add_dtb(pa_data);
16774 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
16775 * area (640->1Mb) as ram even though it is not.
16776 * take them out.
16777 */
16778 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
16779 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
16780 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
16781 }
16782
16783 @@ -773,14 +773,14 @@ void __init setup_arch(char **cmdline_p)
16784
16785 if (!boot_params.hdr.root_flags)
16786 root_mountflags &= ~MS_RDONLY;
16787 - init_mm.start_code = (unsigned long) _text;
16788 - init_mm.end_code = (unsigned long) _etext;
16789 + init_mm.start_code = ktla_ktva((unsigned long) _text);
16790 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
16791 init_mm.end_data = (unsigned long) _edata;
16792 init_mm.brk = _brk_end;
16793
16794 - code_resource.start = virt_to_phys(_text);
16795 - code_resource.end = virt_to_phys(_etext)-1;
16796 - data_resource.start = virt_to_phys(_etext);
16797 + code_resource.start = virt_to_phys(ktla_ktva(_text));
16798 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
16799 + data_resource.start = virt_to_phys(_sdata);
16800 data_resource.end = virt_to_phys(_edata)-1;
16801 bss_resource.start = virt_to_phys(&__bss_start);
16802 bss_resource.end = virt_to_phys(&__bss_stop)-1;
16803 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
16804 index 71f4727..16dc9f7 100644
16805 --- a/arch/x86/kernel/setup_percpu.c
16806 +++ b/arch/x86/kernel/setup_percpu.c
16807 @@ -21,19 +21,17 @@
16808 #include <asm/cpu.h>
16809 #include <asm/stackprotector.h>
16810
16811 -DEFINE_PER_CPU(int, cpu_number);
16812 +#ifdef CONFIG_SMP
16813 +DEFINE_PER_CPU(unsigned int, cpu_number);
16814 EXPORT_PER_CPU_SYMBOL(cpu_number);
16815 +#endif
16816
16817 -#ifdef CONFIG_X86_64
16818 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
16819 -#else
16820 -#define BOOT_PERCPU_OFFSET 0
16821 -#endif
16822
16823 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
16824 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
16825
16826 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
16827 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
16828 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
16829 };
16830 EXPORT_SYMBOL(__per_cpu_offset);
16831 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
16832 {
16833 #ifdef CONFIG_X86_32
16834 struct desc_struct gdt;
16835 + unsigned long base = per_cpu_offset(cpu);
16836
16837 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
16838 - 0x2 | DESCTYPE_S, 0x8);
16839 - gdt.s = 1;
16840 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
16841 + 0x83 | DESCTYPE_S, 0xC);
16842 write_gdt_entry(get_cpu_gdt_table(cpu),
16843 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
16844 #endif
16845 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
16846 /* alrighty, percpu areas up and running */
16847 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
16848 for_each_possible_cpu(cpu) {
16849 +#ifdef CONFIG_CC_STACKPROTECTOR
16850 +#ifdef CONFIG_X86_32
16851 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
16852 +#endif
16853 +#endif
16854 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
16855 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
16856 per_cpu(cpu_number, cpu) = cpu;
16857 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
16858 */
16859 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
16860 #endif
16861 +#ifdef CONFIG_CC_STACKPROTECTOR
16862 +#ifdef CONFIG_X86_32
16863 + if (!cpu)
16864 + per_cpu(stack_canary.canary, cpu) = canary;
16865 +#endif
16866 +#endif
16867 /*
16868 * Up to this point, the boot CPU has been using .init.data
16869 * area. Reload any changed state for the boot CPU.
16870 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
16871 index 54ddaeb2..22c3bdc 100644
16872 --- a/arch/x86/kernel/signal.c
16873 +++ b/arch/x86/kernel/signal.c
16874 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
16875 * Align the stack pointer according to the i386 ABI,
16876 * i.e. so that on function entry ((sp + 4) & 15) == 0.
16877 */
16878 - sp = ((sp + 4) & -16ul) - 4;
16879 + sp = ((sp - 12) & -16ul) - 4;
16880 #else /* !CONFIG_X86_32 */
16881 sp = round_down(sp, 16) - 8;
16882 #endif
16883 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
16884 * Return an always-bogus address instead so we will die with SIGSEGV.
16885 */
16886 if (onsigstack && !likely(on_sig_stack(sp)))
16887 - return (void __user *)-1L;
16888 + return (__force void __user *)-1L;
16889
16890 /* save i387 state */
16891 if (used_math() && save_i387_xstate(*fpstate) < 0)
16892 - return (void __user *)-1L;
16893 + return (__force void __user *)-1L;
16894
16895 return (void __user *)sp;
16896 }
16897 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
16898 }
16899
16900 if (current->mm->context.vdso)
16901 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
16902 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
16903 else
16904 - restorer = &frame->retcode;
16905 + restorer = (void __user *)&frame->retcode;
16906 if (ka->sa.sa_flags & SA_RESTORER)
16907 restorer = ka->sa.sa_restorer;
16908
16909 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
16910 * reasons and because gdb uses it as a signature to notice
16911 * signal handler stack frames.
16912 */
16913 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
16914 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
16915
16916 if (err)
16917 return -EFAULT;
16918 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
16919 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
16920
16921 /* Set up to return from userspace. */
16922 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
16923 + if (current->mm->context.vdso)
16924 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
16925 + else
16926 + restorer = (void __user *)&frame->retcode;
16927 if (ka->sa.sa_flags & SA_RESTORER)
16928 restorer = ka->sa.sa_restorer;
16929 put_user_ex(restorer, &frame->pretcode);
16930 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
16931 * reasons and because gdb uses it as a signature to notice
16932 * signal handler stack frames.
16933 */
16934 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
16935 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
16936 } put_user_catch(err);
16937
16938 if (err)
16939 @@ -769,7 +772,7 @@ static void do_signal(struct pt_regs *regs)
16940 * X86_32: vm86 regs switched out by assembly code before reaching
16941 * here, so testing against kernel CS suffices.
16942 */
16943 - if (!user_mode(regs))
16944 + if (!user_mode_novm(regs))
16945 return;
16946
16947 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
16948 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
16949 index 9f548cb..caf76f7 100644
16950 --- a/arch/x86/kernel/smpboot.c
16951 +++ b/arch/x86/kernel/smpboot.c
16952 @@ -709,17 +709,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
16953 set_idle_for_cpu(cpu, c_idle.idle);
16954 do_rest:
16955 per_cpu(current_task, cpu) = c_idle.idle;
16956 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
16957 #ifdef CONFIG_X86_32
16958 /* Stack for startup_32 can be just as for start_secondary onwards */
16959 irq_ctx_init(cpu);
16960 #else
16961 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
16962 initial_gs = per_cpu_offset(cpu);
16963 - per_cpu(kernel_stack, cpu) =
16964 - (unsigned long)task_stack_page(c_idle.idle) -
16965 - KERNEL_STACK_OFFSET + THREAD_SIZE;
16966 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
16967 #endif
16968 +
16969 + pax_open_kernel();
16970 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16971 + pax_close_kernel();
16972 +
16973 initial_code = (unsigned long)start_secondary;
16974 stack_start = c_idle.idle->thread.sp;
16975
16976 @@ -861,6 +864,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
16977
16978 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
16979
16980 +#ifdef CONFIG_PAX_PER_CPU_PGD
16981 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
16982 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
16983 + KERNEL_PGD_PTRS);
16984 +#endif
16985 +
16986 err = do_boot_cpu(apicid, cpu);
16987 if (err) {
16988 pr_debug("do_boot_cpu failed %d\n", err);
16989 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
16990 index c346d11..d43b163 100644
16991 --- a/arch/x86/kernel/step.c
16992 +++ b/arch/x86/kernel/step.c
16993 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
16994 struct desc_struct *desc;
16995 unsigned long base;
16996
16997 - seg &= ~7UL;
16998 + seg >>= 3;
16999
17000 mutex_lock(&child->mm->context.lock);
17001 - if (unlikely((seg >> 3) >= child->mm->context.size))
17002 + if (unlikely(seg >= child->mm->context.size))
17003 addr = -1L; /* bogus selector, access would fault */
17004 else {
17005 desc = child->mm->context.ldt + seg;
17006 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
17007 addr += base;
17008 }
17009 mutex_unlock(&child->mm->context.lock);
17010 - }
17011 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
17012 + addr = ktla_ktva(addr);
17013
17014 return addr;
17015 }
17016 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
17017 unsigned char opcode[15];
17018 unsigned long addr = convert_ip_to_linear(child, regs);
17019
17020 + if (addr == -EINVAL)
17021 + return 0;
17022 +
17023 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
17024 for (i = 0; i < copied; i++) {
17025 switch (opcode[i]) {
17026 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
17027 index 0b0cb5f..db6b9ed 100644
17028 --- a/arch/x86/kernel/sys_i386_32.c
17029 +++ b/arch/x86/kernel/sys_i386_32.c
17030 @@ -24,17 +24,224 @@
17031
17032 #include <asm/syscalls.h>
17033
17034 -/*
17035 - * Do a system call from kernel instead of calling sys_execve so we
17036 - * end up with proper pt_regs.
17037 - */
17038 -int kernel_execve(const char *filename,
17039 - const char *const argv[],
17040 - const char *const envp[])
17041 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
17042 {
17043 - long __res;
17044 - asm volatile ("int $0x80"
17045 - : "=a" (__res)
17046 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
17047 - return __res;
17048 + unsigned long pax_task_size = TASK_SIZE;
17049 +
17050 +#ifdef CONFIG_PAX_SEGMEXEC
17051 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
17052 + pax_task_size = SEGMEXEC_TASK_SIZE;
17053 +#endif
17054 +
17055 + if (len > pax_task_size || addr > pax_task_size - len)
17056 + return -EINVAL;
17057 +
17058 + return 0;
17059 +}
17060 +
17061 +unsigned long
17062 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
17063 + unsigned long len, unsigned long pgoff, unsigned long flags)
17064 +{
17065 + struct mm_struct *mm = current->mm;
17066 + struct vm_area_struct *vma;
17067 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17068 +
17069 +#ifdef CONFIG_PAX_SEGMEXEC
17070 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17071 + pax_task_size = SEGMEXEC_TASK_SIZE;
17072 +#endif
17073 +
17074 + pax_task_size -= PAGE_SIZE;
17075 +
17076 + if (len > pax_task_size)
17077 + return -ENOMEM;
17078 +
17079 + if (flags & MAP_FIXED)
17080 + return addr;
17081 +
17082 +#ifdef CONFIG_PAX_RANDMMAP
17083 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17084 +#endif
17085 +
17086 + if (addr) {
17087 + addr = PAGE_ALIGN(addr);
17088 + if (pax_task_size - len >= addr) {
17089 + vma = find_vma(mm, addr);
17090 + if (check_heap_stack_gap(vma, addr, len))
17091 + return addr;
17092 + }
17093 + }
17094 + if (len > mm->cached_hole_size) {
17095 + start_addr = addr = mm->free_area_cache;
17096 + } else {
17097 + start_addr = addr = mm->mmap_base;
17098 + mm->cached_hole_size = 0;
17099 + }
17100 +
17101 +#ifdef CONFIG_PAX_PAGEEXEC
17102 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17103 + start_addr = 0x00110000UL;
17104 +
17105 +#ifdef CONFIG_PAX_RANDMMAP
17106 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17107 + start_addr += mm->delta_mmap & 0x03FFF000UL;
17108 +#endif
17109 +
17110 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17111 + start_addr = addr = mm->mmap_base;
17112 + else
17113 + addr = start_addr;
17114 + }
17115 +#endif
17116 +
17117 +full_search:
17118 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17119 + /* At this point: (!vma || addr < vma->vm_end). */
17120 + if (pax_task_size - len < addr) {
17121 + /*
17122 + * Start a new search - just in case we missed
17123 + * some holes.
17124 + */
17125 + if (start_addr != mm->mmap_base) {
17126 + start_addr = addr = mm->mmap_base;
17127 + mm->cached_hole_size = 0;
17128 + goto full_search;
17129 + }
17130 + return -ENOMEM;
17131 + }
17132 + if (check_heap_stack_gap(vma, addr, len))
17133 + break;
17134 + if (addr + mm->cached_hole_size < vma->vm_start)
17135 + mm->cached_hole_size = vma->vm_start - addr;
17136 + addr = vma->vm_end;
17137 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
17138 + start_addr = addr = mm->mmap_base;
17139 + mm->cached_hole_size = 0;
17140 + goto full_search;
17141 + }
17142 + }
17143 +
17144 + /*
17145 + * Remember the place where we stopped the search:
17146 + */
17147 + mm->free_area_cache = addr + len;
17148 + return addr;
17149 +}
17150 +
17151 +unsigned long
17152 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17153 + const unsigned long len, const unsigned long pgoff,
17154 + const unsigned long flags)
17155 +{
17156 + struct vm_area_struct *vma;
17157 + struct mm_struct *mm = current->mm;
17158 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
17159 +
17160 +#ifdef CONFIG_PAX_SEGMEXEC
17161 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17162 + pax_task_size = SEGMEXEC_TASK_SIZE;
17163 +#endif
17164 +
17165 + pax_task_size -= PAGE_SIZE;
17166 +
17167 + /* requested length too big for entire address space */
17168 + if (len > pax_task_size)
17169 + return -ENOMEM;
17170 +
17171 + if (flags & MAP_FIXED)
17172 + return addr;
17173 +
17174 +#ifdef CONFIG_PAX_PAGEEXEC
17175 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
17176 + goto bottomup;
17177 +#endif
17178 +
17179 +#ifdef CONFIG_PAX_RANDMMAP
17180 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17181 +#endif
17182 +
17183 + /* requesting a specific address */
17184 + if (addr) {
17185 + addr = PAGE_ALIGN(addr);
17186 + if (pax_task_size - len >= addr) {
17187 + vma = find_vma(mm, addr);
17188 + if (check_heap_stack_gap(vma, addr, len))
17189 + return addr;
17190 + }
17191 + }
17192 +
17193 + /* check if free_area_cache is useful for us */
17194 + if (len <= mm->cached_hole_size) {
17195 + mm->cached_hole_size = 0;
17196 + mm->free_area_cache = mm->mmap_base;
17197 + }
17198 +
17199 + /* either no address requested or can't fit in requested address hole */
17200 + addr = mm->free_area_cache;
17201 +
17202 + /* make sure it can fit in the remaining address space */
17203 + if (addr > len) {
17204 + vma = find_vma(mm, addr-len);
17205 + if (check_heap_stack_gap(vma, addr - len, len))
17206 + /* remember the address as a hint for next time */
17207 + return (mm->free_area_cache = addr-len);
17208 + }
17209 +
17210 + if (mm->mmap_base < len)
17211 + goto bottomup;
17212 +
17213 + addr = mm->mmap_base-len;
17214 +
17215 + do {
17216 + /*
17217 + * Lookup failure means no vma is above this address,
17218 + * else if new region fits below vma->vm_start,
17219 + * return with success:
17220 + */
17221 + vma = find_vma(mm, addr);
17222 + if (check_heap_stack_gap(vma, addr, len))
17223 + /* remember the address as a hint for next time */
17224 + return (mm->free_area_cache = addr);
17225 +
17226 + /* remember the largest hole we saw so far */
17227 + if (addr + mm->cached_hole_size < vma->vm_start)
17228 + mm->cached_hole_size = vma->vm_start - addr;
17229 +
17230 + /* try just below the current vma->vm_start */
17231 + addr = skip_heap_stack_gap(vma, len);
17232 + } while (!IS_ERR_VALUE(addr));
17233 +
17234 +bottomup:
17235 + /*
17236 + * A failed mmap() very likely causes application failure,
17237 + * so fall back to the bottom-up function here. This scenario
17238 + * can happen with large stack limits and large mmap()
17239 + * allocations.
17240 + */
17241 +
17242 +#ifdef CONFIG_PAX_SEGMEXEC
17243 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17244 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17245 + else
17246 +#endif
17247 +
17248 + mm->mmap_base = TASK_UNMAPPED_BASE;
17249 +
17250 +#ifdef CONFIG_PAX_RANDMMAP
17251 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17252 + mm->mmap_base += mm->delta_mmap;
17253 +#endif
17254 +
17255 + mm->free_area_cache = mm->mmap_base;
17256 + mm->cached_hole_size = ~0UL;
17257 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17258 + /*
17259 + * Restore the topdown base:
17260 + */
17261 + mm->mmap_base = base;
17262 + mm->free_area_cache = base;
17263 + mm->cached_hole_size = ~0UL;
17264 +
17265 + return addr;
17266 }
17267 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
17268 index 0514890..3dbebce 100644
17269 --- a/arch/x86/kernel/sys_x86_64.c
17270 +++ b/arch/x86/kernel/sys_x86_64.c
17271 @@ -95,8 +95,8 @@ out:
17272 return error;
17273 }
17274
17275 -static void find_start_end(unsigned long flags, unsigned long *begin,
17276 - unsigned long *end)
17277 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
17278 + unsigned long *begin, unsigned long *end)
17279 {
17280 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17281 unsigned long new_begin;
17282 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
17283 *begin = new_begin;
17284 }
17285 } else {
17286 - *begin = TASK_UNMAPPED_BASE;
17287 + *begin = mm->mmap_base;
17288 *end = TASK_SIZE;
17289 }
17290 }
17291 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
17292 if (flags & MAP_FIXED)
17293 return addr;
17294
17295 - find_start_end(flags, &begin, &end);
17296 + find_start_end(mm, flags, &begin, &end);
17297
17298 if (len > end)
17299 return -ENOMEM;
17300
17301 +#ifdef CONFIG_PAX_RANDMMAP
17302 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17303 +#endif
17304 +
17305 if (addr) {
17306 addr = PAGE_ALIGN(addr);
17307 vma = find_vma(mm, addr);
17308 - if (end - len >= addr &&
17309 - (!vma || addr + len <= vma->vm_start))
17310 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17311 return addr;
17312 }
17313 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17314 @@ -172,7 +175,7 @@ full_search:
17315 }
17316 return -ENOMEM;
17317 }
17318 - if (!vma || addr + len <= vma->vm_start) {
17319 + if (check_heap_stack_gap(vma, addr, len)) {
17320 /*
17321 * Remember the place where we stopped the search:
17322 */
17323 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17324 {
17325 struct vm_area_struct *vma;
17326 struct mm_struct *mm = current->mm;
17327 - unsigned long addr = addr0;
17328 + unsigned long base = mm->mmap_base, addr = addr0;
17329
17330 /* requested length too big for entire address space */
17331 if (len > TASK_SIZE)
17332 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17333 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17334 goto bottomup;
17335
17336 +#ifdef CONFIG_PAX_RANDMMAP
17337 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17338 +#endif
17339 +
17340 /* requesting a specific address */
17341 if (addr) {
17342 addr = PAGE_ALIGN(addr);
17343 - vma = find_vma(mm, addr);
17344 - if (TASK_SIZE - len >= addr &&
17345 - (!vma || addr + len <= vma->vm_start))
17346 - return addr;
17347 + if (TASK_SIZE - len >= addr) {
17348 + vma = find_vma(mm, addr);
17349 + if (check_heap_stack_gap(vma, addr, len))
17350 + return addr;
17351 + }
17352 }
17353
17354 /* check if free_area_cache is useful for us */
17355 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17356 ALIGN_TOPDOWN);
17357
17358 vma = find_vma(mm, tmp_addr);
17359 - if (!vma || tmp_addr + len <= vma->vm_start)
17360 + if (check_heap_stack_gap(vma, tmp_addr, len))
17361 /* remember the address as a hint for next time */
17362 return mm->free_area_cache = tmp_addr;
17363 }
17364 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17365 * return with success:
17366 */
17367 vma = find_vma(mm, addr);
17368 - if (!vma || addr+len <= vma->vm_start)
17369 + if (check_heap_stack_gap(vma, addr, len))
17370 /* remember the address as a hint for next time */
17371 return mm->free_area_cache = addr;
17372
17373 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17374 mm->cached_hole_size = vma->vm_start - addr;
17375
17376 /* try just below the current vma->vm_start */
17377 - addr = vma->vm_start-len;
17378 - } while (len < vma->vm_start);
17379 + addr = skip_heap_stack_gap(vma, len);
17380 + } while (!IS_ERR_VALUE(addr));
17381
17382 bottomup:
17383 /*
17384 @@ -270,13 +278,21 @@ bottomup:
17385 * can happen with large stack limits and large mmap()
17386 * allocations.
17387 */
17388 + mm->mmap_base = TASK_UNMAPPED_BASE;
17389 +
17390 +#ifdef CONFIG_PAX_RANDMMAP
17391 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17392 + mm->mmap_base += mm->delta_mmap;
17393 +#endif
17394 +
17395 + mm->free_area_cache = mm->mmap_base;
17396 mm->cached_hole_size = ~0UL;
17397 - mm->free_area_cache = TASK_UNMAPPED_BASE;
17398 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17399 /*
17400 * Restore the topdown base:
17401 */
17402 - mm->free_area_cache = mm->mmap_base;
17403 + mm->mmap_base = base;
17404 + mm->free_area_cache = base;
17405 mm->cached_hole_size = ~0UL;
17406
17407 return addr;
17408 diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
17409 index 9a0e312..e6f66f2 100644
17410 --- a/arch/x86/kernel/syscall_table_32.S
17411 +++ b/arch/x86/kernel/syscall_table_32.S
17412 @@ -1,3 +1,4 @@
17413 +.section .rodata,"a",@progbits
17414 ENTRY(sys_call_table)
17415 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
17416 .long sys_exit
17417 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
17418 index e2410e2..4fe3fbc 100644
17419 --- a/arch/x86/kernel/tboot.c
17420 +++ b/arch/x86/kernel/tboot.c
17421 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
17422
17423 void tboot_shutdown(u32 shutdown_type)
17424 {
17425 - void (*shutdown)(void);
17426 + void (* __noreturn shutdown)(void);
17427
17428 if (!tboot_enabled())
17429 return;
17430 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
17431
17432 switch_to_tboot_pt();
17433
17434 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17435 + shutdown = (void *)tboot->shutdown_entry;
17436 shutdown();
17437
17438 /* should not reach here */
17439 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
17440 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17441 }
17442
17443 -static atomic_t ap_wfs_count;
17444 +static atomic_unchecked_t ap_wfs_count;
17445
17446 static int tboot_wait_for_aps(int num_aps)
17447 {
17448 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
17449 {
17450 switch (action) {
17451 case CPU_DYING:
17452 - atomic_inc(&ap_wfs_count);
17453 + atomic_inc_unchecked(&ap_wfs_count);
17454 if (num_online_cpus() == 1)
17455 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17456 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17457 return NOTIFY_BAD;
17458 break;
17459 }
17460 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
17461
17462 tboot_create_trampoline();
17463
17464 - atomic_set(&ap_wfs_count, 0);
17465 + atomic_set_unchecked(&ap_wfs_count, 0);
17466 register_hotcpu_notifier(&tboot_cpu_notifier);
17467 return 0;
17468 }
17469 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
17470 index dd5fbf4..b7f2232 100644
17471 --- a/arch/x86/kernel/time.c
17472 +++ b/arch/x86/kernel/time.c
17473 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
17474 {
17475 unsigned long pc = instruction_pointer(regs);
17476
17477 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17478 + if (!user_mode(regs) && in_lock_functions(pc)) {
17479 #ifdef CONFIG_FRAME_POINTER
17480 - return *(unsigned long *)(regs->bp + sizeof(long));
17481 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17482 #else
17483 unsigned long *sp =
17484 (unsigned long *)kernel_stack_pointer(regs);
17485 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
17486 * or above a saved flags. Eflags has bits 22-31 zero,
17487 * kernel addresses don't.
17488 */
17489 +
17490 +#ifdef CONFIG_PAX_KERNEXEC
17491 + return ktla_ktva(sp[0]);
17492 +#else
17493 if (sp[0] >> 22)
17494 return sp[0];
17495 if (sp[1] >> 22)
17496 return sp[1];
17497 #endif
17498 +
17499 +#endif
17500 }
17501 return pc;
17502 }
17503 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
17504 index 6bb7b85..dd853e1 100644
17505 --- a/arch/x86/kernel/tls.c
17506 +++ b/arch/x86/kernel/tls.c
17507 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
17508 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17509 return -EINVAL;
17510
17511 +#ifdef CONFIG_PAX_SEGMEXEC
17512 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17513 + return -EINVAL;
17514 +#endif
17515 +
17516 set_tls_desc(p, idx, &info, 1);
17517
17518 return 0;
17519 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
17520 index 451c0a7..e57f551 100644
17521 --- a/arch/x86/kernel/trampoline_32.S
17522 +++ b/arch/x86/kernel/trampoline_32.S
17523 @@ -32,6 +32,12 @@
17524 #include <asm/segment.h>
17525 #include <asm/page_types.h>
17526
17527 +#ifdef CONFIG_PAX_KERNEXEC
17528 +#define ta(X) (X)
17529 +#else
17530 +#define ta(X) ((X) - __PAGE_OFFSET)
17531 +#endif
17532 +
17533 #ifdef CONFIG_SMP
17534
17535 .section ".x86_trampoline","a"
17536 @@ -62,7 +68,7 @@ r_base = .
17537 inc %ax # protected mode (PE) bit
17538 lmsw %ax # into protected mode
17539 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17540 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17541 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
17542
17543 # These need to be in the same 64K segment as the above;
17544 # hence we don't use the boot_gdt_descr defined in head.S
17545 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
17546 index 09ff517..df19fbff 100644
17547 --- a/arch/x86/kernel/trampoline_64.S
17548 +++ b/arch/x86/kernel/trampoline_64.S
17549 @@ -90,7 +90,7 @@ startup_32:
17550 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17551 movl %eax, %ds
17552
17553 - movl $X86_CR4_PAE, %eax
17554 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17555 movl %eax, %cr4 # Enable PAE mode
17556
17557 # Setup trampoline 4 level pagetables
17558 @@ -138,7 +138,7 @@ tidt:
17559 # so the kernel can live anywhere
17560 .balign 4
17561 tgdt:
17562 - .short tgdt_end - tgdt # gdt limit
17563 + .short tgdt_end - tgdt - 1 # gdt limit
17564 .long tgdt - r_base
17565 .short 0
17566 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17567 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
17568 index a8e3eb8..c9dbd7d 100644
17569 --- a/arch/x86/kernel/traps.c
17570 +++ b/arch/x86/kernel/traps.c
17571 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
17572
17573 /* Do we ignore FPU interrupts ? */
17574 char ignore_fpu_irq;
17575 -
17576 -/*
17577 - * The IDT has to be page-aligned to simplify the Pentium
17578 - * F0 0F bug workaround.
17579 - */
17580 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17581 #endif
17582
17583 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17584 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
17585 }
17586
17587 static void __kprobes
17588 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17589 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17590 long error_code, siginfo_t *info)
17591 {
17592 struct task_struct *tsk = current;
17593
17594 #ifdef CONFIG_X86_32
17595 - if (regs->flags & X86_VM_MASK) {
17596 + if (v8086_mode(regs)) {
17597 /*
17598 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17599 * On nmi (interrupt 2), do_trap should not be called.
17600 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17601 }
17602 #endif
17603
17604 - if (!user_mode(regs))
17605 + if (!user_mode_novm(regs))
17606 goto kernel_trap;
17607
17608 #ifdef CONFIG_X86_32
17609 @@ -148,7 +142,7 @@ trap_signal:
17610 printk_ratelimit()) {
17611 printk(KERN_INFO
17612 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17613 - tsk->comm, tsk->pid, str,
17614 + tsk->comm, task_pid_nr(tsk), str,
17615 regs->ip, regs->sp, error_code);
17616 print_vma_addr(" in ", regs->ip);
17617 printk("\n");
17618 @@ -165,8 +159,20 @@ kernel_trap:
17619 if (!fixup_exception(regs)) {
17620 tsk->thread.error_code = error_code;
17621 tsk->thread.trap_no = trapnr;
17622 +
17623 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17624 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17625 + str = "PAX: suspicious stack segment fault";
17626 +#endif
17627 +
17628 die(str, regs, error_code);
17629 }
17630 +
17631 +#ifdef CONFIG_PAX_REFCOUNT
17632 + if (trapnr == 4)
17633 + pax_report_refcount_overflow(regs);
17634 +#endif
17635 +
17636 return;
17637
17638 #ifdef CONFIG_X86_32
17639 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
17640 conditional_sti(regs);
17641
17642 #ifdef CONFIG_X86_32
17643 - if (regs->flags & X86_VM_MASK)
17644 + if (v8086_mode(regs))
17645 goto gp_in_vm86;
17646 #endif
17647
17648 tsk = current;
17649 - if (!user_mode(regs))
17650 + if (!user_mode_novm(regs))
17651 goto gp_in_kernel;
17652
17653 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17654 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17655 + struct mm_struct *mm = tsk->mm;
17656 + unsigned long limit;
17657 +
17658 + down_write(&mm->mmap_sem);
17659 + limit = mm->context.user_cs_limit;
17660 + if (limit < TASK_SIZE) {
17661 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17662 + up_write(&mm->mmap_sem);
17663 + return;
17664 + }
17665 + up_write(&mm->mmap_sem);
17666 + }
17667 +#endif
17668 +
17669 tsk->thread.error_code = error_code;
17670 tsk->thread.trap_no = 13;
17671
17672 @@ -295,6 +317,13 @@ gp_in_kernel:
17673 if (notify_die(DIE_GPF, "general protection fault", regs,
17674 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17675 return;
17676 +
17677 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17678 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
17679 + die("PAX: suspicious general protection fault", regs, error_code);
17680 + else
17681 +#endif
17682 +
17683 die("general protection fault", regs, error_code);
17684 }
17685
17686 @@ -414,7 +443,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
17687 /* It's safe to allow irq's after DR6 has been saved */
17688 preempt_conditional_sti(regs);
17689
17690 - if (regs->flags & X86_VM_MASK) {
17691 + if (v8086_mode(regs)) {
17692 handle_vm86_trap((struct kernel_vm86_regs *) regs,
17693 error_code, 1);
17694 preempt_conditional_cli(regs);
17695 @@ -428,7 +457,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
17696 * We already checked v86 mode above, so we can check for kernel mode
17697 * by just checking the CPL of CS.
17698 */
17699 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
17700 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
17701 tsk->thread.debugreg6 &= ~DR_STEP;
17702 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
17703 regs->flags &= ~X86_EFLAGS_TF;
17704 @@ -457,7 +486,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
17705 return;
17706 conditional_sti(regs);
17707
17708 - if (!user_mode_vm(regs))
17709 + if (!user_mode(regs))
17710 {
17711 if (!fixup_exception(regs)) {
17712 task->thread.error_code = error_code;
17713 @@ -568,7 +597,7 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
17714 void __math_state_restore(void)
17715 {
17716 struct thread_info *thread = current_thread_info();
17717 - struct task_struct *tsk = thread->task;
17718 + struct task_struct *tsk = current;
17719
17720 /*
17721 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
17722 @@ -595,8 +624,7 @@ void __math_state_restore(void)
17723 */
17724 asmlinkage void math_state_restore(void)
17725 {
17726 - struct thread_info *thread = current_thread_info();
17727 - struct task_struct *tsk = thread->task;
17728 + struct task_struct *tsk = current;
17729
17730 if (!tsk_used_math(tsk)) {
17731 local_irq_enable();
17732 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
17733 index b9242ba..50c5edd 100644
17734 --- a/arch/x86/kernel/verify_cpu.S
17735 +++ b/arch/x86/kernel/verify_cpu.S
17736 @@ -20,6 +20,7 @@
17737 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
17738 * arch/x86/kernel/trampoline_64.S: secondary processor verification
17739 * arch/x86/kernel/head_32.S: processor startup
17740 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
17741 *
17742 * verify_cpu, returns the status of longmode and SSE in register %eax.
17743 * 0: Success 1: Failure
17744 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
17745 index 863f875..4307295 100644
17746 --- a/arch/x86/kernel/vm86_32.c
17747 +++ b/arch/x86/kernel/vm86_32.c
17748 @@ -41,6 +41,7 @@
17749 #include <linux/ptrace.h>
17750 #include <linux/audit.h>
17751 #include <linux/stddef.h>
17752 +#include <linux/grsecurity.h>
17753
17754 #include <asm/uaccess.h>
17755 #include <asm/io.h>
17756 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
17757 do_exit(SIGSEGV);
17758 }
17759
17760 - tss = &per_cpu(init_tss, get_cpu());
17761 + tss = init_tss + get_cpu();
17762 current->thread.sp0 = current->thread.saved_sp0;
17763 current->thread.sysenter_cs = __KERNEL_CS;
17764 load_sp0(tss, &current->thread);
17765 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
17766 struct task_struct *tsk;
17767 int tmp, ret = -EPERM;
17768
17769 +#ifdef CONFIG_GRKERNSEC_VM86
17770 + if (!capable(CAP_SYS_RAWIO)) {
17771 + gr_handle_vm86();
17772 + goto out;
17773 + }
17774 +#endif
17775 +
17776 tsk = current;
17777 if (tsk->thread.saved_sp0)
17778 goto out;
17779 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
17780 int tmp, ret;
17781 struct vm86plus_struct __user *v86;
17782
17783 +#ifdef CONFIG_GRKERNSEC_VM86
17784 + if (!capable(CAP_SYS_RAWIO)) {
17785 + gr_handle_vm86();
17786 + ret = -EPERM;
17787 + goto out;
17788 + }
17789 +#endif
17790 +
17791 tsk = current;
17792 switch (cmd) {
17793 case VM86_REQUEST_IRQ:
17794 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
17795 tsk->thread.saved_fs = info->regs32->fs;
17796 tsk->thread.saved_gs = get_user_gs(info->regs32);
17797
17798 - tss = &per_cpu(init_tss, get_cpu());
17799 + tss = init_tss + get_cpu();
17800 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
17801 if (cpu_has_sep)
17802 tsk->thread.sysenter_cs = 0;
17803 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
17804 goto cannot_handle;
17805 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
17806 goto cannot_handle;
17807 - intr_ptr = (unsigned long __user *) (i << 2);
17808 + intr_ptr = (__force unsigned long __user *) (i << 2);
17809 if (get_user(segoffs, intr_ptr))
17810 goto cannot_handle;
17811 if ((segoffs >> 16) == BIOSSEG)
17812 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
17813 index 0f703f1..9e15f64 100644
17814 --- a/arch/x86/kernel/vmlinux.lds.S
17815 +++ b/arch/x86/kernel/vmlinux.lds.S
17816 @@ -26,6 +26,13 @@
17817 #include <asm/page_types.h>
17818 #include <asm/cache.h>
17819 #include <asm/boot.h>
17820 +#include <asm/segment.h>
17821 +
17822 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17823 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
17824 +#else
17825 +#define __KERNEL_TEXT_OFFSET 0
17826 +#endif
17827
17828 #undef i386 /* in case the preprocessor is a 32bit one */
17829
17830 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
17831
17832 PHDRS {
17833 text PT_LOAD FLAGS(5); /* R_E */
17834 +#ifdef CONFIG_X86_32
17835 + module PT_LOAD FLAGS(5); /* R_E */
17836 +#endif
17837 +#ifdef CONFIG_XEN
17838 + rodata PT_LOAD FLAGS(5); /* R_E */
17839 +#else
17840 + rodata PT_LOAD FLAGS(4); /* R__ */
17841 +#endif
17842 data PT_LOAD FLAGS(6); /* RW_ */
17843 -#ifdef CONFIG_X86_64
17844 + init.begin PT_LOAD FLAGS(6); /* RW_ */
17845 #ifdef CONFIG_SMP
17846 percpu PT_LOAD FLAGS(6); /* RW_ */
17847 #endif
17848 + text.init PT_LOAD FLAGS(5); /* R_E */
17849 + text.exit PT_LOAD FLAGS(5); /* R_E */
17850 init PT_LOAD FLAGS(7); /* RWE */
17851 -#endif
17852 note PT_NOTE FLAGS(0); /* ___ */
17853 }
17854
17855 SECTIONS
17856 {
17857 #ifdef CONFIG_X86_32
17858 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
17859 - phys_startup_32 = startup_32 - LOAD_OFFSET;
17860 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
17861 #else
17862 - . = __START_KERNEL;
17863 - phys_startup_64 = startup_64 - LOAD_OFFSET;
17864 + . = __START_KERNEL;
17865 #endif
17866
17867 /* Text and read-only data */
17868 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
17869 - _text = .;
17870 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
17871 /* bootstrapping code */
17872 +#ifdef CONFIG_X86_32
17873 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17874 +#else
17875 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17876 +#endif
17877 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17878 + _text = .;
17879 HEAD_TEXT
17880 #ifdef CONFIG_X86_32
17881 . = ALIGN(PAGE_SIZE);
17882 @@ -108,13 +128,47 @@ SECTIONS
17883 IRQENTRY_TEXT
17884 *(.fixup)
17885 *(.gnu.warning)
17886 - /* End of text section */
17887 - _etext = .;
17888 } :text = 0x9090
17889
17890 - NOTES :text :note
17891 + . += __KERNEL_TEXT_OFFSET;
17892
17893 - EXCEPTION_TABLE(16) :text = 0x9090
17894 +#ifdef CONFIG_X86_32
17895 + . = ALIGN(PAGE_SIZE);
17896 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
17897 +
17898 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
17899 + MODULES_EXEC_VADDR = .;
17900 + BYTE(0)
17901 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
17902 + . = ALIGN(HPAGE_SIZE);
17903 + MODULES_EXEC_END = . - 1;
17904 +#endif
17905 +
17906 + } :module
17907 +#endif
17908 +
17909 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
17910 + /* End of text section */
17911 + _etext = . - __KERNEL_TEXT_OFFSET;
17912 + }
17913 +
17914 +#ifdef CONFIG_X86_32
17915 + . = ALIGN(PAGE_SIZE);
17916 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
17917 + *(.idt)
17918 + . = ALIGN(PAGE_SIZE);
17919 + *(.empty_zero_page)
17920 + *(.initial_pg_fixmap)
17921 + *(.initial_pg_pmd)
17922 + *(.initial_page_table)
17923 + *(.swapper_pg_dir)
17924 + } :rodata
17925 +#endif
17926 +
17927 + . = ALIGN(PAGE_SIZE);
17928 + NOTES :rodata :note
17929 +
17930 + EXCEPTION_TABLE(16) :rodata
17931
17932 #if defined(CONFIG_DEBUG_RODATA)
17933 /* .text should occupy whole number of pages */
17934 @@ -126,16 +180,20 @@ SECTIONS
17935
17936 /* Data */
17937 .data : AT(ADDR(.data) - LOAD_OFFSET) {
17938 +
17939 +#ifdef CONFIG_PAX_KERNEXEC
17940 + . = ALIGN(HPAGE_SIZE);
17941 +#else
17942 + . = ALIGN(PAGE_SIZE);
17943 +#endif
17944 +
17945 /* Start of data section */
17946 _sdata = .;
17947
17948 /* init_task */
17949 INIT_TASK_DATA(THREAD_SIZE)
17950
17951 -#ifdef CONFIG_X86_32
17952 - /* 32 bit has nosave before _edata */
17953 NOSAVE_DATA
17954 -#endif
17955
17956 PAGE_ALIGNED_DATA(PAGE_SIZE)
17957
17958 @@ -176,12 +234,19 @@ SECTIONS
17959 #endif /* CONFIG_X86_64 */
17960
17961 /* Init code and data - will be freed after init */
17962 - . = ALIGN(PAGE_SIZE);
17963 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
17964 + BYTE(0)
17965 +
17966 +#ifdef CONFIG_PAX_KERNEXEC
17967 + . = ALIGN(HPAGE_SIZE);
17968 +#else
17969 + . = ALIGN(PAGE_SIZE);
17970 +#endif
17971 +
17972 __init_begin = .; /* paired with __init_end */
17973 - }
17974 + } :init.begin
17975
17976 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
17977 +#ifdef CONFIG_SMP
17978 /*
17979 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
17980 * output PHDR, so the next output section - .init.text - should
17981 @@ -190,12 +255,27 @@ SECTIONS
17982 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
17983 #endif
17984
17985 - INIT_TEXT_SECTION(PAGE_SIZE)
17986 -#ifdef CONFIG_X86_64
17987 - :init
17988 -#endif
17989 + . = ALIGN(PAGE_SIZE);
17990 + init_begin = .;
17991 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
17992 + VMLINUX_SYMBOL(_sinittext) = .;
17993 + INIT_TEXT
17994 + VMLINUX_SYMBOL(_einittext) = .;
17995 + . = ALIGN(PAGE_SIZE);
17996 + } :text.init
17997
17998 - INIT_DATA_SECTION(16)
17999 + /*
18000 + * .exit.text is discard at runtime, not link time, to deal with
18001 + * references from .altinstructions and .eh_frame
18002 + */
18003 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18004 + EXIT_TEXT
18005 + . = ALIGN(16);
18006 + } :text.exit
18007 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
18008 +
18009 + . = ALIGN(PAGE_SIZE);
18010 + INIT_DATA_SECTION(16) :init
18011
18012 /*
18013 * Code and data for a variety of lowlevel trampolines, to be
18014 @@ -269,19 +349,12 @@ SECTIONS
18015 }
18016
18017 . = ALIGN(8);
18018 - /*
18019 - * .exit.text is discard at runtime, not link time, to deal with
18020 - * references from .altinstructions and .eh_frame
18021 - */
18022 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
18023 - EXIT_TEXT
18024 - }
18025
18026 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18027 EXIT_DATA
18028 }
18029
18030 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18031 +#ifndef CONFIG_SMP
18032 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
18033 #endif
18034
18035 @@ -300,16 +373,10 @@ SECTIONS
18036 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
18037 __smp_locks = .;
18038 *(.smp_locks)
18039 - . = ALIGN(PAGE_SIZE);
18040 __smp_locks_end = .;
18041 + . = ALIGN(PAGE_SIZE);
18042 }
18043
18044 -#ifdef CONFIG_X86_64
18045 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18046 - NOSAVE_DATA
18047 - }
18048 -#endif
18049 -
18050 /* BSS */
18051 . = ALIGN(PAGE_SIZE);
18052 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18053 @@ -325,6 +392,7 @@ SECTIONS
18054 __brk_base = .;
18055 . += 64 * 1024; /* 64k alignment slop space */
18056 *(.brk_reservation) /* areas brk users have reserved */
18057 + . = ALIGN(HPAGE_SIZE);
18058 __brk_limit = .;
18059 }
18060
18061 @@ -351,13 +419,12 @@ SECTIONS
18062 * for the boot processor.
18063 */
18064 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
18065 -INIT_PER_CPU(gdt_page);
18066 INIT_PER_CPU(irq_stack_union);
18067
18068 /*
18069 * Build-time check on the image size:
18070 */
18071 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18072 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18073 "kernel image bigger than KERNEL_IMAGE_SIZE");
18074
18075 #ifdef CONFIG_SMP
18076 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
18077 index e4d4a22..47ee71f 100644
18078 --- a/arch/x86/kernel/vsyscall_64.c
18079 +++ b/arch/x86/kernel/vsyscall_64.c
18080 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
18081 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
18082 };
18083
18084 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = NATIVE;
18085 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
18086
18087 static int __init vsyscall_setup(char *str)
18088 {
18089 if (str) {
18090 if (!strcmp("emulate", str))
18091 vsyscall_mode = EMULATE;
18092 - else if (!strcmp("native", str))
18093 - vsyscall_mode = NATIVE;
18094 else if (!strcmp("none", str))
18095 vsyscall_mode = NONE;
18096 else
18097 @@ -178,7 +176,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18098
18099 tsk = current;
18100 if (seccomp_mode(&tsk->seccomp))
18101 - do_exit(SIGKILL);
18102 + do_group_exit(SIGKILL);
18103
18104 switch (vsyscall_nr) {
18105 case 0:
18106 @@ -220,8 +218,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18107 return true;
18108
18109 sigsegv:
18110 - force_sig(SIGSEGV, current);
18111 - return true;
18112 + do_group_exit(SIGKILL);
18113 }
18114
18115 /*
18116 @@ -274,10 +271,7 @@ void __init map_vsyscall(void)
18117 extern char __vvar_page;
18118 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
18119
18120 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
18121 - vsyscall_mode == NATIVE
18122 - ? PAGE_KERNEL_VSYSCALL
18123 - : PAGE_KERNEL_VVAR);
18124 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
18125 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
18126 (unsigned long)VSYSCALL_START);
18127
18128 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
18129 index 9796c2f..f686fbf 100644
18130 --- a/arch/x86/kernel/x8664_ksyms_64.c
18131 +++ b/arch/x86/kernel/x8664_ksyms_64.c
18132 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
18133 EXPORT_SYMBOL(copy_user_generic_string);
18134 EXPORT_SYMBOL(copy_user_generic_unrolled);
18135 EXPORT_SYMBOL(__copy_user_nocache);
18136 -EXPORT_SYMBOL(_copy_from_user);
18137 -EXPORT_SYMBOL(_copy_to_user);
18138
18139 EXPORT_SYMBOL(copy_page);
18140 EXPORT_SYMBOL(clear_page);
18141 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
18142 index a391134..d0b63b6e 100644
18143 --- a/arch/x86/kernel/xsave.c
18144 +++ b/arch/x86/kernel/xsave.c
18145 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
18146 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18147 return -EINVAL;
18148
18149 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18150 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18151 fx_sw_user->extended_size -
18152 FP_XSTATE_MAGIC2_SIZE));
18153 if (err)
18154 @@ -267,7 +267,7 @@ fx_only:
18155 * the other extended state.
18156 */
18157 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18158 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18159 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
18160 }
18161
18162 /*
18163 @@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf)
18164 if (use_xsave())
18165 err = restore_user_xstate(buf);
18166 else
18167 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
18168 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
18169 buf);
18170 if (unlikely(err)) {
18171 /*
18172 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
18173 index f1e3be1..588efc8 100644
18174 --- a/arch/x86/kvm/emulate.c
18175 +++ b/arch/x86/kvm/emulate.c
18176 @@ -249,6 +249,7 @@ struct gprefix {
18177
18178 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
18179 do { \
18180 + unsigned long _tmp; \
18181 __asm__ __volatile__ ( \
18182 _PRE_EFLAGS("0", "4", "2") \
18183 _op _suffix " %"_x"3,%1; " \
18184 @@ -263,8 +264,6 @@ struct gprefix {
18185 /* Raw emulation: instruction has two explicit operands. */
18186 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
18187 do { \
18188 - unsigned long _tmp; \
18189 - \
18190 switch ((ctxt)->dst.bytes) { \
18191 case 2: \
18192 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
18193 @@ -280,7 +279,6 @@ struct gprefix {
18194
18195 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18196 do { \
18197 - unsigned long _tmp; \
18198 switch ((ctxt)->dst.bytes) { \
18199 case 1: \
18200 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
18201 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
18202 index 54abb40..a192606 100644
18203 --- a/arch/x86/kvm/lapic.c
18204 +++ b/arch/x86/kvm/lapic.c
18205 @@ -53,7 +53,7 @@
18206 #define APIC_BUS_CYCLE_NS 1
18207
18208 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18209 -#define apic_debug(fmt, arg...)
18210 +#define apic_debug(fmt, arg...) do {} while (0)
18211
18212 #define APIC_LVT_NUM 6
18213 /* 14 is the version for Xeon and Pentium 8.4.8*/
18214 diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
18215 index f1b36cf..af8a124 100644
18216 --- a/arch/x86/kvm/mmu.c
18217 +++ b/arch/x86/kvm/mmu.c
18218 @@ -3555,7 +3555,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
18219
18220 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
18221
18222 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
18223 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
18224
18225 /*
18226 * Assume that the pte write on a page table of the same type
18227 @@ -3587,7 +3587,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
18228 }
18229
18230 spin_lock(&vcpu->kvm->mmu_lock);
18231 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18232 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18233 gentry = 0;
18234 kvm_mmu_free_some_pages(vcpu);
18235 ++vcpu->kvm->stat.mmu_pte_write;
18236 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
18237 index 9299410..ade2f9b 100644
18238 --- a/arch/x86/kvm/paging_tmpl.h
18239 +++ b/arch/x86/kvm/paging_tmpl.h
18240 @@ -197,7 +197,7 @@ retry_walk:
18241 if (unlikely(kvm_is_error_hva(host_addr)))
18242 goto error;
18243
18244 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
18245 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
18246 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
18247 goto error;
18248
18249 @@ -705,7 +705,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
18250 if (need_flush)
18251 kvm_flush_remote_tlbs(vcpu->kvm);
18252
18253 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
18254 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
18255
18256 spin_unlock(&vcpu->kvm->mmu_lock);
18257
18258 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
18259 index e32243e..a6e6172 100644
18260 --- a/arch/x86/kvm/svm.c
18261 +++ b/arch/x86/kvm/svm.c
18262 @@ -3400,7 +3400,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
18263 int cpu = raw_smp_processor_id();
18264
18265 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
18266 +
18267 + pax_open_kernel();
18268 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
18269 + pax_close_kernel();
18270 +
18271 load_TR_desc();
18272 }
18273
18274 @@ -3778,6 +3782,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
18275 #endif
18276 #endif
18277
18278 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18279 + __set_fs(current_thread_info()->addr_limit);
18280 +#endif
18281 +
18282 reload_tss(vcpu);
18283
18284 local_irq_disable();
18285 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
18286 index 579a0b5..ed7bbf9 100644
18287 --- a/arch/x86/kvm/vmx.c
18288 +++ b/arch/x86/kvm/vmx.c
18289 @@ -1305,7 +1305,11 @@ static void reload_tss(void)
18290 struct desc_struct *descs;
18291
18292 descs = (void *)gdt->address;
18293 +
18294 + pax_open_kernel();
18295 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18296 + pax_close_kernel();
18297 +
18298 load_TR_desc();
18299 }
18300
18301 @@ -2633,8 +2637,11 @@ static __init int hardware_setup(void)
18302 if (!cpu_has_vmx_flexpriority())
18303 flexpriority_enabled = 0;
18304
18305 - if (!cpu_has_vmx_tpr_shadow())
18306 - kvm_x86_ops->update_cr8_intercept = NULL;
18307 + if (!cpu_has_vmx_tpr_shadow()) {
18308 + pax_open_kernel();
18309 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18310 + pax_close_kernel();
18311 + }
18312
18313 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18314 kvm_disable_largepages();
18315 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
18316 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
18317
18318 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
18319 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
18320 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
18321
18322 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
18323 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
18324 @@ -6169,6 +6176,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18325 "jmp .Lkvm_vmx_return \n\t"
18326 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18327 ".Lkvm_vmx_return: "
18328 +
18329 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18330 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18331 + ".Lkvm_vmx_return2: "
18332 +#endif
18333 +
18334 /* Save guest registers, load host registers, keep flags */
18335 "mov %0, %c[wordsize](%%"R"sp) \n\t"
18336 "pop %0 \n\t"
18337 @@ -6217,6 +6230,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18338 #endif
18339 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
18340 [wordsize]"i"(sizeof(ulong))
18341 +
18342 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18343 + ,[cs]"i"(__KERNEL_CS)
18344 +#endif
18345 +
18346 : "cc", "memory"
18347 , R"ax", R"bx", R"di", R"si"
18348 #ifdef CONFIG_X86_64
18349 @@ -6245,7 +6263,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18350 }
18351 }
18352
18353 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18354 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18355 +
18356 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18357 + loadsegment(fs, __KERNEL_PERCPU);
18358 +#endif
18359 +
18360 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18361 + __set_fs(current_thread_info()->addr_limit);
18362 +#endif
18363 +
18364 vmx->loaded_vmcs->launched = 1;
18365
18366 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
18367 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
18368 index 4c938da..4ddef65 100644
18369 --- a/arch/x86/kvm/x86.c
18370 +++ b/arch/x86/kvm/x86.c
18371 @@ -1345,8 +1345,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
18372 {
18373 struct kvm *kvm = vcpu->kvm;
18374 int lm = is_long_mode(vcpu);
18375 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
18376 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
18377 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
18378 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
18379 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
18380 : kvm->arch.xen_hvm_config.blob_size_32;
18381 u32 page_num = data & ~PAGE_MASK;
18382 @@ -2165,6 +2165,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
18383 if (n < msr_list.nmsrs)
18384 goto out;
18385 r = -EFAULT;
18386 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
18387 + goto out;
18388 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
18389 num_msrs_to_save * sizeof(u32)))
18390 goto out;
18391 @@ -2340,15 +2342,20 @@ static int kvm_vcpu_ioctl_set_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 > KVM_MAX_CPUID_ENTRIES)
18400 goto out;
18401 r = -EFAULT;
18402 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18403 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18404 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18405 goto out;
18406 + for (i = 0; i < cpuid->nent; ++i) {
18407 + struct kvm_cpuid_entry2 cpuid_entry;
18408 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18409 + goto out;
18410 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
18411 + }
18412 vcpu->arch.cpuid_nent = cpuid->nent;
18413 kvm_apic_set_version(vcpu);
18414 kvm_x86_ops->cpuid_update(vcpu);
18415 @@ -2363,15 +2370,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
18416 struct kvm_cpuid2 *cpuid,
18417 struct kvm_cpuid_entry2 __user *entries)
18418 {
18419 - int r;
18420 + int r, i;
18421
18422 r = -E2BIG;
18423 if (cpuid->nent < vcpu->arch.cpuid_nent)
18424 goto out;
18425 r = -EFAULT;
18426 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18427 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18428 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18429 goto out;
18430 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18431 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18432 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18433 + goto out;
18434 + }
18435 return 0;
18436
18437 out:
18438 @@ -2746,7 +2757,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
18439 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18440 struct kvm_interrupt *irq)
18441 {
18442 - if (irq->irq < 0 || irq->irq >= 256)
18443 + if (irq->irq >= 256)
18444 return -EINVAL;
18445 if (irqchip_in_kernel(vcpu->kvm))
18446 return -ENXIO;
18447 @@ -5162,7 +5173,7 @@ static void kvm_set_mmio_spte_mask(void)
18448 kvm_mmu_set_mmio_spte_mask(mask);
18449 }
18450
18451 -int kvm_arch_init(void *opaque)
18452 +int kvm_arch_init(const void *opaque)
18453 {
18454 int r;
18455 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18456 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
18457 index cf4603b..7cdde38 100644
18458 --- a/arch/x86/lguest/boot.c
18459 +++ b/arch/x86/lguest/boot.c
18460 @@ -1195,9 +1195,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
18461 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
18462 * Launcher to reboot us.
18463 */
18464 -static void lguest_restart(char *reason)
18465 +static __noreturn void lguest_restart(char *reason)
18466 {
18467 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
18468 + BUG();
18469 }
18470
18471 /*G:050
18472 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
18473 index 042f682..c92afb6 100644
18474 --- a/arch/x86/lib/atomic64_32.c
18475 +++ b/arch/x86/lib/atomic64_32.c
18476 @@ -8,18 +8,30 @@
18477
18478 long long atomic64_read_cx8(long long, const atomic64_t *v);
18479 EXPORT_SYMBOL(atomic64_read_cx8);
18480 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18481 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
18482 long long atomic64_set_cx8(long long, const atomic64_t *v);
18483 EXPORT_SYMBOL(atomic64_set_cx8);
18484 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18485 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
18486 long long atomic64_xchg_cx8(long long, unsigned high);
18487 EXPORT_SYMBOL(atomic64_xchg_cx8);
18488 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
18489 EXPORT_SYMBOL(atomic64_add_return_cx8);
18490 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18491 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
18492 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
18493 EXPORT_SYMBOL(atomic64_sub_return_cx8);
18494 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18495 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
18496 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
18497 EXPORT_SYMBOL(atomic64_inc_return_cx8);
18498 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18499 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
18500 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
18501 EXPORT_SYMBOL(atomic64_dec_return_cx8);
18502 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18503 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
18504 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
18505 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
18506 int atomic64_inc_not_zero_cx8(atomic64_t *v);
18507 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
18508 #ifndef CONFIG_X86_CMPXCHG64
18509 long long atomic64_read_386(long long, const atomic64_t *v);
18510 EXPORT_SYMBOL(atomic64_read_386);
18511 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
18512 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
18513 long long atomic64_set_386(long long, const atomic64_t *v);
18514 EXPORT_SYMBOL(atomic64_set_386);
18515 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
18516 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
18517 long long atomic64_xchg_386(long long, unsigned high);
18518 EXPORT_SYMBOL(atomic64_xchg_386);
18519 long long atomic64_add_return_386(long long a, atomic64_t *v);
18520 EXPORT_SYMBOL(atomic64_add_return_386);
18521 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18522 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
18523 long long atomic64_sub_return_386(long long a, atomic64_t *v);
18524 EXPORT_SYMBOL(atomic64_sub_return_386);
18525 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18526 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
18527 long long atomic64_inc_return_386(long long a, atomic64_t *v);
18528 EXPORT_SYMBOL(atomic64_inc_return_386);
18529 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18530 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
18531 long long atomic64_dec_return_386(long long a, atomic64_t *v);
18532 EXPORT_SYMBOL(atomic64_dec_return_386);
18533 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18534 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
18535 long long atomic64_add_386(long long a, atomic64_t *v);
18536 EXPORT_SYMBOL(atomic64_add_386);
18537 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
18538 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
18539 long long atomic64_sub_386(long long a, atomic64_t *v);
18540 EXPORT_SYMBOL(atomic64_sub_386);
18541 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
18542 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
18543 long long atomic64_inc_386(long long a, atomic64_t *v);
18544 EXPORT_SYMBOL(atomic64_inc_386);
18545 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
18546 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
18547 long long atomic64_dec_386(long long a, atomic64_t *v);
18548 EXPORT_SYMBOL(atomic64_dec_386);
18549 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
18550 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
18551 long long atomic64_dec_if_positive_386(atomic64_t *v);
18552 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
18553 int atomic64_inc_not_zero_386(atomic64_t *v);
18554 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
18555 index e8e7e0d..56fd1b0 100644
18556 --- a/arch/x86/lib/atomic64_386_32.S
18557 +++ b/arch/x86/lib/atomic64_386_32.S
18558 @@ -48,6 +48,10 @@ BEGIN(read)
18559 movl (v), %eax
18560 movl 4(v), %edx
18561 RET_ENDP
18562 +BEGIN(read_unchecked)
18563 + movl (v), %eax
18564 + movl 4(v), %edx
18565 +RET_ENDP
18566 #undef v
18567
18568 #define v %esi
18569 @@ -55,6 +59,10 @@ BEGIN(set)
18570 movl %ebx, (v)
18571 movl %ecx, 4(v)
18572 RET_ENDP
18573 +BEGIN(set_unchecked)
18574 + movl %ebx, (v)
18575 + movl %ecx, 4(v)
18576 +RET_ENDP
18577 #undef v
18578
18579 #define v %esi
18580 @@ -70,6 +78,20 @@ RET_ENDP
18581 BEGIN(add)
18582 addl %eax, (v)
18583 adcl %edx, 4(v)
18584 +
18585 +#ifdef CONFIG_PAX_REFCOUNT
18586 + jno 0f
18587 + subl %eax, (v)
18588 + sbbl %edx, 4(v)
18589 + int $4
18590 +0:
18591 + _ASM_EXTABLE(0b, 0b)
18592 +#endif
18593 +
18594 +RET_ENDP
18595 +BEGIN(add_unchecked)
18596 + addl %eax, (v)
18597 + adcl %edx, 4(v)
18598 RET_ENDP
18599 #undef v
18600
18601 @@ -77,6 +99,24 @@ RET_ENDP
18602 BEGIN(add_return)
18603 addl (v), %eax
18604 adcl 4(v), %edx
18605 +
18606 +#ifdef CONFIG_PAX_REFCOUNT
18607 + into
18608 +1234:
18609 + _ASM_EXTABLE(1234b, 2f)
18610 +#endif
18611 +
18612 + movl %eax, (v)
18613 + movl %edx, 4(v)
18614 +
18615 +#ifdef CONFIG_PAX_REFCOUNT
18616 +2:
18617 +#endif
18618 +
18619 +RET_ENDP
18620 +BEGIN(add_return_unchecked)
18621 + addl (v), %eax
18622 + adcl 4(v), %edx
18623 movl %eax, (v)
18624 movl %edx, 4(v)
18625 RET_ENDP
18626 @@ -86,6 +126,20 @@ RET_ENDP
18627 BEGIN(sub)
18628 subl %eax, (v)
18629 sbbl %edx, 4(v)
18630 +
18631 +#ifdef CONFIG_PAX_REFCOUNT
18632 + jno 0f
18633 + addl %eax, (v)
18634 + adcl %edx, 4(v)
18635 + int $4
18636 +0:
18637 + _ASM_EXTABLE(0b, 0b)
18638 +#endif
18639 +
18640 +RET_ENDP
18641 +BEGIN(sub_unchecked)
18642 + subl %eax, (v)
18643 + sbbl %edx, 4(v)
18644 RET_ENDP
18645 #undef v
18646
18647 @@ -96,6 +150,27 @@ BEGIN(sub_return)
18648 sbbl $0, %edx
18649 addl (v), %eax
18650 adcl 4(v), %edx
18651 +
18652 +#ifdef CONFIG_PAX_REFCOUNT
18653 + into
18654 +1234:
18655 + _ASM_EXTABLE(1234b, 2f)
18656 +#endif
18657 +
18658 + movl %eax, (v)
18659 + movl %edx, 4(v)
18660 +
18661 +#ifdef CONFIG_PAX_REFCOUNT
18662 +2:
18663 +#endif
18664 +
18665 +RET_ENDP
18666 +BEGIN(sub_return_unchecked)
18667 + negl %edx
18668 + negl %eax
18669 + sbbl $0, %edx
18670 + addl (v), %eax
18671 + adcl 4(v), %edx
18672 movl %eax, (v)
18673 movl %edx, 4(v)
18674 RET_ENDP
18675 @@ -105,6 +180,20 @@ RET_ENDP
18676 BEGIN(inc)
18677 addl $1, (v)
18678 adcl $0, 4(v)
18679 +
18680 +#ifdef CONFIG_PAX_REFCOUNT
18681 + jno 0f
18682 + subl $1, (v)
18683 + sbbl $0, 4(v)
18684 + int $4
18685 +0:
18686 + _ASM_EXTABLE(0b, 0b)
18687 +#endif
18688 +
18689 +RET_ENDP
18690 +BEGIN(inc_unchecked)
18691 + addl $1, (v)
18692 + adcl $0, 4(v)
18693 RET_ENDP
18694 #undef v
18695
18696 @@ -114,6 +203,26 @@ BEGIN(inc_return)
18697 movl 4(v), %edx
18698 addl $1, %eax
18699 adcl $0, %edx
18700 +
18701 +#ifdef CONFIG_PAX_REFCOUNT
18702 + into
18703 +1234:
18704 + _ASM_EXTABLE(1234b, 2f)
18705 +#endif
18706 +
18707 + movl %eax, (v)
18708 + movl %edx, 4(v)
18709 +
18710 +#ifdef CONFIG_PAX_REFCOUNT
18711 +2:
18712 +#endif
18713 +
18714 +RET_ENDP
18715 +BEGIN(inc_return_unchecked)
18716 + movl (v), %eax
18717 + movl 4(v), %edx
18718 + addl $1, %eax
18719 + adcl $0, %edx
18720 movl %eax, (v)
18721 movl %edx, 4(v)
18722 RET_ENDP
18723 @@ -123,6 +232,20 @@ RET_ENDP
18724 BEGIN(dec)
18725 subl $1, (v)
18726 sbbl $0, 4(v)
18727 +
18728 +#ifdef CONFIG_PAX_REFCOUNT
18729 + jno 0f
18730 + addl $1, (v)
18731 + adcl $0, 4(v)
18732 + int $4
18733 +0:
18734 + _ASM_EXTABLE(0b, 0b)
18735 +#endif
18736 +
18737 +RET_ENDP
18738 +BEGIN(dec_unchecked)
18739 + subl $1, (v)
18740 + sbbl $0, 4(v)
18741 RET_ENDP
18742 #undef v
18743
18744 @@ -132,6 +255,26 @@ BEGIN(dec_return)
18745 movl 4(v), %edx
18746 subl $1, %eax
18747 sbbl $0, %edx
18748 +
18749 +#ifdef CONFIG_PAX_REFCOUNT
18750 + into
18751 +1234:
18752 + _ASM_EXTABLE(1234b, 2f)
18753 +#endif
18754 +
18755 + movl %eax, (v)
18756 + movl %edx, 4(v)
18757 +
18758 +#ifdef CONFIG_PAX_REFCOUNT
18759 +2:
18760 +#endif
18761 +
18762 +RET_ENDP
18763 +BEGIN(dec_return_unchecked)
18764 + movl (v), %eax
18765 + movl 4(v), %edx
18766 + subl $1, %eax
18767 + sbbl $0, %edx
18768 movl %eax, (v)
18769 movl %edx, 4(v)
18770 RET_ENDP
18771 @@ -143,6 +286,13 @@ BEGIN(add_unless)
18772 adcl %edx, %edi
18773 addl (v), %eax
18774 adcl 4(v), %edx
18775 +
18776 +#ifdef CONFIG_PAX_REFCOUNT
18777 + into
18778 +1234:
18779 + _ASM_EXTABLE(1234b, 2f)
18780 +#endif
18781 +
18782 cmpl %eax, %esi
18783 je 3f
18784 1:
18785 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
18786 1:
18787 addl $1, %eax
18788 adcl $0, %edx
18789 +
18790 +#ifdef CONFIG_PAX_REFCOUNT
18791 + into
18792 +1234:
18793 + _ASM_EXTABLE(1234b, 2f)
18794 +#endif
18795 +
18796 movl %eax, (v)
18797 movl %edx, 4(v)
18798 movl $1, %eax
18799 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
18800 movl 4(v), %edx
18801 subl $1, %eax
18802 sbbl $0, %edx
18803 +
18804 +#ifdef CONFIG_PAX_REFCOUNT
18805 + into
18806 +1234:
18807 + _ASM_EXTABLE(1234b, 1f)
18808 +#endif
18809 +
18810 js 1f
18811 movl %eax, (v)
18812 movl %edx, 4(v)
18813 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
18814 index 391a083..d658e9f 100644
18815 --- a/arch/x86/lib/atomic64_cx8_32.S
18816 +++ b/arch/x86/lib/atomic64_cx8_32.S
18817 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
18818 CFI_STARTPROC
18819
18820 read64 %ecx
18821 + pax_force_retaddr
18822 ret
18823 CFI_ENDPROC
18824 ENDPROC(atomic64_read_cx8)
18825
18826 +ENTRY(atomic64_read_unchecked_cx8)
18827 + CFI_STARTPROC
18828 +
18829 + read64 %ecx
18830 + pax_force_retaddr
18831 + ret
18832 + CFI_ENDPROC
18833 +ENDPROC(atomic64_read_unchecked_cx8)
18834 +
18835 ENTRY(atomic64_set_cx8)
18836 CFI_STARTPROC
18837
18838 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
18839 cmpxchg8b (%esi)
18840 jne 1b
18841
18842 + pax_force_retaddr
18843 ret
18844 CFI_ENDPROC
18845 ENDPROC(atomic64_set_cx8)
18846
18847 +ENTRY(atomic64_set_unchecked_cx8)
18848 + CFI_STARTPROC
18849 +
18850 +1:
18851 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
18852 + * are atomic on 586 and newer */
18853 + cmpxchg8b (%esi)
18854 + jne 1b
18855 +
18856 + pax_force_retaddr
18857 + ret
18858 + CFI_ENDPROC
18859 +ENDPROC(atomic64_set_unchecked_cx8)
18860 +
18861 ENTRY(atomic64_xchg_cx8)
18862 CFI_STARTPROC
18863
18864 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
18865 cmpxchg8b (%esi)
18866 jne 1b
18867
18868 + pax_force_retaddr
18869 ret
18870 CFI_ENDPROC
18871 ENDPROC(atomic64_xchg_cx8)
18872
18873 -.macro addsub_return func ins insc
18874 -ENTRY(atomic64_\func\()_return_cx8)
18875 +.macro addsub_return func ins insc unchecked=""
18876 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
18877 CFI_STARTPROC
18878 SAVE ebp
18879 SAVE ebx
18880 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
18881 movl %edx, %ecx
18882 \ins\()l %esi, %ebx
18883 \insc\()l %edi, %ecx
18884 +
18885 +.ifb \unchecked
18886 +#ifdef CONFIG_PAX_REFCOUNT
18887 + into
18888 +2:
18889 + _ASM_EXTABLE(2b, 3f)
18890 +#endif
18891 +.endif
18892 +
18893 LOCK_PREFIX
18894 cmpxchg8b (%ebp)
18895 jne 1b
18896 -
18897 -10:
18898 movl %ebx, %eax
18899 movl %ecx, %edx
18900 +
18901 +.ifb \unchecked
18902 +#ifdef CONFIG_PAX_REFCOUNT
18903 +3:
18904 +#endif
18905 +.endif
18906 +
18907 RESTORE edi
18908 RESTORE esi
18909 RESTORE ebx
18910 RESTORE ebp
18911 + pax_force_retaddr
18912 ret
18913 CFI_ENDPROC
18914 -ENDPROC(atomic64_\func\()_return_cx8)
18915 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
18916 .endm
18917
18918 addsub_return add add adc
18919 addsub_return sub sub sbb
18920 +addsub_return add add adc _unchecked
18921 +addsub_return sub sub sbb _unchecked
18922
18923 -.macro incdec_return func ins insc
18924 -ENTRY(atomic64_\func\()_return_cx8)
18925 +.macro incdec_return func ins insc unchecked
18926 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
18927 CFI_STARTPROC
18928 SAVE ebx
18929
18930 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
18931 movl %edx, %ecx
18932 \ins\()l $1, %ebx
18933 \insc\()l $0, %ecx
18934 +
18935 +.ifb \unchecked
18936 +#ifdef CONFIG_PAX_REFCOUNT
18937 + into
18938 +2:
18939 + _ASM_EXTABLE(2b, 3f)
18940 +#endif
18941 +.endif
18942 +
18943 LOCK_PREFIX
18944 cmpxchg8b (%esi)
18945 jne 1b
18946
18947 -10:
18948 movl %ebx, %eax
18949 movl %ecx, %edx
18950 +
18951 +.ifb \unchecked
18952 +#ifdef CONFIG_PAX_REFCOUNT
18953 +3:
18954 +#endif
18955 +.endif
18956 +
18957 RESTORE ebx
18958 + pax_force_retaddr
18959 ret
18960 CFI_ENDPROC
18961 -ENDPROC(atomic64_\func\()_return_cx8)
18962 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
18963 .endm
18964
18965 incdec_return inc add adc
18966 incdec_return dec sub sbb
18967 +incdec_return inc add adc _unchecked
18968 +incdec_return dec sub sbb _unchecked
18969
18970 ENTRY(atomic64_dec_if_positive_cx8)
18971 CFI_STARTPROC
18972 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
18973 movl %edx, %ecx
18974 subl $1, %ebx
18975 sbb $0, %ecx
18976 +
18977 +#ifdef CONFIG_PAX_REFCOUNT
18978 + into
18979 +1234:
18980 + _ASM_EXTABLE(1234b, 2f)
18981 +#endif
18982 +
18983 js 2f
18984 LOCK_PREFIX
18985 cmpxchg8b (%esi)
18986 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
18987 movl %ebx, %eax
18988 movl %ecx, %edx
18989 RESTORE ebx
18990 + pax_force_retaddr
18991 ret
18992 CFI_ENDPROC
18993 ENDPROC(atomic64_dec_if_positive_cx8)
18994 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
18995 movl %edx, %ecx
18996 addl %esi, %ebx
18997 adcl %edi, %ecx
18998 +
18999 +#ifdef CONFIG_PAX_REFCOUNT
19000 + into
19001 +1234:
19002 + _ASM_EXTABLE(1234b, 3f)
19003 +#endif
19004 +
19005 LOCK_PREFIX
19006 cmpxchg8b (%ebp)
19007 jne 1b
19008 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
19009 CFI_ADJUST_CFA_OFFSET -8
19010 RESTORE ebx
19011 RESTORE ebp
19012 + pax_force_retaddr
19013 ret
19014 4:
19015 cmpl %edx, 4(%esp)
19016 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
19017 movl %edx, %ecx
19018 addl $1, %ebx
19019 adcl $0, %ecx
19020 +
19021 +#ifdef CONFIG_PAX_REFCOUNT
19022 + into
19023 +1234:
19024 + _ASM_EXTABLE(1234b, 3f)
19025 +#endif
19026 +
19027 LOCK_PREFIX
19028 cmpxchg8b (%esi)
19029 jne 1b
19030 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
19031 movl $1, %eax
19032 3:
19033 RESTORE ebx
19034 + pax_force_retaddr
19035 ret
19036 4:
19037 testl %edx, %edx
19038 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
19039 index 78d16a5..fbcf666 100644
19040 --- a/arch/x86/lib/checksum_32.S
19041 +++ b/arch/x86/lib/checksum_32.S
19042 @@ -28,7 +28,8 @@
19043 #include <linux/linkage.h>
19044 #include <asm/dwarf2.h>
19045 #include <asm/errno.h>
19046 -
19047 +#include <asm/segment.h>
19048 +
19049 /*
19050 * computes a partial checksum, e.g. for TCP/UDP fragments
19051 */
19052 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
19053
19054 #define ARGBASE 16
19055 #define FP 12
19056 -
19057 -ENTRY(csum_partial_copy_generic)
19058 +
19059 +ENTRY(csum_partial_copy_generic_to_user)
19060 CFI_STARTPROC
19061 +
19062 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19063 + pushl_cfi %gs
19064 + popl_cfi %es
19065 + jmp csum_partial_copy_generic
19066 +#endif
19067 +
19068 +ENTRY(csum_partial_copy_generic_from_user)
19069 +
19070 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19071 + pushl_cfi %gs
19072 + popl_cfi %ds
19073 +#endif
19074 +
19075 +ENTRY(csum_partial_copy_generic)
19076 subl $4,%esp
19077 CFI_ADJUST_CFA_OFFSET 4
19078 pushl_cfi %edi
19079 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
19080 jmp 4f
19081 SRC(1: movw (%esi), %bx )
19082 addl $2, %esi
19083 -DST( movw %bx, (%edi) )
19084 +DST( movw %bx, %es:(%edi) )
19085 addl $2, %edi
19086 addw %bx, %ax
19087 adcl $0, %eax
19088 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
19089 SRC(1: movl (%esi), %ebx )
19090 SRC( movl 4(%esi), %edx )
19091 adcl %ebx, %eax
19092 -DST( movl %ebx, (%edi) )
19093 +DST( movl %ebx, %es:(%edi) )
19094 adcl %edx, %eax
19095 -DST( movl %edx, 4(%edi) )
19096 +DST( movl %edx, %es:4(%edi) )
19097
19098 SRC( movl 8(%esi), %ebx )
19099 SRC( movl 12(%esi), %edx )
19100 adcl %ebx, %eax
19101 -DST( movl %ebx, 8(%edi) )
19102 +DST( movl %ebx, %es:8(%edi) )
19103 adcl %edx, %eax
19104 -DST( movl %edx, 12(%edi) )
19105 +DST( movl %edx, %es:12(%edi) )
19106
19107 SRC( movl 16(%esi), %ebx )
19108 SRC( movl 20(%esi), %edx )
19109 adcl %ebx, %eax
19110 -DST( movl %ebx, 16(%edi) )
19111 +DST( movl %ebx, %es:16(%edi) )
19112 adcl %edx, %eax
19113 -DST( movl %edx, 20(%edi) )
19114 +DST( movl %edx, %es:20(%edi) )
19115
19116 SRC( movl 24(%esi), %ebx )
19117 SRC( movl 28(%esi), %edx )
19118 adcl %ebx, %eax
19119 -DST( movl %ebx, 24(%edi) )
19120 +DST( movl %ebx, %es:24(%edi) )
19121 adcl %edx, %eax
19122 -DST( movl %edx, 28(%edi) )
19123 +DST( movl %edx, %es:28(%edi) )
19124
19125 lea 32(%esi), %esi
19126 lea 32(%edi), %edi
19127 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
19128 shrl $2, %edx # This clears CF
19129 SRC(3: movl (%esi), %ebx )
19130 adcl %ebx, %eax
19131 -DST( movl %ebx, (%edi) )
19132 +DST( movl %ebx, %es:(%edi) )
19133 lea 4(%esi), %esi
19134 lea 4(%edi), %edi
19135 dec %edx
19136 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
19137 jb 5f
19138 SRC( movw (%esi), %cx )
19139 leal 2(%esi), %esi
19140 -DST( movw %cx, (%edi) )
19141 +DST( movw %cx, %es:(%edi) )
19142 leal 2(%edi), %edi
19143 je 6f
19144 shll $16,%ecx
19145 SRC(5: movb (%esi), %cl )
19146 -DST( movb %cl, (%edi) )
19147 +DST( movb %cl, %es:(%edi) )
19148 6: addl %ecx, %eax
19149 adcl $0, %eax
19150 7:
19151 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
19152
19153 6001:
19154 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19155 - movl $-EFAULT, (%ebx)
19156 + movl $-EFAULT, %ss:(%ebx)
19157
19158 # zero the complete destination - computing the rest
19159 # is too much work
19160 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
19161
19162 6002:
19163 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19164 - movl $-EFAULT,(%ebx)
19165 + movl $-EFAULT,%ss:(%ebx)
19166 jmp 5000b
19167
19168 .previous
19169
19170 + pushl_cfi %ss
19171 + popl_cfi %ds
19172 + pushl_cfi %ss
19173 + popl_cfi %es
19174 popl_cfi %ebx
19175 CFI_RESTORE ebx
19176 popl_cfi %esi
19177 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
19178 popl_cfi %ecx # equivalent to addl $4,%esp
19179 ret
19180 CFI_ENDPROC
19181 -ENDPROC(csum_partial_copy_generic)
19182 +ENDPROC(csum_partial_copy_generic_to_user)
19183
19184 #else
19185
19186 /* Version for PentiumII/PPro */
19187
19188 #define ROUND1(x) \
19189 + nop; nop; nop; \
19190 SRC(movl x(%esi), %ebx ) ; \
19191 addl %ebx, %eax ; \
19192 - DST(movl %ebx, x(%edi) ) ;
19193 + DST(movl %ebx, %es:x(%edi)) ;
19194
19195 #define ROUND(x) \
19196 + nop; nop; nop; \
19197 SRC(movl x(%esi), %ebx ) ; \
19198 adcl %ebx, %eax ; \
19199 - DST(movl %ebx, x(%edi) ) ;
19200 + DST(movl %ebx, %es:x(%edi)) ;
19201
19202 #define ARGBASE 12
19203 -
19204 -ENTRY(csum_partial_copy_generic)
19205 +
19206 +ENTRY(csum_partial_copy_generic_to_user)
19207 CFI_STARTPROC
19208 +
19209 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19210 + pushl_cfi %gs
19211 + popl_cfi %es
19212 + jmp csum_partial_copy_generic
19213 +#endif
19214 +
19215 +ENTRY(csum_partial_copy_generic_from_user)
19216 +
19217 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19218 + pushl_cfi %gs
19219 + popl_cfi %ds
19220 +#endif
19221 +
19222 +ENTRY(csum_partial_copy_generic)
19223 pushl_cfi %ebx
19224 CFI_REL_OFFSET ebx, 0
19225 pushl_cfi %edi
19226 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
19227 subl %ebx, %edi
19228 lea -1(%esi),%edx
19229 andl $-32,%edx
19230 - lea 3f(%ebx,%ebx), %ebx
19231 + lea 3f(%ebx,%ebx,2), %ebx
19232 testl %esi, %esi
19233 jmp *%ebx
19234 1: addl $64,%esi
19235 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
19236 jb 5f
19237 SRC( movw (%esi), %dx )
19238 leal 2(%esi), %esi
19239 -DST( movw %dx, (%edi) )
19240 +DST( movw %dx, %es:(%edi) )
19241 leal 2(%edi), %edi
19242 je 6f
19243 shll $16,%edx
19244 5:
19245 SRC( movb (%esi), %dl )
19246 -DST( movb %dl, (%edi) )
19247 +DST( movb %dl, %es:(%edi) )
19248 6: addl %edx, %eax
19249 adcl $0, %eax
19250 7:
19251 .section .fixup, "ax"
19252 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19253 - movl $-EFAULT, (%ebx)
19254 + movl $-EFAULT, %ss:(%ebx)
19255 # zero the complete destination (computing the rest is too much work)
19256 movl ARGBASE+8(%esp),%edi # dst
19257 movl ARGBASE+12(%esp),%ecx # len
19258 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
19259 rep; stosb
19260 jmp 7b
19261 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19262 - movl $-EFAULT, (%ebx)
19263 + movl $-EFAULT, %ss:(%ebx)
19264 jmp 7b
19265 .previous
19266
19267 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19268 + pushl_cfi %ss
19269 + popl_cfi %ds
19270 + pushl_cfi %ss
19271 + popl_cfi %es
19272 +#endif
19273 +
19274 popl_cfi %esi
19275 CFI_RESTORE esi
19276 popl_cfi %edi
19277 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
19278 CFI_RESTORE ebx
19279 ret
19280 CFI_ENDPROC
19281 -ENDPROC(csum_partial_copy_generic)
19282 +ENDPROC(csum_partial_copy_generic_to_user)
19283
19284 #undef ROUND
19285 #undef ROUND1
19286 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
19287 index f2145cf..cea889d 100644
19288 --- a/arch/x86/lib/clear_page_64.S
19289 +++ b/arch/x86/lib/clear_page_64.S
19290 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
19291 movl $4096/8,%ecx
19292 xorl %eax,%eax
19293 rep stosq
19294 + pax_force_retaddr
19295 ret
19296 CFI_ENDPROC
19297 ENDPROC(clear_page_c)
19298 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
19299 movl $4096,%ecx
19300 xorl %eax,%eax
19301 rep stosb
19302 + pax_force_retaddr
19303 ret
19304 CFI_ENDPROC
19305 ENDPROC(clear_page_c_e)
19306 @@ -43,6 +45,7 @@ ENTRY(clear_page)
19307 leaq 64(%rdi),%rdi
19308 jnz .Lloop
19309 nop
19310 + pax_force_retaddr
19311 ret
19312 CFI_ENDPROC
19313 .Lclear_page_end:
19314 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
19315
19316 #include <asm/cpufeature.h>
19317
19318 - .section .altinstr_replacement,"ax"
19319 + .section .altinstr_replacement,"a"
19320 1: .byte 0xeb /* jmp <disp8> */
19321 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19322 2: .byte 0xeb /* jmp <disp8> */
19323 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
19324 index 1e572c5..2a162cd 100644
19325 --- a/arch/x86/lib/cmpxchg16b_emu.S
19326 +++ b/arch/x86/lib/cmpxchg16b_emu.S
19327 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
19328
19329 popf
19330 mov $1, %al
19331 + pax_force_retaddr
19332 ret
19333
19334 not_same:
19335 popf
19336 xor %al,%al
19337 + pax_force_retaddr
19338 ret
19339
19340 CFI_ENDPROC
19341 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
19342 index 01c805b..dccb07f 100644
19343 --- a/arch/x86/lib/copy_page_64.S
19344 +++ b/arch/x86/lib/copy_page_64.S
19345 @@ -9,6 +9,7 @@ copy_page_c:
19346 CFI_STARTPROC
19347 movl $4096/8,%ecx
19348 rep movsq
19349 + pax_force_retaddr
19350 ret
19351 CFI_ENDPROC
19352 ENDPROC(copy_page_c)
19353 @@ -39,7 +40,7 @@ ENTRY(copy_page)
19354 movq 16 (%rsi), %rdx
19355 movq 24 (%rsi), %r8
19356 movq 32 (%rsi), %r9
19357 - movq 40 (%rsi), %r10
19358 + movq 40 (%rsi), %r13
19359 movq 48 (%rsi), %r11
19360 movq 56 (%rsi), %r12
19361
19362 @@ -50,7 +51,7 @@ ENTRY(copy_page)
19363 movq %rdx, 16 (%rdi)
19364 movq %r8, 24 (%rdi)
19365 movq %r9, 32 (%rdi)
19366 - movq %r10, 40 (%rdi)
19367 + movq %r13, 40 (%rdi)
19368 movq %r11, 48 (%rdi)
19369 movq %r12, 56 (%rdi)
19370
19371 @@ -69,7 +70,7 @@ ENTRY(copy_page)
19372 movq 16 (%rsi), %rdx
19373 movq 24 (%rsi), %r8
19374 movq 32 (%rsi), %r9
19375 - movq 40 (%rsi), %r10
19376 + movq 40 (%rsi), %r13
19377 movq 48 (%rsi), %r11
19378 movq 56 (%rsi), %r12
19379
19380 @@ -78,7 +79,7 @@ ENTRY(copy_page)
19381 movq %rdx, 16 (%rdi)
19382 movq %r8, 24 (%rdi)
19383 movq %r9, 32 (%rdi)
19384 - movq %r10, 40 (%rdi)
19385 + movq %r13, 40 (%rdi)
19386 movq %r11, 48 (%rdi)
19387 movq %r12, 56 (%rdi)
19388
19389 @@ -95,6 +96,7 @@ ENTRY(copy_page)
19390 CFI_RESTORE r13
19391 addq $3*8,%rsp
19392 CFI_ADJUST_CFA_OFFSET -3*8
19393 + pax_force_retaddr
19394 ret
19395 .Lcopy_page_end:
19396 CFI_ENDPROC
19397 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
19398
19399 #include <asm/cpufeature.h>
19400
19401 - .section .altinstr_replacement,"ax"
19402 + .section .altinstr_replacement,"a"
19403 1: .byte 0xeb /* jmp <disp8> */
19404 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19405 2:
19406 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
19407 index 0248402..821c786 100644
19408 --- a/arch/x86/lib/copy_user_64.S
19409 +++ b/arch/x86/lib/copy_user_64.S
19410 @@ -16,6 +16,7 @@
19411 #include <asm/thread_info.h>
19412 #include <asm/cpufeature.h>
19413 #include <asm/alternative-asm.h>
19414 +#include <asm/pgtable.h>
19415
19416 /*
19417 * By placing feature2 after feature1 in altinstructions section, we logically
19418 @@ -29,7 +30,7 @@
19419 .byte 0xe9 /* 32bit jump */
19420 .long \orig-1f /* by default jump to orig */
19421 1:
19422 - .section .altinstr_replacement,"ax"
19423 + .section .altinstr_replacement,"a"
19424 2: .byte 0xe9 /* near jump with 32bit immediate */
19425 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
19426 3: .byte 0xe9 /* near jump with 32bit immediate */
19427 @@ -71,47 +72,20 @@
19428 #endif
19429 .endm
19430
19431 -/* Standard copy_to_user with segment limit checking */
19432 -ENTRY(_copy_to_user)
19433 - CFI_STARTPROC
19434 - GET_THREAD_INFO(%rax)
19435 - movq %rdi,%rcx
19436 - addq %rdx,%rcx
19437 - jc bad_to_user
19438 - cmpq TI_addr_limit(%rax),%rcx
19439 - ja bad_to_user
19440 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
19441 - copy_user_generic_unrolled,copy_user_generic_string, \
19442 - copy_user_enhanced_fast_string
19443 - CFI_ENDPROC
19444 -ENDPROC(_copy_to_user)
19445 -
19446 -/* Standard copy_from_user with segment limit checking */
19447 -ENTRY(_copy_from_user)
19448 - CFI_STARTPROC
19449 - GET_THREAD_INFO(%rax)
19450 - movq %rsi,%rcx
19451 - addq %rdx,%rcx
19452 - jc bad_from_user
19453 - cmpq TI_addr_limit(%rax),%rcx
19454 - ja bad_from_user
19455 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
19456 - copy_user_generic_unrolled,copy_user_generic_string, \
19457 - copy_user_enhanced_fast_string
19458 - CFI_ENDPROC
19459 -ENDPROC(_copy_from_user)
19460 -
19461 .section .fixup,"ax"
19462 /* must zero dest */
19463 ENTRY(bad_from_user)
19464 bad_from_user:
19465 CFI_STARTPROC
19466 + testl %edx,%edx
19467 + js bad_to_user
19468 movl %edx,%ecx
19469 xorl %eax,%eax
19470 rep
19471 stosb
19472 bad_to_user:
19473 movl %edx,%eax
19474 + pax_force_retaddr
19475 ret
19476 CFI_ENDPROC
19477 ENDPROC(bad_from_user)
19478 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
19479 jz 17f
19480 1: movq (%rsi),%r8
19481 2: movq 1*8(%rsi),%r9
19482 -3: movq 2*8(%rsi),%r10
19483 +3: movq 2*8(%rsi),%rax
19484 4: movq 3*8(%rsi),%r11
19485 5: movq %r8,(%rdi)
19486 6: movq %r9,1*8(%rdi)
19487 -7: movq %r10,2*8(%rdi)
19488 +7: movq %rax,2*8(%rdi)
19489 8: movq %r11,3*8(%rdi)
19490 9: movq 4*8(%rsi),%r8
19491 10: movq 5*8(%rsi),%r9
19492 -11: movq 6*8(%rsi),%r10
19493 +11: movq 6*8(%rsi),%rax
19494 12: movq 7*8(%rsi),%r11
19495 13: movq %r8,4*8(%rdi)
19496 14: movq %r9,5*8(%rdi)
19497 -15: movq %r10,6*8(%rdi)
19498 +15: movq %rax,6*8(%rdi)
19499 16: movq %r11,7*8(%rdi)
19500 leaq 64(%rsi),%rsi
19501 leaq 64(%rdi),%rdi
19502 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
19503 decl %ecx
19504 jnz 21b
19505 23: xor %eax,%eax
19506 + pax_force_retaddr
19507 ret
19508
19509 .section .fixup,"ax"
19510 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
19511 3: rep
19512 movsb
19513 4: xorl %eax,%eax
19514 + pax_force_retaddr
19515 ret
19516
19517 .section .fixup,"ax"
19518 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
19519 1: rep
19520 movsb
19521 2: xorl %eax,%eax
19522 + pax_force_retaddr
19523 ret
19524
19525 .section .fixup,"ax"
19526 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
19527 index cb0c112..e3a6895 100644
19528 --- a/arch/x86/lib/copy_user_nocache_64.S
19529 +++ b/arch/x86/lib/copy_user_nocache_64.S
19530 @@ -8,12 +8,14 @@
19531
19532 #include <linux/linkage.h>
19533 #include <asm/dwarf2.h>
19534 +#include <asm/alternative-asm.h>
19535
19536 #define FIX_ALIGNMENT 1
19537
19538 #include <asm/current.h>
19539 #include <asm/asm-offsets.h>
19540 #include <asm/thread_info.h>
19541 +#include <asm/pgtable.h>
19542
19543 .macro ALIGN_DESTINATION
19544 #ifdef FIX_ALIGNMENT
19545 @@ -50,6 +52,15 @@
19546 */
19547 ENTRY(__copy_user_nocache)
19548 CFI_STARTPROC
19549 +
19550 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19551 + mov $PAX_USER_SHADOW_BASE,%rcx
19552 + cmp %rcx,%rsi
19553 + jae 1f
19554 + add %rcx,%rsi
19555 +1:
19556 +#endif
19557 +
19558 cmpl $8,%edx
19559 jb 20f /* less then 8 bytes, go to byte copy loop */
19560 ALIGN_DESTINATION
19561 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
19562 jz 17f
19563 1: movq (%rsi),%r8
19564 2: movq 1*8(%rsi),%r9
19565 -3: movq 2*8(%rsi),%r10
19566 +3: movq 2*8(%rsi),%rax
19567 4: movq 3*8(%rsi),%r11
19568 5: movnti %r8,(%rdi)
19569 6: movnti %r9,1*8(%rdi)
19570 -7: movnti %r10,2*8(%rdi)
19571 +7: movnti %rax,2*8(%rdi)
19572 8: movnti %r11,3*8(%rdi)
19573 9: movq 4*8(%rsi),%r8
19574 10: movq 5*8(%rsi),%r9
19575 -11: movq 6*8(%rsi),%r10
19576 +11: movq 6*8(%rsi),%rax
19577 12: movq 7*8(%rsi),%r11
19578 13: movnti %r8,4*8(%rdi)
19579 14: movnti %r9,5*8(%rdi)
19580 -15: movnti %r10,6*8(%rdi)
19581 +15: movnti %rax,6*8(%rdi)
19582 16: movnti %r11,7*8(%rdi)
19583 leaq 64(%rsi),%rsi
19584 leaq 64(%rdi),%rdi
19585 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
19586 jnz 21b
19587 23: xorl %eax,%eax
19588 sfence
19589 + pax_force_retaddr
19590 ret
19591
19592 .section .fixup,"ax"
19593 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
19594 index fb903b7..c92b7f7 100644
19595 --- a/arch/x86/lib/csum-copy_64.S
19596 +++ b/arch/x86/lib/csum-copy_64.S
19597 @@ -8,6 +8,7 @@
19598 #include <linux/linkage.h>
19599 #include <asm/dwarf2.h>
19600 #include <asm/errno.h>
19601 +#include <asm/alternative-asm.h>
19602
19603 /*
19604 * Checksum copy with exception handling.
19605 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
19606 CFI_RESTORE rbp
19607 addq $7*8, %rsp
19608 CFI_ADJUST_CFA_OFFSET -7*8
19609 + pax_force_retaddr 0, 1
19610 ret
19611 CFI_RESTORE_STATE
19612
19613 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
19614 index 459b58a..9570bc7 100644
19615 --- a/arch/x86/lib/csum-wrappers_64.c
19616 +++ b/arch/x86/lib/csum-wrappers_64.c
19617 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
19618 len -= 2;
19619 }
19620 }
19621 - isum = csum_partial_copy_generic((__force const void *)src,
19622 +
19623 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19624 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19625 + src += PAX_USER_SHADOW_BASE;
19626 +#endif
19627 +
19628 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
19629 dst, len, isum, errp, NULL);
19630 if (unlikely(*errp))
19631 goto out_err;
19632 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
19633 }
19634
19635 *errp = 0;
19636 - return csum_partial_copy_generic(src, (void __force *)dst,
19637 +
19638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19639 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19640 + dst += PAX_USER_SHADOW_BASE;
19641 +#endif
19642 +
19643 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
19644 len, isum, NULL, errp);
19645 }
19646 EXPORT_SYMBOL(csum_partial_copy_to_user);
19647 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
19648 index 51f1504..ddac4c1 100644
19649 --- a/arch/x86/lib/getuser.S
19650 +++ b/arch/x86/lib/getuser.S
19651 @@ -33,15 +33,38 @@
19652 #include <asm/asm-offsets.h>
19653 #include <asm/thread_info.h>
19654 #include <asm/asm.h>
19655 +#include <asm/segment.h>
19656 +#include <asm/pgtable.h>
19657 +#include <asm/alternative-asm.h>
19658 +
19659 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19660 +#define __copyuser_seg gs;
19661 +#else
19662 +#define __copyuser_seg
19663 +#endif
19664
19665 .text
19666 ENTRY(__get_user_1)
19667 CFI_STARTPROC
19668 +
19669 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19670 GET_THREAD_INFO(%_ASM_DX)
19671 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19672 jae bad_get_user
19673 -1: movzb (%_ASM_AX),%edx
19674 +
19675 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19676 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19677 + cmp %_ASM_DX,%_ASM_AX
19678 + jae 1234f
19679 + add %_ASM_DX,%_ASM_AX
19680 +1234:
19681 +#endif
19682 +
19683 +#endif
19684 +
19685 +1: __copyuser_seg movzb (%_ASM_AX),%edx
19686 xor %eax,%eax
19687 + pax_force_retaddr
19688 ret
19689 CFI_ENDPROC
19690 ENDPROC(__get_user_1)
19691 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
19692 ENTRY(__get_user_2)
19693 CFI_STARTPROC
19694 add $1,%_ASM_AX
19695 +
19696 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19697 jc bad_get_user
19698 GET_THREAD_INFO(%_ASM_DX)
19699 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19700 jae bad_get_user
19701 -2: movzwl -1(%_ASM_AX),%edx
19702 +
19703 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19704 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19705 + cmp %_ASM_DX,%_ASM_AX
19706 + jae 1234f
19707 + add %_ASM_DX,%_ASM_AX
19708 +1234:
19709 +#endif
19710 +
19711 +#endif
19712 +
19713 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19714 xor %eax,%eax
19715 + pax_force_retaddr
19716 ret
19717 CFI_ENDPROC
19718 ENDPROC(__get_user_2)
19719 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
19720 ENTRY(__get_user_4)
19721 CFI_STARTPROC
19722 add $3,%_ASM_AX
19723 +
19724 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19725 jc bad_get_user
19726 GET_THREAD_INFO(%_ASM_DX)
19727 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19728 jae bad_get_user
19729 -3: mov -3(%_ASM_AX),%edx
19730 +
19731 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19732 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19733 + cmp %_ASM_DX,%_ASM_AX
19734 + jae 1234f
19735 + add %_ASM_DX,%_ASM_AX
19736 +1234:
19737 +#endif
19738 +
19739 +#endif
19740 +
19741 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
19742 xor %eax,%eax
19743 + pax_force_retaddr
19744 ret
19745 CFI_ENDPROC
19746 ENDPROC(__get_user_4)
19747 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
19748 GET_THREAD_INFO(%_ASM_DX)
19749 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19750 jae bad_get_user
19751 +
19752 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19753 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19754 + cmp %_ASM_DX,%_ASM_AX
19755 + jae 1234f
19756 + add %_ASM_DX,%_ASM_AX
19757 +1234:
19758 +#endif
19759 +
19760 4: movq -7(%_ASM_AX),%_ASM_DX
19761 xor %eax,%eax
19762 + pax_force_retaddr
19763 ret
19764 CFI_ENDPROC
19765 ENDPROC(__get_user_8)
19766 @@ -91,6 +152,7 @@ bad_get_user:
19767 CFI_STARTPROC
19768 xor %edx,%edx
19769 mov $(-EFAULT),%_ASM_AX
19770 + pax_force_retaddr
19771 ret
19772 CFI_ENDPROC
19773 END(bad_get_user)
19774 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
19775 index 374562e..a75830b 100644
19776 --- a/arch/x86/lib/insn.c
19777 +++ b/arch/x86/lib/insn.c
19778 @@ -21,6 +21,11 @@
19779 #include <linux/string.h>
19780 #include <asm/inat.h>
19781 #include <asm/insn.h>
19782 +#ifdef __KERNEL__
19783 +#include <asm/pgtable_types.h>
19784 +#else
19785 +#define ktla_ktva(addr) addr
19786 +#endif
19787
19788 /* Verify next sizeof(t) bytes can be on the same instruction */
19789 #define validate_next(t, insn, n) \
19790 @@ -49,8 +54,8 @@
19791 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
19792 {
19793 memset(insn, 0, sizeof(*insn));
19794 - insn->kaddr = kaddr;
19795 - insn->next_byte = kaddr;
19796 + insn->kaddr = ktla_ktva(kaddr);
19797 + insn->next_byte = ktla_ktva(kaddr);
19798 insn->x86_64 = x86_64 ? 1 : 0;
19799 insn->opnd_bytes = 4;
19800 if (x86_64)
19801 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
19802 index 05a95e7..326f2fa 100644
19803 --- a/arch/x86/lib/iomap_copy_64.S
19804 +++ b/arch/x86/lib/iomap_copy_64.S
19805 @@ -17,6 +17,7 @@
19806
19807 #include <linux/linkage.h>
19808 #include <asm/dwarf2.h>
19809 +#include <asm/alternative-asm.h>
19810
19811 /*
19812 * override generic version in lib/iomap_copy.c
19813 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
19814 CFI_STARTPROC
19815 movl %edx,%ecx
19816 rep movsd
19817 + pax_force_retaddr
19818 ret
19819 CFI_ENDPROC
19820 ENDPROC(__iowrite32_copy)
19821 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
19822 index efbf2a0..8893637 100644
19823 --- a/arch/x86/lib/memcpy_64.S
19824 +++ b/arch/x86/lib/memcpy_64.S
19825 @@ -34,6 +34,7 @@
19826 rep movsq
19827 movl %edx, %ecx
19828 rep movsb
19829 + pax_force_retaddr
19830 ret
19831 .Lmemcpy_e:
19832 .previous
19833 @@ -51,6 +52,7 @@
19834
19835 movl %edx, %ecx
19836 rep movsb
19837 + pax_force_retaddr
19838 ret
19839 .Lmemcpy_e_e:
19840 .previous
19841 @@ -81,13 +83,13 @@ ENTRY(memcpy)
19842 */
19843 movq 0*8(%rsi), %r8
19844 movq 1*8(%rsi), %r9
19845 - movq 2*8(%rsi), %r10
19846 + movq 2*8(%rsi), %rcx
19847 movq 3*8(%rsi), %r11
19848 leaq 4*8(%rsi), %rsi
19849
19850 movq %r8, 0*8(%rdi)
19851 movq %r9, 1*8(%rdi)
19852 - movq %r10, 2*8(%rdi)
19853 + movq %rcx, 2*8(%rdi)
19854 movq %r11, 3*8(%rdi)
19855 leaq 4*8(%rdi), %rdi
19856 jae .Lcopy_forward_loop
19857 @@ -110,12 +112,12 @@ ENTRY(memcpy)
19858 subq $0x20, %rdx
19859 movq -1*8(%rsi), %r8
19860 movq -2*8(%rsi), %r9
19861 - movq -3*8(%rsi), %r10
19862 + movq -3*8(%rsi), %rcx
19863 movq -4*8(%rsi), %r11
19864 leaq -4*8(%rsi), %rsi
19865 movq %r8, -1*8(%rdi)
19866 movq %r9, -2*8(%rdi)
19867 - movq %r10, -3*8(%rdi)
19868 + movq %rcx, -3*8(%rdi)
19869 movq %r11, -4*8(%rdi)
19870 leaq -4*8(%rdi), %rdi
19871 jae .Lcopy_backward_loop
19872 @@ -135,12 +137,13 @@ ENTRY(memcpy)
19873 */
19874 movq 0*8(%rsi), %r8
19875 movq 1*8(%rsi), %r9
19876 - movq -2*8(%rsi, %rdx), %r10
19877 + movq -2*8(%rsi, %rdx), %rcx
19878 movq -1*8(%rsi, %rdx), %r11
19879 movq %r8, 0*8(%rdi)
19880 movq %r9, 1*8(%rdi)
19881 - movq %r10, -2*8(%rdi, %rdx)
19882 + movq %rcx, -2*8(%rdi, %rdx)
19883 movq %r11, -1*8(%rdi, %rdx)
19884 + pax_force_retaddr
19885 retq
19886 .p2align 4
19887 .Lless_16bytes:
19888 @@ -153,6 +156,7 @@ ENTRY(memcpy)
19889 movq -1*8(%rsi, %rdx), %r9
19890 movq %r8, 0*8(%rdi)
19891 movq %r9, -1*8(%rdi, %rdx)
19892 + pax_force_retaddr
19893 retq
19894 .p2align 4
19895 .Lless_8bytes:
19896 @@ -166,6 +170,7 @@ ENTRY(memcpy)
19897 movl -4(%rsi, %rdx), %r8d
19898 movl %ecx, (%rdi)
19899 movl %r8d, -4(%rdi, %rdx)
19900 + pax_force_retaddr
19901 retq
19902 .p2align 4
19903 .Lless_3bytes:
19904 @@ -183,6 +188,7 @@ ENTRY(memcpy)
19905 jnz .Lloop_1
19906
19907 .Lend:
19908 + pax_force_retaddr
19909 retq
19910 CFI_ENDPROC
19911 ENDPROC(memcpy)
19912 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
19913 index ee16461..c39c199 100644
19914 --- a/arch/x86/lib/memmove_64.S
19915 +++ b/arch/x86/lib/memmove_64.S
19916 @@ -61,13 +61,13 @@ ENTRY(memmove)
19917 5:
19918 sub $0x20, %rdx
19919 movq 0*8(%rsi), %r11
19920 - movq 1*8(%rsi), %r10
19921 + movq 1*8(%rsi), %rcx
19922 movq 2*8(%rsi), %r9
19923 movq 3*8(%rsi), %r8
19924 leaq 4*8(%rsi), %rsi
19925
19926 movq %r11, 0*8(%rdi)
19927 - movq %r10, 1*8(%rdi)
19928 + movq %rcx, 1*8(%rdi)
19929 movq %r9, 2*8(%rdi)
19930 movq %r8, 3*8(%rdi)
19931 leaq 4*8(%rdi), %rdi
19932 @@ -81,10 +81,10 @@ ENTRY(memmove)
19933 4:
19934 movq %rdx, %rcx
19935 movq -8(%rsi, %rdx), %r11
19936 - lea -8(%rdi, %rdx), %r10
19937 + lea -8(%rdi, %rdx), %r9
19938 shrq $3, %rcx
19939 rep movsq
19940 - movq %r11, (%r10)
19941 + movq %r11, (%r9)
19942 jmp 13f
19943 .Lmemmove_end_forward:
19944
19945 @@ -95,14 +95,14 @@ ENTRY(memmove)
19946 7:
19947 movq %rdx, %rcx
19948 movq (%rsi), %r11
19949 - movq %rdi, %r10
19950 + movq %rdi, %r9
19951 leaq -8(%rsi, %rdx), %rsi
19952 leaq -8(%rdi, %rdx), %rdi
19953 shrq $3, %rcx
19954 std
19955 rep movsq
19956 cld
19957 - movq %r11, (%r10)
19958 + movq %r11, (%r9)
19959 jmp 13f
19960
19961 /*
19962 @@ -127,13 +127,13 @@ ENTRY(memmove)
19963 8:
19964 subq $0x20, %rdx
19965 movq -1*8(%rsi), %r11
19966 - movq -2*8(%rsi), %r10
19967 + movq -2*8(%rsi), %rcx
19968 movq -3*8(%rsi), %r9
19969 movq -4*8(%rsi), %r8
19970 leaq -4*8(%rsi), %rsi
19971
19972 movq %r11, -1*8(%rdi)
19973 - movq %r10, -2*8(%rdi)
19974 + movq %rcx, -2*8(%rdi)
19975 movq %r9, -3*8(%rdi)
19976 movq %r8, -4*8(%rdi)
19977 leaq -4*8(%rdi), %rdi
19978 @@ -151,11 +151,11 @@ ENTRY(memmove)
19979 * Move data from 16 bytes to 31 bytes.
19980 */
19981 movq 0*8(%rsi), %r11
19982 - movq 1*8(%rsi), %r10
19983 + movq 1*8(%rsi), %rcx
19984 movq -2*8(%rsi, %rdx), %r9
19985 movq -1*8(%rsi, %rdx), %r8
19986 movq %r11, 0*8(%rdi)
19987 - movq %r10, 1*8(%rdi)
19988 + movq %rcx, 1*8(%rdi)
19989 movq %r9, -2*8(%rdi, %rdx)
19990 movq %r8, -1*8(%rdi, %rdx)
19991 jmp 13f
19992 @@ -167,9 +167,9 @@ ENTRY(memmove)
19993 * Move data from 8 bytes to 15 bytes.
19994 */
19995 movq 0*8(%rsi), %r11
19996 - movq -1*8(%rsi, %rdx), %r10
19997 + movq -1*8(%rsi, %rdx), %r9
19998 movq %r11, 0*8(%rdi)
19999 - movq %r10, -1*8(%rdi, %rdx)
20000 + movq %r9, -1*8(%rdi, %rdx)
20001 jmp 13f
20002 10:
20003 cmpq $4, %rdx
20004 @@ -178,9 +178,9 @@ ENTRY(memmove)
20005 * Move data from 4 bytes to 7 bytes.
20006 */
20007 movl (%rsi), %r11d
20008 - movl -4(%rsi, %rdx), %r10d
20009 + movl -4(%rsi, %rdx), %r9d
20010 movl %r11d, (%rdi)
20011 - movl %r10d, -4(%rdi, %rdx)
20012 + movl %r9d, -4(%rdi, %rdx)
20013 jmp 13f
20014 11:
20015 cmp $2, %rdx
20016 @@ -189,9 +189,9 @@ ENTRY(memmove)
20017 * Move data from 2 bytes to 3 bytes.
20018 */
20019 movw (%rsi), %r11w
20020 - movw -2(%rsi, %rdx), %r10w
20021 + movw -2(%rsi, %rdx), %r9w
20022 movw %r11w, (%rdi)
20023 - movw %r10w, -2(%rdi, %rdx)
20024 + movw %r9w, -2(%rdi, %rdx)
20025 jmp 13f
20026 12:
20027 cmp $1, %rdx
20028 @@ -202,6 +202,7 @@ ENTRY(memmove)
20029 movb (%rsi), %r11b
20030 movb %r11b, (%rdi)
20031 13:
20032 + pax_force_retaddr
20033 retq
20034 CFI_ENDPROC
20035
20036 @@ -210,6 +211,7 @@ ENTRY(memmove)
20037 /* Forward moving data. */
20038 movq %rdx, %rcx
20039 rep movsb
20040 + pax_force_retaddr
20041 retq
20042 .Lmemmove_end_forward_efs:
20043 .previous
20044 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
20045 index 79bd454..dff325a 100644
20046 --- a/arch/x86/lib/memset_64.S
20047 +++ b/arch/x86/lib/memset_64.S
20048 @@ -31,6 +31,7 @@
20049 movl %r8d,%ecx
20050 rep stosb
20051 movq %r9,%rax
20052 + pax_force_retaddr
20053 ret
20054 .Lmemset_e:
20055 .previous
20056 @@ -53,6 +54,7 @@
20057 movl %edx,%ecx
20058 rep stosb
20059 movq %r9,%rax
20060 + pax_force_retaddr
20061 ret
20062 .Lmemset_e_e:
20063 .previous
20064 @@ -60,13 +62,13 @@
20065 ENTRY(memset)
20066 ENTRY(__memset)
20067 CFI_STARTPROC
20068 - movq %rdi,%r10
20069 movq %rdx,%r11
20070
20071 /* expand byte value */
20072 movzbl %sil,%ecx
20073 movabs $0x0101010101010101,%rax
20074 mul %rcx /* with rax, clobbers rdx */
20075 + movq %rdi,%rdx
20076
20077 /* align dst */
20078 movl %edi,%r9d
20079 @@ -120,7 +122,8 @@ ENTRY(__memset)
20080 jnz .Lloop_1
20081
20082 .Lende:
20083 - movq %r10,%rax
20084 + movq %rdx,%rax
20085 + pax_force_retaddr
20086 ret
20087
20088 CFI_RESTORE_STATE
20089 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
20090 index c9f2d9b..e7fd2c0 100644
20091 --- a/arch/x86/lib/mmx_32.c
20092 +++ b/arch/x86/lib/mmx_32.c
20093 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
20094 {
20095 void *p;
20096 int i;
20097 + unsigned long cr0;
20098
20099 if (unlikely(in_interrupt()))
20100 return __memcpy(to, from, len);
20101 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
20102 kernel_fpu_begin();
20103
20104 __asm__ __volatile__ (
20105 - "1: prefetch (%0)\n" /* This set is 28 bytes */
20106 - " prefetch 64(%0)\n"
20107 - " prefetch 128(%0)\n"
20108 - " prefetch 192(%0)\n"
20109 - " prefetch 256(%0)\n"
20110 + "1: prefetch (%1)\n" /* This set is 28 bytes */
20111 + " prefetch 64(%1)\n"
20112 + " prefetch 128(%1)\n"
20113 + " prefetch 192(%1)\n"
20114 + " prefetch 256(%1)\n"
20115 "2: \n"
20116 ".section .fixup, \"ax\"\n"
20117 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20118 + "3: \n"
20119 +
20120 +#ifdef CONFIG_PAX_KERNEXEC
20121 + " movl %%cr0, %0\n"
20122 + " movl %0, %%eax\n"
20123 + " andl $0xFFFEFFFF, %%eax\n"
20124 + " movl %%eax, %%cr0\n"
20125 +#endif
20126 +
20127 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20128 +
20129 +#ifdef CONFIG_PAX_KERNEXEC
20130 + " movl %0, %%cr0\n"
20131 +#endif
20132 +
20133 " jmp 2b\n"
20134 ".previous\n"
20135 _ASM_EXTABLE(1b, 3b)
20136 - : : "r" (from));
20137 + : "=&r" (cr0) : "r" (from) : "ax");
20138
20139 for ( ; i > 5; i--) {
20140 __asm__ __volatile__ (
20141 - "1: prefetch 320(%0)\n"
20142 - "2: movq (%0), %%mm0\n"
20143 - " movq 8(%0), %%mm1\n"
20144 - " movq 16(%0), %%mm2\n"
20145 - " movq 24(%0), %%mm3\n"
20146 - " movq %%mm0, (%1)\n"
20147 - " movq %%mm1, 8(%1)\n"
20148 - " movq %%mm2, 16(%1)\n"
20149 - " movq %%mm3, 24(%1)\n"
20150 - " movq 32(%0), %%mm0\n"
20151 - " movq 40(%0), %%mm1\n"
20152 - " movq 48(%0), %%mm2\n"
20153 - " movq 56(%0), %%mm3\n"
20154 - " movq %%mm0, 32(%1)\n"
20155 - " movq %%mm1, 40(%1)\n"
20156 - " movq %%mm2, 48(%1)\n"
20157 - " movq %%mm3, 56(%1)\n"
20158 + "1: prefetch 320(%1)\n"
20159 + "2: movq (%1), %%mm0\n"
20160 + " movq 8(%1), %%mm1\n"
20161 + " movq 16(%1), %%mm2\n"
20162 + " movq 24(%1), %%mm3\n"
20163 + " movq %%mm0, (%2)\n"
20164 + " movq %%mm1, 8(%2)\n"
20165 + " movq %%mm2, 16(%2)\n"
20166 + " movq %%mm3, 24(%2)\n"
20167 + " movq 32(%1), %%mm0\n"
20168 + " movq 40(%1), %%mm1\n"
20169 + " movq 48(%1), %%mm2\n"
20170 + " movq 56(%1), %%mm3\n"
20171 + " movq %%mm0, 32(%2)\n"
20172 + " movq %%mm1, 40(%2)\n"
20173 + " movq %%mm2, 48(%2)\n"
20174 + " movq %%mm3, 56(%2)\n"
20175 ".section .fixup, \"ax\"\n"
20176 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20177 + "3:\n"
20178 +
20179 +#ifdef CONFIG_PAX_KERNEXEC
20180 + " movl %%cr0, %0\n"
20181 + " movl %0, %%eax\n"
20182 + " andl $0xFFFEFFFF, %%eax\n"
20183 + " movl %%eax, %%cr0\n"
20184 +#endif
20185 +
20186 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20187 +
20188 +#ifdef CONFIG_PAX_KERNEXEC
20189 + " movl %0, %%cr0\n"
20190 +#endif
20191 +
20192 " jmp 2b\n"
20193 ".previous\n"
20194 _ASM_EXTABLE(1b, 3b)
20195 - : : "r" (from), "r" (to) : "memory");
20196 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20197
20198 from += 64;
20199 to += 64;
20200 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
20201 static void fast_copy_page(void *to, void *from)
20202 {
20203 int i;
20204 + unsigned long cr0;
20205
20206 kernel_fpu_begin();
20207
20208 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
20209 * but that is for later. -AV
20210 */
20211 __asm__ __volatile__(
20212 - "1: prefetch (%0)\n"
20213 - " prefetch 64(%0)\n"
20214 - " prefetch 128(%0)\n"
20215 - " prefetch 192(%0)\n"
20216 - " prefetch 256(%0)\n"
20217 + "1: prefetch (%1)\n"
20218 + " prefetch 64(%1)\n"
20219 + " prefetch 128(%1)\n"
20220 + " prefetch 192(%1)\n"
20221 + " prefetch 256(%1)\n"
20222 "2: \n"
20223 ".section .fixup, \"ax\"\n"
20224 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20225 + "3: \n"
20226 +
20227 +#ifdef CONFIG_PAX_KERNEXEC
20228 + " movl %%cr0, %0\n"
20229 + " movl %0, %%eax\n"
20230 + " andl $0xFFFEFFFF, %%eax\n"
20231 + " movl %%eax, %%cr0\n"
20232 +#endif
20233 +
20234 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20235 +
20236 +#ifdef CONFIG_PAX_KERNEXEC
20237 + " movl %0, %%cr0\n"
20238 +#endif
20239 +
20240 " jmp 2b\n"
20241 ".previous\n"
20242 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20243 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20244
20245 for (i = 0; i < (4096-320)/64; i++) {
20246 __asm__ __volatile__ (
20247 - "1: prefetch 320(%0)\n"
20248 - "2: movq (%0), %%mm0\n"
20249 - " movntq %%mm0, (%1)\n"
20250 - " movq 8(%0), %%mm1\n"
20251 - " movntq %%mm1, 8(%1)\n"
20252 - " movq 16(%0), %%mm2\n"
20253 - " movntq %%mm2, 16(%1)\n"
20254 - " movq 24(%0), %%mm3\n"
20255 - " movntq %%mm3, 24(%1)\n"
20256 - " movq 32(%0), %%mm4\n"
20257 - " movntq %%mm4, 32(%1)\n"
20258 - " movq 40(%0), %%mm5\n"
20259 - " movntq %%mm5, 40(%1)\n"
20260 - " movq 48(%0), %%mm6\n"
20261 - " movntq %%mm6, 48(%1)\n"
20262 - " movq 56(%0), %%mm7\n"
20263 - " movntq %%mm7, 56(%1)\n"
20264 + "1: prefetch 320(%1)\n"
20265 + "2: movq (%1), %%mm0\n"
20266 + " movntq %%mm0, (%2)\n"
20267 + " movq 8(%1), %%mm1\n"
20268 + " movntq %%mm1, 8(%2)\n"
20269 + " movq 16(%1), %%mm2\n"
20270 + " movntq %%mm2, 16(%2)\n"
20271 + " movq 24(%1), %%mm3\n"
20272 + " movntq %%mm3, 24(%2)\n"
20273 + " movq 32(%1), %%mm4\n"
20274 + " movntq %%mm4, 32(%2)\n"
20275 + " movq 40(%1), %%mm5\n"
20276 + " movntq %%mm5, 40(%2)\n"
20277 + " movq 48(%1), %%mm6\n"
20278 + " movntq %%mm6, 48(%2)\n"
20279 + " movq 56(%1), %%mm7\n"
20280 + " movntq %%mm7, 56(%2)\n"
20281 ".section .fixup, \"ax\"\n"
20282 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20283 + "3:\n"
20284 +
20285 +#ifdef CONFIG_PAX_KERNEXEC
20286 + " movl %%cr0, %0\n"
20287 + " movl %0, %%eax\n"
20288 + " andl $0xFFFEFFFF, %%eax\n"
20289 + " movl %%eax, %%cr0\n"
20290 +#endif
20291 +
20292 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20293 +
20294 +#ifdef CONFIG_PAX_KERNEXEC
20295 + " movl %0, %%cr0\n"
20296 +#endif
20297 +
20298 " jmp 2b\n"
20299 ".previous\n"
20300 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
20301 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20302
20303 from += 64;
20304 to += 64;
20305 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
20306 static void fast_copy_page(void *to, void *from)
20307 {
20308 int i;
20309 + unsigned long cr0;
20310
20311 kernel_fpu_begin();
20312
20313 __asm__ __volatile__ (
20314 - "1: prefetch (%0)\n"
20315 - " prefetch 64(%0)\n"
20316 - " prefetch 128(%0)\n"
20317 - " prefetch 192(%0)\n"
20318 - " prefetch 256(%0)\n"
20319 + "1: prefetch (%1)\n"
20320 + " prefetch 64(%1)\n"
20321 + " prefetch 128(%1)\n"
20322 + " prefetch 192(%1)\n"
20323 + " prefetch 256(%1)\n"
20324 "2: \n"
20325 ".section .fixup, \"ax\"\n"
20326 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20327 + "3: \n"
20328 +
20329 +#ifdef CONFIG_PAX_KERNEXEC
20330 + " movl %%cr0, %0\n"
20331 + " movl %0, %%eax\n"
20332 + " andl $0xFFFEFFFF, %%eax\n"
20333 + " movl %%eax, %%cr0\n"
20334 +#endif
20335 +
20336 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20337 +
20338 +#ifdef CONFIG_PAX_KERNEXEC
20339 + " movl %0, %%cr0\n"
20340 +#endif
20341 +
20342 " jmp 2b\n"
20343 ".previous\n"
20344 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20345 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20346
20347 for (i = 0; i < 4096/64; i++) {
20348 __asm__ __volatile__ (
20349 - "1: prefetch 320(%0)\n"
20350 - "2: movq (%0), %%mm0\n"
20351 - " movq 8(%0), %%mm1\n"
20352 - " movq 16(%0), %%mm2\n"
20353 - " movq 24(%0), %%mm3\n"
20354 - " movq %%mm0, (%1)\n"
20355 - " movq %%mm1, 8(%1)\n"
20356 - " movq %%mm2, 16(%1)\n"
20357 - " movq %%mm3, 24(%1)\n"
20358 - " movq 32(%0), %%mm0\n"
20359 - " movq 40(%0), %%mm1\n"
20360 - " movq 48(%0), %%mm2\n"
20361 - " movq 56(%0), %%mm3\n"
20362 - " movq %%mm0, 32(%1)\n"
20363 - " movq %%mm1, 40(%1)\n"
20364 - " movq %%mm2, 48(%1)\n"
20365 - " movq %%mm3, 56(%1)\n"
20366 + "1: prefetch 320(%1)\n"
20367 + "2: movq (%1), %%mm0\n"
20368 + " movq 8(%1), %%mm1\n"
20369 + " movq 16(%1), %%mm2\n"
20370 + " movq 24(%1), %%mm3\n"
20371 + " movq %%mm0, (%2)\n"
20372 + " movq %%mm1, 8(%2)\n"
20373 + " movq %%mm2, 16(%2)\n"
20374 + " movq %%mm3, 24(%2)\n"
20375 + " movq 32(%1), %%mm0\n"
20376 + " movq 40(%1), %%mm1\n"
20377 + " movq 48(%1), %%mm2\n"
20378 + " movq 56(%1), %%mm3\n"
20379 + " movq %%mm0, 32(%2)\n"
20380 + " movq %%mm1, 40(%2)\n"
20381 + " movq %%mm2, 48(%2)\n"
20382 + " movq %%mm3, 56(%2)\n"
20383 ".section .fixup, \"ax\"\n"
20384 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20385 + "3:\n"
20386 +
20387 +#ifdef CONFIG_PAX_KERNEXEC
20388 + " movl %%cr0, %0\n"
20389 + " movl %0, %%eax\n"
20390 + " andl $0xFFFEFFFF, %%eax\n"
20391 + " movl %%eax, %%cr0\n"
20392 +#endif
20393 +
20394 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20395 +
20396 +#ifdef CONFIG_PAX_KERNEXEC
20397 + " movl %0, %%cr0\n"
20398 +#endif
20399 +
20400 " jmp 2b\n"
20401 ".previous\n"
20402 _ASM_EXTABLE(1b, 3b)
20403 - : : "r" (from), "r" (to) : "memory");
20404 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20405
20406 from += 64;
20407 to += 64;
20408 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
20409 index 69fa106..adda88b 100644
20410 --- a/arch/x86/lib/msr-reg.S
20411 +++ b/arch/x86/lib/msr-reg.S
20412 @@ -3,6 +3,7 @@
20413 #include <asm/dwarf2.h>
20414 #include <asm/asm.h>
20415 #include <asm/msr.h>
20416 +#include <asm/alternative-asm.h>
20417
20418 #ifdef CONFIG_X86_64
20419 /*
20420 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
20421 CFI_STARTPROC
20422 pushq_cfi %rbx
20423 pushq_cfi %rbp
20424 - movq %rdi, %r10 /* Save pointer */
20425 + movq %rdi, %r9 /* Save pointer */
20426 xorl %r11d, %r11d /* Return value */
20427 movl (%rdi), %eax
20428 movl 4(%rdi), %ecx
20429 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
20430 movl 28(%rdi), %edi
20431 CFI_REMEMBER_STATE
20432 1: \op
20433 -2: movl %eax, (%r10)
20434 +2: movl %eax, (%r9)
20435 movl %r11d, %eax /* Return value */
20436 - movl %ecx, 4(%r10)
20437 - movl %edx, 8(%r10)
20438 - movl %ebx, 12(%r10)
20439 - movl %ebp, 20(%r10)
20440 - movl %esi, 24(%r10)
20441 - movl %edi, 28(%r10)
20442 + movl %ecx, 4(%r9)
20443 + movl %edx, 8(%r9)
20444 + movl %ebx, 12(%r9)
20445 + movl %ebp, 20(%r9)
20446 + movl %esi, 24(%r9)
20447 + movl %edi, 28(%r9)
20448 popq_cfi %rbp
20449 popq_cfi %rbx
20450 + pax_force_retaddr
20451 ret
20452 3:
20453 CFI_RESTORE_STATE
20454 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
20455 index 36b0d15..d381858 100644
20456 --- a/arch/x86/lib/putuser.S
20457 +++ b/arch/x86/lib/putuser.S
20458 @@ -15,7 +15,9 @@
20459 #include <asm/thread_info.h>
20460 #include <asm/errno.h>
20461 #include <asm/asm.h>
20462 -
20463 +#include <asm/segment.h>
20464 +#include <asm/pgtable.h>
20465 +#include <asm/alternative-asm.h>
20466
20467 /*
20468 * __put_user_X
20469 @@ -29,52 +31,119 @@
20470 * as they get called from within inline assembly.
20471 */
20472
20473 -#define ENTER CFI_STARTPROC ; \
20474 - GET_THREAD_INFO(%_ASM_BX)
20475 -#define EXIT ret ; \
20476 +#define ENTER CFI_STARTPROC
20477 +#define EXIT pax_force_retaddr; ret ; \
20478 CFI_ENDPROC
20479
20480 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20481 +#define _DEST %_ASM_CX,%_ASM_BX
20482 +#else
20483 +#define _DEST %_ASM_CX
20484 +#endif
20485 +
20486 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20487 +#define __copyuser_seg gs;
20488 +#else
20489 +#define __copyuser_seg
20490 +#endif
20491 +
20492 .text
20493 ENTRY(__put_user_1)
20494 ENTER
20495 +
20496 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20497 + GET_THREAD_INFO(%_ASM_BX)
20498 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
20499 jae bad_put_user
20500 -1: movb %al,(%_ASM_CX)
20501 +
20502 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20503 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20504 + cmp %_ASM_BX,%_ASM_CX
20505 + jb 1234f
20506 + xor %ebx,%ebx
20507 +1234:
20508 +#endif
20509 +
20510 +#endif
20511 +
20512 +1: __copyuser_seg movb %al,(_DEST)
20513 xor %eax,%eax
20514 EXIT
20515 ENDPROC(__put_user_1)
20516
20517 ENTRY(__put_user_2)
20518 ENTER
20519 +
20520 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20521 + GET_THREAD_INFO(%_ASM_BX)
20522 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20523 sub $1,%_ASM_BX
20524 cmp %_ASM_BX,%_ASM_CX
20525 jae bad_put_user
20526 -2: movw %ax,(%_ASM_CX)
20527 +
20528 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20529 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20530 + cmp %_ASM_BX,%_ASM_CX
20531 + jb 1234f
20532 + xor %ebx,%ebx
20533 +1234:
20534 +#endif
20535 +
20536 +#endif
20537 +
20538 +2: __copyuser_seg movw %ax,(_DEST)
20539 xor %eax,%eax
20540 EXIT
20541 ENDPROC(__put_user_2)
20542
20543 ENTRY(__put_user_4)
20544 ENTER
20545 +
20546 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20547 + GET_THREAD_INFO(%_ASM_BX)
20548 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20549 sub $3,%_ASM_BX
20550 cmp %_ASM_BX,%_ASM_CX
20551 jae bad_put_user
20552 -3: movl %eax,(%_ASM_CX)
20553 +
20554 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20555 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20556 + cmp %_ASM_BX,%_ASM_CX
20557 + jb 1234f
20558 + xor %ebx,%ebx
20559 +1234:
20560 +#endif
20561 +
20562 +#endif
20563 +
20564 +3: __copyuser_seg movl %eax,(_DEST)
20565 xor %eax,%eax
20566 EXIT
20567 ENDPROC(__put_user_4)
20568
20569 ENTRY(__put_user_8)
20570 ENTER
20571 +
20572 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20573 + GET_THREAD_INFO(%_ASM_BX)
20574 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20575 sub $7,%_ASM_BX
20576 cmp %_ASM_BX,%_ASM_CX
20577 jae bad_put_user
20578 -4: mov %_ASM_AX,(%_ASM_CX)
20579 +
20580 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20581 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20582 + cmp %_ASM_BX,%_ASM_CX
20583 + jb 1234f
20584 + xor %ebx,%ebx
20585 +1234:
20586 +#endif
20587 +
20588 +#endif
20589 +
20590 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
20591 #ifdef CONFIG_X86_32
20592 -5: movl %edx,4(%_ASM_CX)
20593 +5: __copyuser_seg movl %edx,4(_DEST)
20594 #endif
20595 xor %eax,%eax
20596 EXIT
20597 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
20598 index 1cad221..de671ee 100644
20599 --- a/arch/x86/lib/rwlock.S
20600 +++ b/arch/x86/lib/rwlock.S
20601 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
20602 FRAME
20603 0: LOCK_PREFIX
20604 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
20605 +
20606 +#ifdef CONFIG_PAX_REFCOUNT
20607 + jno 1234f
20608 + LOCK_PREFIX
20609 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
20610 + int $4
20611 +1234:
20612 + _ASM_EXTABLE(1234b, 1234b)
20613 +#endif
20614 +
20615 1: rep; nop
20616 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
20617 jne 1b
20618 LOCK_PREFIX
20619 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
20620 +
20621 +#ifdef CONFIG_PAX_REFCOUNT
20622 + jno 1234f
20623 + LOCK_PREFIX
20624 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
20625 + int $4
20626 +1234:
20627 + _ASM_EXTABLE(1234b, 1234b)
20628 +#endif
20629 +
20630 jnz 0b
20631 ENDFRAME
20632 + pax_force_retaddr
20633 ret
20634 CFI_ENDPROC
20635 END(__write_lock_failed)
20636 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
20637 FRAME
20638 0: LOCK_PREFIX
20639 READ_LOCK_SIZE(inc) (%__lock_ptr)
20640 +
20641 +#ifdef CONFIG_PAX_REFCOUNT
20642 + jno 1234f
20643 + LOCK_PREFIX
20644 + READ_LOCK_SIZE(dec) (%__lock_ptr)
20645 + int $4
20646 +1234:
20647 + _ASM_EXTABLE(1234b, 1234b)
20648 +#endif
20649 +
20650 1: rep; nop
20651 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
20652 js 1b
20653 LOCK_PREFIX
20654 READ_LOCK_SIZE(dec) (%__lock_ptr)
20655 +
20656 +#ifdef CONFIG_PAX_REFCOUNT
20657 + jno 1234f
20658 + LOCK_PREFIX
20659 + READ_LOCK_SIZE(inc) (%__lock_ptr)
20660 + int $4
20661 +1234:
20662 + _ASM_EXTABLE(1234b, 1234b)
20663 +#endif
20664 +
20665 js 0b
20666 ENDFRAME
20667 + pax_force_retaddr
20668 ret
20669 CFI_ENDPROC
20670 END(__read_lock_failed)
20671 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
20672 index 5dff5f0..cadebf4 100644
20673 --- a/arch/x86/lib/rwsem.S
20674 +++ b/arch/x86/lib/rwsem.S
20675 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
20676 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
20677 CFI_RESTORE __ASM_REG(dx)
20678 restore_common_regs
20679 + pax_force_retaddr
20680 ret
20681 CFI_ENDPROC
20682 ENDPROC(call_rwsem_down_read_failed)
20683 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
20684 movq %rax,%rdi
20685 call rwsem_down_write_failed
20686 restore_common_regs
20687 + pax_force_retaddr
20688 ret
20689 CFI_ENDPROC
20690 ENDPROC(call_rwsem_down_write_failed)
20691 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
20692 movq %rax,%rdi
20693 call rwsem_wake
20694 restore_common_regs
20695 -1: ret
20696 +1: pax_force_retaddr
20697 + ret
20698 CFI_ENDPROC
20699 ENDPROC(call_rwsem_wake)
20700
20701 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
20702 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
20703 CFI_RESTORE __ASM_REG(dx)
20704 restore_common_regs
20705 + pax_force_retaddr
20706 ret
20707 CFI_ENDPROC
20708 ENDPROC(call_rwsem_downgrade_wake)
20709 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
20710 index a63efd6..ccecad8 100644
20711 --- a/arch/x86/lib/thunk_64.S
20712 +++ b/arch/x86/lib/thunk_64.S
20713 @@ -8,6 +8,7 @@
20714 #include <linux/linkage.h>
20715 #include <asm/dwarf2.h>
20716 #include <asm/calling.h>
20717 +#include <asm/alternative-asm.h>
20718
20719 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
20720 .macro THUNK name, func, put_ret_addr_in_rdi=0
20721 @@ -41,5 +42,6 @@
20722 SAVE_ARGS
20723 restore:
20724 RESTORE_ARGS
20725 + pax_force_retaddr
20726 ret
20727 CFI_ENDPROC
20728 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
20729 index e218d5d..35679b4 100644
20730 --- a/arch/x86/lib/usercopy_32.c
20731 +++ b/arch/x86/lib/usercopy_32.c
20732 @@ -43,7 +43,7 @@ do { \
20733 __asm__ __volatile__( \
20734 " testl %1,%1\n" \
20735 " jz 2f\n" \
20736 - "0: lodsb\n" \
20737 + "0: "__copyuser_seg"lodsb\n" \
20738 " stosb\n" \
20739 " testb %%al,%%al\n" \
20740 " jz 1f\n" \
20741 @@ -128,10 +128,12 @@ do { \
20742 int __d0; \
20743 might_fault(); \
20744 __asm__ __volatile__( \
20745 + __COPYUSER_SET_ES \
20746 "0: rep; stosl\n" \
20747 " movl %2,%0\n" \
20748 "1: rep; stosb\n" \
20749 "2:\n" \
20750 + __COPYUSER_RESTORE_ES \
20751 ".section .fixup,\"ax\"\n" \
20752 "3: lea 0(%2,%0,4),%0\n" \
20753 " jmp 2b\n" \
20754 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
20755 might_fault();
20756
20757 __asm__ __volatile__(
20758 + __COPYUSER_SET_ES
20759 " testl %0, %0\n"
20760 " jz 3f\n"
20761 " andl %0,%%ecx\n"
20762 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
20763 " subl %%ecx,%0\n"
20764 " addl %0,%%eax\n"
20765 "1:\n"
20766 + __COPYUSER_RESTORE_ES
20767 ".section .fixup,\"ax\"\n"
20768 "2: xorl %%eax,%%eax\n"
20769 " jmp 1b\n"
20770 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
20771
20772 #ifdef CONFIG_X86_INTEL_USERCOPY
20773 static unsigned long
20774 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
20775 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
20776 {
20777 int d0, d1;
20778 __asm__ __volatile__(
20779 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
20780 " .align 2,0x90\n"
20781 "3: movl 0(%4), %%eax\n"
20782 "4: movl 4(%4), %%edx\n"
20783 - "5: movl %%eax, 0(%3)\n"
20784 - "6: movl %%edx, 4(%3)\n"
20785 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
20786 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
20787 "7: movl 8(%4), %%eax\n"
20788 "8: movl 12(%4),%%edx\n"
20789 - "9: movl %%eax, 8(%3)\n"
20790 - "10: movl %%edx, 12(%3)\n"
20791 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
20792 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
20793 "11: movl 16(%4), %%eax\n"
20794 "12: movl 20(%4), %%edx\n"
20795 - "13: movl %%eax, 16(%3)\n"
20796 - "14: movl %%edx, 20(%3)\n"
20797 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
20798 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
20799 "15: movl 24(%4), %%eax\n"
20800 "16: movl 28(%4), %%edx\n"
20801 - "17: movl %%eax, 24(%3)\n"
20802 - "18: movl %%edx, 28(%3)\n"
20803 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
20804 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
20805 "19: movl 32(%4), %%eax\n"
20806 "20: movl 36(%4), %%edx\n"
20807 - "21: movl %%eax, 32(%3)\n"
20808 - "22: movl %%edx, 36(%3)\n"
20809 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
20810 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
20811 "23: movl 40(%4), %%eax\n"
20812 "24: movl 44(%4), %%edx\n"
20813 - "25: movl %%eax, 40(%3)\n"
20814 - "26: movl %%edx, 44(%3)\n"
20815 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
20816 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
20817 "27: movl 48(%4), %%eax\n"
20818 "28: movl 52(%4), %%edx\n"
20819 - "29: movl %%eax, 48(%3)\n"
20820 - "30: movl %%edx, 52(%3)\n"
20821 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
20822 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
20823 "31: movl 56(%4), %%eax\n"
20824 "32: movl 60(%4), %%edx\n"
20825 - "33: movl %%eax, 56(%3)\n"
20826 - "34: movl %%edx, 60(%3)\n"
20827 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
20828 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
20829 " addl $-64, %0\n"
20830 " addl $64, %4\n"
20831 " addl $64, %3\n"
20832 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
20833 " shrl $2, %0\n"
20834 " andl $3, %%eax\n"
20835 " cld\n"
20836 + __COPYUSER_SET_ES
20837 "99: rep; movsl\n"
20838 "36: movl %%eax, %0\n"
20839 "37: rep; movsb\n"
20840 "100:\n"
20841 + __COPYUSER_RESTORE_ES
20842 + ".section .fixup,\"ax\"\n"
20843 + "101: lea 0(%%eax,%0,4),%0\n"
20844 + " jmp 100b\n"
20845 + ".previous\n"
20846 + ".section __ex_table,\"a\"\n"
20847 + " .align 4\n"
20848 + " .long 1b,100b\n"
20849 + " .long 2b,100b\n"
20850 + " .long 3b,100b\n"
20851 + " .long 4b,100b\n"
20852 + " .long 5b,100b\n"
20853 + " .long 6b,100b\n"
20854 + " .long 7b,100b\n"
20855 + " .long 8b,100b\n"
20856 + " .long 9b,100b\n"
20857 + " .long 10b,100b\n"
20858 + " .long 11b,100b\n"
20859 + " .long 12b,100b\n"
20860 + " .long 13b,100b\n"
20861 + " .long 14b,100b\n"
20862 + " .long 15b,100b\n"
20863 + " .long 16b,100b\n"
20864 + " .long 17b,100b\n"
20865 + " .long 18b,100b\n"
20866 + " .long 19b,100b\n"
20867 + " .long 20b,100b\n"
20868 + " .long 21b,100b\n"
20869 + " .long 22b,100b\n"
20870 + " .long 23b,100b\n"
20871 + " .long 24b,100b\n"
20872 + " .long 25b,100b\n"
20873 + " .long 26b,100b\n"
20874 + " .long 27b,100b\n"
20875 + " .long 28b,100b\n"
20876 + " .long 29b,100b\n"
20877 + " .long 30b,100b\n"
20878 + " .long 31b,100b\n"
20879 + " .long 32b,100b\n"
20880 + " .long 33b,100b\n"
20881 + " .long 34b,100b\n"
20882 + " .long 35b,100b\n"
20883 + " .long 36b,100b\n"
20884 + " .long 37b,100b\n"
20885 + " .long 99b,101b\n"
20886 + ".previous"
20887 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
20888 + : "1"(to), "2"(from), "0"(size)
20889 + : "eax", "edx", "memory");
20890 + return size;
20891 +}
20892 +
20893 +static unsigned long
20894 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
20895 +{
20896 + int d0, d1;
20897 + __asm__ __volatile__(
20898 + " .align 2,0x90\n"
20899 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
20900 + " cmpl $67, %0\n"
20901 + " jbe 3f\n"
20902 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
20903 + " .align 2,0x90\n"
20904 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
20905 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
20906 + "5: movl %%eax, 0(%3)\n"
20907 + "6: movl %%edx, 4(%3)\n"
20908 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
20909 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
20910 + "9: movl %%eax, 8(%3)\n"
20911 + "10: movl %%edx, 12(%3)\n"
20912 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
20913 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
20914 + "13: movl %%eax, 16(%3)\n"
20915 + "14: movl %%edx, 20(%3)\n"
20916 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
20917 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
20918 + "17: movl %%eax, 24(%3)\n"
20919 + "18: movl %%edx, 28(%3)\n"
20920 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
20921 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
20922 + "21: movl %%eax, 32(%3)\n"
20923 + "22: movl %%edx, 36(%3)\n"
20924 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
20925 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
20926 + "25: movl %%eax, 40(%3)\n"
20927 + "26: movl %%edx, 44(%3)\n"
20928 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
20929 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
20930 + "29: movl %%eax, 48(%3)\n"
20931 + "30: movl %%edx, 52(%3)\n"
20932 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
20933 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
20934 + "33: movl %%eax, 56(%3)\n"
20935 + "34: movl %%edx, 60(%3)\n"
20936 + " addl $-64, %0\n"
20937 + " addl $64, %4\n"
20938 + " addl $64, %3\n"
20939 + " cmpl $63, %0\n"
20940 + " ja 1b\n"
20941 + "35: movl %0, %%eax\n"
20942 + " shrl $2, %0\n"
20943 + " andl $3, %%eax\n"
20944 + " cld\n"
20945 + "99: rep; "__copyuser_seg" movsl\n"
20946 + "36: movl %%eax, %0\n"
20947 + "37: rep; "__copyuser_seg" movsb\n"
20948 + "100:\n"
20949 ".section .fixup,\"ax\"\n"
20950 "101: lea 0(%%eax,%0,4),%0\n"
20951 " jmp 100b\n"
20952 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
20953 int d0, d1;
20954 __asm__ __volatile__(
20955 " .align 2,0x90\n"
20956 - "0: movl 32(%4), %%eax\n"
20957 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20958 " cmpl $67, %0\n"
20959 " jbe 2f\n"
20960 - "1: movl 64(%4), %%eax\n"
20961 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20962 " .align 2,0x90\n"
20963 - "2: movl 0(%4), %%eax\n"
20964 - "21: movl 4(%4), %%edx\n"
20965 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20966 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20967 " movl %%eax, 0(%3)\n"
20968 " movl %%edx, 4(%3)\n"
20969 - "3: movl 8(%4), %%eax\n"
20970 - "31: movl 12(%4),%%edx\n"
20971 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20972 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20973 " movl %%eax, 8(%3)\n"
20974 " movl %%edx, 12(%3)\n"
20975 - "4: movl 16(%4), %%eax\n"
20976 - "41: movl 20(%4), %%edx\n"
20977 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20978 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20979 " movl %%eax, 16(%3)\n"
20980 " movl %%edx, 20(%3)\n"
20981 - "10: movl 24(%4), %%eax\n"
20982 - "51: movl 28(%4), %%edx\n"
20983 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20984 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20985 " movl %%eax, 24(%3)\n"
20986 " movl %%edx, 28(%3)\n"
20987 - "11: movl 32(%4), %%eax\n"
20988 - "61: movl 36(%4), %%edx\n"
20989 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20990 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20991 " movl %%eax, 32(%3)\n"
20992 " movl %%edx, 36(%3)\n"
20993 - "12: movl 40(%4), %%eax\n"
20994 - "71: movl 44(%4), %%edx\n"
20995 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20996 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20997 " movl %%eax, 40(%3)\n"
20998 " movl %%edx, 44(%3)\n"
20999 - "13: movl 48(%4), %%eax\n"
21000 - "81: movl 52(%4), %%edx\n"
21001 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21002 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21003 " movl %%eax, 48(%3)\n"
21004 " movl %%edx, 52(%3)\n"
21005 - "14: movl 56(%4), %%eax\n"
21006 - "91: movl 60(%4), %%edx\n"
21007 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21008 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21009 " movl %%eax, 56(%3)\n"
21010 " movl %%edx, 60(%3)\n"
21011 " addl $-64, %0\n"
21012 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
21013 " shrl $2, %0\n"
21014 " andl $3, %%eax\n"
21015 " cld\n"
21016 - "6: rep; movsl\n"
21017 + "6: rep; "__copyuser_seg" movsl\n"
21018 " movl %%eax,%0\n"
21019 - "7: rep; movsb\n"
21020 + "7: rep; "__copyuser_seg" movsb\n"
21021 "8:\n"
21022 ".section .fixup,\"ax\"\n"
21023 "9: lea 0(%%eax,%0,4),%0\n"
21024 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
21025
21026 __asm__ __volatile__(
21027 " .align 2,0x90\n"
21028 - "0: movl 32(%4), %%eax\n"
21029 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21030 " cmpl $67, %0\n"
21031 " jbe 2f\n"
21032 - "1: movl 64(%4), %%eax\n"
21033 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21034 " .align 2,0x90\n"
21035 - "2: movl 0(%4), %%eax\n"
21036 - "21: movl 4(%4), %%edx\n"
21037 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21038 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21039 " movnti %%eax, 0(%3)\n"
21040 " movnti %%edx, 4(%3)\n"
21041 - "3: movl 8(%4), %%eax\n"
21042 - "31: movl 12(%4),%%edx\n"
21043 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21044 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21045 " movnti %%eax, 8(%3)\n"
21046 " movnti %%edx, 12(%3)\n"
21047 - "4: movl 16(%4), %%eax\n"
21048 - "41: movl 20(%4), %%edx\n"
21049 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21050 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21051 " movnti %%eax, 16(%3)\n"
21052 " movnti %%edx, 20(%3)\n"
21053 - "10: movl 24(%4), %%eax\n"
21054 - "51: movl 28(%4), %%edx\n"
21055 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21056 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21057 " movnti %%eax, 24(%3)\n"
21058 " movnti %%edx, 28(%3)\n"
21059 - "11: movl 32(%4), %%eax\n"
21060 - "61: movl 36(%4), %%edx\n"
21061 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21062 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21063 " movnti %%eax, 32(%3)\n"
21064 " movnti %%edx, 36(%3)\n"
21065 - "12: movl 40(%4), %%eax\n"
21066 - "71: movl 44(%4), %%edx\n"
21067 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21068 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21069 " movnti %%eax, 40(%3)\n"
21070 " movnti %%edx, 44(%3)\n"
21071 - "13: movl 48(%4), %%eax\n"
21072 - "81: movl 52(%4), %%edx\n"
21073 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21074 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21075 " movnti %%eax, 48(%3)\n"
21076 " movnti %%edx, 52(%3)\n"
21077 - "14: movl 56(%4), %%eax\n"
21078 - "91: movl 60(%4), %%edx\n"
21079 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21080 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21081 " movnti %%eax, 56(%3)\n"
21082 " movnti %%edx, 60(%3)\n"
21083 " addl $-64, %0\n"
21084 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
21085 " shrl $2, %0\n"
21086 " andl $3, %%eax\n"
21087 " cld\n"
21088 - "6: rep; movsl\n"
21089 + "6: rep; "__copyuser_seg" movsl\n"
21090 " movl %%eax,%0\n"
21091 - "7: rep; movsb\n"
21092 + "7: rep; "__copyuser_seg" movsb\n"
21093 "8:\n"
21094 ".section .fixup,\"ax\"\n"
21095 "9: lea 0(%%eax,%0,4),%0\n"
21096 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
21097
21098 __asm__ __volatile__(
21099 " .align 2,0x90\n"
21100 - "0: movl 32(%4), %%eax\n"
21101 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21102 " cmpl $67, %0\n"
21103 " jbe 2f\n"
21104 - "1: movl 64(%4), %%eax\n"
21105 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21106 " .align 2,0x90\n"
21107 - "2: movl 0(%4), %%eax\n"
21108 - "21: movl 4(%4), %%edx\n"
21109 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21110 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21111 " movnti %%eax, 0(%3)\n"
21112 " movnti %%edx, 4(%3)\n"
21113 - "3: movl 8(%4), %%eax\n"
21114 - "31: movl 12(%4),%%edx\n"
21115 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21116 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21117 " movnti %%eax, 8(%3)\n"
21118 " movnti %%edx, 12(%3)\n"
21119 - "4: movl 16(%4), %%eax\n"
21120 - "41: movl 20(%4), %%edx\n"
21121 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21122 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21123 " movnti %%eax, 16(%3)\n"
21124 " movnti %%edx, 20(%3)\n"
21125 - "10: movl 24(%4), %%eax\n"
21126 - "51: movl 28(%4), %%edx\n"
21127 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21128 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21129 " movnti %%eax, 24(%3)\n"
21130 " movnti %%edx, 28(%3)\n"
21131 - "11: movl 32(%4), %%eax\n"
21132 - "61: movl 36(%4), %%edx\n"
21133 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21134 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21135 " movnti %%eax, 32(%3)\n"
21136 " movnti %%edx, 36(%3)\n"
21137 - "12: movl 40(%4), %%eax\n"
21138 - "71: movl 44(%4), %%edx\n"
21139 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21140 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21141 " movnti %%eax, 40(%3)\n"
21142 " movnti %%edx, 44(%3)\n"
21143 - "13: movl 48(%4), %%eax\n"
21144 - "81: movl 52(%4), %%edx\n"
21145 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21146 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21147 " movnti %%eax, 48(%3)\n"
21148 " movnti %%edx, 52(%3)\n"
21149 - "14: movl 56(%4), %%eax\n"
21150 - "91: movl 60(%4), %%edx\n"
21151 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21152 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21153 " movnti %%eax, 56(%3)\n"
21154 " movnti %%edx, 60(%3)\n"
21155 " addl $-64, %0\n"
21156 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
21157 " shrl $2, %0\n"
21158 " andl $3, %%eax\n"
21159 " cld\n"
21160 - "6: rep; movsl\n"
21161 + "6: rep; "__copyuser_seg" movsl\n"
21162 " movl %%eax,%0\n"
21163 - "7: rep; movsb\n"
21164 + "7: rep; "__copyuser_seg" movsb\n"
21165 "8:\n"
21166 ".section .fixup,\"ax\"\n"
21167 "9: lea 0(%%eax,%0,4),%0\n"
21168 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
21169 */
21170 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
21171 unsigned long size);
21172 -unsigned long __copy_user_intel(void __user *to, const void *from,
21173 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
21174 + unsigned long size);
21175 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
21176 unsigned long size);
21177 unsigned long __copy_user_zeroing_intel_nocache(void *to,
21178 const void __user *from, unsigned long size);
21179 #endif /* CONFIG_X86_INTEL_USERCOPY */
21180
21181 /* Generic arbitrary sized copy. */
21182 -#define __copy_user(to, from, size) \
21183 +#define __copy_user(to, from, size, prefix, set, restore) \
21184 do { \
21185 int __d0, __d1, __d2; \
21186 __asm__ __volatile__( \
21187 + set \
21188 " cmp $7,%0\n" \
21189 " jbe 1f\n" \
21190 " movl %1,%0\n" \
21191 " negl %0\n" \
21192 " andl $7,%0\n" \
21193 " subl %0,%3\n" \
21194 - "4: rep; movsb\n" \
21195 + "4: rep; "prefix"movsb\n" \
21196 " movl %3,%0\n" \
21197 " shrl $2,%0\n" \
21198 " andl $3,%3\n" \
21199 " .align 2,0x90\n" \
21200 - "0: rep; movsl\n" \
21201 + "0: rep; "prefix"movsl\n" \
21202 " movl %3,%0\n" \
21203 - "1: rep; movsb\n" \
21204 + "1: rep; "prefix"movsb\n" \
21205 "2:\n" \
21206 + restore \
21207 ".section .fixup,\"ax\"\n" \
21208 "5: addl %3,%0\n" \
21209 " jmp 2b\n" \
21210 @@ -682,14 +799,14 @@ do { \
21211 " negl %0\n" \
21212 " andl $7,%0\n" \
21213 " subl %0,%3\n" \
21214 - "4: rep; movsb\n" \
21215 + "4: rep; "__copyuser_seg"movsb\n" \
21216 " movl %3,%0\n" \
21217 " shrl $2,%0\n" \
21218 " andl $3,%3\n" \
21219 " .align 2,0x90\n" \
21220 - "0: rep; movsl\n" \
21221 + "0: rep; "__copyuser_seg"movsl\n" \
21222 " movl %3,%0\n" \
21223 - "1: rep; movsb\n" \
21224 + "1: rep; "__copyuser_seg"movsb\n" \
21225 "2:\n" \
21226 ".section .fixup,\"ax\"\n" \
21227 "5: addl %3,%0\n" \
21228 @@ -775,9 +892,9 @@ survive:
21229 }
21230 #endif
21231 if (movsl_is_ok(to, from, n))
21232 - __copy_user(to, from, n);
21233 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
21234 else
21235 - n = __copy_user_intel(to, from, n);
21236 + n = __generic_copy_to_user_intel(to, from, n);
21237 return n;
21238 }
21239 EXPORT_SYMBOL(__copy_to_user_ll);
21240 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
21241 unsigned long n)
21242 {
21243 if (movsl_is_ok(to, from, n))
21244 - __copy_user(to, from, n);
21245 + __copy_user(to, from, n, __copyuser_seg, "", "");
21246 else
21247 - n = __copy_user_intel((void __user *)to,
21248 - (const void *)from, n);
21249 + n = __generic_copy_from_user_intel(to, from, n);
21250 return n;
21251 }
21252 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
21253 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
21254 if (n > 64 && cpu_has_xmm2)
21255 n = __copy_user_intel_nocache(to, from, n);
21256 else
21257 - __copy_user(to, from, n);
21258 + __copy_user(to, from, n, __copyuser_seg, "", "");
21259 #else
21260 - __copy_user(to, from, n);
21261 + __copy_user(to, from, n, __copyuser_seg, "", "");
21262 #endif
21263 return n;
21264 }
21265 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
21266
21267 -/**
21268 - * copy_to_user: - Copy a block of data into user space.
21269 - * @to: Destination address, in user space.
21270 - * @from: Source address, in kernel space.
21271 - * @n: Number of bytes to copy.
21272 - *
21273 - * Context: User context only. This function may sleep.
21274 - *
21275 - * Copy data from kernel space to user space.
21276 - *
21277 - * Returns number of bytes that could not be copied.
21278 - * On success, this will be zero.
21279 - */
21280 -unsigned long
21281 -copy_to_user(void __user *to, const void *from, unsigned long n)
21282 -{
21283 - if (access_ok(VERIFY_WRITE, to, n))
21284 - n = __copy_to_user(to, from, n);
21285 - return n;
21286 -}
21287 -EXPORT_SYMBOL(copy_to_user);
21288 -
21289 -/**
21290 - * copy_from_user: - Copy a block of data from user space.
21291 - * @to: Destination address, in kernel space.
21292 - * @from: Source address, in user space.
21293 - * @n: Number of bytes to copy.
21294 - *
21295 - * Context: User context only. This function may sleep.
21296 - *
21297 - * Copy data from user space to kernel space.
21298 - *
21299 - * Returns number of bytes that could not be copied.
21300 - * On success, this will be zero.
21301 - *
21302 - * If some data could not be copied, this function will pad the copied
21303 - * data to the requested size using zero bytes.
21304 - */
21305 -unsigned long
21306 -_copy_from_user(void *to, const void __user *from, unsigned long n)
21307 -{
21308 - if (access_ok(VERIFY_READ, from, n))
21309 - n = __copy_from_user(to, from, n);
21310 - else
21311 - memset(to, 0, n);
21312 - return n;
21313 -}
21314 -EXPORT_SYMBOL(_copy_from_user);
21315 -
21316 void copy_from_user_overflow(void)
21317 {
21318 WARN(1, "Buffer overflow detected!\n");
21319 }
21320 EXPORT_SYMBOL(copy_from_user_overflow);
21321 +
21322 +void copy_to_user_overflow(void)
21323 +{
21324 + WARN(1, "Buffer overflow detected!\n");
21325 +}
21326 +EXPORT_SYMBOL(copy_to_user_overflow);
21327 +
21328 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21329 +void __set_fs(mm_segment_t x)
21330 +{
21331 + switch (x.seg) {
21332 + case 0:
21333 + loadsegment(gs, 0);
21334 + break;
21335 + case TASK_SIZE_MAX:
21336 + loadsegment(gs, __USER_DS);
21337 + break;
21338 + case -1UL:
21339 + loadsegment(gs, __KERNEL_DS);
21340 + break;
21341 + default:
21342 + BUG();
21343 + }
21344 + return;
21345 +}
21346 +EXPORT_SYMBOL(__set_fs);
21347 +
21348 +void set_fs(mm_segment_t x)
21349 +{
21350 + current_thread_info()->addr_limit = x;
21351 + __set_fs(x);
21352 +}
21353 +EXPORT_SYMBOL(set_fs);
21354 +#endif
21355 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
21356 index b7c2849..8633ad8 100644
21357 --- a/arch/x86/lib/usercopy_64.c
21358 +++ b/arch/x86/lib/usercopy_64.c
21359 @@ -42,6 +42,12 @@ long
21360 __strncpy_from_user(char *dst, const char __user *src, long count)
21361 {
21362 long res;
21363 +
21364 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21365 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21366 + src += PAX_USER_SHADOW_BASE;
21367 +#endif
21368 +
21369 __do_strncpy_from_user(dst, src, count, res);
21370 return res;
21371 }
21372 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
21373 {
21374 long __d0;
21375 might_fault();
21376 +
21377 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21378 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
21379 + addr += PAX_USER_SHADOW_BASE;
21380 +#endif
21381 +
21382 /* no memory constraint because it doesn't change any memory gcc knows
21383 about */
21384 asm volatile(
21385 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
21386 }
21387 EXPORT_SYMBOL(strlen_user);
21388
21389 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
21390 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
21391 {
21392 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21393 - return copy_user_generic((__force void *)to, (__force void *)from, len);
21394 - }
21395 - return len;
21396 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21397 +
21398 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21399 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
21400 + to += PAX_USER_SHADOW_BASE;
21401 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
21402 + from += PAX_USER_SHADOW_BASE;
21403 +#endif
21404 +
21405 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
21406 + }
21407 + return len;
21408 }
21409 EXPORT_SYMBOL(copy_in_user);
21410
21411 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
21412 * it is not necessary to optimize tail handling.
21413 */
21414 unsigned long
21415 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
21416 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
21417 {
21418 char c;
21419 unsigned zero_len;
21420 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
21421 index d0474ad..36e9257 100644
21422 --- a/arch/x86/mm/extable.c
21423 +++ b/arch/x86/mm/extable.c
21424 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
21425 const struct exception_table_entry *fixup;
21426
21427 #ifdef CONFIG_PNPBIOS
21428 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
21429 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
21430 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
21431 extern u32 pnp_bios_is_utter_crap;
21432 pnp_bios_is_utter_crap = 1;
21433 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
21434 index 5db0490..2ddce45 100644
21435 --- a/arch/x86/mm/fault.c
21436 +++ b/arch/x86/mm/fault.c
21437 @@ -13,11 +13,18 @@
21438 #include <linux/perf_event.h> /* perf_sw_event */
21439 #include <linux/hugetlb.h> /* hstate_index_to_shift */
21440 #include <linux/prefetch.h> /* prefetchw */
21441 +#include <linux/unistd.h>
21442 +#include <linux/compiler.h>
21443
21444 #include <asm/traps.h> /* dotraplinkage, ... */
21445 #include <asm/pgalloc.h> /* pgd_*(), ... */
21446 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
21447 #include <asm/fixmap.h> /* VSYSCALL_START */
21448 +#include <asm/tlbflush.h>
21449 +
21450 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21451 +#include <asm/stacktrace.h>
21452 +#endif
21453
21454 /*
21455 * Page fault error code bits:
21456 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
21457 int ret = 0;
21458
21459 /* kprobe_running() needs smp_processor_id() */
21460 - if (kprobes_built_in() && !user_mode_vm(regs)) {
21461 + if (kprobes_built_in() && !user_mode(regs)) {
21462 preempt_disable();
21463 if (kprobe_running() && kprobe_fault_handler(regs, 14))
21464 ret = 1;
21465 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
21466 return !instr_lo || (instr_lo>>1) == 1;
21467 case 0x00:
21468 /* Prefetch instruction is 0x0F0D or 0x0F18 */
21469 - if (probe_kernel_address(instr, opcode))
21470 + if (user_mode(regs)) {
21471 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
21472 + return 0;
21473 + } else if (probe_kernel_address(instr, opcode))
21474 return 0;
21475
21476 *prefetch = (instr_lo == 0xF) &&
21477 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
21478 while (instr < max_instr) {
21479 unsigned char opcode;
21480
21481 - if (probe_kernel_address(instr, opcode))
21482 + if (user_mode(regs)) {
21483 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
21484 + break;
21485 + } else if (probe_kernel_address(instr, opcode))
21486 break;
21487
21488 instr++;
21489 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
21490 force_sig_info(si_signo, &info, tsk);
21491 }
21492
21493 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21494 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
21495 +#endif
21496 +
21497 +#ifdef CONFIG_PAX_EMUTRAMP
21498 +static int pax_handle_fetch_fault(struct pt_regs *regs);
21499 +#endif
21500 +
21501 +#ifdef CONFIG_PAX_PAGEEXEC
21502 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
21503 +{
21504 + pgd_t *pgd;
21505 + pud_t *pud;
21506 + pmd_t *pmd;
21507 +
21508 + pgd = pgd_offset(mm, address);
21509 + if (!pgd_present(*pgd))
21510 + return NULL;
21511 + pud = pud_offset(pgd, address);
21512 + if (!pud_present(*pud))
21513 + return NULL;
21514 + pmd = pmd_offset(pud, address);
21515 + if (!pmd_present(*pmd))
21516 + return NULL;
21517 + return pmd;
21518 +}
21519 +#endif
21520 +
21521 DEFINE_SPINLOCK(pgd_lock);
21522 LIST_HEAD(pgd_list);
21523
21524 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
21525 for (address = VMALLOC_START & PMD_MASK;
21526 address >= TASK_SIZE && address < FIXADDR_TOP;
21527 address += PMD_SIZE) {
21528 +
21529 +#ifdef CONFIG_PAX_PER_CPU_PGD
21530 + unsigned long cpu;
21531 +#else
21532 struct page *page;
21533 +#endif
21534
21535 spin_lock(&pgd_lock);
21536 +
21537 +#ifdef CONFIG_PAX_PER_CPU_PGD
21538 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
21539 + pgd_t *pgd = get_cpu_pgd(cpu);
21540 + pmd_t *ret;
21541 +#else
21542 list_for_each_entry(page, &pgd_list, lru) {
21543 + pgd_t *pgd = page_address(page);
21544 spinlock_t *pgt_lock;
21545 pmd_t *ret;
21546
21547 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
21548 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
21549
21550 spin_lock(pgt_lock);
21551 - ret = vmalloc_sync_one(page_address(page), address);
21552 +#endif
21553 +
21554 + ret = vmalloc_sync_one(pgd, address);
21555 +
21556 +#ifndef CONFIG_PAX_PER_CPU_PGD
21557 spin_unlock(pgt_lock);
21558 +#endif
21559
21560 if (!ret)
21561 break;
21562 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
21563 * an interrupt in the middle of a task switch..
21564 */
21565 pgd_paddr = read_cr3();
21566 +
21567 +#ifdef CONFIG_PAX_PER_CPU_PGD
21568 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
21569 +#endif
21570 +
21571 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
21572 if (!pmd_k)
21573 return -1;
21574 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
21575 * happen within a race in page table update. In the later
21576 * case just flush:
21577 */
21578 +
21579 +#ifdef CONFIG_PAX_PER_CPU_PGD
21580 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
21581 + pgd = pgd_offset_cpu(smp_processor_id(), address);
21582 +#else
21583 pgd = pgd_offset(current->active_mm, address);
21584 +#endif
21585 +
21586 pgd_ref = pgd_offset_k(address);
21587 if (pgd_none(*pgd_ref))
21588 return -1;
21589 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
21590 static int is_errata100(struct pt_regs *regs, unsigned long address)
21591 {
21592 #ifdef CONFIG_X86_64
21593 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
21594 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
21595 return 1;
21596 #endif
21597 return 0;
21598 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
21599 }
21600
21601 static const char nx_warning[] = KERN_CRIT
21602 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
21603 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
21604
21605 static void
21606 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21607 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21608 if (!oops_may_print())
21609 return;
21610
21611 - if (error_code & PF_INSTR) {
21612 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
21613 unsigned int level;
21614
21615 pte_t *pte = lookup_address(address, &level);
21616
21617 if (pte && pte_present(*pte) && !pte_exec(*pte))
21618 - printk(nx_warning, current_uid());
21619 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
21620 }
21621
21622 +#ifdef CONFIG_PAX_KERNEXEC
21623 + if (init_mm.start_code <= address && address < init_mm.end_code) {
21624 + if (current->signal->curr_ip)
21625 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21626 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
21627 + else
21628 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21629 + current->comm, task_pid_nr(current), current_uid(), current_euid());
21630 + }
21631 +#endif
21632 +
21633 printk(KERN_ALERT "BUG: unable to handle kernel ");
21634 if (address < PAGE_SIZE)
21635 printk(KERN_CONT "NULL pointer dereference");
21636 @@ -739,6 +820,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
21637 }
21638 #endif
21639
21640 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21641 + if (pax_is_fetch_fault(regs, error_code, address)) {
21642 +
21643 +#ifdef CONFIG_PAX_EMUTRAMP
21644 + switch (pax_handle_fetch_fault(regs)) {
21645 + case 2:
21646 + return;
21647 + }
21648 +#endif
21649 +
21650 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21651 + do_group_exit(SIGKILL);
21652 + }
21653 +#endif
21654 +
21655 if (unlikely(show_unhandled_signals))
21656 show_signal_msg(regs, error_code, address, tsk);
21657
21658 @@ -835,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
21659 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
21660 printk(KERN_ERR
21661 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
21662 - tsk->comm, tsk->pid, address);
21663 + tsk->comm, task_pid_nr(tsk), address);
21664 code = BUS_MCEERR_AR;
21665 }
21666 #endif
21667 @@ -890,6 +986,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
21668 return 1;
21669 }
21670
21671 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21672 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
21673 +{
21674 + pte_t *pte;
21675 + pmd_t *pmd;
21676 + spinlock_t *ptl;
21677 + unsigned char pte_mask;
21678 +
21679 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
21680 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
21681 + return 0;
21682 +
21683 + /* PaX: it's our fault, let's handle it if we can */
21684 +
21685 + /* PaX: take a look at read faults before acquiring any locks */
21686 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
21687 + /* instruction fetch attempt from a protected page in user mode */
21688 + up_read(&mm->mmap_sem);
21689 +
21690 +#ifdef CONFIG_PAX_EMUTRAMP
21691 + switch (pax_handle_fetch_fault(regs)) {
21692 + case 2:
21693 + return 1;
21694 + }
21695 +#endif
21696 +
21697 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21698 + do_group_exit(SIGKILL);
21699 + }
21700 +
21701 + pmd = pax_get_pmd(mm, address);
21702 + if (unlikely(!pmd))
21703 + return 0;
21704 +
21705 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21706 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21707 + pte_unmap_unlock(pte, ptl);
21708 + return 0;
21709 + }
21710 +
21711 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21712 + /* write attempt to a protected page in user mode */
21713 + pte_unmap_unlock(pte, ptl);
21714 + return 0;
21715 + }
21716 +
21717 +#ifdef CONFIG_SMP
21718 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21719 +#else
21720 + if (likely(address > get_limit(regs->cs)))
21721 +#endif
21722 + {
21723 + set_pte(pte, pte_mkread(*pte));
21724 + __flush_tlb_one(address);
21725 + pte_unmap_unlock(pte, ptl);
21726 + up_read(&mm->mmap_sem);
21727 + return 1;
21728 + }
21729 +
21730 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21731 +
21732 + /*
21733 + * PaX: fill DTLB with user rights and retry
21734 + */
21735 + __asm__ __volatile__ (
21736 + "orb %2,(%1)\n"
21737 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
21738 +/*
21739 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
21740 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
21741 + * page fault when examined during a TLB load attempt. this is true not only
21742 + * for PTEs holding a non-present entry but also present entries that will
21743 + * raise a page fault (such as those set up by PaX, or the copy-on-write
21744 + * mechanism). in effect it means that we do *not* need to flush the TLBs
21745 + * for our target pages since their PTEs are simply not in the TLBs at all.
21746 +
21747 + * the best thing in omitting it is that we gain around 15-20% speed in the
21748 + * fast path of the page fault handler and can get rid of tracing since we
21749 + * can no longer flush unintended entries.
21750 + */
21751 + "invlpg (%0)\n"
21752 +#endif
21753 + __copyuser_seg"testb $0,(%0)\n"
21754 + "xorb %3,(%1)\n"
21755 + :
21756 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21757 + : "memory", "cc");
21758 + pte_unmap_unlock(pte, ptl);
21759 + up_read(&mm->mmap_sem);
21760 + return 1;
21761 +}
21762 +#endif
21763 +
21764 /*
21765 * Handle a spurious fault caused by a stale TLB entry.
21766 *
21767 @@ -962,6 +1151,9 @@ int show_unhandled_signals = 1;
21768 static inline int
21769 access_error(unsigned long error_code, struct vm_area_struct *vma)
21770 {
21771 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21772 + return 1;
21773 +
21774 if (error_code & PF_WRITE) {
21775 /* write, present and write, not present: */
21776 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21777 @@ -995,18 +1187,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
21778 {
21779 struct vm_area_struct *vma;
21780 struct task_struct *tsk;
21781 - unsigned long address;
21782 struct mm_struct *mm;
21783 int fault;
21784 int write = error_code & PF_WRITE;
21785 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
21786 (write ? FAULT_FLAG_WRITE : 0);
21787
21788 - tsk = current;
21789 - mm = tsk->mm;
21790 -
21791 /* Get the faulting address: */
21792 - address = read_cr2();
21793 + unsigned long address = read_cr2();
21794 +
21795 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21796 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21797 + if (!search_exception_tables(regs->ip)) {
21798 + bad_area_nosemaphore(regs, error_code, address);
21799 + return;
21800 + }
21801 + if (address < PAX_USER_SHADOW_BASE) {
21802 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21803 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
21804 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21805 + } else
21806 + address -= PAX_USER_SHADOW_BASE;
21807 + }
21808 +#endif
21809 +
21810 + tsk = current;
21811 + mm = tsk->mm;
21812
21813 /*
21814 * Detect and handle instructions that would cause a page fault for
21815 @@ -1067,7 +1273,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
21816 * User-mode registers count as a user access even for any
21817 * potential system fault or CPU buglet:
21818 */
21819 - if (user_mode_vm(regs)) {
21820 + if (user_mode(regs)) {
21821 local_irq_enable();
21822 error_code |= PF_USER;
21823 } else {
21824 @@ -1122,6 +1328,11 @@ retry:
21825 might_sleep();
21826 }
21827
21828 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21829 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
21830 + return;
21831 +#endif
21832 +
21833 vma = find_vma(mm, address);
21834 if (unlikely(!vma)) {
21835 bad_area(regs, error_code, address);
21836 @@ -1133,18 +1344,24 @@ retry:
21837 bad_area(regs, error_code, address);
21838 return;
21839 }
21840 - if (error_code & PF_USER) {
21841 - /*
21842 - * Accessing the stack below %sp is always a bug.
21843 - * The large cushion allows instructions like enter
21844 - * and pusha to work. ("enter $65535, $31" pushes
21845 - * 32 pointers and then decrements %sp by 65535.)
21846 - */
21847 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
21848 - bad_area(regs, error_code, address);
21849 - return;
21850 - }
21851 + /*
21852 + * Accessing the stack below %sp is always a bug.
21853 + * The large cushion allows instructions like enter
21854 + * and pusha to work. ("enter $65535, $31" pushes
21855 + * 32 pointers and then decrements %sp by 65535.)
21856 + */
21857 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
21858 + bad_area(regs, error_code, address);
21859 + return;
21860 }
21861 +
21862 +#ifdef CONFIG_PAX_SEGMEXEC
21863 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
21864 + bad_area(regs, error_code, address);
21865 + return;
21866 + }
21867 +#endif
21868 +
21869 if (unlikely(expand_stack(vma, address))) {
21870 bad_area(regs, error_code, address);
21871 return;
21872 @@ -1199,3 +1416,292 @@ good_area:
21873
21874 up_read(&mm->mmap_sem);
21875 }
21876 +
21877 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21878 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
21879 +{
21880 + struct mm_struct *mm = current->mm;
21881 + unsigned long ip = regs->ip;
21882 +
21883 + if (v8086_mode(regs))
21884 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
21885 +
21886 +#ifdef CONFIG_PAX_PAGEEXEC
21887 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
21888 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
21889 + return true;
21890 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
21891 + return true;
21892 + return false;
21893 + }
21894 +#endif
21895 +
21896 +#ifdef CONFIG_PAX_SEGMEXEC
21897 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
21898 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
21899 + return true;
21900 + return false;
21901 + }
21902 +#endif
21903 +
21904 + return false;
21905 +}
21906 +#endif
21907 +
21908 +#ifdef CONFIG_PAX_EMUTRAMP
21909 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
21910 +{
21911 + int err;
21912 +
21913 + do { /* PaX: libffi trampoline emulation */
21914 + unsigned char mov, jmp;
21915 + unsigned int addr1, addr2;
21916 +
21917 +#ifdef CONFIG_X86_64
21918 + if ((regs->ip + 9) >> 32)
21919 + break;
21920 +#endif
21921 +
21922 + err = get_user(mov, (unsigned char __user *)regs->ip);
21923 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21924 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21925 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21926 +
21927 + if (err)
21928 + break;
21929 +
21930 + if (mov == 0xB8 && jmp == 0xE9) {
21931 + regs->ax = addr1;
21932 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21933 + return 2;
21934 + }
21935 + } while (0);
21936 +
21937 + do { /* PaX: gcc trampoline emulation #1 */
21938 + unsigned char mov1, mov2;
21939 + unsigned short jmp;
21940 + unsigned int addr1, addr2;
21941 +
21942 +#ifdef CONFIG_X86_64
21943 + if ((regs->ip + 11) >> 32)
21944 + break;
21945 +#endif
21946 +
21947 + err = get_user(mov1, (unsigned char __user *)regs->ip);
21948 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21949 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
21950 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21951 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
21952 +
21953 + if (err)
21954 + break;
21955 +
21956 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
21957 + regs->cx = addr1;
21958 + regs->ax = addr2;
21959 + regs->ip = addr2;
21960 + return 2;
21961 + }
21962 + } while (0);
21963 +
21964 + do { /* PaX: gcc trampoline emulation #2 */
21965 + unsigned char mov, jmp;
21966 + unsigned int addr1, addr2;
21967 +
21968 +#ifdef CONFIG_X86_64
21969 + if ((regs->ip + 9) >> 32)
21970 + break;
21971 +#endif
21972 +
21973 + err = get_user(mov, (unsigned char __user *)regs->ip);
21974 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21975 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21976 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21977 +
21978 + if (err)
21979 + break;
21980 +
21981 + if (mov == 0xB9 && jmp == 0xE9) {
21982 + regs->cx = addr1;
21983 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21984 + return 2;
21985 + }
21986 + } while (0);
21987 +
21988 + return 1; /* PaX in action */
21989 +}
21990 +
21991 +#ifdef CONFIG_X86_64
21992 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
21993 +{
21994 + int err;
21995 +
21996 + do { /* PaX: libffi trampoline emulation */
21997 + unsigned short mov1, mov2, jmp1;
21998 + unsigned char stcclc, jmp2;
21999 + unsigned long addr1, addr2;
22000 +
22001 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22002 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
22003 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
22004 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
22005 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
22006 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
22007 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
22008 +
22009 + if (err)
22010 + break;
22011 +
22012 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22013 + regs->r11 = addr1;
22014 + regs->r10 = addr2;
22015 + if (stcclc == 0xF8)
22016 + regs->flags &= ~X86_EFLAGS_CF;
22017 + else
22018 + regs->flags |= X86_EFLAGS_CF;
22019 + regs->ip = addr1;
22020 + return 2;
22021 + }
22022 + } while (0);
22023 +
22024 + do { /* PaX: gcc trampoline emulation #1 */
22025 + unsigned short mov1, mov2, jmp1;
22026 + unsigned char jmp2;
22027 + unsigned int addr1;
22028 + unsigned long addr2;
22029 +
22030 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22031 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
22032 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
22033 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
22034 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
22035 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
22036 +
22037 + if (err)
22038 + break;
22039 +
22040 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22041 + regs->r11 = addr1;
22042 + regs->r10 = addr2;
22043 + regs->ip = addr1;
22044 + return 2;
22045 + }
22046 + } while (0);
22047 +
22048 + do { /* PaX: gcc trampoline emulation #2 */
22049 + unsigned short mov1, mov2, jmp1;
22050 + unsigned char jmp2;
22051 + unsigned long addr1, addr2;
22052 +
22053 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22054 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
22055 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
22056 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
22057 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
22058 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
22059 +
22060 + if (err)
22061 + break;
22062 +
22063 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22064 + regs->r11 = addr1;
22065 + regs->r10 = addr2;
22066 + regs->ip = addr1;
22067 + return 2;
22068 + }
22069 + } while (0);
22070 +
22071 + return 1; /* PaX in action */
22072 +}
22073 +#endif
22074 +
22075 +/*
22076 + * PaX: decide what to do with offenders (regs->ip = fault address)
22077 + *
22078 + * returns 1 when task should be killed
22079 + * 2 when gcc trampoline was detected
22080 + */
22081 +static int pax_handle_fetch_fault(struct pt_regs *regs)
22082 +{
22083 + if (v8086_mode(regs))
22084 + return 1;
22085 +
22086 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
22087 + return 1;
22088 +
22089 +#ifdef CONFIG_X86_32
22090 + return pax_handle_fetch_fault_32(regs);
22091 +#else
22092 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
22093 + return pax_handle_fetch_fault_32(regs);
22094 + else
22095 + return pax_handle_fetch_fault_64(regs);
22096 +#endif
22097 +}
22098 +#endif
22099 +
22100 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22101 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
22102 +{
22103 + long i;
22104 +
22105 + printk(KERN_ERR "PAX: bytes at PC: ");
22106 + for (i = 0; i < 20; i++) {
22107 + unsigned char c;
22108 + if (get_user(c, (unsigned char __force_user *)pc+i))
22109 + printk(KERN_CONT "?? ");
22110 + else
22111 + printk(KERN_CONT "%02x ", c);
22112 + }
22113 + printk("\n");
22114 +
22115 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
22116 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
22117 + unsigned long c;
22118 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
22119 +#ifdef CONFIG_X86_32
22120 + printk(KERN_CONT "???????? ");
22121 +#else
22122 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
22123 + printk(KERN_CONT "???????? ???????? ");
22124 + else
22125 + printk(KERN_CONT "???????????????? ");
22126 +#endif
22127 + } else {
22128 +#ifdef CONFIG_X86_64
22129 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
22130 + printk(KERN_CONT "%08x ", (unsigned int)c);
22131 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
22132 + } else
22133 +#endif
22134 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
22135 + }
22136 + }
22137 + printk("\n");
22138 +}
22139 +#endif
22140 +
22141 +/**
22142 + * probe_kernel_write(): safely attempt to write to a location
22143 + * @dst: address to write to
22144 + * @src: pointer to the data that shall be written
22145 + * @size: size of the data chunk
22146 + *
22147 + * Safely write to address @dst from the buffer at @src. If a kernel fault
22148 + * happens, handle that and return -EFAULT.
22149 + */
22150 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
22151 +{
22152 + long ret;
22153 + mm_segment_t old_fs = get_fs();
22154 +
22155 + set_fs(KERNEL_DS);
22156 + pagefault_disable();
22157 + pax_open_kernel();
22158 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
22159 + pax_close_kernel();
22160 + pagefault_enable();
22161 + set_fs(old_fs);
22162 +
22163 + return ret ? -EFAULT : 0;
22164 +}
22165 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
22166 index dd74e46..7d26398 100644
22167 --- a/arch/x86/mm/gup.c
22168 +++ b/arch/x86/mm/gup.c
22169 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
22170 addr = start;
22171 len = (unsigned long) nr_pages << PAGE_SHIFT;
22172 end = start + len;
22173 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22174 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22175 (void __user *)start, len)))
22176 return 0;
22177
22178 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
22179 index f4f29b1..5cac4fb 100644
22180 --- a/arch/x86/mm/highmem_32.c
22181 +++ b/arch/x86/mm/highmem_32.c
22182 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
22183 idx = type + KM_TYPE_NR*smp_processor_id();
22184 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22185 BUG_ON(!pte_none(*(kmap_pte-idx)));
22186 +
22187 + pax_open_kernel();
22188 set_pte(kmap_pte-idx, mk_pte(page, prot));
22189 + pax_close_kernel();
22190 +
22191 arch_flush_lazy_mmu_mode();
22192
22193 return (void *)vaddr;
22194 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
22195 index f581a18..29efd37 100644
22196 --- a/arch/x86/mm/hugetlbpage.c
22197 +++ b/arch/x86/mm/hugetlbpage.c
22198 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
22199 struct hstate *h = hstate_file(file);
22200 struct mm_struct *mm = current->mm;
22201 struct vm_area_struct *vma;
22202 - unsigned long start_addr;
22203 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22204 +
22205 +#ifdef CONFIG_PAX_SEGMEXEC
22206 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22207 + pax_task_size = SEGMEXEC_TASK_SIZE;
22208 +#endif
22209 +
22210 + pax_task_size -= PAGE_SIZE;
22211
22212 if (len > mm->cached_hole_size) {
22213 - start_addr = mm->free_area_cache;
22214 + start_addr = mm->free_area_cache;
22215 } else {
22216 - start_addr = TASK_UNMAPPED_BASE;
22217 - mm->cached_hole_size = 0;
22218 + start_addr = mm->mmap_base;
22219 + mm->cached_hole_size = 0;
22220 }
22221
22222 full_search:
22223 @@ -280,26 +287,27 @@ full_search:
22224
22225 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22226 /* At this point: (!vma || addr < vma->vm_end). */
22227 - if (TASK_SIZE - len < addr) {
22228 + if (pax_task_size - len < addr) {
22229 /*
22230 * Start a new search - just in case we missed
22231 * some holes.
22232 */
22233 - if (start_addr != TASK_UNMAPPED_BASE) {
22234 - start_addr = TASK_UNMAPPED_BASE;
22235 + if (start_addr != mm->mmap_base) {
22236 + start_addr = mm->mmap_base;
22237 mm->cached_hole_size = 0;
22238 goto full_search;
22239 }
22240 return -ENOMEM;
22241 }
22242 - if (!vma || addr + len <= vma->vm_start) {
22243 - mm->free_area_cache = addr + len;
22244 - return addr;
22245 - }
22246 + if (check_heap_stack_gap(vma, addr, len))
22247 + break;
22248 if (addr + mm->cached_hole_size < vma->vm_start)
22249 mm->cached_hole_size = vma->vm_start - addr;
22250 addr = ALIGN(vma->vm_end, huge_page_size(h));
22251 }
22252 +
22253 + mm->free_area_cache = addr + len;
22254 + return addr;
22255 }
22256
22257 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22258 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22259 {
22260 struct hstate *h = hstate_file(file);
22261 struct mm_struct *mm = current->mm;
22262 - struct vm_area_struct *vma, *prev_vma;
22263 - unsigned long base = mm->mmap_base, addr = addr0;
22264 + struct vm_area_struct *vma;
22265 + unsigned long base = mm->mmap_base, addr;
22266 unsigned long largest_hole = mm->cached_hole_size;
22267 - int first_time = 1;
22268
22269 /* don't allow allocations above current base */
22270 if (mm->free_area_cache > base)
22271 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22272 largest_hole = 0;
22273 mm->free_area_cache = base;
22274 }
22275 -try_again:
22276 +
22277 /* make sure it can fit in the remaining address space */
22278 if (mm->free_area_cache < len)
22279 goto fail;
22280
22281 /* either no address requested or can't fit in requested address hole */
22282 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
22283 + addr = (mm->free_area_cache - len);
22284 do {
22285 + addr &= huge_page_mask(h);
22286 + vma = find_vma(mm, addr);
22287 /*
22288 * Lookup failure means no vma is above this address,
22289 * i.e. return with success:
22290 - */
22291 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
22292 - return addr;
22293 -
22294 - /*
22295 * new region fits between prev_vma->vm_end and
22296 * vma->vm_start, use it:
22297 */
22298 - if (addr + len <= vma->vm_start &&
22299 - (!prev_vma || (addr >= prev_vma->vm_end))) {
22300 + if (check_heap_stack_gap(vma, addr, len)) {
22301 /* remember the address as a hint for next time */
22302 - mm->cached_hole_size = largest_hole;
22303 - return (mm->free_area_cache = addr);
22304 - } else {
22305 - /* pull free_area_cache down to the first hole */
22306 - if (mm->free_area_cache == vma->vm_end) {
22307 - mm->free_area_cache = vma->vm_start;
22308 - mm->cached_hole_size = largest_hole;
22309 - }
22310 + mm->cached_hole_size = largest_hole;
22311 + return (mm->free_area_cache = addr);
22312 + }
22313 + /* pull free_area_cache down to the first hole */
22314 + if (mm->free_area_cache == vma->vm_end) {
22315 + mm->free_area_cache = vma->vm_start;
22316 + mm->cached_hole_size = largest_hole;
22317 }
22318
22319 /* remember the largest hole we saw so far */
22320 if (addr + largest_hole < vma->vm_start)
22321 - largest_hole = vma->vm_start - addr;
22322 + largest_hole = vma->vm_start - addr;
22323
22324 /* try just below the current vma->vm_start */
22325 - addr = (vma->vm_start - len) & huge_page_mask(h);
22326 - } while (len <= vma->vm_start);
22327 + addr = skip_heap_stack_gap(vma, len);
22328 + } while (!IS_ERR_VALUE(addr));
22329
22330 fail:
22331 /*
22332 - * if hint left us with no space for the requested
22333 - * mapping then try again:
22334 - */
22335 - if (first_time) {
22336 - mm->free_area_cache = base;
22337 - largest_hole = 0;
22338 - first_time = 0;
22339 - goto try_again;
22340 - }
22341 - /*
22342 * A failed mmap() very likely causes application failure,
22343 * so fall back to the bottom-up function here. This scenario
22344 * can happen with large stack limits and large mmap()
22345 * allocations.
22346 */
22347 - mm->free_area_cache = TASK_UNMAPPED_BASE;
22348 +
22349 +#ifdef CONFIG_PAX_SEGMEXEC
22350 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22351 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22352 + else
22353 +#endif
22354 +
22355 + mm->mmap_base = TASK_UNMAPPED_BASE;
22356 +
22357 +#ifdef CONFIG_PAX_RANDMMAP
22358 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22359 + mm->mmap_base += mm->delta_mmap;
22360 +#endif
22361 +
22362 + mm->free_area_cache = mm->mmap_base;
22363 mm->cached_hole_size = ~0UL;
22364 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
22365 len, pgoff, flags);
22366 @@ -386,6 +392,7 @@ fail:
22367 /*
22368 * Restore the topdown base:
22369 */
22370 + mm->mmap_base = base;
22371 mm->free_area_cache = base;
22372 mm->cached_hole_size = ~0UL;
22373
22374 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
22375 struct hstate *h = hstate_file(file);
22376 struct mm_struct *mm = current->mm;
22377 struct vm_area_struct *vma;
22378 + unsigned long pax_task_size = TASK_SIZE;
22379
22380 if (len & ~huge_page_mask(h))
22381 return -EINVAL;
22382 - if (len > TASK_SIZE)
22383 +
22384 +#ifdef CONFIG_PAX_SEGMEXEC
22385 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22386 + pax_task_size = SEGMEXEC_TASK_SIZE;
22387 +#endif
22388 +
22389 + pax_task_size -= PAGE_SIZE;
22390 +
22391 + if (len > pax_task_size)
22392 return -ENOMEM;
22393
22394 if (flags & MAP_FIXED) {
22395 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
22396 if (addr) {
22397 addr = ALIGN(addr, huge_page_size(h));
22398 vma = find_vma(mm, addr);
22399 - if (TASK_SIZE - len >= addr &&
22400 - (!vma || addr + len <= vma->vm_start))
22401 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
22402 return addr;
22403 }
22404 if (mm->get_unmapped_area == arch_get_unmapped_area)
22405 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
22406 index 87488b9..399f416 100644
22407 --- a/arch/x86/mm/init.c
22408 +++ b/arch/x86/mm/init.c
22409 @@ -15,6 +15,7 @@
22410 #include <asm/tlbflush.h>
22411 #include <asm/tlb.h>
22412 #include <asm/proto.h>
22413 +#include <asm/desc.h>
22414
22415 unsigned long __initdata pgt_buf_start;
22416 unsigned long __meminitdata pgt_buf_end;
22417 @@ -31,7 +32,7 @@ int direct_gbpages
22418 static void __init find_early_table_space(unsigned long end, int use_pse,
22419 int use_gbpages)
22420 {
22421 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
22422 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
22423 phys_addr_t base;
22424
22425 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
22426 @@ -312,8 +313,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
22427 */
22428 int devmem_is_allowed(unsigned long pagenr)
22429 {
22430 +#ifdef CONFIG_GRKERNSEC_KMEM
22431 + /* allow BDA */
22432 + if (!pagenr)
22433 + return 1;
22434 + /* allow EBDA */
22435 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
22436 + return 1;
22437 +#else
22438 + if (!pagenr)
22439 + return 1;
22440 +#ifdef CONFIG_VM86
22441 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22442 + return 1;
22443 +#endif
22444 +#endif
22445 +
22446 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22447 + return 1;
22448 +#ifdef CONFIG_GRKERNSEC_KMEM
22449 + /* throw out everything else below 1MB */
22450 if (pagenr <= 256)
22451 - return 1;
22452 + return 0;
22453 +#endif
22454 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22455 return 0;
22456 if (!page_is_ram(pagenr))
22457 @@ -372,6 +394,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
22458
22459 void free_initmem(void)
22460 {
22461 +
22462 +#ifdef CONFIG_PAX_KERNEXEC
22463 +#ifdef CONFIG_X86_32
22464 + /* PaX: limit KERNEL_CS to actual size */
22465 + unsigned long addr, limit;
22466 + struct desc_struct d;
22467 + int cpu;
22468 +
22469 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22470 + limit = (limit - 1UL) >> PAGE_SHIFT;
22471 +
22472 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22473 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
22474 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22475 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22476 + }
22477 +
22478 + /* PaX: make KERNEL_CS read-only */
22479 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22480 + if (!paravirt_enabled())
22481 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22482 +/*
22483 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22484 + pgd = pgd_offset_k(addr);
22485 + pud = pud_offset(pgd, addr);
22486 + pmd = pmd_offset(pud, addr);
22487 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22488 + }
22489 +*/
22490 +#ifdef CONFIG_X86_PAE
22491 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22492 +/*
22493 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22494 + pgd = pgd_offset_k(addr);
22495 + pud = pud_offset(pgd, addr);
22496 + pmd = pmd_offset(pud, addr);
22497 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22498 + }
22499 +*/
22500 +#endif
22501 +
22502 +#ifdef CONFIG_MODULES
22503 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22504 +#endif
22505 +
22506 +#else
22507 + pgd_t *pgd;
22508 + pud_t *pud;
22509 + pmd_t *pmd;
22510 + unsigned long addr, end;
22511 +
22512 + /* PaX: make kernel code/rodata read-only, rest non-executable */
22513 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22514 + pgd = pgd_offset_k(addr);
22515 + pud = pud_offset(pgd, addr);
22516 + pmd = pmd_offset(pud, addr);
22517 + if (!pmd_present(*pmd))
22518 + continue;
22519 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22520 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22521 + else
22522 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22523 + }
22524 +
22525 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22526 + end = addr + KERNEL_IMAGE_SIZE;
22527 + for (; addr < end; addr += PMD_SIZE) {
22528 + pgd = pgd_offset_k(addr);
22529 + pud = pud_offset(pgd, addr);
22530 + pmd = pmd_offset(pud, addr);
22531 + if (!pmd_present(*pmd))
22532 + continue;
22533 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22534 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22535 + }
22536 +#endif
22537 +
22538 + flush_tlb_all();
22539 +#endif
22540 +
22541 free_init_pages("unused kernel memory",
22542 (unsigned long)(&__init_begin),
22543 (unsigned long)(&__init_end));
22544 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
22545 index 29f7c6d..b46b35b 100644
22546 --- a/arch/x86/mm/init_32.c
22547 +++ b/arch/x86/mm/init_32.c
22548 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
22549 }
22550
22551 /*
22552 - * Creates a middle page table and puts a pointer to it in the
22553 - * given global directory entry. This only returns the gd entry
22554 - * in non-PAE compilation mode, since the middle layer is folded.
22555 - */
22556 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
22557 -{
22558 - pud_t *pud;
22559 - pmd_t *pmd_table;
22560 -
22561 -#ifdef CONFIG_X86_PAE
22562 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
22563 - if (after_bootmem)
22564 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
22565 - else
22566 - pmd_table = (pmd_t *)alloc_low_page();
22567 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
22568 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
22569 - pud = pud_offset(pgd, 0);
22570 - BUG_ON(pmd_table != pmd_offset(pud, 0));
22571 -
22572 - return pmd_table;
22573 - }
22574 -#endif
22575 - pud = pud_offset(pgd, 0);
22576 - pmd_table = pmd_offset(pud, 0);
22577 -
22578 - return pmd_table;
22579 -}
22580 -
22581 -/*
22582 * Create a page table and place a pointer to it in a middle page
22583 * directory entry:
22584 */
22585 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
22586 page_table = (pte_t *)alloc_low_page();
22587
22588 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
22589 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22590 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
22591 +#else
22592 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
22593 +#endif
22594 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
22595 }
22596
22597 return pte_offset_kernel(pmd, 0);
22598 }
22599
22600 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
22601 +{
22602 + pud_t *pud;
22603 + pmd_t *pmd_table;
22604 +
22605 + pud = pud_offset(pgd, 0);
22606 + pmd_table = pmd_offset(pud, 0);
22607 +
22608 + return pmd_table;
22609 +}
22610 +
22611 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
22612 {
22613 int pgd_idx = pgd_index(vaddr);
22614 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22615 int pgd_idx, pmd_idx;
22616 unsigned long vaddr;
22617 pgd_t *pgd;
22618 + pud_t *pud;
22619 pmd_t *pmd;
22620 pte_t *pte = NULL;
22621
22622 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22623 pgd = pgd_base + pgd_idx;
22624
22625 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
22626 - pmd = one_md_table_init(pgd);
22627 - pmd = pmd + pmd_index(vaddr);
22628 + pud = pud_offset(pgd, vaddr);
22629 + pmd = pmd_offset(pud, vaddr);
22630 +
22631 +#ifdef CONFIG_X86_PAE
22632 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22633 +#endif
22634 +
22635 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
22636 pmd++, pmd_idx++) {
22637 pte = page_table_kmap_check(one_page_table_init(pmd),
22638 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22639 }
22640 }
22641
22642 -static inline int is_kernel_text(unsigned long addr)
22643 +static inline int is_kernel_text(unsigned long start, unsigned long end)
22644 {
22645 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
22646 - return 1;
22647 - return 0;
22648 + if ((start > ktla_ktva((unsigned long)_etext) ||
22649 + end <= ktla_ktva((unsigned long)_stext)) &&
22650 + (start > ktla_ktva((unsigned long)_einittext) ||
22651 + end <= ktla_ktva((unsigned long)_sinittext)) &&
22652 +
22653 +#ifdef CONFIG_ACPI_SLEEP
22654 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
22655 +#endif
22656 +
22657 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
22658 + return 0;
22659 + return 1;
22660 }
22661
22662 /*
22663 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
22664 unsigned long last_map_addr = end;
22665 unsigned long start_pfn, end_pfn;
22666 pgd_t *pgd_base = swapper_pg_dir;
22667 - int pgd_idx, pmd_idx, pte_ofs;
22668 + unsigned int pgd_idx, pmd_idx, pte_ofs;
22669 unsigned long pfn;
22670 pgd_t *pgd;
22671 + pud_t *pud;
22672 pmd_t *pmd;
22673 pte_t *pte;
22674 unsigned pages_2m, pages_4k;
22675 @@ -281,8 +282,13 @@ repeat:
22676 pfn = start_pfn;
22677 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22678 pgd = pgd_base + pgd_idx;
22679 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
22680 - pmd = one_md_table_init(pgd);
22681 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
22682 + pud = pud_offset(pgd, 0);
22683 + pmd = pmd_offset(pud, 0);
22684 +
22685 +#ifdef CONFIG_X86_PAE
22686 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22687 +#endif
22688
22689 if (pfn >= end_pfn)
22690 continue;
22691 @@ -294,14 +300,13 @@ repeat:
22692 #endif
22693 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
22694 pmd++, pmd_idx++) {
22695 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
22696 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
22697
22698 /*
22699 * Map with big pages if possible, otherwise
22700 * create normal page tables:
22701 */
22702 if (use_pse) {
22703 - unsigned int addr2;
22704 pgprot_t prot = PAGE_KERNEL_LARGE;
22705 /*
22706 * first pass will use the same initial
22707 @@ -311,11 +316,7 @@ repeat:
22708 __pgprot(PTE_IDENT_ATTR |
22709 _PAGE_PSE);
22710
22711 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
22712 - PAGE_OFFSET + PAGE_SIZE-1;
22713 -
22714 - if (is_kernel_text(addr) ||
22715 - is_kernel_text(addr2))
22716 + if (is_kernel_text(address, address + PMD_SIZE))
22717 prot = PAGE_KERNEL_LARGE_EXEC;
22718
22719 pages_2m++;
22720 @@ -332,7 +333,7 @@ repeat:
22721 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22722 pte += pte_ofs;
22723 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
22724 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
22725 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
22726 pgprot_t prot = PAGE_KERNEL;
22727 /*
22728 * first pass will use the same initial
22729 @@ -340,7 +341,7 @@ repeat:
22730 */
22731 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
22732
22733 - if (is_kernel_text(addr))
22734 + if (is_kernel_text(address, address + PAGE_SIZE))
22735 prot = PAGE_KERNEL_EXEC;
22736
22737 pages_4k++;
22738 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
22739
22740 pud = pud_offset(pgd, va);
22741 pmd = pmd_offset(pud, va);
22742 - if (!pmd_present(*pmd))
22743 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
22744 break;
22745
22746 pte = pte_offset_kernel(pmd, va);
22747 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_range_init(void)
22748
22749 static void __init pagetable_init(void)
22750 {
22751 - pgd_t *pgd_base = swapper_pg_dir;
22752 -
22753 - permanent_kmaps_init(pgd_base);
22754 + permanent_kmaps_init(swapper_pg_dir);
22755 }
22756
22757 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22758 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22759 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22760
22761 /* user-defined highmem size */
22762 @@ -757,6 +756,12 @@ void __init mem_init(void)
22763
22764 pci_iommu_alloc();
22765
22766 +#ifdef CONFIG_PAX_PER_CPU_PGD
22767 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22768 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22769 + KERNEL_PGD_PTRS);
22770 +#endif
22771 +
22772 #ifdef CONFIG_FLATMEM
22773 BUG_ON(!mem_map);
22774 #endif
22775 @@ -774,7 +779,7 @@ void __init mem_init(void)
22776 set_highmem_pages_init();
22777
22778 codesize = (unsigned long) &_etext - (unsigned long) &_text;
22779 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
22780 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
22781 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
22782
22783 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
22784 @@ -815,10 +820,10 @@ void __init mem_init(void)
22785 ((unsigned long)&__init_end -
22786 (unsigned long)&__init_begin) >> 10,
22787
22788 - (unsigned long)&_etext, (unsigned long)&_edata,
22789 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
22790 + (unsigned long)&_sdata, (unsigned long)&_edata,
22791 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
22792
22793 - (unsigned long)&_text, (unsigned long)&_etext,
22794 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
22795 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
22796
22797 /*
22798 @@ -896,6 +901,7 @@ void set_kernel_text_rw(void)
22799 if (!kernel_set_to_readonly)
22800 return;
22801
22802 + start = ktla_ktva(start);
22803 pr_debug("Set kernel text: %lx - %lx for read write\n",
22804 start, start+size);
22805
22806 @@ -910,6 +916,7 @@ void set_kernel_text_ro(void)
22807 if (!kernel_set_to_readonly)
22808 return;
22809
22810 + start = ktla_ktva(start);
22811 pr_debug("Set kernel text: %lx - %lx for read only\n",
22812 start, start+size);
22813
22814 @@ -938,6 +945,7 @@ void mark_rodata_ro(void)
22815 unsigned long start = PFN_ALIGN(_text);
22816 unsigned long size = PFN_ALIGN(_etext) - start;
22817
22818 + start = ktla_ktva(start);
22819 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
22820 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
22821 size >> 10);
22822 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
22823 index bbaaa00..796fa65 100644
22824 --- a/arch/x86/mm/init_64.c
22825 +++ b/arch/x86/mm/init_64.c
22826 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
22827 * around without checking the pgd every time.
22828 */
22829
22830 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
22831 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
22832 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22833
22834 int force_personality32;
22835 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
22836
22837 for (address = start; address <= end; address += PGDIR_SIZE) {
22838 const pgd_t *pgd_ref = pgd_offset_k(address);
22839 +
22840 +#ifdef CONFIG_PAX_PER_CPU_PGD
22841 + unsigned long cpu;
22842 +#else
22843 struct page *page;
22844 +#endif
22845
22846 if (pgd_none(*pgd_ref))
22847 continue;
22848
22849 spin_lock(&pgd_lock);
22850 +
22851 +#ifdef CONFIG_PAX_PER_CPU_PGD
22852 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
22853 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
22854 +#else
22855 list_for_each_entry(page, &pgd_list, lru) {
22856 pgd_t *pgd;
22857 spinlock_t *pgt_lock;
22858 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
22859 /* the pgt_lock only for Xen */
22860 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22861 spin_lock(pgt_lock);
22862 +#endif
22863
22864 if (pgd_none(*pgd))
22865 set_pgd(pgd, *pgd_ref);
22866 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
22867 BUG_ON(pgd_page_vaddr(*pgd)
22868 != pgd_page_vaddr(*pgd_ref));
22869
22870 +#ifndef CONFIG_PAX_PER_CPU_PGD
22871 spin_unlock(pgt_lock);
22872 +#endif
22873 +
22874 }
22875 spin_unlock(&pgd_lock);
22876 }
22877 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
22878 pmd = fill_pmd(pud, vaddr);
22879 pte = fill_pte(pmd, vaddr);
22880
22881 + pax_open_kernel();
22882 set_pte(pte, new_pte);
22883 + pax_close_kernel();
22884
22885 /*
22886 * It's enough to flush this one mapping.
22887 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
22888 pgd = pgd_offset_k((unsigned long)__va(phys));
22889 if (pgd_none(*pgd)) {
22890 pud = (pud_t *) spp_getpage();
22891 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
22892 - _PAGE_USER));
22893 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
22894 }
22895 pud = pud_offset(pgd, (unsigned long)__va(phys));
22896 if (pud_none(*pud)) {
22897 pmd = (pmd_t *) spp_getpage();
22898 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
22899 - _PAGE_USER));
22900 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
22901 }
22902 pmd = pmd_offset(pud, phys);
22903 BUG_ON(!pmd_none(*pmd));
22904 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
22905 if (pfn >= pgt_buf_top)
22906 panic("alloc_low_page: ran out of memory");
22907
22908 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
22909 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
22910 clear_page(adr);
22911 *phys = pfn * PAGE_SIZE;
22912 return adr;
22913 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
22914
22915 phys = __pa(virt);
22916 left = phys & (PAGE_SIZE - 1);
22917 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
22918 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
22919 adr = (void *)(((unsigned long)adr) | left);
22920
22921 return adr;
22922 @@ -693,6 +707,12 @@ void __init mem_init(void)
22923
22924 pci_iommu_alloc();
22925
22926 +#ifdef CONFIG_PAX_PER_CPU_PGD
22927 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22928 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22929 + KERNEL_PGD_PTRS);
22930 +#endif
22931 +
22932 /* clear_bss() already clear the empty_zero_page */
22933
22934 reservedpages = 0;
22935 @@ -853,8 +873,8 @@ int kern_addr_valid(unsigned long addr)
22936 static struct vm_area_struct gate_vma = {
22937 .vm_start = VSYSCALL_START,
22938 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
22939 - .vm_page_prot = PAGE_READONLY_EXEC,
22940 - .vm_flags = VM_READ | VM_EXEC
22941 + .vm_page_prot = PAGE_READONLY,
22942 + .vm_flags = VM_READ
22943 };
22944
22945 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
22946 @@ -888,7 +908,7 @@ int in_gate_area_no_mm(unsigned long addr)
22947
22948 const char *arch_vma_name(struct vm_area_struct *vma)
22949 {
22950 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
22951 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
22952 return "[vdso]";
22953 if (vma == &gate_vma)
22954 return "[vsyscall]";
22955 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
22956 index 7b179b4..6bd1777 100644
22957 --- a/arch/x86/mm/iomap_32.c
22958 +++ b/arch/x86/mm/iomap_32.c
22959 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
22960 type = kmap_atomic_idx_push();
22961 idx = type + KM_TYPE_NR * smp_processor_id();
22962 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22963 +
22964 + pax_open_kernel();
22965 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
22966 + pax_close_kernel();
22967 +
22968 arch_flush_lazy_mmu_mode();
22969
22970 return (void *)vaddr;
22971 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
22972 index be1ef57..55f0160 100644
22973 --- a/arch/x86/mm/ioremap.c
22974 +++ b/arch/x86/mm/ioremap.c
22975 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
22976 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
22977 int is_ram = page_is_ram(pfn);
22978
22979 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
22980 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
22981 return NULL;
22982 WARN_ON_ONCE(is_ram);
22983 }
22984 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
22985
22986 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
22987 if (page_is_ram(start >> PAGE_SHIFT))
22988 +#ifdef CONFIG_HIGHMEM
22989 + if ((start >> PAGE_SHIFT) < max_low_pfn)
22990 +#endif
22991 return __va(phys);
22992
22993 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
22994 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
22995 early_param("early_ioremap_debug", early_ioremap_debug_setup);
22996
22997 static __initdata int after_paging_init;
22998 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
22999 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
23000
23001 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
23002 {
23003 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
23004 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
23005
23006 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
23007 - memset(bm_pte, 0, sizeof(bm_pte));
23008 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
23009 + pmd_populate_user(&init_mm, pmd, bm_pte);
23010
23011 /*
23012 * The boot-ioremap range spans multiple pmds, for which
23013 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
23014 index d87dd6d..bf3fa66 100644
23015 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
23016 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
23017 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
23018 * memory (e.g. tracked pages)? For now, we need this to avoid
23019 * invoking kmemcheck for PnP BIOS calls.
23020 */
23021 - if (regs->flags & X86_VM_MASK)
23022 + if (v8086_mode(regs))
23023 return false;
23024 - if (regs->cs != __KERNEL_CS)
23025 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
23026 return false;
23027
23028 pte = kmemcheck_pte_lookup(address);
23029 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
23030 index 845df68..1d8d29f 100644
23031 --- a/arch/x86/mm/mmap.c
23032 +++ b/arch/x86/mm/mmap.c
23033 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
23034 * Leave an at least ~128 MB hole with possible stack randomization.
23035 */
23036 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
23037 -#define MAX_GAP (TASK_SIZE/6*5)
23038 +#define MAX_GAP (pax_task_size/6*5)
23039
23040 static int mmap_is_legacy(void)
23041 {
23042 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
23043 return rnd << PAGE_SHIFT;
23044 }
23045
23046 -static unsigned long mmap_base(void)
23047 +static unsigned long mmap_base(struct mm_struct *mm)
23048 {
23049 unsigned long gap = rlimit(RLIMIT_STACK);
23050 + unsigned long pax_task_size = TASK_SIZE;
23051 +
23052 +#ifdef CONFIG_PAX_SEGMEXEC
23053 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23054 + pax_task_size = SEGMEXEC_TASK_SIZE;
23055 +#endif
23056
23057 if (gap < MIN_GAP)
23058 gap = MIN_GAP;
23059 else if (gap > MAX_GAP)
23060 gap = MAX_GAP;
23061
23062 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
23063 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
23064 }
23065
23066 /*
23067 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
23068 * does, but not when emulating X86_32
23069 */
23070 -static unsigned long mmap_legacy_base(void)
23071 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
23072 {
23073 - if (mmap_is_ia32())
23074 + if (mmap_is_ia32()) {
23075 +
23076 +#ifdef CONFIG_PAX_SEGMEXEC
23077 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23078 + return SEGMEXEC_TASK_UNMAPPED_BASE;
23079 + else
23080 +#endif
23081 +
23082 return TASK_UNMAPPED_BASE;
23083 - else
23084 + } else
23085 return TASK_UNMAPPED_BASE + mmap_rnd();
23086 }
23087
23088 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
23089 void arch_pick_mmap_layout(struct mm_struct *mm)
23090 {
23091 if (mmap_is_legacy()) {
23092 - mm->mmap_base = mmap_legacy_base();
23093 + mm->mmap_base = mmap_legacy_base(mm);
23094 +
23095 +#ifdef CONFIG_PAX_RANDMMAP
23096 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23097 + mm->mmap_base += mm->delta_mmap;
23098 +#endif
23099 +
23100 mm->get_unmapped_area = arch_get_unmapped_area;
23101 mm->unmap_area = arch_unmap_area;
23102 } else {
23103 - mm->mmap_base = mmap_base();
23104 + mm->mmap_base = mmap_base(mm);
23105 +
23106 +#ifdef CONFIG_PAX_RANDMMAP
23107 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23108 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
23109 +#endif
23110 +
23111 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
23112 mm->unmap_area = arch_unmap_area_topdown;
23113 }
23114 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
23115 index de54b9b..799051e 100644
23116 --- a/arch/x86/mm/mmio-mod.c
23117 +++ b/arch/x86/mm/mmio-mod.c
23118 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
23119 break;
23120 default:
23121 {
23122 - unsigned char *ip = (unsigned char *)instptr;
23123 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
23124 my_trace->opcode = MMIO_UNKNOWN_OP;
23125 my_trace->width = 0;
23126 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
23127 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
23128 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23129 void __iomem *addr)
23130 {
23131 - static atomic_t next_id;
23132 + static atomic_unchecked_t next_id;
23133 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
23134 /* These are page-unaligned. */
23135 struct mmiotrace_map map = {
23136 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23137 .private = trace
23138 },
23139 .phys = offset,
23140 - .id = atomic_inc_return(&next_id)
23141 + .id = atomic_inc_return_unchecked(&next_id)
23142 };
23143 map.map_id = trace->id;
23144
23145 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
23146 index b008656..773eac2 100644
23147 --- a/arch/x86/mm/pageattr-test.c
23148 +++ b/arch/x86/mm/pageattr-test.c
23149 @@ -36,7 +36,7 @@ enum {
23150
23151 static int pte_testbit(pte_t pte)
23152 {
23153 - return pte_flags(pte) & _PAGE_UNUSED1;
23154 + return pte_flags(pte) & _PAGE_CPA_TEST;
23155 }
23156
23157 struct split_state {
23158 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
23159 index f9e5267..77b1a40 100644
23160 --- a/arch/x86/mm/pageattr.c
23161 +++ b/arch/x86/mm/pageattr.c
23162 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23163 */
23164 #ifdef CONFIG_PCI_BIOS
23165 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
23166 - pgprot_val(forbidden) |= _PAGE_NX;
23167 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23168 #endif
23169
23170 /*
23171 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23172 * Does not cover __inittext since that is gone later on. On
23173 * 64bit we do not enforce !NX on the low mapping
23174 */
23175 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
23176 - pgprot_val(forbidden) |= _PAGE_NX;
23177 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
23178 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23179
23180 +#ifdef CONFIG_DEBUG_RODATA
23181 /*
23182 * The .rodata section needs to be read-only. Using the pfn
23183 * catches all aliases.
23184 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23185 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
23186 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
23187 pgprot_val(forbidden) |= _PAGE_RW;
23188 +#endif
23189
23190 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
23191 /*
23192 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23193 }
23194 #endif
23195
23196 +#ifdef CONFIG_PAX_KERNEXEC
23197 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
23198 + pgprot_val(forbidden) |= _PAGE_RW;
23199 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23200 + }
23201 +#endif
23202 +
23203 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
23204
23205 return prot;
23206 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
23207 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
23208 {
23209 /* change init_mm */
23210 + pax_open_kernel();
23211 set_pte_atomic(kpte, pte);
23212 +
23213 #ifdef CONFIG_X86_32
23214 if (!SHARED_KERNEL_PMD) {
23215 +
23216 +#ifdef CONFIG_PAX_PER_CPU_PGD
23217 + unsigned long cpu;
23218 +#else
23219 struct page *page;
23220 +#endif
23221
23222 +#ifdef CONFIG_PAX_PER_CPU_PGD
23223 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23224 + pgd_t *pgd = get_cpu_pgd(cpu);
23225 +#else
23226 list_for_each_entry(page, &pgd_list, lru) {
23227 - pgd_t *pgd;
23228 + pgd_t *pgd = (pgd_t *)page_address(page);
23229 +#endif
23230 +
23231 pud_t *pud;
23232 pmd_t *pmd;
23233
23234 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
23235 + pgd += pgd_index(address);
23236 pud = pud_offset(pgd, address);
23237 pmd = pmd_offset(pud, address);
23238 set_pte_atomic((pte_t *)pmd, pte);
23239 }
23240 }
23241 #endif
23242 + pax_close_kernel();
23243 }
23244
23245 static int
23246 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
23247 index f6ff57b..481690f 100644
23248 --- a/arch/x86/mm/pat.c
23249 +++ b/arch/x86/mm/pat.c
23250 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
23251
23252 if (!entry) {
23253 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
23254 - current->comm, current->pid, start, end);
23255 + current->comm, task_pid_nr(current), start, end);
23256 return -EINVAL;
23257 }
23258
23259 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
23260 while (cursor < to) {
23261 if (!devmem_is_allowed(pfn)) {
23262 printk(KERN_INFO
23263 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
23264 - current->comm, from, to);
23265 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
23266 + current->comm, from, to, cursor);
23267 return 0;
23268 }
23269 cursor += PAGE_SIZE;
23270 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
23271 printk(KERN_INFO
23272 "%s:%d ioremap_change_attr failed %s "
23273 "for %Lx-%Lx\n",
23274 - current->comm, current->pid,
23275 + current->comm, task_pid_nr(current),
23276 cattr_name(flags),
23277 base, (unsigned long long)(base + size));
23278 return -EINVAL;
23279 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
23280 if (want_flags != flags) {
23281 printk(KERN_WARNING
23282 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
23283 - current->comm, current->pid,
23284 + current->comm, task_pid_nr(current),
23285 cattr_name(want_flags),
23286 (unsigned long long)paddr,
23287 (unsigned long long)(paddr + size),
23288 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
23289 free_memtype(paddr, paddr + size);
23290 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
23291 " for %Lx-%Lx, got %s\n",
23292 - current->comm, current->pid,
23293 + current->comm, task_pid_nr(current),
23294 cattr_name(want_flags),
23295 (unsigned long long)paddr,
23296 (unsigned long long)(paddr + size),
23297 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
23298 index 9f0614d..92ae64a 100644
23299 --- a/arch/x86/mm/pf_in.c
23300 +++ b/arch/x86/mm/pf_in.c
23301 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
23302 int i;
23303 enum reason_type rv = OTHERS;
23304
23305 - p = (unsigned char *)ins_addr;
23306 + p = (unsigned char *)ktla_ktva(ins_addr);
23307 p += skip_prefix(p, &prf);
23308 p += get_opcode(p, &opcode);
23309
23310 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
23311 struct prefix_bits prf;
23312 int i;
23313
23314 - p = (unsigned char *)ins_addr;
23315 + p = (unsigned char *)ktla_ktva(ins_addr);
23316 p += skip_prefix(p, &prf);
23317 p += get_opcode(p, &opcode);
23318
23319 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
23320 struct prefix_bits prf;
23321 int i;
23322
23323 - p = (unsigned char *)ins_addr;
23324 + p = (unsigned char *)ktla_ktva(ins_addr);
23325 p += skip_prefix(p, &prf);
23326 p += get_opcode(p, &opcode);
23327
23328 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
23329 struct prefix_bits prf;
23330 int i;
23331
23332 - p = (unsigned char *)ins_addr;
23333 + p = (unsigned char *)ktla_ktva(ins_addr);
23334 p += skip_prefix(p, &prf);
23335 p += get_opcode(p, &opcode);
23336 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
23337 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
23338 struct prefix_bits prf;
23339 int i;
23340
23341 - p = (unsigned char *)ins_addr;
23342 + p = (unsigned char *)ktla_ktva(ins_addr);
23343 p += skip_prefix(p, &prf);
23344 p += get_opcode(p, &opcode);
23345 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
23346 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
23347 index 8573b83..c3b1a30 100644
23348 --- a/arch/x86/mm/pgtable.c
23349 +++ b/arch/x86/mm/pgtable.c
23350 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *pgd)
23351 list_del(&page->lru);
23352 }
23353
23354 -#define UNSHARED_PTRS_PER_PGD \
23355 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23356 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23357 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
23358
23359 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23360 +{
23361 + while (count--)
23362 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
23363 +}
23364 +#endif
23365
23366 +#ifdef CONFIG_PAX_PER_CPU_PGD
23367 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23368 +{
23369 + while (count--)
23370 +
23371 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23372 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
23373 +#else
23374 + *dst++ = *src++;
23375 +#endif
23376 +
23377 +}
23378 +#endif
23379 +
23380 +#ifdef CONFIG_X86_64
23381 +#define pxd_t pud_t
23382 +#define pyd_t pgd_t
23383 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
23384 +#define pxd_free(mm, pud) pud_free((mm), (pud))
23385 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
23386 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
23387 +#define PYD_SIZE PGDIR_SIZE
23388 +#else
23389 +#define pxd_t pmd_t
23390 +#define pyd_t pud_t
23391 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
23392 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
23393 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
23394 +#define pyd_offset(mm, address) pud_offset((mm), (address))
23395 +#define PYD_SIZE PUD_SIZE
23396 +#endif
23397 +
23398 +#ifdef CONFIG_PAX_PER_CPU_PGD
23399 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
23400 +static inline void pgd_dtor(pgd_t *pgd) {}
23401 +#else
23402 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
23403 {
23404 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
23405 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
23406 pgd_list_del(pgd);
23407 spin_unlock(&pgd_lock);
23408 }
23409 +#endif
23410
23411 /*
23412 * List of all pgd's needed for non-PAE so it can invalidate entries
23413 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
23414 * -- wli
23415 */
23416
23417 -#ifdef CONFIG_X86_PAE
23418 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
23419 /*
23420 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
23421 * updating the top-level pagetable entries to guarantee the
23422 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
23423 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
23424 * and initialize the kernel pmds here.
23425 */
23426 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
23427 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23428
23429 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23430 {
23431 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23432 */
23433 flush_tlb_mm(mm);
23434 }
23435 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
23436 +#define PREALLOCATED_PXDS USER_PGD_PTRS
23437 #else /* !CONFIG_X86_PAE */
23438
23439 /* No need to prepopulate any pagetable entries in non-PAE modes. */
23440 -#define PREALLOCATED_PMDS 0
23441 +#define PREALLOCATED_PXDS 0
23442
23443 #endif /* CONFIG_X86_PAE */
23444
23445 -static void free_pmds(pmd_t *pmds[])
23446 +static void free_pxds(pxd_t *pxds[])
23447 {
23448 int i;
23449
23450 - for(i = 0; i < PREALLOCATED_PMDS; i++)
23451 - if (pmds[i])
23452 - free_page((unsigned long)pmds[i]);
23453 + for(i = 0; i < PREALLOCATED_PXDS; i++)
23454 + if (pxds[i])
23455 + free_page((unsigned long)pxds[i]);
23456 }
23457
23458 -static int preallocate_pmds(pmd_t *pmds[])
23459 +static int preallocate_pxds(pxd_t *pxds[])
23460 {
23461 int i;
23462 bool failed = false;
23463
23464 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
23465 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
23466 - if (pmd == NULL)
23467 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
23468 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
23469 + if (pxd == NULL)
23470 failed = true;
23471 - pmds[i] = pmd;
23472 + pxds[i] = pxd;
23473 }
23474
23475 if (failed) {
23476 - free_pmds(pmds);
23477 + free_pxds(pxds);
23478 return -ENOMEM;
23479 }
23480
23481 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[])
23482 * preallocate which never got a corresponding vma will need to be
23483 * freed manually.
23484 */
23485 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
23486 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
23487 {
23488 int i;
23489
23490 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
23491 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
23492 pgd_t pgd = pgdp[i];
23493
23494 if (pgd_val(pgd) != 0) {
23495 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
23496 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
23497
23498 - pgdp[i] = native_make_pgd(0);
23499 + set_pgd(pgdp + i, native_make_pgd(0));
23500
23501 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
23502 - pmd_free(mm, pmd);
23503 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
23504 + pxd_free(mm, pxd);
23505 }
23506 }
23507 }
23508
23509 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
23510 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
23511 {
23512 - pud_t *pud;
23513 + pyd_t *pyd;
23514 unsigned long addr;
23515 int i;
23516
23517 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
23518 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
23519 return;
23520
23521 - pud = pud_offset(pgd, 0);
23522 +#ifdef CONFIG_X86_64
23523 + pyd = pyd_offset(mm, 0L);
23524 +#else
23525 + pyd = pyd_offset(pgd, 0L);
23526 +#endif
23527
23528 - for (addr = i = 0; i < PREALLOCATED_PMDS;
23529 - i++, pud++, addr += PUD_SIZE) {
23530 - pmd_t *pmd = pmds[i];
23531 + for (addr = i = 0; i < PREALLOCATED_PXDS;
23532 + i++, pyd++, addr += PYD_SIZE) {
23533 + pxd_t *pxd = pxds[i];
23534
23535 if (i >= KERNEL_PGD_BOUNDARY)
23536 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23537 - sizeof(pmd_t) * PTRS_PER_PMD);
23538 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23539 + sizeof(pxd_t) * PTRS_PER_PMD);
23540
23541 - pud_populate(mm, pud, pmd);
23542 + pyd_populate(mm, pyd, pxd);
23543 }
23544 }
23545
23546 pgd_t *pgd_alloc(struct mm_struct *mm)
23547 {
23548 pgd_t *pgd;
23549 - pmd_t *pmds[PREALLOCATED_PMDS];
23550 + pxd_t *pxds[PREALLOCATED_PXDS];
23551
23552 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
23553
23554 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23555
23556 mm->pgd = pgd;
23557
23558 - if (preallocate_pmds(pmds) != 0)
23559 + if (preallocate_pxds(pxds) != 0)
23560 goto out_free_pgd;
23561
23562 if (paravirt_pgd_alloc(mm) != 0)
23563 - goto out_free_pmds;
23564 + goto out_free_pxds;
23565
23566 /*
23567 * Make sure that pre-populating the pmds is atomic with
23568 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23569 spin_lock(&pgd_lock);
23570
23571 pgd_ctor(mm, pgd);
23572 - pgd_prepopulate_pmd(mm, pgd, pmds);
23573 + pgd_prepopulate_pxd(mm, pgd, pxds);
23574
23575 spin_unlock(&pgd_lock);
23576
23577 return pgd;
23578
23579 -out_free_pmds:
23580 - free_pmds(pmds);
23581 +out_free_pxds:
23582 + free_pxds(pxds);
23583 out_free_pgd:
23584 free_page((unsigned long)pgd);
23585 out:
23586 @@ -295,7 +344,7 @@ out:
23587
23588 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
23589 {
23590 - pgd_mop_up_pmds(mm, pgd);
23591 + pgd_mop_up_pxds(mm, pgd);
23592 pgd_dtor(pgd);
23593 paravirt_pgd_free(mm, pgd);
23594 free_page((unsigned long)pgd);
23595 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
23596 index cac7184..09a39fa 100644
23597 --- a/arch/x86/mm/pgtable_32.c
23598 +++ b/arch/x86/mm/pgtable_32.c
23599 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
23600 return;
23601 }
23602 pte = pte_offset_kernel(pmd, vaddr);
23603 +
23604 + pax_open_kernel();
23605 if (pte_val(pteval))
23606 set_pte_at(&init_mm, vaddr, pte, pteval);
23607 else
23608 pte_clear(&init_mm, vaddr, pte);
23609 + pax_close_kernel();
23610
23611 /*
23612 * It's enough to flush this one mapping.
23613 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
23614 index 410531d..0f16030 100644
23615 --- a/arch/x86/mm/setup_nx.c
23616 +++ b/arch/x86/mm/setup_nx.c
23617 @@ -5,8 +5,10 @@
23618 #include <asm/pgtable.h>
23619 #include <asm/proto.h>
23620
23621 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23622 static int disable_nx __cpuinitdata;
23623
23624 +#ifndef CONFIG_PAX_PAGEEXEC
23625 /*
23626 * noexec = on|off
23627 *
23628 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
23629 return 0;
23630 }
23631 early_param("noexec", noexec_setup);
23632 +#endif
23633 +
23634 +#endif
23635
23636 void __cpuinit x86_configure_nx(void)
23637 {
23638 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23639 if (cpu_has_nx && !disable_nx)
23640 __supported_pte_mask |= _PAGE_NX;
23641 else
23642 +#endif
23643 __supported_pte_mask &= ~_PAGE_NX;
23644 }
23645
23646 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
23647 index d6c0418..06a0ad5 100644
23648 --- a/arch/x86/mm/tlb.c
23649 +++ b/arch/x86/mm/tlb.c
23650 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
23651 BUG();
23652 cpumask_clear_cpu(cpu,
23653 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
23654 +
23655 +#ifndef CONFIG_PAX_PER_CPU_PGD
23656 load_cr3(swapper_pg_dir);
23657 +#endif
23658 +
23659 }
23660 EXPORT_SYMBOL_GPL(leave_mm);
23661
23662 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
23663 index 6687022..ceabcfa 100644
23664 --- a/arch/x86/net/bpf_jit.S
23665 +++ b/arch/x86/net/bpf_jit.S
23666 @@ -9,6 +9,7 @@
23667 */
23668 #include <linux/linkage.h>
23669 #include <asm/dwarf2.h>
23670 +#include <asm/alternative-asm.h>
23671
23672 /*
23673 * Calling convention :
23674 @@ -35,6 +36,7 @@ sk_load_word:
23675 jle bpf_slow_path_word
23676 mov (SKBDATA,%rsi),%eax
23677 bswap %eax /* ntohl() */
23678 + pax_force_retaddr
23679 ret
23680
23681
23682 @@ -53,6 +55,7 @@ sk_load_half:
23683 jle bpf_slow_path_half
23684 movzwl (SKBDATA,%rsi),%eax
23685 rol $8,%ax # ntohs()
23686 + pax_force_retaddr
23687 ret
23688
23689 sk_load_byte_ind:
23690 @@ -66,6 +69,7 @@ sk_load_byte:
23691 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
23692 jle bpf_slow_path_byte
23693 movzbl (SKBDATA,%rsi),%eax
23694 + pax_force_retaddr
23695 ret
23696
23697 /**
23698 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
23699 movzbl (SKBDATA,%rsi),%ebx
23700 and $15,%bl
23701 shl $2,%bl
23702 + pax_force_retaddr
23703 ret
23704 CFI_ENDPROC
23705 ENDPROC(sk_load_byte_msh)
23706 @@ -91,6 +96,7 @@ bpf_error:
23707 xor %eax,%eax
23708 mov -8(%rbp),%rbx
23709 leaveq
23710 + pax_force_retaddr
23711 ret
23712
23713 /* rsi contains offset and can be scratched */
23714 @@ -113,6 +119,7 @@ bpf_slow_path_word:
23715 js bpf_error
23716 mov -12(%rbp),%eax
23717 bswap %eax
23718 + pax_force_retaddr
23719 ret
23720
23721 bpf_slow_path_half:
23722 @@ -121,12 +128,14 @@ bpf_slow_path_half:
23723 mov -12(%rbp),%ax
23724 rol $8,%ax
23725 movzwl %ax,%eax
23726 + pax_force_retaddr
23727 ret
23728
23729 bpf_slow_path_byte:
23730 bpf_slow_path_common(1)
23731 js bpf_error
23732 movzbl -12(%rbp),%eax
23733 + pax_force_retaddr
23734 ret
23735
23736 bpf_slow_path_byte_msh:
23737 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
23738 and $15,%al
23739 shl $2,%al
23740 xchg %eax,%ebx
23741 + pax_force_retaddr
23742 ret
23743 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
23744 index 7c1b765..8c072c6 100644
23745 --- a/arch/x86/net/bpf_jit_comp.c
23746 +++ b/arch/x86/net/bpf_jit_comp.c
23747 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
23748 set_fs(old_fs);
23749 }
23750
23751 +struct bpf_jit_work {
23752 + struct work_struct work;
23753 + void *image;
23754 +};
23755
23756 void bpf_jit_compile(struct sk_filter *fp)
23757 {
23758 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
23759 if (addrs == NULL)
23760 return;
23761
23762 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
23763 + if (!fp->work)
23764 + goto out;
23765 +
23766 /* Before first pass, make a rough estimation of addrs[]
23767 * each bpf instruction is translated to less than 64 bytes
23768 */
23769 @@ -476,7 +484,7 @@ void bpf_jit_compile(struct sk_filter *fp)
23770 func = sk_load_word;
23771 common_load: seen |= SEEN_DATAREF;
23772 if ((int)K < 0)
23773 - goto out;
23774 + goto error;
23775 t_offset = func - (image + addrs[i]);
23776 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
23777 EMIT1_off32(0xe8, t_offset); /* call */
23778 @@ -586,17 +594,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23779 break;
23780 default:
23781 /* hmm, too complex filter, give up with jit compiler */
23782 - goto out;
23783 + goto error;
23784 }
23785 ilen = prog - temp;
23786 if (image) {
23787 if (unlikely(proglen + ilen > oldproglen)) {
23788 pr_err("bpb_jit_compile fatal error\n");
23789 - kfree(addrs);
23790 - module_free(NULL, image);
23791 - return;
23792 + module_free_exec(NULL, image);
23793 + goto error;
23794 }
23795 + pax_open_kernel();
23796 memcpy(image + proglen, temp, ilen);
23797 + pax_close_kernel();
23798 }
23799 proglen += ilen;
23800 addrs[i] = proglen;
23801 @@ -617,11 +626,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23802 break;
23803 }
23804 if (proglen == oldproglen) {
23805 - image = module_alloc(max_t(unsigned int,
23806 - proglen,
23807 - sizeof(struct work_struct)));
23808 + image = module_alloc_exec(proglen);
23809 if (!image)
23810 - goto out;
23811 + goto error;
23812 }
23813 oldproglen = proglen;
23814 }
23815 @@ -637,7 +644,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23816 bpf_flush_icache(image, image + proglen);
23817
23818 fp->bpf_func = (void *)image;
23819 - }
23820 + } else
23821 +error:
23822 + kfree(fp->work);
23823 +
23824 out:
23825 kfree(addrs);
23826 return;
23827 @@ -645,18 +655,20 @@ out:
23828
23829 static void jit_free_defer(struct work_struct *arg)
23830 {
23831 - module_free(NULL, arg);
23832 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
23833 + kfree(arg);
23834 }
23835
23836 /* run from softirq, we must use a work_struct to call
23837 - * module_free() from process context
23838 + * module_free_exec() from process context
23839 */
23840 void bpf_jit_free(struct sk_filter *fp)
23841 {
23842 if (fp->bpf_func != sk_run_filter) {
23843 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
23844 + struct work_struct *work = &fp->work->work;
23845
23846 INIT_WORK(work, jit_free_defer);
23847 + fp->work->image = fp->bpf_func;
23848 schedule_work(work);
23849 }
23850 }
23851 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
23852 index bff89df..377758a 100644
23853 --- a/arch/x86/oprofile/backtrace.c
23854 +++ b/arch/x86/oprofile/backtrace.c
23855 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
23856 struct stack_frame_ia32 *fp;
23857 unsigned long bytes;
23858
23859 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
23860 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
23861 if (bytes != sizeof(bufhead))
23862 return NULL;
23863
23864 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
23865 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
23866
23867 oprofile_add_trace(bufhead[0].return_address);
23868
23869 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
23870 struct stack_frame bufhead[2];
23871 unsigned long bytes;
23872
23873 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
23874 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
23875 if (bytes != sizeof(bufhead))
23876 return NULL;
23877
23878 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
23879 {
23880 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
23881
23882 - if (!user_mode_vm(regs)) {
23883 + if (!user_mode(regs)) {
23884 unsigned long stack = kernel_stack_pointer(regs);
23885 if (depth)
23886 dump_trace(NULL, regs, (unsigned long *)stack, 0,
23887 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
23888 index cb29191..036766d 100644
23889 --- a/arch/x86/pci/mrst.c
23890 +++ b/arch/x86/pci/mrst.c
23891 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
23892 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
23893 pci_mmcfg_late_init();
23894 pcibios_enable_irq = mrst_pci_irq_enable;
23895 - pci_root_ops = pci_mrst_ops;
23896 + pax_open_kernel();
23897 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
23898 + pax_close_kernel();
23899 /* Continue with standard init */
23900 return 1;
23901 }
23902 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
23903 index db0e9a5..0372c14 100644
23904 --- a/arch/x86/pci/pcbios.c
23905 +++ b/arch/x86/pci/pcbios.c
23906 @@ -79,50 +79,93 @@ union bios32 {
23907 static struct {
23908 unsigned long address;
23909 unsigned short segment;
23910 -} bios32_indirect = { 0, __KERNEL_CS };
23911 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
23912
23913 /*
23914 * Returns the entry point for the given service, NULL on error
23915 */
23916
23917 -static unsigned long bios32_service(unsigned long service)
23918 +static unsigned long __devinit bios32_service(unsigned long service)
23919 {
23920 unsigned char return_code; /* %al */
23921 unsigned long address; /* %ebx */
23922 unsigned long length; /* %ecx */
23923 unsigned long entry; /* %edx */
23924 unsigned long flags;
23925 + struct desc_struct d, *gdt;
23926
23927 local_irq_save(flags);
23928 - __asm__("lcall *(%%edi); cld"
23929 +
23930 + gdt = get_cpu_gdt_table(smp_processor_id());
23931 +
23932 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
23933 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23934 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
23935 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23936 +
23937 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
23938 : "=a" (return_code),
23939 "=b" (address),
23940 "=c" (length),
23941 "=d" (entry)
23942 : "0" (service),
23943 "1" (0),
23944 - "D" (&bios32_indirect));
23945 + "D" (&bios32_indirect),
23946 + "r"(__PCIBIOS_DS)
23947 + : "memory");
23948 +
23949 + pax_open_kernel();
23950 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
23951 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
23952 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
23953 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
23954 + pax_close_kernel();
23955 +
23956 local_irq_restore(flags);
23957
23958 switch (return_code) {
23959 - case 0:
23960 - return address + entry;
23961 - case 0x80: /* Not present */
23962 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23963 - return 0;
23964 - default: /* Shouldn't happen */
23965 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23966 - service, return_code);
23967 + case 0: {
23968 + int cpu;
23969 + unsigned char flags;
23970 +
23971 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
23972 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
23973 + printk(KERN_WARNING "bios32_service: not valid\n");
23974 return 0;
23975 + }
23976 + address = address + PAGE_OFFSET;
23977 + length += 16UL; /* some BIOSs underreport this... */
23978 + flags = 4;
23979 + if (length >= 64*1024*1024) {
23980 + length >>= PAGE_SHIFT;
23981 + flags |= 8;
23982 + }
23983 +
23984 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
23985 + gdt = get_cpu_gdt_table(cpu);
23986 + pack_descriptor(&d, address, length, 0x9b, flags);
23987 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23988 + pack_descriptor(&d, address, length, 0x93, flags);
23989 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23990 + }
23991 + return entry;
23992 + }
23993 + case 0x80: /* Not present */
23994 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23995 + return 0;
23996 + default: /* Shouldn't happen */
23997 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23998 + service, return_code);
23999 + return 0;
24000 }
24001 }
24002
24003 static struct {
24004 unsigned long address;
24005 unsigned short segment;
24006 -} pci_indirect = { 0, __KERNEL_CS };
24007 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
24008
24009 -static int pci_bios_present;
24010 +static int pci_bios_present __read_only;
24011
24012 static int __devinit check_pcibios(void)
24013 {
24014 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
24015 unsigned long flags, pcibios_entry;
24016
24017 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
24018 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
24019 + pci_indirect.address = pcibios_entry;
24020
24021 local_irq_save(flags);
24022 - __asm__(
24023 - "lcall *(%%edi); cld\n\t"
24024 + __asm__("movw %w6, %%ds\n\t"
24025 + "lcall *%%ss:(%%edi); cld\n\t"
24026 + "push %%ss\n\t"
24027 + "pop %%ds\n\t"
24028 "jc 1f\n\t"
24029 "xor %%ah, %%ah\n"
24030 "1:"
24031 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
24032 "=b" (ebx),
24033 "=c" (ecx)
24034 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
24035 - "D" (&pci_indirect)
24036 + "D" (&pci_indirect),
24037 + "r" (__PCIBIOS_DS)
24038 : "memory");
24039 local_irq_restore(flags);
24040
24041 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24042
24043 switch (len) {
24044 case 1:
24045 - __asm__("lcall *(%%esi); cld\n\t"
24046 + __asm__("movw %w6, %%ds\n\t"
24047 + "lcall *%%ss:(%%esi); cld\n\t"
24048 + "push %%ss\n\t"
24049 + "pop %%ds\n\t"
24050 "jc 1f\n\t"
24051 "xor %%ah, %%ah\n"
24052 "1:"
24053 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24054 : "1" (PCIBIOS_READ_CONFIG_BYTE),
24055 "b" (bx),
24056 "D" ((long)reg),
24057 - "S" (&pci_indirect));
24058 + "S" (&pci_indirect),
24059 + "r" (__PCIBIOS_DS));
24060 /*
24061 * Zero-extend the result beyond 8 bits, do not trust the
24062 * BIOS having done it:
24063 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24064 *value &= 0xff;
24065 break;
24066 case 2:
24067 - __asm__("lcall *(%%esi); cld\n\t"
24068 + __asm__("movw %w6, %%ds\n\t"
24069 + "lcall *%%ss:(%%esi); cld\n\t"
24070 + "push %%ss\n\t"
24071 + "pop %%ds\n\t"
24072 "jc 1f\n\t"
24073 "xor %%ah, %%ah\n"
24074 "1:"
24075 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24076 : "1" (PCIBIOS_READ_CONFIG_WORD),
24077 "b" (bx),
24078 "D" ((long)reg),
24079 - "S" (&pci_indirect));
24080 + "S" (&pci_indirect),
24081 + "r" (__PCIBIOS_DS));
24082 /*
24083 * Zero-extend the result beyond 16 bits, do not trust the
24084 * BIOS having done it:
24085 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24086 *value &= 0xffff;
24087 break;
24088 case 4:
24089 - __asm__("lcall *(%%esi); cld\n\t"
24090 + __asm__("movw %w6, %%ds\n\t"
24091 + "lcall *%%ss:(%%esi); cld\n\t"
24092 + "push %%ss\n\t"
24093 + "pop %%ds\n\t"
24094 "jc 1f\n\t"
24095 "xor %%ah, %%ah\n"
24096 "1:"
24097 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24098 : "1" (PCIBIOS_READ_CONFIG_DWORD),
24099 "b" (bx),
24100 "D" ((long)reg),
24101 - "S" (&pci_indirect));
24102 + "S" (&pci_indirect),
24103 + "r" (__PCIBIOS_DS));
24104 break;
24105 }
24106
24107 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24108
24109 switch (len) {
24110 case 1:
24111 - __asm__("lcall *(%%esi); cld\n\t"
24112 + __asm__("movw %w6, %%ds\n\t"
24113 + "lcall *%%ss:(%%esi); cld\n\t"
24114 + "push %%ss\n\t"
24115 + "pop %%ds\n\t"
24116 "jc 1f\n\t"
24117 "xor %%ah, %%ah\n"
24118 "1:"
24119 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24120 "c" (value),
24121 "b" (bx),
24122 "D" ((long)reg),
24123 - "S" (&pci_indirect));
24124 + "S" (&pci_indirect),
24125 + "r" (__PCIBIOS_DS));
24126 break;
24127 case 2:
24128 - __asm__("lcall *(%%esi); cld\n\t"
24129 + __asm__("movw %w6, %%ds\n\t"
24130 + "lcall *%%ss:(%%esi); cld\n\t"
24131 + "push %%ss\n\t"
24132 + "pop %%ds\n\t"
24133 "jc 1f\n\t"
24134 "xor %%ah, %%ah\n"
24135 "1:"
24136 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24137 "c" (value),
24138 "b" (bx),
24139 "D" ((long)reg),
24140 - "S" (&pci_indirect));
24141 + "S" (&pci_indirect),
24142 + "r" (__PCIBIOS_DS));
24143 break;
24144 case 4:
24145 - __asm__("lcall *(%%esi); cld\n\t"
24146 + __asm__("movw %w6, %%ds\n\t"
24147 + "lcall *%%ss:(%%esi); cld\n\t"
24148 + "push %%ss\n\t"
24149 + "pop %%ds\n\t"
24150 "jc 1f\n\t"
24151 "xor %%ah, %%ah\n"
24152 "1:"
24153 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24154 "c" (value),
24155 "b" (bx),
24156 "D" ((long)reg),
24157 - "S" (&pci_indirect));
24158 + "S" (&pci_indirect),
24159 + "r" (__PCIBIOS_DS));
24160 break;
24161 }
24162
24163 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
24164
24165 DBG("PCI: Fetching IRQ routing table... ");
24166 __asm__("push %%es\n\t"
24167 + "movw %w8, %%ds\n\t"
24168 "push %%ds\n\t"
24169 "pop %%es\n\t"
24170 - "lcall *(%%esi); cld\n\t"
24171 + "lcall *%%ss:(%%esi); cld\n\t"
24172 "pop %%es\n\t"
24173 + "push %%ss\n\t"
24174 + "pop %%ds\n"
24175 "jc 1f\n\t"
24176 "xor %%ah, %%ah\n"
24177 "1:"
24178 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
24179 "1" (0),
24180 "D" ((long) &opt),
24181 "S" (&pci_indirect),
24182 - "m" (opt)
24183 + "m" (opt),
24184 + "r" (__PCIBIOS_DS)
24185 : "memory");
24186 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
24187 if (ret & 0xff00)
24188 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
24189 {
24190 int ret;
24191
24192 - __asm__("lcall *(%%esi); cld\n\t"
24193 + __asm__("movw %w5, %%ds\n\t"
24194 + "lcall *%%ss:(%%esi); cld\n\t"
24195 + "push %%ss\n\t"
24196 + "pop %%ds\n"
24197 "jc 1f\n\t"
24198 "xor %%ah, %%ah\n"
24199 "1:"
24200 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
24201 : "0" (PCIBIOS_SET_PCI_HW_INT),
24202 "b" ((dev->bus->number << 8) | dev->devfn),
24203 "c" ((irq << 8) | (pin + 10)),
24204 - "S" (&pci_indirect));
24205 + "S" (&pci_indirect),
24206 + "r" (__PCIBIOS_DS));
24207 return !(ret & 0xff00);
24208 }
24209 EXPORT_SYMBOL(pcibios_set_irq_routing);
24210 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
24211 index 40e4469..1ab536e 100644
24212 --- a/arch/x86/platform/efi/efi_32.c
24213 +++ b/arch/x86/platform/efi/efi_32.c
24214 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
24215 {
24216 struct desc_ptr gdt_descr;
24217
24218 +#ifdef CONFIG_PAX_KERNEXEC
24219 + struct desc_struct d;
24220 +#endif
24221 +
24222 local_irq_save(efi_rt_eflags);
24223
24224 load_cr3(initial_page_table);
24225 __flush_tlb_all();
24226
24227 +#ifdef CONFIG_PAX_KERNEXEC
24228 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
24229 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
24230 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
24231 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
24232 +#endif
24233 +
24234 gdt_descr.address = __pa(get_cpu_gdt_table(0));
24235 gdt_descr.size = GDT_SIZE - 1;
24236 load_gdt(&gdt_descr);
24237 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
24238 {
24239 struct desc_ptr gdt_descr;
24240
24241 +#ifdef CONFIG_PAX_KERNEXEC
24242 + struct desc_struct d;
24243 +
24244 + memset(&d, 0, sizeof d);
24245 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
24246 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
24247 +#endif
24248 +
24249 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
24250 gdt_descr.size = GDT_SIZE - 1;
24251 load_gdt(&gdt_descr);
24252 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
24253 index fbe66e6..c5c0dd2 100644
24254 --- a/arch/x86/platform/efi/efi_stub_32.S
24255 +++ b/arch/x86/platform/efi/efi_stub_32.S
24256 @@ -6,7 +6,9 @@
24257 */
24258
24259 #include <linux/linkage.h>
24260 +#include <linux/init.h>
24261 #include <asm/page_types.h>
24262 +#include <asm/segment.h>
24263
24264 /*
24265 * efi_call_phys(void *, ...) is a function with variable parameters.
24266 @@ -20,7 +22,7 @@
24267 * service functions will comply with gcc calling convention, too.
24268 */
24269
24270 -.text
24271 +__INIT
24272 ENTRY(efi_call_phys)
24273 /*
24274 * 0. The function can only be called in Linux kernel. So CS has been
24275 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
24276 * The mapping of lower virtual memory has been created in prelog and
24277 * epilog.
24278 */
24279 - movl $1f, %edx
24280 - subl $__PAGE_OFFSET, %edx
24281 - jmp *%edx
24282 + movl $(__KERNEXEC_EFI_DS), %edx
24283 + mov %edx, %ds
24284 + mov %edx, %es
24285 + mov %edx, %ss
24286 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
24287 1:
24288
24289 /*
24290 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
24291 * parameter 2, ..., param n. To make things easy, we save the return
24292 * address of efi_call_phys in a global variable.
24293 */
24294 - popl %edx
24295 - movl %edx, saved_return_addr
24296 - /* get the function pointer into ECX*/
24297 - popl %ecx
24298 - movl %ecx, efi_rt_function_ptr
24299 - movl $2f, %edx
24300 - subl $__PAGE_OFFSET, %edx
24301 - pushl %edx
24302 + popl (saved_return_addr)
24303 + popl (efi_rt_function_ptr)
24304
24305 /*
24306 * 3. Clear PG bit in %CR0.
24307 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
24308 /*
24309 * 5. Call the physical function.
24310 */
24311 - jmp *%ecx
24312 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
24313
24314 -2:
24315 /*
24316 * 6. After EFI runtime service returns, control will return to
24317 * following instruction. We'd better readjust stack pointer first.
24318 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
24319 movl %cr0, %edx
24320 orl $0x80000000, %edx
24321 movl %edx, %cr0
24322 - jmp 1f
24323 -1:
24324 +
24325 /*
24326 * 8. Now restore the virtual mode from flat mode by
24327 * adding EIP with PAGE_OFFSET.
24328 */
24329 - movl $1f, %edx
24330 - jmp *%edx
24331 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
24332 1:
24333 + movl $(__KERNEL_DS), %edx
24334 + mov %edx, %ds
24335 + mov %edx, %es
24336 + mov %edx, %ss
24337
24338 /*
24339 * 9. Balance the stack. And because EAX contain the return value,
24340 * we'd better not clobber it.
24341 */
24342 - leal efi_rt_function_ptr, %edx
24343 - movl (%edx), %ecx
24344 - pushl %ecx
24345 + pushl (efi_rt_function_ptr)
24346
24347 /*
24348 - * 10. Push the saved return address onto the stack and return.
24349 + * 10. Return to the saved return address.
24350 */
24351 - leal saved_return_addr, %edx
24352 - movl (%edx), %ecx
24353 - pushl %ecx
24354 - ret
24355 + jmpl *(saved_return_addr)
24356 ENDPROC(efi_call_phys)
24357 .previous
24358
24359 -.data
24360 +__INITDATA
24361 saved_return_addr:
24362 .long 0
24363 efi_rt_function_ptr:
24364 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
24365 index 4c07cca..2c8427d 100644
24366 --- a/arch/x86/platform/efi/efi_stub_64.S
24367 +++ b/arch/x86/platform/efi/efi_stub_64.S
24368 @@ -7,6 +7,7 @@
24369 */
24370
24371 #include <linux/linkage.h>
24372 +#include <asm/alternative-asm.h>
24373
24374 #define SAVE_XMM \
24375 mov %rsp, %rax; \
24376 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
24377 call *%rdi
24378 addq $32, %rsp
24379 RESTORE_XMM
24380 + pax_force_retaddr 0, 1
24381 ret
24382 ENDPROC(efi_call0)
24383
24384 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
24385 call *%rdi
24386 addq $32, %rsp
24387 RESTORE_XMM
24388 + pax_force_retaddr 0, 1
24389 ret
24390 ENDPROC(efi_call1)
24391
24392 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
24393 call *%rdi
24394 addq $32, %rsp
24395 RESTORE_XMM
24396 + pax_force_retaddr 0, 1
24397 ret
24398 ENDPROC(efi_call2)
24399
24400 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
24401 call *%rdi
24402 addq $32, %rsp
24403 RESTORE_XMM
24404 + pax_force_retaddr 0, 1
24405 ret
24406 ENDPROC(efi_call3)
24407
24408 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
24409 call *%rdi
24410 addq $32, %rsp
24411 RESTORE_XMM
24412 + pax_force_retaddr 0, 1
24413 ret
24414 ENDPROC(efi_call4)
24415
24416 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
24417 call *%rdi
24418 addq $48, %rsp
24419 RESTORE_XMM
24420 + pax_force_retaddr 0, 1
24421 ret
24422 ENDPROC(efi_call5)
24423
24424 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
24425 call *%rdi
24426 addq $48, %rsp
24427 RESTORE_XMM
24428 + pax_force_retaddr 0, 1
24429 ret
24430 ENDPROC(efi_call6)
24431 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
24432 index ad4ec1c..686479e 100644
24433 --- a/arch/x86/platform/mrst/mrst.c
24434 +++ b/arch/x86/platform/mrst/mrst.c
24435 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
24436 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
24437 int sfi_mrtc_num;
24438
24439 -static void mrst_power_off(void)
24440 +static __noreturn void mrst_power_off(void)
24441 {
24442 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
24443 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
24444 + BUG();
24445 }
24446
24447 -static void mrst_reboot(void)
24448 +static __noreturn void mrst_reboot(void)
24449 {
24450 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
24451 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
24452 else
24453 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
24454 + BUG();
24455 }
24456
24457 /* parse all the mtimer info to a static mtimer array */
24458 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
24459 index f10c0af..3ec1f95 100644
24460 --- a/arch/x86/power/cpu.c
24461 +++ b/arch/x86/power/cpu.c
24462 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
24463 static void fix_processor_context(void)
24464 {
24465 int cpu = smp_processor_id();
24466 - struct tss_struct *t = &per_cpu(init_tss, cpu);
24467 + struct tss_struct *t = init_tss + cpu;
24468
24469 set_tss_desc(cpu, t); /*
24470 * This just modifies memory; should not be
24471 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
24472 */
24473
24474 #ifdef CONFIG_X86_64
24475 + pax_open_kernel();
24476 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
24477 + pax_close_kernel();
24478
24479 syscall_init(); /* This sets MSR_*STAR and related */
24480 #endif
24481 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
24482 index 5d17950..2253fc9 100644
24483 --- a/arch/x86/vdso/Makefile
24484 +++ b/arch/x86/vdso/Makefile
24485 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
24486 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
24487 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
24488
24489 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24490 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24491 GCOV_PROFILE := n
24492
24493 #
24494 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
24495 index 468d591..8e80a0a 100644
24496 --- a/arch/x86/vdso/vdso32-setup.c
24497 +++ b/arch/x86/vdso/vdso32-setup.c
24498 @@ -25,6 +25,7 @@
24499 #include <asm/tlbflush.h>
24500 #include <asm/vdso.h>
24501 #include <asm/proto.h>
24502 +#include <asm/mman.h>
24503
24504 enum {
24505 VDSO_DISABLED = 0,
24506 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
24507 void enable_sep_cpu(void)
24508 {
24509 int cpu = get_cpu();
24510 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
24511 + struct tss_struct *tss = init_tss + cpu;
24512
24513 if (!boot_cpu_has(X86_FEATURE_SEP)) {
24514 put_cpu();
24515 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
24516 gate_vma.vm_start = FIXADDR_USER_START;
24517 gate_vma.vm_end = FIXADDR_USER_END;
24518 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
24519 - gate_vma.vm_page_prot = __P101;
24520 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
24521 /*
24522 * Make sure the vDSO gets into every core dump.
24523 * Dumping its contents makes post-mortem fully interpretable later
24524 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24525 if (compat)
24526 addr = VDSO_HIGH_BASE;
24527 else {
24528 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
24529 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
24530 if (IS_ERR_VALUE(addr)) {
24531 ret = addr;
24532 goto up_fail;
24533 }
24534 }
24535
24536 - current->mm->context.vdso = (void *)addr;
24537 + current->mm->context.vdso = addr;
24538
24539 if (compat_uses_vma || !compat) {
24540 /*
24541 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24542 }
24543
24544 current_thread_info()->sysenter_return =
24545 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24546 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24547
24548 up_fail:
24549 if (ret)
24550 - current->mm->context.vdso = NULL;
24551 + current->mm->context.vdso = 0;
24552
24553 up_write(&mm->mmap_sem);
24554
24555 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
24556
24557 const char *arch_vma_name(struct vm_area_struct *vma)
24558 {
24559 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24560 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24561 return "[vdso]";
24562 +
24563 +#ifdef CONFIG_PAX_SEGMEXEC
24564 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
24565 + return "[vdso]";
24566 +#endif
24567 +
24568 return NULL;
24569 }
24570
24571 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24572 * Check to see if the corresponding task was created in compat vdso
24573 * mode.
24574 */
24575 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
24576 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
24577 return &gate_vma;
24578 return NULL;
24579 }
24580 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
24581 index 153407c..611cba9 100644
24582 --- a/arch/x86/vdso/vma.c
24583 +++ b/arch/x86/vdso/vma.c
24584 @@ -16,8 +16,6 @@
24585 #include <asm/vdso.h>
24586 #include <asm/page.h>
24587
24588 -unsigned int __read_mostly vdso_enabled = 1;
24589 -
24590 extern char vdso_start[], vdso_end[];
24591 extern unsigned short vdso_sync_cpuid;
24592
24593 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
24594 * unaligned here as a result of stack start randomization.
24595 */
24596 addr = PAGE_ALIGN(addr);
24597 - addr = align_addr(addr, NULL, ALIGN_VDSO);
24598
24599 return addr;
24600 }
24601 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
24602 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24603 {
24604 struct mm_struct *mm = current->mm;
24605 - unsigned long addr;
24606 + unsigned long addr = 0;
24607 int ret;
24608
24609 - if (!vdso_enabled)
24610 - return 0;
24611 -
24612 down_write(&mm->mmap_sem);
24613 +
24614 +#ifdef CONFIG_PAX_RANDMMAP
24615 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
24616 +#endif
24617 +
24618 addr = vdso_addr(mm->start_stack, vdso_size);
24619 + addr = align_addr(addr, NULL, ALIGN_VDSO);
24620 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
24621 if (IS_ERR_VALUE(addr)) {
24622 ret = addr;
24623 goto up_fail;
24624 }
24625
24626 - current->mm->context.vdso = (void *)addr;
24627 + mm->context.vdso = addr;
24628
24629 ret = install_special_mapping(mm, addr, vdso_size,
24630 VM_READ|VM_EXEC|
24631 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
24632 VM_ALWAYSDUMP,
24633 vdso_pages);
24634 - if (ret) {
24635 - current->mm->context.vdso = NULL;
24636 - goto up_fail;
24637 - }
24638 +
24639 + if (ret)
24640 + mm->context.vdso = 0;
24641
24642 up_fail:
24643 up_write(&mm->mmap_sem);
24644 return ret;
24645 }
24646 -
24647 -static __init int vdso_setup(char *s)
24648 -{
24649 - vdso_enabled = simple_strtoul(s, NULL, 0);
24650 - return 0;
24651 -}
24652 -__setup("vdso=", vdso_setup);
24653 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
24654 index 1f92865..c843b20 100644
24655 --- a/arch/x86/xen/enlighten.c
24656 +++ b/arch/x86/xen/enlighten.c
24657 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
24658
24659 struct shared_info xen_dummy_shared_info;
24660
24661 -void *xen_initial_gdt;
24662 -
24663 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
24664 __read_mostly int xen_have_vector_callback;
24665 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
24666 @@ -1029,7 +1027,7 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
24667 #endif
24668 };
24669
24670 -static void xen_reboot(int reason)
24671 +static __noreturn void xen_reboot(int reason)
24672 {
24673 struct sched_shutdown r = { .reason = reason };
24674
24675 @@ -1037,17 +1035,17 @@ static void xen_reboot(int reason)
24676 BUG();
24677 }
24678
24679 -static void xen_restart(char *msg)
24680 +static __noreturn void xen_restart(char *msg)
24681 {
24682 xen_reboot(SHUTDOWN_reboot);
24683 }
24684
24685 -static void xen_emergency_restart(void)
24686 +static __noreturn void xen_emergency_restart(void)
24687 {
24688 xen_reboot(SHUTDOWN_reboot);
24689 }
24690
24691 -static void xen_machine_halt(void)
24692 +static __noreturn void xen_machine_halt(void)
24693 {
24694 xen_reboot(SHUTDOWN_poweroff);
24695 }
24696 @@ -1153,7 +1151,17 @@ asmlinkage void __init xen_start_kernel(void)
24697 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
24698
24699 /* Work out if we support NX */
24700 - x86_configure_nx();
24701 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24702 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
24703 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
24704 + unsigned l, h;
24705 +
24706 + __supported_pte_mask |= _PAGE_NX;
24707 + rdmsr(MSR_EFER, l, h);
24708 + l |= EFER_NX;
24709 + wrmsr(MSR_EFER, l, h);
24710 + }
24711 +#endif
24712
24713 xen_setup_features();
24714
24715 @@ -1184,13 +1192,6 @@ asmlinkage void __init xen_start_kernel(void)
24716
24717 machine_ops = xen_machine_ops;
24718
24719 - /*
24720 - * The only reliable way to retain the initial address of the
24721 - * percpu gdt_page is to remember it here, so we can go and
24722 - * mark it RW later, when the initial percpu area is freed.
24723 - */
24724 - xen_initial_gdt = &per_cpu(gdt_page, 0);
24725 -
24726 xen_smp_init();
24727
24728 #ifdef CONFIG_ACPI_NUMA
24729 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
24730 index 87f6673..e2555a6 100644
24731 --- a/arch/x86/xen/mmu.c
24732 +++ b/arch/x86/xen/mmu.c
24733 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
24734 convert_pfn_mfn(init_level4_pgt);
24735 convert_pfn_mfn(level3_ident_pgt);
24736 convert_pfn_mfn(level3_kernel_pgt);
24737 + convert_pfn_mfn(level3_vmalloc_start_pgt);
24738 + convert_pfn_mfn(level3_vmalloc_end_pgt);
24739 + convert_pfn_mfn(level3_vmemmap_pgt);
24740
24741 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
24742 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
24743 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
24744 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
24745 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
24746 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
24747 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
24748 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
24749 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
24750 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
24751 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
24752 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
24753 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
24754
24755 @@ -1962,6 +1969,7 @@ static void __init xen_post_allocator_init(void)
24756 pv_mmu_ops.set_pud = xen_set_pud;
24757 #if PAGETABLE_LEVELS == 4
24758 pv_mmu_ops.set_pgd = xen_set_pgd;
24759 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
24760 #endif
24761
24762 /* This will work as long as patching hasn't happened yet
24763 @@ -2043,6 +2051,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
24764 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
24765 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
24766 .set_pgd = xen_set_pgd_hyper,
24767 + .set_pgd_batched = xen_set_pgd_hyper,
24768
24769 .alloc_pud = xen_alloc_pmd_init,
24770 .release_pud = xen_release_pmd_init,
24771 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
24772 index 041d4fe..7666b7e 100644
24773 --- a/arch/x86/xen/smp.c
24774 +++ b/arch/x86/xen/smp.c
24775 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
24776 {
24777 BUG_ON(smp_processor_id() != 0);
24778 native_smp_prepare_boot_cpu();
24779 -
24780 - /* We've switched to the "real" per-cpu gdt, so make sure the
24781 - old memory can be recycled */
24782 - make_lowmem_page_readwrite(xen_initial_gdt);
24783 -
24784 xen_filter_cpu_maps();
24785 xen_setup_vcpu_info_placement();
24786 }
24787 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
24788 gdt = get_cpu_gdt_table(cpu);
24789
24790 ctxt->flags = VGCF_IN_KERNEL;
24791 - ctxt->user_regs.ds = __USER_DS;
24792 - ctxt->user_regs.es = __USER_DS;
24793 + ctxt->user_regs.ds = __KERNEL_DS;
24794 + ctxt->user_regs.es = __KERNEL_DS;
24795 ctxt->user_regs.ss = __KERNEL_DS;
24796 #ifdef CONFIG_X86_32
24797 ctxt->user_regs.fs = __KERNEL_PERCPU;
24798 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
24799 + savesegment(gs, ctxt->user_regs.gs);
24800 #else
24801 ctxt->gs_base_kernel = per_cpu_offset(cpu);
24802 #endif
24803 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
24804 int rc;
24805
24806 per_cpu(current_task, cpu) = idle;
24807 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
24808 #ifdef CONFIG_X86_32
24809 irq_ctx_init(cpu);
24810 #else
24811 clear_tsk_thread_flag(idle, TIF_FORK);
24812 - per_cpu(kernel_stack, cpu) =
24813 - (unsigned long)task_stack_page(idle) -
24814 - KERNEL_STACK_OFFSET + THREAD_SIZE;
24815 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
24816 #endif
24817 xen_setup_runstate_info(cpu);
24818 xen_setup_timer(cpu);
24819 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
24820 index b040b0e..8cc4fe0 100644
24821 --- a/arch/x86/xen/xen-asm_32.S
24822 +++ b/arch/x86/xen/xen-asm_32.S
24823 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
24824 ESP_OFFSET=4 # bytes pushed onto stack
24825
24826 /*
24827 - * Store vcpu_info pointer for easy access. Do it this way to
24828 - * avoid having to reload %fs
24829 + * Store vcpu_info pointer for easy access.
24830 */
24831 #ifdef CONFIG_SMP
24832 - GET_THREAD_INFO(%eax)
24833 - movl TI_cpu(%eax), %eax
24834 - movl __per_cpu_offset(,%eax,4), %eax
24835 - mov xen_vcpu(%eax), %eax
24836 + push %fs
24837 + mov $(__KERNEL_PERCPU), %eax
24838 + mov %eax, %fs
24839 + mov PER_CPU_VAR(xen_vcpu), %eax
24840 + pop %fs
24841 #else
24842 movl xen_vcpu, %eax
24843 #endif
24844 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
24845 index aaa7291..3f77960 100644
24846 --- a/arch/x86/xen/xen-head.S
24847 +++ b/arch/x86/xen/xen-head.S
24848 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
24849 #ifdef CONFIG_X86_32
24850 mov %esi,xen_start_info
24851 mov $init_thread_union+THREAD_SIZE,%esp
24852 +#ifdef CONFIG_SMP
24853 + movl $cpu_gdt_table,%edi
24854 + movl $__per_cpu_load,%eax
24855 + movw %ax,__KERNEL_PERCPU + 2(%edi)
24856 + rorl $16,%eax
24857 + movb %al,__KERNEL_PERCPU + 4(%edi)
24858 + movb %ah,__KERNEL_PERCPU + 7(%edi)
24859 + movl $__per_cpu_end - 1,%eax
24860 + subl $__per_cpu_start,%eax
24861 + movw %ax,__KERNEL_PERCPU + 0(%edi)
24862 +#endif
24863 #else
24864 mov %rsi,xen_start_info
24865 mov $init_thread_union+THREAD_SIZE,%rsp
24866 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
24867 index b095739..8c17bcd 100644
24868 --- a/arch/x86/xen/xen-ops.h
24869 +++ b/arch/x86/xen/xen-ops.h
24870 @@ -10,8 +10,6 @@
24871 extern const char xen_hypervisor_callback[];
24872 extern const char xen_failsafe_callback[];
24873
24874 -extern void *xen_initial_gdt;
24875 -
24876 struct trap_info;
24877 void xen_copy_trap_info(struct trap_info *traps);
24878
24879 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
24880 index 58916af..9cb880b 100644
24881 --- a/block/blk-iopoll.c
24882 +++ b/block/blk-iopoll.c
24883 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
24884 }
24885 EXPORT_SYMBOL(blk_iopoll_complete);
24886
24887 -static void blk_iopoll_softirq(struct softirq_action *h)
24888 +static void blk_iopoll_softirq(void)
24889 {
24890 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
24891 int rearm = 0, budget = blk_iopoll_budget;
24892 diff --git a/block/blk-map.c b/block/blk-map.c
24893 index 623e1cd..ca1e109 100644
24894 --- a/block/blk-map.c
24895 +++ b/block/blk-map.c
24896 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
24897 if (!len || !kbuf)
24898 return -EINVAL;
24899
24900 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
24901 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
24902 if (do_copy)
24903 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
24904 else
24905 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
24906 index 1366a89..e17f54b 100644
24907 --- a/block/blk-softirq.c
24908 +++ b/block/blk-softirq.c
24909 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
24910 * Softirq action handler - move entries to local list and loop over them
24911 * while passing them to the queue registered handler.
24912 */
24913 -static void blk_done_softirq(struct softirq_action *h)
24914 +static void blk_done_softirq(void)
24915 {
24916 struct list_head *cpu_list, local_list;
24917
24918 diff --git a/block/bsg.c b/block/bsg.c
24919 index 702f131..37808bf 100644
24920 --- a/block/bsg.c
24921 +++ b/block/bsg.c
24922 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
24923 struct sg_io_v4 *hdr, struct bsg_device *bd,
24924 fmode_t has_write_perm)
24925 {
24926 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24927 + unsigned char *cmdptr;
24928 +
24929 if (hdr->request_len > BLK_MAX_CDB) {
24930 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
24931 if (!rq->cmd)
24932 return -ENOMEM;
24933 - }
24934 + cmdptr = rq->cmd;
24935 + } else
24936 + cmdptr = tmpcmd;
24937
24938 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
24939 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
24940 hdr->request_len))
24941 return -EFAULT;
24942
24943 + if (cmdptr != rq->cmd)
24944 + memcpy(rq->cmd, cmdptr, hdr->request_len);
24945 +
24946 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
24947 if (blk_verify_command(rq->cmd, has_write_perm))
24948 return -EPERM;
24949 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
24950 index 7b72502..646105c 100644
24951 --- a/block/compat_ioctl.c
24952 +++ b/block/compat_ioctl.c
24953 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
24954 err |= __get_user(f->spec1, &uf->spec1);
24955 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
24956 err |= __get_user(name, &uf->name);
24957 - f->name = compat_ptr(name);
24958 + f->name = (void __force_kernel *)compat_ptr(name);
24959 if (err) {
24960 err = -EFAULT;
24961 goto out;
24962 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
24963 index 688be8a..8a37d98 100644
24964 --- a/block/scsi_ioctl.c
24965 +++ b/block/scsi_ioctl.c
24966 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
24967 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
24968 struct sg_io_hdr *hdr, fmode_t mode)
24969 {
24970 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
24971 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24972 + unsigned char *cmdptr;
24973 +
24974 + if (rq->cmd != rq->__cmd)
24975 + cmdptr = rq->cmd;
24976 + else
24977 + cmdptr = tmpcmd;
24978 +
24979 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
24980 return -EFAULT;
24981 +
24982 + if (cmdptr != rq->cmd)
24983 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
24984 +
24985 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
24986 return -EPERM;
24987
24988 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
24989 int err;
24990 unsigned int in_len, out_len, bytes, opcode, cmdlen;
24991 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
24992 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24993 + unsigned char *cmdptr;
24994
24995 if (!sic)
24996 return -EINVAL;
24997 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
24998 */
24999 err = -EFAULT;
25000 rq->cmd_len = cmdlen;
25001 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
25002 +
25003 + if (rq->cmd != rq->__cmd)
25004 + cmdptr = rq->cmd;
25005 + else
25006 + cmdptr = tmpcmd;
25007 +
25008 + if (copy_from_user(cmdptr, sic->data, cmdlen))
25009 goto error;
25010
25011 + if (rq->cmd != cmdptr)
25012 + memcpy(rq->cmd, cmdptr, cmdlen);
25013 +
25014 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
25015 goto error;
25016
25017 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
25018 index 671d4d6..5f24030 100644
25019 --- a/crypto/cryptd.c
25020 +++ b/crypto/cryptd.c
25021 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
25022
25023 struct cryptd_blkcipher_request_ctx {
25024 crypto_completion_t complete;
25025 -};
25026 +} __no_const;
25027
25028 struct cryptd_hash_ctx {
25029 struct crypto_shash *child;
25030 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
25031
25032 struct cryptd_aead_request_ctx {
25033 crypto_completion_t complete;
25034 -};
25035 +} __no_const;
25036
25037 static void cryptd_queue_worker(struct work_struct *work);
25038
25039 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
25040 index 5d41894..22021e4 100644
25041 --- a/drivers/acpi/apei/cper.c
25042 +++ b/drivers/acpi/apei/cper.c
25043 @@ -38,12 +38,12 @@
25044 */
25045 u64 cper_next_record_id(void)
25046 {
25047 - static atomic64_t seq;
25048 + static atomic64_unchecked_t seq;
25049
25050 - if (!atomic64_read(&seq))
25051 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
25052 + if (!atomic64_read_unchecked(&seq))
25053 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
25054
25055 - return atomic64_inc_return(&seq);
25056 + return atomic64_inc_return_unchecked(&seq);
25057 }
25058 EXPORT_SYMBOL_GPL(cper_next_record_id);
25059
25060 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
25061 index 6c47ae9..abfdd63 100644
25062 --- a/drivers/acpi/ec_sys.c
25063 +++ b/drivers/acpi/ec_sys.c
25064 @@ -12,6 +12,7 @@
25065 #include <linux/acpi.h>
25066 #include <linux/debugfs.h>
25067 #include <linux/module.h>
25068 +#include <linux/uaccess.h>
25069 #include "internal.h"
25070
25071 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
25072 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25073 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
25074 */
25075 unsigned int size = EC_SPACE_SIZE;
25076 - u8 *data = (u8 *) buf;
25077 + u8 data;
25078 loff_t init_off = *off;
25079 int err = 0;
25080
25081 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25082 size = count;
25083
25084 while (size) {
25085 - err = ec_read(*off, &data[*off - init_off]);
25086 + err = ec_read(*off, &data);
25087 if (err)
25088 return err;
25089 + if (put_user(data, &buf[*off - init_off]))
25090 + return -EFAULT;
25091 *off += 1;
25092 size--;
25093 }
25094 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25095
25096 unsigned int size = count;
25097 loff_t init_off = *off;
25098 - u8 *data = (u8 *) buf;
25099 int err = 0;
25100
25101 if (*off >= EC_SPACE_SIZE)
25102 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25103 }
25104
25105 while (size) {
25106 - u8 byte_write = data[*off - init_off];
25107 + u8 byte_write;
25108 + if (get_user(byte_write, &buf[*off - init_off]))
25109 + return -EFAULT;
25110 err = ec_write(*off, byte_write);
25111 if (err)
25112 return err;
25113 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
25114 index 251c7b62..000462d 100644
25115 --- a/drivers/acpi/proc.c
25116 +++ b/drivers/acpi/proc.c
25117 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
25118 size_t count, loff_t * ppos)
25119 {
25120 struct list_head *node, *next;
25121 - char strbuf[5];
25122 - char str[5] = "";
25123 - unsigned int len = count;
25124 + char strbuf[5] = {0};
25125
25126 - if (len > 4)
25127 - len = 4;
25128 - if (len < 0)
25129 + if (count > 4)
25130 + count = 4;
25131 + if (copy_from_user(strbuf, buffer, count))
25132 return -EFAULT;
25133 -
25134 - if (copy_from_user(strbuf, buffer, len))
25135 - return -EFAULT;
25136 - strbuf[len] = '\0';
25137 - sscanf(strbuf, "%s", str);
25138 + strbuf[count] = '\0';
25139
25140 mutex_lock(&acpi_device_lock);
25141 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
25142 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
25143 if (!dev->wakeup.flags.valid)
25144 continue;
25145
25146 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
25147 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
25148 if (device_can_wakeup(&dev->dev)) {
25149 bool enable = !device_may_wakeup(&dev->dev);
25150 device_set_wakeup_enable(&dev->dev, enable);
25151 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
25152 index 9d7bc9f..a6fc091 100644
25153 --- a/drivers/acpi/processor_driver.c
25154 +++ b/drivers/acpi/processor_driver.c
25155 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
25156 return 0;
25157 #endif
25158
25159 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
25160 + BUG_ON(pr->id >= nr_cpu_ids);
25161
25162 /*
25163 * Buggy BIOS check
25164 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
25165 index c04ad68..0b99473 100644
25166 --- a/drivers/ata/libata-core.c
25167 +++ b/drivers/ata/libata-core.c
25168 @@ -4733,7 +4733,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
25169 struct ata_port *ap;
25170 unsigned int tag;
25171
25172 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25173 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25174 ap = qc->ap;
25175
25176 qc->flags = 0;
25177 @@ -4749,7 +4749,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
25178 struct ata_port *ap;
25179 struct ata_link *link;
25180
25181 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25182 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25183 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
25184 ap = qc->ap;
25185 link = qc->dev->link;
25186 @@ -5754,6 +5754,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25187 return;
25188
25189 spin_lock(&lock);
25190 + pax_open_kernel();
25191
25192 for (cur = ops->inherits; cur; cur = cur->inherits) {
25193 void **inherit = (void **)cur;
25194 @@ -5767,8 +5768,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25195 if (IS_ERR(*pp))
25196 *pp = NULL;
25197
25198 - ops->inherits = NULL;
25199 + *(struct ata_port_operations **)&ops->inherits = NULL;
25200
25201 + pax_close_kernel();
25202 spin_unlock(&lock);
25203 }
25204
25205 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
25206 index e8574bb..f9f6a72 100644
25207 --- a/drivers/ata/pata_arasan_cf.c
25208 +++ b/drivers/ata/pata_arasan_cf.c
25209 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
25210 /* Handle platform specific quirks */
25211 if (pdata->quirk) {
25212 if (pdata->quirk & CF_BROKEN_PIO) {
25213 - ap->ops->set_piomode = NULL;
25214 + pax_open_kernel();
25215 + *(void **)&ap->ops->set_piomode = NULL;
25216 + pax_close_kernel();
25217 ap->pio_mask = 0;
25218 }
25219 if (pdata->quirk & CF_BROKEN_MWDMA)
25220 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
25221 index f9b983a..887b9d8 100644
25222 --- a/drivers/atm/adummy.c
25223 +++ b/drivers/atm/adummy.c
25224 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
25225 vcc->pop(vcc, skb);
25226 else
25227 dev_kfree_skb_any(skb);
25228 - atomic_inc(&vcc->stats->tx);
25229 + atomic_inc_unchecked(&vcc->stats->tx);
25230
25231 return 0;
25232 }
25233 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
25234 index f8f41e0..1f987dd 100644
25235 --- a/drivers/atm/ambassador.c
25236 +++ b/drivers/atm/ambassador.c
25237 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
25238 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
25239
25240 // VC layer stats
25241 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25242 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25243
25244 // free the descriptor
25245 kfree (tx_descr);
25246 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25247 dump_skb ("<<<", vc, skb);
25248
25249 // VC layer stats
25250 - atomic_inc(&atm_vcc->stats->rx);
25251 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25252 __net_timestamp(skb);
25253 // end of our responsibility
25254 atm_vcc->push (atm_vcc, skb);
25255 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25256 } else {
25257 PRINTK (KERN_INFO, "dropped over-size frame");
25258 // should we count this?
25259 - atomic_inc(&atm_vcc->stats->rx_drop);
25260 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25261 }
25262
25263 } else {
25264 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
25265 }
25266
25267 if (check_area (skb->data, skb->len)) {
25268 - atomic_inc(&atm_vcc->stats->tx_err);
25269 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
25270 return -ENOMEM; // ?
25271 }
25272
25273 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
25274 index b22d71c..d6e1049 100644
25275 --- a/drivers/atm/atmtcp.c
25276 +++ b/drivers/atm/atmtcp.c
25277 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25278 if (vcc->pop) vcc->pop(vcc,skb);
25279 else dev_kfree_skb(skb);
25280 if (dev_data) return 0;
25281 - atomic_inc(&vcc->stats->tx_err);
25282 + atomic_inc_unchecked(&vcc->stats->tx_err);
25283 return -ENOLINK;
25284 }
25285 size = skb->len+sizeof(struct atmtcp_hdr);
25286 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25287 if (!new_skb) {
25288 if (vcc->pop) vcc->pop(vcc,skb);
25289 else dev_kfree_skb(skb);
25290 - atomic_inc(&vcc->stats->tx_err);
25291 + atomic_inc_unchecked(&vcc->stats->tx_err);
25292 return -ENOBUFS;
25293 }
25294 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
25295 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25296 if (vcc->pop) vcc->pop(vcc,skb);
25297 else dev_kfree_skb(skb);
25298 out_vcc->push(out_vcc,new_skb);
25299 - atomic_inc(&vcc->stats->tx);
25300 - atomic_inc(&out_vcc->stats->rx);
25301 + atomic_inc_unchecked(&vcc->stats->tx);
25302 + atomic_inc_unchecked(&out_vcc->stats->rx);
25303 return 0;
25304 }
25305
25306 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25307 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
25308 read_unlock(&vcc_sklist_lock);
25309 if (!out_vcc) {
25310 - atomic_inc(&vcc->stats->tx_err);
25311 + atomic_inc_unchecked(&vcc->stats->tx_err);
25312 goto done;
25313 }
25314 skb_pull(skb,sizeof(struct atmtcp_hdr));
25315 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25316 __net_timestamp(new_skb);
25317 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
25318 out_vcc->push(out_vcc,new_skb);
25319 - atomic_inc(&vcc->stats->tx);
25320 - atomic_inc(&out_vcc->stats->rx);
25321 + atomic_inc_unchecked(&vcc->stats->tx);
25322 + atomic_inc_unchecked(&out_vcc->stats->rx);
25323 done:
25324 if (vcc->pop) vcc->pop(vcc,skb);
25325 else dev_kfree_skb(skb);
25326 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
25327 index 956e9ac..133516d 100644
25328 --- a/drivers/atm/eni.c
25329 +++ b/drivers/atm/eni.c
25330 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
25331 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
25332 vcc->dev->number);
25333 length = 0;
25334 - atomic_inc(&vcc->stats->rx_err);
25335 + atomic_inc_unchecked(&vcc->stats->rx_err);
25336 }
25337 else {
25338 length = ATM_CELL_SIZE-1; /* no HEC */
25339 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25340 size);
25341 }
25342 eff = length = 0;
25343 - atomic_inc(&vcc->stats->rx_err);
25344 + atomic_inc_unchecked(&vcc->stats->rx_err);
25345 }
25346 else {
25347 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
25348 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25349 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
25350 vcc->dev->number,vcc->vci,length,size << 2,descr);
25351 length = eff = 0;
25352 - atomic_inc(&vcc->stats->rx_err);
25353 + atomic_inc_unchecked(&vcc->stats->rx_err);
25354 }
25355 }
25356 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
25357 @@ -771,7 +771,7 @@ rx_dequeued++;
25358 vcc->push(vcc,skb);
25359 pushed++;
25360 }
25361 - atomic_inc(&vcc->stats->rx);
25362 + atomic_inc_unchecked(&vcc->stats->rx);
25363 }
25364 wake_up(&eni_dev->rx_wait);
25365 }
25366 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
25367 PCI_DMA_TODEVICE);
25368 if (vcc->pop) vcc->pop(vcc,skb);
25369 else dev_kfree_skb_irq(skb);
25370 - atomic_inc(&vcc->stats->tx);
25371 + atomic_inc_unchecked(&vcc->stats->tx);
25372 wake_up(&eni_dev->tx_wait);
25373 dma_complete++;
25374 }
25375 @@ -1569,7 +1569,7 @@ tx_complete++;
25376 /*--------------------------------- entries ---------------------------------*/
25377
25378
25379 -static const char *media_name[] __devinitdata = {
25380 +static const char *media_name[] __devinitconst = {
25381 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
25382 "UTP", "05?", "06?", "07?", /* 4- 7 */
25383 "TAXI","09?", "10?", "11?", /* 8-11 */
25384 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
25385 index 5072f8a..fa52520d 100644
25386 --- a/drivers/atm/firestream.c
25387 +++ b/drivers/atm/firestream.c
25388 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
25389 }
25390 }
25391
25392 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25393 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25394
25395 fs_dprintk (FS_DEBUG_TXMEM, "i");
25396 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
25397 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25398 #endif
25399 skb_put (skb, qe->p1 & 0xffff);
25400 ATM_SKB(skb)->vcc = atm_vcc;
25401 - atomic_inc(&atm_vcc->stats->rx);
25402 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25403 __net_timestamp(skb);
25404 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
25405 atm_vcc->push (atm_vcc, skb);
25406 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25407 kfree (pe);
25408 }
25409 if (atm_vcc)
25410 - atomic_inc(&atm_vcc->stats->rx_drop);
25411 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25412 break;
25413 case 0x1f: /* Reassembly abort: no buffers. */
25414 /* Silently increment error counter. */
25415 if (atm_vcc)
25416 - atomic_inc(&atm_vcc->stats->rx_drop);
25417 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25418 break;
25419 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
25420 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
25421 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
25422 index 361f5ae..7fc552d 100644
25423 --- a/drivers/atm/fore200e.c
25424 +++ b/drivers/atm/fore200e.c
25425 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
25426 #endif
25427 /* check error condition */
25428 if (*entry->status & STATUS_ERROR)
25429 - atomic_inc(&vcc->stats->tx_err);
25430 + atomic_inc_unchecked(&vcc->stats->tx_err);
25431 else
25432 - atomic_inc(&vcc->stats->tx);
25433 + atomic_inc_unchecked(&vcc->stats->tx);
25434 }
25435 }
25436
25437 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25438 if (skb == NULL) {
25439 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
25440
25441 - atomic_inc(&vcc->stats->rx_drop);
25442 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25443 return -ENOMEM;
25444 }
25445
25446 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25447
25448 dev_kfree_skb_any(skb);
25449
25450 - atomic_inc(&vcc->stats->rx_drop);
25451 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25452 return -ENOMEM;
25453 }
25454
25455 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25456
25457 vcc->push(vcc, skb);
25458 - atomic_inc(&vcc->stats->rx);
25459 + atomic_inc_unchecked(&vcc->stats->rx);
25460
25461 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25462
25463 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
25464 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
25465 fore200e->atm_dev->number,
25466 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
25467 - atomic_inc(&vcc->stats->rx_err);
25468 + atomic_inc_unchecked(&vcc->stats->rx_err);
25469 }
25470 }
25471
25472 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
25473 goto retry_here;
25474 }
25475
25476 - atomic_inc(&vcc->stats->tx_err);
25477 + atomic_inc_unchecked(&vcc->stats->tx_err);
25478
25479 fore200e->tx_sat++;
25480 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
25481 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
25482 index 9a51df4..f3bb5f8 100644
25483 --- a/drivers/atm/he.c
25484 +++ b/drivers/atm/he.c
25485 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25486
25487 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
25488 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
25489 - atomic_inc(&vcc->stats->rx_drop);
25490 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25491 goto return_host_buffers;
25492 }
25493
25494 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25495 RBRQ_LEN_ERR(he_dev->rbrq_head)
25496 ? "LEN_ERR" : "",
25497 vcc->vpi, vcc->vci);
25498 - atomic_inc(&vcc->stats->rx_err);
25499 + atomic_inc_unchecked(&vcc->stats->rx_err);
25500 goto return_host_buffers;
25501 }
25502
25503 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25504 vcc->push(vcc, skb);
25505 spin_lock(&he_dev->global_lock);
25506
25507 - atomic_inc(&vcc->stats->rx);
25508 + atomic_inc_unchecked(&vcc->stats->rx);
25509
25510 return_host_buffers:
25511 ++pdus_assembled;
25512 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
25513 tpd->vcc->pop(tpd->vcc, tpd->skb);
25514 else
25515 dev_kfree_skb_any(tpd->skb);
25516 - atomic_inc(&tpd->vcc->stats->tx_err);
25517 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
25518 }
25519 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
25520 return;
25521 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25522 vcc->pop(vcc, skb);
25523 else
25524 dev_kfree_skb_any(skb);
25525 - atomic_inc(&vcc->stats->tx_err);
25526 + atomic_inc_unchecked(&vcc->stats->tx_err);
25527 return -EINVAL;
25528 }
25529
25530 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25531 vcc->pop(vcc, skb);
25532 else
25533 dev_kfree_skb_any(skb);
25534 - atomic_inc(&vcc->stats->tx_err);
25535 + atomic_inc_unchecked(&vcc->stats->tx_err);
25536 return -EINVAL;
25537 }
25538 #endif
25539 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25540 vcc->pop(vcc, skb);
25541 else
25542 dev_kfree_skb_any(skb);
25543 - atomic_inc(&vcc->stats->tx_err);
25544 + atomic_inc_unchecked(&vcc->stats->tx_err);
25545 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25546 return -ENOMEM;
25547 }
25548 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25549 vcc->pop(vcc, skb);
25550 else
25551 dev_kfree_skb_any(skb);
25552 - atomic_inc(&vcc->stats->tx_err);
25553 + atomic_inc_unchecked(&vcc->stats->tx_err);
25554 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25555 return -ENOMEM;
25556 }
25557 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25558 __enqueue_tpd(he_dev, tpd, cid);
25559 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25560
25561 - atomic_inc(&vcc->stats->tx);
25562 + atomic_inc_unchecked(&vcc->stats->tx);
25563
25564 return 0;
25565 }
25566 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
25567 index b812103..e391a49 100644
25568 --- a/drivers/atm/horizon.c
25569 +++ b/drivers/atm/horizon.c
25570 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
25571 {
25572 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
25573 // VC layer stats
25574 - atomic_inc(&vcc->stats->rx);
25575 + atomic_inc_unchecked(&vcc->stats->rx);
25576 __net_timestamp(skb);
25577 // end of our responsibility
25578 vcc->push (vcc, skb);
25579 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
25580 dev->tx_iovec = NULL;
25581
25582 // VC layer stats
25583 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25584 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25585
25586 // free the skb
25587 hrz_kfree_skb (skb);
25588 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
25589 index 1c05212..c28e200 100644
25590 --- a/drivers/atm/idt77252.c
25591 +++ b/drivers/atm/idt77252.c
25592 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
25593 else
25594 dev_kfree_skb(skb);
25595
25596 - atomic_inc(&vcc->stats->tx);
25597 + atomic_inc_unchecked(&vcc->stats->tx);
25598 }
25599
25600 atomic_dec(&scq->used);
25601 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25602 if ((sb = dev_alloc_skb(64)) == NULL) {
25603 printk("%s: Can't allocate buffers for aal0.\n",
25604 card->name);
25605 - atomic_add(i, &vcc->stats->rx_drop);
25606 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
25607 break;
25608 }
25609 if (!atm_charge(vcc, sb->truesize)) {
25610 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
25611 card->name);
25612 - atomic_add(i - 1, &vcc->stats->rx_drop);
25613 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
25614 dev_kfree_skb(sb);
25615 break;
25616 }
25617 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25618 ATM_SKB(sb)->vcc = vcc;
25619 __net_timestamp(sb);
25620 vcc->push(vcc, sb);
25621 - atomic_inc(&vcc->stats->rx);
25622 + atomic_inc_unchecked(&vcc->stats->rx);
25623
25624 cell += ATM_CELL_PAYLOAD;
25625 }
25626 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25627 "(CDC: %08x)\n",
25628 card->name, len, rpp->len, readl(SAR_REG_CDC));
25629 recycle_rx_pool_skb(card, rpp);
25630 - atomic_inc(&vcc->stats->rx_err);
25631 + atomic_inc_unchecked(&vcc->stats->rx_err);
25632 return;
25633 }
25634 if (stat & SAR_RSQE_CRC) {
25635 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
25636 recycle_rx_pool_skb(card, rpp);
25637 - atomic_inc(&vcc->stats->rx_err);
25638 + atomic_inc_unchecked(&vcc->stats->rx_err);
25639 return;
25640 }
25641 if (skb_queue_len(&rpp->queue) > 1) {
25642 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25643 RXPRINTK("%s: Can't alloc RX skb.\n",
25644 card->name);
25645 recycle_rx_pool_skb(card, rpp);
25646 - atomic_inc(&vcc->stats->rx_err);
25647 + atomic_inc_unchecked(&vcc->stats->rx_err);
25648 return;
25649 }
25650 if (!atm_charge(vcc, skb->truesize)) {
25651 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25652 __net_timestamp(skb);
25653
25654 vcc->push(vcc, skb);
25655 - atomic_inc(&vcc->stats->rx);
25656 + atomic_inc_unchecked(&vcc->stats->rx);
25657
25658 return;
25659 }
25660 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25661 __net_timestamp(skb);
25662
25663 vcc->push(vcc, skb);
25664 - atomic_inc(&vcc->stats->rx);
25665 + atomic_inc_unchecked(&vcc->stats->rx);
25666
25667 if (skb->truesize > SAR_FB_SIZE_3)
25668 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
25669 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
25670 if (vcc->qos.aal != ATM_AAL0) {
25671 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
25672 card->name, vpi, vci);
25673 - atomic_inc(&vcc->stats->rx_drop);
25674 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25675 goto drop;
25676 }
25677
25678 if ((sb = dev_alloc_skb(64)) == NULL) {
25679 printk("%s: Can't allocate buffers for AAL0.\n",
25680 card->name);
25681 - atomic_inc(&vcc->stats->rx_err);
25682 + atomic_inc_unchecked(&vcc->stats->rx_err);
25683 goto drop;
25684 }
25685
25686 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
25687 ATM_SKB(sb)->vcc = vcc;
25688 __net_timestamp(sb);
25689 vcc->push(vcc, sb);
25690 - atomic_inc(&vcc->stats->rx);
25691 + atomic_inc_unchecked(&vcc->stats->rx);
25692
25693 drop:
25694 skb_pull(queue, 64);
25695 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25696
25697 if (vc == NULL) {
25698 printk("%s: NULL connection in send().\n", card->name);
25699 - atomic_inc(&vcc->stats->tx_err);
25700 + atomic_inc_unchecked(&vcc->stats->tx_err);
25701 dev_kfree_skb(skb);
25702 return -EINVAL;
25703 }
25704 if (!test_bit(VCF_TX, &vc->flags)) {
25705 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
25706 - atomic_inc(&vcc->stats->tx_err);
25707 + atomic_inc_unchecked(&vcc->stats->tx_err);
25708 dev_kfree_skb(skb);
25709 return -EINVAL;
25710 }
25711 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25712 break;
25713 default:
25714 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
25715 - atomic_inc(&vcc->stats->tx_err);
25716 + atomic_inc_unchecked(&vcc->stats->tx_err);
25717 dev_kfree_skb(skb);
25718 return -EINVAL;
25719 }
25720
25721 if (skb_shinfo(skb)->nr_frags != 0) {
25722 printk("%s: No scatter-gather yet.\n", card->name);
25723 - atomic_inc(&vcc->stats->tx_err);
25724 + atomic_inc_unchecked(&vcc->stats->tx_err);
25725 dev_kfree_skb(skb);
25726 return -EINVAL;
25727 }
25728 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25729
25730 err = queue_skb(card, vc, skb, oam);
25731 if (err) {
25732 - atomic_inc(&vcc->stats->tx_err);
25733 + atomic_inc_unchecked(&vcc->stats->tx_err);
25734 dev_kfree_skb(skb);
25735 return err;
25736 }
25737 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
25738 skb = dev_alloc_skb(64);
25739 if (!skb) {
25740 printk("%s: Out of memory in send_oam().\n", card->name);
25741 - atomic_inc(&vcc->stats->tx_err);
25742 + atomic_inc_unchecked(&vcc->stats->tx_err);
25743 return -ENOMEM;
25744 }
25745 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
25746 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
25747 index 3d0c2b0..45441fa 100644
25748 --- a/drivers/atm/iphase.c
25749 +++ b/drivers/atm/iphase.c
25750 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
25751 status = (u_short) (buf_desc_ptr->desc_mode);
25752 if (status & (RX_CER | RX_PTE | RX_OFL))
25753 {
25754 - atomic_inc(&vcc->stats->rx_err);
25755 + atomic_inc_unchecked(&vcc->stats->rx_err);
25756 IF_ERR(printk("IA: bad packet, dropping it");)
25757 if (status & RX_CER) {
25758 IF_ERR(printk(" cause: packet CRC error\n");)
25759 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
25760 len = dma_addr - buf_addr;
25761 if (len > iadev->rx_buf_sz) {
25762 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
25763 - atomic_inc(&vcc->stats->rx_err);
25764 + atomic_inc_unchecked(&vcc->stats->rx_err);
25765 goto out_free_desc;
25766 }
25767
25768 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25769 ia_vcc = INPH_IA_VCC(vcc);
25770 if (ia_vcc == NULL)
25771 {
25772 - atomic_inc(&vcc->stats->rx_err);
25773 + atomic_inc_unchecked(&vcc->stats->rx_err);
25774 dev_kfree_skb_any(skb);
25775 atm_return(vcc, atm_guess_pdu2truesize(len));
25776 goto INCR_DLE;
25777 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25778 if ((length > iadev->rx_buf_sz) || (length >
25779 (skb->len - sizeof(struct cpcs_trailer))))
25780 {
25781 - atomic_inc(&vcc->stats->rx_err);
25782 + atomic_inc_unchecked(&vcc->stats->rx_err);
25783 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
25784 length, skb->len);)
25785 dev_kfree_skb_any(skb);
25786 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25787
25788 IF_RX(printk("rx_dle_intr: skb push");)
25789 vcc->push(vcc,skb);
25790 - atomic_inc(&vcc->stats->rx);
25791 + atomic_inc_unchecked(&vcc->stats->rx);
25792 iadev->rx_pkt_cnt++;
25793 }
25794 INCR_DLE:
25795 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
25796 {
25797 struct k_sonet_stats *stats;
25798 stats = &PRIV(_ia_dev[board])->sonet_stats;
25799 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
25800 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
25801 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
25802 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
25803 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
25804 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
25805 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
25806 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
25807 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
25808 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
25809 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
25810 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
25811 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
25812 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
25813 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
25814 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
25815 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
25816 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
25817 }
25818 ia_cmds.status = 0;
25819 break;
25820 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
25821 if ((desc == 0) || (desc > iadev->num_tx_desc))
25822 {
25823 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
25824 - atomic_inc(&vcc->stats->tx);
25825 + atomic_inc_unchecked(&vcc->stats->tx);
25826 if (vcc->pop)
25827 vcc->pop(vcc, skb);
25828 else
25829 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
25830 ATM_DESC(skb) = vcc->vci;
25831 skb_queue_tail(&iadev->tx_dma_q, skb);
25832
25833 - atomic_inc(&vcc->stats->tx);
25834 + atomic_inc_unchecked(&vcc->stats->tx);
25835 iadev->tx_pkt_cnt++;
25836 /* Increment transaction counter */
25837 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
25838
25839 #if 0
25840 /* add flow control logic */
25841 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
25842 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
25843 if (iavcc->vc_desc_cnt > 10) {
25844 vcc->tx_quota = vcc->tx_quota * 3 / 4;
25845 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
25846 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
25847 index f556969..0da15eb 100644
25848 --- a/drivers/atm/lanai.c
25849 +++ b/drivers/atm/lanai.c
25850 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
25851 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
25852 lanai_endtx(lanai, lvcc);
25853 lanai_free_skb(lvcc->tx.atmvcc, skb);
25854 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
25855 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
25856 }
25857
25858 /* Try to fill the buffer - don't call unless there is backlog */
25859 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
25860 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
25861 __net_timestamp(skb);
25862 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
25863 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
25864 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
25865 out:
25866 lvcc->rx.buf.ptr = end;
25867 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
25868 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25869 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
25870 "vcc %d\n", lanai->number, (unsigned int) s, vci);
25871 lanai->stats.service_rxnotaal5++;
25872 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25873 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25874 return 0;
25875 }
25876 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
25877 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25878 int bytes;
25879 read_unlock(&vcc_sklist_lock);
25880 DPRINTK("got trashed rx pdu on vci %d\n", vci);
25881 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25882 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25883 lvcc->stats.x.aal5.service_trash++;
25884 bytes = (SERVICE_GET_END(s) * 16) -
25885 (((unsigned long) lvcc->rx.buf.ptr) -
25886 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25887 }
25888 if (s & SERVICE_STREAM) {
25889 read_unlock(&vcc_sklist_lock);
25890 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25891 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25892 lvcc->stats.x.aal5.service_stream++;
25893 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
25894 "PDU on VCI %d!\n", lanai->number, vci);
25895 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
25896 return 0;
25897 }
25898 DPRINTK("got rx crc error on vci %d\n", vci);
25899 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25900 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25901 lvcc->stats.x.aal5.service_rxcrc++;
25902 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
25903 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
25904 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
25905 index 1c70c45..300718d 100644
25906 --- a/drivers/atm/nicstar.c
25907 +++ b/drivers/atm/nicstar.c
25908 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25909 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
25910 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
25911 card->index);
25912 - atomic_inc(&vcc->stats->tx_err);
25913 + atomic_inc_unchecked(&vcc->stats->tx_err);
25914 dev_kfree_skb_any(skb);
25915 return -EINVAL;
25916 }
25917 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25918 if (!vc->tx) {
25919 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
25920 card->index);
25921 - atomic_inc(&vcc->stats->tx_err);
25922 + atomic_inc_unchecked(&vcc->stats->tx_err);
25923 dev_kfree_skb_any(skb);
25924 return -EINVAL;
25925 }
25926 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25927 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
25928 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
25929 card->index);
25930 - atomic_inc(&vcc->stats->tx_err);
25931 + atomic_inc_unchecked(&vcc->stats->tx_err);
25932 dev_kfree_skb_any(skb);
25933 return -EINVAL;
25934 }
25935
25936 if (skb_shinfo(skb)->nr_frags != 0) {
25937 printk("nicstar%d: No scatter-gather yet.\n", card->index);
25938 - atomic_inc(&vcc->stats->tx_err);
25939 + atomic_inc_unchecked(&vcc->stats->tx_err);
25940 dev_kfree_skb_any(skb);
25941 return -EINVAL;
25942 }
25943 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
25944 }
25945
25946 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
25947 - atomic_inc(&vcc->stats->tx_err);
25948 + atomic_inc_unchecked(&vcc->stats->tx_err);
25949 dev_kfree_skb_any(skb);
25950 return -EIO;
25951 }
25952 - atomic_inc(&vcc->stats->tx);
25953 + atomic_inc_unchecked(&vcc->stats->tx);
25954
25955 return 0;
25956 }
25957 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25958 printk
25959 ("nicstar%d: Can't allocate buffers for aal0.\n",
25960 card->index);
25961 - atomic_add(i, &vcc->stats->rx_drop);
25962 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
25963 break;
25964 }
25965 if (!atm_charge(vcc, sb->truesize)) {
25966 RXPRINTK
25967 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
25968 card->index);
25969 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
25970 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
25971 dev_kfree_skb_any(sb);
25972 break;
25973 }
25974 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25975 ATM_SKB(sb)->vcc = vcc;
25976 __net_timestamp(sb);
25977 vcc->push(vcc, sb);
25978 - atomic_inc(&vcc->stats->rx);
25979 + atomic_inc_unchecked(&vcc->stats->rx);
25980 cell += ATM_CELL_PAYLOAD;
25981 }
25982
25983 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25984 if (iovb == NULL) {
25985 printk("nicstar%d: Out of iovec buffers.\n",
25986 card->index);
25987 - atomic_inc(&vcc->stats->rx_drop);
25988 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25989 recycle_rx_buf(card, skb);
25990 return;
25991 }
25992 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
25993 small or large buffer itself. */
25994 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
25995 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
25996 - atomic_inc(&vcc->stats->rx_err);
25997 + atomic_inc_unchecked(&vcc->stats->rx_err);
25998 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
25999 NS_MAX_IOVECS);
26000 NS_PRV_IOVCNT(iovb) = 0;
26001 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26002 ("nicstar%d: Expected a small buffer, and this is not one.\n",
26003 card->index);
26004 which_list(card, skb);
26005 - atomic_inc(&vcc->stats->rx_err);
26006 + atomic_inc_unchecked(&vcc->stats->rx_err);
26007 recycle_rx_buf(card, skb);
26008 vc->rx_iov = NULL;
26009 recycle_iov_buf(card, iovb);
26010 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26011 ("nicstar%d: Expected a large buffer, and this is not one.\n",
26012 card->index);
26013 which_list(card, skb);
26014 - atomic_inc(&vcc->stats->rx_err);
26015 + atomic_inc_unchecked(&vcc->stats->rx_err);
26016 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26017 NS_PRV_IOVCNT(iovb));
26018 vc->rx_iov = NULL;
26019 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26020 printk(" - PDU size mismatch.\n");
26021 else
26022 printk(".\n");
26023 - atomic_inc(&vcc->stats->rx_err);
26024 + atomic_inc_unchecked(&vcc->stats->rx_err);
26025 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26026 NS_PRV_IOVCNT(iovb));
26027 vc->rx_iov = NULL;
26028 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26029 /* skb points to a small buffer */
26030 if (!atm_charge(vcc, skb->truesize)) {
26031 push_rxbufs(card, skb);
26032 - atomic_inc(&vcc->stats->rx_drop);
26033 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26034 } else {
26035 skb_put(skb, len);
26036 dequeue_sm_buf(card, skb);
26037 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26038 ATM_SKB(skb)->vcc = vcc;
26039 __net_timestamp(skb);
26040 vcc->push(vcc, skb);
26041 - atomic_inc(&vcc->stats->rx);
26042 + atomic_inc_unchecked(&vcc->stats->rx);
26043 }
26044 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
26045 struct sk_buff *sb;
26046 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26047 if (len <= NS_SMBUFSIZE) {
26048 if (!atm_charge(vcc, sb->truesize)) {
26049 push_rxbufs(card, sb);
26050 - atomic_inc(&vcc->stats->rx_drop);
26051 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26052 } else {
26053 skb_put(sb, len);
26054 dequeue_sm_buf(card, sb);
26055 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26056 ATM_SKB(sb)->vcc = vcc;
26057 __net_timestamp(sb);
26058 vcc->push(vcc, sb);
26059 - atomic_inc(&vcc->stats->rx);
26060 + atomic_inc_unchecked(&vcc->stats->rx);
26061 }
26062
26063 push_rxbufs(card, skb);
26064 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26065
26066 if (!atm_charge(vcc, skb->truesize)) {
26067 push_rxbufs(card, skb);
26068 - atomic_inc(&vcc->stats->rx_drop);
26069 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26070 } else {
26071 dequeue_lg_buf(card, skb);
26072 #ifdef NS_USE_DESTRUCTORS
26073 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26074 ATM_SKB(skb)->vcc = vcc;
26075 __net_timestamp(skb);
26076 vcc->push(vcc, skb);
26077 - atomic_inc(&vcc->stats->rx);
26078 + atomic_inc_unchecked(&vcc->stats->rx);
26079 }
26080
26081 push_rxbufs(card, sb);
26082 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26083 printk
26084 ("nicstar%d: Out of huge buffers.\n",
26085 card->index);
26086 - atomic_inc(&vcc->stats->rx_drop);
26087 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26088 recycle_iovec_rx_bufs(card,
26089 (struct iovec *)
26090 iovb->data,
26091 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26092 card->hbpool.count++;
26093 } else
26094 dev_kfree_skb_any(hb);
26095 - atomic_inc(&vcc->stats->rx_drop);
26096 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26097 } else {
26098 /* Copy the small buffer to the huge buffer */
26099 sb = (struct sk_buff *)iov->iov_base;
26100 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26101 #endif /* NS_USE_DESTRUCTORS */
26102 __net_timestamp(hb);
26103 vcc->push(vcc, hb);
26104 - atomic_inc(&vcc->stats->rx);
26105 + atomic_inc_unchecked(&vcc->stats->rx);
26106 }
26107 }
26108
26109 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
26110 index 5d1d076..12fbca4 100644
26111 --- a/drivers/atm/solos-pci.c
26112 +++ b/drivers/atm/solos-pci.c
26113 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
26114 }
26115 atm_charge(vcc, skb->truesize);
26116 vcc->push(vcc, skb);
26117 - atomic_inc(&vcc->stats->rx);
26118 + atomic_inc_unchecked(&vcc->stats->rx);
26119 break;
26120
26121 case PKT_STATUS:
26122 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
26123 vcc = SKB_CB(oldskb)->vcc;
26124
26125 if (vcc) {
26126 - atomic_inc(&vcc->stats->tx);
26127 + atomic_inc_unchecked(&vcc->stats->tx);
26128 solos_pop(vcc, oldskb);
26129 } else
26130 dev_kfree_skb_irq(oldskb);
26131 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
26132 index 90f1ccc..04c4a1e 100644
26133 --- a/drivers/atm/suni.c
26134 +++ b/drivers/atm/suni.c
26135 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
26136
26137
26138 #define ADD_LIMITED(s,v) \
26139 - atomic_add((v),&stats->s); \
26140 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
26141 + atomic_add_unchecked((v),&stats->s); \
26142 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
26143
26144
26145 static void suni_hz(unsigned long from_timer)
26146 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
26147 index 5120a96..e2572bd 100644
26148 --- a/drivers/atm/uPD98402.c
26149 +++ b/drivers/atm/uPD98402.c
26150 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
26151 struct sonet_stats tmp;
26152 int error = 0;
26153
26154 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26155 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26156 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
26157 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
26158 if (zero && !error) {
26159 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
26160
26161
26162 #define ADD_LIMITED(s,v) \
26163 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
26164 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
26165 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26166 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
26167 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
26168 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26169
26170
26171 static void stat_event(struct atm_dev *dev)
26172 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
26173 if (reason & uPD98402_INT_PFM) stat_event(dev);
26174 if (reason & uPD98402_INT_PCO) {
26175 (void) GET(PCOCR); /* clear interrupt cause */
26176 - atomic_add(GET(HECCT),
26177 + atomic_add_unchecked(GET(HECCT),
26178 &PRIV(dev)->sonet_stats.uncorr_hcs);
26179 }
26180 if ((reason & uPD98402_INT_RFO) &&
26181 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
26182 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
26183 uPD98402_INT_LOS),PIMR); /* enable them */
26184 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
26185 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26186 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
26187 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
26188 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26189 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
26190 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
26191 return 0;
26192 }
26193
26194 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
26195 index d889f56..17eb71e 100644
26196 --- a/drivers/atm/zatm.c
26197 +++ b/drivers/atm/zatm.c
26198 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26199 }
26200 if (!size) {
26201 dev_kfree_skb_irq(skb);
26202 - if (vcc) atomic_inc(&vcc->stats->rx_err);
26203 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
26204 continue;
26205 }
26206 if (!atm_charge(vcc,skb->truesize)) {
26207 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26208 skb->len = size;
26209 ATM_SKB(skb)->vcc = vcc;
26210 vcc->push(vcc,skb);
26211 - atomic_inc(&vcc->stats->rx);
26212 + atomic_inc_unchecked(&vcc->stats->rx);
26213 }
26214 zout(pos & 0xffff,MTA(mbx));
26215 #if 0 /* probably a stupid idea */
26216 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
26217 skb_queue_head(&zatm_vcc->backlog,skb);
26218 break;
26219 }
26220 - atomic_inc(&vcc->stats->tx);
26221 + atomic_inc_unchecked(&vcc->stats->tx);
26222 wake_up(&zatm_vcc->tx_wait);
26223 }
26224
26225 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
26226 index a4760e0..51283cf 100644
26227 --- a/drivers/base/devtmpfs.c
26228 +++ b/drivers/base/devtmpfs.c
26229 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
26230 if (!thread)
26231 return 0;
26232
26233 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
26234 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
26235 if (err)
26236 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
26237 else
26238 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
26239 index caf995f..6f76697 100644
26240 --- a/drivers/base/power/wakeup.c
26241 +++ b/drivers/base/power/wakeup.c
26242 @@ -30,14 +30,14 @@ bool events_check_enabled;
26243 * They need to be modified together atomically, so it's better to use one
26244 * atomic variable to hold them both.
26245 */
26246 -static atomic_t combined_event_count = ATOMIC_INIT(0);
26247 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
26248
26249 #define IN_PROGRESS_BITS (sizeof(int) * 4)
26250 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
26251
26252 static void split_counters(unsigned int *cnt, unsigned int *inpr)
26253 {
26254 - unsigned int comb = atomic_read(&combined_event_count);
26255 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
26256
26257 *cnt = (comb >> IN_PROGRESS_BITS);
26258 *inpr = comb & MAX_IN_PROGRESS;
26259 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
26260 ws->last_time = ktime_get();
26261
26262 /* Increment the counter of events in progress. */
26263 - atomic_inc(&combined_event_count);
26264 + atomic_inc_unchecked(&combined_event_count);
26265 }
26266
26267 /**
26268 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
26269 * Increment the counter of registered wakeup events and decrement the
26270 * couter of wakeup events in progress simultaneously.
26271 */
26272 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
26273 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
26274 }
26275
26276 /**
26277 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
26278 index b0f553b..77b928b 100644
26279 --- a/drivers/block/cciss.c
26280 +++ b/drivers/block/cciss.c
26281 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
26282 int err;
26283 u32 cp;
26284
26285 + memset(&arg64, 0, sizeof(arg64));
26286 +
26287 err = 0;
26288 err |=
26289 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
26290 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
26291 while (!list_empty(&h->reqQ)) {
26292 c = list_entry(h->reqQ.next, CommandList_struct, list);
26293 /* can't do anything if fifo is full */
26294 - if ((h->access.fifo_full(h))) {
26295 + if ((h->access->fifo_full(h))) {
26296 dev_warn(&h->pdev->dev, "fifo full\n");
26297 break;
26298 }
26299 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
26300 h->Qdepth--;
26301
26302 /* Tell the controller execute command */
26303 - h->access.submit_command(h, c);
26304 + h->access->submit_command(h, c);
26305
26306 /* Put job onto the completed Q */
26307 addQ(&h->cmpQ, c);
26308 @@ -3443,17 +3445,17 @@ startio:
26309
26310 static inline unsigned long get_next_completion(ctlr_info_t *h)
26311 {
26312 - return h->access.command_completed(h);
26313 + return h->access->command_completed(h);
26314 }
26315
26316 static inline int interrupt_pending(ctlr_info_t *h)
26317 {
26318 - return h->access.intr_pending(h);
26319 + return h->access->intr_pending(h);
26320 }
26321
26322 static inline long interrupt_not_for_us(ctlr_info_t *h)
26323 {
26324 - return ((h->access.intr_pending(h) == 0) ||
26325 + return ((h->access->intr_pending(h) == 0) ||
26326 (h->interrupts_enabled == 0));
26327 }
26328
26329 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
26330 u32 a;
26331
26332 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
26333 - return h->access.command_completed(h);
26334 + return h->access->command_completed(h);
26335
26336 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
26337 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
26338 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
26339 trans_support & CFGTBL_Trans_use_short_tags);
26340
26341 /* Change the access methods to the performant access methods */
26342 - h->access = SA5_performant_access;
26343 + h->access = &SA5_performant_access;
26344 h->transMethod = CFGTBL_Trans_Performant;
26345
26346 return;
26347 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
26348 if (prod_index < 0)
26349 return -ENODEV;
26350 h->product_name = products[prod_index].product_name;
26351 - h->access = *(products[prod_index].access);
26352 + h->access = products[prod_index].access;
26353
26354 if (cciss_board_disabled(h)) {
26355 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
26356 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
26357 }
26358
26359 /* make sure the board interrupts are off */
26360 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26361 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26362 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
26363 if (rc)
26364 goto clean2;
26365 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
26366 * fake ones to scoop up any residual completions.
26367 */
26368 spin_lock_irqsave(&h->lock, flags);
26369 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26370 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26371 spin_unlock_irqrestore(&h->lock, flags);
26372 free_irq(h->intr[h->intr_mode], h);
26373 rc = cciss_request_irq(h, cciss_msix_discard_completions,
26374 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
26375 dev_info(&h->pdev->dev, "Board READY.\n");
26376 dev_info(&h->pdev->dev,
26377 "Waiting for stale completions to drain.\n");
26378 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26379 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26380 msleep(10000);
26381 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26382 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26383
26384 rc = controller_reset_failed(h->cfgtable);
26385 if (rc)
26386 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
26387 cciss_scsi_setup(h);
26388
26389 /* Turn the interrupts on so we can service requests */
26390 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26391 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26392
26393 /* Get the firmware version */
26394 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
26395 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
26396 kfree(flush_buf);
26397 if (return_code != IO_OK)
26398 dev_warn(&h->pdev->dev, "Error flushing cache\n");
26399 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26400 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26401 free_irq(h->intr[h->intr_mode], h);
26402 }
26403
26404 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
26405 index 7fda30e..eb5dfe0 100644
26406 --- a/drivers/block/cciss.h
26407 +++ b/drivers/block/cciss.h
26408 @@ -101,7 +101,7 @@ struct ctlr_info
26409 /* information about each logical volume */
26410 drive_info_struct *drv[CISS_MAX_LUN];
26411
26412 - struct access_method access;
26413 + struct access_method *access;
26414
26415 /* queue and queue Info */
26416 struct list_head reqQ;
26417 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
26418 index 9125bbe..eede5c8 100644
26419 --- a/drivers/block/cpqarray.c
26420 +++ b/drivers/block/cpqarray.c
26421 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26422 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
26423 goto Enomem4;
26424 }
26425 - hba[i]->access.set_intr_mask(hba[i], 0);
26426 + hba[i]->access->set_intr_mask(hba[i], 0);
26427 if (request_irq(hba[i]->intr, do_ida_intr,
26428 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
26429 {
26430 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26431 add_timer(&hba[i]->timer);
26432
26433 /* Enable IRQ now that spinlock and rate limit timer are set up */
26434 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26435 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26436
26437 for(j=0; j<NWD; j++) {
26438 struct gendisk *disk = ida_gendisk[i][j];
26439 @@ -694,7 +694,7 @@ DBGINFO(
26440 for(i=0; i<NR_PRODUCTS; i++) {
26441 if (board_id == products[i].board_id) {
26442 c->product_name = products[i].product_name;
26443 - c->access = *(products[i].access);
26444 + c->access = products[i].access;
26445 break;
26446 }
26447 }
26448 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
26449 hba[ctlr]->intr = intr;
26450 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
26451 hba[ctlr]->product_name = products[j].product_name;
26452 - hba[ctlr]->access = *(products[j].access);
26453 + hba[ctlr]->access = products[j].access;
26454 hba[ctlr]->ctlr = ctlr;
26455 hba[ctlr]->board_id = board_id;
26456 hba[ctlr]->pci_dev = NULL; /* not PCI */
26457 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
26458
26459 while((c = h->reqQ) != NULL) {
26460 /* Can't do anything if we're busy */
26461 - if (h->access.fifo_full(h) == 0)
26462 + if (h->access->fifo_full(h) == 0)
26463 return;
26464
26465 /* Get the first entry from the request Q */
26466 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
26467 h->Qdepth--;
26468
26469 /* Tell the controller to do our bidding */
26470 - h->access.submit_command(h, c);
26471 + h->access->submit_command(h, c);
26472
26473 /* Get onto the completion Q */
26474 addQ(&h->cmpQ, c);
26475 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26476 unsigned long flags;
26477 __u32 a,a1;
26478
26479 - istat = h->access.intr_pending(h);
26480 + istat = h->access->intr_pending(h);
26481 /* Is this interrupt for us? */
26482 if (istat == 0)
26483 return IRQ_NONE;
26484 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26485 */
26486 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
26487 if (istat & FIFO_NOT_EMPTY) {
26488 - while((a = h->access.command_completed(h))) {
26489 + while((a = h->access->command_completed(h))) {
26490 a1 = a; a &= ~3;
26491 if ((c = h->cmpQ) == NULL)
26492 {
26493 @@ -1449,11 +1449,11 @@ static int sendcmd(
26494 /*
26495 * Disable interrupt
26496 */
26497 - info_p->access.set_intr_mask(info_p, 0);
26498 + info_p->access->set_intr_mask(info_p, 0);
26499 /* Make sure there is room in the command FIFO */
26500 /* Actually it should be completely empty at this time. */
26501 for (i = 200000; i > 0; i--) {
26502 - temp = info_p->access.fifo_full(info_p);
26503 + temp = info_p->access->fifo_full(info_p);
26504 if (temp != 0) {
26505 break;
26506 }
26507 @@ -1466,7 +1466,7 @@ DBG(
26508 /*
26509 * Send the cmd
26510 */
26511 - info_p->access.submit_command(info_p, c);
26512 + info_p->access->submit_command(info_p, c);
26513 complete = pollcomplete(ctlr);
26514
26515 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
26516 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
26517 * we check the new geometry. Then turn interrupts back on when
26518 * we're done.
26519 */
26520 - host->access.set_intr_mask(host, 0);
26521 + host->access->set_intr_mask(host, 0);
26522 getgeometry(ctlr);
26523 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
26524 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
26525
26526 for(i=0; i<NWD; i++) {
26527 struct gendisk *disk = ida_gendisk[ctlr][i];
26528 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
26529 /* Wait (up to 2 seconds) for a command to complete */
26530
26531 for (i = 200000; i > 0; i--) {
26532 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
26533 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
26534 if (done == 0) {
26535 udelay(10); /* a short fixed delay */
26536 } else
26537 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
26538 index be73e9d..7fbf140 100644
26539 --- a/drivers/block/cpqarray.h
26540 +++ b/drivers/block/cpqarray.h
26541 @@ -99,7 +99,7 @@ struct ctlr_info {
26542 drv_info_t drv[NWD];
26543 struct proc_dir_entry *proc;
26544
26545 - struct access_method access;
26546 + struct access_method *access;
26547
26548 cmdlist_t *reqQ;
26549 cmdlist_t *cmpQ;
26550 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
26551 index 9cf2035..bffca95 100644
26552 --- a/drivers/block/drbd/drbd_int.h
26553 +++ b/drivers/block/drbd/drbd_int.h
26554 @@ -736,7 +736,7 @@ struct drbd_request;
26555 struct drbd_epoch {
26556 struct list_head list;
26557 unsigned int barrier_nr;
26558 - atomic_t epoch_size; /* increased on every request added. */
26559 + atomic_unchecked_t epoch_size; /* increased on every request added. */
26560 atomic_t active; /* increased on every req. added, and dec on every finished. */
26561 unsigned long flags;
26562 };
26563 @@ -1108,7 +1108,7 @@ struct drbd_conf {
26564 void *int_dig_in;
26565 void *int_dig_vv;
26566 wait_queue_head_t seq_wait;
26567 - atomic_t packet_seq;
26568 + atomic_unchecked_t packet_seq;
26569 unsigned int peer_seq;
26570 spinlock_t peer_seq_lock;
26571 unsigned int minor;
26572 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
26573
26574 static inline void drbd_tcp_cork(struct socket *sock)
26575 {
26576 - int __user val = 1;
26577 + int val = 1;
26578 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26579 - (char __user *)&val, sizeof(val));
26580 + (char __force_user *)&val, sizeof(val));
26581 }
26582
26583 static inline void drbd_tcp_uncork(struct socket *sock)
26584 {
26585 - int __user val = 0;
26586 + int val = 0;
26587 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26588 - (char __user *)&val, sizeof(val));
26589 + (char __force_user *)&val, sizeof(val));
26590 }
26591
26592 static inline void drbd_tcp_nodelay(struct socket *sock)
26593 {
26594 - int __user val = 1;
26595 + int val = 1;
26596 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
26597 - (char __user *)&val, sizeof(val));
26598 + (char __force_user *)&val, sizeof(val));
26599 }
26600
26601 static inline void drbd_tcp_quickack(struct socket *sock)
26602 {
26603 - int __user val = 2;
26604 + int val = 2;
26605 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
26606 - (char __user *)&val, sizeof(val));
26607 + (char __force_user *)&val, sizeof(val));
26608 }
26609
26610 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
26611 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
26612 index 0358e55..bc33689 100644
26613 --- a/drivers/block/drbd/drbd_main.c
26614 +++ b/drivers/block/drbd/drbd_main.c
26615 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
26616 p.sector = sector;
26617 p.block_id = block_id;
26618 p.blksize = blksize;
26619 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
26620 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
26621
26622 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
26623 return false;
26624 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
26625 p.sector = cpu_to_be64(req->sector);
26626 p.block_id = (unsigned long)req;
26627 p.seq_num = cpu_to_be32(req->seq_num =
26628 - atomic_add_return(1, &mdev->packet_seq));
26629 + atomic_add_return_unchecked(1, &mdev->packet_seq));
26630
26631 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
26632
26633 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
26634 atomic_set(&mdev->unacked_cnt, 0);
26635 atomic_set(&mdev->local_cnt, 0);
26636 atomic_set(&mdev->net_cnt, 0);
26637 - atomic_set(&mdev->packet_seq, 0);
26638 + atomic_set_unchecked(&mdev->packet_seq, 0);
26639 atomic_set(&mdev->pp_in_use, 0);
26640 atomic_set(&mdev->pp_in_use_by_net, 0);
26641 atomic_set(&mdev->rs_sect_in, 0);
26642 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
26643 mdev->receiver.t_state);
26644
26645 /* no need to lock it, I'm the only thread alive */
26646 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
26647 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
26648 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
26649 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
26650 mdev->al_writ_cnt =
26651 mdev->bm_writ_cnt =
26652 mdev->read_cnt =
26653 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
26654 index af2a250..219c74b 100644
26655 --- a/drivers/block/drbd/drbd_nl.c
26656 +++ b/drivers/block/drbd/drbd_nl.c
26657 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
26658 module_put(THIS_MODULE);
26659 }
26660
26661 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26662 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26663
26664 static unsigned short *
26665 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
26666 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
26667 cn_reply->id.idx = CN_IDX_DRBD;
26668 cn_reply->id.val = CN_VAL_DRBD;
26669
26670 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26671 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26672 cn_reply->ack = 0; /* not used here. */
26673 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26674 (int)((char *)tl - (char *)reply->tag_list);
26675 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
26676 cn_reply->id.idx = CN_IDX_DRBD;
26677 cn_reply->id.val = CN_VAL_DRBD;
26678
26679 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26680 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26681 cn_reply->ack = 0; /* not used here. */
26682 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26683 (int)((char *)tl - (char *)reply->tag_list);
26684 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
26685 cn_reply->id.idx = CN_IDX_DRBD;
26686 cn_reply->id.val = CN_VAL_DRBD;
26687
26688 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
26689 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
26690 cn_reply->ack = 0; // not used here.
26691 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26692 (int)((char*)tl - (char*)reply->tag_list);
26693 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
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 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
26703 index 43beaca..4a5b1dd 100644
26704 --- a/drivers/block/drbd/drbd_receiver.c
26705 +++ b/drivers/block/drbd/drbd_receiver.c
26706 @@ -894,7 +894,7 @@ retry:
26707 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
26708 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
26709
26710 - atomic_set(&mdev->packet_seq, 0);
26711 + atomic_set_unchecked(&mdev->packet_seq, 0);
26712 mdev->peer_seq = 0;
26713
26714 drbd_thread_start(&mdev->asender);
26715 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26716 do {
26717 next_epoch = NULL;
26718
26719 - epoch_size = atomic_read(&epoch->epoch_size);
26720 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
26721
26722 switch (ev & ~EV_CLEANUP) {
26723 case EV_PUT:
26724 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26725 rv = FE_DESTROYED;
26726 } else {
26727 epoch->flags = 0;
26728 - atomic_set(&epoch->epoch_size, 0);
26729 + atomic_set_unchecked(&epoch->epoch_size, 0);
26730 /* atomic_set(&epoch->active, 0); is already zero */
26731 if (rv == FE_STILL_LIVE)
26732 rv = FE_RECYCLED;
26733 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26734 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
26735 drbd_flush(mdev);
26736
26737 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26738 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
26739 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
26740 if (epoch)
26741 break;
26742 }
26743
26744 epoch = mdev->current_epoch;
26745 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
26746 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
26747
26748 D_ASSERT(atomic_read(&epoch->active) == 0);
26749 D_ASSERT(epoch->flags == 0);
26750 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26751 }
26752
26753 epoch->flags = 0;
26754 - atomic_set(&epoch->epoch_size, 0);
26755 + atomic_set_unchecked(&epoch->epoch_size, 0);
26756 atomic_set(&epoch->active, 0);
26757
26758 spin_lock(&mdev->epoch_lock);
26759 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26760 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
26761 list_add(&epoch->list, &mdev->current_epoch->list);
26762 mdev->current_epoch = epoch;
26763 mdev->epochs++;
26764 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
26765 spin_unlock(&mdev->peer_seq_lock);
26766
26767 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
26768 - atomic_inc(&mdev->current_epoch->epoch_size);
26769 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
26770 return drbd_drain_block(mdev, data_size);
26771 }
26772
26773 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
26774
26775 spin_lock(&mdev->epoch_lock);
26776 e->epoch = mdev->current_epoch;
26777 - atomic_inc(&e->epoch->epoch_size);
26778 + atomic_inc_unchecked(&e->epoch->epoch_size);
26779 atomic_inc(&e->epoch->active);
26780 spin_unlock(&mdev->epoch_lock);
26781
26782 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
26783 D_ASSERT(list_empty(&mdev->done_ee));
26784
26785 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
26786 - atomic_set(&mdev->current_epoch->epoch_size, 0);
26787 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
26788 D_ASSERT(list_empty(&mdev->current_epoch->list));
26789 }
26790
26791 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
26792 index 1e888c9..05cf1b0 100644
26793 --- a/drivers/block/loop.c
26794 +++ b/drivers/block/loop.c
26795 @@ -227,7 +227,7 @@ static int __do_lo_send_write(struct file *file,
26796 mm_segment_t old_fs = get_fs();
26797
26798 set_fs(get_ds());
26799 - bw = file->f_op->write(file, buf, len, &pos);
26800 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
26801 set_fs(old_fs);
26802 if (likely(bw == len))
26803 return 0;
26804 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
26805 index 4364303..9adf4ee 100644
26806 --- a/drivers/char/Kconfig
26807 +++ b/drivers/char/Kconfig
26808 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
26809
26810 config DEVKMEM
26811 bool "/dev/kmem virtual device support"
26812 - default y
26813 + default n
26814 + depends on !GRKERNSEC_KMEM
26815 help
26816 Say Y here if you want to support the /dev/kmem device. The
26817 /dev/kmem device is rarely used, but can be used for certain
26818 @@ -596,6 +597,7 @@ config DEVPORT
26819 bool
26820 depends on !M68K
26821 depends on ISA || PCI
26822 + depends on !GRKERNSEC_KMEM
26823 default y
26824
26825 source "drivers/s390/char/Kconfig"
26826 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
26827 index 2e04433..22afc64 100644
26828 --- a/drivers/char/agp/frontend.c
26829 +++ b/drivers/char/agp/frontend.c
26830 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
26831 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
26832 return -EFAULT;
26833
26834 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
26835 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
26836 return -EFAULT;
26837
26838 client = agp_find_client_by_pid(reserve.pid);
26839 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
26840 index 095ab90..afad0a4 100644
26841 --- a/drivers/char/briq_panel.c
26842 +++ b/drivers/char/briq_panel.c
26843 @@ -9,6 +9,7 @@
26844 #include <linux/types.h>
26845 #include <linux/errno.h>
26846 #include <linux/tty.h>
26847 +#include <linux/mutex.h>
26848 #include <linux/timer.h>
26849 #include <linux/kernel.h>
26850 #include <linux/wait.h>
26851 @@ -34,6 +35,7 @@ static int vfd_is_open;
26852 static unsigned char vfd[40];
26853 static int vfd_cursor;
26854 static unsigned char ledpb, led;
26855 +static DEFINE_MUTEX(vfd_mutex);
26856
26857 static void update_vfd(void)
26858 {
26859 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
26860 if (!vfd_is_open)
26861 return -EBUSY;
26862
26863 + mutex_lock(&vfd_mutex);
26864 for (;;) {
26865 char c;
26866 if (!indx)
26867 break;
26868 - if (get_user(c, buf))
26869 + if (get_user(c, buf)) {
26870 + mutex_unlock(&vfd_mutex);
26871 return -EFAULT;
26872 + }
26873 if (esc) {
26874 set_led(c);
26875 esc = 0;
26876 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
26877 buf++;
26878 }
26879 update_vfd();
26880 + mutex_unlock(&vfd_mutex);
26881
26882 return len;
26883 }
26884 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
26885 index f773a9d..65cd683 100644
26886 --- a/drivers/char/genrtc.c
26887 +++ b/drivers/char/genrtc.c
26888 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
26889 switch (cmd) {
26890
26891 case RTC_PLL_GET:
26892 + memset(&pll, 0, sizeof(pll));
26893 if (get_rtc_pll(&pll))
26894 return -EINVAL;
26895 else
26896 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
26897 index 0833896..cccce52 100644
26898 --- a/drivers/char/hpet.c
26899 +++ b/drivers/char/hpet.c
26900 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
26901 }
26902
26903 static int
26904 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
26905 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
26906 struct hpet_info *info)
26907 {
26908 struct hpet_timer __iomem *timer;
26909 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
26910 index 58c0e63..46c16bf 100644
26911 --- a/drivers/char/ipmi/ipmi_msghandler.c
26912 +++ b/drivers/char/ipmi/ipmi_msghandler.c
26913 @@ -415,7 +415,7 @@ struct ipmi_smi {
26914 struct proc_dir_entry *proc_dir;
26915 char proc_dir_name[10];
26916
26917 - atomic_t stats[IPMI_NUM_STATS];
26918 + atomic_unchecked_t stats[IPMI_NUM_STATS];
26919
26920 /*
26921 * run_to_completion duplicate of smb_info, smi_info
26922 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
26923
26924
26925 #define ipmi_inc_stat(intf, stat) \
26926 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
26927 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
26928 #define ipmi_get_stat(intf, stat) \
26929 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
26930 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
26931
26932 static int is_lan_addr(struct ipmi_addr *addr)
26933 {
26934 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
26935 INIT_LIST_HEAD(&intf->cmd_rcvrs);
26936 init_waitqueue_head(&intf->waitq);
26937 for (i = 0; i < IPMI_NUM_STATS; i++)
26938 - atomic_set(&intf->stats[i], 0);
26939 + atomic_set_unchecked(&intf->stats[i], 0);
26940
26941 intf->proc_dir = NULL;
26942
26943 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
26944 index 9397ab4..d01bee1 100644
26945 --- a/drivers/char/ipmi/ipmi_si_intf.c
26946 +++ b/drivers/char/ipmi/ipmi_si_intf.c
26947 @@ -277,7 +277,7 @@ struct smi_info {
26948 unsigned char slave_addr;
26949
26950 /* Counters and things for the proc filesystem. */
26951 - atomic_t stats[SI_NUM_STATS];
26952 + atomic_unchecked_t stats[SI_NUM_STATS];
26953
26954 struct task_struct *thread;
26955
26956 @@ -286,9 +286,9 @@ struct smi_info {
26957 };
26958
26959 #define smi_inc_stat(smi, stat) \
26960 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
26961 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
26962 #define smi_get_stat(smi, stat) \
26963 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
26964 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
26965
26966 #define SI_MAX_PARMS 4
26967
26968 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
26969 atomic_set(&new_smi->req_events, 0);
26970 new_smi->run_to_completion = 0;
26971 for (i = 0; i < SI_NUM_STATS; i++)
26972 - atomic_set(&new_smi->stats[i], 0);
26973 + atomic_set_unchecked(&new_smi->stats[i], 0);
26974
26975 new_smi->interrupt_disabled = 1;
26976 atomic_set(&new_smi->stop_operation, 0);
26977 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
26978 index 1aeaaba..e018570 100644
26979 --- a/drivers/char/mbcs.c
26980 +++ b/drivers/char/mbcs.c
26981 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
26982 return 0;
26983 }
26984
26985 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
26986 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
26987 {
26988 .part_num = MBCS_PART_NUM,
26989 .mfg_num = MBCS_MFG_NUM,
26990 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
26991 index 1451790..f705c30 100644
26992 --- a/drivers/char/mem.c
26993 +++ b/drivers/char/mem.c
26994 @@ -18,6 +18,7 @@
26995 #include <linux/raw.h>
26996 #include <linux/tty.h>
26997 #include <linux/capability.h>
26998 +#include <linux/security.h>
26999 #include <linux/ptrace.h>
27000 #include <linux/device.h>
27001 #include <linux/highmem.h>
27002 @@ -35,6 +36,10 @@
27003 # include <linux/efi.h>
27004 #endif
27005
27006 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27007 +extern const struct file_operations grsec_fops;
27008 +#endif
27009 +
27010 static inline unsigned long size_inside_page(unsigned long start,
27011 unsigned long size)
27012 {
27013 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27014
27015 while (cursor < to) {
27016 if (!devmem_is_allowed(pfn)) {
27017 +#ifdef CONFIG_GRKERNSEC_KMEM
27018 + gr_handle_mem_readwrite(from, to);
27019 +#else
27020 printk(KERN_INFO
27021 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
27022 current->comm, from, to);
27023 +#endif
27024 return 0;
27025 }
27026 cursor += PAGE_SIZE;
27027 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27028 }
27029 return 1;
27030 }
27031 +#elif defined(CONFIG_GRKERNSEC_KMEM)
27032 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27033 +{
27034 + return 0;
27035 +}
27036 #else
27037 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27038 {
27039 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27040
27041 while (count > 0) {
27042 unsigned long remaining;
27043 + char *temp;
27044
27045 sz = size_inside_page(p, count);
27046
27047 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27048 if (!ptr)
27049 return -EFAULT;
27050
27051 - remaining = copy_to_user(buf, ptr, sz);
27052 +#ifdef CONFIG_PAX_USERCOPY
27053 + temp = kmalloc(sz, GFP_KERNEL);
27054 + if (!temp) {
27055 + unxlate_dev_mem_ptr(p, ptr);
27056 + return -ENOMEM;
27057 + }
27058 + memcpy(temp, ptr, sz);
27059 +#else
27060 + temp = ptr;
27061 +#endif
27062 +
27063 + remaining = copy_to_user(buf, temp, sz);
27064 +
27065 +#ifdef CONFIG_PAX_USERCOPY
27066 + kfree(temp);
27067 +#endif
27068 +
27069 unxlate_dev_mem_ptr(p, ptr);
27070 if (remaining)
27071 return -EFAULT;
27072 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27073 size_t count, loff_t *ppos)
27074 {
27075 unsigned long p = *ppos;
27076 - ssize_t low_count, read, sz;
27077 + ssize_t low_count, read, sz, err = 0;
27078 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
27079 - int err = 0;
27080
27081 read = 0;
27082 if (p < (unsigned long) high_memory) {
27083 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27084 }
27085 #endif
27086 while (low_count > 0) {
27087 + char *temp;
27088 +
27089 sz = size_inside_page(p, low_count);
27090
27091 /*
27092 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27093 */
27094 kbuf = xlate_dev_kmem_ptr((char *)p);
27095
27096 - if (copy_to_user(buf, kbuf, sz))
27097 +#ifdef CONFIG_PAX_USERCOPY
27098 + temp = kmalloc(sz, GFP_KERNEL);
27099 + if (!temp)
27100 + return -ENOMEM;
27101 + memcpy(temp, kbuf, sz);
27102 +#else
27103 + temp = kbuf;
27104 +#endif
27105 +
27106 + err = copy_to_user(buf, temp, sz);
27107 +
27108 +#ifdef CONFIG_PAX_USERCOPY
27109 + kfree(temp);
27110 +#endif
27111 +
27112 + if (err)
27113 return -EFAULT;
27114 buf += sz;
27115 p += sz;
27116 @@ -867,6 +914,9 @@ static const struct memdev {
27117 #ifdef CONFIG_CRASH_DUMP
27118 [12] = { "oldmem", 0, &oldmem_fops, NULL },
27119 #endif
27120 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27121 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
27122 +#endif
27123 };
27124
27125 static int memory_open(struct inode *inode, struct file *filp)
27126 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
27127 index da3cfee..a5a6606 100644
27128 --- a/drivers/char/nvram.c
27129 +++ b/drivers/char/nvram.c
27130 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
27131
27132 spin_unlock_irq(&rtc_lock);
27133
27134 - if (copy_to_user(buf, contents, tmp - contents))
27135 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
27136 return -EFAULT;
27137
27138 *ppos = i;
27139 diff --git a/drivers/char/random.c b/drivers/char/random.c
27140 index 6035ab8..bdfe4fd 100644
27141 --- a/drivers/char/random.c
27142 +++ b/drivers/char/random.c
27143 @@ -261,8 +261,13 @@
27144 /*
27145 * Configuration information
27146 */
27147 +#ifdef CONFIG_GRKERNSEC_RANDNET
27148 +#define INPUT_POOL_WORDS 512
27149 +#define OUTPUT_POOL_WORDS 128
27150 +#else
27151 #define INPUT_POOL_WORDS 128
27152 #define OUTPUT_POOL_WORDS 32
27153 +#endif
27154 #define SEC_XFER_SIZE 512
27155 #define EXTRACT_SIZE 10
27156
27157 @@ -300,10 +305,17 @@ static struct poolinfo {
27158 int poolwords;
27159 int tap1, tap2, tap3, tap4, tap5;
27160 } poolinfo_table[] = {
27161 +#ifdef CONFIG_GRKERNSEC_RANDNET
27162 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
27163 + { 512, 411, 308, 208, 104, 1 },
27164 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
27165 + { 128, 103, 76, 51, 25, 1 },
27166 +#else
27167 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
27168 { 128, 103, 76, 51, 25, 1 },
27169 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
27170 { 32, 26, 20, 14, 7, 1 },
27171 +#endif
27172 #if 0
27173 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
27174 { 2048, 1638, 1231, 819, 411, 1 },
27175 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
27176
27177 extract_buf(r, tmp);
27178 i = min_t(int, nbytes, EXTRACT_SIZE);
27179 - if (copy_to_user(buf, tmp, i)) {
27180 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
27181 ret = -EFAULT;
27182 break;
27183 }
27184 @@ -1228,7 +1240,7 @@ EXPORT_SYMBOL(generate_random_uuid);
27185 #include <linux/sysctl.h>
27186
27187 static int min_read_thresh = 8, min_write_thresh;
27188 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
27189 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
27190 static int max_write_thresh = INPUT_POOL_WORDS * 32;
27191 static char sysctl_bootid[16];
27192
27193 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
27194 index 1ee8ce7..b778bef 100644
27195 --- a/drivers/char/sonypi.c
27196 +++ b/drivers/char/sonypi.c
27197 @@ -55,6 +55,7 @@
27198 #include <asm/uaccess.h>
27199 #include <asm/io.h>
27200 #include <asm/system.h>
27201 +#include <asm/local.h>
27202
27203 #include <linux/sonypi.h>
27204
27205 @@ -491,7 +492,7 @@ static struct sonypi_device {
27206 spinlock_t fifo_lock;
27207 wait_queue_head_t fifo_proc_list;
27208 struct fasync_struct *fifo_async;
27209 - int open_count;
27210 + local_t open_count;
27211 int model;
27212 struct input_dev *input_jog_dev;
27213 struct input_dev *input_key_dev;
27214 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
27215 static int sonypi_misc_release(struct inode *inode, struct file *file)
27216 {
27217 mutex_lock(&sonypi_device.lock);
27218 - sonypi_device.open_count--;
27219 + local_dec(&sonypi_device.open_count);
27220 mutex_unlock(&sonypi_device.lock);
27221 return 0;
27222 }
27223 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
27224 {
27225 mutex_lock(&sonypi_device.lock);
27226 /* Flush input queue on first open */
27227 - if (!sonypi_device.open_count)
27228 + if (!local_read(&sonypi_device.open_count))
27229 kfifo_reset(&sonypi_device.fifo);
27230 - sonypi_device.open_count++;
27231 + local_inc(&sonypi_device.open_count);
27232 mutex_unlock(&sonypi_device.lock);
27233
27234 return 0;
27235 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
27236 index 361a1df..2471eee 100644
27237 --- a/drivers/char/tpm/tpm.c
27238 +++ b/drivers/char/tpm/tpm.c
27239 @@ -414,7 +414,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
27240 chip->vendor.req_complete_val)
27241 goto out_recv;
27242
27243 - if ((status == chip->vendor.req_canceled)) {
27244 + if (status == chip->vendor.req_canceled) {
27245 dev_err(chip->dev, "Operation Canceled\n");
27246 rc = -ECANCELED;
27247 goto out;
27248 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
27249 index 0636520..169c1d0 100644
27250 --- a/drivers/char/tpm/tpm_bios.c
27251 +++ b/drivers/char/tpm/tpm_bios.c
27252 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
27253 event = addr;
27254
27255 if ((event->event_type == 0 && event->event_size == 0) ||
27256 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
27257 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
27258 return NULL;
27259
27260 return addr;
27261 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
27262 return NULL;
27263
27264 if ((event->event_type == 0 && event->event_size == 0) ||
27265 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
27266 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
27267 return NULL;
27268
27269 (*pos)++;
27270 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
27271 int i;
27272
27273 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
27274 - seq_putc(m, data[i]);
27275 + if (!seq_putc(m, data[i]))
27276 + return -EFAULT;
27277
27278 return 0;
27279 }
27280 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
27281 log->bios_event_log_end = log->bios_event_log + len;
27282
27283 virt = acpi_os_map_memory(start, len);
27284 + if (!virt) {
27285 + kfree(log->bios_event_log);
27286 + log->bios_event_log = NULL;
27287 + return -EFAULT;
27288 + }
27289
27290 - memcpy(log->bios_event_log, virt, len);
27291 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
27292
27293 acpi_os_unmap_memory(virt, len);
27294 return 0;
27295 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
27296 index 8e3c46d..c139b99 100644
27297 --- a/drivers/char/virtio_console.c
27298 +++ b/drivers/char/virtio_console.c
27299 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
27300 if (to_user) {
27301 ssize_t ret;
27302
27303 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
27304 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
27305 if (ret)
27306 return -EFAULT;
27307 } else {
27308 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
27309 if (!port_has_data(port) && !port->host_connected)
27310 return 0;
27311
27312 - return fill_readbuf(port, ubuf, count, true);
27313 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
27314 }
27315
27316 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
27317 diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
27318 index eb1d864..39ee5a7 100644
27319 --- a/drivers/dma/dmatest.c
27320 +++ b/drivers/dma/dmatest.c
27321 @@ -591,7 +591,7 @@ static int dmatest_add_channel(struct dma_chan *chan)
27322 }
27323 if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
27324 cnt = dmatest_add_threads(dtc, DMA_PQ);
27325 - thread_count += cnt > 0 ?: 0;
27326 + thread_count += cnt > 0 ? cnt : 0;
27327 }
27328
27329 pr_info("dmatest: Started %u threads using %s\n",
27330 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
27331 index c9eee6d..f9d5280 100644
27332 --- a/drivers/edac/amd64_edac.c
27333 +++ b/drivers/edac/amd64_edac.c
27334 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
27335 * PCI core identifies what devices are on a system during boot, and then
27336 * inquiry this table to see if this driver is for a given device found.
27337 */
27338 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
27339 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
27340 {
27341 .vendor = PCI_VENDOR_ID_AMD,
27342 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
27343 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
27344 index e47e73b..348e0bd 100644
27345 --- a/drivers/edac/amd76x_edac.c
27346 +++ b/drivers/edac/amd76x_edac.c
27347 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
27348 edac_mc_free(mci);
27349 }
27350
27351 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
27352 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
27353 {
27354 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27355 AMD762},
27356 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
27357 index 1af531a..3a8ff27 100644
27358 --- a/drivers/edac/e752x_edac.c
27359 +++ b/drivers/edac/e752x_edac.c
27360 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
27361 edac_mc_free(mci);
27362 }
27363
27364 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
27365 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
27366 {
27367 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27368 E7520},
27369 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
27370 index 6ffb6d2..383d8d7 100644
27371 --- a/drivers/edac/e7xxx_edac.c
27372 +++ b/drivers/edac/e7xxx_edac.c
27373 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
27374 edac_mc_free(mci);
27375 }
27376
27377 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
27378 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
27379 {
27380 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27381 E7205},
27382 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
27383 index 495198a..ac08c85 100644
27384 --- a/drivers/edac/edac_pci_sysfs.c
27385 +++ b/drivers/edac/edac_pci_sysfs.c
27386 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
27387 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
27388 static int edac_pci_poll_msec = 1000; /* one second workq period */
27389
27390 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
27391 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
27392 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
27393 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
27394
27395 static struct kobject *edac_pci_top_main_kobj;
27396 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
27397 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27398 edac_printk(KERN_CRIT, EDAC_PCI,
27399 "Signaled System Error on %s\n",
27400 pci_name(dev));
27401 - atomic_inc(&pci_nonparity_count);
27402 + atomic_inc_unchecked(&pci_nonparity_count);
27403 }
27404
27405 if (status & (PCI_STATUS_PARITY)) {
27406 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27407 "Master Data Parity Error on %s\n",
27408 pci_name(dev));
27409
27410 - atomic_inc(&pci_parity_count);
27411 + atomic_inc_unchecked(&pci_parity_count);
27412 }
27413
27414 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27415 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27416 "Detected Parity Error on %s\n",
27417 pci_name(dev));
27418
27419 - atomic_inc(&pci_parity_count);
27420 + atomic_inc_unchecked(&pci_parity_count);
27421 }
27422 }
27423
27424 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27425 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
27426 "Signaled System Error on %s\n",
27427 pci_name(dev));
27428 - atomic_inc(&pci_nonparity_count);
27429 + atomic_inc_unchecked(&pci_nonparity_count);
27430 }
27431
27432 if (status & (PCI_STATUS_PARITY)) {
27433 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27434 "Master Data Parity Error on "
27435 "%s\n", pci_name(dev));
27436
27437 - atomic_inc(&pci_parity_count);
27438 + atomic_inc_unchecked(&pci_parity_count);
27439 }
27440
27441 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27442 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27443 "Detected Parity Error on %s\n",
27444 pci_name(dev));
27445
27446 - atomic_inc(&pci_parity_count);
27447 + atomic_inc_unchecked(&pci_parity_count);
27448 }
27449 }
27450 }
27451 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
27452 if (!check_pci_errors)
27453 return;
27454
27455 - before_count = atomic_read(&pci_parity_count);
27456 + before_count = atomic_read_unchecked(&pci_parity_count);
27457
27458 /* scan all PCI devices looking for a Parity Error on devices and
27459 * bridges.
27460 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
27461 /* Only if operator has selected panic on PCI Error */
27462 if (edac_pci_get_panic_on_pe()) {
27463 /* If the count is different 'after' from 'before' */
27464 - if (before_count != atomic_read(&pci_parity_count))
27465 + if (before_count != atomic_read_unchecked(&pci_parity_count))
27466 panic("EDAC: PCI Parity Error");
27467 }
27468 }
27469 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
27470 index c0510b3..6e2a954 100644
27471 --- a/drivers/edac/i3000_edac.c
27472 +++ b/drivers/edac/i3000_edac.c
27473 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
27474 edac_mc_free(mci);
27475 }
27476
27477 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
27478 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
27479 {
27480 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27481 I3000},
27482 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
27483 index aa08497..7e6822a 100644
27484 --- a/drivers/edac/i3200_edac.c
27485 +++ b/drivers/edac/i3200_edac.c
27486 @@ -456,7 +456,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
27487 edac_mc_free(mci);
27488 }
27489
27490 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
27491 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
27492 {
27493 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27494 I3200},
27495 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
27496 index 4dc3ac2..67d05a6 100644
27497 --- a/drivers/edac/i5000_edac.c
27498 +++ b/drivers/edac/i5000_edac.c
27499 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
27500 *
27501 * The "E500P" device is the first device supported.
27502 */
27503 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
27504 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
27505 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
27506 .driver_data = I5000P},
27507
27508 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
27509 index bcbdeec..9886d16 100644
27510 --- a/drivers/edac/i5100_edac.c
27511 +++ b/drivers/edac/i5100_edac.c
27512 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
27513 edac_mc_free(mci);
27514 }
27515
27516 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
27517 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
27518 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
27519 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
27520 { 0, }
27521 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
27522 index 74d6ec34..baff517 100644
27523 --- a/drivers/edac/i5400_edac.c
27524 +++ b/drivers/edac/i5400_edac.c
27525 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
27526 *
27527 * The "E500P" device is the first device supported.
27528 */
27529 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
27530 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
27531 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
27532 {0,} /* 0 terminated list. */
27533 };
27534 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
27535 index 6104dba..e7ea8e1 100644
27536 --- a/drivers/edac/i7300_edac.c
27537 +++ b/drivers/edac/i7300_edac.c
27538 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
27539 *
27540 * Has only 8086:360c PCI ID
27541 */
27542 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
27543 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
27544 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
27545 {0,} /* 0 terminated list. */
27546 };
27547 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
27548 index 70ad892..178943c 100644
27549 --- a/drivers/edac/i7core_edac.c
27550 +++ b/drivers/edac/i7core_edac.c
27551 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
27552 /*
27553 * pci_device_id table for which devices we are looking for
27554 */
27555 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
27556 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
27557 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
27558 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
27559 {0,} /* 0 terminated list. */
27560 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
27561 index 4329d39..f3022ef 100644
27562 --- a/drivers/edac/i82443bxgx_edac.c
27563 +++ b/drivers/edac/i82443bxgx_edac.c
27564 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
27565
27566 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
27567
27568 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
27569 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
27570 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
27571 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
27572 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
27573 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
27574 index 931a057..fd28340 100644
27575 --- a/drivers/edac/i82860_edac.c
27576 +++ b/drivers/edac/i82860_edac.c
27577 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
27578 edac_mc_free(mci);
27579 }
27580
27581 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
27582 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
27583 {
27584 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27585 I82860},
27586 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
27587 index 33864c6..01edc61 100644
27588 --- a/drivers/edac/i82875p_edac.c
27589 +++ b/drivers/edac/i82875p_edac.c
27590 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
27591 edac_mc_free(mci);
27592 }
27593
27594 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
27595 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
27596 {
27597 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27598 I82875P},
27599 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
27600 index a5da732..983363b 100644
27601 --- a/drivers/edac/i82975x_edac.c
27602 +++ b/drivers/edac/i82975x_edac.c
27603 @@ -604,7 +604,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
27604 edac_mc_free(mci);
27605 }
27606
27607 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
27608 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
27609 {
27610 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27611 I82975X
27612 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
27613 index 0106747..0b40417 100644
27614 --- a/drivers/edac/mce_amd.h
27615 +++ b/drivers/edac/mce_amd.h
27616 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
27617 bool (*dc_mce)(u16, u8);
27618 bool (*ic_mce)(u16, u8);
27619 bool (*nb_mce)(u16, u8);
27620 -};
27621 +} __no_const;
27622
27623 void amd_report_gart_errors(bool);
27624 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
27625 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
27626 index b153674..ad2ba9b 100644
27627 --- a/drivers/edac/r82600_edac.c
27628 +++ b/drivers/edac/r82600_edac.c
27629 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
27630 edac_mc_free(mci);
27631 }
27632
27633 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
27634 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
27635 {
27636 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
27637 },
27638 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
27639 index 7a402bf..af0b211 100644
27640 --- a/drivers/edac/sb_edac.c
27641 +++ b/drivers/edac/sb_edac.c
27642 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
27643 /*
27644 * pci_device_id table for which devices we are looking for
27645 */
27646 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
27647 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
27648 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
27649 {0,} /* 0 terminated list. */
27650 };
27651 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
27652 index b6f47de..c5acf3a 100644
27653 --- a/drivers/edac/x38_edac.c
27654 +++ b/drivers/edac/x38_edac.c
27655 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
27656 edac_mc_free(mci);
27657 }
27658
27659 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
27660 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
27661 {
27662 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27663 X38},
27664 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
27665 index 85661b0..c784559a 100644
27666 --- a/drivers/firewire/core-card.c
27667 +++ b/drivers/firewire/core-card.c
27668 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
27669
27670 void fw_core_remove_card(struct fw_card *card)
27671 {
27672 - struct fw_card_driver dummy_driver = dummy_driver_template;
27673 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
27674
27675 card->driver->update_phy_reg(card, 4,
27676 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
27677 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
27678 index 4799393..37bd3ab 100644
27679 --- a/drivers/firewire/core-cdev.c
27680 +++ b/drivers/firewire/core-cdev.c
27681 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
27682 int ret;
27683
27684 if ((request->channels == 0 && request->bandwidth == 0) ||
27685 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
27686 - request->bandwidth < 0)
27687 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
27688 return -EINVAL;
27689
27690 r = kmalloc(sizeof(*r), GFP_KERNEL);
27691 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
27692 index 855ab3f..11f4bbd 100644
27693 --- a/drivers/firewire/core-transaction.c
27694 +++ b/drivers/firewire/core-transaction.c
27695 @@ -37,6 +37,7 @@
27696 #include <linux/timer.h>
27697 #include <linux/types.h>
27698 #include <linux/workqueue.h>
27699 +#include <linux/sched.h>
27700
27701 #include <asm/byteorder.h>
27702
27703 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
27704 index b45be57..5fad18b 100644
27705 --- a/drivers/firewire/core.h
27706 +++ b/drivers/firewire/core.h
27707 @@ -101,6 +101,7 @@ struct fw_card_driver {
27708
27709 int (*stop_iso)(struct fw_iso_context *ctx);
27710 };
27711 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
27712
27713 void fw_card_initialize(struct fw_card *card,
27714 const struct fw_card_driver *driver, struct device *device);
27715 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
27716 index 153980b..4b4d046 100644
27717 --- a/drivers/firmware/dmi_scan.c
27718 +++ b/drivers/firmware/dmi_scan.c
27719 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
27720 }
27721 }
27722 else {
27723 - /*
27724 - * no iounmap() for that ioremap(); it would be a no-op, but
27725 - * it's so early in setup that sucker gets confused into doing
27726 - * what it shouldn't if we actually call it.
27727 - */
27728 p = dmi_ioremap(0xF0000, 0x10000);
27729 if (p == NULL)
27730 goto error;
27731 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
27732 if (buf == NULL)
27733 return -1;
27734
27735 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
27736 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
27737
27738 iounmap(buf);
27739 return 0;
27740 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
27741 index 98723cb..10ca85b 100644
27742 --- a/drivers/gpio/gpio-vr41xx.c
27743 +++ b/drivers/gpio/gpio-vr41xx.c
27744 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
27745 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
27746 maskl, pendl, maskh, pendh);
27747
27748 - atomic_inc(&irq_err_count);
27749 + atomic_inc_unchecked(&irq_err_count);
27750
27751 return -EINVAL;
27752 }
27753 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
27754 index 8323fc3..5c1d755 100644
27755 --- a/drivers/gpu/drm/drm_crtc.c
27756 +++ b/drivers/gpu/drm/drm_crtc.c
27757 @@ -1379,7 +1379,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27758 */
27759 if ((out_resp->count_modes >= mode_count) && mode_count) {
27760 copied = 0;
27761 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
27762 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
27763 list_for_each_entry(mode, &connector->modes, head) {
27764 drm_crtc_convert_to_umode(&u_mode, mode);
27765 if (copy_to_user(mode_ptr + copied,
27766 @@ -1394,8 +1394,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27767
27768 if ((out_resp->count_props >= props_count) && props_count) {
27769 copied = 0;
27770 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
27771 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
27772 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
27773 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
27774 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
27775 if (connector->property_ids[i] != 0) {
27776 if (put_user(connector->property_ids[i],
27777 @@ -1417,7 +1417,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27778
27779 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
27780 copied = 0;
27781 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
27782 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
27783 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
27784 if (connector->encoder_ids[i] != 0) {
27785 if (put_user(connector->encoder_ids[i],
27786 @@ -1576,7 +1576,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
27787 }
27788
27789 for (i = 0; i < crtc_req->count_connectors; i++) {
27790 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
27791 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
27792 if (get_user(out_id, &set_connectors_ptr[i])) {
27793 ret = -EFAULT;
27794 goto out;
27795 @@ -1857,7 +1857,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
27796 fb = obj_to_fb(obj);
27797
27798 num_clips = r->num_clips;
27799 - clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
27800 + clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
27801
27802 if (!num_clips != !clips_ptr) {
27803 ret = -EINVAL;
27804 @@ -2283,7 +2283,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
27805 out_resp->flags = property->flags;
27806
27807 if ((out_resp->count_values >= value_count) && value_count) {
27808 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
27809 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
27810 for (i = 0; i < value_count; i++) {
27811 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
27812 ret = -EFAULT;
27813 @@ -2296,7 +2296,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
27814 if (property->flags & DRM_MODE_PROP_ENUM) {
27815 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
27816 copied = 0;
27817 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
27818 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
27819 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
27820
27821 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
27822 @@ -2319,7 +2319,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
27823 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
27824 copied = 0;
27825 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
27826 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
27827 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
27828
27829 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
27830 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
27831 @@ -2380,7 +2380,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
27832 struct drm_mode_get_blob *out_resp = data;
27833 struct drm_property_blob *blob;
27834 int ret = 0;
27835 - void *blob_ptr;
27836 + void __user *blob_ptr;
27837
27838 if (!drm_core_check_feature(dev, DRIVER_MODESET))
27839 return -EINVAL;
27840 @@ -2394,7 +2394,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
27841 blob = obj_to_blob(obj);
27842
27843 if (out_resp->length == blob->length) {
27844 - blob_ptr = (void *)(unsigned long)out_resp->data;
27845 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
27846 if (copy_to_user(blob_ptr, blob->data, blob->length)){
27847 ret = -EFAULT;
27848 goto done;
27849 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
27850 index d2619d7..bd6bd00 100644
27851 --- a/drivers/gpu/drm/drm_crtc_helper.c
27852 +++ b/drivers/gpu/drm/drm_crtc_helper.c
27853 @@ -279,7 +279,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
27854 struct drm_crtc *tmp;
27855 int crtc_mask = 1;
27856
27857 - WARN(!crtc, "checking null crtc?\n");
27858 + BUG_ON(!crtc);
27859
27860 dev = crtc->dev;
27861
27862 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
27863 index 40c187c..5746164 100644
27864 --- a/drivers/gpu/drm/drm_drv.c
27865 +++ b/drivers/gpu/drm/drm_drv.c
27866 @@ -308,7 +308,7 @@ module_exit(drm_core_exit);
27867 /**
27868 * Copy and IOCTL return string to user space
27869 */
27870 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
27871 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
27872 {
27873 int len;
27874
27875 @@ -387,7 +387,7 @@ long drm_ioctl(struct file *filp,
27876
27877 dev = file_priv->minor->dev;
27878 atomic_inc(&dev->ioctl_count);
27879 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
27880 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
27881 ++file_priv->ioctl_count;
27882
27883 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
27884 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
27885 index 828bf65..cdaa0e9 100644
27886 --- a/drivers/gpu/drm/drm_fops.c
27887 +++ b/drivers/gpu/drm/drm_fops.c
27888 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
27889 }
27890
27891 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
27892 - atomic_set(&dev->counts[i], 0);
27893 + atomic_set_unchecked(&dev->counts[i], 0);
27894
27895 dev->sigdata.lock = NULL;
27896
27897 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
27898
27899 retcode = drm_open_helper(inode, filp, dev);
27900 if (!retcode) {
27901 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
27902 - if (!dev->open_count++)
27903 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
27904 + if (local_inc_return(&dev->open_count) == 1)
27905 retcode = drm_setup(dev);
27906 }
27907 if (!retcode) {
27908 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
27909
27910 mutex_lock(&drm_global_mutex);
27911
27912 - DRM_DEBUG("open_count = %d\n", dev->open_count);
27913 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
27914
27915 if (dev->driver->preclose)
27916 dev->driver->preclose(dev, file_priv);
27917 @@ -485,7 +485,7 @@ int drm_release(struct inode *inode, struct file *filp)
27918 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
27919 task_pid_nr(current),
27920 (long)old_encode_dev(file_priv->minor->device),
27921 - dev->open_count);
27922 + local_read(&dev->open_count));
27923
27924 /* Release any auth tokens that might point to this file_priv,
27925 (do that under the drm_global_mutex) */
27926 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
27927 * End inline drm_release
27928 */
27929
27930 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
27931 - if (!--dev->open_count) {
27932 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
27933 + if (local_dec_and_test(&dev->open_count)) {
27934 if (atomic_read(&dev->ioctl_count)) {
27935 DRM_ERROR("Device busy: %d\n",
27936 atomic_read(&dev->ioctl_count));
27937 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
27938 index c87dc96..326055d 100644
27939 --- a/drivers/gpu/drm/drm_global.c
27940 +++ b/drivers/gpu/drm/drm_global.c
27941 @@ -36,7 +36,7 @@
27942 struct drm_global_item {
27943 struct mutex mutex;
27944 void *object;
27945 - int refcount;
27946 + atomic_t refcount;
27947 };
27948
27949 static struct drm_global_item glob[DRM_GLOBAL_NUM];
27950 @@ -49,7 +49,7 @@ void drm_global_init(void)
27951 struct drm_global_item *item = &glob[i];
27952 mutex_init(&item->mutex);
27953 item->object = NULL;
27954 - item->refcount = 0;
27955 + atomic_set(&item->refcount, 0);
27956 }
27957 }
27958
27959 @@ -59,7 +59,7 @@ void drm_global_release(void)
27960 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
27961 struct drm_global_item *item = &glob[i];
27962 BUG_ON(item->object != NULL);
27963 - BUG_ON(item->refcount != 0);
27964 + BUG_ON(atomic_read(&item->refcount) != 0);
27965 }
27966 }
27967
27968 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
27969 void *object;
27970
27971 mutex_lock(&item->mutex);
27972 - if (item->refcount == 0) {
27973 + if (atomic_read(&item->refcount) == 0) {
27974 item->object = kzalloc(ref->size, GFP_KERNEL);
27975 if (unlikely(item->object == NULL)) {
27976 ret = -ENOMEM;
27977 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
27978 goto out_err;
27979
27980 }
27981 - ++item->refcount;
27982 + atomic_inc(&item->refcount);
27983 ref->object = item->object;
27984 object = item->object;
27985 mutex_unlock(&item->mutex);
27986 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
27987 struct drm_global_item *item = &glob[ref->global_type];
27988
27989 mutex_lock(&item->mutex);
27990 - BUG_ON(item->refcount == 0);
27991 + BUG_ON(atomic_read(&item->refcount) == 0);
27992 BUG_ON(ref->object != item->object);
27993 - if (--item->refcount == 0) {
27994 + if (atomic_dec_and_test(&item->refcount)) {
27995 ref->release(ref);
27996 item->object = NULL;
27997 }
27998 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
27999 index ab1162d..42587b2 100644
28000 --- a/drivers/gpu/drm/drm_info.c
28001 +++ b/drivers/gpu/drm/drm_info.c
28002 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
28003 struct drm_local_map *map;
28004 struct drm_map_list *r_list;
28005
28006 - /* Hardcoded from _DRM_FRAME_BUFFER,
28007 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
28008 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
28009 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
28010 + static const char * const types[] = {
28011 + [_DRM_FRAME_BUFFER] = "FB",
28012 + [_DRM_REGISTERS] = "REG",
28013 + [_DRM_SHM] = "SHM",
28014 + [_DRM_AGP] = "AGP",
28015 + [_DRM_SCATTER_GATHER] = "SG",
28016 + [_DRM_CONSISTENT] = "PCI",
28017 + [_DRM_GEM] = "GEM" };
28018 const char *type;
28019 int i;
28020
28021 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
28022 map = r_list->map;
28023 if (!map)
28024 continue;
28025 - if (map->type < 0 || map->type > 5)
28026 + if (map->type >= ARRAY_SIZE(types))
28027 type = "??";
28028 else
28029 type = types[map->type];
28030 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
28031 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
28032 vma->vm_flags & VM_LOCKED ? 'l' : '-',
28033 vma->vm_flags & VM_IO ? 'i' : '-',
28034 +#ifdef CONFIG_GRKERNSEC_HIDESYM
28035 + 0);
28036 +#else
28037 vma->vm_pgoff);
28038 +#endif
28039
28040 #if defined(__i386__)
28041 pgprot = pgprot_val(vma->vm_page_prot);
28042 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
28043 index ddd70db..40321e6 100644
28044 --- a/drivers/gpu/drm/drm_ioc32.c
28045 +++ b/drivers/gpu/drm/drm_ioc32.c
28046 @@ -456,7 +456,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
28047 request = compat_alloc_user_space(nbytes);
28048 if (!access_ok(VERIFY_WRITE, request, nbytes))
28049 return -EFAULT;
28050 - list = (struct drm_buf_desc *) (request + 1);
28051 + list = (struct drm_buf_desc __user *) (request + 1);
28052
28053 if (__put_user(count, &request->count)
28054 || __put_user(list, &request->list))
28055 @@ -517,7 +517,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
28056 request = compat_alloc_user_space(nbytes);
28057 if (!access_ok(VERIFY_WRITE, request, nbytes))
28058 return -EFAULT;
28059 - list = (struct drm_buf_pub *) (request + 1);
28060 + list = (struct drm_buf_pub __user *) (request + 1);
28061
28062 if (__put_user(count, &request->count)
28063 || __put_user(list, &request->list))
28064 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
28065 index 904d7e9..ab88581 100644
28066 --- a/drivers/gpu/drm/drm_ioctl.c
28067 +++ b/drivers/gpu/drm/drm_ioctl.c
28068 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev, void *data,
28069 stats->data[i].value =
28070 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
28071 else
28072 - stats->data[i].value = atomic_read(&dev->counts[i]);
28073 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
28074 stats->data[i].type = dev->types[i];
28075 }
28076
28077 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
28078 index 632ae24..244cf4a 100644
28079 --- a/drivers/gpu/drm/drm_lock.c
28080 +++ b/drivers/gpu/drm/drm_lock.c
28081 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28082 if (drm_lock_take(&master->lock, lock->context)) {
28083 master->lock.file_priv = file_priv;
28084 master->lock.lock_time = jiffies;
28085 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
28086 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
28087 break; /* Got lock */
28088 }
28089
28090 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28091 return -EINVAL;
28092 }
28093
28094 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
28095 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
28096
28097 if (drm_lock_free(&master->lock, lock->context)) {
28098 /* FIXME: Should really bail out here. */
28099 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
28100 index 8f371e8..9f85d52 100644
28101 --- a/drivers/gpu/drm/i810/i810_dma.c
28102 +++ b/drivers/gpu/drm/i810/i810_dma.c
28103 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
28104 dma->buflist[vertex->idx],
28105 vertex->discard, vertex->used);
28106
28107 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28108 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28109 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28110 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28111 sarea_priv->last_enqueue = dev_priv->counter - 1;
28112 sarea_priv->last_dispatch = (int)hw_status[5];
28113
28114 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
28115 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
28116 mc->last_render);
28117
28118 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28119 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28120 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28121 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28122 sarea_priv->last_enqueue = dev_priv->counter - 1;
28123 sarea_priv->last_dispatch = (int)hw_status[5];
28124
28125 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
28126 index c9339f4..f5e1b9d 100644
28127 --- a/drivers/gpu/drm/i810/i810_drv.h
28128 +++ b/drivers/gpu/drm/i810/i810_drv.h
28129 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
28130 int page_flipping;
28131
28132 wait_queue_head_t irq_queue;
28133 - atomic_t irq_received;
28134 - atomic_t irq_emitted;
28135 + atomic_unchecked_t irq_received;
28136 + atomic_unchecked_t irq_emitted;
28137
28138 int front_offset;
28139 } drm_i810_private_t;
28140 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
28141 index 004b048..7588eba 100644
28142 --- a/drivers/gpu/drm/i915/i915_debugfs.c
28143 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
28144 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
28145 I915_READ(GTIMR));
28146 }
28147 seq_printf(m, "Interrupts received: %d\n",
28148 - atomic_read(&dev_priv->irq_received));
28149 + atomic_read_unchecked(&dev_priv->irq_received));
28150 for (i = 0; i < I915_NUM_RINGS; i++) {
28151 if (IS_GEN6(dev) || IS_GEN7(dev)) {
28152 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
28153 @@ -1232,7 +1232,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
28154 return ret;
28155
28156 if (opregion->header)
28157 - seq_write(m, opregion->header, OPREGION_SIZE);
28158 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
28159
28160 mutex_unlock(&dev->struct_mutex);
28161
28162 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
28163 index a9ae374..43c1e9e 100644
28164 --- a/drivers/gpu/drm/i915/i915_dma.c
28165 +++ b/drivers/gpu/drm/i915/i915_dma.c
28166 @@ -1172,7 +1172,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
28167 bool can_switch;
28168
28169 spin_lock(&dev->count_lock);
28170 - can_switch = (dev->open_count == 0);
28171 + can_switch = (local_read(&dev->open_count) == 0);
28172 spin_unlock(&dev->count_lock);
28173 return can_switch;
28174 }
28175 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
28176 index 554bef7..d24791c 100644
28177 --- a/drivers/gpu/drm/i915/i915_drv.h
28178 +++ b/drivers/gpu/drm/i915/i915_drv.h
28179 @@ -229,7 +229,7 @@ struct drm_i915_display_funcs {
28180 /* render clock increase/decrease */
28181 /* display clock increase/decrease */
28182 /* pll clock increase/decrease */
28183 -};
28184 +} __no_const;
28185
28186 struct intel_device_info {
28187 u8 gen;
28188 @@ -312,7 +312,7 @@ typedef struct drm_i915_private {
28189 int current_page;
28190 int page_flipping;
28191
28192 - atomic_t irq_received;
28193 + atomic_unchecked_t irq_received;
28194
28195 /* protects the irq masks */
28196 spinlock_t irq_lock;
28197 @@ -887,7 +887,7 @@ struct drm_i915_gem_object {
28198 * will be page flipped away on the next vblank. When it
28199 * reaches 0, dev_priv->pending_flip_queue will be woken up.
28200 */
28201 - atomic_t pending_flip;
28202 + atomic_unchecked_t pending_flip;
28203 };
28204
28205 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
28206 @@ -1267,7 +1267,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
28207 extern void intel_teardown_gmbus(struct drm_device *dev);
28208 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
28209 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
28210 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28211 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28212 {
28213 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
28214 }
28215 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28216 index b9da890..cad1d98 100644
28217 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28218 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28219 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
28220 i915_gem_clflush_object(obj);
28221
28222 if (obj->base.pending_write_domain)
28223 - cd->flips |= atomic_read(&obj->pending_flip);
28224 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
28225
28226 /* The actual obj->write_domain will be updated with
28227 * pending_write_domain after we emit the accumulated flush for all
28228 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
28229
28230 static int
28231 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
28232 - int count)
28233 + unsigned int count)
28234 {
28235 - int i;
28236 + unsigned int i;
28237
28238 for (i = 0; i < count; i++) {
28239 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
28240 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
28241 index b40004b..7c53a75 100644
28242 --- a/drivers/gpu/drm/i915/i915_irq.c
28243 +++ b/drivers/gpu/drm/i915/i915_irq.c
28244 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
28245 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
28246 struct drm_i915_master_private *master_priv;
28247
28248 - atomic_inc(&dev_priv->irq_received);
28249 + atomic_inc_unchecked(&dev_priv->irq_received);
28250
28251 /* disable master interrupt before clearing iir */
28252 de_ier = I915_READ(DEIER);
28253 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
28254 struct drm_i915_master_private *master_priv;
28255 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
28256
28257 - atomic_inc(&dev_priv->irq_received);
28258 + atomic_inc_unchecked(&dev_priv->irq_received);
28259
28260 if (IS_GEN6(dev))
28261 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
28262 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
28263 int ret = IRQ_NONE, pipe;
28264 bool blc_event = false;
28265
28266 - atomic_inc(&dev_priv->irq_received);
28267 + atomic_inc_unchecked(&dev_priv->irq_received);
28268
28269 iir = I915_READ(IIR);
28270
28271 @@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
28272 {
28273 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28274
28275 - atomic_set(&dev_priv->irq_received, 0);
28276 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28277
28278 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28279 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28280 @@ -1931,7 +1931,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
28281 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28282 int pipe;
28283
28284 - atomic_set(&dev_priv->irq_received, 0);
28285 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28286
28287 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28288 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28289 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
28290 index daa5743..c0757a9 100644
28291 --- a/drivers/gpu/drm/i915/intel_display.c
28292 +++ b/drivers/gpu/drm/i915/intel_display.c
28293 @@ -2230,7 +2230,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
28294
28295 wait_event(dev_priv->pending_flip_queue,
28296 atomic_read(&dev_priv->mm.wedged) ||
28297 - atomic_read(&obj->pending_flip) == 0);
28298 + atomic_read_unchecked(&obj->pending_flip) == 0);
28299
28300 /* Big Hammer, we also need to ensure that any pending
28301 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
28302 @@ -2851,7 +2851,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
28303 obj = to_intel_framebuffer(crtc->fb)->obj;
28304 dev_priv = crtc->dev->dev_private;
28305 wait_event(dev_priv->pending_flip_queue,
28306 - atomic_read(&obj->pending_flip) == 0);
28307 + atomic_read_unchecked(&obj->pending_flip) == 0);
28308 }
28309
28310 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
28311 @@ -6952,7 +6952,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
28312
28313 atomic_clear_mask(1 << intel_crtc->plane,
28314 &obj->pending_flip.counter);
28315 - if (atomic_read(&obj->pending_flip) == 0)
28316 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
28317 wake_up(&dev_priv->pending_flip_queue);
28318
28319 schedule_work(&work->work);
28320 @@ -7242,7 +7242,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28321 /* Block clients from rendering to the new back buffer until
28322 * the flip occurs and the object is no longer visible.
28323 */
28324 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28325 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28326
28327 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
28328 if (ret)
28329 @@ -7256,7 +7256,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28330 return 0;
28331
28332 cleanup_pending:
28333 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28334 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28335 drm_gem_object_unreference(&work->old_fb_obj->base);
28336 drm_gem_object_unreference(&obj->base);
28337 mutex_unlock(&dev->struct_mutex);
28338 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
28339 index 54558a0..2d97005 100644
28340 --- a/drivers/gpu/drm/mga/mga_drv.h
28341 +++ b/drivers/gpu/drm/mga/mga_drv.h
28342 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
28343 u32 clear_cmd;
28344 u32 maccess;
28345
28346 - atomic_t vbl_received; /**< Number of vblanks received. */
28347 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
28348 wait_queue_head_t fence_queue;
28349 - atomic_t last_fence_retired;
28350 + atomic_unchecked_t last_fence_retired;
28351 u32 next_fence_to_post;
28352
28353 unsigned int fb_cpp;
28354 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
28355 index 2581202..f230a8d9 100644
28356 --- a/drivers/gpu/drm/mga/mga_irq.c
28357 +++ b/drivers/gpu/drm/mga/mga_irq.c
28358 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
28359 if (crtc != 0)
28360 return 0;
28361
28362 - return atomic_read(&dev_priv->vbl_received);
28363 + return atomic_read_unchecked(&dev_priv->vbl_received);
28364 }
28365
28366
28367 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28368 /* VBLANK interrupt */
28369 if (status & MGA_VLINEPEN) {
28370 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
28371 - atomic_inc(&dev_priv->vbl_received);
28372 + atomic_inc_unchecked(&dev_priv->vbl_received);
28373 drm_handle_vblank(dev, 0);
28374 handled = 1;
28375 }
28376 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28377 if ((prim_start & ~0x03) != (prim_end & ~0x03))
28378 MGA_WRITE(MGA_PRIMEND, prim_end);
28379
28380 - atomic_inc(&dev_priv->last_fence_retired);
28381 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
28382 DRM_WAKEUP(&dev_priv->fence_queue);
28383 handled = 1;
28384 }
28385 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
28386 * using fences.
28387 */
28388 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
28389 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
28390 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
28391 - *sequence) <= (1 << 23)));
28392
28393 *sequence = cur_fence;
28394 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
28395 index 5fc201b..7b032b9 100644
28396 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
28397 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
28398 @@ -201,7 +201,7 @@ struct methods {
28399 const char desc[8];
28400 void (*loadbios)(struct drm_device *, uint8_t *);
28401 const bool rw;
28402 -};
28403 +} __do_const;
28404
28405 static struct methods shadow_methods[] = {
28406 { "PRAMIN", load_vbios_pramin, true },
28407 @@ -5474,7 +5474,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
28408 struct bit_table {
28409 const char id;
28410 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
28411 -};
28412 +} __no_const;
28413
28414 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
28415
28416 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
28417 index 4c0be3a..5757582 100644
28418 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
28419 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
28420 @@ -238,7 +238,7 @@ struct nouveau_channel {
28421 struct list_head pending;
28422 uint32_t sequence;
28423 uint32_t sequence_ack;
28424 - atomic_t last_sequence_irq;
28425 + atomic_unchecked_t last_sequence_irq;
28426 struct nouveau_vma vma;
28427 } fence;
28428
28429 @@ -319,7 +319,7 @@ struct nouveau_exec_engine {
28430 u32 handle, u16 class);
28431 void (*set_tile_region)(struct drm_device *dev, int i);
28432 void (*tlb_flush)(struct drm_device *, int engine);
28433 -};
28434 +} __no_const;
28435
28436 struct nouveau_instmem_engine {
28437 void *priv;
28438 @@ -341,13 +341,13 @@ struct nouveau_instmem_engine {
28439 struct nouveau_mc_engine {
28440 int (*init)(struct drm_device *dev);
28441 void (*takedown)(struct drm_device *dev);
28442 -};
28443 +} __no_const;
28444
28445 struct nouveau_timer_engine {
28446 int (*init)(struct drm_device *dev);
28447 void (*takedown)(struct drm_device *dev);
28448 uint64_t (*read)(struct drm_device *dev);
28449 -};
28450 +} __no_const;
28451
28452 struct nouveau_fb_engine {
28453 int num_tiles;
28454 @@ -558,7 +558,7 @@ struct nouveau_vram_engine {
28455 void (*put)(struct drm_device *, struct nouveau_mem **);
28456
28457 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
28458 -};
28459 +} __no_const;
28460
28461 struct nouveau_engine {
28462 struct nouveau_instmem_engine instmem;
28463 @@ -706,7 +706,7 @@ struct drm_nouveau_private {
28464 struct drm_global_reference mem_global_ref;
28465 struct ttm_bo_global_ref bo_global_ref;
28466 struct ttm_bo_device bdev;
28467 - atomic_t validate_sequence;
28468 + atomic_unchecked_t validate_sequence;
28469 } ttm;
28470
28471 struct {
28472 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
28473 index 2f6daae..c9d7b9e 100644
28474 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
28475 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
28476 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
28477 if (USE_REFCNT(dev))
28478 sequence = nvchan_rd32(chan, 0x48);
28479 else
28480 - sequence = atomic_read(&chan->fence.last_sequence_irq);
28481 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
28482
28483 if (chan->fence.sequence_ack == sequence)
28484 goto out;
28485 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
28486 return ret;
28487 }
28488
28489 - atomic_set(&chan->fence.last_sequence_irq, 0);
28490 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
28491 return 0;
28492 }
28493
28494 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
28495 index 5f0bc57..eb9fac8 100644
28496 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
28497 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
28498 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
28499 int trycnt = 0;
28500 int ret, i;
28501
28502 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
28503 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
28504 retry:
28505 if (++trycnt > 100000) {
28506 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
28507 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
28508 index d8831ab..0ba8356 100644
28509 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
28510 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
28511 @@ -542,7 +542,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
28512 bool can_switch;
28513
28514 spin_lock(&dev->count_lock);
28515 - can_switch = (dev->open_count == 0);
28516 + can_switch = (local_read(&dev->open_count) == 0);
28517 spin_unlock(&dev->count_lock);
28518 return can_switch;
28519 }
28520 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
28521 index dbdea8e..cd6eeeb 100644
28522 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
28523 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
28524 @@ -554,7 +554,7 @@ static int
28525 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
28526 u32 class, u32 mthd, u32 data)
28527 {
28528 - atomic_set(&chan->fence.last_sequence_irq, data);
28529 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
28530 return 0;
28531 }
28532
28533 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
28534 index bcac90b..53bfc76 100644
28535 --- a/drivers/gpu/drm/r128/r128_cce.c
28536 +++ b/drivers/gpu/drm/r128/r128_cce.c
28537 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
28538
28539 /* GH: Simple idle check.
28540 */
28541 - atomic_set(&dev_priv->idle_count, 0);
28542 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28543
28544 /* We don't support anything other than bus-mastering ring mode,
28545 * but the ring can be in either AGP or PCI space for the ring
28546 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
28547 index 930c71b..499aded 100644
28548 --- a/drivers/gpu/drm/r128/r128_drv.h
28549 +++ b/drivers/gpu/drm/r128/r128_drv.h
28550 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
28551 int is_pci;
28552 unsigned long cce_buffers_offset;
28553
28554 - atomic_t idle_count;
28555 + atomic_unchecked_t idle_count;
28556
28557 int page_flipping;
28558 int current_page;
28559 u32 crtc_offset;
28560 u32 crtc_offset_cntl;
28561
28562 - atomic_t vbl_received;
28563 + atomic_unchecked_t vbl_received;
28564
28565 u32 color_fmt;
28566 unsigned int front_offset;
28567 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
28568 index 429d5a0..7e899ed 100644
28569 --- a/drivers/gpu/drm/r128/r128_irq.c
28570 +++ b/drivers/gpu/drm/r128/r128_irq.c
28571 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
28572 if (crtc != 0)
28573 return 0;
28574
28575 - return atomic_read(&dev_priv->vbl_received);
28576 + return atomic_read_unchecked(&dev_priv->vbl_received);
28577 }
28578
28579 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28580 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28581 /* VBLANK interrupt */
28582 if (status & R128_CRTC_VBLANK_INT) {
28583 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
28584 - atomic_inc(&dev_priv->vbl_received);
28585 + atomic_inc_unchecked(&dev_priv->vbl_received);
28586 drm_handle_vblank(dev, 0);
28587 return IRQ_HANDLED;
28588 }
28589 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
28590 index a9e33ce..09edd4b 100644
28591 --- a/drivers/gpu/drm/r128/r128_state.c
28592 +++ b/drivers/gpu/drm/r128/r128_state.c
28593 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
28594
28595 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
28596 {
28597 - if (atomic_read(&dev_priv->idle_count) == 0)
28598 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
28599 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
28600 else
28601 - atomic_set(&dev_priv->idle_count, 0);
28602 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28603 }
28604
28605 #endif
28606 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
28607 index 5a82b6b..9e69c73 100644
28608 --- a/drivers/gpu/drm/radeon/mkregtable.c
28609 +++ b/drivers/gpu/drm/radeon/mkregtable.c
28610 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
28611 regex_t mask_rex;
28612 regmatch_t match[4];
28613 char buf[1024];
28614 - size_t end;
28615 + long end;
28616 int len;
28617 int done = 0;
28618 int r;
28619 unsigned o;
28620 struct offset *offset;
28621 char last_reg_s[10];
28622 - int last_reg;
28623 + unsigned long last_reg;
28624
28625 if (regcomp
28626 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
28627 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
28628 index 8227e76..ce0b195 100644
28629 --- a/drivers/gpu/drm/radeon/radeon.h
28630 +++ b/drivers/gpu/drm/radeon/radeon.h
28631 @@ -192,7 +192,7 @@ extern int sumo_get_temp(struct radeon_device *rdev);
28632 */
28633 struct radeon_fence_driver {
28634 uint32_t scratch_reg;
28635 - atomic_t seq;
28636 + atomic_unchecked_t seq;
28637 uint32_t last_seq;
28638 unsigned long last_jiffies;
28639 unsigned long last_timeout;
28640 @@ -530,7 +530,7 @@ struct r600_blit_cp_primitives {
28641 int x2, int y2);
28642 void (*draw_auto)(struct radeon_device *rdev);
28643 void (*set_default_state)(struct radeon_device *rdev);
28644 -};
28645 +} __no_const;
28646
28647 struct r600_blit {
28648 struct mutex mutex;
28649 @@ -954,7 +954,7 @@ struct radeon_asic {
28650 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
28651 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
28652 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
28653 -};
28654 +} __no_const;
28655
28656 /*
28657 * Asic structures
28658 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
28659 index 9b39145..389b93b 100644
28660 --- a/drivers/gpu/drm/radeon/radeon_device.c
28661 +++ b/drivers/gpu/drm/radeon/radeon_device.c
28662 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
28663 bool can_switch;
28664
28665 spin_lock(&dev->count_lock);
28666 - can_switch = (dev->open_count == 0);
28667 + can_switch = (local_read(&dev->open_count) == 0);
28668 spin_unlock(&dev->count_lock);
28669 return can_switch;
28670 }
28671 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
28672 index a1b59ca..86f2d44 100644
28673 --- a/drivers/gpu/drm/radeon/radeon_drv.h
28674 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
28675 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
28676
28677 /* SW interrupt */
28678 wait_queue_head_t swi_queue;
28679 - atomic_t swi_emitted;
28680 + atomic_unchecked_t swi_emitted;
28681 int vblank_crtc;
28682 uint32_t irq_enable_reg;
28683 uint32_t r500_disp_irq_reg;
28684 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
28685 index 76ec0e9..6feb1a3 100644
28686 --- a/drivers/gpu/drm/radeon/radeon_fence.c
28687 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
28688 @@ -78,7 +78,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
28689 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
28690 return 0;
28691 }
28692 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
28693 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
28694 if (!rdev->cp.ready)
28695 /* FIXME: cp is not running assume everythings is done right
28696 * away
28697 @@ -373,7 +373,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
28698 return r;
28699 }
28700 radeon_fence_write(rdev, 0);
28701 - atomic_set(&rdev->fence_drv.seq, 0);
28702 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
28703 INIT_LIST_HEAD(&rdev->fence_drv.created);
28704 INIT_LIST_HEAD(&rdev->fence_drv.emited);
28705 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
28706 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
28707 index 48b7cea..342236f 100644
28708 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
28709 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
28710 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
28711 request = compat_alloc_user_space(sizeof(*request));
28712 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
28713 || __put_user(req32.param, &request->param)
28714 - || __put_user((void __user *)(unsigned long)req32.value,
28715 + || __put_user((unsigned long)req32.value,
28716 &request->value))
28717 return -EFAULT;
28718
28719 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
28720 index 00da384..32f972d 100644
28721 --- a/drivers/gpu/drm/radeon/radeon_irq.c
28722 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
28723 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
28724 unsigned int ret;
28725 RING_LOCALS;
28726
28727 - atomic_inc(&dev_priv->swi_emitted);
28728 - ret = atomic_read(&dev_priv->swi_emitted);
28729 + atomic_inc_unchecked(&dev_priv->swi_emitted);
28730 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
28731
28732 BEGIN_RING(4);
28733 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
28734 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
28735 drm_radeon_private_t *dev_priv =
28736 (drm_radeon_private_t *) dev->dev_private;
28737
28738 - atomic_set(&dev_priv->swi_emitted, 0);
28739 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
28740 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
28741
28742 dev->max_vblank_count = 0x001fffff;
28743 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
28744 index e8422ae..d22d4a8 100644
28745 --- a/drivers/gpu/drm/radeon/radeon_state.c
28746 +++ b/drivers/gpu/drm/radeon/radeon_state.c
28747 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
28748 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
28749 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
28750
28751 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
28752 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
28753 sarea_priv->nbox * sizeof(depth_boxes[0])))
28754 return -EFAULT;
28755
28756 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
28757 {
28758 drm_radeon_private_t *dev_priv = dev->dev_private;
28759 drm_radeon_getparam_t *param = data;
28760 - int value;
28761 + int value = 0;
28762
28763 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
28764
28765 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
28766 index 0b5468b..9c4b308 100644
28767 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
28768 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
28769 @@ -672,8 +672,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
28770 }
28771 if (unlikely(ttm_vm_ops == NULL)) {
28772 ttm_vm_ops = vma->vm_ops;
28773 - radeon_ttm_vm_ops = *ttm_vm_ops;
28774 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
28775 + pax_open_kernel();
28776 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
28777 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
28778 + pax_close_kernel();
28779 }
28780 vma->vm_ops = &radeon_ttm_vm_ops;
28781 return 0;
28782 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
28783 index a9049ed..501f284 100644
28784 --- a/drivers/gpu/drm/radeon/rs690.c
28785 +++ b/drivers/gpu/drm/radeon/rs690.c
28786 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
28787 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
28788 rdev->pm.sideport_bandwidth.full)
28789 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
28790 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
28791 + read_delay_latency.full = dfixed_const(800 * 1000);
28792 read_delay_latency.full = dfixed_div(read_delay_latency,
28793 rdev->pm.igp_sideport_mclk);
28794 + a.full = dfixed_const(370);
28795 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
28796 } else {
28797 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
28798 rdev->pm.k8_bandwidth.full)
28799 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
28800 index 727e93d..1565650 100644
28801 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
28802 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
28803 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
28804 static int ttm_pool_mm_shrink(struct shrinker *shrink,
28805 struct shrink_control *sc)
28806 {
28807 - static atomic_t start_pool = ATOMIC_INIT(0);
28808 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
28809 unsigned i;
28810 - unsigned pool_offset = atomic_add_return(1, &start_pool);
28811 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
28812 struct ttm_page_pool *pool;
28813 int shrink_pages = sc->nr_to_scan;
28814
28815 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
28816 index 9cf87d9..2000b7d 100644
28817 --- a/drivers/gpu/drm/via/via_drv.h
28818 +++ b/drivers/gpu/drm/via/via_drv.h
28819 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
28820 typedef uint32_t maskarray_t[5];
28821
28822 typedef struct drm_via_irq {
28823 - atomic_t irq_received;
28824 + atomic_unchecked_t irq_received;
28825 uint32_t pending_mask;
28826 uint32_t enable_mask;
28827 wait_queue_head_t irq_queue;
28828 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
28829 struct timeval last_vblank;
28830 int last_vblank_valid;
28831 unsigned usec_per_vblank;
28832 - atomic_t vbl_received;
28833 + atomic_unchecked_t vbl_received;
28834 drm_via_state_t hc_state;
28835 char pci_buf[VIA_PCI_BUF_SIZE];
28836 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
28837 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
28838 index d391f48..10c8ca3 100644
28839 --- a/drivers/gpu/drm/via/via_irq.c
28840 +++ b/drivers/gpu/drm/via/via_irq.c
28841 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
28842 if (crtc != 0)
28843 return 0;
28844
28845 - return atomic_read(&dev_priv->vbl_received);
28846 + return atomic_read_unchecked(&dev_priv->vbl_received);
28847 }
28848
28849 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28850 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28851
28852 status = VIA_READ(VIA_REG_INTERRUPT);
28853 if (status & VIA_IRQ_VBLANK_PENDING) {
28854 - atomic_inc(&dev_priv->vbl_received);
28855 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
28856 + atomic_inc_unchecked(&dev_priv->vbl_received);
28857 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
28858 do_gettimeofday(&cur_vblank);
28859 if (dev_priv->last_vblank_valid) {
28860 dev_priv->usec_per_vblank =
28861 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28862 dev_priv->last_vblank = cur_vblank;
28863 dev_priv->last_vblank_valid = 1;
28864 }
28865 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
28866 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
28867 DRM_DEBUG("US per vblank is: %u\n",
28868 dev_priv->usec_per_vblank);
28869 }
28870 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28871
28872 for (i = 0; i < dev_priv->num_irqs; ++i) {
28873 if (status & cur_irq->pending_mask) {
28874 - atomic_inc(&cur_irq->irq_received);
28875 + atomic_inc_unchecked(&cur_irq->irq_received);
28876 DRM_WAKEUP(&cur_irq->irq_queue);
28877 handled = 1;
28878 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
28879 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
28880 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
28881 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
28882 masks[irq][4]));
28883 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
28884 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
28885 } else {
28886 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
28887 (((cur_irq_sequence =
28888 - atomic_read(&cur_irq->irq_received)) -
28889 + atomic_read_unchecked(&cur_irq->irq_received)) -
28890 *sequence) <= (1 << 23)));
28891 }
28892 *sequence = cur_irq_sequence;
28893 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
28894 }
28895
28896 for (i = 0; i < dev_priv->num_irqs; ++i) {
28897 - atomic_set(&cur_irq->irq_received, 0);
28898 + atomic_set_unchecked(&cur_irq->irq_received, 0);
28899 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
28900 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
28901 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
28902 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
28903 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
28904 case VIA_IRQ_RELATIVE:
28905 irqwait->request.sequence +=
28906 - atomic_read(&cur_irq->irq_received);
28907 + atomic_read_unchecked(&cur_irq->irq_received);
28908 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
28909 case VIA_IRQ_ABSOLUTE:
28910 break;
28911 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
28912 index dc27970..f18b008 100644
28913 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
28914 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
28915 @@ -260,7 +260,7 @@ struct vmw_private {
28916 * Fencing and IRQs.
28917 */
28918
28919 - atomic_t marker_seq;
28920 + atomic_unchecked_t marker_seq;
28921 wait_queue_head_t fence_queue;
28922 wait_queue_head_t fifo_queue;
28923 int fence_queue_waiters; /* Protected by hw_mutex */
28924 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
28925 index a0c2f12..68ae6cb 100644
28926 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
28927 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
28928 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
28929 (unsigned int) min,
28930 (unsigned int) fifo->capabilities);
28931
28932 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
28933 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
28934 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
28935 vmw_marker_queue_init(&fifo->marker_queue);
28936 return vmw_fifo_send_fence(dev_priv, &dummy);
28937 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
28938 if (reserveable)
28939 iowrite32(bytes, fifo_mem +
28940 SVGA_FIFO_RESERVED);
28941 - return fifo_mem + (next_cmd >> 2);
28942 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
28943 } else {
28944 need_bounce = true;
28945 }
28946 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
28947
28948 fm = vmw_fifo_reserve(dev_priv, bytes);
28949 if (unlikely(fm == NULL)) {
28950 - *seqno = atomic_read(&dev_priv->marker_seq);
28951 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
28952 ret = -ENOMEM;
28953 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
28954 false, 3*HZ);
28955 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
28956 }
28957
28958 do {
28959 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
28960 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
28961 } while (*seqno == 0);
28962
28963 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
28964 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
28965 index cabc95f..14b3d77 100644
28966 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
28967 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
28968 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
28969 * emitted. Then the fence is stale and signaled.
28970 */
28971
28972 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
28973 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
28974 > VMW_FENCE_WRAP);
28975
28976 return ret;
28977 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
28978
28979 if (fifo_idle)
28980 down_read(&fifo_state->rwsem);
28981 - signal_seq = atomic_read(&dev_priv->marker_seq);
28982 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
28983 ret = 0;
28984
28985 for (;;) {
28986 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
28987 index 8a8725c..afed796 100644
28988 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
28989 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
28990 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
28991 while (!vmw_lag_lt(queue, us)) {
28992 spin_lock(&queue->lock);
28993 if (list_empty(&queue->head))
28994 - seqno = atomic_read(&dev_priv->marker_seq);
28995 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
28996 else {
28997 marker = list_first_entry(&queue->head,
28998 struct vmw_marker, head);
28999 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
29000 index bb656d8..4169fca 100644
29001 --- a/drivers/hid/hid-core.c
29002 +++ b/drivers/hid/hid-core.c
29003 @@ -2012,7 +2012,7 @@ static bool hid_ignore(struct hid_device *hdev)
29004
29005 int hid_add_device(struct hid_device *hdev)
29006 {
29007 - static atomic_t id = ATOMIC_INIT(0);
29008 + static atomic_unchecked_t id = ATOMIC_INIT(0);
29009 int ret;
29010
29011 if (WARN_ON(hdev->status & HID_STAT_ADDED))
29012 @@ -2027,7 +2027,7 @@ int hid_add_device(struct hid_device *hdev)
29013 /* XXX hack, any other cleaner solution after the driver core
29014 * is converted to allow more than 20 bytes as the device name? */
29015 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
29016 - hdev->vendor, hdev->product, atomic_inc_return(&id));
29017 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
29018
29019 hid_debug_register(hdev, dev_name(&hdev->dev));
29020 ret = device_add(&hdev->dev);
29021 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
29022 index 4ef02b2..8a96831 100644
29023 --- a/drivers/hid/usbhid/hiddev.c
29024 +++ b/drivers/hid/usbhid/hiddev.c
29025 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29026 break;
29027
29028 case HIDIOCAPPLICATION:
29029 - if (arg < 0 || arg >= hid->maxapplication)
29030 + if (arg >= hid->maxapplication)
29031 break;
29032
29033 for (i = 0; i < hid->maxcollection; i++)
29034 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
29035 index 4065374..10ed7dc 100644
29036 --- a/drivers/hv/channel.c
29037 +++ b/drivers/hv/channel.c
29038 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
29039 int ret = 0;
29040 int t;
29041
29042 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
29043 - atomic_inc(&vmbus_connection.next_gpadl_handle);
29044 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
29045 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
29046
29047 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
29048 if (ret)
29049 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
29050 index 0fb100e..baf87e5 100644
29051 --- a/drivers/hv/hv.c
29052 +++ b/drivers/hv/hv.c
29053 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
29054 u64 output_address = (output) ? virt_to_phys(output) : 0;
29055 u32 output_address_hi = output_address >> 32;
29056 u32 output_address_lo = output_address & 0xFFFFFFFF;
29057 - void *hypercall_page = hv_context.hypercall_page;
29058 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
29059
29060 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
29061 "=a"(hv_status_lo) : "d" (control_hi),
29062 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
29063 index 0aee112..b72d21f 100644
29064 --- a/drivers/hv/hyperv_vmbus.h
29065 +++ b/drivers/hv/hyperv_vmbus.h
29066 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
29067 struct vmbus_connection {
29068 enum vmbus_connect_state conn_state;
29069
29070 - atomic_t next_gpadl_handle;
29071 + atomic_unchecked_t next_gpadl_handle;
29072
29073 /*
29074 * Represents channel interrupts. Each bit position represents a
29075 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
29076 index d2d0a2a..90b8f4d 100644
29077 --- a/drivers/hv/vmbus_drv.c
29078 +++ b/drivers/hv/vmbus_drv.c
29079 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
29080 {
29081 int ret = 0;
29082
29083 - static atomic_t device_num = ATOMIC_INIT(0);
29084 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
29085
29086 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
29087 - atomic_inc_return(&device_num));
29088 + atomic_inc_return_unchecked(&device_num));
29089
29090 child_device_obj->device.bus = &hv_bus;
29091 child_device_obj->device.parent = &hv_acpi_dev->dev;
29092 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
29093 index 66f6729..2d6de0a 100644
29094 --- a/drivers/hwmon/acpi_power_meter.c
29095 +++ b/drivers/hwmon/acpi_power_meter.c
29096 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
29097 return res;
29098
29099 temp /= 1000;
29100 - if (temp < 0)
29101 - return -EINVAL;
29102
29103 mutex_lock(&resource->lock);
29104 resource->trip[attr->index - 7] = temp;
29105 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
29106 index 5357925..6cf0418 100644
29107 --- a/drivers/hwmon/sht15.c
29108 +++ b/drivers/hwmon/sht15.c
29109 @@ -166,7 +166,7 @@ struct sht15_data {
29110 int supply_uV;
29111 bool supply_uV_valid;
29112 struct work_struct update_supply_work;
29113 - atomic_t interrupt_handled;
29114 + atomic_unchecked_t interrupt_handled;
29115 };
29116
29117 /**
29118 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
29119 return ret;
29120
29121 gpio_direction_input(data->pdata->gpio_data);
29122 - atomic_set(&data->interrupt_handled, 0);
29123 + atomic_set_unchecked(&data->interrupt_handled, 0);
29124
29125 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29126 if (gpio_get_value(data->pdata->gpio_data) == 0) {
29127 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
29128 /* Only relevant if the interrupt hasn't occurred. */
29129 - if (!atomic_read(&data->interrupt_handled))
29130 + if (!atomic_read_unchecked(&data->interrupt_handled))
29131 schedule_work(&data->read_work);
29132 }
29133 ret = wait_event_timeout(data->wait_queue,
29134 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
29135
29136 /* First disable the interrupt */
29137 disable_irq_nosync(irq);
29138 - atomic_inc(&data->interrupt_handled);
29139 + atomic_inc_unchecked(&data->interrupt_handled);
29140 /* Then schedule a reading work struct */
29141 if (data->state != SHT15_READING_NOTHING)
29142 schedule_work(&data->read_work);
29143 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
29144 * If not, then start the interrupt again - care here as could
29145 * have gone low in meantime so verify it hasn't!
29146 */
29147 - atomic_set(&data->interrupt_handled, 0);
29148 + atomic_set_unchecked(&data->interrupt_handled, 0);
29149 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29150 /* If still not occurred or another handler has been scheduled */
29151 if (gpio_get_value(data->pdata->gpio_data)
29152 - || atomic_read(&data->interrupt_handled))
29153 + || atomic_read_unchecked(&data->interrupt_handled))
29154 return;
29155 }
29156
29157 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
29158 index 378fcb5..5e91fa8 100644
29159 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
29160 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
29161 @@ -43,7 +43,7 @@
29162 extern struct i2c_adapter amd756_smbus;
29163
29164 static struct i2c_adapter *s4882_adapter;
29165 -static struct i2c_algorithm *s4882_algo;
29166 +static i2c_algorithm_no_const *s4882_algo;
29167
29168 /* Wrapper access functions for multiplexed SMBus */
29169 static DEFINE_MUTEX(amd756_lock);
29170 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
29171 index 29015eb..af2d8e9 100644
29172 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
29173 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
29174 @@ -41,7 +41,7 @@
29175 extern struct i2c_adapter *nforce2_smbus;
29176
29177 static struct i2c_adapter *s4985_adapter;
29178 -static struct i2c_algorithm *s4985_algo;
29179 +static i2c_algorithm_no_const *s4985_algo;
29180
29181 /* Wrapper access functions for multiplexed SMBus */
29182 static DEFINE_MUTEX(nforce2_lock);
29183 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
29184 index d7a4833..7fae376 100644
29185 --- a/drivers/i2c/i2c-mux.c
29186 +++ b/drivers/i2c/i2c-mux.c
29187 @@ -28,7 +28,7 @@
29188 /* multiplexer per channel data */
29189 struct i2c_mux_priv {
29190 struct i2c_adapter adap;
29191 - struct i2c_algorithm algo;
29192 + i2c_algorithm_no_const algo;
29193
29194 struct i2c_adapter *parent;
29195 void *mux_dev; /* the mux chip/device */
29196 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
29197 index 57d00ca..0145194 100644
29198 --- a/drivers/ide/aec62xx.c
29199 +++ b/drivers/ide/aec62xx.c
29200 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
29201 .cable_detect = atp86x_cable_detect,
29202 };
29203
29204 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
29205 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
29206 { /* 0: AEC6210 */
29207 .name = DRV_NAME,
29208 .init_chipset = init_chipset_aec62xx,
29209 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
29210 index 2c8016a..911a27c 100644
29211 --- a/drivers/ide/alim15x3.c
29212 +++ b/drivers/ide/alim15x3.c
29213 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
29214 .dma_sff_read_status = ide_dma_sff_read_status,
29215 };
29216
29217 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
29218 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
29219 .name = DRV_NAME,
29220 .init_chipset = init_chipset_ali15x3,
29221 .init_hwif = init_hwif_ali15x3,
29222 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
29223 index 3747b25..56fc995 100644
29224 --- a/drivers/ide/amd74xx.c
29225 +++ b/drivers/ide/amd74xx.c
29226 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
29227 .udma_mask = udma, \
29228 }
29229
29230 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
29231 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
29232 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
29233 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
29234 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
29235 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
29236 index 15f0ead..cb43480 100644
29237 --- a/drivers/ide/atiixp.c
29238 +++ b/drivers/ide/atiixp.c
29239 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
29240 .cable_detect = atiixp_cable_detect,
29241 };
29242
29243 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
29244 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
29245 { /* 0: IXP200/300/400/700 */
29246 .name = DRV_NAME,
29247 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
29248 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
29249 index 5f80312..d1fc438 100644
29250 --- a/drivers/ide/cmd64x.c
29251 +++ b/drivers/ide/cmd64x.c
29252 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
29253 .dma_sff_read_status = ide_dma_sff_read_status,
29254 };
29255
29256 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
29257 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
29258 { /* 0: CMD643 */
29259 .name = DRV_NAME,
29260 .init_chipset = init_chipset_cmd64x,
29261 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
29262 index 2c1e5f7..1444762 100644
29263 --- a/drivers/ide/cs5520.c
29264 +++ b/drivers/ide/cs5520.c
29265 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
29266 .set_dma_mode = cs5520_set_dma_mode,
29267 };
29268
29269 -static const struct ide_port_info cyrix_chipset __devinitdata = {
29270 +static const struct ide_port_info cyrix_chipset __devinitconst = {
29271 .name = DRV_NAME,
29272 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
29273 .port_ops = &cs5520_port_ops,
29274 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
29275 index 4dc4eb9..49b40ad 100644
29276 --- a/drivers/ide/cs5530.c
29277 +++ b/drivers/ide/cs5530.c
29278 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
29279 .udma_filter = cs5530_udma_filter,
29280 };
29281
29282 -static const struct ide_port_info cs5530_chipset __devinitdata = {
29283 +static const struct ide_port_info cs5530_chipset __devinitconst = {
29284 .name = DRV_NAME,
29285 .init_chipset = init_chipset_cs5530,
29286 .init_hwif = init_hwif_cs5530,
29287 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
29288 index 5059faf..18d4c85 100644
29289 --- a/drivers/ide/cs5535.c
29290 +++ b/drivers/ide/cs5535.c
29291 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
29292 .cable_detect = cs5535_cable_detect,
29293 };
29294
29295 -static const struct ide_port_info cs5535_chipset __devinitdata = {
29296 +static const struct ide_port_info cs5535_chipset __devinitconst = {
29297 .name = DRV_NAME,
29298 .port_ops = &cs5535_port_ops,
29299 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
29300 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
29301 index 847553f..3ffb49d 100644
29302 --- a/drivers/ide/cy82c693.c
29303 +++ b/drivers/ide/cy82c693.c
29304 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
29305 .set_dma_mode = cy82c693_set_dma_mode,
29306 };
29307
29308 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
29309 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
29310 .name = DRV_NAME,
29311 .init_iops = init_iops_cy82c693,
29312 .port_ops = &cy82c693_port_ops,
29313 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
29314 index 58c51cd..4aec3b8 100644
29315 --- a/drivers/ide/hpt366.c
29316 +++ b/drivers/ide/hpt366.c
29317 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
29318 }
29319 };
29320
29321 -static const struct hpt_info hpt36x __devinitdata = {
29322 +static const struct hpt_info hpt36x __devinitconst = {
29323 .chip_name = "HPT36x",
29324 .chip_type = HPT36x,
29325 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
29326 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
29327 .timings = &hpt36x_timings
29328 };
29329
29330 -static const struct hpt_info hpt370 __devinitdata = {
29331 +static const struct hpt_info hpt370 __devinitconst = {
29332 .chip_name = "HPT370",
29333 .chip_type = HPT370,
29334 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29335 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
29336 .timings = &hpt37x_timings
29337 };
29338
29339 -static const struct hpt_info hpt370a __devinitdata = {
29340 +static const struct hpt_info hpt370a __devinitconst = {
29341 .chip_name = "HPT370A",
29342 .chip_type = HPT370A,
29343 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29344 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
29345 .timings = &hpt37x_timings
29346 };
29347
29348 -static const struct hpt_info hpt374 __devinitdata = {
29349 +static const struct hpt_info hpt374 __devinitconst = {
29350 .chip_name = "HPT374",
29351 .chip_type = HPT374,
29352 .udma_mask = ATA_UDMA5,
29353 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
29354 .timings = &hpt37x_timings
29355 };
29356
29357 -static const struct hpt_info hpt372 __devinitdata = {
29358 +static const struct hpt_info hpt372 __devinitconst = {
29359 .chip_name = "HPT372",
29360 .chip_type = HPT372,
29361 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29362 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
29363 .timings = &hpt37x_timings
29364 };
29365
29366 -static const struct hpt_info hpt372a __devinitdata = {
29367 +static const struct hpt_info hpt372a __devinitconst = {
29368 .chip_name = "HPT372A",
29369 .chip_type = HPT372A,
29370 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29371 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
29372 .timings = &hpt37x_timings
29373 };
29374
29375 -static const struct hpt_info hpt302 __devinitdata = {
29376 +static const struct hpt_info hpt302 __devinitconst = {
29377 .chip_name = "HPT302",
29378 .chip_type = HPT302,
29379 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29380 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
29381 .timings = &hpt37x_timings
29382 };
29383
29384 -static const struct hpt_info hpt371 __devinitdata = {
29385 +static const struct hpt_info hpt371 __devinitconst = {
29386 .chip_name = "HPT371",
29387 .chip_type = HPT371,
29388 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29389 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
29390 .timings = &hpt37x_timings
29391 };
29392
29393 -static const struct hpt_info hpt372n __devinitdata = {
29394 +static const struct hpt_info hpt372n __devinitconst = {
29395 .chip_name = "HPT372N",
29396 .chip_type = HPT372N,
29397 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29398 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
29399 .timings = &hpt37x_timings
29400 };
29401
29402 -static const struct hpt_info hpt302n __devinitdata = {
29403 +static const struct hpt_info hpt302n __devinitconst = {
29404 .chip_name = "HPT302N",
29405 .chip_type = HPT302N,
29406 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29407 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
29408 .timings = &hpt37x_timings
29409 };
29410
29411 -static const struct hpt_info hpt371n __devinitdata = {
29412 +static const struct hpt_info hpt371n __devinitconst = {
29413 .chip_name = "HPT371N",
29414 .chip_type = HPT371N,
29415 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29416 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
29417 .dma_sff_read_status = ide_dma_sff_read_status,
29418 };
29419
29420 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
29421 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
29422 { /* 0: HPT36x */
29423 .name = DRV_NAME,
29424 .init_chipset = init_chipset_hpt366,
29425 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
29426 index 8126824..55a2798 100644
29427 --- a/drivers/ide/ide-cd.c
29428 +++ b/drivers/ide/ide-cd.c
29429 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
29430 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
29431 if ((unsigned long)buf & alignment
29432 || blk_rq_bytes(rq) & q->dma_pad_mask
29433 - || object_is_on_stack(buf))
29434 + || object_starts_on_stack(buf))
29435 drive->dma = 0;
29436 }
29437 }
29438 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
29439 index a743e68..1cfd674 100644
29440 --- a/drivers/ide/ide-pci-generic.c
29441 +++ b/drivers/ide/ide-pci-generic.c
29442 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
29443 .udma_mask = ATA_UDMA6, \
29444 }
29445
29446 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
29447 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
29448 /* 0: Unknown */
29449 DECLARE_GENERIC_PCI_DEV(0),
29450
29451 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
29452 index 560e66d..d5dd180 100644
29453 --- a/drivers/ide/it8172.c
29454 +++ b/drivers/ide/it8172.c
29455 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
29456 .set_dma_mode = it8172_set_dma_mode,
29457 };
29458
29459 -static const struct ide_port_info it8172_port_info __devinitdata = {
29460 +static const struct ide_port_info it8172_port_info __devinitconst = {
29461 .name = DRV_NAME,
29462 .port_ops = &it8172_port_ops,
29463 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
29464 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
29465 index 46816ba..1847aeb 100644
29466 --- a/drivers/ide/it8213.c
29467 +++ b/drivers/ide/it8213.c
29468 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
29469 .cable_detect = it8213_cable_detect,
29470 };
29471
29472 -static const struct ide_port_info it8213_chipset __devinitdata = {
29473 +static const struct ide_port_info it8213_chipset __devinitconst = {
29474 .name = DRV_NAME,
29475 .enablebits = { {0x41, 0x80, 0x80} },
29476 .port_ops = &it8213_port_ops,
29477 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
29478 index 2e3169f..c5611db 100644
29479 --- a/drivers/ide/it821x.c
29480 +++ b/drivers/ide/it821x.c
29481 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
29482 .cable_detect = it821x_cable_detect,
29483 };
29484
29485 -static const struct ide_port_info it821x_chipset __devinitdata = {
29486 +static const struct ide_port_info it821x_chipset __devinitconst = {
29487 .name = DRV_NAME,
29488 .init_chipset = init_chipset_it821x,
29489 .init_hwif = init_hwif_it821x,
29490 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
29491 index 74c2c4a..efddd7d 100644
29492 --- a/drivers/ide/jmicron.c
29493 +++ b/drivers/ide/jmicron.c
29494 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
29495 .cable_detect = jmicron_cable_detect,
29496 };
29497
29498 -static const struct ide_port_info jmicron_chipset __devinitdata = {
29499 +static const struct ide_port_info jmicron_chipset __devinitconst = {
29500 .name = DRV_NAME,
29501 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
29502 .port_ops = &jmicron_port_ops,
29503 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
29504 index 95327a2..73f78d8 100644
29505 --- a/drivers/ide/ns87415.c
29506 +++ b/drivers/ide/ns87415.c
29507 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
29508 .dma_sff_read_status = superio_dma_sff_read_status,
29509 };
29510
29511 -static const struct ide_port_info ns87415_chipset __devinitdata = {
29512 +static const struct ide_port_info ns87415_chipset __devinitconst = {
29513 .name = DRV_NAME,
29514 .init_hwif = init_hwif_ns87415,
29515 .tp_ops = &ns87415_tp_ops,
29516 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
29517 index 1a53a4c..39edc66 100644
29518 --- a/drivers/ide/opti621.c
29519 +++ b/drivers/ide/opti621.c
29520 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
29521 .set_pio_mode = opti621_set_pio_mode,
29522 };
29523
29524 -static const struct ide_port_info opti621_chipset __devinitdata = {
29525 +static const struct ide_port_info opti621_chipset __devinitconst = {
29526 .name = DRV_NAME,
29527 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
29528 .port_ops = &opti621_port_ops,
29529 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
29530 index 9546fe2..2e5ceb6 100644
29531 --- a/drivers/ide/pdc202xx_new.c
29532 +++ b/drivers/ide/pdc202xx_new.c
29533 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
29534 .udma_mask = udma, \
29535 }
29536
29537 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
29538 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
29539 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
29540 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
29541 };
29542 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
29543 index 3a35ec6..5634510 100644
29544 --- a/drivers/ide/pdc202xx_old.c
29545 +++ b/drivers/ide/pdc202xx_old.c
29546 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
29547 .max_sectors = sectors, \
29548 }
29549
29550 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
29551 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
29552 { /* 0: PDC20246 */
29553 .name = DRV_NAME,
29554 .init_chipset = init_chipset_pdc202xx,
29555 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
29556 index 1892e81..fe0fd60 100644
29557 --- a/drivers/ide/piix.c
29558 +++ b/drivers/ide/piix.c
29559 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
29560 .udma_mask = udma, \
29561 }
29562
29563 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
29564 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
29565 /* 0: MPIIX */
29566 { /*
29567 * MPIIX actually has only a single IDE channel mapped to
29568 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
29569 index a6414a8..c04173e 100644
29570 --- a/drivers/ide/rz1000.c
29571 +++ b/drivers/ide/rz1000.c
29572 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
29573 }
29574 }
29575
29576 -static const struct ide_port_info rz1000_chipset __devinitdata = {
29577 +static const struct ide_port_info rz1000_chipset __devinitconst = {
29578 .name = DRV_NAME,
29579 .host_flags = IDE_HFLAG_NO_DMA,
29580 };
29581 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
29582 index 356b9b5..d4758eb 100644
29583 --- a/drivers/ide/sc1200.c
29584 +++ b/drivers/ide/sc1200.c
29585 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
29586 .dma_sff_read_status = ide_dma_sff_read_status,
29587 };
29588
29589 -static const struct ide_port_info sc1200_chipset __devinitdata = {
29590 +static const struct ide_port_info sc1200_chipset __devinitconst = {
29591 .name = DRV_NAME,
29592 .port_ops = &sc1200_port_ops,
29593 .dma_ops = &sc1200_dma_ops,
29594 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
29595 index b7f5b0c..9701038 100644
29596 --- a/drivers/ide/scc_pata.c
29597 +++ b/drivers/ide/scc_pata.c
29598 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
29599 .dma_sff_read_status = scc_dma_sff_read_status,
29600 };
29601
29602 -static const struct ide_port_info scc_chipset __devinitdata = {
29603 +static const struct ide_port_info scc_chipset __devinitconst = {
29604 .name = "sccIDE",
29605 .init_iops = init_iops_scc,
29606 .init_dma = scc_init_dma,
29607 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
29608 index 35fb8da..24d72ef 100644
29609 --- a/drivers/ide/serverworks.c
29610 +++ b/drivers/ide/serverworks.c
29611 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
29612 .cable_detect = svwks_cable_detect,
29613 };
29614
29615 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
29616 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
29617 { /* 0: OSB4 */
29618 .name = DRV_NAME,
29619 .init_chipset = init_chipset_svwks,
29620 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
29621 index ddeda44..46f7e30 100644
29622 --- a/drivers/ide/siimage.c
29623 +++ b/drivers/ide/siimage.c
29624 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
29625 .udma_mask = ATA_UDMA6, \
29626 }
29627
29628 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
29629 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
29630 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
29631 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
29632 };
29633 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
29634 index 4a00225..09e61b4 100644
29635 --- a/drivers/ide/sis5513.c
29636 +++ b/drivers/ide/sis5513.c
29637 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
29638 .cable_detect = sis_cable_detect,
29639 };
29640
29641 -static const struct ide_port_info sis5513_chipset __devinitdata = {
29642 +static const struct ide_port_info sis5513_chipset __devinitconst = {
29643 .name = DRV_NAME,
29644 .init_chipset = init_chipset_sis5513,
29645 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
29646 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
29647 index f21dc2a..d051cd2 100644
29648 --- a/drivers/ide/sl82c105.c
29649 +++ b/drivers/ide/sl82c105.c
29650 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
29651 .dma_sff_read_status = ide_dma_sff_read_status,
29652 };
29653
29654 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
29655 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
29656 .name = DRV_NAME,
29657 .init_chipset = init_chipset_sl82c105,
29658 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
29659 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
29660 index 864ffe0..863a5e9 100644
29661 --- a/drivers/ide/slc90e66.c
29662 +++ b/drivers/ide/slc90e66.c
29663 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
29664 .cable_detect = slc90e66_cable_detect,
29665 };
29666
29667 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
29668 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
29669 .name = DRV_NAME,
29670 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
29671 .port_ops = &slc90e66_port_ops,
29672 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
29673 index 4799d5c..1794678 100644
29674 --- a/drivers/ide/tc86c001.c
29675 +++ b/drivers/ide/tc86c001.c
29676 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
29677 .dma_sff_read_status = ide_dma_sff_read_status,
29678 };
29679
29680 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
29681 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
29682 .name = DRV_NAME,
29683 .init_hwif = init_hwif_tc86c001,
29684 .port_ops = &tc86c001_port_ops,
29685 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
29686 index 281c914..55ce1b8 100644
29687 --- a/drivers/ide/triflex.c
29688 +++ b/drivers/ide/triflex.c
29689 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
29690 .set_dma_mode = triflex_set_mode,
29691 };
29692
29693 -static const struct ide_port_info triflex_device __devinitdata = {
29694 +static const struct ide_port_info triflex_device __devinitconst = {
29695 .name = DRV_NAME,
29696 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
29697 .port_ops = &triflex_port_ops,
29698 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
29699 index 4b42ca0..e494a98 100644
29700 --- a/drivers/ide/trm290.c
29701 +++ b/drivers/ide/trm290.c
29702 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
29703 .dma_check = trm290_dma_check,
29704 };
29705
29706 -static const struct ide_port_info trm290_chipset __devinitdata = {
29707 +static const struct ide_port_info trm290_chipset __devinitconst = {
29708 .name = DRV_NAME,
29709 .init_hwif = init_hwif_trm290,
29710 .tp_ops = &trm290_tp_ops,
29711 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
29712 index f46f49c..eb77678 100644
29713 --- a/drivers/ide/via82cxxx.c
29714 +++ b/drivers/ide/via82cxxx.c
29715 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
29716 .cable_detect = via82cxxx_cable_detect,
29717 };
29718
29719 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
29720 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
29721 .name = DRV_NAME,
29722 .init_chipset = init_chipset_via82cxxx,
29723 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
29724 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
29725 index eb0e2cc..14241c7 100644
29726 --- a/drivers/ieee802154/fakehard.c
29727 +++ b/drivers/ieee802154/fakehard.c
29728 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
29729 phy->transmit_power = 0xbf;
29730
29731 dev->netdev_ops = &fake_ops;
29732 - dev->ml_priv = &fake_mlme;
29733 + dev->ml_priv = (void *)&fake_mlme;
29734
29735 priv = netdev_priv(dev);
29736 priv->phy = phy;
29737 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
29738 index 8b72f39..55df4c8 100644
29739 --- a/drivers/infiniband/core/cm.c
29740 +++ b/drivers/infiniband/core/cm.c
29741 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
29742
29743 struct cm_counter_group {
29744 struct kobject obj;
29745 - atomic_long_t counter[CM_ATTR_COUNT];
29746 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
29747 };
29748
29749 struct cm_counter_attribute {
29750 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
29751 struct ib_mad_send_buf *msg = NULL;
29752 int ret;
29753
29754 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29755 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29756 counter[CM_REQ_COUNTER]);
29757
29758 /* Quick state check to discard duplicate REQs. */
29759 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
29760 if (!cm_id_priv)
29761 return;
29762
29763 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29764 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29765 counter[CM_REP_COUNTER]);
29766 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
29767 if (ret)
29768 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
29769 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
29770 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
29771 spin_unlock_irq(&cm_id_priv->lock);
29772 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29773 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29774 counter[CM_RTU_COUNTER]);
29775 goto out;
29776 }
29777 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
29778 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
29779 dreq_msg->local_comm_id);
29780 if (!cm_id_priv) {
29781 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29782 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29783 counter[CM_DREQ_COUNTER]);
29784 cm_issue_drep(work->port, work->mad_recv_wc);
29785 return -EINVAL;
29786 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
29787 case IB_CM_MRA_REP_RCVD:
29788 break;
29789 case IB_CM_TIMEWAIT:
29790 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29791 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29792 counter[CM_DREQ_COUNTER]);
29793 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
29794 goto unlock;
29795 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
29796 cm_free_msg(msg);
29797 goto deref;
29798 case IB_CM_DREQ_RCVD:
29799 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29800 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29801 counter[CM_DREQ_COUNTER]);
29802 goto unlock;
29803 default:
29804 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
29805 ib_modify_mad(cm_id_priv->av.port->mad_agent,
29806 cm_id_priv->msg, timeout)) {
29807 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
29808 - atomic_long_inc(&work->port->
29809 + atomic_long_inc_unchecked(&work->port->
29810 counter_group[CM_RECV_DUPLICATES].
29811 counter[CM_MRA_COUNTER]);
29812 goto out;
29813 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
29814 break;
29815 case IB_CM_MRA_REQ_RCVD:
29816 case IB_CM_MRA_REP_RCVD:
29817 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29818 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29819 counter[CM_MRA_COUNTER]);
29820 /* fall through */
29821 default:
29822 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
29823 case IB_CM_LAP_IDLE:
29824 break;
29825 case IB_CM_MRA_LAP_SENT:
29826 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29827 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29828 counter[CM_LAP_COUNTER]);
29829 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
29830 goto unlock;
29831 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
29832 cm_free_msg(msg);
29833 goto deref;
29834 case IB_CM_LAP_RCVD:
29835 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29836 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29837 counter[CM_LAP_COUNTER]);
29838 goto unlock;
29839 default:
29840 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
29841 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
29842 if (cur_cm_id_priv) {
29843 spin_unlock_irq(&cm.lock);
29844 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29845 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29846 counter[CM_SIDR_REQ_COUNTER]);
29847 goto out; /* Duplicate message. */
29848 }
29849 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
29850 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
29851 msg->retries = 1;
29852
29853 - atomic_long_add(1 + msg->retries,
29854 + atomic_long_add_unchecked(1 + msg->retries,
29855 &port->counter_group[CM_XMIT].counter[attr_index]);
29856 if (msg->retries)
29857 - atomic_long_add(msg->retries,
29858 + atomic_long_add_unchecked(msg->retries,
29859 &port->counter_group[CM_XMIT_RETRIES].
29860 counter[attr_index]);
29861
29862 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
29863 }
29864
29865 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
29866 - atomic_long_inc(&port->counter_group[CM_RECV].
29867 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
29868 counter[attr_id - CM_ATTR_ID_OFFSET]);
29869
29870 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
29871 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
29872 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
29873
29874 return sprintf(buf, "%ld\n",
29875 - atomic_long_read(&group->counter[cm_attr->index]));
29876 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
29877 }
29878
29879 static const struct sysfs_ops cm_counter_ops = {
29880 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
29881 index 176c8f9..2627b62 100644
29882 --- a/drivers/infiniband/core/fmr_pool.c
29883 +++ b/drivers/infiniband/core/fmr_pool.c
29884 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
29885
29886 struct task_struct *thread;
29887
29888 - atomic_t req_ser;
29889 - atomic_t flush_ser;
29890 + atomic_unchecked_t req_ser;
29891 + atomic_unchecked_t flush_ser;
29892
29893 wait_queue_head_t force_wait;
29894 };
29895 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
29896 struct ib_fmr_pool *pool = pool_ptr;
29897
29898 do {
29899 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
29900 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
29901 ib_fmr_batch_release(pool);
29902
29903 - atomic_inc(&pool->flush_ser);
29904 + atomic_inc_unchecked(&pool->flush_ser);
29905 wake_up_interruptible(&pool->force_wait);
29906
29907 if (pool->flush_function)
29908 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
29909 }
29910
29911 set_current_state(TASK_INTERRUPTIBLE);
29912 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
29913 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
29914 !kthread_should_stop())
29915 schedule();
29916 __set_current_state(TASK_RUNNING);
29917 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
29918 pool->dirty_watermark = params->dirty_watermark;
29919 pool->dirty_len = 0;
29920 spin_lock_init(&pool->pool_lock);
29921 - atomic_set(&pool->req_ser, 0);
29922 - atomic_set(&pool->flush_ser, 0);
29923 + atomic_set_unchecked(&pool->req_ser, 0);
29924 + atomic_set_unchecked(&pool->flush_ser, 0);
29925 init_waitqueue_head(&pool->force_wait);
29926
29927 pool->thread = kthread_run(ib_fmr_cleanup_thread,
29928 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
29929 }
29930 spin_unlock_irq(&pool->pool_lock);
29931
29932 - serial = atomic_inc_return(&pool->req_ser);
29933 + serial = atomic_inc_return_unchecked(&pool->req_ser);
29934 wake_up_process(pool->thread);
29935
29936 if (wait_event_interruptible(pool->force_wait,
29937 - atomic_read(&pool->flush_ser) - serial >= 0))
29938 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
29939 return -EINTR;
29940
29941 return 0;
29942 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
29943 } else {
29944 list_add_tail(&fmr->list, &pool->dirty_list);
29945 if (++pool->dirty_len >= pool->dirty_watermark) {
29946 - atomic_inc(&pool->req_ser);
29947 + atomic_inc_unchecked(&pool->req_ser);
29948 wake_up_process(pool->thread);
29949 }
29950 }
29951 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
29952 index 40c8353..946b0e4 100644
29953 --- a/drivers/infiniband/hw/cxgb4/mem.c
29954 +++ b/drivers/infiniband/hw/cxgb4/mem.c
29955 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
29956 int err;
29957 struct fw_ri_tpte tpt;
29958 u32 stag_idx;
29959 - static atomic_t key;
29960 + static atomic_unchecked_t key;
29961
29962 if (c4iw_fatal_error(rdev))
29963 return -EIO;
29964 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
29965 &rdev->resource.tpt_fifo_lock);
29966 if (!stag_idx)
29967 return -ENOMEM;
29968 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
29969 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
29970 }
29971 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
29972 __func__, stag_state, type, pdid, stag_idx);
29973 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
29974 index 79b3dbc..96e5fcc 100644
29975 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
29976 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
29977 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
29978 struct ib_atomic_eth *ateth;
29979 struct ipath_ack_entry *e;
29980 u64 vaddr;
29981 - atomic64_t *maddr;
29982 + atomic64_unchecked_t *maddr;
29983 u64 sdata;
29984 u32 rkey;
29985 u8 next;
29986 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
29987 IB_ACCESS_REMOTE_ATOMIC)))
29988 goto nack_acc_unlck;
29989 /* Perform atomic OP and save result. */
29990 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
29991 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
29992 sdata = be64_to_cpu(ateth->swap_data);
29993 e = &qp->s_ack_queue[qp->r_head_ack_queue];
29994 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
29995 - (u64) atomic64_add_return(sdata, maddr) - sdata :
29996 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
29997 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
29998 be64_to_cpu(ateth->compare_data),
29999 sdata);
30000 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
30001 index 1f95bba..9530f87 100644
30002 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
30003 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
30004 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
30005 unsigned long flags;
30006 struct ib_wc wc;
30007 u64 sdata;
30008 - atomic64_t *maddr;
30009 + atomic64_unchecked_t *maddr;
30010 enum ib_wc_status send_status;
30011
30012 /*
30013 @@ -382,11 +382,11 @@ again:
30014 IB_ACCESS_REMOTE_ATOMIC)))
30015 goto acc_err;
30016 /* Perform atomic OP and save result. */
30017 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30018 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30019 sdata = wqe->wr.wr.atomic.compare_add;
30020 *(u64 *) sqp->s_sge.sge.vaddr =
30021 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30022 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30023 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30024 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30025 sdata, wqe->wr.wr.atomic.swap);
30026 goto send_comp;
30027 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
30028 index 5965b3d..16817fb 100644
30029 --- a/drivers/infiniband/hw/nes/nes.c
30030 +++ b/drivers/infiniband/hw/nes/nes.c
30031 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
30032 LIST_HEAD(nes_adapter_list);
30033 static LIST_HEAD(nes_dev_list);
30034
30035 -atomic_t qps_destroyed;
30036 +atomic_unchecked_t qps_destroyed;
30037
30038 static unsigned int ee_flsh_adapter;
30039 static unsigned int sysfs_nonidx_addr;
30040 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
30041 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30042 struct nes_adapter *nesadapter = nesdev->nesadapter;
30043
30044 - atomic_inc(&qps_destroyed);
30045 + atomic_inc_unchecked(&qps_destroyed);
30046
30047 /* Free the control structures */
30048
30049 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
30050 index 568b4f1..5ea3eff 100644
30051 --- a/drivers/infiniband/hw/nes/nes.h
30052 +++ b/drivers/infiniband/hw/nes/nes.h
30053 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
30054 extern unsigned int wqm_quanta;
30055 extern struct list_head nes_adapter_list;
30056
30057 -extern atomic_t cm_connects;
30058 -extern atomic_t cm_accepts;
30059 -extern atomic_t cm_disconnects;
30060 -extern atomic_t cm_closes;
30061 -extern atomic_t cm_connecteds;
30062 -extern atomic_t cm_connect_reqs;
30063 -extern atomic_t cm_rejects;
30064 -extern atomic_t mod_qp_timouts;
30065 -extern atomic_t qps_created;
30066 -extern atomic_t qps_destroyed;
30067 -extern atomic_t sw_qps_destroyed;
30068 +extern atomic_unchecked_t cm_connects;
30069 +extern atomic_unchecked_t cm_accepts;
30070 +extern atomic_unchecked_t cm_disconnects;
30071 +extern atomic_unchecked_t cm_closes;
30072 +extern atomic_unchecked_t cm_connecteds;
30073 +extern atomic_unchecked_t cm_connect_reqs;
30074 +extern atomic_unchecked_t cm_rejects;
30075 +extern atomic_unchecked_t mod_qp_timouts;
30076 +extern atomic_unchecked_t qps_created;
30077 +extern atomic_unchecked_t qps_destroyed;
30078 +extern atomic_unchecked_t sw_qps_destroyed;
30079 extern u32 mh_detected;
30080 extern u32 mh_pauses_sent;
30081 extern u32 cm_packets_sent;
30082 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
30083 extern u32 cm_packets_received;
30084 extern u32 cm_packets_dropped;
30085 extern u32 cm_packets_retrans;
30086 -extern atomic_t cm_listens_created;
30087 -extern atomic_t cm_listens_destroyed;
30088 +extern atomic_unchecked_t cm_listens_created;
30089 +extern atomic_unchecked_t cm_listens_destroyed;
30090 extern u32 cm_backlog_drops;
30091 -extern atomic_t cm_loopbacks;
30092 -extern atomic_t cm_nodes_created;
30093 -extern atomic_t cm_nodes_destroyed;
30094 -extern atomic_t cm_accel_dropped_pkts;
30095 -extern atomic_t cm_resets_recvd;
30096 -extern atomic_t pau_qps_created;
30097 -extern atomic_t pau_qps_destroyed;
30098 +extern atomic_unchecked_t cm_loopbacks;
30099 +extern atomic_unchecked_t cm_nodes_created;
30100 +extern atomic_unchecked_t cm_nodes_destroyed;
30101 +extern atomic_unchecked_t cm_accel_dropped_pkts;
30102 +extern atomic_unchecked_t cm_resets_recvd;
30103 +extern atomic_unchecked_t pau_qps_created;
30104 +extern atomic_unchecked_t pau_qps_destroyed;
30105
30106 extern u32 int_mod_timer_init;
30107 extern u32 int_mod_cq_depth_256;
30108 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
30109 index 0a52d72..0642f36 100644
30110 --- a/drivers/infiniband/hw/nes/nes_cm.c
30111 +++ b/drivers/infiniband/hw/nes/nes_cm.c
30112 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30113 u32 cm_packets_retrans;
30114 u32 cm_packets_created;
30115 u32 cm_packets_received;
30116 -atomic_t cm_listens_created;
30117 -atomic_t cm_listens_destroyed;
30118 +atomic_unchecked_t cm_listens_created;
30119 +atomic_unchecked_t cm_listens_destroyed;
30120 u32 cm_backlog_drops;
30121 -atomic_t cm_loopbacks;
30122 -atomic_t cm_nodes_created;
30123 -atomic_t cm_nodes_destroyed;
30124 -atomic_t cm_accel_dropped_pkts;
30125 -atomic_t cm_resets_recvd;
30126 +atomic_unchecked_t cm_loopbacks;
30127 +atomic_unchecked_t cm_nodes_created;
30128 +atomic_unchecked_t cm_nodes_destroyed;
30129 +atomic_unchecked_t cm_accel_dropped_pkts;
30130 +atomic_unchecked_t cm_resets_recvd;
30131
30132 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
30133 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
30134 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
30135
30136 static struct nes_cm_core *g_cm_core;
30137
30138 -atomic_t cm_connects;
30139 -atomic_t cm_accepts;
30140 -atomic_t cm_disconnects;
30141 -atomic_t cm_closes;
30142 -atomic_t cm_connecteds;
30143 -atomic_t cm_connect_reqs;
30144 -atomic_t cm_rejects;
30145 +atomic_unchecked_t cm_connects;
30146 +atomic_unchecked_t cm_accepts;
30147 +atomic_unchecked_t cm_disconnects;
30148 +atomic_unchecked_t cm_closes;
30149 +atomic_unchecked_t cm_connecteds;
30150 +atomic_unchecked_t cm_connect_reqs;
30151 +atomic_unchecked_t cm_rejects;
30152
30153 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
30154 {
30155 @@ -1271,7 +1271,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
30156 kfree(listener);
30157 listener = NULL;
30158 ret = 0;
30159 - atomic_inc(&cm_listens_destroyed);
30160 + atomic_inc_unchecked(&cm_listens_destroyed);
30161 } else {
30162 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30163 }
30164 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
30165 cm_node->rem_mac);
30166
30167 add_hte_node(cm_core, cm_node);
30168 - atomic_inc(&cm_nodes_created);
30169 + atomic_inc_unchecked(&cm_nodes_created);
30170
30171 return cm_node;
30172 }
30173 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
30174 }
30175
30176 atomic_dec(&cm_core->node_cnt);
30177 - atomic_inc(&cm_nodes_destroyed);
30178 + atomic_inc_unchecked(&cm_nodes_destroyed);
30179 nesqp = cm_node->nesqp;
30180 if (nesqp) {
30181 nesqp->cm_node = NULL;
30182 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
30183
30184 static void drop_packet(struct sk_buff *skb)
30185 {
30186 - atomic_inc(&cm_accel_dropped_pkts);
30187 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30188 dev_kfree_skb_any(skb);
30189 }
30190
30191 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
30192 {
30193
30194 int reset = 0; /* whether to send reset in case of err.. */
30195 - atomic_inc(&cm_resets_recvd);
30196 + atomic_inc_unchecked(&cm_resets_recvd);
30197 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30198 " refcnt=%d\n", cm_node, cm_node->state,
30199 atomic_read(&cm_node->ref_count));
30200 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
30201 rem_ref_cm_node(cm_node->cm_core, cm_node);
30202 return NULL;
30203 }
30204 - atomic_inc(&cm_loopbacks);
30205 + atomic_inc_unchecked(&cm_loopbacks);
30206 loopbackremotenode->loopbackpartner = cm_node;
30207 loopbackremotenode->tcp_cntxt.rcv_wscale =
30208 NES_CM_DEFAULT_RCV_WND_SCALE;
30209 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
30210 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
30211 else {
30212 rem_ref_cm_node(cm_core, cm_node);
30213 - atomic_inc(&cm_accel_dropped_pkts);
30214 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30215 dev_kfree_skb_any(skb);
30216 }
30217 break;
30218 @@ -2880,7 +2880,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30219
30220 if ((cm_id) && (cm_id->event_handler)) {
30221 if (issue_disconn) {
30222 - atomic_inc(&cm_disconnects);
30223 + atomic_inc_unchecked(&cm_disconnects);
30224 cm_event.event = IW_CM_EVENT_DISCONNECT;
30225 cm_event.status = disconn_status;
30226 cm_event.local_addr = cm_id->local_addr;
30227 @@ -2902,7 +2902,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30228 }
30229
30230 if (issue_close) {
30231 - atomic_inc(&cm_closes);
30232 + atomic_inc_unchecked(&cm_closes);
30233 nes_disconnect(nesqp, 1);
30234
30235 cm_id->provider_data = nesqp;
30236 @@ -3038,7 +3038,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30237
30238 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30239 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30240 - atomic_inc(&cm_accepts);
30241 + atomic_inc_unchecked(&cm_accepts);
30242
30243 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30244 netdev_refcnt_read(nesvnic->netdev));
30245 @@ -3240,7 +3240,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
30246 struct nes_cm_core *cm_core;
30247 u8 *start_buff;
30248
30249 - atomic_inc(&cm_rejects);
30250 + atomic_inc_unchecked(&cm_rejects);
30251 cm_node = (struct nes_cm_node *)cm_id->provider_data;
30252 loopback = cm_node->loopbackpartner;
30253 cm_core = cm_node->cm_core;
30254 @@ -3300,7 +3300,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30255 ntohl(cm_id->local_addr.sin_addr.s_addr),
30256 ntohs(cm_id->local_addr.sin_port));
30257
30258 - atomic_inc(&cm_connects);
30259 + atomic_inc_unchecked(&cm_connects);
30260 nesqp->active_conn = 1;
30261
30262 /* cache the cm_id in the qp */
30263 @@ -3406,7 +3406,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
30264 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30265 return err;
30266 }
30267 - atomic_inc(&cm_listens_created);
30268 + atomic_inc_unchecked(&cm_listens_created);
30269 }
30270
30271 cm_id->add_ref(cm_id);
30272 @@ -3507,7 +3507,7 @@ static void cm_event_connected(struct nes_cm_event *event)
30273
30274 if (nesqp->destroyed)
30275 return;
30276 - atomic_inc(&cm_connecteds);
30277 + atomic_inc_unchecked(&cm_connecteds);
30278 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30279 " local port 0x%04X. jiffies = %lu.\n",
30280 nesqp->hwqp.qp_id,
30281 @@ -3694,7 +3694,7 @@ static void cm_event_reset(struct nes_cm_event *event)
30282
30283 cm_id->add_ref(cm_id);
30284 ret = cm_id->event_handler(cm_id, &cm_event);
30285 - atomic_inc(&cm_closes);
30286 + atomic_inc_unchecked(&cm_closes);
30287 cm_event.event = IW_CM_EVENT_CLOSE;
30288 cm_event.status = 0;
30289 cm_event.provider_data = cm_id->provider_data;
30290 @@ -3730,7 +3730,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
30291 return;
30292 cm_id = cm_node->cm_id;
30293
30294 - atomic_inc(&cm_connect_reqs);
30295 + atomic_inc_unchecked(&cm_connect_reqs);
30296 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30297 cm_node, cm_id, jiffies);
30298
30299 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
30300 return;
30301 cm_id = cm_node->cm_id;
30302
30303 - atomic_inc(&cm_connect_reqs);
30304 + atomic_inc_unchecked(&cm_connect_reqs);
30305 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30306 cm_node, cm_id, jiffies);
30307
30308 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
30309 index b3b2a24..7bfaf1e 100644
30310 --- a/drivers/infiniband/hw/nes/nes_mgt.c
30311 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
30312 @@ -40,8 +40,8 @@
30313 #include "nes.h"
30314 #include "nes_mgt.h"
30315
30316 -atomic_t pau_qps_created;
30317 -atomic_t pau_qps_destroyed;
30318 +atomic_unchecked_t pau_qps_created;
30319 +atomic_unchecked_t pau_qps_destroyed;
30320
30321 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
30322 {
30323 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
30324 {
30325 struct sk_buff *skb;
30326 unsigned long flags;
30327 - atomic_inc(&pau_qps_destroyed);
30328 + atomic_inc_unchecked(&pau_qps_destroyed);
30329
30330 /* Free packets that have not yet been forwarded */
30331 /* Lock is acquired by skb_dequeue when removing the skb */
30332 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
30333 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
30334 skb_queue_head_init(&nesqp->pau_list);
30335 spin_lock_init(&nesqp->pau_lock);
30336 - atomic_inc(&pau_qps_created);
30337 + atomic_inc_unchecked(&pau_qps_created);
30338 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
30339 }
30340
30341 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
30342 index c00d2f3..8834298 100644
30343 --- a/drivers/infiniband/hw/nes/nes_nic.c
30344 +++ b/drivers/infiniband/hw/nes/nes_nic.c
30345 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
30346 target_stat_values[++index] = mh_detected;
30347 target_stat_values[++index] = mh_pauses_sent;
30348 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
30349 - target_stat_values[++index] = atomic_read(&cm_connects);
30350 - target_stat_values[++index] = atomic_read(&cm_accepts);
30351 - target_stat_values[++index] = atomic_read(&cm_disconnects);
30352 - target_stat_values[++index] = atomic_read(&cm_connecteds);
30353 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
30354 - target_stat_values[++index] = atomic_read(&cm_rejects);
30355 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
30356 - target_stat_values[++index] = atomic_read(&qps_created);
30357 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
30358 - target_stat_values[++index] = atomic_read(&qps_destroyed);
30359 - target_stat_values[++index] = atomic_read(&cm_closes);
30360 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
30361 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
30362 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
30363 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
30364 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
30365 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
30366 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
30367 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
30368 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
30369 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
30370 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
30371 target_stat_values[++index] = cm_packets_sent;
30372 target_stat_values[++index] = cm_packets_bounced;
30373 target_stat_values[++index] = cm_packets_created;
30374 target_stat_values[++index] = cm_packets_received;
30375 target_stat_values[++index] = cm_packets_dropped;
30376 target_stat_values[++index] = cm_packets_retrans;
30377 - target_stat_values[++index] = atomic_read(&cm_listens_created);
30378 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
30379 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
30380 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
30381 target_stat_values[++index] = cm_backlog_drops;
30382 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
30383 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
30384 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
30385 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
30386 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
30387 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
30388 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
30389 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
30390 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
30391 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
30392 target_stat_values[++index] = nesadapter->free_4kpbl;
30393 target_stat_values[++index] = nesadapter->free_256pbl;
30394 target_stat_values[++index] = int_mod_timer_init;
30395 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
30396 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
30397 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
30398 - target_stat_values[++index] = atomic_read(&pau_qps_created);
30399 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
30400 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
30401 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
30402 }
30403
30404 /**
30405 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
30406 index 5095bc4..41e8fff 100644
30407 --- a/drivers/infiniband/hw/nes/nes_verbs.c
30408 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
30409 @@ -46,9 +46,9 @@
30410
30411 #include <rdma/ib_umem.h>
30412
30413 -atomic_t mod_qp_timouts;
30414 -atomic_t qps_created;
30415 -atomic_t sw_qps_destroyed;
30416 +atomic_unchecked_t mod_qp_timouts;
30417 +atomic_unchecked_t qps_created;
30418 +atomic_unchecked_t sw_qps_destroyed;
30419
30420 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
30421
30422 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
30423 if (init_attr->create_flags)
30424 return ERR_PTR(-EINVAL);
30425
30426 - atomic_inc(&qps_created);
30427 + atomic_inc_unchecked(&qps_created);
30428 switch (init_attr->qp_type) {
30429 case IB_QPT_RC:
30430 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
30431 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
30432 struct iw_cm_event cm_event;
30433 int ret = 0;
30434
30435 - atomic_inc(&sw_qps_destroyed);
30436 + atomic_inc_unchecked(&sw_qps_destroyed);
30437 nesqp->destroyed = 1;
30438
30439 /* Blow away the connection if it exists. */
30440 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
30441 index b881bdc..c2e360c 100644
30442 --- a/drivers/infiniband/hw/qib/qib.h
30443 +++ b/drivers/infiniband/hw/qib/qib.h
30444 @@ -51,6 +51,7 @@
30445 #include <linux/completion.h>
30446 #include <linux/kref.h>
30447 #include <linux/sched.h>
30448 +#include <linux/slab.h>
30449
30450 #include "qib_common.h"
30451 #include "qib_verbs.h"
30452 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
30453 index c351aa4..e6967c2 100644
30454 --- a/drivers/input/gameport/gameport.c
30455 +++ b/drivers/input/gameport/gameport.c
30456 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
30457 */
30458 static void gameport_init_port(struct gameport *gameport)
30459 {
30460 - static atomic_t gameport_no = ATOMIC_INIT(0);
30461 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
30462
30463 __module_get(THIS_MODULE);
30464
30465 mutex_init(&gameport->drv_mutex);
30466 device_initialize(&gameport->dev);
30467 dev_set_name(&gameport->dev, "gameport%lu",
30468 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
30469 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
30470 gameport->dev.bus = &gameport_bus;
30471 gameport->dev.release = gameport_release_port;
30472 if (gameport->parent)
30473 diff --git a/drivers/input/input.c b/drivers/input/input.c
30474 index da38d97..2aa0b79 100644
30475 --- a/drivers/input/input.c
30476 +++ b/drivers/input/input.c
30477 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
30478 */
30479 int input_register_device(struct input_dev *dev)
30480 {
30481 - static atomic_t input_no = ATOMIC_INIT(0);
30482 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
30483 struct input_handler *handler;
30484 const char *path;
30485 int error;
30486 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
30487 dev->setkeycode = input_default_setkeycode;
30488
30489 dev_set_name(&dev->dev, "input%ld",
30490 - (unsigned long) atomic_inc_return(&input_no) - 1);
30491 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
30492
30493 error = device_add(&dev->dev);
30494 if (error)
30495 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
30496 index b8d8611..7a4a04b 100644
30497 --- a/drivers/input/joystick/sidewinder.c
30498 +++ b/drivers/input/joystick/sidewinder.c
30499 @@ -30,6 +30,7 @@
30500 #include <linux/kernel.h>
30501 #include <linux/module.h>
30502 #include <linux/slab.h>
30503 +#include <linux/sched.h>
30504 #include <linux/init.h>
30505 #include <linux/input.h>
30506 #include <linux/gameport.h>
30507 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
30508 index d728875..844c89b 100644
30509 --- a/drivers/input/joystick/xpad.c
30510 +++ b/drivers/input/joystick/xpad.c
30511 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
30512
30513 static int xpad_led_probe(struct usb_xpad *xpad)
30514 {
30515 - static atomic_t led_seq = ATOMIC_INIT(0);
30516 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
30517 long led_no;
30518 struct xpad_led *led;
30519 struct led_classdev *led_cdev;
30520 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
30521 if (!led)
30522 return -ENOMEM;
30523
30524 - led_no = (long)atomic_inc_return(&led_seq) - 1;
30525 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
30526
30527 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
30528 led->xpad = xpad;
30529 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
30530 index 0110b5a..d3ad144 100644
30531 --- a/drivers/input/mousedev.c
30532 +++ b/drivers/input/mousedev.c
30533 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
30534
30535 spin_unlock_irq(&client->packet_lock);
30536
30537 - if (copy_to_user(buffer, data, count))
30538 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
30539 return -EFAULT;
30540
30541 return count;
30542 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
30543 index ba70058..571d25d 100644
30544 --- a/drivers/input/serio/serio.c
30545 +++ b/drivers/input/serio/serio.c
30546 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
30547 */
30548 static void serio_init_port(struct serio *serio)
30549 {
30550 - static atomic_t serio_no = ATOMIC_INIT(0);
30551 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
30552
30553 __module_get(THIS_MODULE);
30554
30555 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
30556 mutex_init(&serio->drv_mutex);
30557 device_initialize(&serio->dev);
30558 dev_set_name(&serio->dev, "serio%ld",
30559 - (long)atomic_inc_return(&serio_no) - 1);
30560 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
30561 serio->dev.bus = &serio_bus;
30562 serio->dev.release = serio_release_port;
30563 serio->dev.groups = serio_device_attr_groups;
30564 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
30565 index e44933d..9ba484a 100644
30566 --- a/drivers/isdn/capi/capi.c
30567 +++ b/drivers/isdn/capi/capi.c
30568 @@ -83,8 +83,8 @@ struct capiminor {
30569
30570 struct capi20_appl *ap;
30571 u32 ncci;
30572 - atomic_t datahandle;
30573 - atomic_t msgid;
30574 + atomic_unchecked_t datahandle;
30575 + atomic_unchecked_t msgid;
30576
30577 struct tty_port port;
30578 int ttyinstop;
30579 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
30580 capimsg_setu16(s, 2, mp->ap->applid);
30581 capimsg_setu8 (s, 4, CAPI_DATA_B3);
30582 capimsg_setu8 (s, 5, CAPI_RESP);
30583 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
30584 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
30585 capimsg_setu32(s, 8, mp->ncci);
30586 capimsg_setu16(s, 12, datahandle);
30587 }
30588 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
30589 mp->outbytes -= len;
30590 spin_unlock_bh(&mp->outlock);
30591
30592 - datahandle = atomic_inc_return(&mp->datahandle);
30593 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
30594 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
30595 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30596 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30597 capimsg_setu16(skb->data, 2, mp->ap->applid);
30598 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
30599 capimsg_setu8 (skb->data, 5, CAPI_REQ);
30600 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
30601 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
30602 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
30603 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
30604 capimsg_setu16(skb->data, 16, len); /* Data length */
30605 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
30606 index db621db..825ea1a 100644
30607 --- a/drivers/isdn/gigaset/common.c
30608 +++ b/drivers/isdn/gigaset/common.c
30609 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
30610 cs->commands_pending = 0;
30611 cs->cur_at_seq = 0;
30612 cs->gotfwver = -1;
30613 - cs->open_count = 0;
30614 + local_set(&cs->open_count, 0);
30615 cs->dev = NULL;
30616 cs->tty = NULL;
30617 cs->tty_dev = NULL;
30618 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
30619 index 212efaf..f187c6b 100644
30620 --- a/drivers/isdn/gigaset/gigaset.h
30621 +++ b/drivers/isdn/gigaset/gigaset.h
30622 @@ -35,6 +35,7 @@
30623 #include <linux/tty_driver.h>
30624 #include <linux/list.h>
30625 #include <linux/atomic.h>
30626 +#include <asm/local.h>
30627
30628 #define GIG_VERSION {0, 5, 0, 0}
30629 #define GIG_COMPAT {0, 4, 0, 0}
30630 @@ -433,7 +434,7 @@ struct cardstate {
30631 spinlock_t cmdlock;
30632 unsigned curlen, cmdbytes;
30633
30634 - unsigned open_count;
30635 + local_t open_count;
30636 struct tty_struct *tty;
30637 struct tasklet_struct if_wake_tasklet;
30638 unsigned control_state;
30639 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
30640 index ee0a549..a7c9798 100644
30641 --- a/drivers/isdn/gigaset/interface.c
30642 +++ b/drivers/isdn/gigaset/interface.c
30643 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
30644 }
30645 tty->driver_data = cs;
30646
30647 - ++cs->open_count;
30648 -
30649 - if (cs->open_count == 1) {
30650 + if (local_inc_return(&cs->open_count) == 1) {
30651 spin_lock_irqsave(&cs->lock, flags);
30652 cs->tty = tty;
30653 spin_unlock_irqrestore(&cs->lock, flags);
30654 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
30655
30656 if (!cs->connected)
30657 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30658 - else if (!cs->open_count)
30659 + else if (!local_read(&cs->open_count))
30660 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30661 else {
30662 - if (!--cs->open_count) {
30663 + if (!local_dec_return(&cs->open_count)) {
30664 spin_lock_irqsave(&cs->lock, flags);
30665 cs->tty = NULL;
30666 spin_unlock_irqrestore(&cs->lock, flags);
30667 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
30668 if (!cs->connected) {
30669 gig_dbg(DEBUG_IF, "not connected");
30670 retval = -ENODEV;
30671 - } else if (!cs->open_count)
30672 + } else if (!local_read(&cs->open_count))
30673 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30674 else {
30675 retval = 0;
30676 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
30677 retval = -ENODEV;
30678 goto done;
30679 }
30680 - if (!cs->open_count) {
30681 + if (!local_read(&cs->open_count)) {
30682 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30683 retval = -ENODEV;
30684 goto done;
30685 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
30686 if (!cs->connected) {
30687 gig_dbg(DEBUG_IF, "not connected");
30688 retval = -ENODEV;
30689 - } else if (!cs->open_count)
30690 + } else if (!local_read(&cs->open_count))
30691 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30692 else if (cs->mstate != MS_LOCKED) {
30693 dev_warn(cs->dev, "can't write to unlocked device\n");
30694 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
30695
30696 if (!cs->connected)
30697 gig_dbg(DEBUG_IF, "not connected");
30698 - else if (!cs->open_count)
30699 + else if (!local_read(&cs->open_count))
30700 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30701 else if (cs->mstate != MS_LOCKED)
30702 dev_warn(cs->dev, "can't write to unlocked device\n");
30703 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
30704
30705 if (!cs->connected)
30706 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30707 - else if (!cs->open_count)
30708 + else if (!local_read(&cs->open_count))
30709 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30710 else
30711 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
30712 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
30713
30714 if (!cs->connected)
30715 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30716 - else if (!cs->open_count)
30717 + else if (!local_read(&cs->open_count))
30718 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30719 else
30720 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
30721 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
30722 goto out;
30723 }
30724
30725 - if (!cs->open_count) {
30726 + if (!local_read(&cs->open_count)) {
30727 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30728 goto out;
30729 }
30730 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
30731 index 2a57da59..e7a12ed 100644
30732 --- a/drivers/isdn/hardware/avm/b1.c
30733 +++ b/drivers/isdn/hardware/avm/b1.c
30734 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
30735 }
30736 if (left) {
30737 if (t4file->user) {
30738 - if (copy_from_user(buf, dp, left))
30739 + if (left > sizeof buf || copy_from_user(buf, dp, left))
30740 return -EFAULT;
30741 } else {
30742 memcpy(buf, dp, left);
30743 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
30744 }
30745 if (left) {
30746 if (config->user) {
30747 - if (copy_from_user(buf, dp, left))
30748 + if (left > sizeof buf || copy_from_user(buf, dp, left))
30749 return -EFAULT;
30750 } else {
30751 memcpy(buf, dp, left);
30752 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
30753 index 85784a7..a19ca98 100644
30754 --- a/drivers/isdn/hardware/eicon/divasync.h
30755 +++ b/drivers/isdn/hardware/eicon/divasync.h
30756 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
30757 } diva_didd_add_adapter_t;
30758 typedef struct _diva_didd_remove_adapter {
30759 IDI_CALL p_request;
30760 -} diva_didd_remove_adapter_t;
30761 +} __no_const diva_didd_remove_adapter_t;
30762 typedef struct _diva_didd_read_adapter_array {
30763 void * buffer;
30764 dword length;
30765 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
30766 index a3bd163..8956575 100644
30767 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
30768 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
30769 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
30770 typedef struct _diva_os_idi_adapter_interface {
30771 diva_init_card_proc_t cleanup_adapter_proc;
30772 diva_cmd_card_proc_t cmd_proc;
30773 -} diva_os_idi_adapter_interface_t;
30774 +} __no_const diva_os_idi_adapter_interface_t;
30775
30776 typedef struct _diva_os_xdi_adapter {
30777 struct list_head link;
30778 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
30779 index 1f355bb..43f1fea 100644
30780 --- a/drivers/isdn/icn/icn.c
30781 +++ b/drivers/isdn/icn/icn.c
30782 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
30783 if (count > len)
30784 count = len;
30785 if (user) {
30786 - if (copy_from_user(msg, buf, count))
30787 + if (count > sizeof msg || copy_from_user(msg, buf, count))
30788 return -EFAULT;
30789 } else
30790 memcpy(msg, buf, count);
30791 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
30792 index b5fdcb7..5b6c59f 100644
30793 --- a/drivers/lguest/core.c
30794 +++ b/drivers/lguest/core.c
30795 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
30796 * it's worked so far. The end address needs +1 because __get_vm_area
30797 * allocates an extra guard page, so we need space for that.
30798 */
30799 +
30800 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30801 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
30802 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
30803 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
30804 +#else
30805 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
30806 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
30807 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
30808 +#endif
30809 +
30810 if (!switcher_vma) {
30811 err = -ENOMEM;
30812 printk("lguest: could not map switcher pages high\n");
30813 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
30814 * Now the Switcher is mapped at the right address, we can't fail!
30815 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
30816 */
30817 - memcpy(switcher_vma->addr, start_switcher_text,
30818 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
30819 end_switcher_text - start_switcher_text);
30820
30821 printk(KERN_INFO "lguest: mapped switcher at %p\n",
30822 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
30823 index 65af42f..530c87a 100644
30824 --- a/drivers/lguest/x86/core.c
30825 +++ b/drivers/lguest/x86/core.c
30826 @@ -59,7 +59,7 @@ static struct {
30827 /* Offset from where switcher.S was compiled to where we've copied it */
30828 static unsigned long switcher_offset(void)
30829 {
30830 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
30831 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
30832 }
30833
30834 /* This cpu's struct lguest_pages. */
30835 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
30836 * These copies are pretty cheap, so we do them unconditionally: */
30837 /* Save the current Host top-level page directory.
30838 */
30839 +
30840 +#ifdef CONFIG_PAX_PER_CPU_PGD
30841 + pages->state.host_cr3 = read_cr3();
30842 +#else
30843 pages->state.host_cr3 = __pa(current->mm->pgd);
30844 +#endif
30845 +
30846 /*
30847 * Set up the Guest's page tables to see this CPU's pages (and no
30848 * other CPU's pages).
30849 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
30850 * compiled-in switcher code and the high-mapped copy we just made.
30851 */
30852 for (i = 0; i < IDT_ENTRIES; i++)
30853 - default_idt_entries[i] += switcher_offset();
30854 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
30855
30856 /*
30857 * Set up the Switcher's per-cpu areas.
30858 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
30859 * it will be undisturbed when we switch. To change %cs and jump we
30860 * need this structure to feed to Intel's "lcall" instruction.
30861 */
30862 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
30863 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
30864 lguest_entry.segment = LGUEST_CS;
30865
30866 /*
30867 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
30868 index 40634b0..4f5855e 100644
30869 --- a/drivers/lguest/x86/switcher_32.S
30870 +++ b/drivers/lguest/x86/switcher_32.S
30871 @@ -87,6 +87,7 @@
30872 #include <asm/page.h>
30873 #include <asm/segment.h>
30874 #include <asm/lguest.h>
30875 +#include <asm/processor-flags.h>
30876
30877 // We mark the start of the code to copy
30878 // It's placed in .text tho it's never run here
30879 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
30880 // Changes type when we load it: damn Intel!
30881 // For after we switch over our page tables
30882 // That entry will be read-only: we'd crash.
30883 +
30884 +#ifdef CONFIG_PAX_KERNEXEC
30885 + mov %cr0, %edx
30886 + xor $X86_CR0_WP, %edx
30887 + mov %edx, %cr0
30888 +#endif
30889 +
30890 movl $(GDT_ENTRY_TSS*8), %edx
30891 ltr %dx
30892
30893 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
30894 // Let's clear it again for our return.
30895 // The GDT descriptor of the Host
30896 // Points to the table after two "size" bytes
30897 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
30898 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
30899 // Clear "used" from type field (byte 5, bit 2)
30900 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
30901 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
30902 +
30903 +#ifdef CONFIG_PAX_KERNEXEC
30904 + mov %cr0, %eax
30905 + xor $X86_CR0_WP, %eax
30906 + mov %eax, %cr0
30907 +#endif
30908
30909 // Once our page table's switched, the Guest is live!
30910 // The Host fades as we run this final step.
30911 @@ -295,13 +309,12 @@ deliver_to_host:
30912 // I consulted gcc, and it gave
30913 // These instructions, which I gladly credit:
30914 leal (%edx,%ebx,8), %eax
30915 - movzwl (%eax),%edx
30916 - movl 4(%eax), %eax
30917 - xorw %ax, %ax
30918 - orl %eax, %edx
30919 + movl 4(%eax), %edx
30920 + movw (%eax), %dx
30921 // Now the address of the handler's in %edx
30922 // We call it now: its "iret" drops us home.
30923 - jmp *%edx
30924 + ljmp $__KERNEL_CS, $1f
30925 +1: jmp *%edx
30926
30927 // Every interrupt can come to us here
30928 // But we must truly tell each apart.
30929 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
30930 index 4daf9e5..b8d1d0f 100644
30931 --- a/drivers/macintosh/macio_asic.c
30932 +++ b/drivers/macintosh/macio_asic.c
30933 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
30934 * MacIO is matched against any Apple ID, it's probe() function
30935 * will then decide wether it applies or not
30936 */
30937 -static const struct pci_device_id __devinitdata pci_ids [] = { {
30938 +static const struct pci_device_id __devinitconst pci_ids [] = { {
30939 .vendor = PCI_VENDOR_ID_APPLE,
30940 .device = PCI_ANY_ID,
30941 .subvendor = PCI_ANY_ID,
30942 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
30943 index 31c2dc2..a2de7a6 100644
30944 --- a/drivers/md/dm-ioctl.c
30945 +++ b/drivers/md/dm-ioctl.c
30946 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
30947 cmd == DM_LIST_VERSIONS_CMD)
30948 return 0;
30949
30950 - if ((cmd == DM_DEV_CREATE_CMD)) {
30951 + if (cmd == DM_DEV_CREATE_CMD) {
30952 if (!*param->name) {
30953 DMWARN("name not supplied when creating device");
30954 return -EINVAL;
30955 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
30956 index 9bfd057..01180bc 100644
30957 --- a/drivers/md/dm-raid1.c
30958 +++ b/drivers/md/dm-raid1.c
30959 @@ -40,7 +40,7 @@ enum dm_raid1_error {
30960
30961 struct mirror {
30962 struct mirror_set *ms;
30963 - atomic_t error_count;
30964 + atomic_unchecked_t error_count;
30965 unsigned long error_type;
30966 struct dm_dev *dev;
30967 sector_t offset;
30968 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
30969 struct mirror *m;
30970
30971 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
30972 - if (!atomic_read(&m->error_count))
30973 + if (!atomic_read_unchecked(&m->error_count))
30974 return m;
30975
30976 return NULL;
30977 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
30978 * simple way to tell if a device has encountered
30979 * errors.
30980 */
30981 - atomic_inc(&m->error_count);
30982 + atomic_inc_unchecked(&m->error_count);
30983
30984 if (test_and_set_bit(error_type, &m->error_type))
30985 return;
30986 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
30987 struct mirror *m = get_default_mirror(ms);
30988
30989 do {
30990 - if (likely(!atomic_read(&m->error_count)))
30991 + if (likely(!atomic_read_unchecked(&m->error_count)))
30992 return m;
30993
30994 if (m-- == ms->mirror)
30995 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
30996 {
30997 struct mirror *default_mirror = get_default_mirror(m->ms);
30998
30999 - return !atomic_read(&default_mirror->error_count);
31000 + return !atomic_read_unchecked(&default_mirror->error_count);
31001 }
31002
31003 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31004 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
31005 */
31006 if (likely(region_in_sync(ms, region, 1)))
31007 m = choose_mirror(ms, bio->bi_sector);
31008 - else if (m && atomic_read(&m->error_count))
31009 + else if (m && atomic_read_unchecked(&m->error_count))
31010 m = NULL;
31011
31012 if (likely(m))
31013 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
31014 }
31015
31016 ms->mirror[mirror].ms = ms;
31017 - atomic_set(&(ms->mirror[mirror].error_count), 0);
31018 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31019 ms->mirror[mirror].error_type = 0;
31020 ms->mirror[mirror].offset = offset;
31021
31022 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
31023 */
31024 static char device_status_char(struct mirror *m)
31025 {
31026 - if (!atomic_read(&(m->error_count)))
31027 + if (!atomic_read_unchecked(&(m->error_count)))
31028 return 'A';
31029
31030 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31031 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
31032 index 3d80cf0..b77cc47 100644
31033 --- a/drivers/md/dm-stripe.c
31034 +++ b/drivers/md/dm-stripe.c
31035 @@ -20,7 +20,7 @@ struct stripe {
31036 struct dm_dev *dev;
31037 sector_t physical_start;
31038
31039 - atomic_t error_count;
31040 + atomic_unchecked_t error_count;
31041 };
31042
31043 struct stripe_c {
31044 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
31045 kfree(sc);
31046 return r;
31047 }
31048 - atomic_set(&(sc->stripe[i].error_count), 0);
31049 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
31050 }
31051
31052 ti->private = sc;
31053 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
31054 DMEMIT("%d ", sc->stripes);
31055 for (i = 0; i < sc->stripes; i++) {
31056 DMEMIT("%s ", sc->stripe[i].dev->name);
31057 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
31058 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
31059 'D' : 'A';
31060 }
31061 buffer[i] = '\0';
31062 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
31063 */
31064 for (i = 0; i < sc->stripes; i++)
31065 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
31066 - atomic_inc(&(sc->stripe[i].error_count));
31067 - if (atomic_read(&(sc->stripe[i].error_count)) <
31068 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
31069 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
31070 DM_IO_ERROR_THRESHOLD)
31071 schedule_work(&sc->trigger_event);
31072 }
31073 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
31074 index 8e91321..fd17aef 100644
31075 --- a/drivers/md/dm-table.c
31076 +++ b/drivers/md/dm-table.c
31077 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
31078 if (!dev_size)
31079 return 0;
31080
31081 - if ((start >= dev_size) || (start + len > dev_size)) {
31082 + if ((start >= dev_size) || (len > dev_size - start)) {
31083 DMWARN("%s: %s too small for target: "
31084 "start=%llu, len=%llu, dev_size=%llu",
31085 dm_device_name(ti->table->md), bdevname(bdev, b),
31086 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
31087 index 59c4f04..4c7b661 100644
31088 --- a/drivers/md/dm-thin-metadata.c
31089 +++ b/drivers/md/dm-thin-metadata.c
31090 @@ -431,7 +431,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
31091
31092 pmd->info.tm = tm;
31093 pmd->info.levels = 2;
31094 - pmd->info.value_type.context = pmd->data_sm;
31095 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
31096 pmd->info.value_type.size = sizeof(__le64);
31097 pmd->info.value_type.inc = data_block_inc;
31098 pmd->info.value_type.dec = data_block_dec;
31099 @@ -450,7 +450,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
31100
31101 pmd->bl_info.tm = tm;
31102 pmd->bl_info.levels = 1;
31103 - pmd->bl_info.value_type.context = pmd->data_sm;
31104 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
31105 pmd->bl_info.value_type.size = sizeof(__le64);
31106 pmd->bl_info.value_type.inc = data_block_inc;
31107 pmd->bl_info.value_type.dec = data_block_dec;
31108 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
31109 index 4720f68..78d1df7 100644
31110 --- a/drivers/md/dm.c
31111 +++ b/drivers/md/dm.c
31112 @@ -177,9 +177,9 @@ struct mapped_device {
31113 /*
31114 * Event handling.
31115 */
31116 - atomic_t event_nr;
31117 + atomic_unchecked_t event_nr;
31118 wait_queue_head_t eventq;
31119 - atomic_t uevent_seq;
31120 + atomic_unchecked_t uevent_seq;
31121 struct list_head uevent_list;
31122 spinlock_t uevent_lock; /* Protect access to uevent_list */
31123
31124 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
31125 rwlock_init(&md->map_lock);
31126 atomic_set(&md->holders, 1);
31127 atomic_set(&md->open_count, 0);
31128 - atomic_set(&md->event_nr, 0);
31129 - atomic_set(&md->uevent_seq, 0);
31130 + atomic_set_unchecked(&md->event_nr, 0);
31131 + atomic_set_unchecked(&md->uevent_seq, 0);
31132 INIT_LIST_HEAD(&md->uevent_list);
31133 spin_lock_init(&md->uevent_lock);
31134
31135 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
31136
31137 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31138
31139 - atomic_inc(&md->event_nr);
31140 + atomic_inc_unchecked(&md->event_nr);
31141 wake_up(&md->eventq);
31142 }
31143
31144 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
31145
31146 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31147 {
31148 - return atomic_add_return(1, &md->uevent_seq);
31149 + return atomic_add_return_unchecked(1, &md->uevent_seq);
31150 }
31151
31152 uint32_t dm_get_event_nr(struct mapped_device *md)
31153 {
31154 - return atomic_read(&md->event_nr);
31155 + return atomic_read_unchecked(&md->event_nr);
31156 }
31157
31158 int dm_wait_event(struct mapped_device *md, int event_nr)
31159 {
31160 return wait_event_interruptible(md->eventq,
31161 - (event_nr != atomic_read(&md->event_nr)));
31162 + (event_nr != atomic_read_unchecked(&md->event_nr)));
31163 }
31164
31165 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31166 diff --git a/drivers/md/md.c b/drivers/md/md.c
31167 index f47f1f8..b7f559e 100644
31168 --- a/drivers/md/md.c
31169 +++ b/drivers/md/md.c
31170 @@ -278,10 +278,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
31171 * start build, activate spare
31172 */
31173 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
31174 -static atomic_t md_event_count;
31175 +static atomic_unchecked_t md_event_count;
31176 void md_new_event(struct mddev *mddev)
31177 {
31178 - atomic_inc(&md_event_count);
31179 + atomic_inc_unchecked(&md_event_count);
31180 wake_up(&md_event_waiters);
31181 }
31182 EXPORT_SYMBOL_GPL(md_new_event);
31183 @@ -291,7 +291,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
31184 */
31185 static void md_new_event_inintr(struct mddev *mddev)
31186 {
31187 - atomic_inc(&md_event_count);
31188 + atomic_inc_unchecked(&md_event_count);
31189 wake_up(&md_event_waiters);
31190 }
31191
31192 @@ -1525,7 +1525,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
31193
31194 rdev->preferred_minor = 0xffff;
31195 rdev->data_offset = le64_to_cpu(sb->data_offset);
31196 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31197 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31198
31199 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
31200 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
31201 @@ -1742,7 +1742,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
31202 else
31203 sb->resync_offset = cpu_to_le64(0);
31204
31205 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
31206 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
31207
31208 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
31209 sb->size = cpu_to_le64(mddev->dev_sectors);
31210 @@ -2639,7 +2639,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
31211 static ssize_t
31212 errors_show(struct md_rdev *rdev, char *page)
31213 {
31214 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
31215 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
31216 }
31217
31218 static ssize_t
31219 @@ -2648,7 +2648,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
31220 char *e;
31221 unsigned long n = simple_strtoul(buf, &e, 10);
31222 if (*buf && (*e == 0 || *e == '\n')) {
31223 - atomic_set(&rdev->corrected_errors, n);
31224 + atomic_set_unchecked(&rdev->corrected_errors, n);
31225 return len;
31226 }
31227 return -EINVAL;
31228 @@ -3039,8 +3039,8 @@ int md_rdev_init(struct md_rdev *rdev)
31229 rdev->sb_loaded = 0;
31230 rdev->bb_page = NULL;
31231 atomic_set(&rdev->nr_pending, 0);
31232 - atomic_set(&rdev->read_errors, 0);
31233 - atomic_set(&rdev->corrected_errors, 0);
31234 + atomic_set_unchecked(&rdev->read_errors, 0);
31235 + atomic_set_unchecked(&rdev->corrected_errors, 0);
31236
31237 INIT_LIST_HEAD(&rdev->same_set);
31238 init_waitqueue_head(&rdev->blocked_wait);
31239 @@ -6683,7 +6683,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31240
31241 spin_unlock(&pers_lock);
31242 seq_printf(seq, "\n");
31243 - seq->poll_event = atomic_read(&md_event_count);
31244 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31245 return 0;
31246 }
31247 if (v == (void*)2) {
31248 @@ -6772,7 +6772,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31249 chunk_kb ? "KB" : "B");
31250 if (bitmap->file) {
31251 seq_printf(seq, ", file: ");
31252 - seq_path(seq, &bitmap->file->f_path, " \t\n");
31253 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
31254 }
31255
31256 seq_printf(seq, "\n");
31257 @@ -6803,7 +6803,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
31258 return error;
31259
31260 seq = file->private_data;
31261 - seq->poll_event = atomic_read(&md_event_count);
31262 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31263 return error;
31264 }
31265
31266 @@ -6817,7 +6817,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
31267 /* always allow read */
31268 mask = POLLIN | POLLRDNORM;
31269
31270 - if (seq->poll_event != atomic_read(&md_event_count))
31271 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
31272 mask |= POLLERR | POLLPRI;
31273 return mask;
31274 }
31275 @@ -6861,7 +6861,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
31276 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
31277 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
31278 (int)part_stat_read(&disk->part0, sectors[1]) -
31279 - atomic_read(&disk->sync_io);
31280 + atomic_read_unchecked(&disk->sync_io);
31281 /* sync IO will cause sync_io to increase before the disk_stats
31282 * as sync_io is counted when a request starts, and
31283 * disk_stats is counted when it completes.
31284 diff --git a/drivers/md/md.h b/drivers/md/md.h
31285 index cf742d9..7c7c745 100644
31286 --- a/drivers/md/md.h
31287 +++ b/drivers/md/md.h
31288 @@ -120,13 +120,13 @@ struct md_rdev {
31289 * only maintained for arrays that
31290 * support hot removal
31291 */
31292 - atomic_t read_errors; /* number of consecutive read errors that
31293 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
31294 * we have tried to ignore.
31295 */
31296 struct timespec last_read_error; /* monotonic time since our
31297 * last read error
31298 */
31299 - atomic_t corrected_errors; /* number of corrected read errors,
31300 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
31301 * for reporting to userspace and storing
31302 * in superblock.
31303 */
31304 @@ -410,7 +410,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
31305
31306 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
31307 {
31308 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31309 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31310 }
31311
31312 struct md_personality
31313 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
31314 index 50ed53b..4f29d7d 100644
31315 --- a/drivers/md/persistent-data/dm-space-map-checker.c
31316 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
31317 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
31318 /*----------------------------------------------------------------*/
31319
31320 struct sm_checker {
31321 - struct dm_space_map sm;
31322 + dm_space_map_no_const sm;
31323
31324 struct count_array old_counts;
31325 struct count_array counts;
31326 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
31327 index fc469ba..2d91555 100644
31328 --- a/drivers/md/persistent-data/dm-space-map-disk.c
31329 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
31330 @@ -23,7 +23,7 @@
31331 * Space map interface.
31332 */
31333 struct sm_disk {
31334 - struct dm_space_map sm;
31335 + dm_space_map_no_const sm;
31336
31337 struct ll_disk ll;
31338 struct ll_disk old_ll;
31339 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
31340 index e89ae5e..062e4c2 100644
31341 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
31342 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
31343 @@ -43,7 +43,7 @@ struct block_op {
31344 };
31345
31346 struct sm_metadata {
31347 - struct dm_space_map sm;
31348 + dm_space_map_no_const sm;
31349
31350 struct ll_disk ll;
31351 struct ll_disk old_ll;
31352 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
31353 index 1cbfc6b..56e1dbb 100644
31354 --- a/drivers/md/persistent-data/dm-space-map.h
31355 +++ b/drivers/md/persistent-data/dm-space-map.h
31356 @@ -60,6 +60,7 @@ struct dm_space_map {
31357 int (*root_size)(struct dm_space_map *sm, size_t *result);
31358 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
31359 };
31360 +typedef struct dm_space_map __no_const dm_space_map_no_const;
31361
31362 /*----------------------------------------------------------------*/
31363
31364 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
31365 index 7d9e071..015b1d5 100644
31366 --- a/drivers/md/raid1.c
31367 +++ b/drivers/md/raid1.c
31368 @@ -1568,7 +1568,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
31369 if (r1_sync_page_io(rdev, sect, s,
31370 bio->bi_io_vec[idx].bv_page,
31371 READ) != 0)
31372 - atomic_add(s, &rdev->corrected_errors);
31373 + atomic_add_unchecked(s, &rdev->corrected_errors);
31374 }
31375 sectors -= s;
31376 sect += s;
31377 @@ -1781,7 +1781,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
31378 test_bit(In_sync, &rdev->flags)) {
31379 if (r1_sync_page_io(rdev, sect, s,
31380 conf->tmppage, READ)) {
31381 - atomic_add(s, &rdev->corrected_errors);
31382 + atomic_add_unchecked(s, &rdev->corrected_errors);
31383 printk(KERN_INFO
31384 "md/raid1:%s: read error corrected "
31385 "(%d sectors at %llu on %s)\n",
31386 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
31387 index 685ddf3..955b087 100644
31388 --- a/drivers/md/raid10.c
31389 +++ b/drivers/md/raid10.c
31390 @@ -1440,7 +1440,7 @@ static void end_sync_read(struct bio *bio, int error)
31391 /* The write handler will notice the lack of
31392 * R10BIO_Uptodate and record any errors etc
31393 */
31394 - atomic_add(r10_bio->sectors,
31395 + atomic_add_unchecked(r10_bio->sectors,
31396 &conf->mirrors[d].rdev->corrected_errors);
31397
31398 /* for reconstruct, we always reschedule after a read.
31399 @@ -1740,7 +1740,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
31400 {
31401 struct timespec cur_time_mon;
31402 unsigned long hours_since_last;
31403 - unsigned int read_errors = atomic_read(&rdev->read_errors);
31404 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
31405
31406 ktime_get_ts(&cur_time_mon);
31407
31408 @@ -1762,9 +1762,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
31409 * overflowing the shift of read_errors by hours_since_last.
31410 */
31411 if (hours_since_last >= 8 * sizeof(read_errors))
31412 - atomic_set(&rdev->read_errors, 0);
31413 + atomic_set_unchecked(&rdev->read_errors, 0);
31414 else
31415 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
31416 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
31417 }
31418
31419 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
31420 @@ -1814,8 +1814,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31421 return;
31422
31423 check_decay_read_errors(mddev, rdev);
31424 - atomic_inc(&rdev->read_errors);
31425 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
31426 + atomic_inc_unchecked(&rdev->read_errors);
31427 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
31428 char b[BDEVNAME_SIZE];
31429 bdevname(rdev->bdev, b);
31430
31431 @@ -1823,7 +1823,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31432 "md/raid10:%s: %s: Raid device exceeded "
31433 "read_error threshold [cur %d:max %d]\n",
31434 mdname(mddev), b,
31435 - atomic_read(&rdev->read_errors), max_read_errors);
31436 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
31437 printk(KERN_NOTICE
31438 "md/raid10:%s: %s: Failing raid device\n",
31439 mdname(mddev), b);
31440 @@ -1968,7 +1968,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31441 (unsigned long long)(
31442 sect + rdev->data_offset),
31443 bdevname(rdev->bdev, b));
31444 - atomic_add(s, &rdev->corrected_errors);
31445 + atomic_add_unchecked(s, &rdev->corrected_errors);
31446 }
31447
31448 rdev_dec_pending(rdev, mddev);
31449 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
31450 index 858fdbb..b2dac95 100644
31451 --- a/drivers/md/raid5.c
31452 +++ b/drivers/md/raid5.c
31453 @@ -1610,19 +1610,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
31454 (unsigned long long)(sh->sector
31455 + rdev->data_offset),
31456 bdevname(rdev->bdev, b));
31457 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
31458 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
31459 clear_bit(R5_ReadError, &sh->dev[i].flags);
31460 clear_bit(R5_ReWrite, &sh->dev[i].flags);
31461 }
31462 - if (atomic_read(&conf->disks[i].rdev->read_errors))
31463 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
31464 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
31465 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
31466 } else {
31467 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
31468 int retry = 0;
31469 rdev = conf->disks[i].rdev;
31470
31471 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
31472 - atomic_inc(&rdev->read_errors);
31473 + atomic_inc_unchecked(&rdev->read_errors);
31474 if (conf->mddev->degraded >= conf->max_degraded)
31475 printk_ratelimited(
31476 KERN_WARNING
31477 @@ -1642,7 +1642,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
31478 (unsigned long long)(sh->sector
31479 + rdev->data_offset),
31480 bdn);
31481 - else if (atomic_read(&rdev->read_errors)
31482 + else if (atomic_read_unchecked(&rdev->read_errors)
31483 > conf->max_nr_stripes)
31484 printk(KERN_WARNING
31485 "md/raid:%s: Too many read errors, failing device %s.\n",
31486 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
31487 index ba9a643..e474ab5 100644
31488 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
31489 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
31490 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
31491 .subvendor = _subvend, .subdevice = _subdev, \
31492 .driver_data = (unsigned long)&_driverdata }
31493
31494 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
31495 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
31496 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
31497 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
31498 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
31499 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
31500 index a7d876f..8c21b61 100644
31501 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
31502 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
31503 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
31504 union {
31505 dmx_ts_cb ts;
31506 dmx_section_cb sec;
31507 - } cb;
31508 + } __no_const cb;
31509
31510 struct dvb_demux *demux;
31511 void *priv;
31512 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
31513 index f732877..d38c35a 100644
31514 --- a/drivers/media/dvb/dvb-core/dvbdev.c
31515 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
31516 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
31517 const struct dvb_device *template, void *priv, int type)
31518 {
31519 struct dvb_device *dvbdev;
31520 - struct file_operations *dvbdevfops;
31521 + file_operations_no_const *dvbdevfops;
31522 struct device *clsdev;
31523 int minor;
31524 int id;
31525 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
31526 index 9f2a02c..5920f88 100644
31527 --- a/drivers/media/dvb/dvb-usb/cxusb.c
31528 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
31529 @@ -1069,7 +1069,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
31530 struct dib0700_adapter_state {
31531 int (*set_param_save) (struct dvb_frontend *,
31532 struct dvb_frontend_parameters *);
31533 -};
31534 +} __no_const;
31535
31536 static int dib7070_set_param_override(struct dvb_frontend *fe,
31537 struct dvb_frontend_parameters *fep)
31538 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
31539 index f103ec1..5e8968b 100644
31540 --- a/drivers/media/dvb/dvb-usb/dw2102.c
31541 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
31542 @@ -95,7 +95,7 @@ struct su3000_state {
31543
31544 struct s6x0_state {
31545 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
31546 -};
31547 +} __no_const;
31548
31549 /* debug */
31550 static int dvb_usb_dw2102_debug;
31551 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
31552 index 404f63a..4796533 100644
31553 --- a/drivers/media/dvb/frontends/dib3000.h
31554 +++ b/drivers/media/dvb/frontends/dib3000.h
31555 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
31556 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
31557 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
31558 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
31559 -};
31560 +} __no_const;
31561
31562 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
31563 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
31564 diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
31565 index 90bf573..e8463da 100644
31566 --- a/drivers/media/dvb/frontends/ds3000.c
31567 +++ b/drivers/media/dvb/frontends/ds3000.c
31568 @@ -1210,7 +1210,7 @@ static int ds3000_set_frontend(struct dvb_frontend *fe,
31569
31570 for (i = 0; i < 30 ; i++) {
31571 ds3000_read_status(fe, &status);
31572 - if (status && FE_HAS_LOCK)
31573 + if (status & FE_HAS_LOCK)
31574 break;
31575
31576 msleep(10);
31577 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
31578 index 0564192..75b16f5 100644
31579 --- a/drivers/media/dvb/ngene/ngene-cards.c
31580 +++ b/drivers/media/dvb/ngene/ngene-cards.c
31581 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
31582
31583 /****************************************************************************/
31584
31585 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
31586 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
31587 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
31588 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
31589 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
31590 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
31591 index 16a089f..ab1667d 100644
31592 --- a/drivers/media/radio/radio-cadet.c
31593 +++ b/drivers/media/radio/radio-cadet.c
31594 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
31595 unsigned char readbuf[RDS_BUFFER];
31596 int i = 0;
31597
31598 + if (count > RDS_BUFFER)
31599 + return -EFAULT;
31600 mutex_lock(&dev->lock);
31601 if (dev->rdsstat == 0) {
31602 dev->rdsstat = 1;
31603 diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
31604 index 61287fc..8b08712 100644
31605 --- a/drivers/media/rc/redrat3.c
31606 +++ b/drivers/media/rc/redrat3.c
31607 @@ -905,7 +905,7 @@ static int redrat3_set_tx_carrier(struct rc_dev *dev, u32 carrier)
31608 return carrier;
31609 }
31610
31611 -static int redrat3_transmit_ir(struct rc_dev *rcdev, int *txbuf, u32 n)
31612 +static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, u32 n)
31613 {
31614 struct redrat3_dev *rr3 = rcdev->priv;
31615 struct device *dev = rr3->dev;
31616 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
31617 index 9cde353..8c6a1c3 100644
31618 --- a/drivers/media/video/au0828/au0828.h
31619 +++ b/drivers/media/video/au0828/au0828.h
31620 @@ -191,7 +191,7 @@ struct au0828_dev {
31621
31622 /* I2C */
31623 struct i2c_adapter i2c_adap;
31624 - struct i2c_algorithm i2c_algo;
31625 + i2c_algorithm_no_const i2c_algo;
31626 struct i2c_client i2c_client;
31627 u32 i2c_rc;
31628
31629 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
31630 index 68d1240..46b32eb 100644
31631 --- a/drivers/media/video/cx88/cx88-alsa.c
31632 +++ b/drivers/media/video/cx88/cx88-alsa.c
31633 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
31634 * Only boards with eeprom and byte 1 at eeprom=1 have it
31635 */
31636
31637 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
31638 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
31639 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
31640 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
31641 {0, }
31642 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31643 index 305e6aa..0143317 100644
31644 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31645 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31646 @@ -196,7 +196,7 @@ struct pvr2_hdw {
31647
31648 /* I2C stuff */
31649 struct i2c_adapter i2c_adap;
31650 - struct i2c_algorithm i2c_algo;
31651 + i2c_algorithm_no_const i2c_algo;
31652 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
31653 int i2c_cx25840_hack_state;
31654 int i2c_linked;
31655 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
31656 index a0895bf..b7ebb1b 100644
31657 --- a/drivers/media/video/timblogiw.c
31658 +++ b/drivers/media/video/timblogiw.c
31659 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
31660
31661 /* Platform device functions */
31662
31663 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
31664 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
31665 .vidioc_querycap = timblogiw_querycap,
31666 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
31667 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
31668 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
31669 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
31670 };
31671
31672 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
31673 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
31674 .owner = THIS_MODULE,
31675 .open = timblogiw_open,
31676 .release = timblogiw_close,
31677 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
31678 index e9c6a60..daf6a33 100644
31679 --- a/drivers/message/fusion/mptbase.c
31680 +++ b/drivers/message/fusion/mptbase.c
31681 @@ -6753,8 +6753,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
31682 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
31683 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
31684
31685 +#ifdef CONFIG_GRKERNSEC_HIDESYM
31686 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
31687 +#else
31688 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
31689 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
31690 +#endif
31691 +
31692 /*
31693 * Rounding UP to nearest 4-kB boundary here...
31694 */
31695 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
31696 index 9d95042..b808101 100644
31697 --- a/drivers/message/fusion/mptsas.c
31698 +++ b/drivers/message/fusion/mptsas.c
31699 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
31700 return 0;
31701 }
31702
31703 +static inline void
31704 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
31705 +{
31706 + if (phy_info->port_details) {
31707 + phy_info->port_details->rphy = rphy;
31708 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
31709 + ioc->name, rphy));
31710 + }
31711 +
31712 + if (rphy) {
31713 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
31714 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
31715 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
31716 + ioc->name, rphy, rphy->dev.release));
31717 + }
31718 +}
31719 +
31720 /* no mutex */
31721 static void
31722 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
31723 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
31724 return NULL;
31725 }
31726
31727 -static inline void
31728 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
31729 -{
31730 - if (phy_info->port_details) {
31731 - phy_info->port_details->rphy = rphy;
31732 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
31733 - ioc->name, rphy));
31734 - }
31735 -
31736 - if (rphy) {
31737 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
31738 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
31739 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
31740 - ioc->name, rphy, rphy->dev.release));
31741 - }
31742 -}
31743 -
31744 static inline struct sas_port *
31745 mptsas_get_port(struct mptsas_phyinfo *phy_info)
31746 {
31747 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
31748 index 0c3ced7..1fe34ec 100644
31749 --- a/drivers/message/fusion/mptscsih.c
31750 +++ b/drivers/message/fusion/mptscsih.c
31751 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
31752
31753 h = shost_priv(SChost);
31754
31755 - if (h) {
31756 - if (h->info_kbuf == NULL)
31757 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
31758 - return h->info_kbuf;
31759 - h->info_kbuf[0] = '\0';
31760 + if (!h)
31761 + return NULL;
31762
31763 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
31764 - h->info_kbuf[size-1] = '\0';
31765 - }
31766 + if (h->info_kbuf == NULL)
31767 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
31768 + return h->info_kbuf;
31769 + h->info_kbuf[0] = '\0';
31770 +
31771 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
31772 + h->info_kbuf[size-1] = '\0';
31773
31774 return h->info_kbuf;
31775 }
31776 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
31777 index 07dbeaf..5533142 100644
31778 --- a/drivers/message/i2o/i2o_proc.c
31779 +++ b/drivers/message/i2o/i2o_proc.c
31780 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
31781 "Array Controller Device"
31782 };
31783
31784 -static char *chtostr(u8 * chars, int n)
31785 -{
31786 - char tmp[256];
31787 - tmp[0] = 0;
31788 - return strncat(tmp, (char *)chars, n);
31789 -}
31790 -
31791 static int i2o_report_query_status(struct seq_file *seq, int block_status,
31792 char *group)
31793 {
31794 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
31795
31796 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
31797 seq_printf(seq, "%-#8x", ddm_table.module_id);
31798 - seq_printf(seq, "%-29s",
31799 - chtostr(ddm_table.module_name_version, 28));
31800 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
31801 seq_printf(seq, "%9d ", ddm_table.data_size);
31802 seq_printf(seq, "%8d", ddm_table.code_size);
31803
31804 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
31805
31806 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
31807 seq_printf(seq, "%-#8x", dst->module_id);
31808 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
31809 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
31810 + seq_printf(seq, "%-.28s", dst->module_name_version);
31811 + seq_printf(seq, "%-.8s", dst->date);
31812 seq_printf(seq, "%8d ", dst->module_size);
31813 seq_printf(seq, "%8d ", dst->mpb_size);
31814 seq_printf(seq, "0x%04x", dst->module_flags);
31815 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
31816 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
31817 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
31818 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
31819 - seq_printf(seq, "Vendor info : %s\n",
31820 - chtostr((u8 *) (work32 + 2), 16));
31821 - seq_printf(seq, "Product info : %s\n",
31822 - chtostr((u8 *) (work32 + 6), 16));
31823 - seq_printf(seq, "Description : %s\n",
31824 - chtostr((u8 *) (work32 + 10), 16));
31825 - seq_printf(seq, "Product rev. : %s\n",
31826 - chtostr((u8 *) (work32 + 14), 8));
31827 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
31828 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
31829 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
31830 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
31831
31832 seq_printf(seq, "Serial number : ");
31833 print_serial_number(seq, (u8 *) (work32 + 16),
31834 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
31835 }
31836
31837 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
31838 - seq_printf(seq, "Module name : %s\n",
31839 - chtostr(result.module_name, 24));
31840 - seq_printf(seq, "Module revision : %s\n",
31841 - chtostr(result.module_rev, 8));
31842 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
31843 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
31844
31845 seq_printf(seq, "Serial number : ");
31846 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
31847 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
31848 return 0;
31849 }
31850
31851 - seq_printf(seq, "Device name : %s\n",
31852 - chtostr(result.device_name, 64));
31853 - seq_printf(seq, "Service name : %s\n",
31854 - chtostr(result.service_name, 64));
31855 - seq_printf(seq, "Physical name : %s\n",
31856 - chtostr(result.physical_location, 64));
31857 - seq_printf(seq, "Instance number : %s\n",
31858 - chtostr(result.instance_number, 4));
31859 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
31860 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
31861 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
31862 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
31863
31864 return 0;
31865 }
31866 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
31867 index a8c08f3..155fe3d 100644
31868 --- a/drivers/message/i2o/iop.c
31869 +++ b/drivers/message/i2o/iop.c
31870 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
31871
31872 spin_lock_irqsave(&c->context_list_lock, flags);
31873
31874 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
31875 - atomic_inc(&c->context_list_counter);
31876 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
31877 + atomic_inc_unchecked(&c->context_list_counter);
31878
31879 - entry->context = atomic_read(&c->context_list_counter);
31880 + entry->context = atomic_read_unchecked(&c->context_list_counter);
31881
31882 list_add(&entry->list, &c->context_list);
31883
31884 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
31885
31886 #if BITS_PER_LONG == 64
31887 spin_lock_init(&c->context_list_lock);
31888 - atomic_set(&c->context_list_counter, 0);
31889 + atomic_set_unchecked(&c->context_list_counter, 0);
31890 INIT_LIST_HEAD(&c->context_list);
31891 #endif
31892
31893 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
31894 index 7ce65f4..e66e9bc 100644
31895 --- a/drivers/mfd/abx500-core.c
31896 +++ b/drivers/mfd/abx500-core.c
31897 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
31898
31899 struct abx500_device_entry {
31900 struct list_head list;
31901 - struct abx500_ops ops;
31902 + abx500_ops_no_const ops;
31903 struct device *dev;
31904 };
31905
31906 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
31907 index 5c2a06a..8fa077c 100644
31908 --- a/drivers/mfd/janz-cmodio.c
31909 +++ b/drivers/mfd/janz-cmodio.c
31910 @@ -13,6 +13,7 @@
31911
31912 #include <linux/kernel.h>
31913 #include <linux/module.h>
31914 +#include <linux/slab.h>
31915 #include <linux/init.h>
31916 #include <linux/pci.h>
31917 #include <linux/interrupt.h>
31918 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
31919 index 29d12a7..f900ba4 100644
31920 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
31921 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
31922 @@ -464,7 +464,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
31923 * the lid is closed. This leads to interrupts as soon as a little move
31924 * is done.
31925 */
31926 - atomic_inc(&lis3->count);
31927 + atomic_inc_unchecked(&lis3->count);
31928
31929 wake_up_interruptible(&lis3->misc_wait);
31930 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
31931 @@ -550,7 +550,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
31932 if (lis3->pm_dev)
31933 pm_runtime_get_sync(lis3->pm_dev);
31934
31935 - atomic_set(&lis3->count, 0);
31936 + atomic_set_unchecked(&lis3->count, 0);
31937 return 0;
31938 }
31939
31940 @@ -583,7 +583,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
31941 add_wait_queue(&lis3->misc_wait, &wait);
31942 while (true) {
31943 set_current_state(TASK_INTERRUPTIBLE);
31944 - data = atomic_xchg(&lis3->count, 0);
31945 + data = atomic_xchg_unchecked(&lis3->count, 0);
31946 if (data)
31947 break;
31948
31949 @@ -624,7 +624,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
31950 struct lis3lv02d, miscdev);
31951
31952 poll_wait(file, &lis3->misc_wait, wait);
31953 - if (atomic_read(&lis3->count))
31954 + if (atomic_read_unchecked(&lis3->count))
31955 return POLLIN | POLLRDNORM;
31956 return 0;
31957 }
31958 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
31959 index 2b1482a..5d33616 100644
31960 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
31961 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
31962 @@ -266,7 +266,7 @@ struct lis3lv02d {
31963 struct input_polled_dev *idev; /* input device */
31964 struct platform_device *pdev; /* platform device */
31965 struct regulator_bulk_data regulators[2];
31966 - atomic_t count; /* interrupt count after last read */
31967 + atomic_unchecked_t count; /* interrupt count after last read */
31968 union axis_conversion ac; /* hw -> logical axis */
31969 int mapped_btns[3];
31970
31971 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
31972 index 2f30bad..c4c13d0 100644
31973 --- a/drivers/misc/sgi-gru/gruhandles.c
31974 +++ b/drivers/misc/sgi-gru/gruhandles.c
31975 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
31976 unsigned long nsec;
31977
31978 nsec = CLKS2NSEC(clks);
31979 - atomic_long_inc(&mcs_op_statistics[op].count);
31980 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
31981 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
31982 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
31983 if (mcs_op_statistics[op].max < nsec)
31984 mcs_op_statistics[op].max = nsec;
31985 }
31986 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
31987 index 7768b87..f8aac38 100644
31988 --- a/drivers/misc/sgi-gru/gruprocfs.c
31989 +++ b/drivers/misc/sgi-gru/gruprocfs.c
31990 @@ -32,9 +32,9 @@
31991
31992 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
31993
31994 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
31995 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
31996 {
31997 - unsigned long val = atomic_long_read(v);
31998 + unsigned long val = atomic_long_read_unchecked(v);
31999
32000 seq_printf(s, "%16lu %s\n", val, id);
32001 }
32002 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
32003
32004 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
32005 for (op = 0; op < mcsop_last; op++) {
32006 - count = atomic_long_read(&mcs_op_statistics[op].count);
32007 - total = atomic_long_read(&mcs_op_statistics[op].total);
32008 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
32009 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
32010 max = mcs_op_statistics[op].max;
32011 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
32012 count ? total / count : 0, max);
32013 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
32014 index 5c3ce24..4915ccb 100644
32015 --- a/drivers/misc/sgi-gru/grutables.h
32016 +++ b/drivers/misc/sgi-gru/grutables.h
32017 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
32018 * GRU statistics.
32019 */
32020 struct gru_stats_s {
32021 - atomic_long_t vdata_alloc;
32022 - atomic_long_t vdata_free;
32023 - atomic_long_t gts_alloc;
32024 - atomic_long_t gts_free;
32025 - atomic_long_t gms_alloc;
32026 - atomic_long_t gms_free;
32027 - atomic_long_t gts_double_allocate;
32028 - atomic_long_t assign_context;
32029 - atomic_long_t assign_context_failed;
32030 - atomic_long_t free_context;
32031 - atomic_long_t load_user_context;
32032 - atomic_long_t load_kernel_context;
32033 - atomic_long_t lock_kernel_context;
32034 - atomic_long_t unlock_kernel_context;
32035 - atomic_long_t steal_user_context;
32036 - atomic_long_t steal_kernel_context;
32037 - atomic_long_t steal_context_failed;
32038 - atomic_long_t nopfn;
32039 - atomic_long_t asid_new;
32040 - atomic_long_t asid_next;
32041 - atomic_long_t asid_wrap;
32042 - atomic_long_t asid_reuse;
32043 - atomic_long_t intr;
32044 - atomic_long_t intr_cbr;
32045 - atomic_long_t intr_tfh;
32046 - atomic_long_t intr_spurious;
32047 - atomic_long_t intr_mm_lock_failed;
32048 - atomic_long_t call_os;
32049 - atomic_long_t call_os_wait_queue;
32050 - atomic_long_t user_flush_tlb;
32051 - atomic_long_t user_unload_context;
32052 - atomic_long_t user_exception;
32053 - atomic_long_t set_context_option;
32054 - atomic_long_t check_context_retarget_intr;
32055 - atomic_long_t check_context_unload;
32056 - atomic_long_t tlb_dropin;
32057 - atomic_long_t tlb_preload_page;
32058 - atomic_long_t tlb_dropin_fail_no_asid;
32059 - atomic_long_t tlb_dropin_fail_upm;
32060 - atomic_long_t tlb_dropin_fail_invalid;
32061 - atomic_long_t tlb_dropin_fail_range_active;
32062 - atomic_long_t tlb_dropin_fail_idle;
32063 - atomic_long_t tlb_dropin_fail_fmm;
32064 - atomic_long_t tlb_dropin_fail_no_exception;
32065 - atomic_long_t tfh_stale_on_fault;
32066 - atomic_long_t mmu_invalidate_range;
32067 - atomic_long_t mmu_invalidate_page;
32068 - atomic_long_t flush_tlb;
32069 - atomic_long_t flush_tlb_gru;
32070 - atomic_long_t flush_tlb_gru_tgh;
32071 - atomic_long_t flush_tlb_gru_zero_asid;
32072 + atomic_long_unchecked_t vdata_alloc;
32073 + atomic_long_unchecked_t vdata_free;
32074 + atomic_long_unchecked_t gts_alloc;
32075 + atomic_long_unchecked_t gts_free;
32076 + atomic_long_unchecked_t gms_alloc;
32077 + atomic_long_unchecked_t gms_free;
32078 + atomic_long_unchecked_t gts_double_allocate;
32079 + atomic_long_unchecked_t assign_context;
32080 + atomic_long_unchecked_t assign_context_failed;
32081 + atomic_long_unchecked_t free_context;
32082 + atomic_long_unchecked_t load_user_context;
32083 + atomic_long_unchecked_t load_kernel_context;
32084 + atomic_long_unchecked_t lock_kernel_context;
32085 + atomic_long_unchecked_t unlock_kernel_context;
32086 + atomic_long_unchecked_t steal_user_context;
32087 + atomic_long_unchecked_t steal_kernel_context;
32088 + atomic_long_unchecked_t steal_context_failed;
32089 + atomic_long_unchecked_t nopfn;
32090 + atomic_long_unchecked_t asid_new;
32091 + atomic_long_unchecked_t asid_next;
32092 + atomic_long_unchecked_t asid_wrap;
32093 + atomic_long_unchecked_t asid_reuse;
32094 + atomic_long_unchecked_t intr;
32095 + atomic_long_unchecked_t intr_cbr;
32096 + atomic_long_unchecked_t intr_tfh;
32097 + atomic_long_unchecked_t intr_spurious;
32098 + atomic_long_unchecked_t intr_mm_lock_failed;
32099 + atomic_long_unchecked_t call_os;
32100 + atomic_long_unchecked_t call_os_wait_queue;
32101 + atomic_long_unchecked_t user_flush_tlb;
32102 + atomic_long_unchecked_t user_unload_context;
32103 + atomic_long_unchecked_t user_exception;
32104 + atomic_long_unchecked_t set_context_option;
32105 + atomic_long_unchecked_t check_context_retarget_intr;
32106 + atomic_long_unchecked_t check_context_unload;
32107 + atomic_long_unchecked_t tlb_dropin;
32108 + atomic_long_unchecked_t tlb_preload_page;
32109 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
32110 + atomic_long_unchecked_t tlb_dropin_fail_upm;
32111 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
32112 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
32113 + atomic_long_unchecked_t tlb_dropin_fail_idle;
32114 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
32115 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
32116 + atomic_long_unchecked_t tfh_stale_on_fault;
32117 + atomic_long_unchecked_t mmu_invalidate_range;
32118 + atomic_long_unchecked_t mmu_invalidate_page;
32119 + atomic_long_unchecked_t flush_tlb;
32120 + atomic_long_unchecked_t flush_tlb_gru;
32121 + atomic_long_unchecked_t flush_tlb_gru_tgh;
32122 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
32123
32124 - atomic_long_t copy_gpa;
32125 - atomic_long_t read_gpa;
32126 + atomic_long_unchecked_t copy_gpa;
32127 + atomic_long_unchecked_t read_gpa;
32128
32129 - atomic_long_t mesq_receive;
32130 - atomic_long_t mesq_receive_none;
32131 - atomic_long_t mesq_send;
32132 - atomic_long_t mesq_send_failed;
32133 - atomic_long_t mesq_noop;
32134 - atomic_long_t mesq_send_unexpected_error;
32135 - atomic_long_t mesq_send_lb_overflow;
32136 - atomic_long_t mesq_send_qlimit_reached;
32137 - atomic_long_t mesq_send_amo_nacked;
32138 - atomic_long_t mesq_send_put_nacked;
32139 - atomic_long_t mesq_page_overflow;
32140 - atomic_long_t mesq_qf_locked;
32141 - atomic_long_t mesq_qf_noop_not_full;
32142 - atomic_long_t mesq_qf_switch_head_failed;
32143 - atomic_long_t mesq_qf_unexpected_error;
32144 - atomic_long_t mesq_noop_unexpected_error;
32145 - atomic_long_t mesq_noop_lb_overflow;
32146 - atomic_long_t mesq_noop_qlimit_reached;
32147 - atomic_long_t mesq_noop_amo_nacked;
32148 - atomic_long_t mesq_noop_put_nacked;
32149 - atomic_long_t mesq_noop_page_overflow;
32150 + atomic_long_unchecked_t mesq_receive;
32151 + atomic_long_unchecked_t mesq_receive_none;
32152 + atomic_long_unchecked_t mesq_send;
32153 + atomic_long_unchecked_t mesq_send_failed;
32154 + atomic_long_unchecked_t mesq_noop;
32155 + atomic_long_unchecked_t mesq_send_unexpected_error;
32156 + atomic_long_unchecked_t mesq_send_lb_overflow;
32157 + atomic_long_unchecked_t mesq_send_qlimit_reached;
32158 + atomic_long_unchecked_t mesq_send_amo_nacked;
32159 + atomic_long_unchecked_t mesq_send_put_nacked;
32160 + atomic_long_unchecked_t mesq_page_overflow;
32161 + atomic_long_unchecked_t mesq_qf_locked;
32162 + atomic_long_unchecked_t mesq_qf_noop_not_full;
32163 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
32164 + atomic_long_unchecked_t mesq_qf_unexpected_error;
32165 + atomic_long_unchecked_t mesq_noop_unexpected_error;
32166 + atomic_long_unchecked_t mesq_noop_lb_overflow;
32167 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
32168 + atomic_long_unchecked_t mesq_noop_amo_nacked;
32169 + atomic_long_unchecked_t mesq_noop_put_nacked;
32170 + atomic_long_unchecked_t mesq_noop_page_overflow;
32171
32172 };
32173
32174 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
32175 tghop_invalidate, mcsop_last};
32176
32177 struct mcs_op_statistic {
32178 - atomic_long_t count;
32179 - atomic_long_t total;
32180 + atomic_long_unchecked_t count;
32181 + atomic_long_unchecked_t total;
32182 unsigned long max;
32183 };
32184
32185 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
32186
32187 #define STAT(id) do { \
32188 if (gru_options & OPT_STATS) \
32189 - atomic_long_inc(&gru_stats.id); \
32190 + atomic_long_inc_unchecked(&gru_stats.id); \
32191 } while (0)
32192
32193 #ifdef CONFIG_SGI_GRU_DEBUG
32194 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
32195 index 851b2f2..a4ec097 100644
32196 --- a/drivers/misc/sgi-xp/xp.h
32197 +++ b/drivers/misc/sgi-xp/xp.h
32198 @@ -289,7 +289,7 @@ struct xpc_interface {
32199 xpc_notify_func, void *);
32200 void (*received) (short, int, void *);
32201 enum xp_retval (*partid_to_nasids) (short, void *);
32202 -};
32203 +} __no_const;
32204
32205 extern struct xpc_interface xpc_interface;
32206
32207 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
32208 index b94d5f7..7f494c5 100644
32209 --- a/drivers/misc/sgi-xp/xpc.h
32210 +++ b/drivers/misc/sgi-xp/xpc.h
32211 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
32212 void (*received_payload) (struct xpc_channel *, void *);
32213 void (*notify_senders_of_disconnect) (struct xpc_channel *);
32214 };
32215 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
32216
32217 /* struct xpc_partition act_state values (for XPC HB) */
32218
32219 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
32220 /* found in xpc_main.c */
32221 extern struct device *xpc_part;
32222 extern struct device *xpc_chan;
32223 -extern struct xpc_arch_operations xpc_arch_ops;
32224 +extern xpc_arch_operations_no_const xpc_arch_ops;
32225 extern int xpc_disengage_timelimit;
32226 extern int xpc_disengage_timedout;
32227 extern int xpc_activate_IRQ_rcvd;
32228 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
32229 index 8d082b4..aa749ae 100644
32230 --- a/drivers/misc/sgi-xp/xpc_main.c
32231 +++ b/drivers/misc/sgi-xp/xpc_main.c
32232 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
32233 .notifier_call = xpc_system_die,
32234 };
32235
32236 -struct xpc_arch_operations xpc_arch_ops;
32237 +xpc_arch_operations_no_const xpc_arch_ops;
32238
32239 /*
32240 * Timer function to enforce the timelimit on the partition disengage.
32241 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
32242 index 6878a94..fe5c5f1 100644
32243 --- a/drivers/mmc/host/sdhci-pci.c
32244 +++ b/drivers/mmc/host/sdhci-pci.c
32245 @@ -673,7 +673,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
32246 .probe = via_probe,
32247 };
32248
32249 -static const struct pci_device_id pci_ids[] __devinitdata = {
32250 +static const struct pci_device_id pci_ids[] __devinitconst = {
32251 {
32252 .vendor = PCI_VENDOR_ID_RICOH,
32253 .device = PCI_DEVICE_ID_RICOH_R5C822,
32254 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
32255 index e9fad91..0a7a16a 100644
32256 --- a/drivers/mtd/devices/doc2000.c
32257 +++ b/drivers/mtd/devices/doc2000.c
32258 @@ -773,7 +773,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
32259
32260 /* The ECC will not be calculated correctly if less than 512 is written */
32261 /* DBB-
32262 - if (len != 0x200 && eccbuf)
32263 + if (len != 0x200)
32264 printk(KERN_WARNING
32265 "ECC needs a full sector write (adr: %lx size %lx)\n",
32266 (long) to, (long) len);
32267 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
32268 index a3f7a27..234016e 100644
32269 --- a/drivers/mtd/devices/doc2001.c
32270 +++ b/drivers/mtd/devices/doc2001.c
32271 @@ -392,7 +392,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
32272 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
32273
32274 /* Don't allow read past end of device */
32275 - if (from >= this->totlen)
32276 + if (from >= this->totlen || !len)
32277 return -EINVAL;
32278
32279 /* Don't allow a single read to cross a 512-byte block boundary */
32280 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
32281 index 3984d48..28aa897 100644
32282 --- a/drivers/mtd/nand/denali.c
32283 +++ b/drivers/mtd/nand/denali.c
32284 @@ -26,6 +26,7 @@
32285 #include <linux/pci.h>
32286 #include <linux/mtd/mtd.h>
32287 #include <linux/module.h>
32288 +#include <linux/slab.h>
32289
32290 #include "denali.h"
32291
32292 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
32293 index ac40925..483b753 100644
32294 --- a/drivers/mtd/nftlmount.c
32295 +++ b/drivers/mtd/nftlmount.c
32296 @@ -24,6 +24,7 @@
32297 #include <asm/errno.h>
32298 #include <linux/delay.h>
32299 #include <linux/slab.h>
32300 +#include <linux/sched.h>
32301 #include <linux/mtd/mtd.h>
32302 #include <linux/mtd/nand.h>
32303 #include <linux/mtd/nftl.h>
32304 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
32305 index 6c3fb5a..c542a81 100644
32306 --- a/drivers/mtd/ubi/build.c
32307 +++ b/drivers/mtd/ubi/build.c
32308 @@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
32309 static int __init bytes_str_to_int(const char *str)
32310 {
32311 char *endp;
32312 - unsigned long result;
32313 + unsigned long result, scale = 1;
32314
32315 result = simple_strtoul(str, &endp, 0);
32316 if (str == endp || result >= INT_MAX) {
32317 @@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
32318
32319 switch (*endp) {
32320 case 'G':
32321 - result *= 1024;
32322 + scale *= 1024;
32323 case 'M':
32324 - result *= 1024;
32325 + scale *= 1024;
32326 case 'K':
32327 - result *= 1024;
32328 + scale *= 1024;
32329 if (endp[1] == 'i' && endp[2] == 'B')
32330 endp += 2;
32331 case '\0':
32332 @@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
32333 return -EINVAL;
32334 }
32335
32336 - return result;
32337 + if ((intoverflow_t)result*scale >= INT_MAX) {
32338 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
32339 + str);
32340 + return -EINVAL;
32341 + }
32342 +
32343 + return result*scale;
32344 }
32345
32346 /**
32347 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
32348 index 1feae59..c2a61d2 100644
32349 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
32350 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
32351 @@ -2857,7 +2857,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
32352 */
32353
32354 #define ATL2_PARAM(X, desc) \
32355 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
32356 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
32357 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
32358 MODULE_PARM_DESC(X, desc);
32359 #else
32360 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32361 index 9a517c2..a50cfcb 100644
32362 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32363 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32364 @@ -449,7 +449,7 @@ struct bnx2x_rx_mode_obj {
32365
32366 int (*wait_comp)(struct bnx2x *bp,
32367 struct bnx2x_rx_mode_ramrod_params *p);
32368 -};
32369 +} __no_const;
32370
32371 /********************** Set multicast group ***********************************/
32372
32373 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
32374 index 94b4bd0..73c02de 100644
32375 --- a/drivers/net/ethernet/broadcom/tg3.h
32376 +++ b/drivers/net/ethernet/broadcom/tg3.h
32377 @@ -134,6 +134,7 @@
32378 #define CHIPREV_ID_5750_A0 0x4000
32379 #define CHIPREV_ID_5750_A1 0x4001
32380 #define CHIPREV_ID_5750_A3 0x4003
32381 +#define CHIPREV_ID_5750_C1 0x4201
32382 #define CHIPREV_ID_5750_C2 0x4202
32383 #define CHIPREV_ID_5752_A0_HW 0x5000
32384 #define CHIPREV_ID_5752_A0 0x6000
32385 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32386 index c5f5479..2e8c260 100644
32387 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32388 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32389 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
32390 */
32391 struct l2t_skb_cb {
32392 arp_failure_handler_func arp_failure_handler;
32393 -};
32394 +} __no_const;
32395
32396 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
32397
32398 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
32399 index 871bcaa..4043505 100644
32400 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
32401 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
32402 @@ -5397,7 +5397,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
32403 for (i=0; i<ETH_ALEN; i++) {
32404 tmp.addr[i] = dev->dev_addr[i];
32405 }
32406 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
32407 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
32408 break;
32409
32410 case DE4X5_SET_HWADDR: /* Set the hardware address */
32411 @@ -5437,7 +5437,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
32412 spin_lock_irqsave(&lp->lock, flags);
32413 memcpy(&statbuf, &lp->pktStats, ioc->len);
32414 spin_unlock_irqrestore(&lp->lock, flags);
32415 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
32416 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
32417 return -EFAULT;
32418 break;
32419 }
32420 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
32421 index 14d5b61..1398636 100644
32422 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
32423 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
32424 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
32425 {NULL}};
32426
32427
32428 -static const char *block_name[] __devinitdata = {
32429 +static const char *block_name[] __devinitconst = {
32430 "21140 non-MII",
32431 "21140 MII PHY",
32432 "21142 Serial PHY",
32433 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
32434 index 4d01219..b58d26d 100644
32435 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
32436 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
32437 @@ -236,7 +236,7 @@ struct pci_id_info {
32438 int drv_flags; /* Driver use, intended as capability flags. */
32439 };
32440
32441 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
32442 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
32443 { /* Sometime a Level-One switch card. */
32444 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
32445 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
32446 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
32447 index dcd7f7a..ecb7fb3 100644
32448 --- a/drivers/net/ethernet/dlink/sundance.c
32449 +++ b/drivers/net/ethernet/dlink/sundance.c
32450 @@ -218,7 +218,7 @@ enum {
32451 struct pci_id_info {
32452 const char *name;
32453 };
32454 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
32455 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
32456 {"D-Link DFE-550TX FAST Ethernet Adapter"},
32457 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
32458 {"D-Link DFE-580TX 4 port Server Adapter"},
32459 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
32460 index bf266a0..e024af7 100644
32461 --- a/drivers/net/ethernet/emulex/benet/be_main.c
32462 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
32463 @@ -397,7 +397,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
32464
32465 if (wrapped)
32466 newacc += 65536;
32467 - ACCESS_ONCE(*acc) = newacc;
32468 + ACCESS_ONCE_RW(*acc) = newacc;
32469 }
32470
32471 void be_parse_stats(struct be_adapter *adapter)
32472 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
32473 index 61d2bdd..7f1154a 100644
32474 --- a/drivers/net/ethernet/fealnx.c
32475 +++ b/drivers/net/ethernet/fealnx.c
32476 @@ -150,7 +150,7 @@ struct chip_info {
32477 int flags;
32478 };
32479
32480 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
32481 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
32482 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
32483 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
32484 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
32485 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32486 index e1159e5..e18684d 100644
32487 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32488 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32489 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
32490 {
32491 struct e1000_hw *hw = &adapter->hw;
32492 struct e1000_mac_info *mac = &hw->mac;
32493 - struct e1000_mac_operations *func = &mac->ops;
32494 + e1000_mac_operations_no_const *func = &mac->ops;
32495
32496 /* Set media type */
32497 switch (adapter->pdev->device) {
32498 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
32499 index a3e65fd..f451444 100644
32500 --- a/drivers/net/ethernet/intel/e1000e/82571.c
32501 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
32502 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
32503 {
32504 struct e1000_hw *hw = &adapter->hw;
32505 struct e1000_mac_info *mac = &hw->mac;
32506 - struct e1000_mac_operations *func = &mac->ops;
32507 + e1000_mac_operations_no_const *func = &mac->ops;
32508 u32 swsm = 0;
32509 u32 swsm2 = 0;
32510 bool force_clear_smbi = false;
32511 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
32512 index 2967039..ca8c40c 100644
32513 --- a/drivers/net/ethernet/intel/e1000e/hw.h
32514 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
32515 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
32516 void (*write_vfta)(struct e1000_hw *, u32, u32);
32517 s32 (*read_mac_addr)(struct e1000_hw *);
32518 };
32519 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32520
32521 /*
32522 * When to use various PHY register access functions:
32523 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
32524 void (*power_up)(struct e1000_hw *);
32525 void (*power_down)(struct e1000_hw *);
32526 };
32527 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
32528
32529 /* Function pointers for the NVM. */
32530 struct e1000_nvm_operations {
32531 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
32532 s32 (*validate)(struct e1000_hw *);
32533 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
32534 };
32535 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
32536
32537 struct e1000_mac_info {
32538 - struct e1000_mac_operations ops;
32539 + e1000_mac_operations_no_const ops;
32540 u8 addr[ETH_ALEN];
32541 u8 perm_addr[ETH_ALEN];
32542
32543 @@ -872,7 +875,7 @@ struct e1000_mac_info {
32544 };
32545
32546 struct e1000_phy_info {
32547 - struct e1000_phy_operations ops;
32548 + e1000_phy_operations_no_const ops;
32549
32550 enum e1000_phy_type type;
32551
32552 @@ -906,7 +909,7 @@ struct e1000_phy_info {
32553 };
32554
32555 struct e1000_nvm_info {
32556 - struct e1000_nvm_operations ops;
32557 + e1000_nvm_operations_no_const ops;
32558
32559 enum e1000_nvm_type type;
32560 enum e1000_nvm_override override;
32561 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
32562 index 4519a13..f97fcd0 100644
32563 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
32564 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
32565 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
32566 s32 (*read_mac_addr)(struct e1000_hw *);
32567 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
32568 };
32569 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32570
32571 struct e1000_phy_operations {
32572 s32 (*acquire)(struct e1000_hw *);
32573 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
32574 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
32575 s32 (*write_reg)(struct e1000_hw *, u32, u16);
32576 };
32577 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
32578
32579 struct e1000_nvm_operations {
32580 s32 (*acquire)(struct e1000_hw *);
32581 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
32582 s32 (*update)(struct e1000_hw *);
32583 s32 (*validate)(struct e1000_hw *);
32584 };
32585 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
32586
32587 struct e1000_info {
32588 s32 (*get_invariants)(struct e1000_hw *);
32589 @@ -350,7 +353,7 @@ struct e1000_info {
32590 extern const struct e1000_info e1000_82575_info;
32591
32592 struct e1000_mac_info {
32593 - struct e1000_mac_operations ops;
32594 + e1000_mac_operations_no_const ops;
32595
32596 u8 addr[6];
32597 u8 perm_addr[6];
32598 @@ -388,7 +391,7 @@ struct e1000_mac_info {
32599 };
32600
32601 struct e1000_phy_info {
32602 - struct e1000_phy_operations ops;
32603 + e1000_phy_operations_no_const ops;
32604
32605 enum e1000_phy_type type;
32606
32607 @@ -423,7 +426,7 @@ struct e1000_phy_info {
32608 };
32609
32610 struct e1000_nvm_info {
32611 - struct e1000_nvm_operations ops;
32612 + e1000_nvm_operations_no_const ops;
32613 enum e1000_nvm_type type;
32614 enum e1000_nvm_override override;
32615
32616 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
32617 s32 (*check_for_ack)(struct e1000_hw *, u16);
32618 s32 (*check_for_rst)(struct e1000_hw *, u16);
32619 };
32620 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
32621
32622 struct e1000_mbx_stats {
32623 u32 msgs_tx;
32624 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
32625 };
32626
32627 struct e1000_mbx_info {
32628 - struct e1000_mbx_operations ops;
32629 + e1000_mbx_operations_no_const ops;
32630 struct e1000_mbx_stats stats;
32631 u32 timeout;
32632 u32 usec_delay;
32633 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
32634 index d7ed58f..64cde36 100644
32635 --- a/drivers/net/ethernet/intel/igbvf/vf.h
32636 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
32637 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
32638 s32 (*read_mac_addr)(struct e1000_hw *);
32639 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
32640 };
32641 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32642
32643 struct e1000_mac_info {
32644 - struct e1000_mac_operations ops;
32645 + e1000_mac_operations_no_const ops;
32646 u8 addr[6];
32647 u8 perm_addr[6];
32648
32649 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
32650 s32 (*check_for_ack)(struct e1000_hw *);
32651 s32 (*check_for_rst)(struct e1000_hw *);
32652 };
32653 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
32654
32655 struct e1000_mbx_stats {
32656 u32 msgs_tx;
32657 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
32658 };
32659
32660 struct e1000_mbx_info {
32661 - struct e1000_mbx_operations ops;
32662 + e1000_mbx_operations_no_const ops;
32663 struct e1000_mbx_stats stats;
32664 u32 timeout;
32665 u32 usec_delay;
32666 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32667 index 6c5cca8..de8ef63 100644
32668 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32669 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32670 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
32671 s32 (*update_checksum)(struct ixgbe_hw *);
32672 u16 (*calc_checksum)(struct ixgbe_hw *);
32673 };
32674 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
32675
32676 struct ixgbe_mac_operations {
32677 s32 (*init_hw)(struct ixgbe_hw *);
32678 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
32679 /* Manageability interface */
32680 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
32681 };
32682 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
32683
32684 struct ixgbe_phy_operations {
32685 s32 (*identify)(struct ixgbe_hw *);
32686 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
32687 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
32688 s32 (*check_overtemp)(struct ixgbe_hw *);
32689 };
32690 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
32691
32692 struct ixgbe_eeprom_info {
32693 - struct ixgbe_eeprom_operations ops;
32694 + ixgbe_eeprom_operations_no_const ops;
32695 enum ixgbe_eeprom_type type;
32696 u32 semaphore_delay;
32697 u16 word_size;
32698 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
32699
32700 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
32701 struct ixgbe_mac_info {
32702 - struct ixgbe_mac_operations ops;
32703 + ixgbe_mac_operations_no_const ops;
32704 enum ixgbe_mac_type type;
32705 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
32706 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
32707 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
32708 };
32709
32710 struct ixgbe_phy_info {
32711 - struct ixgbe_phy_operations ops;
32712 + ixgbe_phy_operations_no_const ops;
32713 struct mdio_if_info mdio;
32714 enum ixgbe_phy_type type;
32715 u32 id;
32716 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
32717 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
32718 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
32719 };
32720 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
32721
32722 struct ixgbe_mbx_stats {
32723 u32 msgs_tx;
32724 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
32725 };
32726
32727 struct ixgbe_mbx_info {
32728 - struct ixgbe_mbx_operations ops;
32729 + ixgbe_mbx_operations_no_const ops;
32730 struct ixgbe_mbx_stats stats;
32731 u32 timeout;
32732 u32 usec_delay;
32733 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
32734 index 10306b4..28df758 100644
32735 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
32736 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
32737 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
32738 s32 (*clear_vfta)(struct ixgbe_hw *);
32739 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
32740 };
32741 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
32742
32743 enum ixgbe_mac_type {
32744 ixgbe_mac_unknown = 0,
32745 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
32746 };
32747
32748 struct ixgbe_mac_info {
32749 - struct ixgbe_mac_operations ops;
32750 + ixgbe_mac_operations_no_const ops;
32751 u8 addr[6];
32752 u8 perm_addr[6];
32753
32754 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
32755 s32 (*check_for_ack)(struct ixgbe_hw *);
32756 s32 (*check_for_rst)(struct ixgbe_hw *);
32757 };
32758 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
32759
32760 struct ixgbe_mbx_stats {
32761 u32 msgs_tx;
32762 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
32763 };
32764
32765 struct ixgbe_mbx_info {
32766 - struct ixgbe_mbx_operations ops;
32767 + ixgbe_mbx_operations_no_const ops;
32768 struct ixgbe_mbx_stats stats;
32769 u32 timeout;
32770 u32 udelay;
32771 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
32772 index 94bbc85..78c12e6 100644
32773 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
32774 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
32775 @@ -40,6 +40,7 @@
32776 #include <linux/dma-mapping.h>
32777 #include <linux/slab.h>
32778 #include <linux/io-mapping.h>
32779 +#include <linux/sched.h>
32780
32781 #include <linux/mlx4/device.h>
32782 #include <linux/mlx4/doorbell.h>
32783 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
32784 index 5046a64..71ca936 100644
32785 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
32786 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
32787 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
32788 void (*link_down)(struct __vxge_hw_device *devh);
32789 void (*crit_err)(struct __vxge_hw_device *devh,
32790 enum vxge_hw_event type, u64 ext_data);
32791 -};
32792 +} __no_const;
32793
32794 /*
32795 * struct __vxge_hw_blockpool_entry - Block private data structure
32796 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
32797 index 4a518a3..936b334 100644
32798 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
32799 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
32800 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
32801 struct vxge_hw_mempool_dma *dma_object,
32802 u32 index,
32803 u32 is_last);
32804 -};
32805 +} __no_const;
32806
32807 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
32808 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
32809 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
32810 index c8f47f1..5da9840 100644
32811 --- a/drivers/net/ethernet/realtek/r8169.c
32812 +++ b/drivers/net/ethernet/realtek/r8169.c
32813 @@ -698,17 +698,17 @@ struct rtl8169_private {
32814 struct mdio_ops {
32815 void (*write)(void __iomem *, int, int);
32816 int (*read)(void __iomem *, int);
32817 - } mdio_ops;
32818 + } __no_const mdio_ops;
32819
32820 struct pll_power_ops {
32821 void (*down)(struct rtl8169_private *);
32822 void (*up)(struct rtl8169_private *);
32823 - } pll_power_ops;
32824 + } __no_const pll_power_ops;
32825
32826 struct jumbo_ops {
32827 void (*enable)(struct rtl8169_private *);
32828 void (*disable)(struct rtl8169_private *);
32829 - } jumbo_ops;
32830 + } __no_const jumbo_ops;
32831
32832 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
32833 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
32834 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
32835 index 1b4658c..a30dabb 100644
32836 --- a/drivers/net/ethernet/sis/sis190.c
32837 +++ b/drivers/net/ethernet/sis/sis190.c
32838 @@ -1624,7 +1624,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
32839 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
32840 struct net_device *dev)
32841 {
32842 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
32843 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
32844 struct sis190_private *tp = netdev_priv(dev);
32845 struct pci_dev *isa_bridge;
32846 u8 reg, tmp8;
32847 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
32848 index edfa15d..002bfa9 100644
32849 --- a/drivers/net/ppp/ppp_generic.c
32850 +++ b/drivers/net/ppp/ppp_generic.c
32851 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32852 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
32853 struct ppp_stats stats;
32854 struct ppp_comp_stats cstats;
32855 - char *vers;
32856
32857 switch (cmd) {
32858 case SIOCGPPPSTATS:
32859 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32860 break;
32861
32862 case SIOCGPPPVER:
32863 - vers = PPP_VERSION;
32864 - if (copy_to_user(addr, vers, strlen(vers) + 1))
32865 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
32866 break;
32867 err = 0;
32868 break;
32869 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
32870 index 515f122..41dd273 100644
32871 --- a/drivers/net/tokenring/abyss.c
32872 +++ b/drivers/net/tokenring/abyss.c
32873 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
32874
32875 static int __init abyss_init (void)
32876 {
32877 - abyss_netdev_ops = tms380tr_netdev_ops;
32878 + pax_open_kernel();
32879 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
32880
32881 - abyss_netdev_ops.ndo_open = abyss_open;
32882 - abyss_netdev_ops.ndo_stop = abyss_close;
32883 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
32884 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
32885 + pax_close_kernel();
32886
32887 return pci_register_driver(&abyss_driver);
32888 }
32889 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
32890 index 6153cfd..cf69c1c 100644
32891 --- a/drivers/net/tokenring/madgemc.c
32892 +++ b/drivers/net/tokenring/madgemc.c
32893 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
32894
32895 static int __init madgemc_init (void)
32896 {
32897 - madgemc_netdev_ops = tms380tr_netdev_ops;
32898 - madgemc_netdev_ops.ndo_open = madgemc_open;
32899 - madgemc_netdev_ops.ndo_stop = madgemc_close;
32900 + pax_open_kernel();
32901 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
32902 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
32903 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
32904 + pax_close_kernel();
32905
32906 return mca_register_driver (&madgemc_driver);
32907 }
32908 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
32909 index 8d362e6..f91cc52 100644
32910 --- a/drivers/net/tokenring/proteon.c
32911 +++ b/drivers/net/tokenring/proteon.c
32912 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
32913 struct platform_device *pdev;
32914 int i, num = 0, err = 0;
32915
32916 - proteon_netdev_ops = tms380tr_netdev_ops;
32917 - proteon_netdev_ops.ndo_open = proteon_open;
32918 - proteon_netdev_ops.ndo_stop = tms380tr_close;
32919 + pax_open_kernel();
32920 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
32921 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
32922 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
32923 + pax_close_kernel();
32924
32925 err = platform_driver_register(&proteon_driver);
32926 if (err)
32927 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
32928 index 46db5c5..37c1536 100644
32929 --- a/drivers/net/tokenring/skisa.c
32930 +++ b/drivers/net/tokenring/skisa.c
32931 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
32932 struct platform_device *pdev;
32933 int i, num = 0, err = 0;
32934
32935 - sk_isa_netdev_ops = tms380tr_netdev_ops;
32936 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
32937 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
32938 + pax_open_kernel();
32939 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
32940 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
32941 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
32942 + pax_close_kernel();
32943
32944 err = platform_driver_register(&sk_isa_driver);
32945 if (err)
32946 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
32947 index 304fe78..db112fa 100644
32948 --- a/drivers/net/usb/hso.c
32949 +++ b/drivers/net/usb/hso.c
32950 @@ -71,7 +71,7 @@
32951 #include <asm/byteorder.h>
32952 #include <linux/serial_core.h>
32953 #include <linux/serial.h>
32954 -
32955 +#include <asm/local.h>
32956
32957 #define MOD_AUTHOR "Option Wireless"
32958 #define MOD_DESCRIPTION "USB High Speed Option driver"
32959 @@ -257,7 +257,7 @@ struct hso_serial {
32960
32961 /* from usb_serial_port */
32962 struct tty_struct *tty;
32963 - int open_count;
32964 + local_t open_count;
32965 spinlock_t serial_lock;
32966
32967 int (*write_data) (struct hso_serial *serial);
32968 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
32969 struct urb *urb;
32970
32971 urb = serial->rx_urb[0];
32972 - if (serial->open_count > 0) {
32973 + if (local_read(&serial->open_count) > 0) {
32974 count = put_rxbuf_data(urb, serial);
32975 if (count == -1)
32976 return;
32977 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
32978 DUMP1(urb->transfer_buffer, urb->actual_length);
32979
32980 /* Anyone listening? */
32981 - if (serial->open_count == 0)
32982 + if (local_read(&serial->open_count) == 0)
32983 return;
32984
32985 if (status == 0) {
32986 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
32987 spin_unlock_irq(&serial->serial_lock);
32988
32989 /* check for port already opened, if not set the termios */
32990 - serial->open_count++;
32991 - if (serial->open_count == 1) {
32992 + if (local_inc_return(&serial->open_count) == 1) {
32993 serial->rx_state = RX_IDLE;
32994 /* Force default termio settings */
32995 _hso_serial_set_termios(tty, NULL);
32996 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
32997 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
32998 if (result) {
32999 hso_stop_serial_device(serial->parent);
33000 - serial->open_count--;
33001 + local_dec(&serial->open_count);
33002 kref_put(&serial->parent->ref, hso_serial_ref_free);
33003 }
33004 } else {
33005 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
33006
33007 /* reset the rts and dtr */
33008 /* do the actual close */
33009 - serial->open_count--;
33010 + local_dec(&serial->open_count);
33011
33012 - if (serial->open_count <= 0) {
33013 - serial->open_count = 0;
33014 + if (local_read(&serial->open_count) <= 0) {
33015 + local_set(&serial->open_count, 0);
33016 spin_lock_irq(&serial->serial_lock);
33017 if (serial->tty == tty) {
33018 serial->tty->driver_data = NULL;
33019 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
33020
33021 /* the actual setup */
33022 spin_lock_irqsave(&serial->serial_lock, flags);
33023 - if (serial->open_count)
33024 + if (local_read(&serial->open_count))
33025 _hso_serial_set_termios(tty, old);
33026 else
33027 tty->termios = old;
33028 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
33029 D1("Pending read interrupt on port %d\n", i);
33030 spin_lock(&serial->serial_lock);
33031 if (serial->rx_state == RX_IDLE &&
33032 - serial->open_count > 0) {
33033 + local_read(&serial->open_count) > 0) {
33034 /* Setup and send a ctrl req read on
33035 * port i */
33036 if (!serial->rx_urb_filled[0]) {
33037 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
33038 /* Start all serial ports */
33039 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
33040 if (serial_table[i] && (serial_table[i]->interface == iface)) {
33041 - if (dev2ser(serial_table[i])->open_count) {
33042 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
33043 result =
33044 hso_start_serial_device(serial_table[i], GFP_NOIO);
33045 hso_kick_transmit(dev2ser(serial_table[i]));
33046 diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
33047 index e662cbc..8d4a102 100644
33048 --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
33049 +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
33050 @@ -601,8 +601,7 @@ vmxnet3_set_rss_indir(struct net_device *netdev,
33051 * Return with error code if any of the queue indices
33052 * is out of range
33053 */
33054 - if (p->ring_index[i] < 0 ||
33055 - p->ring_index[i] >= adapter->num_rx_queues)
33056 + if (p->ring_index[i] >= adapter->num_rx_queues)
33057 return -EINVAL;
33058 }
33059
33060 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
33061 index 0f9ee46..e2d6e65 100644
33062 --- a/drivers/net/wireless/ath/ath.h
33063 +++ b/drivers/net/wireless/ath/ath.h
33064 @@ -119,6 +119,7 @@ struct ath_ops {
33065 void (*write_flush) (void *);
33066 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
33067 };
33068 +typedef struct ath_ops __no_const ath_ops_no_const;
33069
33070 struct ath_common;
33071 struct ath_bus_ops;
33072 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33073 index b592016..fe47870 100644
33074 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33075 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33076 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33077 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
33078 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
33079
33080 - ACCESS_ONCE(ads->ds_link) = i->link;
33081 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
33082 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
33083 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
33084
33085 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
33086 ctl6 = SM(i->keytype, AR_EncrType);
33087 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33088
33089 if ((i->is_first || i->is_last) &&
33090 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
33091 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
33092 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
33093 | set11nTries(i->rates, 1)
33094 | set11nTries(i->rates, 2)
33095 | set11nTries(i->rates, 3)
33096 | (i->dur_update ? AR_DurUpdateEna : 0)
33097 | SM(0, AR_BurstDur);
33098
33099 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
33100 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
33101 | set11nRate(i->rates, 1)
33102 | set11nRate(i->rates, 2)
33103 | set11nRate(i->rates, 3);
33104 } else {
33105 - ACCESS_ONCE(ads->ds_ctl2) = 0;
33106 - ACCESS_ONCE(ads->ds_ctl3) = 0;
33107 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
33108 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
33109 }
33110
33111 if (!i->is_first) {
33112 - ACCESS_ONCE(ads->ds_ctl0) = 0;
33113 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
33114 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
33115 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
33116 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
33117 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
33118 return;
33119 }
33120
33121 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33122 break;
33123 }
33124
33125 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
33126 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
33127 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
33128 | SM(i->txpower, AR_XmitPower)
33129 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
33130 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33131 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
33132 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
33133
33134 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
33135 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
33136 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
33137 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
33138
33139 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
33140 return;
33141
33142 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
33143 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
33144 | set11nPktDurRTSCTS(i->rates, 1);
33145
33146 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
33147 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
33148 | set11nPktDurRTSCTS(i->rates, 3);
33149
33150 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
33151 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
33152 | set11nRateFlags(i->rates, 1)
33153 | set11nRateFlags(i->rates, 2)
33154 | set11nRateFlags(i->rates, 3)
33155 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33156 index f5ae3c6..7936af3 100644
33157 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33158 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33159 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33160 (i->qcu << AR_TxQcuNum_S) | 0x17;
33161
33162 checksum += val;
33163 - ACCESS_ONCE(ads->info) = val;
33164 + ACCESS_ONCE_RW(ads->info) = val;
33165
33166 checksum += i->link;
33167 - ACCESS_ONCE(ads->link) = i->link;
33168 + ACCESS_ONCE_RW(ads->link) = i->link;
33169
33170 checksum += i->buf_addr[0];
33171 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
33172 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
33173 checksum += i->buf_addr[1];
33174 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
33175 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
33176 checksum += i->buf_addr[2];
33177 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
33178 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
33179 checksum += i->buf_addr[3];
33180 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
33181 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
33182
33183 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
33184 - ACCESS_ONCE(ads->ctl3) = val;
33185 + ACCESS_ONCE_RW(ads->ctl3) = val;
33186 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
33187 - ACCESS_ONCE(ads->ctl5) = val;
33188 + ACCESS_ONCE_RW(ads->ctl5) = val;
33189 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
33190 - ACCESS_ONCE(ads->ctl7) = val;
33191 + ACCESS_ONCE_RW(ads->ctl7) = val;
33192 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
33193 - ACCESS_ONCE(ads->ctl9) = val;
33194 + ACCESS_ONCE_RW(ads->ctl9) = val;
33195
33196 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
33197 - ACCESS_ONCE(ads->ctl10) = checksum;
33198 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
33199
33200 if (i->is_first || i->is_last) {
33201 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
33202 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
33203 | set11nTries(i->rates, 1)
33204 | set11nTries(i->rates, 2)
33205 | set11nTries(i->rates, 3)
33206 | (i->dur_update ? AR_DurUpdateEna : 0)
33207 | SM(0, AR_BurstDur);
33208
33209 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
33210 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
33211 | set11nRate(i->rates, 1)
33212 | set11nRate(i->rates, 2)
33213 | set11nRate(i->rates, 3);
33214 } else {
33215 - ACCESS_ONCE(ads->ctl13) = 0;
33216 - ACCESS_ONCE(ads->ctl14) = 0;
33217 + ACCESS_ONCE_RW(ads->ctl13) = 0;
33218 + ACCESS_ONCE_RW(ads->ctl14) = 0;
33219 }
33220
33221 ads->ctl20 = 0;
33222 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33223
33224 ctl17 = SM(i->keytype, AR_EncrType);
33225 if (!i->is_first) {
33226 - ACCESS_ONCE(ads->ctl11) = 0;
33227 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
33228 - ACCESS_ONCE(ads->ctl15) = 0;
33229 - ACCESS_ONCE(ads->ctl16) = 0;
33230 - ACCESS_ONCE(ads->ctl17) = ctl17;
33231 - ACCESS_ONCE(ads->ctl18) = 0;
33232 - ACCESS_ONCE(ads->ctl19) = 0;
33233 + ACCESS_ONCE_RW(ads->ctl11) = 0;
33234 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
33235 + ACCESS_ONCE_RW(ads->ctl15) = 0;
33236 + ACCESS_ONCE_RW(ads->ctl16) = 0;
33237 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
33238 + ACCESS_ONCE_RW(ads->ctl18) = 0;
33239 + ACCESS_ONCE_RW(ads->ctl19) = 0;
33240 return;
33241 }
33242
33243 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
33244 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
33245 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
33246 | SM(i->txpower, AR_XmitPower)
33247 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
33248 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33249 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
33250 ctl12 |= SM(val, AR_PAPRDChainMask);
33251
33252 - ACCESS_ONCE(ads->ctl12) = ctl12;
33253 - ACCESS_ONCE(ads->ctl17) = ctl17;
33254 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
33255 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
33256
33257 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
33258 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
33259 | set11nPktDurRTSCTS(i->rates, 1);
33260
33261 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
33262 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
33263 | set11nPktDurRTSCTS(i->rates, 3);
33264
33265 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
33266 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
33267 | set11nRateFlags(i->rates, 1)
33268 | set11nRateFlags(i->rates, 2)
33269 | set11nRateFlags(i->rates, 3)
33270 | SM(i->rtscts_rate, AR_RTSCTSRate);
33271
33272 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
33273 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
33274 }
33275
33276 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
33277 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
33278 index f389b3c..7359e18 100644
33279 --- a/drivers/net/wireless/ath/ath9k/hw.h
33280 +++ b/drivers/net/wireless/ath/ath9k/hw.h
33281 @@ -605,7 +605,7 @@ struct ath_hw_private_ops {
33282
33283 /* ANI */
33284 void (*ani_cache_ini_regs)(struct ath_hw *ah);
33285 -};
33286 +} __no_const;
33287
33288 /**
33289 * struct ath_hw_ops - callbacks used by hardware code and driver code
33290 @@ -635,7 +635,7 @@ struct ath_hw_ops {
33291 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
33292 struct ath_hw_antcomb_conf *antconf);
33293
33294 -};
33295 +} __no_const;
33296
33297 struct ath_nf_limits {
33298 s16 max;
33299 @@ -655,7 +655,7 @@ enum ath_cal_list {
33300 #define AH_FASTCC 0x4
33301
33302 struct ath_hw {
33303 - struct ath_ops reg_ops;
33304 + ath_ops_no_const reg_ops;
33305
33306 struct ieee80211_hw *hw;
33307 struct ath_common common;
33308 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33309 index bea8524..c677c06 100644
33310 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33311 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33312 @@ -547,7 +547,7 @@ struct phy_func_ptr {
33313 void (*carrsuppr)(struct brcms_phy *);
33314 s32 (*rxsigpwr)(struct brcms_phy *, s32);
33315 void (*detach)(struct brcms_phy *);
33316 -};
33317 +} __no_const;
33318
33319 struct brcms_phy {
33320 struct brcms_phy_pub pubpi_ro;
33321 diff --git a/drivers/net/wireless/iwlegacy/iwl3945-base.c b/drivers/net/wireless/iwlegacy/iwl3945-base.c
33322 index 05f2ad1..ae00eea 100644
33323 --- a/drivers/net/wireless/iwlegacy/iwl3945-base.c
33324 +++ b/drivers/net/wireless/iwlegacy/iwl3945-base.c
33325 @@ -3685,7 +3685,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
33326 */
33327 if (iwl3945_mod_params.disable_hw_scan) {
33328 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
33329 - iwl3945_hw_ops.hw_scan = NULL;
33330 + pax_open_kernel();
33331 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
33332 + pax_close_kernel();
33333 }
33334
33335 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
33336 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
33337 index 69a77e2..552b42c 100644
33338 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
33339 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
33340 @@ -71,8 +71,8 @@ do { \
33341 } while (0)
33342
33343 #else
33344 -#define IWL_DEBUG(m, level, fmt, args...)
33345 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
33346 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
33347 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
33348 #define iwl_print_hex_dump(m, level, p, len)
33349 #endif /* CONFIG_IWLWIFI_DEBUG */
33350
33351 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
33352 index 523ad55..f8c5dc5 100644
33353 --- a/drivers/net/wireless/mac80211_hwsim.c
33354 +++ b/drivers/net/wireless/mac80211_hwsim.c
33355 @@ -1678,9 +1678,11 @@ static int __init init_mac80211_hwsim(void)
33356 return -EINVAL;
33357
33358 if (fake_hw_scan) {
33359 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
33360 - mac80211_hwsim_ops.sw_scan_start = NULL;
33361 - mac80211_hwsim_ops.sw_scan_complete = NULL;
33362 + pax_open_kernel();
33363 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
33364 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
33365 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
33366 + pax_close_kernel();
33367 }
33368
33369 spin_lock_init(&hwsim_radio_lock);
33370 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
33371 index 30f138b..c904585 100644
33372 --- a/drivers/net/wireless/mwifiex/main.h
33373 +++ b/drivers/net/wireless/mwifiex/main.h
33374 @@ -543,7 +543,7 @@ struct mwifiex_if_ops {
33375 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
33376 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
33377 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
33378 -};
33379 +} __no_const;
33380
33381 struct mwifiex_adapter {
33382 u8 iface_type;
33383 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
33384 index 0c13840..a5c3ed6 100644
33385 --- a/drivers/net/wireless/rndis_wlan.c
33386 +++ b/drivers/net/wireless/rndis_wlan.c
33387 @@ -1275,7 +1275,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
33388
33389 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
33390
33391 - if (rts_threshold < 0 || rts_threshold > 2347)
33392 + if (rts_threshold > 2347)
33393 rts_threshold = 2347;
33394
33395 tmp = cpu_to_le32(rts_threshold);
33396 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
33397 index a77f1bb..c608b2b 100644
33398 --- a/drivers/net/wireless/wl1251/wl1251.h
33399 +++ b/drivers/net/wireless/wl1251/wl1251.h
33400 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
33401 void (*reset)(struct wl1251 *wl);
33402 void (*enable_irq)(struct wl1251 *wl);
33403 void (*disable_irq)(struct wl1251 *wl);
33404 -};
33405 +} __no_const;
33406
33407 struct wl1251 {
33408 struct ieee80211_hw *hw;
33409 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
33410 index f34b5b2..b5abb9f 100644
33411 --- a/drivers/oprofile/buffer_sync.c
33412 +++ b/drivers/oprofile/buffer_sync.c
33413 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
33414 if (cookie == NO_COOKIE)
33415 offset = pc;
33416 if (cookie == INVALID_COOKIE) {
33417 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
33418 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
33419 offset = pc;
33420 }
33421 if (cookie != last_cookie) {
33422 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
33423 /* add userspace sample */
33424
33425 if (!mm) {
33426 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
33427 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
33428 return 0;
33429 }
33430
33431 cookie = lookup_dcookie(mm, s->eip, &offset);
33432
33433 if (cookie == INVALID_COOKIE) {
33434 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
33435 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
33436 return 0;
33437 }
33438
33439 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
33440 /* ignore backtraces if failed to add a sample */
33441 if (state == sb_bt_start) {
33442 state = sb_bt_ignore;
33443 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
33444 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
33445 }
33446 }
33447 release_mm(mm);
33448 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
33449 index c0cc4e7..44d4e54 100644
33450 --- a/drivers/oprofile/event_buffer.c
33451 +++ b/drivers/oprofile/event_buffer.c
33452 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
33453 }
33454
33455 if (buffer_pos == buffer_size) {
33456 - atomic_inc(&oprofile_stats.event_lost_overflow);
33457 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
33458 return;
33459 }
33460
33461 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
33462 index f8c752e..28bf4fc 100644
33463 --- a/drivers/oprofile/oprof.c
33464 +++ b/drivers/oprofile/oprof.c
33465 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
33466 if (oprofile_ops.switch_events())
33467 return;
33468
33469 - atomic_inc(&oprofile_stats.multiplex_counter);
33470 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
33471 start_switch_worker();
33472 }
33473
33474 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
33475 index 917d28e..d62d981 100644
33476 --- a/drivers/oprofile/oprofile_stats.c
33477 +++ b/drivers/oprofile/oprofile_stats.c
33478 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
33479 cpu_buf->sample_invalid_eip = 0;
33480 }
33481
33482 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
33483 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
33484 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
33485 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
33486 - atomic_set(&oprofile_stats.multiplex_counter, 0);
33487 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
33488 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
33489 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
33490 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
33491 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
33492 }
33493
33494
33495 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
33496 index 38b6fc0..b5cbfce 100644
33497 --- a/drivers/oprofile/oprofile_stats.h
33498 +++ b/drivers/oprofile/oprofile_stats.h
33499 @@ -13,11 +13,11 @@
33500 #include <linux/atomic.h>
33501
33502 struct oprofile_stat_struct {
33503 - atomic_t sample_lost_no_mm;
33504 - atomic_t sample_lost_no_mapping;
33505 - atomic_t bt_lost_no_mapping;
33506 - atomic_t event_lost_overflow;
33507 - atomic_t multiplex_counter;
33508 + atomic_unchecked_t sample_lost_no_mm;
33509 + atomic_unchecked_t sample_lost_no_mapping;
33510 + atomic_unchecked_t bt_lost_no_mapping;
33511 + atomic_unchecked_t event_lost_overflow;
33512 + atomic_unchecked_t multiplex_counter;
33513 };
33514
33515 extern struct oprofile_stat_struct oprofile_stats;
33516 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
33517 index 2f0aa0f..90fab02 100644
33518 --- a/drivers/oprofile/oprofilefs.c
33519 +++ b/drivers/oprofile/oprofilefs.c
33520 @@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
33521
33522
33523 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
33524 - char const *name, atomic_t *val)
33525 + char const *name, atomic_unchecked_t *val)
33526 {
33527 return __oprofilefs_create_file(sb, root, name,
33528 &atomic_ro_fops, 0444, val);
33529 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
33530 index 3f56bc0..707d642 100644
33531 --- a/drivers/parport/procfs.c
33532 +++ b/drivers/parport/procfs.c
33533 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
33534
33535 *ppos += len;
33536
33537 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
33538 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
33539 }
33540
33541 #ifdef CONFIG_PARPORT_1284
33542 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
33543
33544 *ppos += len;
33545
33546 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
33547 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
33548 }
33549 #endif /* IEEE1284.3 support. */
33550
33551 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
33552 index 9fff878..ad0ad53 100644
33553 --- a/drivers/pci/hotplug/cpci_hotplug.h
33554 +++ b/drivers/pci/hotplug/cpci_hotplug.h
33555 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
33556 int (*hardware_test) (struct slot* slot, u32 value);
33557 u8 (*get_power) (struct slot* slot);
33558 int (*set_power) (struct slot* slot, int value);
33559 -};
33560 +} __no_const;
33561
33562 struct cpci_hp_controller {
33563 unsigned int irq;
33564 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
33565 index 76ba8a1..20ca857 100644
33566 --- a/drivers/pci/hotplug/cpqphp_nvram.c
33567 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
33568 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
33569
33570 void compaq_nvram_init (void __iomem *rom_start)
33571 {
33572 +
33573 +#ifndef CONFIG_PAX_KERNEXEC
33574 if (rom_start) {
33575 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
33576 }
33577 +#endif
33578 +
33579 dbg("int15 entry = %p\n", compaq_int15_entry_point);
33580
33581 /* initialize our int15 lock */
33582 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
33583 index 1cfbf22..be96487 100644
33584 --- a/drivers/pci/pcie/aspm.c
33585 +++ b/drivers/pci/pcie/aspm.c
33586 @@ -27,9 +27,9 @@
33587 #define MODULE_PARAM_PREFIX "pcie_aspm."
33588
33589 /* Note: those are not register definitions */
33590 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
33591 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
33592 -#define ASPM_STATE_L1 (4) /* L1 state */
33593 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
33594 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
33595 +#define ASPM_STATE_L1 (4U) /* L1 state */
33596 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
33597 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
33598
33599 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
33600 index 04e74f4..a960176 100644
33601 --- a/drivers/pci/probe.c
33602 +++ b/drivers/pci/probe.c
33603 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
33604 u32 l, sz, mask;
33605 u16 orig_cmd;
33606
33607 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
33608 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
33609
33610 if (!dev->mmio_always_on) {
33611 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
33612 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
33613 index 27911b5..5b6db88 100644
33614 --- a/drivers/pci/proc.c
33615 +++ b/drivers/pci/proc.c
33616 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
33617 static int __init pci_proc_init(void)
33618 {
33619 struct pci_dev *dev = NULL;
33620 +
33621 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
33622 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33623 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
33624 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33625 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
33626 +#endif
33627 +#else
33628 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
33629 +#endif
33630 proc_create("devices", 0, proc_bus_pci_dir,
33631 &proc_bus_pci_dev_operations);
33632 proc_initialized = 1;
33633 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
33634 index 7b82868..b9344c9 100644
33635 --- a/drivers/platform/x86/thinkpad_acpi.c
33636 +++ b/drivers/platform/x86/thinkpad_acpi.c
33637 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
33638 return 0;
33639 }
33640
33641 -void static hotkey_mask_warn_incomplete_mask(void)
33642 +static void hotkey_mask_warn_incomplete_mask(void)
33643 {
33644 /* log only what the user can fix... */
33645 const u32 wantedmask = hotkey_driver_mask &
33646 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
33647 }
33648 }
33649
33650 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33651 - struct tp_nvram_state *newn,
33652 - const u32 event_mask)
33653 -{
33654 -
33655 #define TPACPI_COMPARE_KEY(__scancode, __member) \
33656 do { \
33657 if ((event_mask & (1 << __scancode)) && \
33658 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33659 tpacpi_hotkey_send_key(__scancode); \
33660 } while (0)
33661
33662 - void issue_volchange(const unsigned int oldvol,
33663 - const unsigned int newvol)
33664 - {
33665 - unsigned int i = oldvol;
33666 +static void issue_volchange(const unsigned int oldvol,
33667 + const unsigned int newvol,
33668 + const u32 event_mask)
33669 +{
33670 + unsigned int i = oldvol;
33671
33672 - while (i > newvol) {
33673 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
33674 - i--;
33675 - }
33676 - while (i < newvol) {
33677 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33678 - i++;
33679 - }
33680 + while (i > newvol) {
33681 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
33682 + i--;
33683 }
33684 + while (i < newvol) {
33685 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33686 + i++;
33687 + }
33688 +}
33689
33690 - void issue_brightnesschange(const unsigned int oldbrt,
33691 - const unsigned int newbrt)
33692 - {
33693 - unsigned int i = oldbrt;
33694 +static void issue_brightnesschange(const unsigned int oldbrt,
33695 + const unsigned int newbrt,
33696 + const u32 event_mask)
33697 +{
33698 + unsigned int i = oldbrt;
33699
33700 - while (i > newbrt) {
33701 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
33702 - i--;
33703 - }
33704 - while (i < newbrt) {
33705 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
33706 - i++;
33707 - }
33708 + while (i > newbrt) {
33709 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
33710 + i--;
33711 + }
33712 + while (i < newbrt) {
33713 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
33714 + i++;
33715 }
33716 +}
33717
33718 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33719 + struct tp_nvram_state *newn,
33720 + const u32 event_mask)
33721 +{
33722 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
33723 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
33724 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
33725 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33726 oldn->volume_level != newn->volume_level) {
33727 /* recently muted, or repeated mute keypress, or
33728 * multiple presses ending in mute */
33729 - issue_volchange(oldn->volume_level, newn->volume_level);
33730 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
33731 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
33732 }
33733 } else {
33734 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33735 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33736 }
33737 if (oldn->volume_level != newn->volume_level) {
33738 - issue_volchange(oldn->volume_level, newn->volume_level);
33739 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
33740 } else if (oldn->volume_toggle != newn->volume_toggle) {
33741 /* repeated vol up/down keypress at end of scale ? */
33742 if (newn->volume_level == 0)
33743 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33744 /* handle brightness */
33745 if (oldn->brightness_level != newn->brightness_level) {
33746 issue_brightnesschange(oldn->brightness_level,
33747 - newn->brightness_level);
33748 + newn->brightness_level,
33749 + event_mask);
33750 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
33751 /* repeated key presses that didn't change state */
33752 if (newn->brightness_level == 0)
33753 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33754 && !tp_features.bright_unkfw)
33755 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
33756 }
33757 +}
33758
33759 #undef TPACPI_COMPARE_KEY
33760 #undef TPACPI_MAY_SEND_KEY
33761 -}
33762
33763 /*
33764 * Polling driver
33765 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
33766 index b859d16..5cc6b1a 100644
33767 --- a/drivers/pnp/pnpbios/bioscalls.c
33768 +++ b/drivers/pnp/pnpbios/bioscalls.c
33769 @@ -59,7 +59,7 @@ do { \
33770 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
33771 } while(0)
33772
33773 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
33774 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
33775 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
33776
33777 /*
33778 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
33779
33780 cpu = get_cpu();
33781 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
33782 +
33783 + pax_open_kernel();
33784 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
33785 + pax_close_kernel();
33786
33787 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
33788 spin_lock_irqsave(&pnp_bios_lock, flags);
33789 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
33790 :"memory");
33791 spin_unlock_irqrestore(&pnp_bios_lock, flags);
33792
33793 + pax_open_kernel();
33794 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
33795 + pax_close_kernel();
33796 +
33797 put_cpu();
33798
33799 /* If we get here and this is set then the PnP BIOS faulted on us. */
33800 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
33801 return status;
33802 }
33803
33804 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
33805 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
33806 {
33807 int i;
33808
33809 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
33810 pnp_bios_callpoint.offset = header->fields.pm16offset;
33811 pnp_bios_callpoint.segment = PNP_CS16;
33812
33813 + pax_open_kernel();
33814 +
33815 for_each_possible_cpu(i) {
33816 struct desc_struct *gdt = get_cpu_gdt_table(i);
33817 if (!gdt)
33818 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
33819 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
33820 (unsigned long)__va(header->fields.pm16dseg));
33821 }
33822 +
33823 + pax_close_kernel();
33824 }
33825 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
33826 index b0ecacb..7c9da2e 100644
33827 --- a/drivers/pnp/resource.c
33828 +++ b/drivers/pnp/resource.c
33829 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
33830 return 1;
33831
33832 /* check if the resource is valid */
33833 - if (*irq < 0 || *irq > 15)
33834 + if (*irq > 15)
33835 return 0;
33836
33837 /* check if the resource is reserved */
33838 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
33839 return 1;
33840
33841 /* check if the resource is valid */
33842 - if (*dma < 0 || *dma == 4 || *dma > 7)
33843 + if (*dma == 4 || *dma > 7)
33844 return 0;
33845
33846 /* check if the resource is reserved */
33847 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
33848 index bb16f5b..c751eef 100644
33849 --- a/drivers/power/bq27x00_battery.c
33850 +++ b/drivers/power/bq27x00_battery.c
33851 @@ -67,7 +67,7 @@
33852 struct bq27x00_device_info;
33853 struct bq27x00_access_methods {
33854 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
33855 -};
33856 +} __no_const;
33857
33858 enum bq27x00_chip { BQ27000, BQ27500 };
33859
33860 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
33861 index 33f5d9a..d957d3f 100644
33862 --- a/drivers/regulator/max8660.c
33863 +++ b/drivers/regulator/max8660.c
33864 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
33865 max8660->shadow_regs[MAX8660_OVER1] = 5;
33866 } else {
33867 /* Otherwise devices can be toggled via software */
33868 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
33869 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
33870 + pax_open_kernel();
33871 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
33872 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
33873 + pax_close_kernel();
33874 }
33875
33876 /*
33877 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
33878 index 023d17d..74ef35b 100644
33879 --- a/drivers/regulator/mc13892-regulator.c
33880 +++ b/drivers/regulator/mc13892-regulator.c
33881 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
33882 }
33883 mc13xxx_unlock(mc13892);
33884
33885 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
33886 + pax_open_kernel();
33887 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
33888 = mc13892_vcam_set_mode;
33889 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
33890 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
33891 = mc13892_vcam_get_mode;
33892 + pax_close_kernel();
33893 for (i = 0; i < pdata->num_regulators; i++) {
33894 init_data = &pdata->regulators[i];
33895 priv->regulators[i] = regulator_register(
33896 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
33897 index cace6d3..f623fda 100644
33898 --- a/drivers/rtc/rtc-dev.c
33899 +++ b/drivers/rtc/rtc-dev.c
33900 @@ -14,6 +14,7 @@
33901 #include <linux/module.h>
33902 #include <linux/rtc.h>
33903 #include <linux/sched.h>
33904 +#include <linux/grsecurity.h>
33905 #include "rtc-core.h"
33906
33907 static dev_t rtc_devt;
33908 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
33909 if (copy_from_user(&tm, uarg, sizeof(tm)))
33910 return -EFAULT;
33911
33912 + gr_log_timechange();
33913 +
33914 return rtc_set_time(rtc, &tm);
33915
33916 case RTC_PIE_ON:
33917 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
33918 index ffb5878..e6d785c 100644
33919 --- a/drivers/scsi/aacraid/aacraid.h
33920 +++ b/drivers/scsi/aacraid/aacraid.h
33921 @@ -492,7 +492,7 @@ struct adapter_ops
33922 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
33923 /* Administrative operations */
33924 int (*adapter_comm)(struct aac_dev * dev, int comm);
33925 -};
33926 +} __no_const;
33927
33928 /*
33929 * Define which interrupt handler needs to be installed
33930 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
33931 index 705e13e..91c873c 100644
33932 --- a/drivers/scsi/aacraid/linit.c
33933 +++ b/drivers/scsi/aacraid/linit.c
33934 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
33935 #elif defined(__devinitconst)
33936 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
33937 #else
33938 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
33939 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
33940 #endif
33941 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
33942 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
33943 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
33944 index d5ff142..49c0ebb 100644
33945 --- a/drivers/scsi/aic94xx/aic94xx_init.c
33946 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
33947 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
33948 .lldd_control_phy = asd_control_phy,
33949 };
33950
33951 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
33952 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
33953 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
33954 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
33955 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
33956 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
33957 index a796de9..1ef20e1 100644
33958 --- a/drivers/scsi/bfa/bfa.h
33959 +++ b/drivers/scsi/bfa/bfa.h
33960 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
33961 u32 *end);
33962 int cpe_vec_q0;
33963 int rme_vec_q0;
33964 -};
33965 +} __no_const;
33966 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
33967
33968 struct bfa_faa_cbfn_s {
33969 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
33970 index e07bd47..cd1bbbb 100644
33971 --- a/drivers/scsi/bfa/bfa_fcpim.c
33972 +++ b/drivers/scsi/bfa/bfa_fcpim.c
33973 @@ -4121,7 +4121,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
33974
33975 bfa_iotag_attach(fcp);
33976
33977 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
33978 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
33979 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
33980 (fcp->num_itns * sizeof(struct bfa_itn_s));
33981 memset(fcp->itn_arr, 0,
33982 @@ -4179,7 +4179,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
33983 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
33984 {
33985 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
33986 - struct bfa_itn_s *itn;
33987 + bfa_itn_s_no_const *itn;
33988
33989 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
33990 itn->isr = isr;
33991 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
33992 index 1080bcb..a3b39e3 100644
33993 --- a/drivers/scsi/bfa/bfa_fcpim.h
33994 +++ b/drivers/scsi/bfa/bfa_fcpim.h
33995 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
33996 struct bfa_itn_s {
33997 bfa_isr_func_t isr;
33998 };
33999 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
34000
34001 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
34002 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
34003 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
34004 struct list_head iotag_tio_free_q; /* free IO resources */
34005 struct list_head iotag_unused_q; /* unused IO resources*/
34006 struct bfa_iotag_s *iotag_arr;
34007 - struct bfa_itn_s *itn_arr;
34008 + bfa_itn_s_no_const *itn_arr;
34009 int num_ioim_reqs;
34010 int num_fwtio_reqs;
34011 int num_itns;
34012 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
34013 index 546d46b..642fa5b 100644
34014 --- a/drivers/scsi/bfa/bfa_ioc.h
34015 +++ b/drivers/scsi/bfa/bfa_ioc.h
34016 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
34017 bfa_ioc_disable_cbfn_t disable_cbfn;
34018 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
34019 bfa_ioc_reset_cbfn_t reset_cbfn;
34020 -};
34021 +} __no_const;
34022
34023 /*
34024 * IOC event notification mechanism.
34025 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
34026 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
34027 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
34028 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
34029 -};
34030 +} __no_const;
34031
34032 /*
34033 * Queue element to wait for room in request queue. FIFO order is
34034 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
34035 index 351dc0b..951dc32 100644
34036 --- a/drivers/scsi/hosts.c
34037 +++ b/drivers/scsi/hosts.c
34038 @@ -42,7 +42,7 @@
34039 #include "scsi_logging.h"
34040
34041
34042 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
34043 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
34044
34045
34046 static void scsi_host_cls_release(struct device *dev)
34047 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
34048 * subtract one because we increment first then return, but we need to
34049 * know what the next host number was before increment
34050 */
34051 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
34052 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
34053 shost->dma_channel = 0xff;
34054
34055 /* These three are default values which can be overridden */
34056 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
34057 index 865d452..e9b7fa7 100644
34058 --- a/drivers/scsi/hpsa.c
34059 +++ b/drivers/scsi/hpsa.c
34060 @@ -505,7 +505,7 @@ static inline u32 next_command(struct ctlr_info *h)
34061 u32 a;
34062
34063 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
34064 - return h->access.command_completed(h);
34065 + return h->access->command_completed(h);
34066
34067 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
34068 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
34069 @@ -2989,7 +2989,7 @@ static void start_io(struct ctlr_info *h)
34070 while (!list_empty(&h->reqQ)) {
34071 c = list_entry(h->reqQ.next, struct CommandList, list);
34072 /* can't do anything if fifo is full */
34073 - if ((h->access.fifo_full(h))) {
34074 + if ((h->access->fifo_full(h))) {
34075 dev_warn(&h->pdev->dev, "fifo full\n");
34076 break;
34077 }
34078 @@ -2999,7 +2999,7 @@ static void start_io(struct ctlr_info *h)
34079 h->Qdepth--;
34080
34081 /* Tell the controller execute command */
34082 - h->access.submit_command(h, c);
34083 + h->access->submit_command(h, c);
34084
34085 /* Put job onto the completed Q */
34086 addQ(&h->cmpQ, c);
34087 @@ -3008,17 +3008,17 @@ static void start_io(struct ctlr_info *h)
34088
34089 static inline unsigned long get_next_completion(struct ctlr_info *h)
34090 {
34091 - return h->access.command_completed(h);
34092 + return h->access->command_completed(h);
34093 }
34094
34095 static inline bool interrupt_pending(struct ctlr_info *h)
34096 {
34097 - return h->access.intr_pending(h);
34098 + return h->access->intr_pending(h);
34099 }
34100
34101 static inline long interrupt_not_for_us(struct ctlr_info *h)
34102 {
34103 - return (h->access.intr_pending(h) == 0) ||
34104 + return (h->access->intr_pending(h) == 0) ||
34105 (h->interrupts_enabled == 0);
34106 }
34107
34108 @@ -3917,7 +3917,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
34109 if (prod_index < 0)
34110 return -ENODEV;
34111 h->product_name = products[prod_index].product_name;
34112 - h->access = *(products[prod_index].access);
34113 + h->access = products[prod_index].access;
34114
34115 if (hpsa_board_disabled(h->pdev)) {
34116 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
34117 @@ -4162,7 +4162,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
34118
34119 assert_spin_locked(&lockup_detector_lock);
34120 remove_ctlr_from_lockup_detector_list(h);
34121 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34122 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34123 spin_lock_irqsave(&h->lock, flags);
34124 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
34125 spin_unlock_irqrestore(&h->lock, flags);
34126 @@ -4340,7 +4340,7 @@ reinit_after_soft_reset:
34127 }
34128
34129 /* make sure the board interrupts are off */
34130 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34131 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34132
34133 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
34134 goto clean2;
34135 @@ -4374,7 +4374,7 @@ reinit_after_soft_reset:
34136 * fake ones to scoop up any residual completions.
34137 */
34138 spin_lock_irqsave(&h->lock, flags);
34139 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34140 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34141 spin_unlock_irqrestore(&h->lock, flags);
34142 free_irq(h->intr[h->intr_mode], h);
34143 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
34144 @@ -4393,9 +4393,9 @@ reinit_after_soft_reset:
34145 dev_info(&h->pdev->dev, "Board READY.\n");
34146 dev_info(&h->pdev->dev,
34147 "Waiting for stale completions to drain.\n");
34148 - h->access.set_intr_mask(h, HPSA_INTR_ON);
34149 + h->access->set_intr_mask(h, HPSA_INTR_ON);
34150 msleep(10000);
34151 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34152 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34153
34154 rc = controller_reset_failed(h->cfgtable);
34155 if (rc)
34156 @@ -4416,7 +4416,7 @@ reinit_after_soft_reset:
34157 }
34158
34159 /* Turn the interrupts on so we can service requests */
34160 - h->access.set_intr_mask(h, HPSA_INTR_ON);
34161 + h->access->set_intr_mask(h, HPSA_INTR_ON);
34162
34163 hpsa_hba_inquiry(h);
34164 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
34165 @@ -4468,7 +4468,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
34166 * To write all data in the battery backed cache to disks
34167 */
34168 hpsa_flush_cache(h);
34169 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34170 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34171 free_irq(h->intr[h->intr_mode], h);
34172 #ifdef CONFIG_PCI_MSI
34173 if (h->msix_vector)
34174 @@ -4632,7 +4632,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
34175 return;
34176 }
34177 /* Change the access methods to the performant access methods */
34178 - h->access = SA5_performant_access;
34179 + h->access = &SA5_performant_access;
34180 h->transMethod = CFGTBL_Trans_Performant;
34181 }
34182
34183 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
34184 index 91edafb..a9b88ec 100644
34185 --- a/drivers/scsi/hpsa.h
34186 +++ b/drivers/scsi/hpsa.h
34187 @@ -73,7 +73,7 @@ struct ctlr_info {
34188 unsigned int msix_vector;
34189 unsigned int msi_vector;
34190 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
34191 - struct access_method access;
34192 + struct access_method *access;
34193
34194 /* queue and queue Info */
34195 struct list_head reqQ;
34196 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
34197 index f2df059..a3a9930 100644
34198 --- a/drivers/scsi/ips.h
34199 +++ b/drivers/scsi/ips.h
34200 @@ -1027,7 +1027,7 @@ typedef struct {
34201 int (*intr)(struct ips_ha *);
34202 void (*enableint)(struct ips_ha *);
34203 uint32_t (*statupd)(struct ips_ha *);
34204 -} ips_hw_func_t;
34205 +} __no_const ips_hw_func_t;
34206
34207 typedef struct ips_ha {
34208 uint8_t ha_id[IPS_MAX_CHANNELS+1];
34209 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
34210 index 9de9db2..1e09660 100644
34211 --- a/drivers/scsi/libfc/fc_exch.c
34212 +++ b/drivers/scsi/libfc/fc_exch.c
34213 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
34214 * all together if not used XXX
34215 */
34216 struct {
34217 - atomic_t no_free_exch;
34218 - atomic_t no_free_exch_xid;
34219 - atomic_t xid_not_found;
34220 - atomic_t xid_busy;
34221 - atomic_t seq_not_found;
34222 - atomic_t non_bls_resp;
34223 + atomic_unchecked_t no_free_exch;
34224 + atomic_unchecked_t no_free_exch_xid;
34225 + atomic_unchecked_t xid_not_found;
34226 + atomic_unchecked_t xid_busy;
34227 + atomic_unchecked_t seq_not_found;
34228 + atomic_unchecked_t non_bls_resp;
34229 } stats;
34230 };
34231
34232 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
34233 /* allocate memory for exchange */
34234 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
34235 if (!ep) {
34236 - atomic_inc(&mp->stats.no_free_exch);
34237 + atomic_inc_unchecked(&mp->stats.no_free_exch);
34238 goto out;
34239 }
34240 memset(ep, 0, sizeof(*ep));
34241 @@ -780,7 +780,7 @@ out:
34242 return ep;
34243 err:
34244 spin_unlock_bh(&pool->lock);
34245 - atomic_inc(&mp->stats.no_free_exch_xid);
34246 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
34247 mempool_free(ep, mp->ep_pool);
34248 return NULL;
34249 }
34250 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34251 xid = ntohs(fh->fh_ox_id); /* we originated exch */
34252 ep = fc_exch_find(mp, xid);
34253 if (!ep) {
34254 - atomic_inc(&mp->stats.xid_not_found);
34255 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34256 reject = FC_RJT_OX_ID;
34257 goto out;
34258 }
34259 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34260 ep = fc_exch_find(mp, xid);
34261 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
34262 if (ep) {
34263 - atomic_inc(&mp->stats.xid_busy);
34264 + atomic_inc_unchecked(&mp->stats.xid_busy);
34265 reject = FC_RJT_RX_ID;
34266 goto rel;
34267 }
34268 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34269 }
34270 xid = ep->xid; /* get our XID */
34271 } else if (!ep) {
34272 - atomic_inc(&mp->stats.xid_not_found);
34273 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34274 reject = FC_RJT_RX_ID; /* XID not found */
34275 goto out;
34276 }
34277 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34278 } else {
34279 sp = &ep->seq;
34280 if (sp->id != fh->fh_seq_id) {
34281 - atomic_inc(&mp->stats.seq_not_found);
34282 + atomic_inc_unchecked(&mp->stats.seq_not_found);
34283 if (f_ctl & FC_FC_END_SEQ) {
34284 /*
34285 * Update sequence_id based on incoming last
34286 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34287
34288 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
34289 if (!ep) {
34290 - atomic_inc(&mp->stats.xid_not_found);
34291 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34292 goto out;
34293 }
34294 if (ep->esb_stat & ESB_ST_COMPLETE) {
34295 - atomic_inc(&mp->stats.xid_not_found);
34296 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34297 goto rel;
34298 }
34299 if (ep->rxid == FC_XID_UNKNOWN)
34300 ep->rxid = ntohs(fh->fh_rx_id);
34301 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
34302 - atomic_inc(&mp->stats.xid_not_found);
34303 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34304 goto rel;
34305 }
34306 if (ep->did != ntoh24(fh->fh_s_id) &&
34307 ep->did != FC_FID_FLOGI) {
34308 - atomic_inc(&mp->stats.xid_not_found);
34309 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34310 goto rel;
34311 }
34312 sof = fr_sof(fp);
34313 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34314 sp->ssb_stat |= SSB_ST_RESP;
34315 sp->id = fh->fh_seq_id;
34316 } else if (sp->id != fh->fh_seq_id) {
34317 - atomic_inc(&mp->stats.seq_not_found);
34318 + atomic_inc_unchecked(&mp->stats.seq_not_found);
34319 goto rel;
34320 }
34321
34322 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34323 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
34324
34325 if (!sp)
34326 - atomic_inc(&mp->stats.xid_not_found);
34327 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34328 else
34329 - atomic_inc(&mp->stats.non_bls_resp);
34330 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
34331
34332 fc_frame_free(fp);
34333 }
34334 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
34335 index db9238f..4378ed2 100644
34336 --- a/drivers/scsi/libsas/sas_ata.c
34337 +++ b/drivers/scsi/libsas/sas_ata.c
34338 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
34339 .postreset = ata_std_postreset,
34340 .error_handler = ata_std_error_handler,
34341 .post_internal_cmd = sas_ata_post_internal,
34342 - .qc_defer = ata_std_qc_defer,
34343 + .qc_defer = ata_std_qc_defer,
34344 .qc_prep = ata_noop_qc_prep,
34345 .qc_issue = sas_ata_qc_issue,
34346 .qc_fill_rtf = sas_ata_qc_fill_rtf,
34347 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
34348 index bb4c8e0..f33d849 100644
34349 --- a/drivers/scsi/lpfc/lpfc.h
34350 +++ b/drivers/scsi/lpfc/lpfc.h
34351 @@ -425,7 +425,7 @@ struct lpfc_vport {
34352 struct dentry *debug_nodelist;
34353 struct dentry *vport_debugfs_root;
34354 struct lpfc_debugfs_trc *disc_trc;
34355 - atomic_t disc_trc_cnt;
34356 + atomic_unchecked_t disc_trc_cnt;
34357 #endif
34358 uint8_t stat_data_enabled;
34359 uint8_t stat_data_blocked;
34360 @@ -835,8 +835,8 @@ struct lpfc_hba {
34361 struct timer_list fabric_block_timer;
34362 unsigned long bit_flags;
34363 #define FABRIC_COMANDS_BLOCKED 0
34364 - atomic_t num_rsrc_err;
34365 - atomic_t num_cmd_success;
34366 + atomic_unchecked_t num_rsrc_err;
34367 + atomic_unchecked_t num_cmd_success;
34368 unsigned long last_rsrc_error_time;
34369 unsigned long last_ramp_down_time;
34370 unsigned long last_ramp_up_time;
34371 @@ -866,7 +866,7 @@ struct lpfc_hba {
34372
34373 struct dentry *debug_slow_ring_trc;
34374 struct lpfc_debugfs_trc *slow_ring_trc;
34375 - atomic_t slow_ring_trc_cnt;
34376 + atomic_unchecked_t slow_ring_trc_cnt;
34377 /* iDiag debugfs sub-directory */
34378 struct dentry *idiag_root;
34379 struct dentry *idiag_pci_cfg;
34380 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
34381 index 2838259..a07cfb5 100644
34382 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
34383 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
34384 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
34385
34386 #include <linux/debugfs.h>
34387
34388 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
34389 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
34390 static unsigned long lpfc_debugfs_start_time = 0L;
34391
34392 /* iDiag */
34393 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
34394 lpfc_debugfs_enable = 0;
34395
34396 len = 0;
34397 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
34398 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
34399 (lpfc_debugfs_max_disc_trc - 1);
34400 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
34401 dtp = vport->disc_trc + i;
34402 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
34403 lpfc_debugfs_enable = 0;
34404
34405 len = 0;
34406 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
34407 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
34408 (lpfc_debugfs_max_slow_ring_trc - 1);
34409 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
34410 dtp = phba->slow_ring_trc + i;
34411 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
34412 !vport || !vport->disc_trc)
34413 return;
34414
34415 - index = atomic_inc_return(&vport->disc_trc_cnt) &
34416 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
34417 (lpfc_debugfs_max_disc_trc - 1);
34418 dtp = vport->disc_trc + index;
34419 dtp->fmt = fmt;
34420 dtp->data1 = data1;
34421 dtp->data2 = data2;
34422 dtp->data3 = data3;
34423 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
34424 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
34425 dtp->jif = jiffies;
34426 #endif
34427 return;
34428 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
34429 !phba || !phba->slow_ring_trc)
34430 return;
34431
34432 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
34433 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
34434 (lpfc_debugfs_max_slow_ring_trc - 1);
34435 dtp = phba->slow_ring_trc + index;
34436 dtp->fmt = fmt;
34437 dtp->data1 = data1;
34438 dtp->data2 = data2;
34439 dtp->data3 = data3;
34440 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
34441 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
34442 dtp->jif = jiffies;
34443 #endif
34444 return;
34445 @@ -3986,7 +3986,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
34446 "slow_ring buffer\n");
34447 goto debug_failed;
34448 }
34449 - atomic_set(&phba->slow_ring_trc_cnt, 0);
34450 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
34451 memset(phba->slow_ring_trc, 0,
34452 (sizeof(struct lpfc_debugfs_trc) *
34453 lpfc_debugfs_max_slow_ring_trc));
34454 @@ -4032,7 +4032,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
34455 "buffer\n");
34456 goto debug_failed;
34457 }
34458 - atomic_set(&vport->disc_trc_cnt, 0);
34459 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
34460
34461 snprintf(name, sizeof(name), "discovery_trace");
34462 vport->debug_disc_trc =
34463 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
34464 index 55bc4fc..a2a109c 100644
34465 --- a/drivers/scsi/lpfc/lpfc_init.c
34466 +++ b/drivers/scsi/lpfc/lpfc_init.c
34467 @@ -10027,8 +10027,10 @@ lpfc_init(void)
34468 printk(LPFC_COPYRIGHT "\n");
34469
34470 if (lpfc_enable_npiv) {
34471 - lpfc_transport_functions.vport_create = lpfc_vport_create;
34472 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
34473 + pax_open_kernel();
34474 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
34475 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
34476 + pax_close_kernel();
34477 }
34478 lpfc_transport_template =
34479 fc_attach_transport(&lpfc_transport_functions);
34480 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
34481 index 2e1e54e..1af0a0d 100644
34482 --- a/drivers/scsi/lpfc/lpfc_scsi.c
34483 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
34484 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
34485 uint32_t evt_posted;
34486
34487 spin_lock_irqsave(&phba->hbalock, flags);
34488 - atomic_inc(&phba->num_rsrc_err);
34489 + atomic_inc_unchecked(&phba->num_rsrc_err);
34490 phba->last_rsrc_error_time = jiffies;
34491
34492 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
34493 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
34494 unsigned long flags;
34495 struct lpfc_hba *phba = vport->phba;
34496 uint32_t evt_posted;
34497 - atomic_inc(&phba->num_cmd_success);
34498 + atomic_inc_unchecked(&phba->num_cmd_success);
34499
34500 if (vport->cfg_lun_queue_depth <= queue_depth)
34501 return;
34502 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
34503 unsigned long num_rsrc_err, num_cmd_success;
34504 int i;
34505
34506 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
34507 - num_cmd_success = atomic_read(&phba->num_cmd_success);
34508 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
34509 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
34510
34511 vports = lpfc_create_vport_work_array(phba);
34512 if (vports != NULL)
34513 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
34514 }
34515 }
34516 lpfc_destroy_vport_work_array(phba, vports);
34517 - atomic_set(&phba->num_rsrc_err, 0);
34518 - atomic_set(&phba->num_cmd_success, 0);
34519 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
34520 + atomic_set_unchecked(&phba->num_cmd_success, 0);
34521 }
34522
34523 /**
34524 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
34525 }
34526 }
34527 lpfc_destroy_vport_work_array(phba, vports);
34528 - atomic_set(&phba->num_rsrc_err, 0);
34529 - atomic_set(&phba->num_cmd_success, 0);
34530 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
34531 + atomic_set_unchecked(&phba->num_cmd_success, 0);
34532 }
34533
34534 /**
34535 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
34536 index 5163edb..7b142bc 100644
34537 --- a/drivers/scsi/pmcraid.c
34538 +++ b/drivers/scsi/pmcraid.c
34539 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
34540 res->scsi_dev = scsi_dev;
34541 scsi_dev->hostdata = res;
34542 res->change_detected = 0;
34543 - atomic_set(&res->read_failures, 0);
34544 - atomic_set(&res->write_failures, 0);
34545 + atomic_set_unchecked(&res->read_failures, 0);
34546 + atomic_set_unchecked(&res->write_failures, 0);
34547 rc = 0;
34548 }
34549 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
34550 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
34551
34552 /* If this was a SCSI read/write command keep count of errors */
34553 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
34554 - atomic_inc(&res->read_failures);
34555 + atomic_inc_unchecked(&res->read_failures);
34556 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
34557 - atomic_inc(&res->write_failures);
34558 + atomic_inc_unchecked(&res->write_failures);
34559
34560 if (!RES_IS_GSCSI(res->cfg_entry) &&
34561 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
34562 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
34563 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
34564 * hrrq_id assigned here in queuecommand
34565 */
34566 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
34567 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
34568 pinstance->num_hrrq;
34569 cmd->cmd_done = pmcraid_io_done;
34570
34571 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
34572 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
34573 * hrrq_id assigned here in queuecommand
34574 */
34575 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
34576 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
34577 pinstance->num_hrrq;
34578
34579 if (request_size) {
34580 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
34581
34582 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
34583 /* add resources only after host is added into system */
34584 - if (!atomic_read(&pinstance->expose_resources))
34585 + if (!atomic_read_unchecked(&pinstance->expose_resources))
34586 return;
34587
34588 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
34589 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
34590 init_waitqueue_head(&pinstance->reset_wait_q);
34591
34592 atomic_set(&pinstance->outstanding_cmds, 0);
34593 - atomic_set(&pinstance->last_message_id, 0);
34594 - atomic_set(&pinstance->expose_resources, 0);
34595 + atomic_set_unchecked(&pinstance->last_message_id, 0);
34596 + atomic_set_unchecked(&pinstance->expose_resources, 0);
34597
34598 INIT_LIST_HEAD(&pinstance->free_res_q);
34599 INIT_LIST_HEAD(&pinstance->used_res_q);
34600 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
34601 /* Schedule worker thread to handle CCN and take care of adding and
34602 * removing devices to OS
34603 */
34604 - atomic_set(&pinstance->expose_resources, 1);
34605 + atomic_set_unchecked(&pinstance->expose_resources, 1);
34606 schedule_work(&pinstance->worker_q);
34607 return rc;
34608
34609 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
34610 index ca496c7..9c791d5 100644
34611 --- a/drivers/scsi/pmcraid.h
34612 +++ b/drivers/scsi/pmcraid.h
34613 @@ -748,7 +748,7 @@ struct pmcraid_instance {
34614 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
34615
34616 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
34617 - atomic_t last_message_id;
34618 + atomic_unchecked_t last_message_id;
34619
34620 /* configuration table */
34621 struct pmcraid_config_table *cfg_table;
34622 @@ -777,7 +777,7 @@ struct pmcraid_instance {
34623 atomic_t outstanding_cmds;
34624
34625 /* should add/delete resources to mid-layer now ?*/
34626 - atomic_t expose_resources;
34627 + atomic_unchecked_t expose_resources;
34628
34629
34630
34631 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
34632 struct pmcraid_config_table_entry_ext cfg_entry_ext;
34633 };
34634 struct scsi_device *scsi_dev; /* Link scsi_device structure */
34635 - atomic_t read_failures; /* count of failed READ commands */
34636 - atomic_t write_failures; /* count of failed WRITE commands */
34637 + atomic_unchecked_t read_failures; /* count of failed READ commands */
34638 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
34639
34640 /* To indicate add/delete/modify during CCN */
34641 u8 change_detected;
34642 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
34643 index fcf052c..a8025a4 100644
34644 --- a/drivers/scsi/qla2xxx/qla_def.h
34645 +++ b/drivers/scsi/qla2xxx/qla_def.h
34646 @@ -2244,7 +2244,7 @@ struct isp_operations {
34647 int (*get_flash_version) (struct scsi_qla_host *, void *);
34648 int (*start_scsi) (srb_t *);
34649 int (*abort_isp) (struct scsi_qla_host *);
34650 -};
34651 +} __no_const;
34652
34653 /* MSI-X Support *************************************************************/
34654
34655 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
34656 index fd5edc6..4906148 100644
34657 --- a/drivers/scsi/qla4xxx/ql4_def.h
34658 +++ b/drivers/scsi/qla4xxx/ql4_def.h
34659 @@ -258,7 +258,7 @@ struct ddb_entry {
34660 * (4000 only) */
34661 atomic_t relogin_timer; /* Max Time to wait for
34662 * relogin to complete */
34663 - atomic_t relogin_retry_count; /* Num of times relogin has been
34664 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
34665 * retried */
34666 uint32_t default_time2wait; /* Default Min time between
34667 * relogins (+aens) */
34668 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
34669 index 4169c8b..a8b896b 100644
34670 --- a/drivers/scsi/qla4xxx/ql4_os.c
34671 +++ b/drivers/scsi/qla4xxx/ql4_os.c
34672 @@ -2104,12 +2104,12 @@ void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
34673 */
34674 if (!iscsi_is_session_online(cls_sess)) {
34675 /* Reset retry relogin timer */
34676 - atomic_inc(&ddb_entry->relogin_retry_count);
34677 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
34678 DEBUG2(ql4_printk(KERN_INFO, ha,
34679 "%s: index[%d] relogin timed out-retrying"
34680 " relogin (%d), retry (%d)\n", __func__,
34681 ddb_entry->fw_ddb_index,
34682 - atomic_read(&ddb_entry->relogin_retry_count),
34683 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
34684 ddb_entry->default_time2wait + 4));
34685 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
34686 atomic_set(&ddb_entry->retry_relogin_timer,
34687 @@ -3835,7 +3835,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
34688
34689 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
34690 atomic_set(&ddb_entry->relogin_timer, 0);
34691 - atomic_set(&ddb_entry->relogin_retry_count, 0);
34692 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
34693
34694 ddb_entry->default_relogin_timeout =
34695 le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
34696 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
34697 index 2aeb2e9..46e3925 100644
34698 --- a/drivers/scsi/scsi.c
34699 +++ b/drivers/scsi/scsi.c
34700 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
34701 unsigned long timeout;
34702 int rtn = 0;
34703
34704 - atomic_inc(&cmd->device->iorequest_cnt);
34705 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
34706
34707 /* check if the device is still usable */
34708 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
34709 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
34710 index f85cfa6..a57c9e8 100644
34711 --- a/drivers/scsi/scsi_lib.c
34712 +++ b/drivers/scsi/scsi_lib.c
34713 @@ -1416,7 +1416,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
34714 shost = sdev->host;
34715 scsi_init_cmd_errh(cmd);
34716 cmd->result = DID_NO_CONNECT << 16;
34717 - atomic_inc(&cmd->device->iorequest_cnt);
34718 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
34719
34720 /*
34721 * SCSI request completion path will do scsi_device_unbusy(),
34722 @@ -1442,9 +1442,9 @@ static void scsi_softirq_done(struct request *rq)
34723
34724 INIT_LIST_HEAD(&cmd->eh_entry);
34725
34726 - atomic_inc(&cmd->device->iodone_cnt);
34727 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
34728 if (cmd->result)
34729 - atomic_inc(&cmd->device->ioerr_cnt);
34730 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
34731
34732 disposition = scsi_decide_disposition(cmd);
34733 if (disposition != SUCCESS &&
34734 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
34735 index 04c2a27..9d8bd66 100644
34736 --- a/drivers/scsi/scsi_sysfs.c
34737 +++ b/drivers/scsi/scsi_sysfs.c
34738 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
34739 char *buf) \
34740 { \
34741 struct scsi_device *sdev = to_scsi_device(dev); \
34742 - unsigned long long count = atomic_read(&sdev->field); \
34743 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
34744 return snprintf(buf, 20, "0x%llx\n", count); \
34745 } \
34746 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
34747 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
34748 index 84a1fdf..693b0d6 100644
34749 --- a/drivers/scsi/scsi_tgt_lib.c
34750 +++ b/drivers/scsi/scsi_tgt_lib.c
34751 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
34752 int err;
34753
34754 dprintk("%lx %u\n", uaddr, len);
34755 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
34756 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
34757 if (err) {
34758 /*
34759 * TODO: need to fixup sg_tablesize, max_segment_size,
34760 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
34761 index 1b21491..1b7f60e 100644
34762 --- a/drivers/scsi/scsi_transport_fc.c
34763 +++ b/drivers/scsi/scsi_transport_fc.c
34764 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
34765 * Netlink Infrastructure
34766 */
34767
34768 -static atomic_t fc_event_seq;
34769 +static atomic_unchecked_t fc_event_seq;
34770
34771 /**
34772 * fc_get_event_number - Obtain the next sequential FC event number
34773 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
34774 u32
34775 fc_get_event_number(void)
34776 {
34777 - return atomic_add_return(1, &fc_event_seq);
34778 + return atomic_add_return_unchecked(1, &fc_event_seq);
34779 }
34780 EXPORT_SYMBOL(fc_get_event_number);
34781
34782 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
34783 {
34784 int error;
34785
34786 - atomic_set(&fc_event_seq, 0);
34787 + atomic_set_unchecked(&fc_event_seq, 0);
34788
34789 error = transport_class_register(&fc_host_class);
34790 if (error)
34791 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
34792 char *cp;
34793
34794 *val = simple_strtoul(buf, &cp, 0);
34795 - if ((*cp && (*cp != '\n')) || (*val < 0))
34796 + if (*cp && (*cp != '\n'))
34797 return -EINVAL;
34798 /*
34799 * Check for overflow; dev_loss_tmo is u32
34800 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
34801 index 96029e6..4d77fa0 100644
34802 --- a/drivers/scsi/scsi_transport_iscsi.c
34803 +++ b/drivers/scsi/scsi_transport_iscsi.c
34804 @@ -79,7 +79,7 @@ struct iscsi_internal {
34805 struct transport_container session_cont;
34806 };
34807
34808 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
34809 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
34810 static struct workqueue_struct *iscsi_eh_timer_workq;
34811
34812 static DEFINE_IDA(iscsi_sess_ida);
34813 @@ -1062,7 +1062,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
34814 int err;
34815
34816 ihost = shost->shost_data;
34817 - session->sid = atomic_add_return(1, &iscsi_session_nr);
34818 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
34819
34820 if (target_id == ISCSI_MAX_TARGET) {
34821 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
34822 @@ -2663,7 +2663,7 @@ static __init int iscsi_transport_init(void)
34823 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
34824 ISCSI_TRANSPORT_VERSION);
34825
34826 - atomic_set(&iscsi_session_nr, 0);
34827 + atomic_set_unchecked(&iscsi_session_nr, 0);
34828
34829 err = class_register(&iscsi_transport_class);
34830 if (err)
34831 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
34832 index 21a045e..ec89e03 100644
34833 --- a/drivers/scsi/scsi_transport_srp.c
34834 +++ b/drivers/scsi/scsi_transport_srp.c
34835 @@ -33,7 +33,7 @@
34836 #include "scsi_transport_srp_internal.h"
34837
34838 struct srp_host_attrs {
34839 - atomic_t next_port_id;
34840 + atomic_unchecked_t next_port_id;
34841 };
34842 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
34843
34844 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
34845 struct Scsi_Host *shost = dev_to_shost(dev);
34846 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
34847
34848 - atomic_set(&srp_host->next_port_id, 0);
34849 + atomic_set_unchecked(&srp_host->next_port_id, 0);
34850 return 0;
34851 }
34852
34853 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
34854 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
34855 rport->roles = ids->roles;
34856
34857 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
34858 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
34859 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
34860
34861 transport_setup_device(&rport->dev);
34862 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
34863 index 441a1c5..07cece7 100644
34864 --- a/drivers/scsi/sg.c
34865 +++ b/drivers/scsi/sg.c
34866 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
34867 sdp->disk->disk_name,
34868 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
34869 NULL,
34870 - (char *)arg);
34871 + (char __user *)arg);
34872 case BLKTRACESTART:
34873 return blk_trace_startstop(sdp->device->request_queue, 1);
34874 case BLKTRACESTOP:
34875 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
34876 const struct file_operations * fops;
34877 };
34878
34879 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
34880 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
34881 {"allow_dio", &adio_fops},
34882 {"debug", &debug_fops},
34883 {"def_reserved_size", &dressz_fops},
34884 @@ -2327,7 +2327,7 @@ sg_proc_init(void)
34885 {
34886 int k, mask;
34887 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
34888 - struct sg_proc_leaf * leaf;
34889 + const struct sg_proc_leaf * leaf;
34890
34891 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
34892 if (!sg_proc_sgp)
34893 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
34894 index f64250e..1ee3049 100644
34895 --- a/drivers/spi/spi-dw-pci.c
34896 +++ b/drivers/spi/spi-dw-pci.c
34897 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
34898 #define spi_resume NULL
34899 #endif
34900
34901 -static const struct pci_device_id pci_ids[] __devinitdata = {
34902 +static const struct pci_device_id pci_ids[] __devinitconst = {
34903 /* Intel MID platform SPI controller 0 */
34904 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
34905 {},
34906 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
34907 index 77eae99..b7cdcc9 100644
34908 --- a/drivers/spi/spi.c
34909 +++ b/drivers/spi/spi.c
34910 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
34911 EXPORT_SYMBOL_GPL(spi_bus_unlock);
34912
34913 /* portable code must never pass more than 32 bytes */
34914 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
34915 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
34916
34917 static u8 *buf;
34918
34919 diff --git a/drivers/staging/gma500/power.c b/drivers/staging/gma500/power.c
34920 index 436fe97..4082570 100644
34921 --- a/drivers/staging/gma500/power.c
34922 +++ b/drivers/staging/gma500/power.c
34923 @@ -266,7 +266,7 @@ bool gma_power_begin(struct drm_device *dev, bool force_on)
34924 ret = gma_resume_pci(dev->pdev);
34925 if (ret == 0) {
34926 /* FIXME: we want to defer this for Medfield/Oaktrail */
34927 - gma_resume_display(dev);
34928 + gma_resume_display(dev->pdev);
34929 psb_irq_preinstall(dev);
34930 psb_irq_postinstall(dev);
34931 pm_runtime_get(&dev->pdev->dev);
34932 diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c
34933 index bafccb3..e3ac78d 100644
34934 --- a/drivers/staging/hv/rndis_filter.c
34935 +++ b/drivers/staging/hv/rndis_filter.c
34936 @@ -42,7 +42,7 @@ struct rndis_device {
34937
34938 enum rndis_device_state state;
34939 bool link_state;
34940 - atomic_t new_req_id;
34941 + atomic_unchecked_t new_req_id;
34942
34943 spinlock_t request_lock;
34944 struct list_head req_list;
34945 @@ -116,7 +116,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
34946 * template
34947 */
34948 set = &rndis_msg->msg.set_req;
34949 - set->req_id = atomic_inc_return(&dev->new_req_id);
34950 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
34951
34952 /* Add to the request list */
34953 spin_lock_irqsave(&dev->request_lock, flags);
34954 @@ -646,7 +646,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
34955
34956 /* Setup the rndis set */
34957 halt = &request->request_msg.msg.halt_req;
34958 - halt->req_id = atomic_inc_return(&dev->new_req_id);
34959 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
34960
34961 /* Ignore return since this msg is optional. */
34962 rndis_filter_send_request(dev, request);
34963 diff --git a/drivers/staging/iio/buffer_generic.h b/drivers/staging/iio/buffer_generic.h
34964 index 9e8f010..af9efb5 100644
34965 --- a/drivers/staging/iio/buffer_generic.h
34966 +++ b/drivers/staging/iio/buffer_generic.h
34967 @@ -64,7 +64,7 @@ struct iio_buffer_access_funcs {
34968
34969 int (*is_enabled)(struct iio_buffer *buffer);
34970 int (*enable)(struct iio_buffer *buffer);
34971 -};
34972 +} __no_const;
34973
34974 /**
34975 * struct iio_buffer_setup_ops - buffer setup related callbacks
34976 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
34977 index 8b307b4..a97ac91 100644
34978 --- a/drivers/staging/octeon/ethernet-rx.c
34979 +++ b/drivers/staging/octeon/ethernet-rx.c
34980 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
34981 /* Increment RX stats for virtual ports */
34982 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
34983 #ifdef CONFIG_64BIT
34984 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
34985 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
34986 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
34987 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
34988 #else
34989 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
34990 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
34991 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
34992 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
34993 #endif
34994 }
34995 netif_receive_skb(skb);
34996 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
34997 dev->name);
34998 */
34999 #ifdef CONFIG_64BIT
35000 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
35001 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
35002 #else
35003 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
35004 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
35005 #endif
35006 dev_kfree_skb_irq(skb);
35007 }
35008 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
35009 index 076f866..2308070 100644
35010 --- a/drivers/staging/octeon/ethernet.c
35011 +++ b/drivers/staging/octeon/ethernet.c
35012 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
35013 * since the RX tasklet also increments it.
35014 */
35015 #ifdef CONFIG_64BIT
35016 - atomic64_add(rx_status.dropped_packets,
35017 - (atomic64_t *)&priv->stats.rx_dropped);
35018 + atomic64_add_unchecked(rx_status.dropped_packets,
35019 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
35020 #else
35021 - atomic_add(rx_status.dropped_packets,
35022 - (atomic_t *)&priv->stats.rx_dropped);
35023 + atomic_add_unchecked(rx_status.dropped_packets,
35024 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
35025 #endif
35026 }
35027
35028 diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
35029 index 7a19555..466456d 100644
35030 --- a/drivers/staging/pohmelfs/inode.c
35031 +++ b/drivers/staging/pohmelfs/inode.c
35032 @@ -1861,7 +1861,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
35033 mutex_init(&psb->mcache_lock);
35034 psb->mcache_root = RB_ROOT;
35035 psb->mcache_timeout = msecs_to_jiffies(5000);
35036 - atomic_long_set(&psb->mcache_gen, 0);
35037 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
35038
35039 psb->trans_max_pages = 100;
35040
35041 @@ -1876,7 +1876,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
35042 INIT_LIST_HEAD(&psb->crypto_ready_list);
35043 INIT_LIST_HEAD(&psb->crypto_active_list);
35044
35045 - atomic_set(&psb->trans_gen, 1);
35046 + atomic_set_unchecked(&psb->trans_gen, 1);
35047 atomic_long_set(&psb->total_inodes, 0);
35048
35049 mutex_init(&psb->state_lock);
35050 diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
35051 index e22665c..a2a9390 100644
35052 --- a/drivers/staging/pohmelfs/mcache.c
35053 +++ b/drivers/staging/pohmelfs/mcache.c
35054 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
35055 m->data = data;
35056 m->start = start;
35057 m->size = size;
35058 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
35059 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
35060
35061 mutex_lock(&psb->mcache_lock);
35062 err = pohmelfs_mcache_insert(psb, m);
35063 diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
35064 index 985b6b7..7699e05 100644
35065 --- a/drivers/staging/pohmelfs/netfs.h
35066 +++ b/drivers/staging/pohmelfs/netfs.h
35067 @@ -571,14 +571,14 @@ struct pohmelfs_config;
35068 struct pohmelfs_sb {
35069 struct rb_root mcache_root;
35070 struct mutex mcache_lock;
35071 - atomic_long_t mcache_gen;
35072 + atomic_long_unchecked_t mcache_gen;
35073 unsigned long mcache_timeout;
35074
35075 unsigned int idx;
35076
35077 unsigned int trans_retries;
35078
35079 - atomic_t trans_gen;
35080 + atomic_unchecked_t trans_gen;
35081
35082 unsigned int crypto_attached_size;
35083 unsigned int crypto_align_size;
35084 diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
35085 index 06c1a74..866eebc 100644
35086 --- a/drivers/staging/pohmelfs/trans.c
35087 +++ b/drivers/staging/pohmelfs/trans.c
35088 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
35089 int err;
35090 struct netfs_cmd *cmd = t->iovec.iov_base;
35091
35092 - t->gen = atomic_inc_return(&psb->trans_gen);
35093 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
35094
35095 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
35096 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
35097 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
35098 index 86308a0..feaa925 100644
35099 --- a/drivers/staging/rtl8712/rtl871x_io.h
35100 +++ b/drivers/staging/rtl8712/rtl871x_io.h
35101 @@ -108,7 +108,7 @@ struct _io_ops {
35102 u8 *pmem);
35103 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
35104 u8 *pmem);
35105 -};
35106 +} __no_const;
35107
35108 struct io_req {
35109 struct list_head list;
35110 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
35111 index c7b5e8b..783d6cb 100644
35112 --- a/drivers/staging/sbe-2t3e3/netdev.c
35113 +++ b/drivers/staging/sbe-2t3e3/netdev.c
35114 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35115 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
35116
35117 if (rlen)
35118 - if (copy_to_user(data, &resp, rlen))
35119 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
35120 return -EFAULT;
35121
35122 return 0;
35123 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
35124 index be21617..0954e45 100644
35125 --- a/drivers/staging/usbip/usbip_common.h
35126 +++ b/drivers/staging/usbip/usbip_common.h
35127 @@ -289,7 +289,7 @@ struct usbip_device {
35128 void (*shutdown)(struct usbip_device *);
35129 void (*reset)(struct usbip_device *);
35130 void (*unusable)(struct usbip_device *);
35131 - } eh_ops;
35132 + } __no_const eh_ops;
35133 };
35134
35135 #if 0
35136 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
35137 index 88b3298..3783eee 100644
35138 --- a/drivers/staging/usbip/vhci.h
35139 +++ b/drivers/staging/usbip/vhci.h
35140 @@ -88,7 +88,7 @@ struct vhci_hcd {
35141 unsigned resuming:1;
35142 unsigned long re_timeout;
35143
35144 - atomic_t seqnum;
35145 + atomic_unchecked_t seqnum;
35146
35147 /*
35148 * NOTE:
35149 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
35150 index 2ee97e2..0420b86 100644
35151 --- a/drivers/staging/usbip/vhci_hcd.c
35152 +++ b/drivers/staging/usbip/vhci_hcd.c
35153 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
35154 return;
35155 }
35156
35157 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
35158 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
35159 if (priv->seqnum == 0xffff)
35160 dev_info(&urb->dev->dev, "seqnum max\n");
35161
35162 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
35163 return -ENOMEM;
35164 }
35165
35166 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
35167 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
35168 if (unlink->seqnum == 0xffff)
35169 pr_info("seqnum max\n");
35170
35171 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
35172 vdev->rhport = rhport;
35173 }
35174
35175 - atomic_set(&vhci->seqnum, 0);
35176 + atomic_set_unchecked(&vhci->seqnum, 0);
35177 spin_lock_init(&vhci->lock);
35178
35179 hcd->power_budget = 0; /* no limit */
35180 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
35181 index 3872b8c..fe6d2f4 100644
35182 --- a/drivers/staging/usbip/vhci_rx.c
35183 +++ b/drivers/staging/usbip/vhci_rx.c
35184 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
35185 if (!urb) {
35186 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
35187 pr_info("max seqnum %d\n",
35188 - atomic_read(&the_controller->seqnum));
35189 + atomic_read_unchecked(&the_controller->seqnum));
35190 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
35191 return;
35192 }
35193 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
35194 index 7735027..30eed13 100644
35195 --- a/drivers/staging/vt6655/hostap.c
35196 +++ b/drivers/staging/vt6655/hostap.c
35197 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
35198 *
35199 */
35200
35201 +static net_device_ops_no_const apdev_netdev_ops;
35202 +
35203 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35204 {
35205 PSDevice apdev_priv;
35206 struct net_device *dev = pDevice->dev;
35207 int ret;
35208 - const struct net_device_ops apdev_netdev_ops = {
35209 - .ndo_start_xmit = pDevice->tx_80211,
35210 - };
35211
35212 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
35213
35214 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35215 *apdev_priv = *pDevice;
35216 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
35217
35218 + /* only half broken now */
35219 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
35220 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
35221
35222 pDevice->apdev->type = ARPHRD_IEEE80211;
35223 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
35224 index 51b5adf..098e320 100644
35225 --- a/drivers/staging/vt6656/hostap.c
35226 +++ b/drivers/staging/vt6656/hostap.c
35227 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
35228 *
35229 */
35230
35231 +static net_device_ops_no_const apdev_netdev_ops;
35232 +
35233 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35234 {
35235 PSDevice apdev_priv;
35236 struct net_device *dev = pDevice->dev;
35237 int ret;
35238 - const struct net_device_ops apdev_netdev_ops = {
35239 - .ndo_start_xmit = pDevice->tx_80211,
35240 - };
35241
35242 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
35243
35244 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35245 *apdev_priv = *pDevice;
35246 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
35247
35248 + /* only half broken now */
35249 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
35250 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
35251
35252 pDevice->apdev->type = ARPHRD_IEEE80211;
35253 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
35254 index 7843dfd..3db105f 100644
35255 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
35256 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
35257 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
35258
35259 struct usbctlx_completor {
35260 int (*complete) (struct usbctlx_completor *);
35261 -};
35262 +} __no_const;
35263
35264 static int
35265 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
35266 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
35267 index 1ca66ea..76f1343 100644
35268 --- a/drivers/staging/zcache/tmem.c
35269 +++ b/drivers/staging/zcache/tmem.c
35270 @@ -39,7 +39,7 @@
35271 * A tmem host implementation must use this function to register callbacks
35272 * for memory allocation.
35273 */
35274 -static struct tmem_hostops tmem_hostops;
35275 +static tmem_hostops_no_const tmem_hostops;
35276
35277 static void tmem_objnode_tree_init(void);
35278
35279 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
35280 * A tmem host implementation must use this function to register
35281 * callbacks for a page-accessible memory (PAM) implementation
35282 */
35283 -static struct tmem_pamops tmem_pamops;
35284 +static tmem_pamops_no_const tmem_pamops;
35285
35286 void tmem_register_pamops(struct tmem_pamops *m)
35287 {
35288 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
35289 index ed147c4..94fc3c6 100644
35290 --- a/drivers/staging/zcache/tmem.h
35291 +++ b/drivers/staging/zcache/tmem.h
35292 @@ -180,6 +180,7 @@ struct tmem_pamops {
35293 void (*new_obj)(struct tmem_obj *);
35294 int (*replace_in_obj)(void *, struct tmem_obj *);
35295 };
35296 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
35297 extern void tmem_register_pamops(struct tmem_pamops *m);
35298
35299 /* memory allocation methods provided by the host implementation */
35300 @@ -189,6 +190,7 @@ struct tmem_hostops {
35301 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
35302 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
35303 };
35304 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
35305 extern void tmem_register_hostops(struct tmem_hostops *m);
35306
35307 /* core tmem accessor functions */
35308 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
35309 index 8599545..7761358 100644
35310 --- a/drivers/target/iscsi/iscsi_target.c
35311 +++ b/drivers/target/iscsi/iscsi_target.c
35312 @@ -1364,7 +1364,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
35313 * outstanding_r2ts reaches zero, go ahead and send the delayed
35314 * TASK_ABORTED status.
35315 */
35316 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
35317 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
35318 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
35319 if (--cmd->outstanding_r2ts < 1) {
35320 iscsit_stop_dataout_timer(cmd);
35321 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
35322 index 6845228..df77141 100644
35323 --- a/drivers/target/target_core_tmr.c
35324 +++ b/drivers/target/target_core_tmr.c
35325 @@ -250,7 +250,7 @@ static void core_tmr_drain_task_list(
35326 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
35327 cmd->t_task_list_num,
35328 atomic_read(&cmd->t_task_cdbs_left),
35329 - atomic_read(&cmd->t_task_cdbs_sent),
35330 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
35331 atomic_read(&cmd->t_transport_active),
35332 atomic_read(&cmd->t_transport_stop),
35333 atomic_read(&cmd->t_transport_sent));
35334 @@ -281,7 +281,7 @@ static void core_tmr_drain_task_list(
35335 pr_debug("LUN_RESET: got t_transport_active = 1 for"
35336 " task: %p, t_fe_count: %d dev: %p\n", task,
35337 fe_count, dev);
35338 - atomic_set(&cmd->t_transport_aborted, 1);
35339 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
35340 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35341
35342 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
35343 @@ -289,7 +289,7 @@ static void core_tmr_drain_task_list(
35344 }
35345 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
35346 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
35347 - atomic_set(&cmd->t_transport_aborted, 1);
35348 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
35349 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35350
35351 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
35352 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
35353 index e87d0eb..856cbcc 100644
35354 --- a/drivers/target/target_core_transport.c
35355 +++ b/drivers/target/target_core_transport.c
35356 @@ -1343,7 +1343,7 @@ struct se_device *transport_add_device_to_core_hba(
35357
35358 dev->queue_depth = dev_limits->queue_depth;
35359 atomic_set(&dev->depth_left, dev->queue_depth);
35360 - atomic_set(&dev->dev_ordered_id, 0);
35361 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
35362
35363 se_dev_set_default_attribs(dev, dev_limits);
35364
35365 @@ -1530,7 +1530,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
35366 * Used to determine when ORDERED commands should go from
35367 * Dormant to Active status.
35368 */
35369 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
35370 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
35371 smp_mb__after_atomic_inc();
35372 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
35373 cmd->se_ordered_id, cmd->sam_task_attr,
35374 @@ -1800,7 +1800,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
35375 " t_transport_active: %d t_transport_stop: %d"
35376 " t_transport_sent: %d\n", cmd->t_task_list_num,
35377 atomic_read(&cmd->t_task_cdbs_left),
35378 - atomic_read(&cmd->t_task_cdbs_sent),
35379 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
35380 atomic_read(&cmd->t_task_cdbs_ex_left),
35381 atomic_read(&cmd->t_transport_active),
35382 atomic_read(&cmd->t_transport_stop),
35383 @@ -2089,9 +2089,9 @@ check_depth:
35384
35385 spin_lock_irqsave(&cmd->t_state_lock, flags);
35386 task->task_flags |= (TF_ACTIVE | TF_SENT);
35387 - atomic_inc(&cmd->t_task_cdbs_sent);
35388 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
35389
35390 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
35391 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
35392 cmd->t_task_list_num)
35393 atomic_set(&cmd->t_transport_sent, 1);
35394
35395 @@ -4260,7 +4260,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
35396 atomic_set(&cmd->transport_lun_stop, 0);
35397 }
35398 if (!atomic_read(&cmd->t_transport_active) ||
35399 - atomic_read(&cmd->t_transport_aborted)) {
35400 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
35401 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35402 return false;
35403 }
35404 @@ -4509,7 +4509,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
35405 {
35406 int ret = 0;
35407
35408 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
35409 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
35410 if (!send_status ||
35411 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
35412 return 1;
35413 @@ -4546,7 +4546,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
35414 */
35415 if (cmd->data_direction == DMA_TO_DEVICE) {
35416 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
35417 - atomic_inc(&cmd->t_transport_aborted);
35418 + atomic_inc_unchecked(&cmd->t_transport_aborted);
35419 smp_mb__after_atomic_inc();
35420 }
35421 }
35422 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
35423 index b9040be..e3f5aab 100644
35424 --- a/drivers/tty/hvc/hvcs.c
35425 +++ b/drivers/tty/hvc/hvcs.c
35426 @@ -83,6 +83,7 @@
35427 #include <asm/hvcserver.h>
35428 #include <asm/uaccess.h>
35429 #include <asm/vio.h>
35430 +#include <asm/local.h>
35431
35432 /*
35433 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
35434 @@ -270,7 +271,7 @@ struct hvcs_struct {
35435 unsigned int index;
35436
35437 struct tty_struct *tty;
35438 - int open_count;
35439 + local_t open_count;
35440
35441 /*
35442 * Used to tell the driver kernel_thread what operations need to take
35443 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
35444
35445 spin_lock_irqsave(&hvcsd->lock, flags);
35446
35447 - if (hvcsd->open_count > 0) {
35448 + if (local_read(&hvcsd->open_count) > 0) {
35449 spin_unlock_irqrestore(&hvcsd->lock, flags);
35450 printk(KERN_INFO "HVCS: vterm state unchanged. "
35451 "The hvcs device node is still in use.\n");
35452 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
35453 if ((retval = hvcs_partner_connect(hvcsd)))
35454 goto error_release;
35455
35456 - hvcsd->open_count = 1;
35457 + local_set(&hvcsd->open_count, 1);
35458 hvcsd->tty = tty;
35459 tty->driver_data = hvcsd;
35460
35461 @@ -1179,7 +1180,7 @@ fast_open:
35462
35463 spin_lock_irqsave(&hvcsd->lock, flags);
35464 kref_get(&hvcsd->kref);
35465 - hvcsd->open_count++;
35466 + local_inc(&hvcsd->open_count);
35467 hvcsd->todo_mask |= HVCS_SCHED_READ;
35468 spin_unlock_irqrestore(&hvcsd->lock, flags);
35469
35470 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
35471 hvcsd = tty->driver_data;
35472
35473 spin_lock_irqsave(&hvcsd->lock, flags);
35474 - if (--hvcsd->open_count == 0) {
35475 + if (local_dec_and_test(&hvcsd->open_count)) {
35476
35477 vio_disable_interrupts(hvcsd->vdev);
35478
35479 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
35480 free_irq(irq, hvcsd);
35481 kref_put(&hvcsd->kref, destroy_hvcs_struct);
35482 return;
35483 - } else if (hvcsd->open_count < 0) {
35484 + } else if (local_read(&hvcsd->open_count) < 0) {
35485 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
35486 " is missmanaged.\n",
35487 - hvcsd->vdev->unit_address, hvcsd->open_count);
35488 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
35489 }
35490
35491 spin_unlock_irqrestore(&hvcsd->lock, flags);
35492 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
35493
35494 spin_lock_irqsave(&hvcsd->lock, flags);
35495 /* Preserve this so that we know how many kref refs to put */
35496 - temp_open_count = hvcsd->open_count;
35497 + temp_open_count = local_read(&hvcsd->open_count);
35498
35499 /*
35500 * Don't kref put inside the spinlock because the destruction
35501 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
35502 hvcsd->tty->driver_data = NULL;
35503 hvcsd->tty = NULL;
35504
35505 - hvcsd->open_count = 0;
35506 + local_set(&hvcsd->open_count, 0);
35507
35508 /* This will drop any buffered data on the floor which is OK in a hangup
35509 * scenario. */
35510 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
35511 * the middle of a write operation? This is a crummy place to do this
35512 * but we want to keep it all in the spinlock.
35513 */
35514 - if (hvcsd->open_count <= 0) {
35515 + if (local_read(&hvcsd->open_count) <= 0) {
35516 spin_unlock_irqrestore(&hvcsd->lock, flags);
35517 return -ENODEV;
35518 }
35519 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
35520 {
35521 struct hvcs_struct *hvcsd = tty->driver_data;
35522
35523 - if (!hvcsd || hvcsd->open_count <= 0)
35524 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
35525 return 0;
35526
35527 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
35528 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
35529 index ef92869..f4ebd88 100644
35530 --- a/drivers/tty/ipwireless/tty.c
35531 +++ b/drivers/tty/ipwireless/tty.c
35532 @@ -29,6 +29,7 @@
35533 #include <linux/tty_driver.h>
35534 #include <linux/tty_flip.h>
35535 #include <linux/uaccess.h>
35536 +#include <asm/local.h>
35537
35538 #include "tty.h"
35539 #include "network.h"
35540 @@ -51,7 +52,7 @@ struct ipw_tty {
35541 int tty_type;
35542 struct ipw_network *network;
35543 struct tty_struct *linux_tty;
35544 - int open_count;
35545 + local_t open_count;
35546 unsigned int control_lines;
35547 struct mutex ipw_tty_mutex;
35548 int tx_bytes_queued;
35549 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
35550 mutex_unlock(&tty->ipw_tty_mutex);
35551 return -ENODEV;
35552 }
35553 - if (tty->open_count == 0)
35554 + if (local_read(&tty->open_count) == 0)
35555 tty->tx_bytes_queued = 0;
35556
35557 - tty->open_count++;
35558 + local_inc(&tty->open_count);
35559
35560 tty->linux_tty = linux_tty;
35561 linux_tty->driver_data = tty;
35562 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
35563
35564 static void do_ipw_close(struct ipw_tty *tty)
35565 {
35566 - tty->open_count--;
35567 -
35568 - if (tty->open_count == 0) {
35569 + if (local_dec_return(&tty->open_count) == 0) {
35570 struct tty_struct *linux_tty = tty->linux_tty;
35571
35572 if (linux_tty != NULL) {
35573 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
35574 return;
35575
35576 mutex_lock(&tty->ipw_tty_mutex);
35577 - if (tty->open_count == 0) {
35578 + if (local_read(&tty->open_count) == 0) {
35579 mutex_unlock(&tty->ipw_tty_mutex);
35580 return;
35581 }
35582 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
35583 return;
35584 }
35585
35586 - if (!tty->open_count) {
35587 + if (!local_read(&tty->open_count)) {
35588 mutex_unlock(&tty->ipw_tty_mutex);
35589 return;
35590 }
35591 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
35592 return -ENODEV;
35593
35594 mutex_lock(&tty->ipw_tty_mutex);
35595 - if (!tty->open_count) {
35596 + if (!local_read(&tty->open_count)) {
35597 mutex_unlock(&tty->ipw_tty_mutex);
35598 return -EINVAL;
35599 }
35600 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
35601 if (!tty)
35602 return -ENODEV;
35603
35604 - if (!tty->open_count)
35605 + if (!local_read(&tty->open_count))
35606 return -EINVAL;
35607
35608 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
35609 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
35610 if (!tty)
35611 return 0;
35612
35613 - if (!tty->open_count)
35614 + if (!local_read(&tty->open_count))
35615 return 0;
35616
35617 return tty->tx_bytes_queued;
35618 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
35619 if (!tty)
35620 return -ENODEV;
35621
35622 - if (!tty->open_count)
35623 + if (!local_read(&tty->open_count))
35624 return -EINVAL;
35625
35626 return get_control_lines(tty);
35627 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
35628 if (!tty)
35629 return -ENODEV;
35630
35631 - if (!tty->open_count)
35632 + if (!local_read(&tty->open_count))
35633 return -EINVAL;
35634
35635 return set_control_lines(tty, set, clear);
35636 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
35637 if (!tty)
35638 return -ENODEV;
35639
35640 - if (!tty->open_count)
35641 + if (!local_read(&tty->open_count))
35642 return -EINVAL;
35643
35644 /* FIXME: Exactly how is the tty object locked here .. */
35645 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
35646 against a parallel ioctl etc */
35647 mutex_lock(&ttyj->ipw_tty_mutex);
35648 }
35649 - while (ttyj->open_count)
35650 + while (local_read(&ttyj->open_count))
35651 do_ipw_close(ttyj);
35652 ipwireless_disassociate_network_ttys(network,
35653 ttyj->channel_idx);
35654 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
35655 index fc7bbba..9527e93 100644
35656 --- a/drivers/tty/n_gsm.c
35657 +++ b/drivers/tty/n_gsm.c
35658 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
35659 kref_init(&dlci->ref);
35660 mutex_init(&dlci->mutex);
35661 dlci->fifo = &dlci->_fifo;
35662 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
35663 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
35664 kfree(dlci);
35665 return NULL;
35666 }
35667 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
35668 index 39d6ab6..eb97f41 100644
35669 --- a/drivers/tty/n_tty.c
35670 +++ b/drivers/tty/n_tty.c
35671 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
35672 {
35673 *ops = tty_ldisc_N_TTY;
35674 ops->owner = NULL;
35675 - ops->refcount = ops->flags = 0;
35676 + atomic_set(&ops->refcount, 0);
35677 + ops->flags = 0;
35678 }
35679 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
35680 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
35681 index e18604b..a7d5a11 100644
35682 --- a/drivers/tty/pty.c
35683 +++ b/drivers/tty/pty.c
35684 @@ -773,8 +773,10 @@ static void __init unix98_pty_init(void)
35685 register_sysctl_table(pty_root_table);
35686
35687 /* Now create the /dev/ptmx special device */
35688 + pax_open_kernel();
35689 tty_default_fops(&ptmx_fops);
35690 - ptmx_fops.open = ptmx_open;
35691 + *(void **)&ptmx_fops.open = ptmx_open;
35692 + pax_close_kernel();
35693
35694 cdev_init(&ptmx_cdev, &ptmx_fops);
35695 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
35696 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
35697 index 2b42a01..32a2ed3 100644
35698 --- a/drivers/tty/serial/kgdboc.c
35699 +++ b/drivers/tty/serial/kgdboc.c
35700 @@ -24,8 +24,9 @@
35701 #define MAX_CONFIG_LEN 40
35702
35703 static struct kgdb_io kgdboc_io_ops;
35704 +static struct kgdb_io kgdboc_io_ops_console;
35705
35706 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
35707 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
35708 static int configured = -1;
35709
35710 static char config[MAX_CONFIG_LEN];
35711 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
35712 kgdboc_unregister_kbd();
35713 if (configured == 1)
35714 kgdb_unregister_io_module(&kgdboc_io_ops);
35715 + else if (configured == 2)
35716 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
35717 }
35718
35719 static int configure_kgdboc(void)
35720 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
35721 int err;
35722 char *cptr = config;
35723 struct console *cons;
35724 + int is_console = 0;
35725
35726 err = kgdboc_option_setup(config);
35727 if (err || !strlen(config) || isspace(config[0]))
35728 goto noconfig;
35729
35730 err = -ENODEV;
35731 - kgdboc_io_ops.is_console = 0;
35732 kgdb_tty_driver = NULL;
35733
35734 kgdboc_use_kms = 0;
35735 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
35736 int idx;
35737 if (cons->device && cons->device(cons, &idx) == p &&
35738 idx == tty_line) {
35739 - kgdboc_io_ops.is_console = 1;
35740 + is_console = 1;
35741 break;
35742 }
35743 cons = cons->next;
35744 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
35745 kgdb_tty_line = tty_line;
35746
35747 do_register:
35748 - err = kgdb_register_io_module(&kgdboc_io_ops);
35749 + if (is_console) {
35750 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
35751 + configured = 2;
35752 + } else {
35753 + err = kgdb_register_io_module(&kgdboc_io_ops);
35754 + configured = 1;
35755 + }
35756 if (err)
35757 goto noconfig;
35758
35759 - configured = 1;
35760 -
35761 return 0;
35762
35763 noconfig:
35764 @@ -213,7 +220,7 @@ noconfig:
35765 static int __init init_kgdboc(void)
35766 {
35767 /* Already configured? */
35768 - if (configured == 1)
35769 + if (configured >= 1)
35770 return 0;
35771
35772 return configure_kgdboc();
35773 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
35774 if (config[len - 1] == '\n')
35775 config[len - 1] = '\0';
35776
35777 - if (configured == 1)
35778 + if (configured >= 1)
35779 cleanup_kgdboc();
35780
35781 /* Go and configure with the new params. */
35782 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
35783 .post_exception = kgdboc_post_exp_handler,
35784 };
35785
35786 +static struct kgdb_io kgdboc_io_ops_console = {
35787 + .name = "kgdboc",
35788 + .read_char = kgdboc_get_char,
35789 + .write_char = kgdboc_put_char,
35790 + .pre_exception = kgdboc_pre_exp_handler,
35791 + .post_exception = kgdboc_post_exp_handler,
35792 + .is_console = 1
35793 +};
35794 +
35795 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
35796 /* This is only available if kgdboc is a built in for early debugging */
35797 static int __init kgdboc_early_init(char *opt)
35798 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
35799 index 05085be..67eadb0 100644
35800 --- a/drivers/tty/tty_io.c
35801 +++ b/drivers/tty/tty_io.c
35802 @@ -3240,7 +3240,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
35803
35804 void tty_default_fops(struct file_operations *fops)
35805 {
35806 - *fops = tty_fops;
35807 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
35808 }
35809
35810 /*
35811 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
35812 index 8e0924f..4204eb4 100644
35813 --- a/drivers/tty/tty_ldisc.c
35814 +++ b/drivers/tty/tty_ldisc.c
35815 @@ -75,7 +75,7 @@ static void put_ldisc(struct tty_ldisc *ld)
35816 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
35817 struct tty_ldisc_ops *ldo = ld->ops;
35818
35819 - ldo->refcount--;
35820 + atomic_dec(&ldo->refcount);
35821 module_put(ldo->owner);
35822 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
35823
35824 @@ -110,7 +110,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
35825 spin_lock_irqsave(&tty_ldisc_lock, flags);
35826 tty_ldiscs[disc] = new_ldisc;
35827 new_ldisc->num = disc;
35828 - new_ldisc->refcount = 0;
35829 + atomic_set(&new_ldisc->refcount, 0);
35830 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
35831
35832 return ret;
35833 @@ -138,7 +138,7 @@ int tty_unregister_ldisc(int disc)
35834 return -EINVAL;
35835
35836 spin_lock_irqsave(&tty_ldisc_lock, flags);
35837 - if (tty_ldiscs[disc]->refcount)
35838 + if (atomic_read(&tty_ldiscs[disc]->refcount))
35839 ret = -EBUSY;
35840 else
35841 tty_ldiscs[disc] = NULL;
35842 @@ -159,7 +159,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
35843 if (ldops) {
35844 ret = ERR_PTR(-EAGAIN);
35845 if (try_module_get(ldops->owner)) {
35846 - ldops->refcount++;
35847 + atomic_inc(&ldops->refcount);
35848 ret = ldops;
35849 }
35850 }
35851 @@ -172,7 +172,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
35852 unsigned long flags;
35853
35854 spin_lock_irqsave(&tty_ldisc_lock, flags);
35855 - ldops->refcount--;
35856 + atomic_dec(&ldops->refcount);
35857 module_put(ldops->owner);
35858 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
35859 }
35860 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
35861 index a605549..6bd3c96 100644
35862 --- a/drivers/tty/vt/keyboard.c
35863 +++ b/drivers/tty/vt/keyboard.c
35864 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
35865 kbd->kbdmode == VC_OFF) &&
35866 value != KVAL(K_SAK))
35867 return; /* SAK is allowed even in raw mode */
35868 +
35869 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
35870 + {
35871 + void *func = fn_handler[value];
35872 + if (func == fn_show_state || func == fn_show_ptregs ||
35873 + func == fn_show_mem)
35874 + return;
35875 + }
35876 +#endif
35877 +
35878 fn_handler[value](vc);
35879 }
35880
35881 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
35882 index 5e096f4..0da1363 100644
35883 --- a/drivers/tty/vt/vt_ioctl.c
35884 +++ b/drivers/tty/vt/vt_ioctl.c
35885 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
35886 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
35887 return -EFAULT;
35888
35889 - if (!capable(CAP_SYS_TTY_CONFIG))
35890 - perm = 0;
35891 -
35892 switch (cmd) {
35893 case KDGKBENT:
35894 key_map = key_maps[s];
35895 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
35896 val = (i ? K_HOLE : K_NOSUCHMAP);
35897 return put_user(val, &user_kbe->kb_value);
35898 case KDSKBENT:
35899 + if (!capable(CAP_SYS_TTY_CONFIG))
35900 + perm = 0;
35901 +
35902 if (!perm)
35903 return -EPERM;
35904 if (!i && v == K_NOSUCHMAP) {
35905 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
35906 int i, j, k;
35907 int ret;
35908
35909 - if (!capable(CAP_SYS_TTY_CONFIG))
35910 - perm = 0;
35911 -
35912 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
35913 if (!kbs) {
35914 ret = -ENOMEM;
35915 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
35916 kfree(kbs);
35917 return ((p && *p) ? -EOVERFLOW : 0);
35918 case KDSKBSENT:
35919 + if (!capable(CAP_SYS_TTY_CONFIG))
35920 + perm = 0;
35921 +
35922 if (!perm) {
35923 ret = -EPERM;
35924 goto reterr;
35925 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
35926 index a783d53..cb30d94 100644
35927 --- a/drivers/uio/uio.c
35928 +++ b/drivers/uio/uio.c
35929 @@ -25,6 +25,7 @@
35930 #include <linux/kobject.h>
35931 #include <linux/cdev.h>
35932 #include <linux/uio_driver.h>
35933 +#include <asm/local.h>
35934
35935 #define UIO_MAX_DEVICES (1U << MINORBITS)
35936
35937 @@ -32,10 +33,10 @@ struct uio_device {
35938 struct module *owner;
35939 struct device *dev;
35940 int minor;
35941 - atomic_t event;
35942 + atomic_unchecked_t event;
35943 struct fasync_struct *async_queue;
35944 wait_queue_head_t wait;
35945 - int vma_count;
35946 + local_t vma_count;
35947 struct uio_info *info;
35948 struct kobject *map_dir;
35949 struct kobject *portio_dir;
35950 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
35951 struct device_attribute *attr, char *buf)
35952 {
35953 struct uio_device *idev = dev_get_drvdata(dev);
35954 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
35955 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
35956 }
35957
35958 static struct device_attribute uio_class_attributes[] = {
35959 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
35960 {
35961 struct uio_device *idev = info->uio_dev;
35962
35963 - atomic_inc(&idev->event);
35964 + atomic_inc_unchecked(&idev->event);
35965 wake_up_interruptible(&idev->wait);
35966 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
35967 }
35968 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
35969 }
35970
35971 listener->dev = idev;
35972 - listener->event_count = atomic_read(&idev->event);
35973 + listener->event_count = atomic_read_unchecked(&idev->event);
35974 filep->private_data = listener;
35975
35976 if (idev->info->open) {
35977 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
35978 return -EIO;
35979
35980 poll_wait(filep, &idev->wait, wait);
35981 - if (listener->event_count != atomic_read(&idev->event))
35982 + if (listener->event_count != atomic_read_unchecked(&idev->event))
35983 return POLLIN | POLLRDNORM;
35984 return 0;
35985 }
35986 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
35987 do {
35988 set_current_state(TASK_INTERRUPTIBLE);
35989
35990 - event_count = atomic_read(&idev->event);
35991 + event_count = atomic_read_unchecked(&idev->event);
35992 if (event_count != listener->event_count) {
35993 if (copy_to_user(buf, &event_count, count))
35994 retval = -EFAULT;
35995 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
35996 static void uio_vma_open(struct vm_area_struct *vma)
35997 {
35998 struct uio_device *idev = vma->vm_private_data;
35999 - idev->vma_count++;
36000 + local_inc(&idev->vma_count);
36001 }
36002
36003 static void uio_vma_close(struct vm_area_struct *vma)
36004 {
36005 struct uio_device *idev = vma->vm_private_data;
36006 - idev->vma_count--;
36007 + local_dec(&idev->vma_count);
36008 }
36009
36010 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36011 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
36012 idev->owner = owner;
36013 idev->info = info;
36014 init_waitqueue_head(&idev->wait);
36015 - atomic_set(&idev->event, 0);
36016 + atomic_set_unchecked(&idev->event, 0);
36017
36018 ret = uio_get_minor(idev);
36019 if (ret)
36020 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
36021 index a845f8b..4f54072 100644
36022 --- a/drivers/usb/atm/cxacru.c
36023 +++ b/drivers/usb/atm/cxacru.c
36024 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
36025 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
36026 if (ret < 2)
36027 return -EINVAL;
36028 - if (index < 0 || index > 0x7f)
36029 + if (index > 0x7f)
36030 return -EINVAL;
36031 pos += tmp;
36032
36033 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
36034 index d3448ca..d2864ca 100644
36035 --- a/drivers/usb/atm/usbatm.c
36036 +++ b/drivers/usb/atm/usbatm.c
36037 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36038 if (printk_ratelimit())
36039 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
36040 __func__, vpi, vci);
36041 - atomic_inc(&vcc->stats->rx_err);
36042 + atomic_inc_unchecked(&vcc->stats->rx_err);
36043 return;
36044 }
36045
36046 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36047 if (length > ATM_MAX_AAL5_PDU) {
36048 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
36049 __func__, length, vcc);
36050 - atomic_inc(&vcc->stats->rx_err);
36051 + atomic_inc_unchecked(&vcc->stats->rx_err);
36052 goto out;
36053 }
36054
36055 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36056 if (sarb->len < pdu_length) {
36057 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
36058 __func__, pdu_length, sarb->len, vcc);
36059 - atomic_inc(&vcc->stats->rx_err);
36060 + atomic_inc_unchecked(&vcc->stats->rx_err);
36061 goto out;
36062 }
36063
36064 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
36065 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
36066 __func__, vcc);
36067 - atomic_inc(&vcc->stats->rx_err);
36068 + atomic_inc_unchecked(&vcc->stats->rx_err);
36069 goto out;
36070 }
36071
36072 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36073 if (printk_ratelimit())
36074 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
36075 __func__, length);
36076 - atomic_inc(&vcc->stats->rx_drop);
36077 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36078 goto out;
36079 }
36080
36081 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36082
36083 vcc->push(vcc, skb);
36084
36085 - atomic_inc(&vcc->stats->rx);
36086 + atomic_inc_unchecked(&vcc->stats->rx);
36087 out:
36088 skb_trim(sarb, 0);
36089 }
36090 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
36091 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
36092
36093 usbatm_pop(vcc, skb);
36094 - atomic_inc(&vcc->stats->tx);
36095 + atomic_inc_unchecked(&vcc->stats->tx);
36096
36097 skb = skb_dequeue(&instance->sndqueue);
36098 }
36099 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
36100 if (!left--)
36101 return sprintf(page,
36102 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
36103 - atomic_read(&atm_dev->stats.aal5.tx),
36104 - atomic_read(&atm_dev->stats.aal5.tx_err),
36105 - atomic_read(&atm_dev->stats.aal5.rx),
36106 - atomic_read(&atm_dev->stats.aal5.rx_err),
36107 - atomic_read(&atm_dev->stats.aal5.rx_drop));
36108 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
36109 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
36110 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
36111 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
36112 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
36113
36114 if (!left--) {
36115 if (instance->disconnected)
36116 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
36117 index d956965..4179a77 100644
36118 --- a/drivers/usb/core/devices.c
36119 +++ b/drivers/usb/core/devices.c
36120 @@ -126,7 +126,7 @@ static const char format_endpt[] =
36121 * time it gets called.
36122 */
36123 static struct device_connect_event {
36124 - atomic_t count;
36125 + atomic_unchecked_t count;
36126 wait_queue_head_t wait;
36127 } device_event = {
36128 .count = ATOMIC_INIT(1),
36129 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
36130
36131 void usbfs_conn_disc_event(void)
36132 {
36133 - atomic_add(2, &device_event.count);
36134 + atomic_add_unchecked(2, &device_event.count);
36135 wake_up(&device_event.wait);
36136 }
36137
36138 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
36139
36140 poll_wait(file, &device_event.wait, wait);
36141
36142 - event_count = atomic_read(&device_event.count);
36143 + event_count = atomic_read_unchecked(&device_event.count);
36144 if (file->f_version != event_count) {
36145 file->f_version = event_count;
36146 return POLLIN | POLLRDNORM;
36147 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
36148 index b3bdfed..a9460e0 100644
36149 --- a/drivers/usb/core/message.c
36150 +++ b/drivers/usb/core/message.c
36151 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
36152 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
36153 if (buf) {
36154 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
36155 - if (len > 0) {
36156 - smallbuf = kmalloc(++len, GFP_NOIO);
36157 + if (len++ > 0) {
36158 + smallbuf = kmalloc(len, GFP_NOIO);
36159 if (!smallbuf)
36160 return buf;
36161 memcpy(smallbuf, buf, len);
36162 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
36163 index 1fc8f12..20647c1 100644
36164 --- a/drivers/usb/early/ehci-dbgp.c
36165 +++ b/drivers/usb/early/ehci-dbgp.c
36166 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
36167
36168 #ifdef CONFIG_KGDB
36169 static struct kgdb_io kgdbdbgp_io_ops;
36170 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
36171 +static struct kgdb_io kgdbdbgp_io_ops_console;
36172 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
36173 #else
36174 #define dbgp_kgdb_mode (0)
36175 #endif
36176 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
36177 .write_char = kgdbdbgp_write_char,
36178 };
36179
36180 +static struct kgdb_io kgdbdbgp_io_ops_console = {
36181 + .name = "kgdbdbgp",
36182 + .read_char = kgdbdbgp_read_char,
36183 + .write_char = kgdbdbgp_write_char,
36184 + .is_console = 1
36185 +};
36186 +
36187 static int kgdbdbgp_wait_time;
36188
36189 static int __init kgdbdbgp_parse_config(char *str)
36190 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
36191 ptr++;
36192 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
36193 }
36194 - kgdb_register_io_module(&kgdbdbgp_io_ops);
36195 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
36196 + if (early_dbgp_console.index != -1)
36197 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
36198 + else
36199 + kgdb_register_io_module(&kgdbdbgp_io_ops);
36200
36201 return 0;
36202 }
36203 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
36204 index d6bea3e..60b250e 100644
36205 --- a/drivers/usb/wusbcore/wa-hc.h
36206 +++ b/drivers/usb/wusbcore/wa-hc.h
36207 @@ -192,7 +192,7 @@ struct wahc {
36208 struct list_head xfer_delayed_list;
36209 spinlock_t xfer_list_lock;
36210 struct work_struct xfer_work;
36211 - atomic_t xfer_id_count;
36212 + atomic_unchecked_t xfer_id_count;
36213 };
36214
36215
36216 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
36217 INIT_LIST_HEAD(&wa->xfer_delayed_list);
36218 spin_lock_init(&wa->xfer_list_lock);
36219 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
36220 - atomic_set(&wa->xfer_id_count, 1);
36221 + atomic_set_unchecked(&wa->xfer_id_count, 1);
36222 }
36223
36224 /**
36225 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
36226 index 57c01ab..8a05959 100644
36227 --- a/drivers/usb/wusbcore/wa-xfer.c
36228 +++ b/drivers/usb/wusbcore/wa-xfer.c
36229 @@ -296,7 +296,7 @@ out:
36230 */
36231 static void wa_xfer_id_init(struct wa_xfer *xfer)
36232 {
36233 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
36234 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
36235 }
36236
36237 /*
36238 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
36239 index c14c42b..f955cc2 100644
36240 --- a/drivers/vhost/vhost.c
36241 +++ b/drivers/vhost/vhost.c
36242 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
36243 return 0;
36244 }
36245
36246 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
36247 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
36248 {
36249 struct file *eventfp, *filep = NULL,
36250 *pollstart = NULL, *pollstop = NULL;
36251 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
36252 index b0b2ac3..89a4399 100644
36253 --- a/drivers/video/aty/aty128fb.c
36254 +++ b/drivers/video/aty/aty128fb.c
36255 @@ -148,7 +148,7 @@ enum {
36256 };
36257
36258 /* Must match above enum */
36259 -static const char *r128_family[] __devinitdata = {
36260 +static const char *r128_family[] __devinitconst = {
36261 "AGP",
36262 "PCI",
36263 "PRO AGP",
36264 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
36265 index 5c3960d..15cf8fc 100644
36266 --- a/drivers/video/fbcmap.c
36267 +++ b/drivers/video/fbcmap.c
36268 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
36269 rc = -ENODEV;
36270 goto out;
36271 }
36272 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
36273 - !info->fbops->fb_setcmap)) {
36274 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
36275 rc = -EINVAL;
36276 goto out1;
36277 }
36278 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
36279 index ad93629..e020fc3 100644
36280 --- a/drivers/video/fbmem.c
36281 +++ b/drivers/video/fbmem.c
36282 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
36283 image->dx += image->width + 8;
36284 }
36285 } else if (rotate == FB_ROTATE_UD) {
36286 - for (x = 0; x < num && image->dx >= 0; x++) {
36287 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
36288 info->fbops->fb_imageblit(info, image);
36289 image->dx -= image->width + 8;
36290 }
36291 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
36292 image->dy += image->height + 8;
36293 }
36294 } else if (rotate == FB_ROTATE_CCW) {
36295 - for (x = 0; x < num && image->dy >= 0; x++) {
36296 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
36297 info->fbops->fb_imageblit(info, image);
36298 image->dy -= image->height + 8;
36299 }
36300 @@ -1143,7 +1143,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
36301 return -EFAULT;
36302 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
36303 return -EINVAL;
36304 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
36305 + if (con2fb.framebuffer >= FB_MAX)
36306 return -EINVAL;
36307 if (!registered_fb[con2fb.framebuffer])
36308 request_module("fb%d", con2fb.framebuffer);
36309 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
36310 index 5a5d092..265c5ed 100644
36311 --- a/drivers/video/geode/gx1fb_core.c
36312 +++ b/drivers/video/geode/gx1fb_core.c
36313 @@ -29,7 +29,7 @@ static int crt_option = 1;
36314 static char panel_option[32] = "";
36315
36316 /* Modes relevant to the GX1 (taken from modedb.c) */
36317 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
36318 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
36319 /* 640x480-60 VESA */
36320 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
36321 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
36322 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
36323 index 0fad23f..0e9afa4 100644
36324 --- a/drivers/video/gxt4500.c
36325 +++ b/drivers/video/gxt4500.c
36326 @@ -156,7 +156,7 @@ struct gxt4500_par {
36327 static char *mode_option;
36328
36329 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
36330 -static const struct fb_videomode defaultmode __devinitdata = {
36331 +static const struct fb_videomode defaultmode __devinitconst = {
36332 .refresh = 60,
36333 .xres = 1280,
36334 .yres = 1024,
36335 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
36336 return 0;
36337 }
36338
36339 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
36340 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
36341 .id = "IBM GXT4500P",
36342 .type = FB_TYPE_PACKED_PIXELS,
36343 .visual = FB_VISUAL_PSEUDOCOLOR,
36344 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
36345 index 7672d2e..b56437f 100644
36346 --- a/drivers/video/i810/i810_accel.c
36347 +++ b/drivers/video/i810/i810_accel.c
36348 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
36349 }
36350 }
36351 printk("ringbuffer lockup!!!\n");
36352 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
36353 i810_report_error(mmio);
36354 par->dev_flags |= LOCKUP;
36355 info->pixmap.scan_align = 1;
36356 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
36357 index 318f6fb..9a389c1 100644
36358 --- a/drivers/video/i810/i810_main.c
36359 +++ b/drivers/video/i810/i810_main.c
36360 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
36361 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
36362
36363 /* PCI */
36364 -static const char *i810_pci_list[] __devinitdata = {
36365 +static const char *i810_pci_list[] __devinitconst = {
36366 "Intel(R) 810 Framebuffer Device" ,
36367 "Intel(R) 810-DC100 Framebuffer Device" ,
36368 "Intel(R) 810E Framebuffer Device" ,
36369 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
36370 index de36693..3c63fc2 100644
36371 --- a/drivers/video/jz4740_fb.c
36372 +++ b/drivers/video/jz4740_fb.c
36373 @@ -136,7 +136,7 @@ struct jzfb {
36374 uint32_t pseudo_palette[16];
36375 };
36376
36377 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
36378 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
36379 .id = "JZ4740 FB",
36380 .type = FB_TYPE_PACKED_PIXELS,
36381 .visual = FB_VISUAL_TRUECOLOR,
36382 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
36383 index 3c14e43..eafa544 100644
36384 --- a/drivers/video/logo/logo_linux_clut224.ppm
36385 +++ b/drivers/video/logo/logo_linux_clut224.ppm
36386 @@ -1,1604 +1,1123 @@
36387 P3
36388 -# Standard 224-color Linux logo
36389 80 80
36390 255
36391 - 0 0 0 0 0 0 0 0 0 0 0 0
36392 - 0 0 0 0 0 0 0 0 0 0 0 0
36393 - 0 0 0 0 0 0 0 0 0 0 0 0
36394 - 0 0 0 0 0 0 0 0 0 0 0 0
36395 - 0 0 0 0 0 0 0 0 0 0 0 0
36396 - 0 0 0 0 0 0 0 0 0 0 0 0
36397 - 0 0 0 0 0 0 0 0 0 0 0 0
36398 - 0 0 0 0 0 0 0 0 0 0 0 0
36399 - 0 0 0 0 0 0 0 0 0 0 0 0
36400 - 6 6 6 6 6 6 10 10 10 10 10 10
36401 - 10 10 10 6 6 6 6 6 6 6 6 6
36402 - 0 0 0 0 0 0 0 0 0 0 0 0
36403 - 0 0 0 0 0 0 0 0 0 0 0 0
36404 - 0 0 0 0 0 0 0 0 0 0 0 0
36405 - 0 0 0 0 0 0 0 0 0 0 0 0
36406 - 0 0 0 0 0 0 0 0 0 0 0 0
36407 - 0 0 0 0 0 0 0 0 0 0 0 0
36408 - 0 0 0 0 0 0 0 0 0 0 0 0
36409 - 0 0 0 0 0 0 0 0 0 0 0 0
36410 - 0 0 0 0 0 0 0 0 0 0 0 0
36411 - 0 0 0 0 0 0 0 0 0 0 0 0
36412 - 0 0 0 0 0 0 0 0 0 0 0 0
36413 - 0 0 0 0 0 0 0 0 0 0 0 0
36414 - 0 0 0 0 0 0 0 0 0 0 0 0
36415 - 0 0 0 0 0 0 0 0 0 0 0 0
36416 - 0 0 0 0 0 0 0 0 0 0 0 0
36417 - 0 0 0 0 0 0 0 0 0 0 0 0
36418 - 0 0 0 0 0 0 0 0 0 0 0 0
36419 - 0 0 0 6 6 6 10 10 10 14 14 14
36420 - 22 22 22 26 26 26 30 30 30 34 34 34
36421 - 30 30 30 30 30 30 26 26 26 18 18 18
36422 - 14 14 14 10 10 10 6 6 6 0 0 0
36423 - 0 0 0 0 0 0 0 0 0 0 0 0
36424 - 0 0 0 0 0 0 0 0 0 0 0 0
36425 - 0 0 0 0 0 0 0 0 0 0 0 0
36426 - 0 0 0 0 0 0 0 0 0 0 0 0
36427 - 0 0 0 0 0 0 0 0 0 0 0 0
36428 - 0 0 0 0 0 0 0 0 0 0 0 0
36429 - 0 0 0 0 0 0 0 0 0 0 0 0
36430 - 0 0 0 0 0 0 0 0 0 0 0 0
36431 - 0 0 0 0 0 0 0 0 0 0 0 0
36432 - 0 0 0 0 0 1 0 0 1 0 0 0
36433 - 0 0 0 0 0 0 0 0 0 0 0 0
36434 - 0 0 0 0 0 0 0 0 0 0 0 0
36435 - 0 0 0 0 0 0 0 0 0 0 0 0
36436 - 0 0 0 0 0 0 0 0 0 0 0 0
36437 - 0 0 0 0 0 0 0 0 0 0 0 0
36438 - 0 0 0 0 0 0 0 0 0 0 0 0
36439 - 6 6 6 14 14 14 26 26 26 42 42 42
36440 - 54 54 54 66 66 66 78 78 78 78 78 78
36441 - 78 78 78 74 74 74 66 66 66 54 54 54
36442 - 42 42 42 26 26 26 18 18 18 10 10 10
36443 - 6 6 6 0 0 0 0 0 0 0 0 0
36444 - 0 0 0 0 0 0 0 0 0 0 0 0
36445 - 0 0 0 0 0 0 0 0 0 0 0 0
36446 - 0 0 0 0 0 0 0 0 0 0 0 0
36447 - 0 0 0 0 0 0 0 0 0 0 0 0
36448 - 0 0 0 0 0 0 0 0 0 0 0 0
36449 - 0 0 0 0 0 0 0 0 0 0 0 0
36450 - 0 0 0 0 0 0 0 0 0 0 0 0
36451 - 0 0 0 0 0 0 0 0 0 0 0 0
36452 - 0 0 1 0 0 0 0 0 0 0 0 0
36453 - 0 0 0 0 0 0 0 0 0 0 0 0
36454 - 0 0 0 0 0 0 0 0 0 0 0 0
36455 - 0 0 0 0 0 0 0 0 0 0 0 0
36456 - 0 0 0 0 0 0 0 0 0 0 0 0
36457 - 0 0 0 0 0 0 0 0 0 0 0 0
36458 - 0 0 0 0 0 0 0 0 0 10 10 10
36459 - 22 22 22 42 42 42 66 66 66 86 86 86
36460 - 66 66 66 38 38 38 38 38 38 22 22 22
36461 - 26 26 26 34 34 34 54 54 54 66 66 66
36462 - 86 86 86 70 70 70 46 46 46 26 26 26
36463 - 14 14 14 6 6 6 0 0 0 0 0 0
36464 - 0 0 0 0 0 0 0 0 0 0 0 0
36465 - 0 0 0 0 0 0 0 0 0 0 0 0
36466 - 0 0 0 0 0 0 0 0 0 0 0 0
36467 - 0 0 0 0 0 0 0 0 0 0 0 0
36468 - 0 0 0 0 0 0 0 0 0 0 0 0
36469 - 0 0 0 0 0 0 0 0 0 0 0 0
36470 - 0 0 0 0 0 0 0 0 0 0 0 0
36471 - 0 0 0 0 0 0 0 0 0 0 0 0
36472 - 0 0 1 0 0 1 0 0 1 0 0 0
36473 - 0 0 0 0 0 0 0 0 0 0 0 0
36474 - 0 0 0 0 0 0 0 0 0 0 0 0
36475 - 0 0 0 0 0 0 0 0 0 0 0 0
36476 - 0 0 0 0 0 0 0 0 0 0 0 0
36477 - 0 0 0 0 0 0 0 0 0 0 0 0
36478 - 0 0 0 0 0 0 10 10 10 26 26 26
36479 - 50 50 50 82 82 82 58 58 58 6 6 6
36480 - 2 2 6 2 2 6 2 2 6 2 2 6
36481 - 2 2 6 2 2 6 2 2 6 2 2 6
36482 - 6 6 6 54 54 54 86 86 86 66 66 66
36483 - 38 38 38 18 18 18 6 6 6 0 0 0
36484 - 0 0 0 0 0 0 0 0 0 0 0 0
36485 - 0 0 0 0 0 0 0 0 0 0 0 0
36486 - 0 0 0 0 0 0 0 0 0 0 0 0
36487 - 0 0 0 0 0 0 0 0 0 0 0 0
36488 - 0 0 0 0 0 0 0 0 0 0 0 0
36489 - 0 0 0 0 0 0 0 0 0 0 0 0
36490 - 0 0 0 0 0 0 0 0 0 0 0 0
36491 - 0 0 0 0 0 0 0 0 0 0 0 0
36492 - 0 0 0 0 0 0 0 0 0 0 0 0
36493 - 0 0 0 0 0 0 0 0 0 0 0 0
36494 - 0 0 0 0 0 0 0 0 0 0 0 0
36495 - 0 0 0 0 0 0 0 0 0 0 0 0
36496 - 0 0 0 0 0 0 0 0 0 0 0 0
36497 - 0 0 0 0 0 0 0 0 0 0 0 0
36498 - 0 0 0 6 6 6 22 22 22 50 50 50
36499 - 78 78 78 34 34 34 2 2 6 2 2 6
36500 - 2 2 6 2 2 6 2 2 6 2 2 6
36501 - 2 2 6 2 2 6 2 2 6 2 2 6
36502 - 2 2 6 2 2 6 6 6 6 70 70 70
36503 - 78 78 78 46 46 46 22 22 22 6 6 6
36504 - 0 0 0 0 0 0 0 0 0 0 0 0
36505 - 0 0 0 0 0 0 0 0 0 0 0 0
36506 - 0 0 0 0 0 0 0 0 0 0 0 0
36507 - 0 0 0 0 0 0 0 0 0 0 0 0
36508 - 0 0 0 0 0 0 0 0 0 0 0 0
36509 - 0 0 0 0 0 0 0 0 0 0 0 0
36510 - 0 0 0 0 0 0 0 0 0 0 0 0
36511 - 0 0 0 0 0 0 0 0 0 0 0 0
36512 - 0 0 1 0 0 1 0 0 1 0 0 0
36513 - 0 0 0 0 0 0 0 0 0 0 0 0
36514 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 18 18 18 42 42 42 82 82 82
36519 - 26 26 26 2 2 6 2 2 6 2 2 6
36520 - 2 2 6 2 2 6 2 2 6 2 2 6
36521 - 2 2 6 2 2 6 2 2 6 14 14 14
36522 - 46 46 46 34 34 34 6 6 6 2 2 6
36523 - 42 42 42 78 78 78 42 42 42 18 18 18
36524 - 6 6 6 0 0 0 0 0 0 0 0 0
36525 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
36539 - 2 2 6 2 2 6 2 2 6 2 2 6
36540 - 2 2 6 2 2 6 2 2 6 2 2 6
36541 - 2 2 6 2 2 6 2 2 6 26 26 26
36542 - 86 86 86 101 101 101 46 46 46 10 10 10
36543 - 2 2 6 58 58 58 70 70 70 34 34 34
36544 - 10 10 10 0 0 0 0 0 0 0 0 0
36545 - 0 0 0 0 0 0 0 0 0 0 0 0
36546 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0
36557 - 0 0 0 0 0 0 0 0 0 0 0 0
36558 - 14 14 14 42 42 42 86 86 86 10 10 10
36559 - 2 2 6 2 2 6 2 2 6 2 2 6
36560 - 2 2 6 2 2 6 2 2 6 2 2 6
36561 - 2 2 6 2 2 6 2 2 6 30 30 30
36562 - 94 94 94 94 94 94 58 58 58 26 26 26
36563 - 2 2 6 6 6 6 78 78 78 54 54 54
36564 - 22 22 22 6 6 6 0 0 0 0 0 0
36565 - 0 0 0 0 0 0 0 0 0 0 0 0
36566 - 0 0 0 0 0 0 0 0 0 0 0 0
36567 - 0 0 0 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 0 0 0 0 0 0 0 0 0 0
36577 - 0 0 0 0 0 0 0 0 0 6 6 6
36578 - 22 22 22 62 62 62 62 62 62 2 2 6
36579 - 2 2 6 2 2 6 2 2 6 2 2 6
36580 - 2 2 6 2 2 6 2 2 6 2 2 6
36581 - 2 2 6 2 2 6 2 2 6 26 26 26
36582 - 54 54 54 38 38 38 18 18 18 10 10 10
36583 - 2 2 6 2 2 6 34 34 34 82 82 82
36584 - 38 38 38 14 14 14 0 0 0 0 0 0
36585 - 0 0 0 0 0 0 0 0 0 0 0 0
36586 - 0 0 0 0 0 0 0 0 0 0 0 0
36587 - 0 0 0 0 0 0 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 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
36597 - 0 0 0 0 0 0 0 0 0 6 6 6
36598 - 30 30 30 78 78 78 30 30 30 2 2 6
36599 - 2 2 6 2 2 6 2 2 6 2 2 6
36600 - 2 2 6 2 2 6 2 2 6 2 2 6
36601 - 2 2 6 2 2 6 2 2 6 10 10 10
36602 - 10 10 10 2 2 6 2 2 6 2 2 6
36603 - 2 2 6 2 2 6 2 2 6 78 78 78
36604 - 50 50 50 18 18 18 6 6 6 0 0 0
36605 - 0 0 0 0 0 0 0 0 0 0 0 0
36606 - 0 0 0 0 0 0 0 0 0 0 0 0
36607 - 0 0 0 0 0 0 0 0 0 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 1 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 10 10 10
36618 - 38 38 38 86 86 86 14 14 14 2 2 6
36619 - 2 2 6 2 2 6 2 2 6 2 2 6
36620 - 2 2 6 2 2 6 2 2 6 2 2 6
36621 - 2 2 6 2 2 6 2 2 6 2 2 6
36622 - 2 2 6 2 2 6 2 2 6 2 2 6
36623 - 2 2 6 2 2 6 2 2 6 54 54 54
36624 - 66 66 66 26 26 26 6 6 6 0 0 0
36625 - 0 0 0 0 0 0 0 0 0 0 0 0
36626 - 0 0 0 0 0 0 0 0 0 0 0 0
36627 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
36637 - 0 0 0 0 0 0 0 0 0 14 14 14
36638 - 42 42 42 82 82 82 2 2 6 2 2 6
36639 - 2 2 6 6 6 6 10 10 10 2 2 6
36640 - 2 2 6 2 2 6 2 2 6 2 2 6
36641 - 2 2 6 2 2 6 2 2 6 6 6 6
36642 - 14 14 14 10 10 10 2 2 6 2 2 6
36643 - 2 2 6 2 2 6 2 2 6 18 18 18
36644 - 82 82 82 34 34 34 10 10 10 0 0 0
36645 - 0 0 0 0 0 0 0 0 0 0 0 0
36646 - 0 0 0 0 0 0 0 0 0 0 0 0
36647 - 0 0 0 0 0 0 0 0 0 0 0 0
36648 - 0 0 0 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 1 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 0 0 0 0 0 0 0 0 0 0
36657 - 0 0 0 0 0 0 0 0 0 14 14 14
36658 - 46 46 46 86 86 86 2 2 6 2 2 6
36659 - 6 6 6 6 6 6 22 22 22 34 34 34
36660 - 6 6 6 2 2 6 2 2 6 2 2 6
36661 - 2 2 6 2 2 6 18 18 18 34 34 34
36662 - 10 10 10 50 50 50 22 22 22 2 2 6
36663 - 2 2 6 2 2 6 2 2 6 10 10 10
36664 - 86 86 86 42 42 42 14 14 14 0 0 0
36665 - 0 0 0 0 0 0 0 0 0 0 0 0
36666 - 0 0 0 0 0 0 0 0 0 0 0 0
36667 - 0 0 0 0 0 0 0 0 0 0 0 0
36668 - 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
36677 - 0 0 0 0 0 0 0 0 0 14 14 14
36678 - 46 46 46 86 86 86 2 2 6 2 2 6
36679 - 38 38 38 116 116 116 94 94 94 22 22 22
36680 - 22 22 22 2 2 6 2 2 6 2 2 6
36681 - 14 14 14 86 86 86 138 138 138 162 162 162
36682 -154 154 154 38 38 38 26 26 26 6 6 6
36683 - 2 2 6 2 2 6 2 2 6 2 2 6
36684 - 86 86 86 46 46 46 14 14 14 0 0 0
36685 - 0 0 0 0 0 0 0 0 0 0 0 0
36686 - 0 0 0 0 0 0 0 0 0 0 0 0
36687 - 0 0 0 0 0 0 0 0 0 0 0 0
36688 - 0 0 0 0 0 0 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 14 14 14
36698 - 46 46 46 86 86 86 2 2 6 14 14 14
36699 -134 134 134 198 198 198 195 195 195 116 116 116
36700 - 10 10 10 2 2 6 2 2 6 6 6 6
36701 -101 98 89 187 187 187 210 210 210 218 218 218
36702 -214 214 214 134 134 134 14 14 14 6 6 6
36703 - 2 2 6 2 2 6 2 2 6 2 2 6
36704 - 86 86 86 50 50 50 18 18 18 6 6 6
36705 - 0 0 0 0 0 0 0 0 0 0 0 0
36706 - 0 0 0 0 0 0 0 0 0 0 0 0
36707 - 0 0 0 0 0 0 0 0 0 0 0 0
36708 - 0 0 0 0 0 0 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 1 0 0 0
36712 - 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0
36717 - 0 0 0 0 0 0 0 0 0 14 14 14
36718 - 46 46 46 86 86 86 2 2 6 54 54 54
36719 -218 218 218 195 195 195 226 226 226 246 246 246
36720 - 58 58 58 2 2 6 2 2 6 30 30 30
36721 -210 210 210 253 253 253 174 174 174 123 123 123
36722 -221 221 221 234 234 234 74 74 74 2 2 6
36723 - 2 2 6 2 2 6 2 2 6 2 2 6
36724 - 70 70 70 58 58 58 22 22 22 6 6 6
36725 - 0 0 0 0 0 0 0 0 0 0 0 0
36726 - 0 0 0 0 0 0 0 0 0 0 0 0
36727 - 0 0 0 0 0 0 0 0 0 0 0 0
36728 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0
36737 - 0 0 0 0 0 0 0 0 0 14 14 14
36738 - 46 46 46 82 82 82 2 2 6 106 106 106
36739 -170 170 170 26 26 26 86 86 86 226 226 226
36740 -123 123 123 10 10 10 14 14 14 46 46 46
36741 -231 231 231 190 190 190 6 6 6 70 70 70
36742 - 90 90 90 238 238 238 158 158 158 2 2 6
36743 - 2 2 6 2 2 6 2 2 6 2 2 6
36744 - 70 70 70 58 58 58 22 22 22 6 6 6
36745 - 0 0 0 0 0 0 0 0 0 0 0 0
36746 - 0 0 0 0 0 0 0 0 0 0 0 0
36747 - 0 0 0 0 0 0 0 0 0 0 0 0
36748 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
36752 - 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0
36757 - 0 0 0 0 0 0 0 0 0 14 14 14
36758 - 42 42 42 86 86 86 6 6 6 116 116 116
36759 -106 106 106 6 6 6 70 70 70 149 149 149
36760 -128 128 128 18 18 18 38 38 38 54 54 54
36761 -221 221 221 106 106 106 2 2 6 14 14 14
36762 - 46 46 46 190 190 190 198 198 198 2 2 6
36763 - 2 2 6 2 2 6 2 2 6 2 2 6
36764 - 74 74 74 62 62 62 22 22 22 6 6 6
36765 - 0 0 0 0 0 0 0 0 0 0 0 0
36766 - 0 0 0 0 0 0 0 0 0 0 0 0
36767 - 0 0 0 0 0 0 0 0 0 0 0 0
36768 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
36772 - 0 0 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0 0 0 0
36777 - 0 0 0 0 0 0 0 0 0 14 14 14
36778 - 42 42 42 94 94 94 14 14 14 101 101 101
36779 -128 128 128 2 2 6 18 18 18 116 116 116
36780 -118 98 46 121 92 8 121 92 8 98 78 10
36781 -162 162 162 106 106 106 2 2 6 2 2 6
36782 - 2 2 6 195 195 195 195 195 195 6 6 6
36783 - 2 2 6 2 2 6 2 2 6 2 2 6
36784 - 74 74 74 62 62 62 22 22 22 6 6 6
36785 - 0 0 0 0 0 0 0 0 0 0 0 0
36786 - 0 0 0 0 0 0 0 0 0 0 0 0
36787 - 0 0 0 0 0 0 0 0 0 0 0 0
36788 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1
36792 - 0 0 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0 0 0 0
36797 - 0 0 0 0 0 0 0 0 0 10 10 10
36798 - 38 38 38 90 90 90 14 14 14 58 58 58
36799 -210 210 210 26 26 26 54 38 6 154 114 10
36800 -226 170 11 236 186 11 225 175 15 184 144 12
36801 -215 174 15 175 146 61 37 26 9 2 2 6
36802 - 70 70 70 246 246 246 138 138 138 2 2 6
36803 - 2 2 6 2 2 6 2 2 6 2 2 6
36804 - 70 70 70 66 66 66 26 26 26 6 6 6
36805 - 0 0 0 0 0 0 0 0 0 0 0 0
36806 - 0 0 0 0 0 0 0 0 0 0 0 0
36807 - 0 0 0 0 0 0 0 0 0 0 0 0
36808 - 0 0 0 0 0 0 0 0 0 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 10 10 10
36818 - 38 38 38 86 86 86 14 14 14 10 10 10
36819 -195 195 195 188 164 115 192 133 9 225 175 15
36820 -239 182 13 234 190 10 232 195 16 232 200 30
36821 -245 207 45 241 208 19 232 195 16 184 144 12
36822 -218 194 134 211 206 186 42 42 42 2 2 6
36823 - 2 2 6 2 2 6 2 2 6 2 2 6
36824 - 50 50 50 74 74 74 30 30 30 6 6 6
36825 - 0 0 0 0 0 0 0 0 0 0 0 0
36826 - 0 0 0 0 0 0 0 0 0 0 0 0
36827 - 0 0 0 0 0 0 0 0 0 0 0 0
36828 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
36836 - 0 0 0 0 0 0 0 0 0 0 0 0
36837 - 0 0 0 0 0 0 0 0 0 10 10 10
36838 - 34 34 34 86 86 86 14 14 14 2 2 6
36839 -121 87 25 192 133 9 219 162 10 239 182 13
36840 -236 186 11 232 195 16 241 208 19 244 214 54
36841 -246 218 60 246 218 38 246 215 20 241 208 19
36842 -241 208 19 226 184 13 121 87 25 2 2 6
36843 - 2 2 6 2 2 6 2 2 6 2 2 6
36844 - 50 50 50 82 82 82 34 34 34 10 10 10
36845 - 0 0 0 0 0 0 0 0 0 0 0 0
36846 - 0 0 0 0 0 0 0 0 0 0 0 0
36847 - 0 0 0 0 0 0 0 0 0 0 0 0
36848 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
36858 - 34 34 34 82 82 82 30 30 30 61 42 6
36859 -180 123 7 206 145 10 230 174 11 239 182 13
36860 -234 190 10 238 202 15 241 208 19 246 218 74
36861 -246 218 38 246 215 20 246 215 20 246 215 20
36862 -226 184 13 215 174 15 184 144 12 6 6 6
36863 - 2 2 6 2 2 6 2 2 6 2 2 6
36864 - 26 26 26 94 94 94 42 42 42 14 14 14
36865 - 0 0 0 0 0 0 0 0 0 0 0 0
36866 - 0 0 0 0 0 0 0 0 0 0 0 0
36867 - 0 0 0 0 0 0 0 0 0 0 0 0
36868 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
36876 - 0 0 0 0 0 0 0 0 0 0 0 0
36877 - 0 0 0 0 0 0 0 0 0 10 10 10
36878 - 30 30 30 78 78 78 50 50 50 104 69 6
36879 -192 133 9 216 158 10 236 178 12 236 186 11
36880 -232 195 16 241 208 19 244 214 54 245 215 43
36881 -246 215 20 246 215 20 241 208 19 198 155 10
36882 -200 144 11 216 158 10 156 118 10 2 2 6
36883 - 2 2 6 2 2 6 2 2 6 2 2 6
36884 - 6 6 6 90 90 90 54 54 54 18 18 18
36885 - 6 6 6 0 0 0 0 0 0 0 0 0
36886 - 0 0 0 0 0 0 0 0 0 0 0 0
36887 - 0 0 0 0 0 0 0 0 0 0 0 0
36888 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
36896 - 0 0 0 0 0 0 0 0 0 0 0 0
36897 - 0 0 0 0 0 0 0 0 0 10 10 10
36898 - 30 30 30 78 78 78 46 46 46 22 22 22
36899 -137 92 6 210 162 10 239 182 13 238 190 10
36900 -238 202 15 241 208 19 246 215 20 246 215 20
36901 -241 208 19 203 166 17 185 133 11 210 150 10
36902 -216 158 10 210 150 10 102 78 10 2 2 6
36903 - 6 6 6 54 54 54 14 14 14 2 2 6
36904 - 2 2 6 62 62 62 74 74 74 30 30 30
36905 - 10 10 10 0 0 0 0 0 0 0 0 0
36906 - 0 0 0 0 0 0 0 0 0 0 0 0
36907 - 0 0 0 0 0 0 0 0 0 0 0 0
36908 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
36916 - 0 0 0 0 0 0 0 0 0 0 0 0
36917 - 0 0 0 0 0 0 0 0 0 10 10 10
36918 - 34 34 34 78 78 78 50 50 50 6 6 6
36919 - 94 70 30 139 102 15 190 146 13 226 184 13
36920 -232 200 30 232 195 16 215 174 15 190 146 13
36921 -168 122 10 192 133 9 210 150 10 213 154 11
36922 -202 150 34 182 157 106 101 98 89 2 2 6
36923 - 2 2 6 78 78 78 116 116 116 58 58 58
36924 - 2 2 6 22 22 22 90 90 90 46 46 46
36925 - 18 18 18 6 6 6 0 0 0 0 0 0
36926 - 0 0 0 0 0 0 0 0 0 0 0 0
36927 - 0 0 0 0 0 0 0 0 0 0 0 0
36928 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
36938 - 38 38 38 86 86 86 50 50 50 6 6 6
36939 -128 128 128 174 154 114 156 107 11 168 122 10
36940 -198 155 10 184 144 12 197 138 11 200 144 11
36941 -206 145 10 206 145 10 197 138 11 188 164 115
36942 -195 195 195 198 198 198 174 174 174 14 14 14
36943 - 2 2 6 22 22 22 116 116 116 116 116 116
36944 - 22 22 22 2 2 6 74 74 74 70 70 70
36945 - 30 30 30 10 10 10 0 0 0 0 0 0
36946 - 0 0 0 0 0 0 0 0 0 0 0 0
36947 - 0 0 0 0 0 0 0 0 0 0 0 0
36948 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
36958 - 50 50 50 101 101 101 26 26 26 10 10 10
36959 -138 138 138 190 190 190 174 154 114 156 107 11
36960 -197 138 11 200 144 11 197 138 11 192 133 9
36961 -180 123 7 190 142 34 190 178 144 187 187 187
36962 -202 202 202 221 221 221 214 214 214 66 66 66
36963 - 2 2 6 2 2 6 50 50 50 62 62 62
36964 - 6 6 6 2 2 6 10 10 10 90 90 90
36965 - 50 50 50 18 18 18 6 6 6 0 0 0
36966 - 0 0 0 0 0 0 0 0 0 0 0 0
36967 - 0 0 0 0 0 0 0 0 0 0 0 0
36968 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 34 34 34
36978 - 74 74 74 74 74 74 2 2 6 6 6 6
36979 -144 144 144 198 198 198 190 190 190 178 166 146
36980 -154 121 60 156 107 11 156 107 11 168 124 44
36981 -174 154 114 187 187 187 190 190 190 210 210 210
36982 -246 246 246 253 253 253 253 253 253 182 182 182
36983 - 6 6 6 2 2 6 2 2 6 2 2 6
36984 - 2 2 6 2 2 6 2 2 6 62 62 62
36985 - 74 74 74 34 34 34 14 14 14 0 0 0
36986 - 0 0 0 0 0 0 0 0 0 0 0 0
36987 - 0 0 0 0 0 0 0 0 0 0 0 0
36988 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 22 22 22 54 54 54
36998 - 94 94 94 18 18 18 2 2 6 46 46 46
36999 -234 234 234 221 221 221 190 190 190 190 190 190
37000 -190 190 190 187 187 187 187 187 187 190 190 190
37001 -190 190 190 195 195 195 214 214 214 242 242 242
37002 -253 253 253 253 253 253 253 253 253 253 253 253
37003 - 82 82 82 2 2 6 2 2 6 2 2 6
37004 - 2 2 6 2 2 6 2 2 6 14 14 14
37005 - 86 86 86 54 54 54 22 22 22 6 6 6
37006 - 0 0 0 0 0 0 0 0 0 0 0 0
37007 - 0 0 0 0 0 0 0 0 0 0 0 0
37008 - 0 0 0 0 0 0 0 0 0 0 0 0
37009 - 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
37018 - 46 46 46 18 18 18 6 6 6 182 182 182
37019 -253 253 253 246 246 246 206 206 206 190 190 190
37020 -190 190 190 190 190 190 190 190 190 190 190 190
37021 -206 206 206 231 231 231 250 250 250 253 253 253
37022 -253 253 253 253 253 253 253 253 253 253 253 253
37023 -202 202 202 14 14 14 2 2 6 2 2 6
37024 - 2 2 6 2 2 6 2 2 6 2 2 6
37025 - 42 42 42 86 86 86 42 42 42 18 18 18
37026 - 6 6 6 0 0 0 0 0 0 0 0 0
37027 - 0 0 0 0 0 0 0 0 0 0 0 0
37028 - 0 0 0 0 0 0 0 0 0 0 0 0
37029 - 0 0 0 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 6 6 6
37037 - 14 14 14 38 38 38 74 74 74 66 66 66
37038 - 2 2 6 6 6 6 90 90 90 250 250 250
37039 -253 253 253 253 253 253 238 238 238 198 198 198
37040 -190 190 190 190 190 190 195 195 195 221 221 221
37041 -246 246 246 253 253 253 253 253 253 253 253 253
37042 -253 253 253 253 253 253 253 253 253 253 253 253
37043 -253 253 253 82 82 82 2 2 6 2 2 6
37044 - 2 2 6 2 2 6 2 2 6 2 2 6
37045 - 2 2 6 78 78 78 70 70 70 34 34 34
37046 - 14 14 14 6 6 6 0 0 0 0 0 0
37047 - 0 0 0 0 0 0 0 0 0 0 0 0
37048 - 0 0 0 0 0 0 0 0 0 0 0 0
37049 - 0 0 0 0 0 0 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 14 14 14
37057 - 34 34 34 66 66 66 78 78 78 6 6 6
37058 - 2 2 6 18 18 18 218 218 218 253 253 253
37059 -253 253 253 253 253 253 253 253 253 246 246 246
37060 -226 226 226 231 231 231 246 246 246 253 253 253
37061 -253 253 253 253 253 253 253 253 253 253 253 253
37062 -253 253 253 253 253 253 253 253 253 253 253 253
37063 -253 253 253 178 178 178 2 2 6 2 2 6
37064 - 2 2 6 2 2 6 2 2 6 2 2 6
37065 - 2 2 6 18 18 18 90 90 90 62 62 62
37066 - 30 30 30 10 10 10 0 0 0 0 0 0
37067 - 0 0 0 0 0 0 0 0 0 0 0 0
37068 - 0 0 0 0 0 0 0 0 0 0 0 0
37069 - 0 0 0 0 0 0 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 10 10 10 26 26 26
37077 - 58 58 58 90 90 90 18 18 18 2 2 6
37078 - 2 2 6 110 110 110 253 253 253 253 253 253
37079 -253 253 253 253 253 253 253 253 253 253 253 253
37080 -250 250 250 253 253 253 253 253 253 253 253 253
37081 -253 253 253 253 253 253 253 253 253 253 253 253
37082 -253 253 253 253 253 253 253 253 253 253 253 253
37083 -253 253 253 231 231 231 18 18 18 2 2 6
37084 - 2 2 6 2 2 6 2 2 6 2 2 6
37085 - 2 2 6 2 2 6 18 18 18 94 94 94
37086 - 54 54 54 26 26 26 10 10 10 0 0 0
37087 - 0 0 0 0 0 0 0 0 0 0 0 0
37088 - 0 0 0 0 0 0 0 0 0 0 0 0
37089 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
37097 - 90 90 90 26 26 26 2 2 6 2 2 6
37098 - 14 14 14 195 195 195 250 250 250 253 253 253
37099 -253 253 253 253 253 253 253 253 253 253 253 253
37100 -253 253 253 253 253 253 253 253 253 253 253 253
37101 -253 253 253 253 253 253 253 253 253 253 253 253
37102 -253 253 253 253 253 253 253 253 253 253 253 253
37103 -250 250 250 242 242 242 54 54 54 2 2 6
37104 - 2 2 6 2 2 6 2 2 6 2 2 6
37105 - 2 2 6 2 2 6 2 2 6 38 38 38
37106 - 86 86 86 50 50 50 22 22 22 6 6 6
37107 - 0 0 0 0 0 0 0 0 0 0 0 0
37108 - 0 0 0 0 0 0 0 0 0 0 0 0
37109 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 14 14 14 38 38 38 82 82 82
37117 - 34 34 34 2 2 6 2 2 6 2 2 6
37118 - 42 42 42 195 195 195 246 246 246 253 253 253
37119 -253 253 253 253 253 253 253 253 253 250 250 250
37120 -242 242 242 242 242 242 250 250 250 253 253 253
37121 -253 253 253 253 253 253 253 253 253 253 253 253
37122 -253 253 253 250 250 250 246 246 246 238 238 238
37123 -226 226 226 231 231 231 101 101 101 6 6 6
37124 - 2 2 6 2 2 6 2 2 6 2 2 6
37125 - 2 2 6 2 2 6 2 2 6 2 2 6
37126 - 38 38 38 82 82 82 42 42 42 14 14 14
37127 - 6 6 6 0 0 0 0 0 0 0 0 0
37128 - 0 0 0 0 0 0 0 0 0 0 0 0
37129 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 10 10 10 26 26 26 62 62 62 66 66 66
37137 - 2 2 6 2 2 6 2 2 6 6 6 6
37138 - 70 70 70 170 170 170 206 206 206 234 234 234
37139 -246 246 246 250 250 250 250 250 250 238 238 238
37140 -226 226 226 231 231 231 238 238 238 250 250 250
37141 -250 250 250 250 250 250 246 246 246 231 231 231
37142 -214 214 214 206 206 206 202 202 202 202 202 202
37143 -198 198 198 202 202 202 182 182 182 18 18 18
37144 - 2 2 6 2 2 6 2 2 6 2 2 6
37145 - 2 2 6 2 2 6 2 2 6 2 2 6
37146 - 2 2 6 62 62 62 66 66 66 30 30 30
37147 - 10 10 10 0 0 0 0 0 0 0 0 0
37148 - 0 0 0 0 0 0 0 0 0 0 0 0
37149 - 0 0 0 0 0 0 0 0 0 0 0 0
37150 - 0 0 0 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 - 14 14 14 42 42 42 82 82 82 18 18 18
37157 - 2 2 6 2 2 6 2 2 6 10 10 10
37158 - 94 94 94 182 182 182 218 218 218 242 242 242
37159 -250 250 250 253 253 253 253 253 253 250 250 250
37160 -234 234 234 253 253 253 253 253 253 253 253 253
37161 -253 253 253 253 253 253 253 253 253 246 246 246
37162 -238 238 238 226 226 226 210 210 210 202 202 202
37163 -195 195 195 195 195 195 210 210 210 158 158 158
37164 - 6 6 6 14 14 14 50 50 50 14 14 14
37165 - 2 2 6 2 2 6 2 2 6 2 2 6
37166 - 2 2 6 6 6 6 86 86 86 46 46 46
37167 - 18 18 18 6 6 6 0 0 0 0 0 0
37168 - 0 0 0 0 0 0 0 0 0 0 0 0
37169 - 0 0 0 0 0 0 0 0 0 0 0 0
37170 - 0 0 0 0 0 0 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 6 6 6
37176 - 22 22 22 54 54 54 70 70 70 2 2 6
37177 - 2 2 6 10 10 10 2 2 6 22 22 22
37178 -166 166 166 231 231 231 250 250 250 253 253 253
37179 -253 253 253 253 253 253 253 253 253 250 250 250
37180 -242 242 242 253 253 253 253 253 253 253 253 253
37181 -253 253 253 253 253 253 253 253 253 253 253 253
37182 -253 253 253 253 253 253 253 253 253 246 246 246
37183 -231 231 231 206 206 206 198 198 198 226 226 226
37184 - 94 94 94 2 2 6 6 6 6 38 38 38
37185 - 30 30 30 2 2 6 2 2 6 2 2 6
37186 - 2 2 6 2 2 6 62 62 62 66 66 66
37187 - 26 26 26 10 10 10 0 0 0 0 0 0
37188 - 0 0 0 0 0 0 0 0 0 0 0 0
37189 - 0 0 0 0 0 0 0 0 0 0 0 0
37190 - 0 0 0 0 0 0 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 10 10 10
37196 - 30 30 30 74 74 74 50 50 50 2 2 6
37197 - 26 26 26 26 26 26 2 2 6 106 106 106
37198 -238 238 238 253 253 253 253 253 253 253 253 253
37199 -253 253 253 253 253 253 253 253 253 253 253 253
37200 -253 253 253 253 253 253 253 253 253 253 253 253
37201 -253 253 253 253 253 253 253 253 253 253 253 253
37202 -253 253 253 253 253 253 253 253 253 253 253 253
37203 -253 253 253 246 246 246 218 218 218 202 202 202
37204 -210 210 210 14 14 14 2 2 6 2 2 6
37205 - 30 30 30 22 22 22 2 2 6 2 2 6
37206 - 2 2 6 2 2 6 18 18 18 86 86 86
37207 - 42 42 42 14 14 14 0 0 0 0 0 0
37208 - 0 0 0 0 0 0 0 0 0 0 0 0
37209 - 0 0 0 0 0 0 0 0 0 0 0 0
37210 - 0 0 0 0 0 0 0 0 0 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 14 14 14
37216 - 42 42 42 90 90 90 22 22 22 2 2 6
37217 - 42 42 42 2 2 6 18 18 18 218 218 218
37218 -253 253 253 253 253 253 253 253 253 253 253 253
37219 -253 253 253 253 253 253 253 253 253 253 253 253
37220 -253 253 253 253 253 253 253 253 253 253 253 253
37221 -253 253 253 253 253 253 253 253 253 253 253 253
37222 -253 253 253 253 253 253 253 253 253 253 253 253
37223 -253 253 253 253 253 253 250 250 250 221 221 221
37224 -218 218 218 101 101 101 2 2 6 14 14 14
37225 - 18 18 18 38 38 38 10 10 10 2 2 6
37226 - 2 2 6 2 2 6 2 2 6 78 78 78
37227 - 58 58 58 22 22 22 6 6 6 0 0 0
37228 - 0 0 0 0 0 0 0 0 0 0 0 0
37229 - 0 0 0 0 0 0 0 0 0 0 0 0
37230 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
37236 - 54 54 54 82 82 82 2 2 6 26 26 26
37237 - 22 22 22 2 2 6 123 123 123 253 253 253
37238 -253 253 253 253 253 253 253 253 253 253 253 253
37239 -253 253 253 253 253 253 253 253 253 253 253 253
37240 -253 253 253 253 253 253 253 253 253 253 253 253
37241 -253 253 253 253 253 253 253 253 253 253 253 253
37242 -253 253 253 253 253 253 253 253 253 253 253 253
37243 -253 253 253 253 253 253 253 253 253 250 250 250
37244 -238 238 238 198 198 198 6 6 6 38 38 38
37245 - 58 58 58 26 26 26 38 38 38 2 2 6
37246 - 2 2 6 2 2 6 2 2 6 46 46 46
37247 - 78 78 78 30 30 30 10 10 10 0 0 0
37248 - 0 0 0 0 0 0 0 0 0 0 0 0
37249 - 0 0 0 0 0 0 0 0 0 0 0 0
37250 - 0 0 0 0 0 0 0 0 0 0 0 0
37251 - 0 0 0 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 10 10 10 30 30 30
37256 - 74 74 74 58 58 58 2 2 6 42 42 42
37257 - 2 2 6 22 22 22 231 231 231 253 253 253
37258 -253 253 253 253 253 253 253 253 253 253 253 253
37259 -253 253 253 253 253 253 253 253 253 250 250 250
37260 -253 253 253 253 253 253 253 253 253 253 253 253
37261 -253 253 253 253 253 253 253 253 253 253 253 253
37262 -253 253 253 253 253 253 253 253 253 253 253 253
37263 -253 253 253 253 253 253 253 253 253 253 253 253
37264 -253 253 253 246 246 246 46 46 46 38 38 38
37265 - 42 42 42 14 14 14 38 38 38 14 14 14
37266 - 2 2 6 2 2 6 2 2 6 6 6 6
37267 - 86 86 86 46 46 46 14 14 14 0 0 0
37268 - 0 0 0 0 0 0 0 0 0 0 0 0
37269 - 0 0 0 0 0 0 0 0 0 0 0 0
37270 - 0 0 0 0 0 0 0 0 0 0 0 0
37271 - 0 0 0 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 6 6 6 14 14 14 42 42 42
37276 - 90 90 90 18 18 18 18 18 18 26 26 26
37277 - 2 2 6 116 116 116 253 253 253 253 253 253
37278 -253 253 253 253 253 253 253 253 253 253 253 253
37279 -253 253 253 253 253 253 250 250 250 238 238 238
37280 -253 253 253 253 253 253 253 253 253 253 253 253
37281 -253 253 253 253 253 253 253 253 253 253 253 253
37282 -253 253 253 253 253 253 253 253 253 253 253 253
37283 -253 253 253 253 253 253 253 253 253 253 253 253
37284 -253 253 253 253 253 253 94 94 94 6 6 6
37285 - 2 2 6 2 2 6 10 10 10 34 34 34
37286 - 2 2 6 2 2 6 2 2 6 2 2 6
37287 - 74 74 74 58 58 58 22 22 22 6 6 6
37288 - 0 0 0 0 0 0 0 0 0 0 0 0
37289 - 0 0 0 0 0 0 0 0 0 0 0 0
37290 - 0 0 0 0 0 0 0 0 0 0 0 0
37291 - 0 0 0 0 0 0 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 10 10 10 26 26 26 66 66 66
37296 - 82 82 82 2 2 6 38 38 38 6 6 6
37297 - 14 14 14 210 210 210 253 253 253 253 253 253
37298 -253 253 253 253 253 253 253 253 253 253 253 253
37299 -253 253 253 253 253 253 246 246 246 242 242 242
37300 -253 253 253 253 253 253 253 253 253 253 253 253
37301 -253 253 253 253 253 253 253 253 253 253 253 253
37302 -253 253 253 253 253 253 253 253 253 253 253 253
37303 -253 253 253 253 253 253 253 253 253 253 253 253
37304 -253 253 253 253 253 253 144 144 144 2 2 6
37305 - 2 2 6 2 2 6 2 2 6 46 46 46
37306 - 2 2 6 2 2 6 2 2 6 2 2 6
37307 - 42 42 42 74 74 74 30 30 30 10 10 10
37308 - 0 0 0 0 0 0 0 0 0 0 0 0
37309 - 0 0 0 0 0 0 0 0 0 0 0 0
37310 - 0 0 0 0 0 0 0 0 0 0 0 0
37311 - 0 0 0 0 0 0 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 - 6 6 6 14 14 14 42 42 42 90 90 90
37316 - 26 26 26 6 6 6 42 42 42 2 2 6
37317 - 74 74 74 250 250 250 253 253 253 253 253 253
37318 -253 253 253 253 253 253 253 253 253 253 253 253
37319 -253 253 253 253 253 253 242 242 242 242 242 242
37320 -253 253 253 253 253 253 253 253 253 253 253 253
37321 -253 253 253 253 253 253 253 253 253 253 253 253
37322 -253 253 253 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 182 182 182 2 2 6
37325 - 2 2 6 2 2 6 2 2 6 46 46 46
37326 - 2 2 6 2 2 6 2 2 6 2 2 6
37327 - 10 10 10 86 86 86 38 38 38 10 10 10
37328 - 0 0 0 0 0 0 0 0 0 0 0 0
37329 - 0 0 0 0 0 0 0 0 0 0 0 0
37330 - 0 0 0 0 0 0 0 0 0 0 0 0
37331 - 0 0 0 0 0 0 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 - 10 10 10 26 26 26 66 66 66 82 82 82
37336 - 2 2 6 22 22 22 18 18 18 2 2 6
37337 -149 149 149 253 253 253 253 253 253 253 253 253
37338 -253 253 253 253 253 253 253 253 253 253 253 253
37339 -253 253 253 253 253 253 234 234 234 242 242 242
37340 -253 253 253 253 253 253 253 253 253 253 253 253
37341 -253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 2 2 6
37345 - 2 2 6 2 2 6 2 2 6 38 38 38
37346 - 2 2 6 2 2 6 2 2 6 2 2 6
37347 - 6 6 6 86 86 86 46 46 46 14 14 14
37348 - 0 0 0 0 0 0 0 0 0 0 0 0
37349 - 0 0 0 0 0 0 0 0 0 0 0 0
37350 - 0 0 0 0 0 0 0 0 0 0 0 0
37351 - 0 0 0 0 0 0 0 0 0 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 6 6 6
37355 - 18 18 18 46 46 46 86 86 86 18 18 18
37356 - 2 2 6 34 34 34 10 10 10 6 6 6
37357 -210 210 210 253 253 253 253 253 253 253 253 253
37358 -253 253 253 253 253 253 253 253 253 253 253 253
37359 -253 253 253 253 253 253 234 234 234 242 242 242
37360 -253 253 253 253 253 253 253 253 253 253 253 253
37361 -253 253 253 253 253 253 253 253 253 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 221 221 221 6 6 6
37365 - 2 2 6 2 2 6 6 6 6 30 30 30
37366 - 2 2 6 2 2 6 2 2 6 2 2 6
37367 - 2 2 6 82 82 82 54 54 54 18 18 18
37368 - 6 6 6 0 0 0 0 0 0 0 0 0
37369 - 0 0 0 0 0 0 0 0 0 0 0 0
37370 - 0 0 0 0 0 0 0 0 0 0 0 0
37371 - 0 0 0 0 0 0 0 0 0 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 10 10 10
37375 - 26 26 26 66 66 66 62 62 62 2 2 6
37376 - 2 2 6 38 38 38 10 10 10 26 26 26
37377 -238 238 238 253 253 253 253 253 253 253 253 253
37378 -253 253 253 253 253 253 253 253 253 253 253 253
37379 -253 253 253 253 253 253 231 231 231 238 238 238
37380 -253 253 253 253 253 253 253 253 253 253 253 253
37381 -253 253 253 253 253 253 253 253 253 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 253 253 253
37384 -253 253 253 253 253 253 231 231 231 6 6 6
37385 - 2 2 6 2 2 6 10 10 10 30 30 30
37386 - 2 2 6 2 2 6 2 2 6 2 2 6
37387 - 2 2 6 66 66 66 58 58 58 22 22 22
37388 - 6 6 6 0 0 0 0 0 0 0 0 0
37389 - 0 0 0 0 0 0 0 0 0 0 0 0
37390 - 0 0 0 0 0 0 0 0 0 0 0 0
37391 - 0 0 0 0 0 0 0 0 0 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 10 10 10
37395 - 38 38 38 78 78 78 6 6 6 2 2 6
37396 - 2 2 6 46 46 46 14 14 14 42 42 42
37397 -246 246 246 253 253 253 253 253 253 253 253 253
37398 -253 253 253 253 253 253 253 253 253 253 253 253
37399 -253 253 253 253 253 253 231 231 231 242 242 242
37400 -253 253 253 253 253 253 253 253 253 253 253 253
37401 -253 253 253 253 253 253 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 253 253 253 253 253 253
37404 -253 253 253 253 253 253 234 234 234 10 10 10
37405 - 2 2 6 2 2 6 22 22 22 14 14 14
37406 - 2 2 6 2 2 6 2 2 6 2 2 6
37407 - 2 2 6 66 66 66 62 62 62 22 22 22
37408 - 6 6 6 0 0 0 0 0 0 0 0 0
37409 - 0 0 0 0 0 0 0 0 0 0 0 0
37410 - 0 0 0 0 0 0 0 0 0 0 0 0
37411 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
37415 - 50 50 50 74 74 74 2 2 6 2 2 6
37416 - 14 14 14 70 70 70 34 34 34 62 62 62
37417 -250 250 250 253 253 253 253 253 253 253 253 253
37418 -253 253 253 253 253 253 253 253 253 253 253 253
37419 -253 253 253 253 253 253 231 231 231 246 246 246
37420 -253 253 253 253 253 253 253 253 253 253 253 253
37421 -253 253 253 253 253 253 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 253 253 253 253 253 253
37424 -253 253 253 253 253 253 234 234 234 14 14 14
37425 - 2 2 6 2 2 6 30 30 30 2 2 6
37426 - 2 2 6 2 2 6 2 2 6 2 2 6
37427 - 2 2 6 66 66 66 62 62 62 22 22 22
37428 - 6 6 6 0 0 0 0 0 0 0 0 0
37429 - 0 0 0 0 0 0 0 0 0 0 0 0
37430 - 0 0 0 0 0 0 0 0 0 0 0 0
37431 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
37435 - 54 54 54 62 62 62 2 2 6 2 2 6
37436 - 2 2 6 30 30 30 46 46 46 70 70 70
37437 -250 250 250 253 253 253 253 253 253 253 253 253
37438 -253 253 253 253 253 253 253 253 253 253 253 253
37439 -253 253 253 253 253 253 231 231 231 246 246 246
37440 -253 253 253 253 253 253 253 253 253 253 253 253
37441 -253 253 253 253 253 253 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 253 253 253 253 253 253
37444 -253 253 253 253 253 253 226 226 226 10 10 10
37445 - 2 2 6 6 6 6 30 30 30 2 2 6
37446 - 2 2 6 2 2 6 2 2 6 2 2 6
37447 - 2 2 6 66 66 66 58 58 58 22 22 22
37448 - 6 6 6 0 0 0 0 0 0 0 0 0
37449 - 0 0 0 0 0 0 0 0 0 0 0 0
37450 - 0 0 0 0 0 0 0 0 0 0 0 0
37451 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22
37455 - 58 58 58 62 62 62 2 2 6 2 2 6
37456 - 2 2 6 2 2 6 30 30 30 78 78 78
37457 -250 250 250 253 253 253 253 253 253 253 253 253
37458 -253 253 253 253 253 253 253 253 253 253 253 253
37459 -253 253 253 253 253 253 231 231 231 246 246 246
37460 -253 253 253 253 253 253 253 253 253 253 253 253
37461 -253 253 253 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 253 253 253 253 253 253
37464 -253 253 253 253 253 253 206 206 206 2 2 6
37465 - 22 22 22 34 34 34 18 14 6 22 22 22
37466 - 26 26 26 18 18 18 6 6 6 2 2 6
37467 - 2 2 6 82 82 82 54 54 54 18 18 18
37468 - 6 6 6 0 0 0 0 0 0 0 0 0
37469 - 0 0 0 0 0 0 0 0 0 0 0 0
37470 - 0 0 0 0 0 0 0 0 0 0 0 0
37471 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 26 26 26
37475 - 62 62 62 106 106 106 74 54 14 185 133 11
37476 -210 162 10 121 92 8 6 6 6 62 62 62
37477 -238 238 238 253 253 253 253 253 253 253 253 253
37478 -253 253 253 253 253 253 253 253 253 253 253 253
37479 -253 253 253 253 253 253 231 231 231 246 246 246
37480 -253 253 253 253 253 253 253 253 253 253 253 253
37481 -253 253 253 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 253 253 253 253 253 253
37484 -253 253 253 253 253 253 158 158 158 18 18 18
37485 - 14 14 14 2 2 6 2 2 6 2 2 6
37486 - 6 6 6 18 18 18 66 66 66 38 38 38
37487 - 6 6 6 94 94 94 50 50 50 18 18 18
37488 - 6 6 6 0 0 0 0 0 0 0 0 0
37489 - 0 0 0 0 0 0 0 0 0 0 0 0
37490 - 0 0 0 0 0 0 0 0 0 0 0 0
37491 - 0 0 0 0 0 0 0 0 0 0 0 0
37492 - 0 0 0 0 0 0 0 0 0 0 0 0
37493 - 0 0 0 0 0 0 0 0 0 6 6 6
37494 - 10 10 10 10 10 10 18 18 18 38 38 38
37495 - 78 78 78 142 134 106 216 158 10 242 186 14
37496 -246 190 14 246 190 14 156 118 10 10 10 10
37497 - 90 90 90 238 238 238 253 253 253 253 253 253
37498 -253 253 253 253 253 253 253 253 253 253 253 253
37499 -253 253 253 253 253 253 231 231 231 250 250 250
37500 -253 253 253 253 253 253 253 253 253 253 253 253
37501 -253 253 253 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 253 253 253 246 230 190
37504 -238 204 91 238 204 91 181 142 44 37 26 9
37505 - 2 2 6 2 2 6 2 2 6 2 2 6
37506 - 2 2 6 2 2 6 38 38 38 46 46 46
37507 - 26 26 26 106 106 106 54 54 54 18 18 18
37508 - 6 6 6 0 0 0 0 0 0 0 0 0
37509 - 0 0 0 0 0 0 0 0 0 0 0 0
37510 - 0 0 0 0 0 0 0 0 0 0 0 0
37511 - 0 0 0 0 0 0 0 0 0 0 0 0
37512 - 0 0 0 0 0 0 0 0 0 0 0 0
37513 - 0 0 0 6 6 6 14 14 14 22 22 22
37514 - 30 30 30 38 38 38 50 50 50 70 70 70
37515 -106 106 106 190 142 34 226 170 11 242 186 14
37516 -246 190 14 246 190 14 246 190 14 154 114 10
37517 - 6 6 6 74 74 74 226 226 226 253 253 253
37518 -253 253 253 253 253 253 253 253 253 253 253 253
37519 -253 253 253 253 253 253 231 231 231 250 250 250
37520 -253 253 253 253 253 253 253 253 253 253 253 253
37521 -253 253 253 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 253 253 253 228 184 62
37524 -241 196 14 241 208 19 232 195 16 38 30 10
37525 - 2 2 6 2 2 6 2 2 6 2 2 6
37526 - 2 2 6 6 6 6 30 30 30 26 26 26
37527 -203 166 17 154 142 90 66 66 66 26 26 26
37528 - 6 6 6 0 0 0 0 0 0 0 0 0
37529 - 0 0 0 0 0 0 0 0 0 0 0 0
37530 - 0 0 0 0 0 0 0 0 0 0 0 0
37531 - 0 0 0 0 0 0 0 0 0 0 0 0
37532 - 0 0 0 0 0 0 0 0 0 0 0 0
37533 - 6 6 6 18 18 18 38 38 38 58 58 58
37534 - 78 78 78 86 86 86 101 101 101 123 123 123
37535 -175 146 61 210 150 10 234 174 13 246 186 14
37536 -246 190 14 246 190 14 246 190 14 238 190 10
37537 -102 78 10 2 2 6 46 46 46 198 198 198
37538 -253 253 253 253 253 253 253 253 253 253 253 253
37539 -253 253 253 253 253 253 234 234 234 242 242 242
37540 -253 253 253 253 253 253 253 253 253 253 253 253
37541 -253 253 253 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 253 253 253 224 178 62
37544 -242 186 14 241 196 14 210 166 10 22 18 6
37545 - 2 2 6 2 2 6 2 2 6 2 2 6
37546 - 2 2 6 2 2 6 6 6 6 121 92 8
37547 -238 202 15 232 195 16 82 82 82 34 34 34
37548 - 10 10 10 0 0 0 0 0 0 0 0 0
37549 - 0 0 0 0 0 0 0 0 0 0 0 0
37550 - 0 0 0 0 0 0 0 0 0 0 0 0
37551 - 0 0 0 0 0 0 0 0 0 0 0 0
37552 - 0 0 0 0 0 0 0 0 0 0 0 0
37553 - 14 14 14 38 38 38 70 70 70 154 122 46
37554 -190 142 34 200 144 11 197 138 11 197 138 11
37555 -213 154 11 226 170 11 242 186 14 246 190 14
37556 -246 190 14 246 190 14 246 190 14 246 190 14
37557 -225 175 15 46 32 6 2 2 6 22 22 22
37558 -158 158 158 250 250 250 253 253 253 253 253 253
37559 -253 253 253 253 253 253 253 253 253 253 253 253
37560 -253 253 253 253 253 253 253 253 253 253 253 253
37561 -253 253 253 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 250 250 250 242 242 242 224 178 62
37564 -239 182 13 236 186 11 213 154 11 46 32 6
37565 - 2 2 6 2 2 6 2 2 6 2 2 6
37566 - 2 2 6 2 2 6 61 42 6 225 175 15
37567 -238 190 10 236 186 11 112 100 78 42 42 42
37568 - 14 14 14 0 0 0 0 0 0 0 0 0
37569 - 0 0 0 0 0 0 0 0 0 0 0 0
37570 - 0 0 0 0 0 0 0 0 0 0 0 0
37571 - 0 0 0 0 0 0 0 0 0 0 0 0
37572 - 0 0 0 0 0 0 0 0 0 6 6 6
37573 - 22 22 22 54 54 54 154 122 46 213 154 11
37574 -226 170 11 230 174 11 226 170 11 226 170 11
37575 -236 178 12 242 186 14 246 190 14 246 190 14
37576 -246 190 14 246 190 14 246 190 14 246 190 14
37577 -241 196 14 184 144 12 10 10 10 2 2 6
37578 - 6 6 6 116 116 116 242 242 242 253 253 253
37579 -253 253 253 253 253 253 253 253 253 253 253 253
37580 -253 253 253 253 253 253 253 253 253 253 253 253
37581 -253 253 253 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 231 231 231 198 198 198 214 170 54
37584 -236 178 12 236 178 12 210 150 10 137 92 6
37585 - 18 14 6 2 2 6 2 2 6 2 2 6
37586 - 6 6 6 70 47 6 200 144 11 236 178 12
37587 -239 182 13 239 182 13 124 112 88 58 58 58
37588 - 22 22 22 6 6 6 0 0 0 0 0 0
37589 - 0 0 0 0 0 0 0 0 0 0 0 0
37590 - 0 0 0 0 0 0 0 0 0 0 0 0
37591 - 0 0 0 0 0 0 0 0 0 0 0 0
37592 - 0 0 0 0 0 0 0 0 0 10 10 10
37593 - 30 30 30 70 70 70 180 133 36 226 170 11
37594 -239 182 13 242 186 14 242 186 14 246 186 14
37595 -246 190 14 246 190 14 246 190 14 246 190 14
37596 -246 190 14 246 190 14 246 190 14 246 190 14
37597 -246 190 14 232 195 16 98 70 6 2 2 6
37598 - 2 2 6 2 2 6 66 66 66 221 221 221
37599 -253 253 253 253 253 253 253 253 253 253 253 253
37600 -253 253 253 253 253 253 253 253 253 253 253 253
37601 -253 253 253 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 206 206 206 198 198 198 214 166 58
37604 -230 174 11 230 174 11 216 158 10 192 133 9
37605 -163 110 8 116 81 8 102 78 10 116 81 8
37606 -167 114 7 197 138 11 226 170 11 239 182 13
37607 -242 186 14 242 186 14 162 146 94 78 78 78
37608 - 34 34 34 14 14 14 6 6 6 0 0 0
37609 - 0 0 0 0 0 0 0 0 0 0 0 0
37610 - 0 0 0 0 0 0 0 0 0 0 0 0
37611 - 0 0 0 0 0 0 0 0 0 0 0 0
37612 - 0 0 0 0 0 0 0 0 0 6 6 6
37613 - 30 30 30 78 78 78 190 142 34 226 170 11
37614 -239 182 13 246 190 14 246 190 14 246 190 14
37615 -246 190 14 246 190 14 246 190 14 246 190 14
37616 -246 190 14 246 190 14 246 190 14 246 190 14
37617 -246 190 14 241 196 14 203 166 17 22 18 6
37618 - 2 2 6 2 2 6 2 2 6 38 38 38
37619 -218 218 218 253 253 253 253 253 253 253 253 253
37620 -253 253 253 253 253 253 253 253 253 253 253 253
37621 -253 253 253 253 253 253 253 253 253 253 253 253
37622 -253 253 253 253 253 253 253 253 253 253 253 253
37623 -250 250 250 206 206 206 198 198 198 202 162 69
37624 -226 170 11 236 178 12 224 166 10 210 150 10
37625 -200 144 11 197 138 11 192 133 9 197 138 11
37626 -210 150 10 226 170 11 242 186 14 246 190 14
37627 -246 190 14 246 186 14 225 175 15 124 112 88
37628 - 62 62 62 30 30 30 14 14 14 6 6 6
37629 - 0 0 0 0 0 0 0 0 0 0 0 0
37630 - 0 0 0 0 0 0 0 0 0 0 0 0
37631 - 0 0 0 0 0 0 0 0 0 0 0 0
37632 - 0 0 0 0 0 0 0 0 0 10 10 10
37633 - 30 30 30 78 78 78 174 135 50 224 166 10
37634 -239 182 13 246 190 14 246 190 14 246 190 14
37635 -246 190 14 246 190 14 246 190 14 246 190 14
37636 -246 190 14 246 190 14 246 190 14 246 190 14
37637 -246 190 14 246 190 14 241 196 14 139 102 15
37638 - 2 2 6 2 2 6 2 2 6 2 2 6
37639 - 78 78 78 250 250 250 253 253 253 253 253 253
37640 -253 253 253 253 253 253 253 253 253 253 253 253
37641 -253 253 253 253 253 253 253 253 253 253 253 253
37642 -253 253 253 253 253 253 253 253 253 253 253 253
37643 -250 250 250 214 214 214 198 198 198 190 150 46
37644 -219 162 10 236 178 12 234 174 13 224 166 10
37645 -216 158 10 213 154 11 213 154 11 216 158 10
37646 -226 170 11 239 182 13 246 190 14 246 190 14
37647 -246 190 14 246 190 14 242 186 14 206 162 42
37648 -101 101 101 58 58 58 30 30 30 14 14 14
37649 - 6 6 6 0 0 0 0 0 0 0 0 0
37650 - 0 0 0 0 0 0 0 0 0 0 0 0
37651 - 0 0 0 0 0 0 0 0 0 0 0 0
37652 - 0 0 0 0 0 0 0 0 0 10 10 10
37653 - 30 30 30 74 74 74 174 135 50 216 158 10
37654 -236 178 12 246 190 14 246 190 14 246 190 14
37655 -246 190 14 246 190 14 246 190 14 246 190 14
37656 -246 190 14 246 190 14 246 190 14 246 190 14
37657 -246 190 14 246 190 14 241 196 14 226 184 13
37658 - 61 42 6 2 2 6 2 2 6 2 2 6
37659 - 22 22 22 238 238 238 253 253 253 253 253 253
37660 -253 253 253 253 253 253 253 253 253 253 253 253
37661 -253 253 253 253 253 253 253 253 253 253 253 253
37662 -253 253 253 253 253 253 253 253 253 253 253 253
37663 -253 253 253 226 226 226 187 187 187 180 133 36
37664 -216 158 10 236 178 12 239 182 13 236 178 12
37665 -230 174 11 226 170 11 226 170 11 230 174 11
37666 -236 178 12 242 186 14 246 190 14 246 190 14
37667 -246 190 14 246 190 14 246 186 14 239 182 13
37668 -206 162 42 106 106 106 66 66 66 34 34 34
37669 - 14 14 14 6 6 6 0 0 0 0 0 0
37670 - 0 0 0 0 0 0 0 0 0 0 0 0
37671 - 0 0 0 0 0 0 0 0 0 0 0 0
37672 - 0 0 0 0 0 0 0 0 0 6 6 6
37673 - 26 26 26 70 70 70 163 133 67 213 154 11
37674 -236 178 12 246 190 14 246 190 14 246 190 14
37675 -246 190 14 246 190 14 246 190 14 246 190 14
37676 -246 190 14 246 190 14 246 190 14 246 190 14
37677 -246 190 14 246 190 14 246 190 14 241 196 14
37678 -190 146 13 18 14 6 2 2 6 2 2 6
37679 - 46 46 46 246 246 246 253 253 253 253 253 253
37680 -253 253 253 253 253 253 253 253 253 253 253 253
37681 -253 253 253 253 253 253 253 253 253 253 253 253
37682 -253 253 253 253 253 253 253 253 253 253 253 253
37683 -253 253 253 221 221 221 86 86 86 156 107 11
37684 -216 158 10 236 178 12 242 186 14 246 186 14
37685 -242 186 14 239 182 13 239 182 13 242 186 14
37686 -242 186 14 246 186 14 246 190 14 246 190 14
37687 -246 190 14 246 190 14 246 190 14 246 190 14
37688 -242 186 14 225 175 15 142 122 72 66 66 66
37689 - 30 30 30 10 10 10 0 0 0 0 0 0
37690 - 0 0 0 0 0 0 0 0 0 0 0 0
37691 - 0 0 0 0 0 0 0 0 0 0 0 0
37692 - 0 0 0 0 0 0 0 0 0 6 6 6
37693 - 26 26 26 70 70 70 163 133 67 210 150 10
37694 -236 178 12 246 190 14 246 190 14 246 190 14
37695 -246 190 14 246 190 14 246 190 14 246 190 14
37696 -246 190 14 246 190 14 246 190 14 246 190 14
37697 -246 190 14 246 190 14 246 190 14 246 190 14
37698 -232 195 16 121 92 8 34 34 34 106 106 106
37699 -221 221 221 253 253 253 253 253 253 253 253 253
37700 -253 253 253 253 253 253 253 253 253 253 253 253
37701 -253 253 253 253 253 253 253 253 253 253 253 253
37702 -253 253 253 253 253 253 253 253 253 253 253 253
37703 -242 242 242 82 82 82 18 14 6 163 110 8
37704 -216 158 10 236 178 12 242 186 14 246 190 14
37705 -246 190 14 246 190 14 246 190 14 246 190 14
37706 -246 190 14 246 190 14 246 190 14 246 190 14
37707 -246 190 14 246 190 14 246 190 14 246 190 14
37708 -246 190 14 246 190 14 242 186 14 163 133 67
37709 - 46 46 46 18 18 18 6 6 6 0 0 0
37710 - 0 0 0 0 0 0 0 0 0 0 0 0
37711 - 0 0 0 0 0 0 0 0 0 0 0 0
37712 - 0 0 0 0 0 0 0 0 0 10 10 10
37713 - 30 30 30 78 78 78 163 133 67 210 150 10
37714 -236 178 12 246 186 14 246 190 14 246 190 14
37715 -246 190 14 246 190 14 246 190 14 246 190 14
37716 -246 190 14 246 190 14 246 190 14 246 190 14
37717 -246 190 14 246 190 14 246 190 14 246 190 14
37718 -241 196 14 215 174 15 190 178 144 253 253 253
37719 -253 253 253 253 253 253 253 253 253 253 253 253
37720 -253 253 253 253 253 253 253 253 253 253 253 253
37721 -253 253 253 253 253 253 253 253 253 253 253 253
37722 -253 253 253 253 253 253 253 253 253 218 218 218
37723 - 58 58 58 2 2 6 22 18 6 167 114 7
37724 -216 158 10 236 178 12 246 186 14 246 190 14
37725 -246 190 14 246 190 14 246 190 14 246 190 14
37726 -246 190 14 246 190 14 246 190 14 246 190 14
37727 -246 190 14 246 190 14 246 190 14 246 190 14
37728 -246 190 14 246 186 14 242 186 14 190 150 46
37729 - 54 54 54 22 22 22 6 6 6 0 0 0
37730 - 0 0 0 0 0 0 0 0 0 0 0 0
37731 - 0 0 0 0 0 0 0 0 0 0 0 0
37732 - 0 0 0 0 0 0 0 0 0 14 14 14
37733 - 38 38 38 86 86 86 180 133 36 213 154 11
37734 -236 178 12 246 186 14 246 190 14 246 190 14
37735 -246 190 14 246 190 14 246 190 14 246 190 14
37736 -246 190 14 246 190 14 246 190 14 246 190 14
37737 -246 190 14 246 190 14 246 190 14 246 190 14
37738 -246 190 14 232 195 16 190 146 13 214 214 214
37739 -253 253 253 253 253 253 253 253 253 253 253 253
37740 -253 253 253 253 253 253 253 253 253 253 253 253
37741 -253 253 253 253 253 253 253 253 253 253 253 253
37742 -253 253 253 250 250 250 170 170 170 26 26 26
37743 - 2 2 6 2 2 6 37 26 9 163 110 8
37744 -219 162 10 239 182 13 246 186 14 246 190 14
37745 -246 190 14 246 190 14 246 190 14 246 190 14
37746 -246 190 14 246 190 14 246 190 14 246 190 14
37747 -246 190 14 246 190 14 246 190 14 246 190 14
37748 -246 186 14 236 178 12 224 166 10 142 122 72
37749 - 46 46 46 18 18 18 6 6 6 0 0 0
37750 - 0 0 0 0 0 0 0 0 0 0 0 0
37751 - 0 0 0 0 0 0 0 0 0 0 0 0
37752 - 0 0 0 0 0 0 6 6 6 18 18 18
37753 - 50 50 50 109 106 95 192 133 9 224 166 10
37754 -242 186 14 246 190 14 246 190 14 246 190 14
37755 -246 190 14 246 190 14 246 190 14 246 190 14
37756 -246 190 14 246 190 14 246 190 14 246 190 14
37757 -246 190 14 246 190 14 246 190 14 246 190 14
37758 -242 186 14 226 184 13 210 162 10 142 110 46
37759 -226 226 226 253 253 253 253 253 253 253 253 253
37760 -253 253 253 253 253 253 253 253 253 253 253 253
37761 -253 253 253 253 253 253 253 253 253 253 253 253
37762 -198 198 198 66 66 66 2 2 6 2 2 6
37763 - 2 2 6 2 2 6 50 34 6 156 107 11
37764 -219 162 10 239 182 13 246 186 14 246 190 14
37765 -246 190 14 246 190 14 246 190 14 246 190 14
37766 -246 190 14 246 190 14 246 190 14 246 190 14
37767 -246 190 14 246 190 14 246 190 14 242 186 14
37768 -234 174 13 213 154 11 154 122 46 66 66 66
37769 - 30 30 30 10 10 10 0 0 0 0 0 0
37770 - 0 0 0 0 0 0 0 0 0 0 0 0
37771 - 0 0 0 0 0 0 0 0 0 0 0 0
37772 - 0 0 0 0 0 0 6 6 6 22 22 22
37773 - 58 58 58 154 121 60 206 145 10 234 174 13
37774 -242 186 14 246 186 14 246 190 14 246 190 14
37775 -246 190 14 246 190 14 246 190 14 246 190 14
37776 -246 190 14 246 190 14 246 190 14 246 190 14
37777 -246 190 14 246 190 14 246 190 14 246 190 14
37778 -246 186 14 236 178 12 210 162 10 163 110 8
37779 - 61 42 6 138 138 138 218 218 218 250 250 250
37780 -253 253 253 253 253 253 253 253 253 250 250 250
37781 -242 242 242 210 210 210 144 144 144 66 66 66
37782 - 6 6 6 2 2 6 2 2 6 2 2 6
37783 - 2 2 6 2 2 6 61 42 6 163 110 8
37784 -216 158 10 236 178 12 246 190 14 246 190 14
37785 -246 190 14 246 190 14 246 190 14 246 190 14
37786 -246 190 14 246 190 14 246 190 14 246 190 14
37787 -246 190 14 239 182 13 230 174 11 216 158 10
37788 -190 142 34 124 112 88 70 70 70 38 38 38
37789 - 18 18 18 6 6 6 0 0 0 0 0 0
37790 - 0 0 0 0 0 0 0 0 0 0 0 0
37791 - 0 0 0 0 0 0 0 0 0 0 0 0
37792 - 0 0 0 0 0 0 6 6 6 22 22 22
37793 - 62 62 62 168 124 44 206 145 10 224 166 10
37794 -236 178 12 239 182 13 242 186 14 242 186 14
37795 -246 186 14 246 190 14 246 190 14 246 190 14
37796 -246 190 14 246 190 14 246 190 14 246 190 14
37797 -246 190 14 246 190 14 246 190 14 246 190 14
37798 -246 190 14 236 178 12 216 158 10 175 118 6
37799 - 80 54 7 2 2 6 6 6 6 30 30 30
37800 - 54 54 54 62 62 62 50 50 50 38 38 38
37801 - 14 14 14 2 2 6 2 2 6 2 2 6
37802 - 2 2 6 2 2 6 2 2 6 2 2 6
37803 - 2 2 6 6 6 6 80 54 7 167 114 7
37804 -213 154 11 236 178 12 246 190 14 246 190 14
37805 -246 190 14 246 190 14 246 190 14 246 190 14
37806 -246 190 14 242 186 14 239 182 13 239 182 13
37807 -230 174 11 210 150 10 174 135 50 124 112 88
37808 - 82 82 82 54 54 54 34 34 34 18 18 18
37809 - 6 6 6 0 0 0 0 0 0 0 0 0
37810 - 0 0 0 0 0 0 0 0 0 0 0 0
37811 - 0 0 0 0 0 0 0 0 0 0 0 0
37812 - 0 0 0 0 0 0 6 6 6 18 18 18
37813 - 50 50 50 158 118 36 192 133 9 200 144 11
37814 -216 158 10 219 162 10 224 166 10 226 170 11
37815 -230 174 11 236 178 12 239 182 13 239 182 13
37816 -242 186 14 246 186 14 246 190 14 246 190 14
37817 -246 190 14 246 190 14 246 190 14 246 190 14
37818 -246 186 14 230 174 11 210 150 10 163 110 8
37819 -104 69 6 10 10 10 2 2 6 2 2 6
37820 - 2 2 6 2 2 6 2 2 6 2 2 6
37821 - 2 2 6 2 2 6 2 2 6 2 2 6
37822 - 2 2 6 2 2 6 2 2 6 2 2 6
37823 - 2 2 6 6 6 6 91 60 6 167 114 7
37824 -206 145 10 230 174 11 242 186 14 246 190 14
37825 -246 190 14 246 190 14 246 186 14 242 186 14
37826 -239 182 13 230 174 11 224 166 10 213 154 11
37827 -180 133 36 124 112 88 86 86 86 58 58 58
37828 - 38 38 38 22 22 22 10 10 10 6 6 6
37829 - 0 0 0 0 0 0 0 0 0 0 0 0
37830 - 0 0 0 0 0 0 0 0 0 0 0 0
37831 - 0 0 0 0 0 0 0 0 0 0 0 0
37832 - 0 0 0 0 0 0 0 0 0 14 14 14
37833 - 34 34 34 70 70 70 138 110 50 158 118 36
37834 -167 114 7 180 123 7 192 133 9 197 138 11
37835 -200 144 11 206 145 10 213 154 11 219 162 10
37836 -224 166 10 230 174 11 239 182 13 242 186 14
37837 -246 186 14 246 186 14 246 186 14 246 186 14
37838 -239 182 13 216 158 10 185 133 11 152 99 6
37839 -104 69 6 18 14 6 2 2 6 2 2 6
37840 - 2 2 6 2 2 6 2 2 6 2 2 6
37841 - 2 2 6 2 2 6 2 2 6 2 2 6
37842 - 2 2 6 2 2 6 2 2 6 2 2 6
37843 - 2 2 6 6 6 6 80 54 7 152 99 6
37844 -192 133 9 219 162 10 236 178 12 239 182 13
37845 -246 186 14 242 186 14 239 182 13 236 178 12
37846 -224 166 10 206 145 10 192 133 9 154 121 60
37847 - 94 94 94 62 62 62 42 42 42 22 22 22
37848 - 14 14 14 6 6 6 0 0 0 0 0 0
37849 - 0 0 0 0 0 0 0 0 0 0 0 0
37850 - 0 0 0 0 0 0 0 0 0 0 0 0
37851 - 0 0 0 0 0 0 0 0 0 0 0 0
37852 - 0 0 0 0 0 0 0 0 0 6 6 6
37853 - 18 18 18 34 34 34 58 58 58 78 78 78
37854 -101 98 89 124 112 88 142 110 46 156 107 11
37855 -163 110 8 167 114 7 175 118 6 180 123 7
37856 -185 133 11 197 138 11 210 150 10 219 162 10
37857 -226 170 11 236 178 12 236 178 12 234 174 13
37858 -219 162 10 197 138 11 163 110 8 130 83 6
37859 - 91 60 6 10 10 10 2 2 6 2 2 6
37860 - 18 18 18 38 38 38 38 38 38 38 38 38
37861 - 38 38 38 38 38 38 38 38 38 38 38 38
37862 - 38 38 38 38 38 38 26 26 26 2 2 6
37863 - 2 2 6 6 6 6 70 47 6 137 92 6
37864 -175 118 6 200 144 11 219 162 10 230 174 11
37865 -234 174 13 230 174 11 219 162 10 210 150 10
37866 -192 133 9 163 110 8 124 112 88 82 82 82
37867 - 50 50 50 30 30 30 14 14 14 6 6 6
37868 - 0 0 0 0 0 0 0 0 0 0 0 0
37869 - 0 0 0 0 0 0 0 0 0 0 0 0
37870 - 0 0 0 0 0 0 0 0 0 0 0 0
37871 - 0 0 0 0 0 0 0 0 0 0 0 0
37872 - 0 0 0 0 0 0 0 0 0 0 0 0
37873 - 6 6 6 14 14 14 22 22 22 34 34 34
37874 - 42 42 42 58 58 58 74 74 74 86 86 86
37875 -101 98 89 122 102 70 130 98 46 121 87 25
37876 -137 92 6 152 99 6 163 110 8 180 123 7
37877 -185 133 11 197 138 11 206 145 10 200 144 11
37878 -180 123 7 156 107 11 130 83 6 104 69 6
37879 - 50 34 6 54 54 54 110 110 110 101 98 89
37880 - 86 86 86 82 82 82 78 78 78 78 78 78
37881 - 78 78 78 78 78 78 78 78 78 78 78 78
37882 - 78 78 78 82 82 82 86 86 86 94 94 94
37883 -106 106 106 101 101 101 86 66 34 124 80 6
37884 -156 107 11 180 123 7 192 133 9 200 144 11
37885 -206 145 10 200 144 11 192 133 9 175 118 6
37886 -139 102 15 109 106 95 70 70 70 42 42 42
37887 - 22 22 22 10 10 10 0 0 0 0 0 0
37888 - 0 0 0 0 0 0 0 0 0 0 0 0
37889 - 0 0 0 0 0 0 0 0 0 0 0 0
37890 - 0 0 0 0 0 0 0 0 0 0 0 0
37891 - 0 0 0 0 0 0 0 0 0 0 0 0
37892 - 0 0 0 0 0 0 0 0 0 0 0 0
37893 - 0 0 0 0 0 0 6 6 6 10 10 10
37894 - 14 14 14 22 22 22 30 30 30 38 38 38
37895 - 50 50 50 62 62 62 74 74 74 90 90 90
37896 -101 98 89 112 100 78 121 87 25 124 80 6
37897 -137 92 6 152 99 6 152 99 6 152 99 6
37898 -138 86 6 124 80 6 98 70 6 86 66 30
37899 -101 98 89 82 82 82 58 58 58 46 46 46
37900 - 38 38 38 34 34 34 34 34 34 34 34 34
37901 - 34 34 34 34 34 34 34 34 34 34 34 34
37902 - 34 34 34 34 34 34 38 38 38 42 42 42
37903 - 54 54 54 82 82 82 94 86 76 91 60 6
37904 -134 86 6 156 107 11 167 114 7 175 118 6
37905 -175 118 6 167 114 7 152 99 6 121 87 25
37906 -101 98 89 62 62 62 34 34 34 18 18 18
37907 - 6 6 6 0 0 0 0 0 0 0 0 0
37908 - 0 0 0 0 0 0 0 0 0 0 0 0
37909 - 0 0 0 0 0 0 0 0 0 0 0 0
37910 - 0 0 0 0 0 0 0 0 0 0 0 0
37911 - 0 0 0 0 0 0 0 0 0 0 0 0
37912 - 0 0 0 0 0 0 0 0 0 0 0 0
37913 - 0 0 0 0 0 0 0 0 0 0 0 0
37914 - 0 0 0 6 6 6 6 6 6 10 10 10
37915 - 18 18 18 22 22 22 30 30 30 42 42 42
37916 - 50 50 50 66 66 66 86 86 86 101 98 89
37917 -106 86 58 98 70 6 104 69 6 104 69 6
37918 -104 69 6 91 60 6 82 62 34 90 90 90
37919 - 62 62 62 38 38 38 22 22 22 14 14 14
37920 - 10 10 10 10 10 10 10 10 10 10 10 10
37921 - 10 10 10 10 10 10 6 6 6 10 10 10
37922 - 10 10 10 10 10 10 10 10 10 14 14 14
37923 - 22 22 22 42 42 42 70 70 70 89 81 66
37924 - 80 54 7 104 69 6 124 80 6 137 92 6
37925 -134 86 6 116 81 8 100 82 52 86 86 86
37926 - 58 58 58 30 30 30 14 14 14 6 6 6
37927 - 0 0 0 0 0 0 0 0 0 0 0 0
37928 - 0 0 0 0 0 0 0 0 0 0 0 0
37929 - 0 0 0 0 0 0 0 0 0 0 0 0
37930 - 0 0 0 0 0 0 0 0 0 0 0 0
37931 - 0 0 0 0 0 0 0 0 0 0 0 0
37932 - 0 0 0 0 0 0 0 0 0 0 0 0
37933 - 0 0 0 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 6 6 6 10 10 10 14 14 14
37936 - 18 18 18 26 26 26 38 38 38 54 54 54
37937 - 70 70 70 86 86 86 94 86 76 89 81 66
37938 - 89 81 66 86 86 86 74 74 74 50 50 50
37939 - 30 30 30 14 14 14 6 6 6 0 0 0
37940 - 0 0 0 0 0 0 0 0 0 0 0 0
37941 - 0 0 0 0 0 0 0 0 0 0 0 0
37942 - 0 0 0 0 0 0 0 0 0 0 0 0
37943 - 6 6 6 18 18 18 34 34 34 58 58 58
37944 - 82 82 82 89 81 66 89 81 66 89 81 66
37945 - 94 86 66 94 86 76 74 74 74 50 50 50
37946 - 26 26 26 14 14 14 6 6 6 0 0 0
37947 - 0 0 0 0 0 0 0 0 0 0 0 0
37948 - 0 0 0 0 0 0 0 0 0 0 0 0
37949 - 0 0 0 0 0 0 0 0 0 0 0 0
37950 - 0 0 0 0 0 0 0 0 0 0 0 0
37951 - 0 0 0 0 0 0 0 0 0 0 0 0
37952 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 6 6 6 14 14 14 18 18 18
37957 - 30 30 30 38 38 38 46 46 46 54 54 54
37958 - 50 50 50 42 42 42 30 30 30 18 18 18
37959 - 10 10 10 0 0 0 0 0 0 0 0 0
37960 - 0 0 0 0 0 0 0 0 0 0 0 0
37961 - 0 0 0 0 0 0 0 0 0 0 0 0
37962 - 0 0 0 0 0 0 0 0 0 0 0 0
37963 - 0 0 0 6 6 6 14 14 14 26 26 26
37964 - 38 38 38 50 50 50 58 58 58 58 58 58
37965 - 54 54 54 42 42 42 30 30 30 18 18 18
37966 - 10 10 10 0 0 0 0 0 0 0 0 0
37967 - 0 0 0 0 0 0 0 0 0 0 0 0
37968 - 0 0 0 0 0 0 0 0 0 0 0 0
37969 - 0 0 0 0 0 0 0 0 0 0 0 0
37970 - 0 0 0 0 0 0 0 0 0 0 0 0
37971 - 0 0 0 0 0 0 0 0 0 0 0 0
37972 - 0 0 0 0 0 0 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 - 6 6 6 10 10 10 14 14 14 18 18 18
37978 - 18 18 18 14 14 14 10 10 10 6 6 6
37979 - 0 0 0 0 0 0 0 0 0 0 0 0
37980 - 0 0 0 0 0 0 0 0 0 0 0 0
37981 - 0 0 0 0 0 0 0 0 0 0 0 0
37982 - 0 0 0 0 0 0 0 0 0 0 0 0
37983 - 0 0 0 0 0 0 0 0 0 6 6 6
37984 - 14 14 14 18 18 18 22 22 22 22 22 22
37985 - 18 18 18 14 14 14 10 10 10 6 6 6
37986 - 0 0 0 0 0 0 0 0 0 0 0 0
37987 - 0 0 0 0 0 0 0 0 0 0 0 0
37988 - 0 0 0 0 0 0 0 0 0 0 0 0
37989 - 0 0 0 0 0 0 0 0 0 0 0 0
37990 - 0 0 0 0 0 0 0 0 0 0 0 0
37991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
37992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
37993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
37994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
37995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
37996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
37997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
37998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
37999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38004 +4 4 4 4 4 4
38005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38018 +4 4 4 4 4 4
38019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38032 +4 4 4 4 4 4
38033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38046 +4 4 4 4 4 4
38047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38060 +4 4 4 4 4 4
38061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38074 +4 4 4 4 4 4
38075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38079 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
38080 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
38081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38084 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
38085 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38086 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
38087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38088 +4 4 4 4 4 4
38089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38093 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
38094 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
38095 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38098 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
38099 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
38100 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
38101 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38102 +4 4 4 4 4 4
38103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38107 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
38108 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
38109 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38112 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
38113 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
38114 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
38115 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
38116 +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 5 5 5 5 5 5 2 2 2 0 0 0
38121 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
38122 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
38123 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
38126 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
38127 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
38128 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
38129 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
38130 +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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
38135 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
38136 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
38137 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
38138 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
38139 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
38140 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
38141 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
38142 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
38143 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
38144 +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 5 5 5
38148 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
38149 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
38150 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
38151 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
38152 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
38153 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
38154 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
38155 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
38156 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
38157 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
38158 +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 5 5 5 3 3 3
38162 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
38163 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
38164 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
38165 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
38166 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
38167 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
38168 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
38169 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
38170 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
38171 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
38172 +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 2 2 2 0 0 0 4 0 0
38176 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
38177 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
38178 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
38179 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
38180 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
38181 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
38182 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
38183 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
38184 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
38185 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
38186 +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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
38190 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
38191 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
38192 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
38193 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
38194 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
38195 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
38196 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
38197 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
38198 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
38199 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38200 +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 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
38204 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
38205 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
38206 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
38207 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
38208 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
38209 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
38210 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
38211 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
38212 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
38213 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
38214 +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 3 3 3 0 0 0
38217 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
38218 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
38219 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
38220 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
38221 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
38222 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
38223 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
38224 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
38225 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
38226 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
38227 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
38228 +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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
38231 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
38232 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
38233 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
38234 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
38235 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
38236 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
38237 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
38238 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
38239 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
38240 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
38241 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
38242 +0 0 0 4 4 4
38243 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
38244 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
38245 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
38246 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
38247 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
38248 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
38249 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
38250 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
38251 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
38252 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
38253 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
38254 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
38255 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
38256 +2 0 0 0 0 0
38257 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
38258 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
38259 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
38260 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
38261 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
38262 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
38263 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
38264 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
38265 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
38266 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
38267 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
38268 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
38269 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
38270 +37 38 37 0 0 0
38271 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
38272 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
38273 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
38274 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
38275 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
38276 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
38277 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
38278 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
38279 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
38280 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
38281 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
38282 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
38283 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
38284 +85 115 134 4 0 0
38285 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
38286 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
38287 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
38288 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
38289 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
38290 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
38291 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
38292 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
38293 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
38294 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
38295 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
38296 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
38297 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
38298 +60 73 81 4 0 0
38299 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
38300 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
38301 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
38302 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
38303 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
38304 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
38305 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
38306 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
38307 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
38308 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
38309 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
38310 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
38311 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
38312 +16 19 21 4 0 0
38313 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
38314 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
38315 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
38316 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
38317 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
38318 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
38319 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
38320 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
38321 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
38322 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
38323 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
38324 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
38325 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
38326 +4 0 0 4 3 3
38327 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
38328 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
38329 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
38330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
38331 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
38332 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
38333 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
38334 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
38335 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
38336 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
38337 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
38338 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
38339 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
38340 +3 2 2 4 4 4
38341 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
38342 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
38343 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
38344 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
38345 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
38346 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
38347 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
38348 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
38349 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
38350 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
38351 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
38352 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
38353 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
38354 +4 4 4 4 4 4
38355 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
38356 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
38357 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
38358 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
38359 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
38360 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
38361 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
38362 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
38363 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
38364 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
38365 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
38366 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
38367 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
38368 +4 4 4 4 4 4
38369 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
38370 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
38371 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
38372 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
38373 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
38374 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
38375 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
38376 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
38377 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
38378 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
38379 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
38380 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
38381 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
38382 +5 5 5 5 5 5
38383 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
38384 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
38385 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
38386 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
38387 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
38388 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38389 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
38390 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
38391 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
38392 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
38393 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
38394 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
38395 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
38396 +5 5 5 4 4 4
38397 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
38398 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
38399 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
38400 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
38401 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38402 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
38403 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
38404 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
38405 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
38406 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
38407 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
38408 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
38409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38410 +4 4 4 4 4 4
38411 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
38412 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
38413 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
38414 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
38415 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
38416 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38417 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38418 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
38419 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
38420 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
38421 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
38422 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
38423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38424 +4 4 4 4 4 4
38425 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
38426 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
38427 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
38428 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
38429 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38430 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
38431 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
38432 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
38433 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
38434 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
38435 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
38436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38438 +4 4 4 4 4 4
38439 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
38440 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
38441 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
38442 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
38443 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38444 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38445 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38446 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
38447 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
38448 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
38449 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
38450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38452 +4 4 4 4 4 4
38453 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
38454 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
38455 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
38456 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
38457 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38458 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
38459 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
38460 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
38461 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
38462 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
38463 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38466 +4 4 4 4 4 4
38467 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
38468 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
38469 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
38470 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
38471 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38472 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
38473 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
38474 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
38475 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
38476 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
38477 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
38478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38480 +4 4 4 4 4 4
38481 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
38482 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
38483 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
38484 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
38485 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38486 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
38487 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
38488 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
38489 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
38490 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
38491 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
38492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38494 +4 4 4 4 4 4
38495 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
38496 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
38497 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
38498 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
38499 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
38500 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
38501 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
38502 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
38503 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
38504 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
38505 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38508 +4 4 4 4 4 4
38509 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
38510 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
38511 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
38512 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
38513 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38514 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
38515 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
38516 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
38517 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
38518 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
38519 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38522 +4 4 4 4 4 4
38523 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
38524 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
38525 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
38526 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
38527 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38528 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
38529 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
38530 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
38531 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
38532 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
38533 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38536 +4 4 4 4 4 4
38537 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
38538 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
38539 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
38540 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
38541 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38542 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
38543 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
38544 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
38545 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
38546 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38547 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38550 +4 4 4 4 4 4
38551 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
38552 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
38553 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
38554 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
38555 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
38556 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
38557 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
38558 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
38559 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38560 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38561 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38564 +4 4 4 4 4 4
38565 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
38566 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
38567 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
38568 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
38569 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38570 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
38571 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
38572 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
38573 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38574 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38575 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38578 +4 4 4 4 4 4
38579 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
38580 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
38581 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
38582 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
38583 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
38584 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
38585 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
38586 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
38587 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38588 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38589 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38592 +4 4 4 4 4 4
38593 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
38594 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
38595 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38596 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
38597 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
38598 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
38599 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
38600 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
38601 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
38602 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38603 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38606 +4 4 4 4 4 4
38607 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
38608 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
38609 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
38610 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
38611 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
38612 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
38613 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
38614 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
38615 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38616 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38617 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38620 +4 4 4 4 4 4
38621 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
38622 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
38623 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38624 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
38625 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
38626 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
38627 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
38628 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
38629 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
38630 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38631 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38634 +4 4 4 4 4 4
38635 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
38636 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
38637 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
38638 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
38639 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
38640 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
38641 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
38642 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
38643 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38644 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38645 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38648 +4 4 4 4 4 4
38649 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38650 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
38651 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38652 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
38653 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
38654 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
38655 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
38656 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
38657 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38658 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38659 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38662 +4 4 4 4 4 4
38663 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
38664 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
38665 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
38666 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
38667 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
38668 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
38669 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38670 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
38671 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38672 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38673 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38676 +4 4 4 4 4 4
38677 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38678 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
38679 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
38680 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
38681 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
38682 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
38683 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38684 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
38685 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38686 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38687 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38690 +4 4 4 4 4 4
38691 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
38692 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
38693 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
38694 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
38695 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
38696 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
38697 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
38698 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
38699 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
38700 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38701 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38704 +4 4 4 4 4 4
38705 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38706 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
38707 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
38708 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
38709 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
38710 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
38711 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
38712 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
38713 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
38714 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38715 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38718 +4 4 4 4 4 4
38719 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
38720 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
38721 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
38722 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
38723 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
38724 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
38725 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
38726 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
38727 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
38728 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38729 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38732 +4 4 4 4 4 4
38733 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38734 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
38735 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
38736 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
38737 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
38738 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
38739 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
38740 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
38741 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
38742 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38743 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38746 +4 4 4 4 4 4
38747 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
38748 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
38749 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
38750 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
38751 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
38752 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
38753 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
38754 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
38755 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
38756 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
38757 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38760 +4 4 4 4 4 4
38761 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
38762 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
38763 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
38764 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
38765 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
38766 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
38767 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
38768 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
38769 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
38770 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
38771 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38774 +4 4 4 4 4 4
38775 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
38776 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
38777 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
38778 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
38779 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
38780 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
38781 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38782 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
38783 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
38784 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
38785 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
38786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38788 +4 4 4 4 4 4
38789 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
38790 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
38791 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
38792 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
38793 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
38794 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
38795 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
38796 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
38797 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
38798 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
38799 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38802 +4 4 4 4 4 4
38803 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
38804 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
38805 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
38806 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
38807 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
38808 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
38809 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
38810 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
38811 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
38812 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
38815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38816 +4 4 4 4 4 4
38817 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
38818 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
38819 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
38820 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
38821 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
38822 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
38823 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
38824 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
38825 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
38826 +13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
38829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38830 +4 4 4 4 4 4
38831 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
38832 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
38833 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
38834 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
38835 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
38836 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
38837 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
38838 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
38839 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
38840 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
38843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38844 +4 4 4 4 4 4
38845 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
38846 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
38847 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
38848 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
38849 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
38850 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
38851 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
38852 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
38853 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
38854 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
38857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38858 +4 4 4 4 4 4
38859 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
38860 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
38861 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
38862 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
38863 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
38864 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
38865 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
38866 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
38867 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
38871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38872 +4 4 4 4 4 4
38873 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
38874 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
38875 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
38876 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
38877 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
38878 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
38879 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
38880 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
38881 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
38885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38886 +4 4 4 4 4 4
38887 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
38888 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
38889 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
38890 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
38891 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
38892 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
38893 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
38894 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
38895 +4 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 4 4 4 4 4 4 4 4 4 4 4 4
38899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38900 +4 4 4 4 4 4
38901 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
38902 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
38903 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
38904 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
38905 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
38906 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
38907 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
38908 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
38909 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
38913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38914 +4 4 4 4 4 4
38915 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
38916 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
38917 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
38918 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
38919 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
38920 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
38921 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
38922 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
38923 +4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
38927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38928 +4 4 4 4 4 4
38929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
38930 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
38931 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
38932 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
38933 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
38934 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
38935 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
38936 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
38941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38942 +4 4 4 4 4 4
38943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38944 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
38945 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
38946 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
38947 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
38948 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
38949 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
38950 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
38955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38956 +4 4 4 4 4 4
38957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38958 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
38959 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
38960 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
38961 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
38962 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
38963 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
38964 +5 5 5 5 5 5 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
38969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38970 +4 4 4 4 4 4
38971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38973 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
38974 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
38975 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
38976 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
38977 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
38983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38984 +4 4 4 4 4 4
38985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
38988 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
38989 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
38990 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
38991 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
38997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38998 +4 4 4 4 4 4
38999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39002 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
39003 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
39004 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
39005 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
39011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39012 +4 4 4 4 4 4
39013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39016 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
39017 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
39018 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
39019 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
39025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39026 +4 4 4 4 4 4
39027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39030 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
39031 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
39032 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
39033 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
39039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39040 +4 4 4 4 4 4
39041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39045 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
39046 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
39047 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
39053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39054 +4 4 4 4 4 4
39055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39059 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
39060 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
39061 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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 4 4 4
39069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39073 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
39074 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
39075 +5 5 5 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 4 4 4 4 4 4 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
39083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39087 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
39088 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 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
39097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39101 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
39102 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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
39111 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
39112 index 3473e75..c930142 100644
39113 --- a/drivers/video/udlfb.c
39114 +++ b/drivers/video/udlfb.c
39115 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
39116 dlfb_urb_completion(urb);
39117
39118 error:
39119 - atomic_add(bytes_sent, &dev->bytes_sent);
39120 - atomic_add(bytes_identical, &dev->bytes_identical);
39121 - atomic_add(width*height*2, &dev->bytes_rendered);
39122 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
39123 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
39124 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
39125 end_cycles = get_cycles();
39126 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
39127 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
39128 >> 10)), /* Kcycles */
39129 &dev->cpu_kcycles_used);
39130
39131 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
39132 dlfb_urb_completion(urb);
39133
39134 error:
39135 - atomic_add(bytes_sent, &dev->bytes_sent);
39136 - atomic_add(bytes_identical, &dev->bytes_identical);
39137 - atomic_add(bytes_rendered, &dev->bytes_rendered);
39138 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
39139 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
39140 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
39141 end_cycles = get_cycles();
39142 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
39143 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
39144 >> 10)), /* Kcycles */
39145 &dev->cpu_kcycles_used);
39146 }
39147 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
39148 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39149 struct dlfb_data *dev = fb_info->par;
39150 return snprintf(buf, PAGE_SIZE, "%u\n",
39151 - atomic_read(&dev->bytes_rendered));
39152 + atomic_read_unchecked(&dev->bytes_rendered));
39153 }
39154
39155 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
39156 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
39157 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39158 struct dlfb_data *dev = fb_info->par;
39159 return snprintf(buf, PAGE_SIZE, "%u\n",
39160 - atomic_read(&dev->bytes_identical));
39161 + atomic_read_unchecked(&dev->bytes_identical));
39162 }
39163
39164 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
39165 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
39166 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39167 struct dlfb_data *dev = fb_info->par;
39168 return snprintf(buf, PAGE_SIZE, "%u\n",
39169 - atomic_read(&dev->bytes_sent));
39170 + atomic_read_unchecked(&dev->bytes_sent));
39171 }
39172
39173 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
39174 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
39175 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39176 struct dlfb_data *dev = fb_info->par;
39177 return snprintf(buf, PAGE_SIZE, "%u\n",
39178 - atomic_read(&dev->cpu_kcycles_used));
39179 + atomic_read_unchecked(&dev->cpu_kcycles_used));
39180 }
39181
39182 static ssize_t edid_show(
39183 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
39184 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39185 struct dlfb_data *dev = fb_info->par;
39186
39187 - atomic_set(&dev->bytes_rendered, 0);
39188 - atomic_set(&dev->bytes_identical, 0);
39189 - atomic_set(&dev->bytes_sent, 0);
39190 - atomic_set(&dev->cpu_kcycles_used, 0);
39191 + atomic_set_unchecked(&dev->bytes_rendered, 0);
39192 + atomic_set_unchecked(&dev->bytes_identical, 0);
39193 + atomic_set_unchecked(&dev->bytes_sent, 0);
39194 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
39195
39196 return count;
39197 }
39198 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
39199 index 7f8472c..9842e87 100644
39200 --- a/drivers/video/uvesafb.c
39201 +++ b/drivers/video/uvesafb.c
39202 @@ -19,6 +19,7 @@
39203 #include <linux/io.h>
39204 #include <linux/mutex.h>
39205 #include <linux/slab.h>
39206 +#include <linux/moduleloader.h>
39207 #include <video/edid.h>
39208 #include <video/uvesafb.h>
39209 #ifdef CONFIG_X86
39210 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
39211 NULL,
39212 };
39213
39214 - return call_usermodehelper(v86d_path, argv, envp, 1);
39215 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
39216 }
39217
39218 /*
39219 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
39220 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
39221 par->pmi_setpal = par->ypan = 0;
39222 } else {
39223 +
39224 +#ifdef CONFIG_PAX_KERNEXEC
39225 +#ifdef CONFIG_MODULES
39226 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
39227 +#endif
39228 + if (!par->pmi_code) {
39229 + par->pmi_setpal = par->ypan = 0;
39230 + return 0;
39231 + }
39232 +#endif
39233 +
39234 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
39235 + task->t.regs.edi);
39236 +
39237 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39238 + pax_open_kernel();
39239 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
39240 + pax_close_kernel();
39241 +
39242 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
39243 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
39244 +#else
39245 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
39246 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
39247 +#endif
39248 +
39249 printk(KERN_INFO "uvesafb: protected mode interface info at "
39250 "%04x:%04x\n",
39251 (u16)task->t.regs.es, (u16)task->t.regs.edi);
39252 @@ -1821,6 +1844,11 @@ out:
39253 if (par->vbe_modes)
39254 kfree(par->vbe_modes);
39255
39256 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39257 + if (par->pmi_code)
39258 + module_free_exec(NULL, par->pmi_code);
39259 +#endif
39260 +
39261 framebuffer_release(info);
39262 return err;
39263 }
39264 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
39265 kfree(par->vbe_state_orig);
39266 if (par->vbe_state_saved)
39267 kfree(par->vbe_state_saved);
39268 +
39269 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39270 + if (par->pmi_code)
39271 + module_free_exec(NULL, par->pmi_code);
39272 +#endif
39273 +
39274 }
39275
39276 framebuffer_release(info);
39277 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
39278 index 501b340..86bd4cf 100644
39279 --- a/drivers/video/vesafb.c
39280 +++ b/drivers/video/vesafb.c
39281 @@ -9,6 +9,7 @@
39282 */
39283
39284 #include <linux/module.h>
39285 +#include <linux/moduleloader.h>
39286 #include <linux/kernel.h>
39287 #include <linux/errno.h>
39288 #include <linux/string.h>
39289 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
39290 static int vram_total __initdata; /* Set total amount of memory */
39291 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
39292 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
39293 -static void (*pmi_start)(void) __read_mostly;
39294 -static void (*pmi_pal) (void) __read_mostly;
39295 +static void (*pmi_start)(void) __read_only;
39296 +static void (*pmi_pal) (void) __read_only;
39297 static int depth __read_mostly;
39298 static int vga_compat __read_mostly;
39299 /* --------------------------------------------------------------------- */
39300 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
39301 unsigned int size_vmode;
39302 unsigned int size_remap;
39303 unsigned int size_total;
39304 + void *pmi_code = NULL;
39305
39306 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
39307 return -ENODEV;
39308 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
39309 size_remap = size_total;
39310 vesafb_fix.smem_len = size_remap;
39311
39312 -#ifndef __i386__
39313 - screen_info.vesapm_seg = 0;
39314 -#endif
39315 -
39316 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
39317 printk(KERN_WARNING
39318 "vesafb: cannot reserve video memory at 0x%lx\n",
39319 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
39320 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
39321 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
39322
39323 +#ifdef __i386__
39324 +
39325 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39326 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
39327 + if (!pmi_code)
39328 +#elif !defined(CONFIG_PAX_KERNEXEC)
39329 + if (0)
39330 +#endif
39331 +
39332 +#endif
39333 + screen_info.vesapm_seg = 0;
39334 +
39335 if (screen_info.vesapm_seg) {
39336 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
39337 - screen_info.vesapm_seg,screen_info.vesapm_off);
39338 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
39339 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
39340 }
39341
39342 if (screen_info.vesapm_seg < 0xc000)
39343 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
39344
39345 if (ypan || pmi_setpal) {
39346 unsigned short *pmi_base;
39347 +
39348 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
39349 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
39350 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
39351 +
39352 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39353 + pax_open_kernel();
39354 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
39355 +#else
39356 + pmi_code = pmi_base;
39357 +#endif
39358 +
39359 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
39360 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
39361 +
39362 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39363 + pmi_start = ktva_ktla(pmi_start);
39364 + pmi_pal = ktva_ktla(pmi_pal);
39365 + pax_close_kernel();
39366 +#endif
39367 +
39368 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
39369 if (pmi_base[3]) {
39370 printk(KERN_INFO "vesafb: pmi: ports = ");
39371 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
39372 info->node, info->fix.id);
39373 return 0;
39374 err:
39375 +
39376 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39377 + module_free_exec(NULL, pmi_code);
39378 +#endif
39379 +
39380 if (info->screen_base)
39381 iounmap(info->screen_base);
39382 framebuffer_release(info);
39383 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
39384 index 88714ae..16c2e11 100644
39385 --- a/drivers/video/via/via_clock.h
39386 +++ b/drivers/video/via/via_clock.h
39387 @@ -56,7 +56,7 @@ struct via_clock {
39388
39389 void (*set_engine_pll_state)(u8 state);
39390 void (*set_engine_pll)(struct via_pll_config config);
39391 -};
39392 +} __no_const;
39393
39394
39395 static inline u32 get_pll_internal_frequency(u32 ref_freq,
39396 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
39397 index e56c934..fc22f4b 100644
39398 --- a/drivers/xen/xen-pciback/conf_space.h
39399 +++ b/drivers/xen/xen-pciback/conf_space.h
39400 @@ -44,15 +44,15 @@ struct config_field {
39401 struct {
39402 conf_dword_write write;
39403 conf_dword_read read;
39404 - } dw;
39405 + } __no_const dw;
39406 struct {
39407 conf_word_write write;
39408 conf_word_read read;
39409 - } w;
39410 + } __no_const w;
39411 struct {
39412 conf_byte_write write;
39413 conf_byte_read read;
39414 - } b;
39415 + } __no_const b;
39416 } u;
39417 struct list_head list;
39418 };
39419 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
39420 index 879ed88..bc03a01 100644
39421 --- a/fs/9p/vfs_inode.c
39422 +++ b/fs/9p/vfs_inode.c
39423 @@ -1286,7 +1286,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
39424 void
39425 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
39426 {
39427 - char *s = nd_get_link(nd);
39428 + const char *s = nd_get_link(nd);
39429
39430 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
39431 IS_ERR(s) ? "<error>" : s);
39432 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
39433 index 79e2ca7..5828ad1 100644
39434 --- a/fs/Kconfig.binfmt
39435 +++ b/fs/Kconfig.binfmt
39436 @@ -86,7 +86,7 @@ config HAVE_AOUT
39437
39438 config BINFMT_AOUT
39439 tristate "Kernel support for a.out and ECOFF binaries"
39440 - depends on HAVE_AOUT
39441 + depends on HAVE_AOUT && BROKEN
39442 ---help---
39443 A.out (Assembler.OUTput) is a set of formats for libraries and
39444 executables used in the earliest versions of UNIX. Linux used
39445 diff --git a/fs/aio.c b/fs/aio.c
39446 index 969beb0..09fab51 100644
39447 --- a/fs/aio.c
39448 +++ b/fs/aio.c
39449 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
39450 size += sizeof(struct io_event) * nr_events;
39451 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
39452
39453 - if (nr_pages < 0)
39454 + if (nr_pages <= 0)
39455 return -EINVAL;
39456
39457 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
39458 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
39459 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
39460 {
39461 ssize_t ret;
39462 + struct iovec iovstack;
39463
39464 #ifdef CONFIG_COMPAT
39465 if (compat)
39466 ret = compat_rw_copy_check_uvector(type,
39467 (struct compat_iovec __user *)kiocb->ki_buf,
39468 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
39469 + kiocb->ki_nbytes, 1, &iovstack,
39470 &kiocb->ki_iovec, 1);
39471 else
39472 #endif
39473 ret = rw_copy_check_uvector(type,
39474 (struct iovec __user *)kiocb->ki_buf,
39475 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
39476 + kiocb->ki_nbytes, 1, &iovstack,
39477 &kiocb->ki_iovec, 1);
39478 if (ret < 0)
39479 goto out;
39480
39481 + if (kiocb->ki_iovec == &iovstack) {
39482 + kiocb->ki_inline_vec = iovstack;
39483 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
39484 + }
39485 kiocb->ki_nr_segs = kiocb->ki_nbytes;
39486 kiocb->ki_cur_seg = 0;
39487 /* ki_nbytes/left now reflect bytes instead of segs */
39488 diff --git a/fs/attr.c b/fs/attr.c
39489 index 7ee7ba4..0c61a60 100644
39490 --- a/fs/attr.c
39491 +++ b/fs/attr.c
39492 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
39493 unsigned long limit;
39494
39495 limit = rlimit(RLIMIT_FSIZE);
39496 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
39497 if (limit != RLIM_INFINITY && offset > limit)
39498 goto out_sig;
39499 if (offset > inode->i_sb->s_maxbytes)
39500 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
39501 index e1fbdee..cd5ea56 100644
39502 --- a/fs/autofs4/waitq.c
39503 +++ b/fs/autofs4/waitq.c
39504 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
39505 {
39506 unsigned long sigpipe, flags;
39507 mm_segment_t fs;
39508 - const char *data = (const char *)addr;
39509 + const char __user *data = (const char __force_user *)addr;
39510 ssize_t wr = 0;
39511
39512 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
39513 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
39514 index 8342ca6..82fd192 100644
39515 --- a/fs/befs/linuxvfs.c
39516 +++ b/fs/befs/linuxvfs.c
39517 @@ -503,7 +503,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
39518 {
39519 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
39520 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
39521 - char *link = nd_get_link(nd);
39522 + const char *link = nd_get_link(nd);
39523 if (!IS_ERR(link))
39524 kfree(link);
39525 }
39526 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
39527 index a6395bd..a5b24c4 100644
39528 --- a/fs/binfmt_aout.c
39529 +++ b/fs/binfmt_aout.c
39530 @@ -16,6 +16,7 @@
39531 #include <linux/string.h>
39532 #include <linux/fs.h>
39533 #include <linux/file.h>
39534 +#include <linux/security.h>
39535 #include <linux/stat.h>
39536 #include <linux/fcntl.h>
39537 #include <linux/ptrace.h>
39538 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
39539 #endif
39540 # define START_STACK(u) ((void __user *)u.start_stack)
39541
39542 + memset(&dump, 0, sizeof(dump));
39543 +
39544 fs = get_fs();
39545 set_fs(KERNEL_DS);
39546 has_dumped = 1;
39547 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
39548
39549 /* If the size of the dump file exceeds the rlimit, then see what would happen
39550 if we wrote the stack, but not the data area. */
39551 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
39552 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
39553 dump.u_dsize = 0;
39554
39555 /* Make sure we have enough room to write the stack and data areas. */
39556 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
39557 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
39558 dump.u_ssize = 0;
39559
39560 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39561 rlim = rlimit(RLIMIT_DATA);
39562 if (rlim >= RLIM_INFINITY)
39563 rlim = ~0;
39564 +
39565 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
39566 if (ex.a_data + ex.a_bss > rlim)
39567 return -ENOMEM;
39568
39569 @@ -262,6 +269,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39570 install_exec_creds(bprm);
39571 current->flags &= ~PF_FORKNOEXEC;
39572
39573 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
39574 + current->mm->pax_flags = 0UL;
39575 +#endif
39576 +
39577 +#ifdef CONFIG_PAX_PAGEEXEC
39578 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
39579 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
39580 +
39581 +#ifdef CONFIG_PAX_EMUTRAMP
39582 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
39583 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
39584 +#endif
39585 +
39586 +#ifdef CONFIG_PAX_MPROTECT
39587 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
39588 + current->mm->pax_flags |= MF_PAX_MPROTECT;
39589 +#endif
39590 +
39591 + }
39592 +#endif
39593 +
39594 if (N_MAGIC(ex) == OMAGIC) {
39595 unsigned long text_addr, map_size;
39596 loff_t pos;
39597 @@ -334,7 +362,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39598
39599 down_write(&current->mm->mmap_sem);
39600 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
39601 - PROT_READ | PROT_WRITE | PROT_EXEC,
39602 + PROT_READ | PROT_WRITE,
39603 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
39604 fd_offset + ex.a_text);
39605 up_write(&current->mm->mmap_sem);
39606 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
39607 index 21ac5ee..31d14e9 100644
39608 --- a/fs/binfmt_elf.c
39609 +++ b/fs/binfmt_elf.c
39610 @@ -32,6 +32,7 @@
39611 #include <linux/elf.h>
39612 #include <linux/utsname.h>
39613 #include <linux/coredump.h>
39614 +#include <linux/xattr.h>
39615 #include <asm/uaccess.h>
39616 #include <asm/param.h>
39617 #include <asm/page.h>
39618 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
39619 #define elf_core_dump NULL
39620 #endif
39621
39622 +#ifdef CONFIG_PAX_MPROTECT
39623 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
39624 +#endif
39625 +
39626 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
39627 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
39628 #else
39629 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
39630 .load_binary = load_elf_binary,
39631 .load_shlib = load_elf_library,
39632 .core_dump = elf_core_dump,
39633 +
39634 +#ifdef CONFIG_PAX_MPROTECT
39635 + .handle_mprotect= elf_handle_mprotect,
39636 +#endif
39637 +
39638 .min_coredump = ELF_EXEC_PAGESIZE,
39639 };
39640
39641 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
39642
39643 static int set_brk(unsigned long start, unsigned long end)
39644 {
39645 + unsigned long e = end;
39646 +
39647 start = ELF_PAGEALIGN(start);
39648 end = ELF_PAGEALIGN(end);
39649 if (end > start) {
39650 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
39651 if (BAD_ADDR(addr))
39652 return addr;
39653 }
39654 - current->mm->start_brk = current->mm->brk = end;
39655 + current->mm->start_brk = current->mm->brk = e;
39656 return 0;
39657 }
39658
39659 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39660 elf_addr_t __user *u_rand_bytes;
39661 const char *k_platform = ELF_PLATFORM;
39662 const char *k_base_platform = ELF_BASE_PLATFORM;
39663 - unsigned char k_rand_bytes[16];
39664 + u32 k_rand_bytes[4];
39665 int items;
39666 elf_addr_t *elf_info;
39667 int ei_index = 0;
39668 const struct cred *cred = current_cred();
39669 struct vm_area_struct *vma;
39670 + unsigned long saved_auxv[AT_VECTOR_SIZE];
39671
39672 /*
39673 * In some cases (e.g. Hyper-Threading), we want to avoid L1
39674 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39675 * Generate 16 random bytes for userspace PRNG seeding.
39676 */
39677 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
39678 - u_rand_bytes = (elf_addr_t __user *)
39679 - STACK_ALLOC(p, sizeof(k_rand_bytes));
39680 + srandom32(k_rand_bytes[0] ^ random32());
39681 + srandom32(k_rand_bytes[1] ^ random32());
39682 + srandom32(k_rand_bytes[2] ^ random32());
39683 + srandom32(k_rand_bytes[3] ^ random32());
39684 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
39685 + u_rand_bytes = (elf_addr_t __user *) p;
39686 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
39687 return -EFAULT;
39688
39689 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39690 return -EFAULT;
39691 current->mm->env_end = p;
39692
39693 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
39694 +
39695 /* Put the elf_info on the stack in the right place. */
39696 sp = (elf_addr_t __user *)envp + 1;
39697 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
39698 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
39699 return -EFAULT;
39700 return 0;
39701 }
39702 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
39703 {
39704 struct elf_phdr *elf_phdata;
39705 struct elf_phdr *eppnt;
39706 - unsigned long load_addr = 0;
39707 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
39708 int load_addr_set = 0;
39709 unsigned long last_bss = 0, elf_bss = 0;
39710 - unsigned long error = ~0UL;
39711 + unsigned long error = -EINVAL;
39712 unsigned long total_size;
39713 int retval, i, size;
39714
39715 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
39716 goto out_close;
39717 }
39718
39719 +#ifdef CONFIG_PAX_SEGMEXEC
39720 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
39721 + pax_task_size = SEGMEXEC_TASK_SIZE;
39722 +#endif
39723 +
39724 eppnt = elf_phdata;
39725 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
39726 if (eppnt->p_type == PT_LOAD) {
39727 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
39728 k = load_addr + eppnt->p_vaddr;
39729 if (BAD_ADDR(k) ||
39730 eppnt->p_filesz > eppnt->p_memsz ||
39731 - eppnt->p_memsz > TASK_SIZE ||
39732 - TASK_SIZE - eppnt->p_memsz < k) {
39733 + eppnt->p_memsz > pax_task_size ||
39734 + pax_task_size - eppnt->p_memsz < k) {
39735 error = -ENOMEM;
39736 goto out_close;
39737 }
39738 @@ -528,6 +552,351 @@ out:
39739 return error;
39740 }
39741
39742 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
39743 +{
39744 + unsigned long pax_flags = 0UL;
39745 +
39746 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
39747 +
39748 +#ifdef CONFIG_PAX_PAGEEXEC
39749 + if (elf_phdata->p_flags & PF_PAGEEXEC)
39750 + pax_flags |= MF_PAX_PAGEEXEC;
39751 +#endif
39752 +
39753 +#ifdef CONFIG_PAX_SEGMEXEC
39754 + if (elf_phdata->p_flags & PF_SEGMEXEC)
39755 + pax_flags |= MF_PAX_SEGMEXEC;
39756 +#endif
39757 +
39758 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39759 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39760 + if ((__supported_pte_mask & _PAGE_NX))
39761 + pax_flags &= ~MF_PAX_SEGMEXEC;
39762 + else
39763 + pax_flags &= ~MF_PAX_PAGEEXEC;
39764 + }
39765 +#endif
39766 +
39767 +#ifdef CONFIG_PAX_EMUTRAMP
39768 + if (elf_phdata->p_flags & PF_EMUTRAMP)
39769 + pax_flags |= MF_PAX_EMUTRAMP;
39770 +#endif
39771 +
39772 +#ifdef CONFIG_PAX_MPROTECT
39773 + if (elf_phdata->p_flags & PF_MPROTECT)
39774 + pax_flags |= MF_PAX_MPROTECT;
39775 +#endif
39776 +
39777 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
39778 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
39779 + pax_flags |= MF_PAX_RANDMMAP;
39780 +#endif
39781 +
39782 +#endif
39783 +
39784 + return pax_flags;
39785 +}
39786 +
39787 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
39788 +{
39789 + unsigned long pax_flags = 0UL;
39790 +
39791 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
39792 +
39793 +#ifdef CONFIG_PAX_PAGEEXEC
39794 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
39795 + pax_flags |= MF_PAX_PAGEEXEC;
39796 +#endif
39797 +
39798 +#ifdef CONFIG_PAX_SEGMEXEC
39799 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
39800 + pax_flags |= MF_PAX_SEGMEXEC;
39801 +#endif
39802 +
39803 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39804 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39805 + if ((__supported_pte_mask & _PAGE_NX))
39806 + pax_flags &= ~MF_PAX_SEGMEXEC;
39807 + else
39808 + pax_flags &= ~MF_PAX_PAGEEXEC;
39809 + }
39810 +#endif
39811 +
39812 +#ifdef CONFIG_PAX_EMUTRAMP
39813 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
39814 + pax_flags |= MF_PAX_EMUTRAMP;
39815 +#endif
39816 +
39817 +#ifdef CONFIG_PAX_MPROTECT
39818 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
39819 + pax_flags |= MF_PAX_MPROTECT;
39820 +#endif
39821 +
39822 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
39823 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
39824 + pax_flags |= MF_PAX_RANDMMAP;
39825 +#endif
39826 +
39827 +#endif
39828 +
39829 + return pax_flags;
39830 +}
39831 +
39832 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
39833 +{
39834 + unsigned long pax_flags = 0UL;
39835 +
39836 +#ifdef CONFIG_PAX_EI_PAX
39837 +
39838 +#ifdef CONFIG_PAX_PAGEEXEC
39839 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
39840 + pax_flags |= MF_PAX_PAGEEXEC;
39841 +#endif
39842 +
39843 +#ifdef CONFIG_PAX_SEGMEXEC
39844 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
39845 + pax_flags |= MF_PAX_SEGMEXEC;
39846 +#endif
39847 +
39848 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39849 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39850 + if ((__supported_pte_mask & _PAGE_NX))
39851 + pax_flags &= ~MF_PAX_SEGMEXEC;
39852 + else
39853 + pax_flags &= ~MF_PAX_PAGEEXEC;
39854 + }
39855 +#endif
39856 +
39857 +#ifdef CONFIG_PAX_EMUTRAMP
39858 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
39859 + pax_flags |= MF_PAX_EMUTRAMP;
39860 +#endif
39861 +
39862 +#ifdef CONFIG_PAX_MPROTECT
39863 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
39864 + pax_flags |= MF_PAX_MPROTECT;
39865 +#endif
39866 +
39867 +#ifdef CONFIG_PAX_ASLR
39868 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
39869 + pax_flags |= MF_PAX_RANDMMAP;
39870 +#endif
39871 +
39872 +#else
39873 +
39874 +#ifdef CONFIG_PAX_PAGEEXEC
39875 + pax_flags |= MF_PAX_PAGEEXEC;
39876 +#endif
39877 +
39878 +#ifdef CONFIG_PAX_MPROTECT
39879 + pax_flags |= MF_PAX_MPROTECT;
39880 +#endif
39881 +
39882 +#ifdef CONFIG_PAX_RANDMMAP
39883 + pax_flags |= MF_PAX_RANDMMAP;
39884 +#endif
39885 +
39886 +#ifdef CONFIG_PAX_SEGMEXEC
39887 + if (!(__supported_pte_mask & _PAGE_NX)) {
39888 + pax_flags &= ~MF_PAX_PAGEEXEC;
39889 + pax_flags |= MF_PAX_SEGMEXEC;
39890 + }
39891 +#endif
39892 +
39893 +#endif
39894 +
39895 + return pax_flags;
39896 +}
39897 +
39898 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
39899 +{
39900 +
39901 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
39902 + unsigned long i;
39903 +
39904 + for (i = 0UL; i < elf_ex->e_phnum; i++)
39905 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
39906 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
39907 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
39908 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
39909 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
39910 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
39911 + return ~0UL;
39912 +
39913 +#ifdef CONFIG_PAX_SOFTMODE
39914 + if (pax_softmode)
39915 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
39916 + else
39917 +#endif
39918 +
39919 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
39920 + break;
39921 + }
39922 +#endif
39923 +
39924 + return ~0UL;
39925 +}
39926 +
39927 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
39928 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
39929 +{
39930 + unsigned long pax_flags = 0UL;
39931 +
39932 +#ifdef CONFIG_PAX_PAGEEXEC
39933 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
39934 + pax_flags |= MF_PAX_PAGEEXEC;
39935 +#endif
39936 +
39937 +#ifdef CONFIG_PAX_SEGMEXEC
39938 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
39939 + pax_flags |= MF_PAX_SEGMEXEC;
39940 +#endif
39941 +
39942 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39943 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39944 + if ((__supported_pte_mask & _PAGE_NX))
39945 + pax_flags &= ~MF_PAX_SEGMEXEC;
39946 + else
39947 + pax_flags &= ~MF_PAX_PAGEEXEC;
39948 + }
39949 +#endif
39950 +
39951 +#ifdef CONFIG_PAX_EMUTRAMP
39952 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
39953 + pax_flags |= MF_PAX_EMUTRAMP;
39954 +#endif
39955 +
39956 +#ifdef CONFIG_PAX_MPROTECT
39957 + if (pax_flags_softmode & MF_PAX_MPROTECT)
39958 + pax_flags |= MF_PAX_MPROTECT;
39959 +#endif
39960 +
39961 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
39962 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
39963 + pax_flags |= MF_PAX_RANDMMAP;
39964 +#endif
39965 +
39966 + return pax_flags;
39967 +}
39968 +
39969 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
39970 +{
39971 + unsigned long pax_flags = 0UL;
39972 +
39973 +#ifdef CONFIG_PAX_PAGEEXEC
39974 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
39975 + pax_flags |= MF_PAX_PAGEEXEC;
39976 +#endif
39977 +
39978 +#ifdef CONFIG_PAX_SEGMEXEC
39979 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
39980 + pax_flags |= MF_PAX_SEGMEXEC;
39981 +#endif
39982 +
39983 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39984 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39985 + if ((__supported_pte_mask & _PAGE_NX))
39986 + pax_flags &= ~MF_PAX_SEGMEXEC;
39987 + else
39988 + pax_flags &= ~MF_PAX_PAGEEXEC;
39989 + }
39990 +#endif
39991 +
39992 +#ifdef CONFIG_PAX_EMUTRAMP
39993 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
39994 + pax_flags |= MF_PAX_EMUTRAMP;
39995 +#endif
39996 +
39997 +#ifdef CONFIG_PAX_MPROTECT
39998 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
39999 + pax_flags |= MF_PAX_MPROTECT;
40000 +#endif
40001 +
40002 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
40003 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
40004 + pax_flags |= MF_PAX_RANDMMAP;
40005 +#endif
40006 +
40007 + return pax_flags;
40008 +}
40009 +#endif
40010 +
40011 +static unsigned long pax_parse_xattr_pax(struct file * const file)
40012 +{
40013 +
40014 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
40015 + ssize_t xattr_size, i;
40016 + unsigned char xattr_value[5];
40017 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
40018 +
40019 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
40020 + if (xattr_size <= 0)
40021 + return ~0UL;
40022 +
40023 + for (i = 0; i < xattr_size; i++)
40024 + switch (xattr_value[i]) {
40025 + default:
40026 + return ~0UL;
40027 +
40028 +#define parse_flag(option1, option2, flag) \
40029 + case option1: \
40030 + pax_flags_hardmode |= MF_PAX_##flag; \
40031 + break; \
40032 + case option2: \
40033 + pax_flags_softmode |= MF_PAX_##flag; \
40034 + break;
40035 +
40036 + parse_flag('p', 'P', PAGEEXEC);
40037 + parse_flag('e', 'E', EMUTRAMP);
40038 + parse_flag('m', 'M', MPROTECT);
40039 + parse_flag('r', 'R', RANDMMAP);
40040 + parse_flag('s', 'S', SEGMEXEC);
40041 +
40042 +#undef parse_flag
40043 + }
40044 +
40045 + if (pax_flags_hardmode & pax_flags_softmode)
40046 + return ~0UL;
40047 +
40048 +#ifdef CONFIG_PAX_SOFTMODE
40049 + if (pax_softmode)
40050 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
40051 + else
40052 +#endif
40053 +
40054 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
40055 +#else
40056 + return ~0UL;
40057 +#endif
40058 +
40059 +}
40060 +
40061 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
40062 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
40063 +{
40064 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
40065 +
40066 + pax_flags = pax_parse_ei_pax(elf_ex);
40067 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
40068 + xattr_pax_flags = pax_parse_xattr_pax(file);
40069 +
40070 + if (pt_pax_flags == ~0UL)
40071 + pt_pax_flags = xattr_pax_flags;
40072 + else if (xattr_pax_flags == ~0UL)
40073 + xattr_pax_flags = pt_pax_flags;
40074 + if (pt_pax_flags != xattr_pax_flags)
40075 + return -EINVAL;
40076 + if (pt_pax_flags != ~0UL)
40077 + pax_flags = pt_pax_flags;
40078 +
40079 + if (0 > pax_check_flags(&pax_flags))
40080 + return -EINVAL;
40081 +
40082 + current->mm->pax_flags = pax_flags;
40083 + return 0;
40084 +}
40085 +#endif
40086 +
40087 /*
40088 * These are the functions used to load ELF style executables and shared
40089 * libraries. There is no binary dependent code anywhere else.
40090 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
40091 {
40092 unsigned int random_variable = 0;
40093
40094 +#ifdef CONFIG_PAX_RANDUSTACK
40095 + if (randomize_va_space)
40096 + return stack_top - current->mm->delta_stack;
40097 +#endif
40098 +
40099 if ((current->flags & PF_RANDOMIZE) &&
40100 !(current->personality & ADDR_NO_RANDOMIZE)) {
40101 random_variable = get_random_int() & STACK_RND_MASK;
40102 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40103 unsigned long load_addr = 0, load_bias = 0;
40104 int load_addr_set = 0;
40105 char * elf_interpreter = NULL;
40106 - unsigned long error;
40107 + unsigned long error = 0;
40108 struct elf_phdr *elf_ppnt, *elf_phdata;
40109 unsigned long elf_bss, elf_brk;
40110 int retval, i;
40111 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40112 unsigned long start_code, end_code, start_data, end_data;
40113 unsigned long reloc_func_desc __maybe_unused = 0;
40114 int executable_stack = EXSTACK_DEFAULT;
40115 - unsigned long def_flags = 0;
40116 struct {
40117 struct elfhdr elf_ex;
40118 struct elfhdr interp_elf_ex;
40119 } *loc;
40120 + unsigned long pax_task_size = TASK_SIZE;
40121
40122 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
40123 if (!loc) {
40124 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40125
40126 /* OK, This is the point of no return */
40127 current->flags &= ~PF_FORKNOEXEC;
40128 - current->mm->def_flags = def_flags;
40129 +
40130 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
40131 + current->mm->pax_flags = 0UL;
40132 +#endif
40133 +
40134 +#ifdef CONFIG_PAX_DLRESOLVE
40135 + current->mm->call_dl_resolve = 0UL;
40136 +#endif
40137 +
40138 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
40139 + current->mm->call_syscall = 0UL;
40140 +#endif
40141 +
40142 +#ifdef CONFIG_PAX_ASLR
40143 + current->mm->delta_mmap = 0UL;
40144 + current->mm->delta_stack = 0UL;
40145 +#endif
40146 +
40147 + current->mm->def_flags = 0;
40148 +
40149 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
40150 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
40151 + send_sig(SIGKILL, current, 0);
40152 + goto out_free_dentry;
40153 + }
40154 +#endif
40155 +
40156 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
40157 + pax_set_initial_flags(bprm);
40158 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
40159 + if (pax_set_initial_flags_func)
40160 + (pax_set_initial_flags_func)(bprm);
40161 +#endif
40162 +
40163 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
40164 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
40165 + current->mm->context.user_cs_limit = PAGE_SIZE;
40166 + current->mm->def_flags |= VM_PAGEEXEC;
40167 + }
40168 +#endif
40169 +
40170 +#ifdef CONFIG_PAX_SEGMEXEC
40171 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
40172 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
40173 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
40174 + pax_task_size = SEGMEXEC_TASK_SIZE;
40175 + current->mm->def_flags |= VM_NOHUGEPAGE;
40176 + }
40177 +#endif
40178 +
40179 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
40180 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40181 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
40182 + put_cpu();
40183 + }
40184 +#endif
40185
40186 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
40187 may depend on the personality. */
40188 SET_PERSONALITY(loc->elf_ex);
40189 +
40190 +#ifdef CONFIG_PAX_ASLR
40191 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
40192 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
40193 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
40194 + }
40195 +#endif
40196 +
40197 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
40198 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40199 + executable_stack = EXSTACK_DISABLE_X;
40200 + current->personality &= ~READ_IMPLIES_EXEC;
40201 + } else
40202 +#endif
40203 +
40204 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
40205 current->personality |= READ_IMPLIES_EXEC;
40206
40207 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40208 #else
40209 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
40210 #endif
40211 +
40212 +#ifdef CONFIG_PAX_RANDMMAP
40213 + /* PaX: randomize base address at the default exe base if requested */
40214 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
40215 +#ifdef CONFIG_SPARC64
40216 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
40217 +#else
40218 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
40219 +#endif
40220 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
40221 + elf_flags |= MAP_FIXED;
40222 + }
40223 +#endif
40224 +
40225 }
40226
40227 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
40228 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40229 * allowed task size. Note that p_filesz must always be
40230 * <= p_memsz so it is only necessary to check p_memsz.
40231 */
40232 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
40233 - elf_ppnt->p_memsz > TASK_SIZE ||
40234 - TASK_SIZE - elf_ppnt->p_memsz < k) {
40235 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
40236 + elf_ppnt->p_memsz > pax_task_size ||
40237 + pax_task_size - elf_ppnt->p_memsz < k) {
40238 /* set_brk can never work. Avoid overflows. */
40239 send_sig(SIGKILL, current, 0);
40240 retval = -EINVAL;
40241 @@ -870,6 +1328,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40242 start_data += load_bias;
40243 end_data += load_bias;
40244
40245 +#ifdef CONFIG_PAX_RANDMMAP
40246 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
40247 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
40248 +#endif
40249 +
40250 /* Calling set_brk effectively mmaps the pages that we need
40251 * for the bss and break sections. We must do this before
40252 * mapping in the interpreter, to make sure it doesn't wind
40253 @@ -881,9 +1344,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40254 goto out_free_dentry;
40255 }
40256 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
40257 - send_sig(SIGSEGV, current, 0);
40258 - retval = -EFAULT; /* Nobody gets to see this, but.. */
40259 - goto out_free_dentry;
40260 + /*
40261 + * This bss-zeroing can fail if the ELF
40262 + * file specifies odd protections. So
40263 + * we don't check the return value
40264 + */
40265 }
40266
40267 if (elf_interpreter) {
40268 @@ -1098,7 +1563,7 @@ out:
40269 * Decide what to dump of a segment, part, all or none.
40270 */
40271 static unsigned long vma_dump_size(struct vm_area_struct *vma,
40272 - unsigned long mm_flags)
40273 + unsigned long mm_flags, long signr)
40274 {
40275 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
40276
40277 @@ -1132,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
40278 if (vma->vm_file == NULL)
40279 return 0;
40280
40281 - if (FILTER(MAPPED_PRIVATE))
40282 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
40283 goto whole;
40284
40285 /*
40286 @@ -1354,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
40287 {
40288 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
40289 int i = 0;
40290 - do
40291 + do {
40292 i += 2;
40293 - while (auxv[i - 2] != AT_NULL);
40294 + } while (auxv[i - 2] != AT_NULL);
40295 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
40296 }
40297
40298 @@ -1862,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
40299 }
40300
40301 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
40302 - unsigned long mm_flags)
40303 + struct coredump_params *cprm)
40304 {
40305 struct vm_area_struct *vma;
40306 size_t size = 0;
40307
40308 for (vma = first_vma(current, gate_vma); vma != NULL;
40309 vma = next_vma(vma, gate_vma))
40310 - size += vma_dump_size(vma, mm_flags);
40311 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40312 return size;
40313 }
40314
40315 @@ -1963,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40316
40317 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
40318
40319 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
40320 + offset += elf_core_vma_data_size(gate_vma, cprm);
40321 offset += elf_core_extra_data_size();
40322 e_shoff = offset;
40323
40324 @@ -1977,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
40325 offset = dataoff;
40326
40327 size += sizeof(*elf);
40328 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40329 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
40330 goto end_coredump;
40331
40332 size += sizeof(*phdr4note);
40333 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40334 if (size > cprm->limit
40335 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
40336 goto end_coredump;
40337 @@ -1994,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40338 phdr.p_offset = offset;
40339 phdr.p_vaddr = vma->vm_start;
40340 phdr.p_paddr = 0;
40341 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
40342 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40343 phdr.p_memsz = vma->vm_end - vma->vm_start;
40344 offset += phdr.p_filesz;
40345 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
40346 @@ -2005,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40347 phdr.p_align = ELF_EXEC_PAGESIZE;
40348
40349 size += sizeof(phdr);
40350 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40351 if (size > cprm->limit
40352 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
40353 goto end_coredump;
40354 @@ -2029,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40355 unsigned long addr;
40356 unsigned long end;
40357
40358 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
40359 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40360
40361 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
40362 struct page *page;
40363 @@ -2038,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40364 page = get_dump_page(addr);
40365 if (page) {
40366 void *kaddr = kmap(page);
40367 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
40368 stop = ((size += PAGE_SIZE) > cprm->limit) ||
40369 !dump_write(cprm->file, kaddr,
40370 PAGE_SIZE);
40371 @@ -2055,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40372
40373 if (e_phnum == PN_XNUM) {
40374 size += sizeof(*shdr4extnum);
40375 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40376 if (size > cprm->limit
40377 || !dump_write(cprm->file, shdr4extnum,
40378 sizeof(*shdr4extnum)))
40379 @@ -2075,6 +2545,97 @@ out:
40380
40381 #endif /* CONFIG_ELF_CORE */
40382
40383 +#ifdef CONFIG_PAX_MPROTECT
40384 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
40385 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
40386 + * we'll remove VM_MAYWRITE for good on RELRO segments.
40387 + *
40388 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
40389 + * basis because we want to allow the common case and not the special ones.
40390 + */
40391 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
40392 +{
40393 + struct elfhdr elf_h;
40394 + struct elf_phdr elf_p;
40395 + unsigned long i;
40396 + unsigned long oldflags;
40397 + bool is_textrel_rw, is_textrel_rx, is_relro;
40398 +
40399 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
40400 + return;
40401 +
40402 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
40403 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
40404 +
40405 +#ifdef CONFIG_PAX_ELFRELOCS
40406 + /* possible TEXTREL */
40407 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
40408 + 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);
40409 +#else
40410 + is_textrel_rw = false;
40411 + is_textrel_rx = false;
40412 +#endif
40413 +
40414 + /* possible RELRO */
40415 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
40416 +
40417 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
40418 + return;
40419 +
40420 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
40421 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
40422 +
40423 +#ifdef CONFIG_PAX_ETEXECRELOCS
40424 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
40425 +#else
40426 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
40427 +#endif
40428 +
40429 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
40430 + !elf_check_arch(&elf_h) ||
40431 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
40432 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
40433 + return;
40434 +
40435 + for (i = 0UL; i < elf_h.e_phnum; i++) {
40436 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
40437 + return;
40438 + switch (elf_p.p_type) {
40439 + case PT_DYNAMIC:
40440 + if (!is_textrel_rw && !is_textrel_rx)
40441 + continue;
40442 + i = 0UL;
40443 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
40444 + elf_dyn dyn;
40445 +
40446 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
40447 + return;
40448 + if (dyn.d_tag == DT_NULL)
40449 + return;
40450 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
40451 + gr_log_textrel(vma);
40452 + if (is_textrel_rw)
40453 + vma->vm_flags |= VM_MAYWRITE;
40454 + else
40455 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
40456 + vma->vm_flags &= ~VM_MAYWRITE;
40457 + return;
40458 + }
40459 + i++;
40460 + }
40461 + return;
40462 +
40463 + case PT_GNU_RELRO:
40464 + if (!is_relro)
40465 + continue;
40466 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
40467 + vma->vm_flags &= ~VM_MAYWRITE;
40468 + return;
40469 + }
40470 + }
40471 +}
40472 +#endif
40473 +
40474 static int __init init_elf_binfmt(void)
40475 {
40476 return register_binfmt(&elf_format);
40477 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
40478 index 1bffbe0..c8c283e 100644
40479 --- a/fs/binfmt_flat.c
40480 +++ b/fs/binfmt_flat.c
40481 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
40482 realdatastart = (unsigned long) -ENOMEM;
40483 printk("Unable to allocate RAM for process data, errno %d\n",
40484 (int)-realdatastart);
40485 + down_write(&current->mm->mmap_sem);
40486 do_munmap(current->mm, textpos, text_len);
40487 + up_write(&current->mm->mmap_sem);
40488 ret = realdatastart;
40489 goto err;
40490 }
40491 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
40492 }
40493 if (IS_ERR_VALUE(result)) {
40494 printk("Unable to read data+bss, errno %d\n", (int)-result);
40495 + down_write(&current->mm->mmap_sem);
40496 do_munmap(current->mm, textpos, text_len);
40497 do_munmap(current->mm, realdatastart, len);
40498 + up_write(&current->mm->mmap_sem);
40499 ret = result;
40500 goto err;
40501 }
40502 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
40503 }
40504 if (IS_ERR_VALUE(result)) {
40505 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
40506 + down_write(&current->mm->mmap_sem);
40507 do_munmap(current->mm, textpos, text_len + data_len + extra +
40508 MAX_SHARED_LIBS * sizeof(unsigned long));
40509 + up_write(&current->mm->mmap_sem);
40510 ret = result;
40511 goto err;
40512 }
40513 diff --git a/fs/bio.c b/fs/bio.c
40514 index b1fe82c..84da0a9 100644
40515 --- a/fs/bio.c
40516 +++ b/fs/bio.c
40517 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
40518 const int read = bio_data_dir(bio) == READ;
40519 struct bio_map_data *bmd = bio->bi_private;
40520 int i;
40521 - char *p = bmd->sgvecs[0].iov_base;
40522 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
40523
40524 __bio_for_each_segment(bvec, bio, i, 0) {
40525 char *addr = page_address(bvec->bv_page);
40526 diff --git a/fs/block_dev.c b/fs/block_dev.c
40527 index b07f1da..9efcb92 100644
40528 --- a/fs/block_dev.c
40529 +++ b/fs/block_dev.c
40530 @@ -681,7 +681,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
40531 else if (bdev->bd_contains == bdev)
40532 return true; /* is a whole device which isn't held */
40533
40534 - else if (whole->bd_holder == bd_may_claim)
40535 + else if (whole->bd_holder == (void *)bd_may_claim)
40536 return true; /* is a partition of a device that is being partitioned */
40537 else if (whole->bd_holder != NULL)
40538 return false; /* is a partition of a held device */
40539 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
40540 index dede441..f2a2507 100644
40541 --- a/fs/btrfs/ctree.c
40542 +++ b/fs/btrfs/ctree.c
40543 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
40544 free_extent_buffer(buf);
40545 add_root_to_dirty_list(root);
40546 } else {
40547 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
40548 - parent_start = parent->start;
40549 - else
40550 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
40551 + if (parent)
40552 + parent_start = parent->start;
40553 + else
40554 + parent_start = 0;
40555 + } else
40556 parent_start = 0;
40557
40558 WARN_ON(trans->transid != btrfs_header_generation(parent));
40559 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
40560 index fd1a06d..6e9033d 100644
40561 --- a/fs/btrfs/inode.c
40562 +++ b/fs/btrfs/inode.c
40563 @@ -6895,7 +6895,7 @@ fail:
40564 return -ENOMEM;
40565 }
40566
40567 -static int btrfs_getattr(struct vfsmount *mnt,
40568 +int btrfs_getattr(struct vfsmount *mnt,
40569 struct dentry *dentry, struct kstat *stat)
40570 {
40571 struct inode *inode = dentry->d_inode;
40572 @@ -6909,6 +6909,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
40573 return 0;
40574 }
40575
40576 +EXPORT_SYMBOL(btrfs_getattr);
40577 +
40578 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
40579 +{
40580 + return BTRFS_I(inode)->root->anon_dev;
40581 +}
40582 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
40583 +
40584 /*
40585 * If a file is moved, it will inherit the cow and compression flags of the new
40586 * directory.
40587 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
40588 index c04f02c..f5c9e2e 100644
40589 --- a/fs/btrfs/ioctl.c
40590 +++ b/fs/btrfs/ioctl.c
40591 @@ -2733,9 +2733,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
40592 for (i = 0; i < num_types; i++) {
40593 struct btrfs_space_info *tmp;
40594
40595 + /* Don't copy in more than we allocated */
40596 if (!slot_count)
40597 break;
40598
40599 + slot_count--;
40600 +
40601 info = NULL;
40602 rcu_read_lock();
40603 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
40604 @@ -2757,15 +2760,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
40605 memcpy(dest, &space, sizeof(space));
40606 dest++;
40607 space_args.total_spaces++;
40608 - slot_count--;
40609 }
40610 - if (!slot_count)
40611 - break;
40612 }
40613 up_read(&info->groups_sem);
40614 }
40615
40616 - user_dest = (struct btrfs_ioctl_space_info *)
40617 + user_dest = (struct btrfs_ioctl_space_info __user *)
40618 (arg + sizeof(struct btrfs_ioctl_space_args));
40619
40620 if (copy_to_user(user_dest, dest_orig, alloc_size))
40621 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
40622 index cfb5543..1ae7347 100644
40623 --- a/fs/btrfs/relocation.c
40624 +++ b/fs/btrfs/relocation.c
40625 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
40626 }
40627 spin_unlock(&rc->reloc_root_tree.lock);
40628
40629 - BUG_ON((struct btrfs_root *)node->data != root);
40630 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
40631
40632 if (!del) {
40633 spin_lock(&rc->reloc_root_tree.lock);
40634 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
40635 index 622f469..e8d2d55 100644
40636 --- a/fs/cachefiles/bind.c
40637 +++ b/fs/cachefiles/bind.c
40638 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
40639 args);
40640
40641 /* start by checking things over */
40642 - ASSERT(cache->fstop_percent >= 0 &&
40643 - cache->fstop_percent < cache->fcull_percent &&
40644 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
40645 cache->fcull_percent < cache->frun_percent &&
40646 cache->frun_percent < 100);
40647
40648 - ASSERT(cache->bstop_percent >= 0 &&
40649 - cache->bstop_percent < cache->bcull_percent &&
40650 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
40651 cache->bcull_percent < cache->brun_percent &&
40652 cache->brun_percent < 100);
40653
40654 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
40655 index 0a1467b..6a53245 100644
40656 --- a/fs/cachefiles/daemon.c
40657 +++ b/fs/cachefiles/daemon.c
40658 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
40659 if (n > buflen)
40660 return -EMSGSIZE;
40661
40662 - if (copy_to_user(_buffer, buffer, n) != 0)
40663 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
40664 return -EFAULT;
40665
40666 return n;
40667 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
40668 if (test_bit(CACHEFILES_DEAD, &cache->flags))
40669 return -EIO;
40670
40671 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
40672 + if (datalen > PAGE_SIZE - 1)
40673 return -EOPNOTSUPP;
40674
40675 /* drag the command string into the kernel so we can parse it */
40676 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
40677 if (args[0] != '%' || args[1] != '\0')
40678 return -EINVAL;
40679
40680 - if (fstop < 0 || fstop >= cache->fcull_percent)
40681 + if (fstop >= cache->fcull_percent)
40682 return cachefiles_daemon_range_error(cache, args);
40683
40684 cache->fstop_percent = fstop;
40685 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
40686 if (args[0] != '%' || args[1] != '\0')
40687 return -EINVAL;
40688
40689 - if (bstop < 0 || bstop >= cache->bcull_percent)
40690 + if (bstop >= cache->bcull_percent)
40691 return cachefiles_daemon_range_error(cache, args);
40692
40693 cache->bstop_percent = bstop;
40694 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
40695 index bd6bc1b..b627b53 100644
40696 --- a/fs/cachefiles/internal.h
40697 +++ b/fs/cachefiles/internal.h
40698 @@ -57,7 +57,7 @@ struct cachefiles_cache {
40699 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
40700 struct rb_root active_nodes; /* active nodes (can't be culled) */
40701 rwlock_t active_lock; /* lock for active_nodes */
40702 - atomic_t gravecounter; /* graveyard uniquifier */
40703 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
40704 unsigned frun_percent; /* when to stop culling (% files) */
40705 unsigned fcull_percent; /* when to start culling (% files) */
40706 unsigned fstop_percent; /* when to stop allocating (% files) */
40707 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
40708 * proc.c
40709 */
40710 #ifdef CONFIG_CACHEFILES_HISTOGRAM
40711 -extern atomic_t cachefiles_lookup_histogram[HZ];
40712 -extern atomic_t cachefiles_mkdir_histogram[HZ];
40713 -extern atomic_t cachefiles_create_histogram[HZ];
40714 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
40715 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
40716 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
40717
40718 extern int __init cachefiles_proc_init(void);
40719 extern void cachefiles_proc_cleanup(void);
40720 static inline
40721 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
40722 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
40723 {
40724 unsigned long jif = jiffies - start_jif;
40725 if (jif >= HZ)
40726 jif = HZ - 1;
40727 - atomic_inc(&histogram[jif]);
40728 + atomic_inc_unchecked(&histogram[jif]);
40729 }
40730
40731 #else
40732 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
40733 index a0358c2..d6137f2 100644
40734 --- a/fs/cachefiles/namei.c
40735 +++ b/fs/cachefiles/namei.c
40736 @@ -318,7 +318,7 @@ try_again:
40737 /* first step is to make up a grave dentry in the graveyard */
40738 sprintf(nbuffer, "%08x%08x",
40739 (uint32_t) get_seconds(),
40740 - (uint32_t) atomic_inc_return(&cache->gravecounter));
40741 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
40742
40743 /* do the multiway lock magic */
40744 trap = lock_rename(cache->graveyard, dir);
40745 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
40746 index eccd339..4c1d995 100644
40747 --- a/fs/cachefiles/proc.c
40748 +++ b/fs/cachefiles/proc.c
40749 @@ -14,9 +14,9 @@
40750 #include <linux/seq_file.h>
40751 #include "internal.h"
40752
40753 -atomic_t cachefiles_lookup_histogram[HZ];
40754 -atomic_t cachefiles_mkdir_histogram[HZ];
40755 -atomic_t cachefiles_create_histogram[HZ];
40756 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
40757 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
40758 +atomic_unchecked_t cachefiles_create_histogram[HZ];
40759
40760 /*
40761 * display the latency histogram
40762 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
40763 return 0;
40764 default:
40765 index = (unsigned long) v - 3;
40766 - x = atomic_read(&cachefiles_lookup_histogram[index]);
40767 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
40768 - z = atomic_read(&cachefiles_create_histogram[index]);
40769 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
40770 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
40771 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
40772 if (x == 0 && y == 0 && z == 0)
40773 return 0;
40774
40775 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
40776 index 0e3c092..818480e 100644
40777 --- a/fs/cachefiles/rdwr.c
40778 +++ b/fs/cachefiles/rdwr.c
40779 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
40780 old_fs = get_fs();
40781 set_fs(KERNEL_DS);
40782 ret = file->f_op->write(
40783 - file, (const void __user *) data, len, &pos);
40784 + file, (const void __force_user *) data, len, &pos);
40785 set_fs(old_fs);
40786 kunmap(page);
40787 if (ret != len)
40788 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
40789 index 9895400..fa40a7d 100644
40790 --- a/fs/ceph/dir.c
40791 +++ b/fs/ceph/dir.c
40792 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
40793 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
40794 struct ceph_mds_client *mdsc = fsc->mdsc;
40795 unsigned frag = fpos_frag(filp->f_pos);
40796 - int off = fpos_off(filp->f_pos);
40797 + unsigned int off = fpos_off(filp->f_pos);
40798 int err;
40799 u32 ftype;
40800 struct ceph_mds_reply_info_parsed *rinfo;
40801 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
40802 index 84e8c07..6170d31 100644
40803 --- a/fs/cifs/cifs_debug.c
40804 +++ b/fs/cifs/cifs_debug.c
40805 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
40806
40807 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
40808 #ifdef CONFIG_CIFS_STATS2
40809 - atomic_set(&totBufAllocCount, 0);
40810 - atomic_set(&totSmBufAllocCount, 0);
40811 + atomic_set_unchecked(&totBufAllocCount, 0);
40812 + atomic_set_unchecked(&totSmBufAllocCount, 0);
40813 #endif /* CONFIG_CIFS_STATS2 */
40814 spin_lock(&cifs_tcp_ses_lock);
40815 list_for_each(tmp1, &cifs_tcp_ses_list) {
40816 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
40817 tcon = list_entry(tmp3,
40818 struct cifs_tcon,
40819 tcon_list);
40820 - atomic_set(&tcon->num_smbs_sent, 0);
40821 - atomic_set(&tcon->num_writes, 0);
40822 - atomic_set(&tcon->num_reads, 0);
40823 - atomic_set(&tcon->num_oplock_brks, 0);
40824 - atomic_set(&tcon->num_opens, 0);
40825 - atomic_set(&tcon->num_posixopens, 0);
40826 - atomic_set(&tcon->num_posixmkdirs, 0);
40827 - atomic_set(&tcon->num_closes, 0);
40828 - atomic_set(&tcon->num_deletes, 0);
40829 - atomic_set(&tcon->num_mkdirs, 0);
40830 - atomic_set(&tcon->num_rmdirs, 0);
40831 - atomic_set(&tcon->num_renames, 0);
40832 - atomic_set(&tcon->num_t2renames, 0);
40833 - atomic_set(&tcon->num_ffirst, 0);
40834 - atomic_set(&tcon->num_fnext, 0);
40835 - atomic_set(&tcon->num_fclose, 0);
40836 - atomic_set(&tcon->num_hardlinks, 0);
40837 - atomic_set(&tcon->num_symlinks, 0);
40838 - atomic_set(&tcon->num_locks, 0);
40839 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
40840 + atomic_set_unchecked(&tcon->num_writes, 0);
40841 + atomic_set_unchecked(&tcon->num_reads, 0);
40842 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
40843 + atomic_set_unchecked(&tcon->num_opens, 0);
40844 + atomic_set_unchecked(&tcon->num_posixopens, 0);
40845 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
40846 + atomic_set_unchecked(&tcon->num_closes, 0);
40847 + atomic_set_unchecked(&tcon->num_deletes, 0);
40848 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
40849 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
40850 + atomic_set_unchecked(&tcon->num_renames, 0);
40851 + atomic_set_unchecked(&tcon->num_t2renames, 0);
40852 + atomic_set_unchecked(&tcon->num_ffirst, 0);
40853 + atomic_set_unchecked(&tcon->num_fnext, 0);
40854 + atomic_set_unchecked(&tcon->num_fclose, 0);
40855 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
40856 + atomic_set_unchecked(&tcon->num_symlinks, 0);
40857 + atomic_set_unchecked(&tcon->num_locks, 0);
40858 }
40859 }
40860 }
40861 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
40862 smBufAllocCount.counter, cifs_min_small);
40863 #ifdef CONFIG_CIFS_STATS2
40864 seq_printf(m, "Total Large %d Small %d Allocations\n",
40865 - atomic_read(&totBufAllocCount),
40866 - atomic_read(&totSmBufAllocCount));
40867 + atomic_read_unchecked(&totBufAllocCount),
40868 + atomic_read_unchecked(&totSmBufAllocCount));
40869 #endif /* CONFIG_CIFS_STATS2 */
40870
40871 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
40872 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
40873 if (tcon->need_reconnect)
40874 seq_puts(m, "\tDISCONNECTED ");
40875 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
40876 - atomic_read(&tcon->num_smbs_sent),
40877 - atomic_read(&tcon->num_oplock_brks));
40878 + atomic_read_unchecked(&tcon->num_smbs_sent),
40879 + atomic_read_unchecked(&tcon->num_oplock_brks));
40880 seq_printf(m, "\nReads: %d Bytes: %lld",
40881 - atomic_read(&tcon->num_reads),
40882 + atomic_read_unchecked(&tcon->num_reads),
40883 (long long)(tcon->bytes_read));
40884 seq_printf(m, "\nWrites: %d Bytes: %lld",
40885 - atomic_read(&tcon->num_writes),
40886 + atomic_read_unchecked(&tcon->num_writes),
40887 (long long)(tcon->bytes_written));
40888 seq_printf(m, "\nFlushes: %d",
40889 - atomic_read(&tcon->num_flushes));
40890 + atomic_read_unchecked(&tcon->num_flushes));
40891 seq_printf(m, "\nLocks: %d HardLinks: %d "
40892 "Symlinks: %d",
40893 - atomic_read(&tcon->num_locks),
40894 - atomic_read(&tcon->num_hardlinks),
40895 - atomic_read(&tcon->num_symlinks));
40896 + atomic_read_unchecked(&tcon->num_locks),
40897 + atomic_read_unchecked(&tcon->num_hardlinks),
40898 + atomic_read_unchecked(&tcon->num_symlinks));
40899 seq_printf(m, "\nOpens: %d Closes: %d "
40900 "Deletes: %d",
40901 - atomic_read(&tcon->num_opens),
40902 - atomic_read(&tcon->num_closes),
40903 - atomic_read(&tcon->num_deletes));
40904 + atomic_read_unchecked(&tcon->num_opens),
40905 + atomic_read_unchecked(&tcon->num_closes),
40906 + atomic_read_unchecked(&tcon->num_deletes));
40907 seq_printf(m, "\nPosix Opens: %d "
40908 "Posix Mkdirs: %d",
40909 - atomic_read(&tcon->num_posixopens),
40910 - atomic_read(&tcon->num_posixmkdirs));
40911 + atomic_read_unchecked(&tcon->num_posixopens),
40912 + atomic_read_unchecked(&tcon->num_posixmkdirs));
40913 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
40914 - atomic_read(&tcon->num_mkdirs),
40915 - atomic_read(&tcon->num_rmdirs));
40916 + atomic_read_unchecked(&tcon->num_mkdirs),
40917 + atomic_read_unchecked(&tcon->num_rmdirs));
40918 seq_printf(m, "\nRenames: %d T2 Renames %d",
40919 - atomic_read(&tcon->num_renames),
40920 - atomic_read(&tcon->num_t2renames));
40921 + atomic_read_unchecked(&tcon->num_renames),
40922 + atomic_read_unchecked(&tcon->num_t2renames));
40923 seq_printf(m, "\nFindFirst: %d FNext %d "
40924 "FClose %d",
40925 - atomic_read(&tcon->num_ffirst),
40926 - atomic_read(&tcon->num_fnext),
40927 - atomic_read(&tcon->num_fclose));
40928 + atomic_read_unchecked(&tcon->num_ffirst),
40929 + atomic_read_unchecked(&tcon->num_fnext),
40930 + atomic_read_unchecked(&tcon->num_fclose));
40931 }
40932 }
40933 }
40934 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
40935 index 8f1fe32..38f9e27 100644
40936 --- a/fs/cifs/cifsfs.c
40937 +++ b/fs/cifs/cifsfs.c
40938 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
40939 cifs_req_cachep = kmem_cache_create("cifs_request",
40940 CIFSMaxBufSize +
40941 MAX_CIFS_HDR_SIZE, 0,
40942 - SLAB_HWCACHE_ALIGN, NULL);
40943 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
40944 if (cifs_req_cachep == NULL)
40945 return -ENOMEM;
40946
40947 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
40948 efficient to alloc 1 per page off the slab compared to 17K (5page)
40949 alloc of large cifs buffers even when page debugging is on */
40950 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
40951 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
40952 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
40953 NULL);
40954 if (cifs_sm_req_cachep == NULL) {
40955 mempool_destroy(cifs_req_poolp);
40956 @@ -1101,8 +1101,8 @@ init_cifs(void)
40957 atomic_set(&bufAllocCount, 0);
40958 atomic_set(&smBufAllocCount, 0);
40959 #ifdef CONFIG_CIFS_STATS2
40960 - atomic_set(&totBufAllocCount, 0);
40961 - atomic_set(&totSmBufAllocCount, 0);
40962 + atomic_set_unchecked(&totBufAllocCount, 0);
40963 + atomic_set_unchecked(&totSmBufAllocCount, 0);
40964 #endif /* CONFIG_CIFS_STATS2 */
40965
40966 atomic_set(&midCount, 0);
40967 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
40968 index 8238aa1..0347196 100644
40969 --- a/fs/cifs/cifsglob.h
40970 +++ b/fs/cifs/cifsglob.h
40971 @@ -392,28 +392,28 @@ struct cifs_tcon {
40972 __u16 Flags; /* optional support bits */
40973 enum statusEnum tidStatus;
40974 #ifdef CONFIG_CIFS_STATS
40975 - atomic_t num_smbs_sent;
40976 - atomic_t num_writes;
40977 - atomic_t num_reads;
40978 - atomic_t num_flushes;
40979 - atomic_t num_oplock_brks;
40980 - atomic_t num_opens;
40981 - atomic_t num_closes;
40982 - atomic_t num_deletes;
40983 - atomic_t num_mkdirs;
40984 - atomic_t num_posixopens;
40985 - atomic_t num_posixmkdirs;
40986 - atomic_t num_rmdirs;
40987 - atomic_t num_renames;
40988 - atomic_t num_t2renames;
40989 - atomic_t num_ffirst;
40990 - atomic_t num_fnext;
40991 - atomic_t num_fclose;
40992 - atomic_t num_hardlinks;
40993 - atomic_t num_symlinks;
40994 - atomic_t num_locks;
40995 - atomic_t num_acl_get;
40996 - atomic_t num_acl_set;
40997 + atomic_unchecked_t num_smbs_sent;
40998 + atomic_unchecked_t num_writes;
40999 + atomic_unchecked_t num_reads;
41000 + atomic_unchecked_t num_flushes;
41001 + atomic_unchecked_t num_oplock_brks;
41002 + atomic_unchecked_t num_opens;
41003 + atomic_unchecked_t num_closes;
41004 + atomic_unchecked_t num_deletes;
41005 + atomic_unchecked_t num_mkdirs;
41006 + atomic_unchecked_t num_posixopens;
41007 + atomic_unchecked_t num_posixmkdirs;
41008 + atomic_unchecked_t num_rmdirs;
41009 + atomic_unchecked_t num_renames;
41010 + atomic_unchecked_t num_t2renames;
41011 + atomic_unchecked_t num_ffirst;
41012 + atomic_unchecked_t num_fnext;
41013 + atomic_unchecked_t num_fclose;
41014 + atomic_unchecked_t num_hardlinks;
41015 + atomic_unchecked_t num_symlinks;
41016 + atomic_unchecked_t num_locks;
41017 + atomic_unchecked_t num_acl_get;
41018 + atomic_unchecked_t num_acl_set;
41019 #ifdef CONFIG_CIFS_STATS2
41020 unsigned long long time_writes;
41021 unsigned long long time_reads;
41022 @@ -628,7 +628,7 @@ convert_delimiter(char *path, char delim)
41023 }
41024
41025 #ifdef CONFIG_CIFS_STATS
41026 -#define cifs_stats_inc atomic_inc
41027 +#define cifs_stats_inc atomic_inc_unchecked
41028
41029 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
41030 unsigned int bytes)
41031 @@ -985,8 +985,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
41032 /* Various Debug counters */
41033 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
41034 #ifdef CONFIG_CIFS_STATS2
41035 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
41036 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
41037 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
41038 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
41039 #endif
41040 GLOBAL_EXTERN atomic_t smBufAllocCount;
41041 GLOBAL_EXTERN atomic_t midCount;
41042 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
41043 index 6b0e064..94e6c3c 100644
41044 --- a/fs/cifs/link.c
41045 +++ b/fs/cifs/link.c
41046 @@ -600,7 +600,7 @@ symlink_exit:
41047
41048 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
41049 {
41050 - char *p = nd_get_link(nd);
41051 + const char *p = nd_get_link(nd);
41052 if (!IS_ERR(p))
41053 kfree(p);
41054 }
41055 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
41056 index 703ef5c..2a44ed5 100644
41057 --- a/fs/cifs/misc.c
41058 +++ b/fs/cifs/misc.c
41059 @@ -156,7 +156,7 @@ cifs_buf_get(void)
41060 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
41061 atomic_inc(&bufAllocCount);
41062 #ifdef CONFIG_CIFS_STATS2
41063 - atomic_inc(&totBufAllocCount);
41064 + atomic_inc_unchecked(&totBufAllocCount);
41065 #endif /* CONFIG_CIFS_STATS2 */
41066 }
41067
41068 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
41069 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
41070 atomic_inc(&smBufAllocCount);
41071 #ifdef CONFIG_CIFS_STATS2
41072 - atomic_inc(&totSmBufAllocCount);
41073 + atomic_inc_unchecked(&totSmBufAllocCount);
41074 #endif /* CONFIG_CIFS_STATS2 */
41075
41076 }
41077 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
41078 index 6901578..d402eb5 100644
41079 --- a/fs/coda/cache.c
41080 +++ b/fs/coda/cache.c
41081 @@ -24,7 +24,7 @@
41082 #include "coda_linux.h"
41083 #include "coda_cache.h"
41084
41085 -static atomic_t permission_epoch = ATOMIC_INIT(0);
41086 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
41087
41088 /* replace or extend an acl cache hit */
41089 void coda_cache_enter(struct inode *inode, int mask)
41090 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
41091 struct coda_inode_info *cii = ITOC(inode);
41092
41093 spin_lock(&cii->c_lock);
41094 - cii->c_cached_epoch = atomic_read(&permission_epoch);
41095 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
41096 if (cii->c_uid != current_fsuid()) {
41097 cii->c_uid = current_fsuid();
41098 cii->c_cached_perm = mask;
41099 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
41100 {
41101 struct coda_inode_info *cii = ITOC(inode);
41102 spin_lock(&cii->c_lock);
41103 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
41104 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
41105 spin_unlock(&cii->c_lock);
41106 }
41107
41108 /* remove all acl caches */
41109 void coda_cache_clear_all(struct super_block *sb)
41110 {
41111 - atomic_inc(&permission_epoch);
41112 + atomic_inc_unchecked(&permission_epoch);
41113 }
41114
41115
41116 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
41117 spin_lock(&cii->c_lock);
41118 hit = (mask & cii->c_cached_perm) == mask &&
41119 cii->c_uid == current_fsuid() &&
41120 - cii->c_cached_epoch == atomic_read(&permission_epoch);
41121 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
41122 spin_unlock(&cii->c_lock);
41123
41124 return hit;
41125 diff --git a/fs/compat.c b/fs/compat.c
41126 index c987875..08771ca 100644
41127 --- a/fs/compat.c
41128 +++ b/fs/compat.c
41129 @@ -132,8 +132,8 @@ asmlinkage long compat_sys_utimes(const char __user *filename, struct compat_tim
41130 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
41131 {
41132 compat_ino_t ino = stat->ino;
41133 - typeof(ubuf->st_uid) uid = 0;
41134 - typeof(ubuf->st_gid) gid = 0;
41135 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
41136 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
41137 int err;
41138
41139 SET_UID(uid, stat->uid);
41140 @@ -504,7 +504,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
41141
41142 set_fs(KERNEL_DS);
41143 /* The __user pointer cast is valid because of the set_fs() */
41144 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
41145 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
41146 set_fs(oldfs);
41147 /* truncating is ok because it's a user address */
41148 if (!ret)
41149 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
41150 goto out;
41151
41152 ret = -EINVAL;
41153 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
41154 + if (nr_segs > UIO_MAXIOV)
41155 goto out;
41156 if (nr_segs > fast_segs) {
41157 ret = -ENOMEM;
41158 @@ -845,6 +845,7 @@ struct compat_old_linux_dirent {
41159
41160 struct compat_readdir_callback {
41161 struct compat_old_linux_dirent __user *dirent;
41162 + struct file * file;
41163 int result;
41164 };
41165
41166 @@ -862,6 +863,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
41167 buf->result = -EOVERFLOW;
41168 return -EOVERFLOW;
41169 }
41170 +
41171 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41172 + return 0;
41173 +
41174 buf->result++;
41175 dirent = buf->dirent;
41176 if (!access_ok(VERIFY_WRITE, dirent,
41177 @@ -894,6 +899,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
41178
41179 buf.result = 0;
41180 buf.dirent = dirent;
41181 + buf.file = file;
41182
41183 error = vfs_readdir(file, compat_fillonedir, &buf);
41184 if (buf.result)
41185 @@ -914,6 +920,7 @@ struct compat_linux_dirent {
41186 struct compat_getdents_callback {
41187 struct compat_linux_dirent __user *current_dir;
41188 struct compat_linux_dirent __user *previous;
41189 + struct file * file;
41190 int count;
41191 int error;
41192 };
41193 @@ -935,6 +942,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
41194 buf->error = -EOVERFLOW;
41195 return -EOVERFLOW;
41196 }
41197 +
41198 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41199 + return 0;
41200 +
41201 dirent = buf->previous;
41202 if (dirent) {
41203 if (__put_user(offset, &dirent->d_off))
41204 @@ -982,6 +993,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
41205 buf.previous = NULL;
41206 buf.count = count;
41207 buf.error = 0;
41208 + buf.file = file;
41209
41210 error = vfs_readdir(file, compat_filldir, &buf);
41211 if (error >= 0)
41212 @@ -1003,6 +1015,7 @@ out:
41213 struct compat_getdents_callback64 {
41214 struct linux_dirent64 __user *current_dir;
41215 struct linux_dirent64 __user *previous;
41216 + struct file * file;
41217 int count;
41218 int error;
41219 };
41220 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
41221 buf->error = -EINVAL; /* only used if we fail.. */
41222 if (reclen > buf->count)
41223 return -EINVAL;
41224 +
41225 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41226 + return 0;
41227 +
41228 dirent = buf->previous;
41229
41230 if (dirent) {
41231 @@ -1070,13 +1087,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
41232 buf.previous = NULL;
41233 buf.count = count;
41234 buf.error = 0;
41235 + buf.file = file;
41236
41237 error = vfs_readdir(file, compat_filldir64, &buf);
41238 if (error >= 0)
41239 error = buf.error;
41240 lastdirent = buf.previous;
41241 if (lastdirent) {
41242 - typeof(lastdirent->d_off) d_off = file->f_pos;
41243 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
41244 if (__put_user_unaligned(d_off, &lastdirent->d_off))
41245 error = -EFAULT;
41246 else
41247 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
41248 index 112e45a..b59845b 100644
41249 --- a/fs/compat_binfmt_elf.c
41250 +++ b/fs/compat_binfmt_elf.c
41251 @@ -30,11 +30,13 @@
41252 #undef elf_phdr
41253 #undef elf_shdr
41254 #undef elf_note
41255 +#undef elf_dyn
41256 #undef elf_addr_t
41257 #define elfhdr elf32_hdr
41258 #define elf_phdr elf32_phdr
41259 #define elf_shdr elf32_shdr
41260 #define elf_note elf32_note
41261 +#define elf_dyn Elf32_Dyn
41262 #define elf_addr_t Elf32_Addr
41263
41264 /*
41265 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
41266 index 51352de..93292ff 100644
41267 --- a/fs/compat_ioctl.c
41268 +++ b/fs/compat_ioctl.c
41269 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
41270
41271 err = get_user(palp, &up->palette);
41272 err |= get_user(length, &up->length);
41273 + if (err)
41274 + return -EFAULT;
41275
41276 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
41277 err = put_user(compat_ptr(palp), &up_native->palette);
41278 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
41279 return -EFAULT;
41280 if (__get_user(udata, &ss32->iomem_base))
41281 return -EFAULT;
41282 - ss.iomem_base = compat_ptr(udata);
41283 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
41284 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
41285 __get_user(ss.port_high, &ss32->port_high))
41286 return -EFAULT;
41287 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
41288 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
41289 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
41290 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
41291 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
41292 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
41293 return -EFAULT;
41294
41295 return ioctl_preallocate(file, p);
41296 @@ -1644,8 +1646,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
41297 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
41298 {
41299 unsigned int a, b;
41300 - a = *(unsigned int *)p;
41301 - b = *(unsigned int *)q;
41302 + a = *(const unsigned int *)p;
41303 + b = *(const unsigned int *)q;
41304 if (a > b)
41305 return 1;
41306 if (a < b)
41307 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
41308 index 9a37a9b..35792b6 100644
41309 --- a/fs/configfs/dir.c
41310 +++ b/fs/configfs/dir.c
41311 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
41312 }
41313 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
41314 struct configfs_dirent *next;
41315 - const char * name;
41316 + const unsigned char * name;
41317 + char d_name[sizeof(next->s_dentry->d_iname)];
41318 int len;
41319 struct inode *inode = NULL;
41320
41321 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
41322 continue;
41323
41324 name = configfs_get_name(next);
41325 - len = strlen(name);
41326 + if (next->s_dentry && name == next->s_dentry->d_iname) {
41327 + len = next->s_dentry->d_name.len;
41328 + memcpy(d_name, name, len);
41329 + name = d_name;
41330 + } else
41331 + len = strlen(name);
41332
41333 /*
41334 * We'll have a dentry and an inode for
41335 diff --git a/fs/dcache.c b/fs/dcache.c
41336 index f7908ae..920a680 100644
41337 --- a/fs/dcache.c
41338 +++ b/fs/dcache.c
41339 @@ -3042,7 +3042,7 @@ void __init vfs_caches_init(unsigned long mempages)
41340 mempages -= reserve;
41341
41342 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
41343 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
41344 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
41345
41346 dcache_init();
41347 inode_init();
41348 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
41349 index f3a257d..715ac0f 100644
41350 --- a/fs/debugfs/inode.c
41351 +++ b/fs/debugfs/inode.c
41352 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
41353 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
41354 {
41355 return debugfs_create_file(name,
41356 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
41357 + S_IFDIR | S_IRWXU,
41358 +#else
41359 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
41360 +#endif
41361 parent, NULL, NULL);
41362 }
41363 EXPORT_SYMBOL_GPL(debugfs_create_dir);
41364 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
41365 index d2039ca..a766407 100644
41366 --- a/fs/ecryptfs/inode.c
41367 +++ b/fs/ecryptfs/inode.c
41368 @@ -691,7 +691,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
41369 old_fs = get_fs();
41370 set_fs(get_ds());
41371 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
41372 - (char __user *)lower_buf,
41373 + (char __force_user *)lower_buf,
41374 lower_bufsiz);
41375 set_fs(old_fs);
41376 if (rc < 0)
41377 @@ -737,7 +737,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41378 }
41379 old_fs = get_fs();
41380 set_fs(get_ds());
41381 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
41382 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
41383 set_fs(old_fs);
41384 if (rc < 0) {
41385 kfree(buf);
41386 @@ -752,7 +752,7 @@ out:
41387 static void
41388 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
41389 {
41390 - char *buf = nd_get_link(nd);
41391 + const char *buf = nd_get_link(nd);
41392 if (!IS_ERR(buf)) {
41393 /* Free the char* */
41394 kfree(buf);
41395 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
41396 index 0dc5a3d..d3cdeea 100644
41397 --- a/fs/ecryptfs/miscdev.c
41398 +++ b/fs/ecryptfs/miscdev.c
41399 @@ -328,7 +328,7 @@ check_list:
41400 goto out_unlock_msg_ctx;
41401 i = 5;
41402 if (msg_ctx->msg) {
41403 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
41404 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
41405 goto out_unlock_msg_ctx;
41406 i += packet_length_size;
41407 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
41408 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
41409 index 54eb14c..7d040a8 100644
41410 --- a/fs/ecryptfs/read_write.c
41411 +++ b/fs/ecryptfs/read_write.c
41412 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
41413 return -EIO;
41414 fs_save = get_fs();
41415 set_fs(get_ds());
41416 - rc = vfs_write(lower_file, data, size, &offset);
41417 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
41418 set_fs(fs_save);
41419 mark_inode_dirty_sync(ecryptfs_inode);
41420 return rc;
41421 @@ -130,7 +130,7 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset,
41422 pgoff_t ecryptfs_page_idx = (pos >> PAGE_CACHE_SHIFT);
41423 size_t start_offset_in_page = (pos & ~PAGE_CACHE_MASK);
41424 size_t num_bytes = (PAGE_CACHE_SIZE - start_offset_in_page);
41425 - size_t total_remaining_bytes = ((offset + size) - pos);
41426 + loff_t total_remaining_bytes = ((offset + size) - pos);
41427
41428 if (fatal_signal_pending(current)) {
41429 rc = -EINTR;
41430 @@ -141,7 +141,7 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset,
41431 num_bytes = total_remaining_bytes;
41432 if (pos < offset) {
41433 /* remaining zeros to write, up to destination offset */
41434 - size_t total_remaining_zeros = (offset - pos);
41435 + loff_t total_remaining_zeros = (offset - pos);
41436
41437 if (num_bytes > total_remaining_zeros)
41438 num_bytes = total_remaining_zeros;
41439 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
41440 return -EIO;
41441 fs_save = get_fs();
41442 set_fs(get_ds());
41443 - rc = vfs_read(lower_file, data, size, &offset);
41444 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
41445 set_fs(fs_save);
41446 return rc;
41447 }
41448 diff --git a/fs/exec.c b/fs/exec.c
41449 index 3625464..902bd4a 100644
41450 --- a/fs/exec.c
41451 +++ b/fs/exec.c
41452 @@ -55,12 +55,28 @@
41453 #include <linux/pipe_fs_i.h>
41454 #include <linux/oom.h>
41455 #include <linux/compat.h>
41456 +#include <linux/random.h>
41457 +#include <linux/seq_file.h>
41458 +
41459 +#ifdef CONFIG_PAX_REFCOUNT
41460 +#include <linux/kallsyms.h>
41461 +#include <linux/kdebug.h>
41462 +#endif
41463
41464 #include <asm/uaccess.h>
41465 #include <asm/mmu_context.h>
41466 #include <asm/tlb.h>
41467 #include "internal.h"
41468
41469 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
41470 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
41471 +#endif
41472 +
41473 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
41474 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
41475 +EXPORT_SYMBOL(pax_set_initial_flags_func);
41476 +#endif
41477 +
41478 int core_uses_pid;
41479 char core_pattern[CORENAME_MAX_SIZE] = "core";
41480 unsigned int core_pipe_limit;
41481 @@ -70,7 +86,7 @@ struct core_name {
41482 char *corename;
41483 int used, size;
41484 };
41485 -static atomic_t call_count = ATOMIC_INIT(1);
41486 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
41487
41488 /* The maximal length of core_pattern is also specified in sysctl.c */
41489
41490 @@ -188,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
41491 int write)
41492 {
41493 struct page *page;
41494 - int ret;
41495
41496 -#ifdef CONFIG_STACK_GROWSUP
41497 - if (write) {
41498 - ret = expand_downwards(bprm->vma, pos);
41499 - if (ret < 0)
41500 - return NULL;
41501 - }
41502 -#endif
41503 - ret = get_user_pages(current, bprm->mm, pos,
41504 - 1, write, 1, &page, NULL);
41505 - if (ret <= 0)
41506 + if (0 > expand_downwards(bprm->vma, pos))
41507 + return NULL;
41508 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
41509 return NULL;
41510
41511 if (write) {
41512 @@ -274,6 +282,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
41513 vma->vm_end = STACK_TOP_MAX;
41514 vma->vm_start = vma->vm_end - PAGE_SIZE;
41515 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
41516 +
41517 +#ifdef CONFIG_PAX_SEGMEXEC
41518 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
41519 +#endif
41520 +
41521 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
41522 INIT_LIST_HEAD(&vma->anon_vma_chain);
41523
41524 @@ -288,6 +301,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
41525 mm->stack_vm = mm->total_vm = 1;
41526 up_write(&mm->mmap_sem);
41527 bprm->p = vma->vm_end - sizeof(void *);
41528 +
41529 +#ifdef CONFIG_PAX_RANDUSTACK
41530 + if (randomize_va_space)
41531 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
41532 +#endif
41533 +
41534 return 0;
41535 err:
41536 up_write(&mm->mmap_sem);
41537 @@ -396,19 +415,7 @@ err:
41538 return err;
41539 }
41540
41541 -struct user_arg_ptr {
41542 -#ifdef CONFIG_COMPAT
41543 - bool is_compat;
41544 -#endif
41545 - union {
41546 - const char __user *const __user *native;
41547 -#ifdef CONFIG_COMPAT
41548 - compat_uptr_t __user *compat;
41549 -#endif
41550 - } ptr;
41551 -};
41552 -
41553 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41554 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41555 {
41556 const char __user *native;
41557
41558 @@ -417,14 +424,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41559 compat_uptr_t compat;
41560
41561 if (get_user(compat, argv.ptr.compat + nr))
41562 - return ERR_PTR(-EFAULT);
41563 + return (const char __force_user *)ERR_PTR(-EFAULT);
41564
41565 return compat_ptr(compat);
41566 }
41567 #endif
41568
41569 if (get_user(native, argv.ptr.native + nr))
41570 - return ERR_PTR(-EFAULT);
41571 + return (const char __force_user *)ERR_PTR(-EFAULT);
41572
41573 return native;
41574 }
41575 @@ -443,7 +450,7 @@ static int count(struct user_arg_ptr argv, int max)
41576 if (!p)
41577 break;
41578
41579 - if (IS_ERR(p))
41580 + if (IS_ERR((const char __force_kernel *)p))
41581 return -EFAULT;
41582
41583 if (i++ >= max)
41584 @@ -477,7 +484,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
41585
41586 ret = -EFAULT;
41587 str = get_user_arg_ptr(argv, argc);
41588 - if (IS_ERR(str))
41589 + if (IS_ERR((const char __force_kernel *)str))
41590 goto out;
41591
41592 len = strnlen_user(str, MAX_ARG_STRLEN);
41593 @@ -559,7 +566,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
41594 int r;
41595 mm_segment_t oldfs = get_fs();
41596 struct user_arg_ptr argv = {
41597 - .ptr.native = (const char __user *const __user *)__argv,
41598 + .ptr.native = (const char __force_user *const __force_user *)__argv,
41599 };
41600
41601 set_fs(KERNEL_DS);
41602 @@ -594,7 +601,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
41603 unsigned long new_end = old_end - shift;
41604 struct mmu_gather tlb;
41605
41606 - BUG_ON(new_start > new_end);
41607 + if (new_start >= new_end || new_start < mmap_min_addr)
41608 + return -ENOMEM;
41609
41610 /*
41611 * ensure there are no vmas between where we want to go
41612 @@ -603,6 +611,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
41613 if (vma != find_vma(mm, new_start))
41614 return -EFAULT;
41615
41616 +#ifdef CONFIG_PAX_SEGMEXEC
41617 + BUG_ON(pax_find_mirror_vma(vma));
41618 +#endif
41619 +
41620 /*
41621 * cover the whole range: [new_start, old_end)
41622 */
41623 @@ -683,10 +695,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
41624 stack_top = arch_align_stack(stack_top);
41625 stack_top = PAGE_ALIGN(stack_top);
41626
41627 - if (unlikely(stack_top < mmap_min_addr) ||
41628 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
41629 - return -ENOMEM;
41630 -
41631 stack_shift = vma->vm_end - stack_top;
41632
41633 bprm->p -= stack_shift;
41634 @@ -698,8 +706,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
41635 bprm->exec -= stack_shift;
41636
41637 down_write(&mm->mmap_sem);
41638 +
41639 + /* Move stack pages down in memory. */
41640 + if (stack_shift) {
41641 + ret = shift_arg_pages(vma, stack_shift);
41642 + if (ret)
41643 + goto out_unlock;
41644 + }
41645 +
41646 vm_flags = VM_STACK_FLAGS;
41647
41648 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41649 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41650 + vm_flags &= ~VM_EXEC;
41651 +
41652 +#ifdef CONFIG_PAX_MPROTECT
41653 + if (mm->pax_flags & MF_PAX_MPROTECT)
41654 + vm_flags &= ~VM_MAYEXEC;
41655 +#endif
41656 +
41657 + }
41658 +#endif
41659 +
41660 /*
41661 * Adjust stack execute permissions; explicitly enable for
41662 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
41663 @@ -718,13 +746,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
41664 goto out_unlock;
41665 BUG_ON(prev != vma);
41666
41667 - /* Move stack pages down in memory. */
41668 - if (stack_shift) {
41669 - ret = shift_arg_pages(vma, stack_shift);
41670 - if (ret)
41671 - goto out_unlock;
41672 - }
41673 -
41674 /* mprotect_fixup is overkill to remove the temporary stack flags */
41675 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
41676
41677 @@ -805,7 +826,7 @@ int kernel_read(struct file *file, loff_t offset,
41678 old_fs = get_fs();
41679 set_fs(get_ds());
41680 /* The cast to a user pointer is valid due to the set_fs() */
41681 - result = vfs_read(file, (void __user *)addr, count, &pos);
41682 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
41683 set_fs(old_fs);
41684 return result;
41685 }
41686 @@ -1247,7 +1268,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
41687 }
41688 rcu_read_unlock();
41689
41690 - if (p->fs->users > n_fs) {
41691 + if (atomic_read(&p->fs->users) > n_fs) {
41692 bprm->unsafe |= LSM_UNSAFE_SHARE;
41693 } else {
41694 res = -EAGAIN;
41695 @@ -1442,6 +1463,10 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
41696
41697 EXPORT_SYMBOL(search_binary_handler);
41698
41699 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
41700 +atomic64_unchecked_t global_exec_counter = ATOMIC64_INIT(0);
41701 +#endif
41702 +
41703 /*
41704 * sys_execve() executes a new program.
41705 */
41706 @@ -1450,6 +1475,11 @@ static int do_execve_common(const char *filename,
41707 struct user_arg_ptr envp,
41708 struct pt_regs *regs)
41709 {
41710 +#ifdef CONFIG_GRKERNSEC
41711 + struct file *old_exec_file;
41712 + struct acl_subject_label *old_acl;
41713 + struct rlimit old_rlim[RLIM_NLIMITS];
41714 +#endif
41715 struct linux_binprm *bprm;
41716 struct file *file;
41717 struct files_struct *displaced;
41718 @@ -1457,6 +1487,8 @@ static int do_execve_common(const char *filename,
41719 int retval;
41720 const struct cred *cred = current_cred();
41721
41722 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
41723 +
41724 /*
41725 * We move the actual failure in case of RLIMIT_NPROC excess from
41726 * set*uid() to execve() because too many poorly written programs
41727 @@ -1497,12 +1529,27 @@ static int do_execve_common(const char *filename,
41728 if (IS_ERR(file))
41729 goto out_unmark;
41730
41731 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
41732 + retval = -EPERM;
41733 + goto out_file;
41734 + }
41735 +
41736 sched_exec();
41737
41738 bprm->file = file;
41739 bprm->filename = filename;
41740 bprm->interp = filename;
41741
41742 + if (gr_process_user_ban()) {
41743 + retval = -EPERM;
41744 + goto out_file;
41745 + }
41746 +
41747 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
41748 + retval = -EACCES;
41749 + goto out_file;
41750 + }
41751 +
41752 retval = bprm_mm_init(bprm);
41753 if (retval)
41754 goto out_file;
41755 @@ -1532,11 +1579,46 @@ static int do_execve_common(const char *filename,
41756 if (retval < 0)
41757 goto out;
41758
41759 + if (!gr_tpe_allow(file)) {
41760 + retval = -EACCES;
41761 + goto out;
41762 + }
41763 +
41764 + if (gr_check_crash_exec(file)) {
41765 + retval = -EACCES;
41766 + goto out;
41767 + }
41768 +
41769 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
41770 +
41771 + gr_handle_exec_args(bprm, argv);
41772 +
41773 +#ifdef CONFIG_GRKERNSEC
41774 + old_acl = current->acl;
41775 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
41776 + old_exec_file = current->exec_file;
41777 + get_file(file);
41778 + current->exec_file = file;
41779 +#endif
41780 +
41781 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
41782 + bprm->unsafe);
41783 + if (retval < 0)
41784 + goto out_fail;
41785 +
41786 retval = search_binary_handler(bprm,regs);
41787 if (retval < 0)
41788 - goto out;
41789 + goto out_fail;
41790 +#ifdef CONFIG_GRKERNSEC
41791 + if (old_exec_file)
41792 + fput(old_exec_file);
41793 +#endif
41794
41795 /* execve succeeded */
41796 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
41797 + current->exec_id = atomic64_inc_return_unchecked(&global_exec_counter);
41798 +#endif
41799 +
41800 current->fs->in_exec = 0;
41801 current->in_execve = 0;
41802 acct_update_integrals(current);
41803 @@ -1545,6 +1627,14 @@ static int do_execve_common(const char *filename,
41804 put_files_struct(displaced);
41805 return retval;
41806
41807 +out_fail:
41808 +#ifdef CONFIG_GRKERNSEC
41809 + current->acl = old_acl;
41810 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
41811 + fput(current->exec_file);
41812 + current->exec_file = old_exec_file;
41813 +#endif
41814 +
41815 out:
41816 if (bprm->mm) {
41817 acct_arg_size(bprm, 0);
41818 @@ -1618,7 +1708,7 @@ static int expand_corename(struct core_name *cn)
41819 {
41820 char *old_corename = cn->corename;
41821
41822 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
41823 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
41824 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
41825
41826 if (!cn->corename) {
41827 @@ -1715,7 +1805,7 @@ static int format_corename(struct core_name *cn, long signr)
41828 int pid_in_pattern = 0;
41829 int err = 0;
41830
41831 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
41832 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
41833 cn->corename = kmalloc(cn->size, GFP_KERNEL);
41834 cn->used = 0;
41835
41836 @@ -1812,6 +1902,218 @@ out:
41837 return ispipe;
41838 }
41839
41840 +int pax_check_flags(unsigned long *flags)
41841 +{
41842 + int retval = 0;
41843 +
41844 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
41845 + if (*flags & MF_PAX_SEGMEXEC)
41846 + {
41847 + *flags &= ~MF_PAX_SEGMEXEC;
41848 + retval = -EINVAL;
41849 + }
41850 +#endif
41851 +
41852 + if ((*flags & MF_PAX_PAGEEXEC)
41853 +
41854 +#ifdef CONFIG_PAX_PAGEEXEC
41855 + && (*flags & MF_PAX_SEGMEXEC)
41856 +#endif
41857 +
41858 + )
41859 + {
41860 + *flags &= ~MF_PAX_PAGEEXEC;
41861 + retval = -EINVAL;
41862 + }
41863 +
41864 + if ((*flags & MF_PAX_MPROTECT)
41865 +
41866 +#ifdef CONFIG_PAX_MPROTECT
41867 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
41868 +#endif
41869 +
41870 + )
41871 + {
41872 + *flags &= ~MF_PAX_MPROTECT;
41873 + retval = -EINVAL;
41874 + }
41875 +
41876 + if ((*flags & MF_PAX_EMUTRAMP)
41877 +
41878 +#ifdef CONFIG_PAX_EMUTRAMP
41879 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
41880 +#endif
41881 +
41882 + )
41883 + {
41884 + *flags &= ~MF_PAX_EMUTRAMP;
41885 + retval = -EINVAL;
41886 + }
41887 +
41888 + return retval;
41889 +}
41890 +
41891 +EXPORT_SYMBOL(pax_check_flags);
41892 +
41893 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41894 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
41895 +{
41896 + struct task_struct *tsk = current;
41897 + struct mm_struct *mm = current->mm;
41898 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
41899 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
41900 + char *path_exec = NULL;
41901 + char *path_fault = NULL;
41902 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
41903 +
41904 + if (buffer_exec && buffer_fault) {
41905 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
41906 +
41907 + down_read(&mm->mmap_sem);
41908 + vma = mm->mmap;
41909 + while (vma && (!vma_exec || !vma_fault)) {
41910 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
41911 + vma_exec = vma;
41912 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
41913 + vma_fault = vma;
41914 + vma = vma->vm_next;
41915 + }
41916 + if (vma_exec) {
41917 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
41918 + if (IS_ERR(path_exec))
41919 + path_exec = "<path too long>";
41920 + else {
41921 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
41922 + if (path_exec) {
41923 + *path_exec = 0;
41924 + path_exec = buffer_exec;
41925 + } else
41926 + path_exec = "<path too long>";
41927 + }
41928 + }
41929 + if (vma_fault) {
41930 + start = vma_fault->vm_start;
41931 + end = vma_fault->vm_end;
41932 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
41933 + if (vma_fault->vm_file) {
41934 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
41935 + if (IS_ERR(path_fault))
41936 + path_fault = "<path too long>";
41937 + else {
41938 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
41939 + if (path_fault) {
41940 + *path_fault = 0;
41941 + path_fault = buffer_fault;
41942 + } else
41943 + path_fault = "<path too long>";
41944 + }
41945 + } else
41946 + path_fault = "<anonymous mapping>";
41947 + }
41948 + up_read(&mm->mmap_sem);
41949 + }
41950 + if (tsk->signal->curr_ip)
41951 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
41952 + else
41953 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
41954 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
41955 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
41956 + task_uid(tsk), task_euid(tsk), pc, sp);
41957 + free_page((unsigned long)buffer_exec);
41958 + free_page((unsigned long)buffer_fault);
41959 + pax_report_insns(regs, pc, sp);
41960 + do_coredump(SIGKILL, SIGKILL, regs);
41961 +}
41962 +#endif
41963 +
41964 +#ifdef CONFIG_PAX_REFCOUNT
41965 +void pax_report_refcount_overflow(struct pt_regs *regs)
41966 +{
41967 + if (current->signal->curr_ip)
41968 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
41969 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
41970 + else
41971 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
41972 + current->comm, task_pid_nr(current), current_uid(), current_euid());
41973 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
41974 + show_regs(regs);
41975 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
41976 +}
41977 +#endif
41978 +
41979 +#ifdef CONFIG_PAX_USERCOPY
41980 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
41981 +int object_is_on_stack(const void *obj, unsigned long len)
41982 +{
41983 + const void * const stack = task_stack_page(current);
41984 + const void * const stackend = stack + THREAD_SIZE;
41985 +
41986 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
41987 + const void *frame = NULL;
41988 + const void *oldframe;
41989 +#endif
41990 +
41991 + if (obj + len < obj)
41992 + return -1;
41993 +
41994 + if (obj + len <= stack || stackend <= obj)
41995 + return 0;
41996 +
41997 + if (obj < stack || stackend < obj + len)
41998 + return -1;
41999 +
42000 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
42001 + oldframe = __builtin_frame_address(1);
42002 + if (oldframe)
42003 + frame = __builtin_frame_address(2);
42004 + /*
42005 + low ----------------------------------------------> high
42006 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
42007 + ^----------------^
42008 + allow copies only within here
42009 + */
42010 + while (stack <= frame && frame < stackend) {
42011 + /* if obj + len extends past the last frame, this
42012 + check won't pass and the next frame will be 0,
42013 + causing us to bail out and correctly report
42014 + the copy as invalid
42015 + */
42016 + if (obj + len <= frame)
42017 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
42018 + oldframe = frame;
42019 + frame = *(const void * const *)frame;
42020 + }
42021 + return -1;
42022 +#else
42023 + return 1;
42024 +#endif
42025 +}
42026 +
42027 +NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
42028 +{
42029 + if (current->signal->curr_ip)
42030 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
42031 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
42032 + else
42033 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
42034 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
42035 + dump_stack();
42036 + gr_handle_kernel_exploit();
42037 + do_group_exit(SIGKILL);
42038 +}
42039 +#endif
42040 +
42041 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
42042 +void pax_track_stack(void)
42043 +{
42044 + unsigned long sp = (unsigned long)&sp;
42045 + if (sp < current_thread_info()->lowest_stack &&
42046 + sp > (unsigned long)task_stack_page(current))
42047 + current_thread_info()->lowest_stack = sp;
42048 +}
42049 +EXPORT_SYMBOL(pax_track_stack);
42050 +#endif
42051 +
42052 static int zap_process(struct task_struct *start, int exit_code)
42053 {
42054 struct task_struct *t;
42055 @@ -2023,17 +2325,17 @@ static void wait_for_dump_helpers(struct file *file)
42056 pipe = file->f_path.dentry->d_inode->i_pipe;
42057
42058 pipe_lock(pipe);
42059 - pipe->readers++;
42060 - pipe->writers--;
42061 + atomic_inc(&pipe->readers);
42062 + atomic_dec(&pipe->writers);
42063
42064 - while ((pipe->readers > 1) && (!signal_pending(current))) {
42065 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
42066 wake_up_interruptible_sync(&pipe->wait);
42067 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
42068 pipe_wait(pipe);
42069 }
42070
42071 - pipe->readers--;
42072 - pipe->writers++;
42073 + atomic_dec(&pipe->readers);
42074 + atomic_inc(&pipe->writers);
42075 pipe_unlock(pipe);
42076
42077 }
42078 @@ -2094,7 +2396,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42079 int retval = 0;
42080 int flag = 0;
42081 int ispipe;
42082 - static atomic_t core_dump_count = ATOMIC_INIT(0);
42083 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
42084 struct coredump_params cprm = {
42085 .signr = signr,
42086 .regs = regs,
42087 @@ -2109,6 +2411,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42088
42089 audit_core_dumps(signr);
42090
42091 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
42092 + gr_handle_brute_attach(current, cprm.mm_flags);
42093 +
42094 binfmt = mm->binfmt;
42095 if (!binfmt || !binfmt->core_dump)
42096 goto fail;
42097 @@ -2176,7 +2481,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42098 }
42099 cprm.limit = RLIM_INFINITY;
42100
42101 - dump_count = atomic_inc_return(&core_dump_count);
42102 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
42103 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
42104 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
42105 task_tgid_vnr(current), current->comm);
42106 @@ -2203,6 +2508,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42107 } else {
42108 struct inode *inode;
42109
42110 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
42111 +
42112 if (cprm.limit < binfmt->min_coredump)
42113 goto fail_unlock;
42114
42115 @@ -2246,7 +2553,7 @@ close_fail:
42116 filp_close(cprm.file, NULL);
42117 fail_dropcount:
42118 if (ispipe)
42119 - atomic_dec(&core_dump_count);
42120 + atomic_dec_unchecked(&core_dump_count);
42121 fail_unlock:
42122 kfree(cn.corename);
42123 fail_corename:
42124 @@ -2265,7 +2572,7 @@ fail:
42125 */
42126 int dump_write(struct file *file, const void *addr, int nr)
42127 {
42128 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
42129 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
42130 }
42131 EXPORT_SYMBOL(dump_write);
42132
42133 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
42134 index a8cbe1b..fed04cb 100644
42135 --- a/fs/ext2/balloc.c
42136 +++ b/fs/ext2/balloc.c
42137 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
42138
42139 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
42140 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
42141 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
42142 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
42143 sbi->s_resuid != current_fsuid() &&
42144 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
42145 return 0;
42146 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
42147 index a203892..4e64db5 100644
42148 --- a/fs/ext3/balloc.c
42149 +++ b/fs/ext3/balloc.c
42150 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
42151
42152 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
42153 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
42154 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
42155 + if (free_blocks < root_blocks + 1 &&
42156 !use_reservation && sbi->s_resuid != current_fsuid() &&
42157 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
42158 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
42159 + !capable_nolog(CAP_SYS_RESOURCE)) {
42160 return 0;
42161 }
42162 return 1;
42163 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
42164 index 12ccacd..a6035fce0 100644
42165 --- a/fs/ext4/balloc.c
42166 +++ b/fs/ext4/balloc.c
42167 @@ -436,8 +436,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
42168 /* Hm, nope. Are (enough) root reserved clusters available? */
42169 if (sbi->s_resuid == current_fsuid() ||
42170 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
42171 - capable(CAP_SYS_RESOURCE) ||
42172 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
42173 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
42174 + capable_nolog(CAP_SYS_RESOURCE)) {
42175
42176 if (free_clusters >= (nclusters + dirty_clusters))
42177 return 1;
42178 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
42179 index 5b0e26a..0aa002d 100644
42180 --- a/fs/ext4/ext4.h
42181 +++ b/fs/ext4/ext4.h
42182 @@ -1208,19 +1208,19 @@ struct ext4_sb_info {
42183 unsigned long s_mb_last_start;
42184
42185 /* stats for buddy allocator */
42186 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
42187 - atomic_t s_bal_success; /* we found long enough chunks */
42188 - atomic_t s_bal_allocated; /* in blocks */
42189 - atomic_t s_bal_ex_scanned; /* total extents scanned */
42190 - atomic_t s_bal_goals; /* goal hits */
42191 - atomic_t s_bal_breaks; /* too long searches */
42192 - atomic_t s_bal_2orders; /* 2^order hits */
42193 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
42194 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
42195 + atomic_unchecked_t s_bal_allocated; /* in blocks */
42196 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
42197 + atomic_unchecked_t s_bal_goals; /* goal hits */
42198 + atomic_unchecked_t s_bal_breaks; /* too long searches */
42199 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
42200 spinlock_t s_bal_lock;
42201 unsigned long s_mb_buddies_generated;
42202 unsigned long long s_mb_generation_time;
42203 - atomic_t s_mb_lost_chunks;
42204 - atomic_t s_mb_preallocated;
42205 - atomic_t s_mb_discarded;
42206 + atomic_unchecked_t s_mb_lost_chunks;
42207 + atomic_unchecked_t s_mb_preallocated;
42208 + atomic_unchecked_t s_mb_discarded;
42209 atomic_t s_lock_busy;
42210
42211 /* locality groups */
42212 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
42213 index e2d8be8..c7f0ce9 100644
42214 --- a/fs/ext4/mballoc.c
42215 +++ b/fs/ext4/mballoc.c
42216 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
42217 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
42218
42219 if (EXT4_SB(sb)->s_mb_stats)
42220 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
42221 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
42222
42223 break;
42224 }
42225 @@ -2088,7 +2088,7 @@ repeat:
42226 ac->ac_status = AC_STATUS_CONTINUE;
42227 ac->ac_flags |= EXT4_MB_HINT_FIRST;
42228 cr = 3;
42229 - atomic_inc(&sbi->s_mb_lost_chunks);
42230 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
42231 goto repeat;
42232 }
42233 }
42234 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
42235 if (sbi->s_mb_stats) {
42236 ext4_msg(sb, KERN_INFO,
42237 "mballoc: %u blocks %u reqs (%u success)",
42238 - atomic_read(&sbi->s_bal_allocated),
42239 - atomic_read(&sbi->s_bal_reqs),
42240 - atomic_read(&sbi->s_bal_success));
42241 + atomic_read_unchecked(&sbi->s_bal_allocated),
42242 + atomic_read_unchecked(&sbi->s_bal_reqs),
42243 + atomic_read_unchecked(&sbi->s_bal_success));
42244 ext4_msg(sb, KERN_INFO,
42245 "mballoc: %u extents scanned, %u goal hits, "
42246 "%u 2^N hits, %u breaks, %u lost",
42247 - atomic_read(&sbi->s_bal_ex_scanned),
42248 - atomic_read(&sbi->s_bal_goals),
42249 - atomic_read(&sbi->s_bal_2orders),
42250 - atomic_read(&sbi->s_bal_breaks),
42251 - atomic_read(&sbi->s_mb_lost_chunks));
42252 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
42253 + atomic_read_unchecked(&sbi->s_bal_goals),
42254 + atomic_read_unchecked(&sbi->s_bal_2orders),
42255 + atomic_read_unchecked(&sbi->s_bal_breaks),
42256 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
42257 ext4_msg(sb, KERN_INFO,
42258 "mballoc: %lu generated and it took %Lu",
42259 sbi->s_mb_buddies_generated,
42260 sbi->s_mb_generation_time);
42261 ext4_msg(sb, KERN_INFO,
42262 "mballoc: %u preallocated, %u discarded",
42263 - atomic_read(&sbi->s_mb_preallocated),
42264 - atomic_read(&sbi->s_mb_discarded));
42265 + atomic_read_unchecked(&sbi->s_mb_preallocated),
42266 + atomic_read_unchecked(&sbi->s_mb_discarded));
42267 }
42268
42269 free_percpu(sbi->s_locality_groups);
42270 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
42271 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
42272
42273 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
42274 - atomic_inc(&sbi->s_bal_reqs);
42275 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
42276 + atomic_inc_unchecked(&sbi->s_bal_reqs);
42277 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
42278 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
42279 - atomic_inc(&sbi->s_bal_success);
42280 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
42281 + atomic_inc_unchecked(&sbi->s_bal_success);
42282 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
42283 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
42284 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
42285 - atomic_inc(&sbi->s_bal_goals);
42286 + atomic_inc_unchecked(&sbi->s_bal_goals);
42287 if (ac->ac_found > sbi->s_mb_max_to_scan)
42288 - atomic_inc(&sbi->s_bal_breaks);
42289 + atomic_inc_unchecked(&sbi->s_bal_breaks);
42290 }
42291
42292 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
42293 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
42294 trace_ext4_mb_new_inode_pa(ac, pa);
42295
42296 ext4_mb_use_inode_pa(ac, pa);
42297 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
42298 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
42299
42300 ei = EXT4_I(ac->ac_inode);
42301 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
42302 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
42303 trace_ext4_mb_new_group_pa(ac, pa);
42304
42305 ext4_mb_use_group_pa(ac, pa);
42306 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42307 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42308
42309 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
42310 lg = ac->ac_lg;
42311 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
42312 * from the bitmap and continue.
42313 */
42314 }
42315 - atomic_add(free, &sbi->s_mb_discarded);
42316 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
42317
42318 return err;
42319 }
42320 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
42321 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
42322 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
42323 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
42324 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
42325 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
42326 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
42327
42328 return 0;
42329 diff --git a/fs/fcntl.c b/fs/fcntl.c
42330 index 22764c7..86372c9 100644
42331 --- a/fs/fcntl.c
42332 +++ b/fs/fcntl.c
42333 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
42334 if (err)
42335 return err;
42336
42337 + if (gr_handle_chroot_fowner(pid, type))
42338 + return -ENOENT;
42339 + if (gr_check_protected_task_fowner(pid, type))
42340 + return -EACCES;
42341 +
42342 f_modown(filp, pid, type, force);
42343 return 0;
42344 }
42345 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
42346
42347 static int f_setown_ex(struct file *filp, unsigned long arg)
42348 {
42349 - struct f_owner_ex * __user owner_p = (void * __user)arg;
42350 + struct f_owner_ex __user *owner_p = (void __user *)arg;
42351 struct f_owner_ex owner;
42352 struct pid *pid;
42353 int type;
42354 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
42355
42356 static int f_getown_ex(struct file *filp, unsigned long arg)
42357 {
42358 - struct f_owner_ex * __user owner_p = (void * __user)arg;
42359 + struct f_owner_ex __user *owner_p = (void __user *)arg;
42360 struct f_owner_ex owner;
42361 int ret = 0;
42362
42363 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
42364 switch (cmd) {
42365 case F_DUPFD:
42366 case F_DUPFD_CLOEXEC:
42367 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
42368 if (arg >= rlimit(RLIMIT_NOFILE))
42369 break;
42370 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
42371 diff --git a/fs/fifo.c b/fs/fifo.c
42372 index b1a524d..4ee270e 100644
42373 --- a/fs/fifo.c
42374 +++ b/fs/fifo.c
42375 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
42376 */
42377 filp->f_op = &read_pipefifo_fops;
42378 pipe->r_counter++;
42379 - if (pipe->readers++ == 0)
42380 + if (atomic_inc_return(&pipe->readers) == 1)
42381 wake_up_partner(inode);
42382
42383 - if (!pipe->writers) {
42384 + if (!atomic_read(&pipe->writers)) {
42385 if ((filp->f_flags & O_NONBLOCK)) {
42386 /* suppress POLLHUP until we have
42387 * seen a writer */
42388 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
42389 * errno=ENXIO when there is no process reading the FIFO.
42390 */
42391 ret = -ENXIO;
42392 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
42393 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
42394 goto err;
42395
42396 filp->f_op = &write_pipefifo_fops;
42397 pipe->w_counter++;
42398 - if (!pipe->writers++)
42399 + if (atomic_inc_return(&pipe->writers) == 1)
42400 wake_up_partner(inode);
42401
42402 - if (!pipe->readers) {
42403 + if (!atomic_read(&pipe->readers)) {
42404 wait_for_partner(inode, &pipe->r_counter);
42405 if (signal_pending(current))
42406 goto err_wr;
42407 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
42408 */
42409 filp->f_op = &rdwr_pipefifo_fops;
42410
42411 - pipe->readers++;
42412 - pipe->writers++;
42413 + atomic_inc(&pipe->readers);
42414 + atomic_inc(&pipe->writers);
42415 pipe->r_counter++;
42416 pipe->w_counter++;
42417 - if (pipe->readers == 1 || pipe->writers == 1)
42418 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
42419 wake_up_partner(inode);
42420 break;
42421
42422 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
42423 return 0;
42424
42425 err_rd:
42426 - if (!--pipe->readers)
42427 + if (atomic_dec_and_test(&pipe->readers))
42428 wake_up_interruptible(&pipe->wait);
42429 ret = -ERESTARTSYS;
42430 goto err;
42431
42432 err_wr:
42433 - if (!--pipe->writers)
42434 + if (atomic_dec_and_test(&pipe->writers))
42435 wake_up_interruptible(&pipe->wait);
42436 ret = -ERESTARTSYS;
42437 goto err;
42438
42439 err:
42440 - if (!pipe->readers && !pipe->writers)
42441 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
42442 free_pipe_info(inode);
42443
42444 err_nocleanup:
42445 diff --git a/fs/file.c b/fs/file.c
42446 index 4c6992d..104cdea 100644
42447 --- a/fs/file.c
42448 +++ b/fs/file.c
42449 @@ -15,6 +15,7 @@
42450 #include <linux/slab.h>
42451 #include <linux/vmalloc.h>
42452 #include <linux/file.h>
42453 +#include <linux/security.h>
42454 #include <linux/fdtable.h>
42455 #include <linux/bitops.h>
42456 #include <linux/interrupt.h>
42457 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
42458 * N.B. For clone tasks sharing a files structure, this test
42459 * will limit the total number of files that can be opened.
42460 */
42461 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
42462 if (nr >= rlimit(RLIMIT_NOFILE))
42463 return -EMFILE;
42464
42465 diff --git a/fs/filesystems.c b/fs/filesystems.c
42466 index 0845f84..7b4ebef 100644
42467 --- a/fs/filesystems.c
42468 +++ b/fs/filesystems.c
42469 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(const char *name)
42470 int len = dot ? dot - name : strlen(name);
42471
42472 fs = __get_fs_type(name, len);
42473 +
42474 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
42475 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
42476 +#else
42477 if (!fs && (request_module("%.*s", len, name) == 0))
42478 +#endif
42479 fs = __get_fs_type(name, len);
42480
42481 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
42482 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
42483 index 78b519c..212c0d0 100644
42484 --- a/fs/fs_struct.c
42485 +++ b/fs/fs_struct.c
42486 @@ -4,6 +4,7 @@
42487 #include <linux/path.h>
42488 #include <linux/slab.h>
42489 #include <linux/fs_struct.h>
42490 +#include <linux/grsecurity.h>
42491 #include "internal.h"
42492
42493 static inline void path_get_longterm(struct path *path)
42494 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
42495 old_root = fs->root;
42496 fs->root = *path;
42497 path_get_longterm(path);
42498 + gr_set_chroot_entries(current, path);
42499 write_seqcount_end(&fs->seq);
42500 spin_unlock(&fs->lock);
42501 if (old_root.dentry)
42502 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
42503 && fs->root.mnt == old_root->mnt) {
42504 path_get_longterm(new_root);
42505 fs->root = *new_root;
42506 + gr_set_chroot_entries(p, new_root);
42507 count++;
42508 }
42509 if (fs->pwd.dentry == old_root->dentry
42510 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
42511 spin_lock(&fs->lock);
42512 write_seqcount_begin(&fs->seq);
42513 tsk->fs = NULL;
42514 - kill = !--fs->users;
42515 + gr_clear_chroot_entries(tsk);
42516 + kill = !atomic_dec_return(&fs->users);
42517 write_seqcount_end(&fs->seq);
42518 spin_unlock(&fs->lock);
42519 task_unlock(tsk);
42520 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
42521 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
42522 /* We don't need to lock fs - think why ;-) */
42523 if (fs) {
42524 - fs->users = 1;
42525 + atomic_set(&fs->users, 1);
42526 fs->in_exec = 0;
42527 spin_lock_init(&fs->lock);
42528 seqcount_init(&fs->seq);
42529 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
42530 spin_lock(&old->lock);
42531 fs->root = old->root;
42532 path_get_longterm(&fs->root);
42533 + /* instead of calling gr_set_chroot_entries here,
42534 + we call it from every caller of this function
42535 + */
42536 fs->pwd = old->pwd;
42537 path_get_longterm(&fs->pwd);
42538 spin_unlock(&old->lock);
42539 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
42540
42541 task_lock(current);
42542 spin_lock(&fs->lock);
42543 - kill = !--fs->users;
42544 + kill = !atomic_dec_return(&fs->users);
42545 current->fs = new_fs;
42546 + gr_set_chroot_entries(current, &new_fs->root);
42547 spin_unlock(&fs->lock);
42548 task_unlock(current);
42549
42550 @@ -170,7 +178,7 @@ EXPORT_SYMBOL(current_umask);
42551
42552 /* to be mentioned only in INIT_TASK */
42553 struct fs_struct init_fs = {
42554 - .users = 1,
42555 + .users = ATOMIC_INIT(1),
42556 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
42557 .seq = SEQCNT_ZERO,
42558 .umask = 0022,
42559 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
42560 task_lock(current);
42561
42562 spin_lock(&init_fs.lock);
42563 - init_fs.users++;
42564 + atomic_inc(&init_fs.users);
42565 spin_unlock(&init_fs.lock);
42566
42567 spin_lock(&fs->lock);
42568 current->fs = &init_fs;
42569 - kill = !--fs->users;
42570 + gr_set_chroot_entries(current, &current->fs->root);
42571 + kill = !atomic_dec_return(&fs->users);
42572 spin_unlock(&fs->lock);
42573
42574 task_unlock(current);
42575 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
42576 index 9905350..02eaec4 100644
42577 --- a/fs/fscache/cookie.c
42578 +++ b/fs/fscache/cookie.c
42579 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
42580 parent ? (char *) parent->def->name : "<no-parent>",
42581 def->name, netfs_data);
42582
42583 - fscache_stat(&fscache_n_acquires);
42584 + fscache_stat_unchecked(&fscache_n_acquires);
42585
42586 /* if there's no parent cookie, then we don't create one here either */
42587 if (!parent) {
42588 - fscache_stat(&fscache_n_acquires_null);
42589 + fscache_stat_unchecked(&fscache_n_acquires_null);
42590 _leave(" [no parent]");
42591 return NULL;
42592 }
42593 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
42594 /* allocate and initialise a cookie */
42595 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
42596 if (!cookie) {
42597 - fscache_stat(&fscache_n_acquires_oom);
42598 + fscache_stat_unchecked(&fscache_n_acquires_oom);
42599 _leave(" [ENOMEM]");
42600 return NULL;
42601 }
42602 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
42603
42604 switch (cookie->def->type) {
42605 case FSCACHE_COOKIE_TYPE_INDEX:
42606 - fscache_stat(&fscache_n_cookie_index);
42607 + fscache_stat_unchecked(&fscache_n_cookie_index);
42608 break;
42609 case FSCACHE_COOKIE_TYPE_DATAFILE:
42610 - fscache_stat(&fscache_n_cookie_data);
42611 + fscache_stat_unchecked(&fscache_n_cookie_data);
42612 break;
42613 default:
42614 - fscache_stat(&fscache_n_cookie_special);
42615 + fscache_stat_unchecked(&fscache_n_cookie_special);
42616 break;
42617 }
42618
42619 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
42620 if (fscache_acquire_non_index_cookie(cookie) < 0) {
42621 atomic_dec(&parent->n_children);
42622 __fscache_cookie_put(cookie);
42623 - fscache_stat(&fscache_n_acquires_nobufs);
42624 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
42625 _leave(" = NULL");
42626 return NULL;
42627 }
42628 }
42629
42630 - fscache_stat(&fscache_n_acquires_ok);
42631 + fscache_stat_unchecked(&fscache_n_acquires_ok);
42632 _leave(" = %p", cookie);
42633 return cookie;
42634 }
42635 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
42636 cache = fscache_select_cache_for_object(cookie->parent);
42637 if (!cache) {
42638 up_read(&fscache_addremove_sem);
42639 - fscache_stat(&fscache_n_acquires_no_cache);
42640 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
42641 _leave(" = -ENOMEDIUM [no cache]");
42642 return -ENOMEDIUM;
42643 }
42644 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
42645 object = cache->ops->alloc_object(cache, cookie);
42646 fscache_stat_d(&fscache_n_cop_alloc_object);
42647 if (IS_ERR(object)) {
42648 - fscache_stat(&fscache_n_object_no_alloc);
42649 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
42650 ret = PTR_ERR(object);
42651 goto error;
42652 }
42653
42654 - fscache_stat(&fscache_n_object_alloc);
42655 + fscache_stat_unchecked(&fscache_n_object_alloc);
42656
42657 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
42658
42659 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
42660 struct fscache_object *object;
42661 struct hlist_node *_p;
42662
42663 - fscache_stat(&fscache_n_updates);
42664 + fscache_stat_unchecked(&fscache_n_updates);
42665
42666 if (!cookie) {
42667 - fscache_stat(&fscache_n_updates_null);
42668 + fscache_stat_unchecked(&fscache_n_updates_null);
42669 _leave(" [no cookie]");
42670 return;
42671 }
42672 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
42673 struct fscache_object *object;
42674 unsigned long event;
42675
42676 - fscache_stat(&fscache_n_relinquishes);
42677 + fscache_stat_unchecked(&fscache_n_relinquishes);
42678 if (retire)
42679 - fscache_stat(&fscache_n_relinquishes_retire);
42680 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
42681
42682 if (!cookie) {
42683 - fscache_stat(&fscache_n_relinquishes_null);
42684 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
42685 _leave(" [no cookie]");
42686 return;
42687 }
42688 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
42689
42690 /* wait for the cookie to finish being instantiated (or to fail) */
42691 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
42692 - fscache_stat(&fscache_n_relinquishes_waitcrt);
42693 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
42694 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
42695 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
42696 }
42697 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
42698 index f6aad48..88dcf26 100644
42699 --- a/fs/fscache/internal.h
42700 +++ b/fs/fscache/internal.h
42701 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
42702 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
42703 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
42704
42705 -extern atomic_t fscache_n_op_pend;
42706 -extern atomic_t fscache_n_op_run;
42707 -extern atomic_t fscache_n_op_enqueue;
42708 -extern atomic_t fscache_n_op_deferred_release;
42709 -extern atomic_t fscache_n_op_release;
42710 -extern atomic_t fscache_n_op_gc;
42711 -extern atomic_t fscache_n_op_cancelled;
42712 -extern atomic_t fscache_n_op_rejected;
42713 +extern atomic_unchecked_t fscache_n_op_pend;
42714 +extern atomic_unchecked_t fscache_n_op_run;
42715 +extern atomic_unchecked_t fscache_n_op_enqueue;
42716 +extern atomic_unchecked_t fscache_n_op_deferred_release;
42717 +extern atomic_unchecked_t fscache_n_op_release;
42718 +extern atomic_unchecked_t fscache_n_op_gc;
42719 +extern atomic_unchecked_t fscache_n_op_cancelled;
42720 +extern atomic_unchecked_t fscache_n_op_rejected;
42721
42722 -extern atomic_t fscache_n_attr_changed;
42723 -extern atomic_t fscache_n_attr_changed_ok;
42724 -extern atomic_t fscache_n_attr_changed_nobufs;
42725 -extern atomic_t fscache_n_attr_changed_nomem;
42726 -extern atomic_t fscache_n_attr_changed_calls;
42727 +extern atomic_unchecked_t fscache_n_attr_changed;
42728 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
42729 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
42730 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
42731 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
42732
42733 -extern atomic_t fscache_n_allocs;
42734 -extern atomic_t fscache_n_allocs_ok;
42735 -extern atomic_t fscache_n_allocs_wait;
42736 -extern atomic_t fscache_n_allocs_nobufs;
42737 -extern atomic_t fscache_n_allocs_intr;
42738 -extern atomic_t fscache_n_allocs_object_dead;
42739 -extern atomic_t fscache_n_alloc_ops;
42740 -extern atomic_t fscache_n_alloc_op_waits;
42741 +extern atomic_unchecked_t fscache_n_allocs;
42742 +extern atomic_unchecked_t fscache_n_allocs_ok;
42743 +extern atomic_unchecked_t fscache_n_allocs_wait;
42744 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
42745 +extern atomic_unchecked_t fscache_n_allocs_intr;
42746 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
42747 +extern atomic_unchecked_t fscache_n_alloc_ops;
42748 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
42749
42750 -extern atomic_t fscache_n_retrievals;
42751 -extern atomic_t fscache_n_retrievals_ok;
42752 -extern atomic_t fscache_n_retrievals_wait;
42753 -extern atomic_t fscache_n_retrievals_nodata;
42754 -extern atomic_t fscache_n_retrievals_nobufs;
42755 -extern atomic_t fscache_n_retrievals_intr;
42756 -extern atomic_t fscache_n_retrievals_nomem;
42757 -extern atomic_t fscache_n_retrievals_object_dead;
42758 -extern atomic_t fscache_n_retrieval_ops;
42759 -extern atomic_t fscache_n_retrieval_op_waits;
42760 +extern atomic_unchecked_t fscache_n_retrievals;
42761 +extern atomic_unchecked_t fscache_n_retrievals_ok;
42762 +extern atomic_unchecked_t fscache_n_retrievals_wait;
42763 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
42764 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
42765 +extern atomic_unchecked_t fscache_n_retrievals_intr;
42766 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
42767 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
42768 +extern atomic_unchecked_t fscache_n_retrieval_ops;
42769 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
42770
42771 -extern atomic_t fscache_n_stores;
42772 -extern atomic_t fscache_n_stores_ok;
42773 -extern atomic_t fscache_n_stores_again;
42774 -extern atomic_t fscache_n_stores_nobufs;
42775 -extern atomic_t fscache_n_stores_oom;
42776 -extern atomic_t fscache_n_store_ops;
42777 -extern atomic_t fscache_n_store_calls;
42778 -extern atomic_t fscache_n_store_pages;
42779 -extern atomic_t fscache_n_store_radix_deletes;
42780 -extern atomic_t fscache_n_store_pages_over_limit;
42781 +extern atomic_unchecked_t fscache_n_stores;
42782 +extern atomic_unchecked_t fscache_n_stores_ok;
42783 +extern atomic_unchecked_t fscache_n_stores_again;
42784 +extern atomic_unchecked_t fscache_n_stores_nobufs;
42785 +extern atomic_unchecked_t fscache_n_stores_oom;
42786 +extern atomic_unchecked_t fscache_n_store_ops;
42787 +extern atomic_unchecked_t fscache_n_store_calls;
42788 +extern atomic_unchecked_t fscache_n_store_pages;
42789 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
42790 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
42791
42792 -extern atomic_t fscache_n_store_vmscan_not_storing;
42793 -extern atomic_t fscache_n_store_vmscan_gone;
42794 -extern atomic_t fscache_n_store_vmscan_busy;
42795 -extern atomic_t fscache_n_store_vmscan_cancelled;
42796 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
42797 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
42798 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
42799 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
42800
42801 -extern atomic_t fscache_n_marks;
42802 -extern atomic_t fscache_n_uncaches;
42803 +extern atomic_unchecked_t fscache_n_marks;
42804 +extern atomic_unchecked_t fscache_n_uncaches;
42805
42806 -extern atomic_t fscache_n_acquires;
42807 -extern atomic_t fscache_n_acquires_null;
42808 -extern atomic_t fscache_n_acquires_no_cache;
42809 -extern atomic_t fscache_n_acquires_ok;
42810 -extern atomic_t fscache_n_acquires_nobufs;
42811 -extern atomic_t fscache_n_acquires_oom;
42812 +extern atomic_unchecked_t fscache_n_acquires;
42813 +extern atomic_unchecked_t fscache_n_acquires_null;
42814 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
42815 +extern atomic_unchecked_t fscache_n_acquires_ok;
42816 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
42817 +extern atomic_unchecked_t fscache_n_acquires_oom;
42818
42819 -extern atomic_t fscache_n_updates;
42820 -extern atomic_t fscache_n_updates_null;
42821 -extern atomic_t fscache_n_updates_run;
42822 +extern atomic_unchecked_t fscache_n_updates;
42823 +extern atomic_unchecked_t fscache_n_updates_null;
42824 +extern atomic_unchecked_t fscache_n_updates_run;
42825
42826 -extern atomic_t fscache_n_relinquishes;
42827 -extern atomic_t fscache_n_relinquishes_null;
42828 -extern atomic_t fscache_n_relinquishes_waitcrt;
42829 -extern atomic_t fscache_n_relinquishes_retire;
42830 +extern atomic_unchecked_t fscache_n_relinquishes;
42831 +extern atomic_unchecked_t fscache_n_relinquishes_null;
42832 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
42833 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
42834
42835 -extern atomic_t fscache_n_cookie_index;
42836 -extern atomic_t fscache_n_cookie_data;
42837 -extern atomic_t fscache_n_cookie_special;
42838 +extern atomic_unchecked_t fscache_n_cookie_index;
42839 +extern atomic_unchecked_t fscache_n_cookie_data;
42840 +extern atomic_unchecked_t fscache_n_cookie_special;
42841
42842 -extern atomic_t fscache_n_object_alloc;
42843 -extern atomic_t fscache_n_object_no_alloc;
42844 -extern atomic_t fscache_n_object_lookups;
42845 -extern atomic_t fscache_n_object_lookups_negative;
42846 -extern atomic_t fscache_n_object_lookups_positive;
42847 -extern atomic_t fscache_n_object_lookups_timed_out;
42848 -extern atomic_t fscache_n_object_created;
42849 -extern atomic_t fscache_n_object_avail;
42850 -extern atomic_t fscache_n_object_dead;
42851 +extern atomic_unchecked_t fscache_n_object_alloc;
42852 +extern atomic_unchecked_t fscache_n_object_no_alloc;
42853 +extern atomic_unchecked_t fscache_n_object_lookups;
42854 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
42855 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
42856 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
42857 +extern atomic_unchecked_t fscache_n_object_created;
42858 +extern atomic_unchecked_t fscache_n_object_avail;
42859 +extern atomic_unchecked_t fscache_n_object_dead;
42860
42861 -extern atomic_t fscache_n_checkaux_none;
42862 -extern atomic_t fscache_n_checkaux_okay;
42863 -extern atomic_t fscache_n_checkaux_update;
42864 -extern atomic_t fscache_n_checkaux_obsolete;
42865 +extern atomic_unchecked_t fscache_n_checkaux_none;
42866 +extern atomic_unchecked_t fscache_n_checkaux_okay;
42867 +extern atomic_unchecked_t fscache_n_checkaux_update;
42868 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
42869
42870 extern atomic_t fscache_n_cop_alloc_object;
42871 extern atomic_t fscache_n_cop_lookup_object;
42872 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
42873 atomic_inc(stat);
42874 }
42875
42876 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
42877 +{
42878 + atomic_inc_unchecked(stat);
42879 +}
42880 +
42881 static inline void fscache_stat_d(atomic_t *stat)
42882 {
42883 atomic_dec(stat);
42884 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
42885
42886 #define __fscache_stat(stat) (NULL)
42887 #define fscache_stat(stat) do {} while (0)
42888 +#define fscache_stat_unchecked(stat) do {} while (0)
42889 #define fscache_stat_d(stat) do {} while (0)
42890 #endif
42891
42892 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
42893 index b6b897c..0ffff9c 100644
42894 --- a/fs/fscache/object.c
42895 +++ b/fs/fscache/object.c
42896 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
42897 /* update the object metadata on disk */
42898 case FSCACHE_OBJECT_UPDATING:
42899 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
42900 - fscache_stat(&fscache_n_updates_run);
42901 + fscache_stat_unchecked(&fscache_n_updates_run);
42902 fscache_stat(&fscache_n_cop_update_object);
42903 object->cache->ops->update_object(object);
42904 fscache_stat_d(&fscache_n_cop_update_object);
42905 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
42906 spin_lock(&object->lock);
42907 object->state = FSCACHE_OBJECT_DEAD;
42908 spin_unlock(&object->lock);
42909 - fscache_stat(&fscache_n_object_dead);
42910 + fscache_stat_unchecked(&fscache_n_object_dead);
42911 goto terminal_transit;
42912
42913 /* handle the parent cache of this object being withdrawn from
42914 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
42915 spin_lock(&object->lock);
42916 object->state = FSCACHE_OBJECT_DEAD;
42917 spin_unlock(&object->lock);
42918 - fscache_stat(&fscache_n_object_dead);
42919 + fscache_stat_unchecked(&fscache_n_object_dead);
42920 goto terminal_transit;
42921
42922 /* complain about the object being woken up once it is
42923 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
42924 parent->cookie->def->name, cookie->def->name,
42925 object->cache->tag->name);
42926
42927 - fscache_stat(&fscache_n_object_lookups);
42928 + fscache_stat_unchecked(&fscache_n_object_lookups);
42929 fscache_stat(&fscache_n_cop_lookup_object);
42930 ret = object->cache->ops->lookup_object(object);
42931 fscache_stat_d(&fscache_n_cop_lookup_object);
42932 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
42933 if (ret == -ETIMEDOUT) {
42934 /* probably stuck behind another object, so move this one to
42935 * the back of the queue */
42936 - fscache_stat(&fscache_n_object_lookups_timed_out);
42937 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
42938 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
42939 }
42940
42941 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
42942
42943 spin_lock(&object->lock);
42944 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
42945 - fscache_stat(&fscache_n_object_lookups_negative);
42946 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
42947
42948 /* transit here to allow write requests to begin stacking up
42949 * and read requests to begin returning ENODATA */
42950 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
42951 * result, in which case there may be data available */
42952 spin_lock(&object->lock);
42953 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
42954 - fscache_stat(&fscache_n_object_lookups_positive);
42955 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
42956
42957 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
42958
42959 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
42960 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
42961 } else {
42962 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
42963 - fscache_stat(&fscache_n_object_created);
42964 + fscache_stat_unchecked(&fscache_n_object_created);
42965
42966 object->state = FSCACHE_OBJECT_AVAILABLE;
42967 spin_unlock(&object->lock);
42968 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
42969 fscache_enqueue_dependents(object);
42970
42971 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
42972 - fscache_stat(&fscache_n_object_avail);
42973 + fscache_stat_unchecked(&fscache_n_object_avail);
42974
42975 _leave("");
42976 }
42977 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
42978 enum fscache_checkaux result;
42979
42980 if (!object->cookie->def->check_aux) {
42981 - fscache_stat(&fscache_n_checkaux_none);
42982 + fscache_stat_unchecked(&fscache_n_checkaux_none);
42983 return FSCACHE_CHECKAUX_OKAY;
42984 }
42985
42986 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
42987 switch (result) {
42988 /* entry okay as is */
42989 case FSCACHE_CHECKAUX_OKAY:
42990 - fscache_stat(&fscache_n_checkaux_okay);
42991 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
42992 break;
42993
42994 /* entry requires update */
42995 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
42996 - fscache_stat(&fscache_n_checkaux_update);
42997 + fscache_stat_unchecked(&fscache_n_checkaux_update);
42998 break;
42999
43000 /* entry requires deletion */
43001 case FSCACHE_CHECKAUX_OBSOLETE:
43002 - fscache_stat(&fscache_n_checkaux_obsolete);
43003 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
43004 break;
43005
43006 default:
43007 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
43008 index 30afdfa..2256596 100644
43009 --- a/fs/fscache/operation.c
43010 +++ b/fs/fscache/operation.c
43011 @@ -17,7 +17,7 @@
43012 #include <linux/slab.h>
43013 #include "internal.h"
43014
43015 -atomic_t fscache_op_debug_id;
43016 +atomic_unchecked_t fscache_op_debug_id;
43017 EXPORT_SYMBOL(fscache_op_debug_id);
43018
43019 /**
43020 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
43021 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
43022 ASSERTCMP(atomic_read(&op->usage), >, 0);
43023
43024 - fscache_stat(&fscache_n_op_enqueue);
43025 + fscache_stat_unchecked(&fscache_n_op_enqueue);
43026 switch (op->flags & FSCACHE_OP_TYPE) {
43027 case FSCACHE_OP_ASYNC:
43028 _debug("queue async");
43029 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
43030 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
43031 if (op->processor)
43032 fscache_enqueue_operation(op);
43033 - fscache_stat(&fscache_n_op_run);
43034 + fscache_stat_unchecked(&fscache_n_op_run);
43035 }
43036
43037 /*
43038 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
43039 if (object->n_ops > 1) {
43040 atomic_inc(&op->usage);
43041 list_add_tail(&op->pend_link, &object->pending_ops);
43042 - fscache_stat(&fscache_n_op_pend);
43043 + fscache_stat_unchecked(&fscache_n_op_pend);
43044 } else if (!list_empty(&object->pending_ops)) {
43045 atomic_inc(&op->usage);
43046 list_add_tail(&op->pend_link, &object->pending_ops);
43047 - fscache_stat(&fscache_n_op_pend);
43048 + fscache_stat_unchecked(&fscache_n_op_pend);
43049 fscache_start_operations(object);
43050 } else {
43051 ASSERTCMP(object->n_in_progress, ==, 0);
43052 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
43053 object->n_exclusive++; /* reads and writes must wait */
43054 atomic_inc(&op->usage);
43055 list_add_tail(&op->pend_link, &object->pending_ops);
43056 - fscache_stat(&fscache_n_op_pend);
43057 + fscache_stat_unchecked(&fscache_n_op_pend);
43058 ret = 0;
43059 } else {
43060 /* not allowed to submit ops in any other state */
43061 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
43062 if (object->n_exclusive > 0) {
43063 atomic_inc(&op->usage);
43064 list_add_tail(&op->pend_link, &object->pending_ops);
43065 - fscache_stat(&fscache_n_op_pend);
43066 + fscache_stat_unchecked(&fscache_n_op_pend);
43067 } else if (!list_empty(&object->pending_ops)) {
43068 atomic_inc(&op->usage);
43069 list_add_tail(&op->pend_link, &object->pending_ops);
43070 - fscache_stat(&fscache_n_op_pend);
43071 + fscache_stat_unchecked(&fscache_n_op_pend);
43072 fscache_start_operations(object);
43073 } else {
43074 ASSERTCMP(object->n_exclusive, ==, 0);
43075 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
43076 object->n_ops++;
43077 atomic_inc(&op->usage);
43078 list_add_tail(&op->pend_link, &object->pending_ops);
43079 - fscache_stat(&fscache_n_op_pend);
43080 + fscache_stat_unchecked(&fscache_n_op_pend);
43081 ret = 0;
43082 } else if (object->state == FSCACHE_OBJECT_DYING ||
43083 object->state == FSCACHE_OBJECT_LC_DYING ||
43084 object->state == FSCACHE_OBJECT_WITHDRAWING) {
43085 - fscache_stat(&fscache_n_op_rejected);
43086 + fscache_stat_unchecked(&fscache_n_op_rejected);
43087 ret = -ENOBUFS;
43088 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
43089 fscache_report_unexpected_submission(object, op, ostate);
43090 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
43091
43092 ret = -EBUSY;
43093 if (!list_empty(&op->pend_link)) {
43094 - fscache_stat(&fscache_n_op_cancelled);
43095 + fscache_stat_unchecked(&fscache_n_op_cancelled);
43096 list_del_init(&op->pend_link);
43097 object->n_ops--;
43098 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
43099 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
43100 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
43101 BUG();
43102
43103 - fscache_stat(&fscache_n_op_release);
43104 + fscache_stat_unchecked(&fscache_n_op_release);
43105
43106 if (op->release) {
43107 op->release(op);
43108 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
43109 * lock, and defer it otherwise */
43110 if (!spin_trylock(&object->lock)) {
43111 _debug("defer put");
43112 - fscache_stat(&fscache_n_op_deferred_release);
43113 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
43114
43115 cache = object->cache;
43116 spin_lock(&cache->op_gc_list_lock);
43117 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
43118
43119 _debug("GC DEFERRED REL OBJ%x OP%x",
43120 object->debug_id, op->debug_id);
43121 - fscache_stat(&fscache_n_op_gc);
43122 + fscache_stat_unchecked(&fscache_n_op_gc);
43123
43124 ASSERTCMP(atomic_read(&op->usage), ==, 0);
43125
43126 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
43127 index 3f7a59b..cf196cc 100644
43128 --- a/fs/fscache/page.c
43129 +++ b/fs/fscache/page.c
43130 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
43131 val = radix_tree_lookup(&cookie->stores, page->index);
43132 if (!val) {
43133 rcu_read_unlock();
43134 - fscache_stat(&fscache_n_store_vmscan_not_storing);
43135 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
43136 __fscache_uncache_page(cookie, page);
43137 return true;
43138 }
43139 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
43140 spin_unlock(&cookie->stores_lock);
43141
43142 if (xpage) {
43143 - fscache_stat(&fscache_n_store_vmscan_cancelled);
43144 - fscache_stat(&fscache_n_store_radix_deletes);
43145 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
43146 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
43147 ASSERTCMP(xpage, ==, page);
43148 } else {
43149 - fscache_stat(&fscache_n_store_vmscan_gone);
43150 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
43151 }
43152
43153 wake_up_bit(&cookie->flags, 0);
43154 @@ -107,7 +107,7 @@ page_busy:
43155 /* we might want to wait here, but that could deadlock the allocator as
43156 * the work threads writing to the cache may all end up sleeping
43157 * on memory allocation */
43158 - fscache_stat(&fscache_n_store_vmscan_busy);
43159 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
43160 return false;
43161 }
43162 EXPORT_SYMBOL(__fscache_maybe_release_page);
43163 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
43164 FSCACHE_COOKIE_STORING_TAG);
43165 if (!radix_tree_tag_get(&cookie->stores, page->index,
43166 FSCACHE_COOKIE_PENDING_TAG)) {
43167 - fscache_stat(&fscache_n_store_radix_deletes);
43168 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
43169 xpage = radix_tree_delete(&cookie->stores, page->index);
43170 }
43171 spin_unlock(&cookie->stores_lock);
43172 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
43173
43174 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
43175
43176 - fscache_stat(&fscache_n_attr_changed_calls);
43177 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
43178
43179 if (fscache_object_is_active(object)) {
43180 fscache_stat(&fscache_n_cop_attr_changed);
43181 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43182
43183 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43184
43185 - fscache_stat(&fscache_n_attr_changed);
43186 + fscache_stat_unchecked(&fscache_n_attr_changed);
43187
43188 op = kzalloc(sizeof(*op), GFP_KERNEL);
43189 if (!op) {
43190 - fscache_stat(&fscache_n_attr_changed_nomem);
43191 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
43192 _leave(" = -ENOMEM");
43193 return -ENOMEM;
43194 }
43195 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43196 if (fscache_submit_exclusive_op(object, op) < 0)
43197 goto nobufs;
43198 spin_unlock(&cookie->lock);
43199 - fscache_stat(&fscache_n_attr_changed_ok);
43200 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
43201 fscache_put_operation(op);
43202 _leave(" = 0");
43203 return 0;
43204 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43205 nobufs:
43206 spin_unlock(&cookie->lock);
43207 kfree(op);
43208 - fscache_stat(&fscache_n_attr_changed_nobufs);
43209 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
43210 _leave(" = %d", -ENOBUFS);
43211 return -ENOBUFS;
43212 }
43213 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
43214 /* allocate a retrieval operation and attempt to submit it */
43215 op = kzalloc(sizeof(*op), GFP_NOIO);
43216 if (!op) {
43217 - fscache_stat(&fscache_n_retrievals_nomem);
43218 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43219 return NULL;
43220 }
43221
43222 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
43223 return 0;
43224 }
43225
43226 - fscache_stat(&fscache_n_retrievals_wait);
43227 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
43228
43229 jif = jiffies;
43230 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
43231 fscache_wait_bit_interruptible,
43232 TASK_INTERRUPTIBLE) != 0) {
43233 - fscache_stat(&fscache_n_retrievals_intr);
43234 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43235 _leave(" = -ERESTARTSYS");
43236 return -ERESTARTSYS;
43237 }
43238 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
43239 */
43240 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43241 struct fscache_retrieval *op,
43242 - atomic_t *stat_op_waits,
43243 - atomic_t *stat_object_dead)
43244 + atomic_unchecked_t *stat_op_waits,
43245 + atomic_unchecked_t *stat_object_dead)
43246 {
43247 int ret;
43248
43249 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43250 goto check_if_dead;
43251
43252 _debug(">>> WT");
43253 - fscache_stat(stat_op_waits);
43254 + fscache_stat_unchecked(stat_op_waits);
43255 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
43256 fscache_wait_bit_interruptible,
43257 TASK_INTERRUPTIBLE) < 0) {
43258 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43259
43260 check_if_dead:
43261 if (unlikely(fscache_object_is_dead(object))) {
43262 - fscache_stat(stat_object_dead);
43263 + fscache_stat_unchecked(stat_object_dead);
43264 return -ENOBUFS;
43265 }
43266 return 0;
43267 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43268
43269 _enter("%p,%p,,,", cookie, page);
43270
43271 - fscache_stat(&fscache_n_retrievals);
43272 + fscache_stat_unchecked(&fscache_n_retrievals);
43273
43274 if (hlist_empty(&cookie->backing_objects))
43275 goto nobufs;
43276 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43277 goto nobufs_unlock;
43278 spin_unlock(&cookie->lock);
43279
43280 - fscache_stat(&fscache_n_retrieval_ops);
43281 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
43282
43283 /* pin the netfs read context in case we need to do the actual netfs
43284 * read because we've encountered a cache read failure */
43285 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43286
43287 error:
43288 if (ret == -ENOMEM)
43289 - fscache_stat(&fscache_n_retrievals_nomem);
43290 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43291 else if (ret == -ERESTARTSYS)
43292 - fscache_stat(&fscache_n_retrievals_intr);
43293 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43294 else if (ret == -ENODATA)
43295 - fscache_stat(&fscache_n_retrievals_nodata);
43296 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
43297 else if (ret < 0)
43298 - fscache_stat(&fscache_n_retrievals_nobufs);
43299 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43300 else
43301 - fscache_stat(&fscache_n_retrievals_ok);
43302 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
43303
43304 fscache_put_retrieval(op);
43305 _leave(" = %d", ret);
43306 @@ -429,7 +429,7 @@ nobufs_unlock:
43307 spin_unlock(&cookie->lock);
43308 kfree(op);
43309 nobufs:
43310 - fscache_stat(&fscache_n_retrievals_nobufs);
43311 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43312 _leave(" = -ENOBUFS");
43313 return -ENOBUFS;
43314 }
43315 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43316
43317 _enter("%p,,%d,,,", cookie, *nr_pages);
43318
43319 - fscache_stat(&fscache_n_retrievals);
43320 + fscache_stat_unchecked(&fscache_n_retrievals);
43321
43322 if (hlist_empty(&cookie->backing_objects))
43323 goto nobufs;
43324 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43325 goto nobufs_unlock;
43326 spin_unlock(&cookie->lock);
43327
43328 - fscache_stat(&fscache_n_retrieval_ops);
43329 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
43330
43331 /* pin the netfs read context in case we need to do the actual netfs
43332 * read because we've encountered a cache read failure */
43333 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43334
43335 error:
43336 if (ret == -ENOMEM)
43337 - fscache_stat(&fscache_n_retrievals_nomem);
43338 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43339 else if (ret == -ERESTARTSYS)
43340 - fscache_stat(&fscache_n_retrievals_intr);
43341 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43342 else if (ret == -ENODATA)
43343 - fscache_stat(&fscache_n_retrievals_nodata);
43344 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
43345 else if (ret < 0)
43346 - fscache_stat(&fscache_n_retrievals_nobufs);
43347 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43348 else
43349 - fscache_stat(&fscache_n_retrievals_ok);
43350 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
43351
43352 fscache_put_retrieval(op);
43353 _leave(" = %d", ret);
43354 @@ -545,7 +545,7 @@ nobufs_unlock:
43355 spin_unlock(&cookie->lock);
43356 kfree(op);
43357 nobufs:
43358 - fscache_stat(&fscache_n_retrievals_nobufs);
43359 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43360 _leave(" = -ENOBUFS");
43361 return -ENOBUFS;
43362 }
43363 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43364
43365 _enter("%p,%p,,,", cookie, page);
43366
43367 - fscache_stat(&fscache_n_allocs);
43368 + fscache_stat_unchecked(&fscache_n_allocs);
43369
43370 if (hlist_empty(&cookie->backing_objects))
43371 goto nobufs;
43372 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43373 goto nobufs_unlock;
43374 spin_unlock(&cookie->lock);
43375
43376 - fscache_stat(&fscache_n_alloc_ops);
43377 + fscache_stat_unchecked(&fscache_n_alloc_ops);
43378
43379 ret = fscache_wait_for_retrieval_activation(
43380 object, op,
43381 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43382
43383 error:
43384 if (ret == -ERESTARTSYS)
43385 - fscache_stat(&fscache_n_allocs_intr);
43386 + fscache_stat_unchecked(&fscache_n_allocs_intr);
43387 else if (ret < 0)
43388 - fscache_stat(&fscache_n_allocs_nobufs);
43389 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
43390 else
43391 - fscache_stat(&fscache_n_allocs_ok);
43392 + fscache_stat_unchecked(&fscache_n_allocs_ok);
43393
43394 fscache_put_retrieval(op);
43395 _leave(" = %d", ret);
43396 @@ -625,7 +625,7 @@ nobufs_unlock:
43397 spin_unlock(&cookie->lock);
43398 kfree(op);
43399 nobufs:
43400 - fscache_stat(&fscache_n_allocs_nobufs);
43401 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
43402 _leave(" = -ENOBUFS");
43403 return -ENOBUFS;
43404 }
43405 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43406
43407 spin_lock(&cookie->stores_lock);
43408
43409 - fscache_stat(&fscache_n_store_calls);
43410 + fscache_stat_unchecked(&fscache_n_store_calls);
43411
43412 /* find a page to store */
43413 page = NULL;
43414 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43415 page = results[0];
43416 _debug("gang %d [%lx]", n, page->index);
43417 if (page->index > op->store_limit) {
43418 - fscache_stat(&fscache_n_store_pages_over_limit);
43419 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
43420 goto superseded;
43421 }
43422
43423 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43424 spin_unlock(&cookie->stores_lock);
43425 spin_unlock(&object->lock);
43426
43427 - fscache_stat(&fscache_n_store_pages);
43428 + fscache_stat_unchecked(&fscache_n_store_pages);
43429 fscache_stat(&fscache_n_cop_write_page);
43430 ret = object->cache->ops->write_page(op, page);
43431 fscache_stat_d(&fscache_n_cop_write_page);
43432 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43433 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43434 ASSERT(PageFsCache(page));
43435
43436 - fscache_stat(&fscache_n_stores);
43437 + fscache_stat_unchecked(&fscache_n_stores);
43438
43439 op = kzalloc(sizeof(*op), GFP_NOIO);
43440 if (!op)
43441 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43442 spin_unlock(&cookie->stores_lock);
43443 spin_unlock(&object->lock);
43444
43445 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
43446 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
43447 op->store_limit = object->store_limit;
43448
43449 if (fscache_submit_op(object, &op->op) < 0)
43450 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43451
43452 spin_unlock(&cookie->lock);
43453 radix_tree_preload_end();
43454 - fscache_stat(&fscache_n_store_ops);
43455 - fscache_stat(&fscache_n_stores_ok);
43456 + fscache_stat_unchecked(&fscache_n_store_ops);
43457 + fscache_stat_unchecked(&fscache_n_stores_ok);
43458
43459 /* the work queue now carries its own ref on the object */
43460 fscache_put_operation(&op->op);
43461 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43462 return 0;
43463
43464 already_queued:
43465 - fscache_stat(&fscache_n_stores_again);
43466 + fscache_stat_unchecked(&fscache_n_stores_again);
43467 already_pending:
43468 spin_unlock(&cookie->stores_lock);
43469 spin_unlock(&object->lock);
43470 spin_unlock(&cookie->lock);
43471 radix_tree_preload_end();
43472 kfree(op);
43473 - fscache_stat(&fscache_n_stores_ok);
43474 + fscache_stat_unchecked(&fscache_n_stores_ok);
43475 _leave(" = 0");
43476 return 0;
43477
43478 @@ -851,14 +851,14 @@ nobufs:
43479 spin_unlock(&cookie->lock);
43480 radix_tree_preload_end();
43481 kfree(op);
43482 - fscache_stat(&fscache_n_stores_nobufs);
43483 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
43484 _leave(" = -ENOBUFS");
43485 return -ENOBUFS;
43486
43487 nomem_free:
43488 kfree(op);
43489 nomem:
43490 - fscache_stat(&fscache_n_stores_oom);
43491 + fscache_stat_unchecked(&fscache_n_stores_oom);
43492 _leave(" = -ENOMEM");
43493 return -ENOMEM;
43494 }
43495 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
43496 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43497 ASSERTCMP(page, !=, NULL);
43498
43499 - fscache_stat(&fscache_n_uncaches);
43500 + fscache_stat_unchecked(&fscache_n_uncaches);
43501
43502 /* cache withdrawal may beat us to it */
43503 if (!PageFsCache(page))
43504 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
43505 unsigned long loop;
43506
43507 #ifdef CONFIG_FSCACHE_STATS
43508 - atomic_add(pagevec->nr, &fscache_n_marks);
43509 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
43510 #endif
43511
43512 for (loop = 0; loop < pagevec->nr; loop++) {
43513 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
43514 index 4765190..2a067f2 100644
43515 --- a/fs/fscache/stats.c
43516 +++ b/fs/fscache/stats.c
43517 @@ -18,95 +18,95 @@
43518 /*
43519 * operation counters
43520 */
43521 -atomic_t fscache_n_op_pend;
43522 -atomic_t fscache_n_op_run;
43523 -atomic_t fscache_n_op_enqueue;
43524 -atomic_t fscache_n_op_requeue;
43525 -atomic_t fscache_n_op_deferred_release;
43526 -atomic_t fscache_n_op_release;
43527 -atomic_t fscache_n_op_gc;
43528 -atomic_t fscache_n_op_cancelled;
43529 -atomic_t fscache_n_op_rejected;
43530 +atomic_unchecked_t fscache_n_op_pend;
43531 +atomic_unchecked_t fscache_n_op_run;
43532 +atomic_unchecked_t fscache_n_op_enqueue;
43533 +atomic_unchecked_t fscache_n_op_requeue;
43534 +atomic_unchecked_t fscache_n_op_deferred_release;
43535 +atomic_unchecked_t fscache_n_op_release;
43536 +atomic_unchecked_t fscache_n_op_gc;
43537 +atomic_unchecked_t fscache_n_op_cancelled;
43538 +atomic_unchecked_t fscache_n_op_rejected;
43539
43540 -atomic_t fscache_n_attr_changed;
43541 -atomic_t fscache_n_attr_changed_ok;
43542 -atomic_t fscache_n_attr_changed_nobufs;
43543 -atomic_t fscache_n_attr_changed_nomem;
43544 -atomic_t fscache_n_attr_changed_calls;
43545 +atomic_unchecked_t fscache_n_attr_changed;
43546 +atomic_unchecked_t fscache_n_attr_changed_ok;
43547 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
43548 +atomic_unchecked_t fscache_n_attr_changed_nomem;
43549 +atomic_unchecked_t fscache_n_attr_changed_calls;
43550
43551 -atomic_t fscache_n_allocs;
43552 -atomic_t fscache_n_allocs_ok;
43553 -atomic_t fscache_n_allocs_wait;
43554 -atomic_t fscache_n_allocs_nobufs;
43555 -atomic_t fscache_n_allocs_intr;
43556 -atomic_t fscache_n_allocs_object_dead;
43557 -atomic_t fscache_n_alloc_ops;
43558 -atomic_t fscache_n_alloc_op_waits;
43559 +atomic_unchecked_t fscache_n_allocs;
43560 +atomic_unchecked_t fscache_n_allocs_ok;
43561 +atomic_unchecked_t fscache_n_allocs_wait;
43562 +atomic_unchecked_t fscache_n_allocs_nobufs;
43563 +atomic_unchecked_t fscache_n_allocs_intr;
43564 +atomic_unchecked_t fscache_n_allocs_object_dead;
43565 +atomic_unchecked_t fscache_n_alloc_ops;
43566 +atomic_unchecked_t fscache_n_alloc_op_waits;
43567
43568 -atomic_t fscache_n_retrievals;
43569 -atomic_t fscache_n_retrievals_ok;
43570 -atomic_t fscache_n_retrievals_wait;
43571 -atomic_t fscache_n_retrievals_nodata;
43572 -atomic_t fscache_n_retrievals_nobufs;
43573 -atomic_t fscache_n_retrievals_intr;
43574 -atomic_t fscache_n_retrievals_nomem;
43575 -atomic_t fscache_n_retrievals_object_dead;
43576 -atomic_t fscache_n_retrieval_ops;
43577 -atomic_t fscache_n_retrieval_op_waits;
43578 +atomic_unchecked_t fscache_n_retrievals;
43579 +atomic_unchecked_t fscache_n_retrievals_ok;
43580 +atomic_unchecked_t fscache_n_retrievals_wait;
43581 +atomic_unchecked_t fscache_n_retrievals_nodata;
43582 +atomic_unchecked_t fscache_n_retrievals_nobufs;
43583 +atomic_unchecked_t fscache_n_retrievals_intr;
43584 +atomic_unchecked_t fscache_n_retrievals_nomem;
43585 +atomic_unchecked_t fscache_n_retrievals_object_dead;
43586 +atomic_unchecked_t fscache_n_retrieval_ops;
43587 +atomic_unchecked_t fscache_n_retrieval_op_waits;
43588
43589 -atomic_t fscache_n_stores;
43590 -atomic_t fscache_n_stores_ok;
43591 -atomic_t fscache_n_stores_again;
43592 -atomic_t fscache_n_stores_nobufs;
43593 -atomic_t fscache_n_stores_oom;
43594 -atomic_t fscache_n_store_ops;
43595 -atomic_t fscache_n_store_calls;
43596 -atomic_t fscache_n_store_pages;
43597 -atomic_t fscache_n_store_radix_deletes;
43598 -atomic_t fscache_n_store_pages_over_limit;
43599 +atomic_unchecked_t fscache_n_stores;
43600 +atomic_unchecked_t fscache_n_stores_ok;
43601 +atomic_unchecked_t fscache_n_stores_again;
43602 +atomic_unchecked_t fscache_n_stores_nobufs;
43603 +atomic_unchecked_t fscache_n_stores_oom;
43604 +atomic_unchecked_t fscache_n_store_ops;
43605 +atomic_unchecked_t fscache_n_store_calls;
43606 +atomic_unchecked_t fscache_n_store_pages;
43607 +atomic_unchecked_t fscache_n_store_radix_deletes;
43608 +atomic_unchecked_t fscache_n_store_pages_over_limit;
43609
43610 -atomic_t fscache_n_store_vmscan_not_storing;
43611 -atomic_t fscache_n_store_vmscan_gone;
43612 -atomic_t fscache_n_store_vmscan_busy;
43613 -atomic_t fscache_n_store_vmscan_cancelled;
43614 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
43615 +atomic_unchecked_t fscache_n_store_vmscan_gone;
43616 +atomic_unchecked_t fscache_n_store_vmscan_busy;
43617 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
43618
43619 -atomic_t fscache_n_marks;
43620 -atomic_t fscache_n_uncaches;
43621 +atomic_unchecked_t fscache_n_marks;
43622 +atomic_unchecked_t fscache_n_uncaches;
43623
43624 -atomic_t fscache_n_acquires;
43625 -atomic_t fscache_n_acquires_null;
43626 -atomic_t fscache_n_acquires_no_cache;
43627 -atomic_t fscache_n_acquires_ok;
43628 -atomic_t fscache_n_acquires_nobufs;
43629 -atomic_t fscache_n_acquires_oom;
43630 +atomic_unchecked_t fscache_n_acquires;
43631 +atomic_unchecked_t fscache_n_acquires_null;
43632 +atomic_unchecked_t fscache_n_acquires_no_cache;
43633 +atomic_unchecked_t fscache_n_acquires_ok;
43634 +atomic_unchecked_t fscache_n_acquires_nobufs;
43635 +atomic_unchecked_t fscache_n_acquires_oom;
43636
43637 -atomic_t fscache_n_updates;
43638 -atomic_t fscache_n_updates_null;
43639 -atomic_t fscache_n_updates_run;
43640 +atomic_unchecked_t fscache_n_updates;
43641 +atomic_unchecked_t fscache_n_updates_null;
43642 +atomic_unchecked_t fscache_n_updates_run;
43643
43644 -atomic_t fscache_n_relinquishes;
43645 -atomic_t fscache_n_relinquishes_null;
43646 -atomic_t fscache_n_relinquishes_waitcrt;
43647 -atomic_t fscache_n_relinquishes_retire;
43648 +atomic_unchecked_t fscache_n_relinquishes;
43649 +atomic_unchecked_t fscache_n_relinquishes_null;
43650 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
43651 +atomic_unchecked_t fscache_n_relinquishes_retire;
43652
43653 -atomic_t fscache_n_cookie_index;
43654 -atomic_t fscache_n_cookie_data;
43655 -atomic_t fscache_n_cookie_special;
43656 +atomic_unchecked_t fscache_n_cookie_index;
43657 +atomic_unchecked_t fscache_n_cookie_data;
43658 +atomic_unchecked_t fscache_n_cookie_special;
43659
43660 -atomic_t fscache_n_object_alloc;
43661 -atomic_t fscache_n_object_no_alloc;
43662 -atomic_t fscache_n_object_lookups;
43663 -atomic_t fscache_n_object_lookups_negative;
43664 -atomic_t fscache_n_object_lookups_positive;
43665 -atomic_t fscache_n_object_lookups_timed_out;
43666 -atomic_t fscache_n_object_created;
43667 -atomic_t fscache_n_object_avail;
43668 -atomic_t fscache_n_object_dead;
43669 +atomic_unchecked_t fscache_n_object_alloc;
43670 +atomic_unchecked_t fscache_n_object_no_alloc;
43671 +atomic_unchecked_t fscache_n_object_lookups;
43672 +atomic_unchecked_t fscache_n_object_lookups_negative;
43673 +atomic_unchecked_t fscache_n_object_lookups_positive;
43674 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
43675 +atomic_unchecked_t fscache_n_object_created;
43676 +atomic_unchecked_t fscache_n_object_avail;
43677 +atomic_unchecked_t fscache_n_object_dead;
43678
43679 -atomic_t fscache_n_checkaux_none;
43680 -atomic_t fscache_n_checkaux_okay;
43681 -atomic_t fscache_n_checkaux_update;
43682 -atomic_t fscache_n_checkaux_obsolete;
43683 +atomic_unchecked_t fscache_n_checkaux_none;
43684 +atomic_unchecked_t fscache_n_checkaux_okay;
43685 +atomic_unchecked_t fscache_n_checkaux_update;
43686 +atomic_unchecked_t fscache_n_checkaux_obsolete;
43687
43688 atomic_t fscache_n_cop_alloc_object;
43689 atomic_t fscache_n_cop_lookup_object;
43690 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
43691 seq_puts(m, "FS-Cache statistics\n");
43692
43693 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
43694 - atomic_read(&fscache_n_cookie_index),
43695 - atomic_read(&fscache_n_cookie_data),
43696 - atomic_read(&fscache_n_cookie_special));
43697 + atomic_read_unchecked(&fscache_n_cookie_index),
43698 + atomic_read_unchecked(&fscache_n_cookie_data),
43699 + atomic_read_unchecked(&fscache_n_cookie_special));
43700
43701 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
43702 - atomic_read(&fscache_n_object_alloc),
43703 - atomic_read(&fscache_n_object_no_alloc),
43704 - atomic_read(&fscache_n_object_avail),
43705 - atomic_read(&fscache_n_object_dead));
43706 + atomic_read_unchecked(&fscache_n_object_alloc),
43707 + atomic_read_unchecked(&fscache_n_object_no_alloc),
43708 + atomic_read_unchecked(&fscache_n_object_avail),
43709 + atomic_read_unchecked(&fscache_n_object_dead));
43710 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
43711 - atomic_read(&fscache_n_checkaux_none),
43712 - atomic_read(&fscache_n_checkaux_okay),
43713 - atomic_read(&fscache_n_checkaux_update),
43714 - atomic_read(&fscache_n_checkaux_obsolete));
43715 + atomic_read_unchecked(&fscache_n_checkaux_none),
43716 + atomic_read_unchecked(&fscache_n_checkaux_okay),
43717 + atomic_read_unchecked(&fscache_n_checkaux_update),
43718 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
43719
43720 seq_printf(m, "Pages : mrk=%u unc=%u\n",
43721 - atomic_read(&fscache_n_marks),
43722 - atomic_read(&fscache_n_uncaches));
43723 + atomic_read_unchecked(&fscache_n_marks),
43724 + atomic_read_unchecked(&fscache_n_uncaches));
43725
43726 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
43727 " oom=%u\n",
43728 - atomic_read(&fscache_n_acquires),
43729 - atomic_read(&fscache_n_acquires_null),
43730 - atomic_read(&fscache_n_acquires_no_cache),
43731 - atomic_read(&fscache_n_acquires_ok),
43732 - atomic_read(&fscache_n_acquires_nobufs),
43733 - atomic_read(&fscache_n_acquires_oom));
43734 + atomic_read_unchecked(&fscache_n_acquires),
43735 + atomic_read_unchecked(&fscache_n_acquires_null),
43736 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
43737 + atomic_read_unchecked(&fscache_n_acquires_ok),
43738 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
43739 + atomic_read_unchecked(&fscache_n_acquires_oom));
43740
43741 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
43742 - atomic_read(&fscache_n_object_lookups),
43743 - atomic_read(&fscache_n_object_lookups_negative),
43744 - atomic_read(&fscache_n_object_lookups_positive),
43745 - atomic_read(&fscache_n_object_created),
43746 - atomic_read(&fscache_n_object_lookups_timed_out));
43747 + atomic_read_unchecked(&fscache_n_object_lookups),
43748 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
43749 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
43750 + atomic_read_unchecked(&fscache_n_object_created),
43751 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
43752
43753 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
43754 - atomic_read(&fscache_n_updates),
43755 - atomic_read(&fscache_n_updates_null),
43756 - atomic_read(&fscache_n_updates_run));
43757 + atomic_read_unchecked(&fscache_n_updates),
43758 + atomic_read_unchecked(&fscache_n_updates_null),
43759 + atomic_read_unchecked(&fscache_n_updates_run));
43760
43761 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
43762 - atomic_read(&fscache_n_relinquishes),
43763 - atomic_read(&fscache_n_relinquishes_null),
43764 - atomic_read(&fscache_n_relinquishes_waitcrt),
43765 - atomic_read(&fscache_n_relinquishes_retire));
43766 + atomic_read_unchecked(&fscache_n_relinquishes),
43767 + atomic_read_unchecked(&fscache_n_relinquishes_null),
43768 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
43769 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
43770
43771 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
43772 - atomic_read(&fscache_n_attr_changed),
43773 - atomic_read(&fscache_n_attr_changed_ok),
43774 - atomic_read(&fscache_n_attr_changed_nobufs),
43775 - atomic_read(&fscache_n_attr_changed_nomem),
43776 - atomic_read(&fscache_n_attr_changed_calls));
43777 + atomic_read_unchecked(&fscache_n_attr_changed),
43778 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
43779 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
43780 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
43781 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
43782
43783 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
43784 - atomic_read(&fscache_n_allocs),
43785 - atomic_read(&fscache_n_allocs_ok),
43786 - atomic_read(&fscache_n_allocs_wait),
43787 - atomic_read(&fscache_n_allocs_nobufs),
43788 - atomic_read(&fscache_n_allocs_intr));
43789 + atomic_read_unchecked(&fscache_n_allocs),
43790 + atomic_read_unchecked(&fscache_n_allocs_ok),
43791 + atomic_read_unchecked(&fscache_n_allocs_wait),
43792 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
43793 + atomic_read_unchecked(&fscache_n_allocs_intr));
43794 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
43795 - atomic_read(&fscache_n_alloc_ops),
43796 - atomic_read(&fscache_n_alloc_op_waits),
43797 - atomic_read(&fscache_n_allocs_object_dead));
43798 + atomic_read_unchecked(&fscache_n_alloc_ops),
43799 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
43800 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
43801
43802 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
43803 " int=%u oom=%u\n",
43804 - atomic_read(&fscache_n_retrievals),
43805 - atomic_read(&fscache_n_retrievals_ok),
43806 - atomic_read(&fscache_n_retrievals_wait),
43807 - atomic_read(&fscache_n_retrievals_nodata),
43808 - atomic_read(&fscache_n_retrievals_nobufs),
43809 - atomic_read(&fscache_n_retrievals_intr),
43810 - atomic_read(&fscache_n_retrievals_nomem));
43811 + atomic_read_unchecked(&fscache_n_retrievals),
43812 + atomic_read_unchecked(&fscache_n_retrievals_ok),
43813 + atomic_read_unchecked(&fscache_n_retrievals_wait),
43814 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
43815 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
43816 + atomic_read_unchecked(&fscache_n_retrievals_intr),
43817 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
43818 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
43819 - atomic_read(&fscache_n_retrieval_ops),
43820 - atomic_read(&fscache_n_retrieval_op_waits),
43821 - atomic_read(&fscache_n_retrievals_object_dead));
43822 + atomic_read_unchecked(&fscache_n_retrieval_ops),
43823 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
43824 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
43825
43826 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
43827 - atomic_read(&fscache_n_stores),
43828 - atomic_read(&fscache_n_stores_ok),
43829 - atomic_read(&fscache_n_stores_again),
43830 - atomic_read(&fscache_n_stores_nobufs),
43831 - atomic_read(&fscache_n_stores_oom));
43832 + atomic_read_unchecked(&fscache_n_stores),
43833 + atomic_read_unchecked(&fscache_n_stores_ok),
43834 + atomic_read_unchecked(&fscache_n_stores_again),
43835 + atomic_read_unchecked(&fscache_n_stores_nobufs),
43836 + atomic_read_unchecked(&fscache_n_stores_oom));
43837 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
43838 - atomic_read(&fscache_n_store_ops),
43839 - atomic_read(&fscache_n_store_calls),
43840 - atomic_read(&fscache_n_store_pages),
43841 - atomic_read(&fscache_n_store_radix_deletes),
43842 - atomic_read(&fscache_n_store_pages_over_limit));
43843 + atomic_read_unchecked(&fscache_n_store_ops),
43844 + atomic_read_unchecked(&fscache_n_store_calls),
43845 + atomic_read_unchecked(&fscache_n_store_pages),
43846 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
43847 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
43848
43849 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
43850 - atomic_read(&fscache_n_store_vmscan_not_storing),
43851 - atomic_read(&fscache_n_store_vmscan_gone),
43852 - atomic_read(&fscache_n_store_vmscan_busy),
43853 - atomic_read(&fscache_n_store_vmscan_cancelled));
43854 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
43855 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
43856 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
43857 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
43858
43859 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
43860 - atomic_read(&fscache_n_op_pend),
43861 - atomic_read(&fscache_n_op_run),
43862 - atomic_read(&fscache_n_op_enqueue),
43863 - atomic_read(&fscache_n_op_cancelled),
43864 - atomic_read(&fscache_n_op_rejected));
43865 + atomic_read_unchecked(&fscache_n_op_pend),
43866 + atomic_read_unchecked(&fscache_n_op_run),
43867 + atomic_read_unchecked(&fscache_n_op_enqueue),
43868 + atomic_read_unchecked(&fscache_n_op_cancelled),
43869 + atomic_read_unchecked(&fscache_n_op_rejected));
43870 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
43871 - atomic_read(&fscache_n_op_deferred_release),
43872 - atomic_read(&fscache_n_op_release),
43873 - atomic_read(&fscache_n_op_gc));
43874 + atomic_read_unchecked(&fscache_n_op_deferred_release),
43875 + atomic_read_unchecked(&fscache_n_op_release),
43876 + atomic_read_unchecked(&fscache_n_op_gc));
43877
43878 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
43879 atomic_read(&fscache_n_cop_alloc_object),
43880 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
43881 index 3426521..3b75162 100644
43882 --- a/fs/fuse/cuse.c
43883 +++ b/fs/fuse/cuse.c
43884 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
43885 INIT_LIST_HEAD(&cuse_conntbl[i]);
43886
43887 /* inherit and extend fuse_dev_operations */
43888 - cuse_channel_fops = fuse_dev_operations;
43889 - cuse_channel_fops.owner = THIS_MODULE;
43890 - cuse_channel_fops.open = cuse_channel_open;
43891 - cuse_channel_fops.release = cuse_channel_release;
43892 + pax_open_kernel();
43893 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
43894 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
43895 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
43896 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
43897 + pax_close_kernel();
43898
43899 cuse_class = class_create(THIS_MODULE, "cuse");
43900 if (IS_ERR(cuse_class))
43901 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
43902 index 2aaf3ea..8e50863 100644
43903 --- a/fs/fuse/dev.c
43904 +++ b/fs/fuse/dev.c
43905 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
43906 ret = 0;
43907 pipe_lock(pipe);
43908
43909 - if (!pipe->readers) {
43910 + if (!atomic_read(&pipe->readers)) {
43911 send_sig(SIGPIPE, current, 0);
43912 if (!ret)
43913 ret = -EPIPE;
43914 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
43915 index 9f63e49..d8a64c0 100644
43916 --- a/fs/fuse/dir.c
43917 +++ b/fs/fuse/dir.c
43918 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *dentry)
43919 return link;
43920 }
43921
43922 -static void free_link(char *link)
43923 +static void free_link(const char *link)
43924 {
43925 if (!IS_ERR(link))
43926 free_page((unsigned long) link);
43927 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
43928 index cfd4959..a780959 100644
43929 --- a/fs/gfs2/inode.c
43930 +++ b/fs/gfs2/inode.c
43931 @@ -1490,7 +1490,7 @@ out:
43932
43933 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43934 {
43935 - char *s = nd_get_link(nd);
43936 + const char *s = nd_get_link(nd);
43937 if (!IS_ERR(s))
43938 kfree(s);
43939 }
43940 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
43941 index 0be5a78..9cfb853 100644
43942 --- a/fs/hugetlbfs/inode.c
43943 +++ b/fs/hugetlbfs/inode.c
43944 @@ -915,7 +915,7 @@ static struct file_system_type hugetlbfs_fs_type = {
43945 .kill_sb = kill_litter_super,
43946 };
43947
43948 -static struct vfsmount *hugetlbfs_vfsmount;
43949 +struct vfsmount *hugetlbfs_vfsmount;
43950
43951 static int can_do_hugetlb_shm(void)
43952 {
43953 diff --git a/fs/inode.c b/fs/inode.c
43954 index ee4e66b..0451521 100644
43955 --- a/fs/inode.c
43956 +++ b/fs/inode.c
43957 @@ -787,8 +787,8 @@ unsigned int get_next_ino(void)
43958
43959 #ifdef CONFIG_SMP
43960 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
43961 - static atomic_t shared_last_ino;
43962 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
43963 + static atomic_unchecked_t shared_last_ino;
43964 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
43965
43966 res = next - LAST_INO_BATCH;
43967 }
43968 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
43969 index e513f19..2ab1351 100644
43970 --- a/fs/jffs2/erase.c
43971 +++ b/fs/jffs2/erase.c
43972 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
43973 struct jffs2_unknown_node marker = {
43974 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
43975 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
43976 - .totlen = cpu_to_je32(c->cleanmarker_size)
43977 + .totlen = cpu_to_je32(c->cleanmarker_size),
43978 + .hdr_crc = cpu_to_je32(0)
43979 };
43980
43981 jffs2_prealloc_raw_node_refs(c, jeb, 1);
43982 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
43983 index b09e51d..e482afa 100644
43984 --- a/fs/jffs2/wbuf.c
43985 +++ b/fs/jffs2/wbuf.c
43986 @@ -1011,7 +1011,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
43987 {
43988 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
43989 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
43990 - .totlen = constant_cpu_to_je32(8)
43991 + .totlen = constant_cpu_to_je32(8),
43992 + .hdr_crc = constant_cpu_to_je32(0)
43993 };
43994
43995 /*
43996 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
43997 index a44eff0..462e07d 100644
43998 --- a/fs/jfs/super.c
43999 +++ b/fs/jfs/super.c
44000 @@ -802,7 +802,7 @@ static int __init init_jfs_fs(void)
44001
44002 jfs_inode_cachep =
44003 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
44004 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
44005 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
44006 init_once);
44007 if (jfs_inode_cachep == NULL)
44008 return -ENOMEM;
44009 diff --git a/fs/libfs.c b/fs/libfs.c
44010 index f6d411e..e82a08d 100644
44011 --- a/fs/libfs.c
44012 +++ b/fs/libfs.c
44013 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
44014
44015 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
44016 struct dentry *next;
44017 + char d_name[sizeof(next->d_iname)];
44018 + const unsigned char *name;
44019 +
44020 next = list_entry(p, struct dentry, d_u.d_child);
44021 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
44022 if (!simple_positive(next)) {
44023 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
44024
44025 spin_unlock(&next->d_lock);
44026 spin_unlock(&dentry->d_lock);
44027 - if (filldir(dirent, next->d_name.name,
44028 + name = next->d_name.name;
44029 + if (name == next->d_iname) {
44030 + memcpy(d_name, name, next->d_name.len);
44031 + name = d_name;
44032 + }
44033 + if (filldir(dirent, name,
44034 next->d_name.len, filp->f_pos,
44035 next->d_inode->i_ino,
44036 dt_type(next->d_inode)) < 0)
44037 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
44038 index 8392cb8..80d6193 100644
44039 --- a/fs/lockd/clntproc.c
44040 +++ b/fs/lockd/clntproc.c
44041 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
44042 /*
44043 * Cookie counter for NLM requests
44044 */
44045 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
44046 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
44047
44048 void nlmclnt_next_cookie(struct nlm_cookie *c)
44049 {
44050 - u32 cookie = atomic_inc_return(&nlm_cookie);
44051 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
44052
44053 memcpy(c->data, &cookie, 4);
44054 c->len=4;
44055 diff --git a/fs/locks.c b/fs/locks.c
44056 index 637694b..f84a121 100644
44057 --- a/fs/locks.c
44058 +++ b/fs/locks.c
44059 @@ -2074,16 +2074,16 @@ void locks_remove_flock(struct file *filp)
44060 return;
44061
44062 if (filp->f_op && filp->f_op->flock) {
44063 - struct file_lock fl = {
44064 + struct file_lock flock = {
44065 .fl_pid = current->tgid,
44066 .fl_file = filp,
44067 .fl_flags = FL_FLOCK,
44068 .fl_type = F_UNLCK,
44069 .fl_end = OFFSET_MAX,
44070 };
44071 - filp->f_op->flock(filp, F_SETLKW, &fl);
44072 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
44073 - fl.fl_ops->fl_release_private(&fl);
44074 + filp->f_op->flock(filp, F_SETLKW, &flock);
44075 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
44076 + flock.fl_ops->fl_release_private(&flock);
44077 }
44078
44079 lock_flocks();
44080 diff --git a/fs/namei.c b/fs/namei.c
44081 index 5008f01..90328a7 100644
44082 --- a/fs/namei.c
44083 +++ b/fs/namei.c
44084 @@ -279,16 +279,32 @@ int generic_permission(struct inode *inode, int mask)
44085 if (ret != -EACCES)
44086 return ret;
44087
44088 +#ifdef CONFIG_GRKERNSEC
44089 + /* we'll block if we have to log due to a denied capability use */
44090 + if (mask & MAY_NOT_BLOCK)
44091 + return -ECHILD;
44092 +#endif
44093 +
44094 if (S_ISDIR(inode->i_mode)) {
44095 /* DACs are overridable for directories */
44096 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44097 - return 0;
44098 if (!(mask & MAY_WRITE))
44099 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44100 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
44101 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44102 return 0;
44103 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44104 + return 0;
44105 return -EACCES;
44106 }
44107 /*
44108 + * Searching includes executable on directories, else just read.
44109 + */
44110 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
44111 + if (mask == MAY_READ)
44112 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
44113 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44114 + return 0;
44115 +
44116 + /*
44117 * Read/write DACs are always overridable.
44118 * Executable DACs are overridable when there is
44119 * at least one exec bit set.
44120 @@ -297,14 +313,6 @@ int generic_permission(struct inode *inode, int mask)
44121 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44122 return 0;
44123
44124 - /*
44125 - * Searching includes executable on directories, else just read.
44126 - */
44127 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
44128 - if (mask == MAY_READ)
44129 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44130 - return 0;
44131 -
44132 return -EACCES;
44133 }
44134
44135 @@ -653,11 +661,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
44136 return error;
44137 }
44138
44139 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
44140 + dentry->d_inode, dentry, nd->path.mnt)) {
44141 + error = -EACCES;
44142 + *p = ERR_PTR(error); /* no ->put_link(), please */
44143 + path_put(&nd->path);
44144 + return error;
44145 + }
44146 +
44147 nd->last_type = LAST_BIND;
44148 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
44149 error = PTR_ERR(*p);
44150 if (!IS_ERR(*p)) {
44151 - char *s = nd_get_link(nd);
44152 + const char *s = nd_get_link(nd);
44153 error = 0;
44154 if (s)
44155 error = __vfs_follow_link(nd, s);
44156 @@ -1622,6 +1638,21 @@ static int path_lookupat(int dfd, const char *name,
44157 if (!err)
44158 err = complete_walk(nd);
44159
44160 + if (!(nd->flags & LOOKUP_PARENT)) {
44161 +#ifdef CONFIG_GRKERNSEC
44162 + if (flags & LOOKUP_RCU) {
44163 + if (!err)
44164 + path_put(&nd->path);
44165 + err = -ECHILD;
44166 + } else
44167 +#endif
44168 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44169 + if (!err)
44170 + path_put(&nd->path);
44171 + err = -ENOENT;
44172 + }
44173 + }
44174 +
44175 if (!err && nd->flags & LOOKUP_DIRECTORY) {
44176 if (!nd->inode->i_op->lookup) {
44177 path_put(&nd->path);
44178 @@ -1649,6 +1680,15 @@ static int do_path_lookup(int dfd, const char *name,
44179 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
44180
44181 if (likely(!retval)) {
44182 + if (*name != '/' && nd->path.dentry && nd->inode) {
44183 +#ifdef CONFIG_GRKERNSEC
44184 + if (flags & LOOKUP_RCU)
44185 + return -ECHILD;
44186 +#endif
44187 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
44188 + return -ENOENT;
44189 + }
44190 +
44191 if (unlikely(!audit_dummy_context())) {
44192 if (nd->path.dentry && nd->inode)
44193 audit_inode(name, nd->path.dentry);
44194 @@ -2046,6 +2086,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
44195 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
44196 return -EPERM;
44197
44198 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
44199 + return -EPERM;
44200 + if (gr_handle_rawio(inode))
44201 + return -EPERM;
44202 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
44203 + return -EACCES;
44204 +
44205 return 0;
44206 }
44207
44208 @@ -2107,6 +2154,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44209 error = complete_walk(nd);
44210 if (error)
44211 return ERR_PTR(error);
44212 +#ifdef CONFIG_GRKERNSEC
44213 + if (nd->flags & LOOKUP_RCU) {
44214 + error = -ECHILD;
44215 + goto exit;
44216 + }
44217 +#endif
44218 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44219 + error = -ENOENT;
44220 + goto exit;
44221 + }
44222 audit_inode(pathname, nd->path.dentry);
44223 if (open_flag & O_CREAT) {
44224 error = -EISDIR;
44225 @@ -2117,6 +2174,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44226 error = complete_walk(nd);
44227 if (error)
44228 return ERR_PTR(error);
44229 +#ifdef CONFIG_GRKERNSEC
44230 + if (nd->flags & LOOKUP_RCU) {
44231 + error = -ECHILD;
44232 + goto exit;
44233 + }
44234 +#endif
44235 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
44236 + error = -ENOENT;
44237 + goto exit;
44238 + }
44239 audit_inode(pathname, dir);
44240 goto ok;
44241 }
44242 @@ -2138,6 +2205,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44243 error = complete_walk(nd);
44244 if (error)
44245 return ERR_PTR(-ECHILD);
44246 +#ifdef CONFIG_GRKERNSEC
44247 + if (nd->flags & LOOKUP_RCU) {
44248 + error = -ECHILD;
44249 + goto exit;
44250 + }
44251 +#endif
44252 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44253 + error = -ENOENT;
44254 + goto exit;
44255 + }
44256
44257 error = -ENOTDIR;
44258 if (nd->flags & LOOKUP_DIRECTORY) {
44259 @@ -2178,6 +2255,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44260 /* Negative dentry, just create the file */
44261 if (!dentry->d_inode) {
44262 int mode = op->mode;
44263 +
44264 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
44265 + error = -EACCES;
44266 + goto exit_mutex_unlock;
44267 + }
44268 +
44269 if (!IS_POSIXACL(dir->d_inode))
44270 mode &= ~current_umask();
44271 /*
44272 @@ -2201,6 +2284,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44273 error = vfs_create(dir->d_inode, dentry, mode, nd);
44274 if (error)
44275 goto exit_mutex_unlock;
44276 + else
44277 + gr_handle_create(path->dentry, path->mnt);
44278 mutex_unlock(&dir->d_inode->i_mutex);
44279 dput(nd->path.dentry);
44280 nd->path.dentry = dentry;
44281 @@ -2210,6 +2295,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44282 /*
44283 * It already exists.
44284 */
44285 +
44286 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
44287 + error = -ENOENT;
44288 + goto exit_mutex_unlock;
44289 + }
44290 +
44291 + /* only check if O_CREAT is specified, all other checks need to go
44292 + into may_open */
44293 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
44294 + error = -EACCES;
44295 + goto exit_mutex_unlock;
44296 + }
44297 +
44298 mutex_unlock(&dir->d_inode->i_mutex);
44299 audit_inode(pathname, path->dentry);
44300
44301 @@ -2422,6 +2520,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
44302 *path = nd.path;
44303 return dentry;
44304 eexist:
44305 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
44306 + dput(dentry);
44307 + dentry = ERR_PTR(-ENOENT);
44308 + goto fail;
44309 + }
44310 dput(dentry);
44311 dentry = ERR_PTR(-EEXIST);
44312 fail:
44313 @@ -2444,6 +2547,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
44314 }
44315 EXPORT_SYMBOL(user_path_create);
44316
44317 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
44318 +{
44319 + char *tmp = getname(pathname);
44320 + struct dentry *res;
44321 + if (IS_ERR(tmp))
44322 + return ERR_CAST(tmp);
44323 + res = kern_path_create(dfd, tmp, path, is_dir);
44324 + if (IS_ERR(res))
44325 + putname(tmp);
44326 + else
44327 + *to = tmp;
44328 + return res;
44329 +}
44330 +
44331 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
44332 {
44333 int error = may_create(dir, dentry);
44334 @@ -2511,6 +2628,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
44335 error = mnt_want_write(path.mnt);
44336 if (error)
44337 goto out_dput;
44338 +
44339 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
44340 + error = -EPERM;
44341 + goto out_drop_write;
44342 + }
44343 +
44344 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
44345 + error = -EACCES;
44346 + goto out_drop_write;
44347 + }
44348 +
44349 error = security_path_mknod(&path, dentry, mode, dev);
44350 if (error)
44351 goto out_drop_write;
44352 @@ -2528,6 +2656,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
44353 }
44354 out_drop_write:
44355 mnt_drop_write(path.mnt);
44356 +
44357 + if (!error)
44358 + gr_handle_create(dentry, path.mnt);
44359 out_dput:
44360 dput(dentry);
44361 mutex_unlock(&path.dentry->d_inode->i_mutex);
44362 @@ -2577,12 +2708,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
44363 error = mnt_want_write(path.mnt);
44364 if (error)
44365 goto out_dput;
44366 +
44367 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
44368 + error = -EACCES;
44369 + goto out_drop_write;
44370 + }
44371 +
44372 error = security_path_mkdir(&path, dentry, mode);
44373 if (error)
44374 goto out_drop_write;
44375 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
44376 out_drop_write:
44377 mnt_drop_write(path.mnt);
44378 +
44379 + if (!error)
44380 + gr_handle_create(dentry, path.mnt);
44381 out_dput:
44382 dput(dentry);
44383 mutex_unlock(&path.dentry->d_inode->i_mutex);
44384 @@ -2662,6 +2802,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
44385 char * name;
44386 struct dentry *dentry;
44387 struct nameidata nd;
44388 + ino_t saved_ino = 0;
44389 + dev_t saved_dev = 0;
44390
44391 error = user_path_parent(dfd, pathname, &nd, &name);
44392 if (error)
44393 @@ -2690,6 +2832,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
44394 error = -ENOENT;
44395 goto exit3;
44396 }
44397 +
44398 + saved_ino = dentry->d_inode->i_ino;
44399 + saved_dev = gr_get_dev_from_dentry(dentry);
44400 +
44401 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
44402 + error = -EACCES;
44403 + goto exit3;
44404 + }
44405 +
44406 error = mnt_want_write(nd.path.mnt);
44407 if (error)
44408 goto exit3;
44409 @@ -2697,6 +2848,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
44410 if (error)
44411 goto exit4;
44412 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
44413 + if (!error && (saved_dev || saved_ino))
44414 + gr_handle_delete(saved_ino, saved_dev);
44415 exit4:
44416 mnt_drop_write(nd.path.mnt);
44417 exit3:
44418 @@ -2759,6 +2912,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44419 struct dentry *dentry;
44420 struct nameidata nd;
44421 struct inode *inode = NULL;
44422 + ino_t saved_ino = 0;
44423 + dev_t saved_dev = 0;
44424
44425 error = user_path_parent(dfd, pathname, &nd, &name);
44426 if (error)
44427 @@ -2781,6 +2936,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44428 if (!inode)
44429 goto slashes;
44430 ihold(inode);
44431 +
44432 + if (inode->i_nlink <= 1) {
44433 + saved_ino = inode->i_ino;
44434 + saved_dev = gr_get_dev_from_dentry(dentry);
44435 + }
44436 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
44437 + error = -EACCES;
44438 + goto exit2;
44439 + }
44440 +
44441 error = mnt_want_write(nd.path.mnt);
44442 if (error)
44443 goto exit2;
44444 @@ -2788,6 +2953,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44445 if (error)
44446 goto exit3;
44447 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
44448 + if (!error && (saved_ino || saved_dev))
44449 + gr_handle_delete(saved_ino, saved_dev);
44450 exit3:
44451 mnt_drop_write(nd.path.mnt);
44452 exit2:
44453 @@ -2863,10 +3030,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
44454 error = mnt_want_write(path.mnt);
44455 if (error)
44456 goto out_dput;
44457 +
44458 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
44459 + error = -EACCES;
44460 + goto out_drop_write;
44461 + }
44462 +
44463 error = security_path_symlink(&path, dentry, from);
44464 if (error)
44465 goto out_drop_write;
44466 error = vfs_symlink(path.dentry->d_inode, dentry, from);
44467 + if (!error)
44468 + gr_handle_create(dentry, path.mnt);
44469 out_drop_write:
44470 mnt_drop_write(path.mnt);
44471 out_dput:
44472 @@ -2938,6 +3113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44473 {
44474 struct dentry *new_dentry;
44475 struct path old_path, new_path;
44476 + char *to = NULL;
44477 int how = 0;
44478 int error;
44479
44480 @@ -2961,7 +3137,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44481 if (error)
44482 return error;
44483
44484 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
44485 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
44486 error = PTR_ERR(new_dentry);
44487 if (IS_ERR(new_dentry))
44488 goto out;
44489 @@ -2972,13 +3148,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44490 error = mnt_want_write(new_path.mnt);
44491 if (error)
44492 goto out_dput;
44493 +
44494 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
44495 + old_path.dentry->d_inode,
44496 + old_path.dentry->d_inode->i_mode, to)) {
44497 + error = -EACCES;
44498 + goto out_drop_write;
44499 + }
44500 +
44501 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
44502 + old_path.dentry, old_path.mnt, to)) {
44503 + error = -EACCES;
44504 + goto out_drop_write;
44505 + }
44506 +
44507 error = security_path_link(old_path.dentry, &new_path, new_dentry);
44508 if (error)
44509 goto out_drop_write;
44510 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
44511 + if (!error)
44512 + gr_handle_create(new_dentry, new_path.mnt);
44513 out_drop_write:
44514 mnt_drop_write(new_path.mnt);
44515 out_dput:
44516 + putname(to);
44517 dput(new_dentry);
44518 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
44519 path_put(&new_path);
44520 @@ -3206,6 +3399,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
44521 if (new_dentry == trap)
44522 goto exit5;
44523
44524 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
44525 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
44526 + to);
44527 + if (error)
44528 + goto exit5;
44529 +
44530 error = mnt_want_write(oldnd.path.mnt);
44531 if (error)
44532 goto exit5;
44533 @@ -3215,6 +3414,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
44534 goto exit6;
44535 error = vfs_rename(old_dir->d_inode, old_dentry,
44536 new_dir->d_inode, new_dentry);
44537 + if (!error)
44538 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
44539 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
44540 exit6:
44541 mnt_drop_write(oldnd.path.mnt);
44542 exit5:
44543 @@ -3240,6 +3442,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
44544
44545 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
44546 {
44547 + char tmpbuf[64];
44548 + const char *newlink;
44549 int len;
44550
44551 len = PTR_ERR(link);
44552 @@ -3249,7 +3453,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
44553 len = strlen(link);
44554 if (len > (unsigned) buflen)
44555 len = buflen;
44556 - if (copy_to_user(buffer, link, len))
44557 +
44558 + if (len < sizeof(tmpbuf)) {
44559 + memcpy(tmpbuf, link, len);
44560 + newlink = tmpbuf;
44561 + } else
44562 + newlink = link;
44563 +
44564 + if (copy_to_user(buffer, newlink, len))
44565 len = -EFAULT;
44566 out:
44567 return len;
44568 diff --git a/fs/namespace.c b/fs/namespace.c
44569 index cfc6d44..b4632a5 100644
44570 --- a/fs/namespace.c
44571 +++ b/fs/namespace.c
44572 @@ -1326,6 +1326,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
44573 if (!(sb->s_flags & MS_RDONLY))
44574 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
44575 up_write(&sb->s_umount);
44576 +
44577 + gr_log_remount(mnt->mnt_devname, retval);
44578 +
44579 return retval;
44580 }
44581
44582 @@ -1345,6 +1348,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
44583 br_write_unlock(vfsmount_lock);
44584 up_write(&namespace_sem);
44585 release_mounts(&umount_list);
44586 +
44587 + gr_log_unmount(mnt->mnt_devname, retval);
44588 +
44589 return retval;
44590 }
44591
44592 @@ -2336,6 +2342,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
44593 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
44594 MS_STRICTATIME);
44595
44596 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
44597 + retval = -EPERM;
44598 + goto dput_out;
44599 + }
44600 +
44601 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
44602 + retval = -EPERM;
44603 + goto dput_out;
44604 + }
44605 +
44606 if (flags & MS_REMOUNT)
44607 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
44608 data_page);
44609 @@ -2350,6 +2366,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
44610 dev_name, data_page);
44611 dput_out:
44612 path_put(&path);
44613 +
44614 + gr_log_mount(dev_name, dir_name, retval);
44615 +
44616 return retval;
44617 }
44618
44619 @@ -2605,6 +2624,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
44620 if (error)
44621 goto out2;
44622
44623 + if (gr_handle_chroot_pivot()) {
44624 + error = -EPERM;
44625 + goto out2;
44626 + }
44627 +
44628 get_fs_root(current->fs, &root);
44629 error = lock_mount(&old);
44630 if (error)
44631 diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
44632 index 3db6b82..a57597e 100644
44633 --- a/fs/nfs/blocklayout/blocklayout.c
44634 +++ b/fs/nfs/blocklayout/blocklayout.c
44635 @@ -90,7 +90,7 @@ static int is_writable(struct pnfs_block_extent *be, sector_t isect)
44636 */
44637 struct parallel_io {
44638 struct kref refcnt;
44639 - struct rpc_call_ops call_ops;
44640 + rpc_call_ops_no_const call_ops;
44641 void (*pnfs_callback) (void *data);
44642 void *data;
44643 };
44644 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
44645 index 50a15fa..ca113f9 100644
44646 --- a/fs/nfs/inode.c
44647 +++ b/fs/nfs/inode.c
44648 @@ -150,7 +150,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
44649 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
44650 nfsi->attrtimeo_timestamp = jiffies;
44651
44652 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
44653 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
44654 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
44655 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
44656 else
44657 @@ -1002,16 +1002,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
44658 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
44659 }
44660
44661 -static atomic_long_t nfs_attr_generation_counter;
44662 +static atomic_long_unchecked_t nfs_attr_generation_counter;
44663
44664 static unsigned long nfs_read_attr_generation_counter(void)
44665 {
44666 - return atomic_long_read(&nfs_attr_generation_counter);
44667 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
44668 }
44669
44670 unsigned long nfs_inc_attr_generation_counter(void)
44671 {
44672 - return atomic_long_inc_return(&nfs_attr_generation_counter);
44673 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
44674 }
44675
44676 void nfs_fattr_init(struct nfs_fattr *fattr)
44677 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
44678 index 7a2e442..8e544cc 100644
44679 --- a/fs/nfsd/vfs.c
44680 +++ b/fs/nfsd/vfs.c
44681 @@ -914,7 +914,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
44682 } else {
44683 oldfs = get_fs();
44684 set_fs(KERNEL_DS);
44685 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
44686 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
44687 set_fs(oldfs);
44688 }
44689
44690 @@ -1018,7 +1018,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
44691
44692 /* Write the data. */
44693 oldfs = get_fs(); set_fs(KERNEL_DS);
44694 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
44695 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
44696 set_fs(oldfs);
44697 if (host_err < 0)
44698 goto out_nfserr;
44699 @@ -1553,7 +1553,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
44700 */
44701
44702 oldfs = get_fs(); set_fs(KERNEL_DS);
44703 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
44704 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
44705 set_fs(oldfs);
44706
44707 if (host_err < 0)
44708 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
44709 index 9fde1c0..14e8827 100644
44710 --- a/fs/notify/fanotify/fanotify_user.c
44711 +++ b/fs/notify/fanotify/fanotify_user.c
44712 @@ -276,7 +276,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
44713 goto out_close_fd;
44714
44715 ret = -EFAULT;
44716 - if (copy_to_user(buf, &fanotify_event_metadata,
44717 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
44718 + copy_to_user(buf, &fanotify_event_metadata,
44719 fanotify_event_metadata.event_len))
44720 goto out_kill_access_response;
44721
44722 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
44723 index ee18815..7aa5d01 100644
44724 --- a/fs/notify/notification.c
44725 +++ b/fs/notify/notification.c
44726 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
44727 * get set to 0 so it will never get 'freed'
44728 */
44729 static struct fsnotify_event *q_overflow_event;
44730 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
44731 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
44732
44733 /**
44734 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
44735 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
44736 */
44737 u32 fsnotify_get_cookie(void)
44738 {
44739 - return atomic_inc_return(&fsnotify_sync_cookie);
44740 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
44741 }
44742 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
44743
44744 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
44745 index 99e3610..02c1068 100644
44746 --- a/fs/ntfs/dir.c
44747 +++ b/fs/ntfs/dir.c
44748 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
44749 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
44750 ~(s64)(ndir->itype.index.block_size - 1)));
44751 /* Bounds checks. */
44752 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
44753 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
44754 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
44755 "inode 0x%lx or driver bug.", vdir->i_ino);
44756 goto err_out;
44757 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
44758 index c587e2d..3641eaa 100644
44759 --- a/fs/ntfs/file.c
44760 +++ b/fs/ntfs/file.c
44761 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
44762 #endif /* NTFS_RW */
44763 };
44764
44765 -const struct file_operations ntfs_empty_file_ops = {};
44766 +const struct file_operations ntfs_empty_file_ops __read_only;
44767
44768 -const struct inode_operations ntfs_empty_inode_ops = {};
44769 +const struct inode_operations ntfs_empty_inode_ops __read_only;
44770 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
44771 index 210c352..a174f83 100644
44772 --- a/fs/ocfs2/localalloc.c
44773 +++ b/fs/ocfs2/localalloc.c
44774 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
44775 goto bail;
44776 }
44777
44778 - atomic_inc(&osb->alloc_stats.moves);
44779 + atomic_inc_unchecked(&osb->alloc_stats.moves);
44780
44781 bail:
44782 if (handle)
44783 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
44784 index d355e6e..578d905 100644
44785 --- a/fs/ocfs2/ocfs2.h
44786 +++ b/fs/ocfs2/ocfs2.h
44787 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
44788
44789 struct ocfs2_alloc_stats
44790 {
44791 - atomic_t moves;
44792 - atomic_t local_data;
44793 - atomic_t bitmap_data;
44794 - atomic_t bg_allocs;
44795 - atomic_t bg_extends;
44796 + atomic_unchecked_t moves;
44797 + atomic_unchecked_t local_data;
44798 + atomic_unchecked_t bitmap_data;
44799 + atomic_unchecked_t bg_allocs;
44800 + atomic_unchecked_t bg_extends;
44801 };
44802
44803 enum ocfs2_local_alloc_state
44804 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
44805 index ba5d97e..c77db25 100644
44806 --- a/fs/ocfs2/suballoc.c
44807 +++ b/fs/ocfs2/suballoc.c
44808 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
44809 mlog_errno(status);
44810 goto bail;
44811 }
44812 - atomic_inc(&osb->alloc_stats.bg_extends);
44813 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
44814
44815 /* You should never ask for this much metadata */
44816 BUG_ON(bits_wanted >
44817 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
44818 mlog_errno(status);
44819 goto bail;
44820 }
44821 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44822 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44823
44824 *suballoc_loc = res.sr_bg_blkno;
44825 *suballoc_bit_start = res.sr_bit_offset;
44826 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
44827 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
44828 res->sr_bits);
44829
44830 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44831 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44832
44833 BUG_ON(res->sr_bits != 1);
44834
44835 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
44836 mlog_errno(status);
44837 goto bail;
44838 }
44839 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44840 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
44841
44842 BUG_ON(res.sr_bits != 1);
44843
44844 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
44845 cluster_start,
44846 num_clusters);
44847 if (!status)
44848 - atomic_inc(&osb->alloc_stats.local_data);
44849 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
44850 } else {
44851 if (min_clusters > (osb->bitmap_cpg - 1)) {
44852 /* The only paths asking for contiguousness
44853 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
44854 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
44855 res.sr_bg_blkno,
44856 res.sr_bit_offset);
44857 - atomic_inc(&osb->alloc_stats.bitmap_data);
44858 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
44859 *num_clusters = res.sr_bits;
44860 }
44861 }
44862 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
44863 index 4994f8b..eaab8eb 100644
44864 --- a/fs/ocfs2/super.c
44865 +++ b/fs/ocfs2/super.c
44866 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
44867 "%10s => GlobalAllocs: %d LocalAllocs: %d "
44868 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
44869 "Stats",
44870 - atomic_read(&osb->alloc_stats.bitmap_data),
44871 - atomic_read(&osb->alloc_stats.local_data),
44872 - atomic_read(&osb->alloc_stats.bg_allocs),
44873 - atomic_read(&osb->alloc_stats.moves),
44874 - atomic_read(&osb->alloc_stats.bg_extends));
44875 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
44876 + atomic_read_unchecked(&osb->alloc_stats.local_data),
44877 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
44878 + atomic_read_unchecked(&osb->alloc_stats.moves),
44879 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
44880
44881 out += snprintf(buf + out, len - out,
44882 "%10s => State: %u Descriptor: %llu Size: %u bits "
44883 @@ -2119,11 +2119,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
44884 spin_lock_init(&osb->osb_xattr_lock);
44885 ocfs2_init_steal_slots(osb);
44886
44887 - atomic_set(&osb->alloc_stats.moves, 0);
44888 - atomic_set(&osb->alloc_stats.local_data, 0);
44889 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
44890 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
44891 - atomic_set(&osb->alloc_stats.bg_extends, 0);
44892 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
44893 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
44894 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
44895 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
44896 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
44897
44898 /* Copy the blockcheck stats from the superblock probe */
44899 osb->osb_ecc_stats = *stats;
44900 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
44901 index 5d22872..523db20 100644
44902 --- a/fs/ocfs2/symlink.c
44903 +++ b/fs/ocfs2/symlink.c
44904 @@ -142,7 +142,7 @@ bail:
44905
44906 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
44907 {
44908 - char *link = nd_get_link(nd);
44909 + const char *link = nd_get_link(nd);
44910 if (!IS_ERR(link))
44911 kfree(link);
44912 }
44913 diff --git a/fs/open.c b/fs/open.c
44914 index 22c41b5..695cb17 100644
44915 --- a/fs/open.c
44916 +++ b/fs/open.c
44917 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
44918 error = locks_verify_truncate(inode, NULL, length);
44919 if (!error)
44920 error = security_path_truncate(&path);
44921 +
44922 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
44923 + error = -EACCES;
44924 +
44925 if (!error)
44926 error = do_truncate(path.dentry, length, 0, NULL);
44927
44928 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
44929 if (__mnt_is_readonly(path.mnt))
44930 res = -EROFS;
44931
44932 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
44933 + res = -EACCES;
44934 +
44935 out_path_release:
44936 path_put(&path);
44937 out:
44938 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
44939 if (error)
44940 goto dput_and_out;
44941
44942 + gr_log_chdir(path.dentry, path.mnt);
44943 +
44944 set_fs_pwd(current->fs, &path);
44945
44946 dput_and_out:
44947 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
44948 goto out_putf;
44949
44950 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
44951 +
44952 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
44953 + error = -EPERM;
44954 +
44955 + if (!error)
44956 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
44957 +
44958 if (!error)
44959 set_fs_pwd(current->fs, &file->f_path);
44960 out_putf:
44961 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
44962 if (error)
44963 goto dput_and_out;
44964
44965 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
44966 + goto dput_and_out;
44967 +
44968 set_fs_root(current->fs, &path);
44969 +
44970 + gr_handle_chroot_chdir(&path);
44971 +
44972 error = 0;
44973 dput_and_out:
44974 path_put(&path);
44975 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
44976 if (error)
44977 return error;
44978 mutex_lock(&inode->i_mutex);
44979 +
44980 + if (!gr_acl_handle_fchmod(path->dentry, path->mnt, mode)) {
44981 + error = -EACCES;
44982 + goto out_unlock;
44983 + }
44984 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
44985 + error = -EACCES;
44986 + goto out_unlock;
44987 + }
44988 +
44989 error = security_path_chmod(path->dentry, path->mnt, mode);
44990 if (error)
44991 goto out_unlock;
44992 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
44993 int error;
44994 struct iattr newattrs;
44995
44996 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
44997 + return -EACCES;
44998 +
44999 newattrs.ia_valid = ATTR_CTIME;
45000 if (user != (uid_t) -1) {
45001 newattrs.ia_valid |= ATTR_UID;
45002 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
45003 index 6296b40..417c00f 100644
45004 --- a/fs/partitions/efi.c
45005 +++ b/fs/partitions/efi.c
45006 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
45007 if (!gpt)
45008 return NULL;
45009
45010 + if (!le32_to_cpu(gpt->num_partition_entries))
45011 + return NULL;
45012 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
45013 + if (!pte)
45014 + return NULL;
45015 +
45016 count = le32_to_cpu(gpt->num_partition_entries) *
45017 le32_to_cpu(gpt->sizeof_partition_entry);
45018 - if (!count)
45019 - return NULL;
45020 - pte = kzalloc(count, GFP_KERNEL);
45021 - if (!pte)
45022 - return NULL;
45023 -
45024 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
45025 (u8 *) pte,
45026 count) < count) {
45027 diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
45028 index bd8ae78..539d250 100644
45029 --- a/fs/partitions/ldm.c
45030 +++ b/fs/partitions/ldm.c
45031 @@ -1324,7 +1324,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
45032 goto found;
45033 }
45034
45035 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
45036 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
45037 if (!f) {
45038 ldm_crit ("Out of memory.");
45039 return false;
45040 diff --git a/fs/pipe.c b/fs/pipe.c
45041 index 4065f07..68c0706 100644
45042 --- a/fs/pipe.c
45043 +++ b/fs/pipe.c
45044 @@ -420,9 +420,9 @@ redo:
45045 }
45046 if (bufs) /* More to do? */
45047 continue;
45048 - if (!pipe->writers)
45049 + if (!atomic_read(&pipe->writers))
45050 break;
45051 - if (!pipe->waiting_writers) {
45052 + if (!atomic_read(&pipe->waiting_writers)) {
45053 /* syscall merging: Usually we must not sleep
45054 * if O_NONBLOCK is set, or if we got some data.
45055 * But if a writer sleeps in kernel space, then
45056 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
45057 mutex_lock(&inode->i_mutex);
45058 pipe = inode->i_pipe;
45059
45060 - if (!pipe->readers) {
45061 + if (!atomic_read(&pipe->readers)) {
45062 send_sig(SIGPIPE, current, 0);
45063 ret = -EPIPE;
45064 goto out;
45065 @@ -530,7 +530,7 @@ redo1:
45066 for (;;) {
45067 int bufs;
45068
45069 - if (!pipe->readers) {
45070 + if (!atomic_read(&pipe->readers)) {
45071 send_sig(SIGPIPE, current, 0);
45072 if (!ret)
45073 ret = -EPIPE;
45074 @@ -616,9 +616,9 @@ redo2:
45075 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45076 do_wakeup = 0;
45077 }
45078 - pipe->waiting_writers++;
45079 + atomic_inc(&pipe->waiting_writers);
45080 pipe_wait(pipe);
45081 - pipe->waiting_writers--;
45082 + atomic_dec(&pipe->waiting_writers);
45083 }
45084 out:
45085 mutex_unlock(&inode->i_mutex);
45086 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
45087 mask = 0;
45088 if (filp->f_mode & FMODE_READ) {
45089 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
45090 - if (!pipe->writers && filp->f_version != pipe->w_counter)
45091 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
45092 mask |= POLLHUP;
45093 }
45094
45095 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
45096 * Most Unices do not set POLLERR for FIFOs but on Linux they
45097 * behave exactly like pipes for poll().
45098 */
45099 - if (!pipe->readers)
45100 + if (!atomic_read(&pipe->readers))
45101 mask |= POLLERR;
45102 }
45103
45104 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
45105
45106 mutex_lock(&inode->i_mutex);
45107 pipe = inode->i_pipe;
45108 - pipe->readers -= decr;
45109 - pipe->writers -= decw;
45110 + atomic_sub(decr, &pipe->readers);
45111 + atomic_sub(decw, &pipe->writers);
45112
45113 - if (!pipe->readers && !pipe->writers) {
45114 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
45115 free_pipe_info(inode);
45116 } else {
45117 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
45118 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
45119
45120 if (inode->i_pipe) {
45121 ret = 0;
45122 - inode->i_pipe->readers++;
45123 + atomic_inc(&inode->i_pipe->readers);
45124 }
45125
45126 mutex_unlock(&inode->i_mutex);
45127 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
45128
45129 if (inode->i_pipe) {
45130 ret = 0;
45131 - inode->i_pipe->writers++;
45132 + atomic_inc(&inode->i_pipe->writers);
45133 }
45134
45135 mutex_unlock(&inode->i_mutex);
45136 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
45137 if (inode->i_pipe) {
45138 ret = 0;
45139 if (filp->f_mode & FMODE_READ)
45140 - inode->i_pipe->readers++;
45141 + atomic_inc(&inode->i_pipe->readers);
45142 if (filp->f_mode & FMODE_WRITE)
45143 - inode->i_pipe->writers++;
45144 + atomic_inc(&inode->i_pipe->writers);
45145 }
45146
45147 mutex_unlock(&inode->i_mutex);
45148 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
45149 inode->i_pipe = NULL;
45150 }
45151
45152 -static struct vfsmount *pipe_mnt __read_mostly;
45153 +struct vfsmount *pipe_mnt __read_mostly;
45154
45155 /*
45156 * pipefs_dname() is called from d_path().
45157 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
45158 goto fail_iput;
45159 inode->i_pipe = pipe;
45160
45161 - pipe->readers = pipe->writers = 1;
45162 + atomic_set(&pipe->readers, 1);
45163 + atomic_set(&pipe->writers, 1);
45164 inode->i_fop = &rdwr_pipefifo_fops;
45165
45166 /*
45167 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
45168 index 15af622..0e9f4467 100644
45169 --- a/fs/proc/Kconfig
45170 +++ b/fs/proc/Kconfig
45171 @@ -30,12 +30,12 @@ config PROC_FS
45172
45173 config PROC_KCORE
45174 bool "/proc/kcore support" if !ARM
45175 - depends on PROC_FS && MMU
45176 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
45177
45178 config PROC_VMCORE
45179 bool "/proc/vmcore support"
45180 - depends on PROC_FS && CRASH_DUMP
45181 - default y
45182 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
45183 + default n
45184 help
45185 Exports the dump image of crashed kernel in ELF format.
45186
45187 @@ -59,8 +59,8 @@ config PROC_SYSCTL
45188 limited in memory.
45189
45190 config PROC_PAGE_MONITOR
45191 - default y
45192 - depends on PROC_FS && MMU
45193 + default n
45194 + depends on PROC_FS && MMU && !GRKERNSEC
45195 bool "Enable /proc page monitoring" if EXPERT
45196 help
45197 Various /proc files exist to monitor process memory utilization:
45198 diff --git a/fs/proc/array.c b/fs/proc/array.c
45199 index 3a1dafd..1456746 100644
45200 --- a/fs/proc/array.c
45201 +++ b/fs/proc/array.c
45202 @@ -60,6 +60,7 @@
45203 #include <linux/tty.h>
45204 #include <linux/string.h>
45205 #include <linux/mman.h>
45206 +#include <linux/grsecurity.h>
45207 #include <linux/proc_fs.h>
45208 #include <linux/ioport.h>
45209 #include <linux/uaccess.h>
45210 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
45211 seq_putc(m, '\n');
45212 }
45213
45214 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45215 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
45216 +{
45217 + if (p->mm)
45218 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
45219 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
45220 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
45221 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
45222 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
45223 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
45224 + else
45225 + seq_printf(m, "PaX:\t-----\n");
45226 +}
45227 +#endif
45228 +
45229 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
45230 struct pid *pid, struct task_struct *task)
45231 {
45232 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
45233 task_cpus_allowed(m, task);
45234 cpuset_task_status_allowed(m, task);
45235 task_context_switch_counts(m, task);
45236 +
45237 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45238 + task_pax(m, task);
45239 +#endif
45240 +
45241 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
45242 + task_grsec_rbac(m, task);
45243 +#endif
45244 +
45245 return 0;
45246 }
45247
45248 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45249 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45250 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
45251 + _mm->pax_flags & MF_PAX_SEGMEXEC))
45252 +#endif
45253 +
45254 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45255 struct pid *pid, struct task_struct *task, int whole)
45256 {
45257 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45258 char tcomm[sizeof(task->comm)];
45259 unsigned long flags;
45260
45261 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45262 + if (current->exec_id != m->exec_id) {
45263 + gr_log_badprocpid("stat");
45264 + return 0;
45265 + }
45266 +#endif
45267 +
45268 state = *get_task_state(task);
45269 vsize = eip = esp = 0;
45270 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
45271 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45272 gtime = task->gtime;
45273 }
45274
45275 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45276 + if (PAX_RAND_FLAGS(mm)) {
45277 + eip = 0;
45278 + esp = 0;
45279 + wchan = 0;
45280 + }
45281 +#endif
45282 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45283 + wchan = 0;
45284 + eip =0;
45285 + esp =0;
45286 +#endif
45287 +
45288 /* scale priority and nice values from timeslices to -20..20 */
45289 /* to make it look like a "normal" Unix priority/nice value */
45290 priority = task_prio(task);
45291 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45292 vsize,
45293 mm ? get_mm_rss(mm) : 0,
45294 rsslim,
45295 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45296 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
45297 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
45298 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
45299 +#else
45300 mm ? (permitted ? mm->start_code : 1) : 0,
45301 mm ? (permitted ? mm->end_code : 1) : 0,
45302 (permitted && mm) ? mm->start_stack : 0,
45303 +#endif
45304 esp,
45305 eip,
45306 /* The signal information here is obsolete.
45307 @@ -535,6 +592,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
45308 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
45309 struct mm_struct *mm = get_task_mm(task);
45310
45311 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45312 + if (current->exec_id != m->exec_id) {
45313 + gr_log_badprocpid("statm");
45314 + return 0;
45315 + }
45316 +#endif
45317 +
45318 if (mm) {
45319 size = task_statm(mm, &shared, &text, &data, &resident);
45320 mmput(mm);
45321 @@ -544,3 +608,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
45322
45323 return 0;
45324 }
45325 +
45326 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45327 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
45328 +{
45329 + u32 curr_ip = 0;
45330 + unsigned long flags;
45331 +
45332 + if (lock_task_sighand(task, &flags)) {
45333 + curr_ip = task->signal->curr_ip;
45334 + unlock_task_sighand(task, &flags);
45335 + }
45336 +
45337 + return sprintf(buffer, "%pI4\n", &curr_ip);
45338 +}
45339 +#endif
45340 diff --git a/fs/proc/base.c b/fs/proc/base.c
45341 index 1fc1dca..357b933 100644
45342 --- a/fs/proc/base.c
45343 +++ b/fs/proc/base.c
45344 @@ -107,6 +107,22 @@ struct pid_entry {
45345 union proc_op op;
45346 };
45347
45348 +struct getdents_callback {
45349 + struct linux_dirent __user * current_dir;
45350 + struct linux_dirent __user * previous;
45351 + struct file * file;
45352 + int count;
45353 + int error;
45354 +};
45355 +
45356 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
45357 + loff_t offset, u64 ino, unsigned int d_type)
45358 +{
45359 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
45360 + buf->error = -EINVAL;
45361 + return 0;
45362 +}
45363 +
45364 #define NOD(NAME, MODE, IOP, FOP, OP) { \
45365 .name = (NAME), \
45366 .len = sizeof(NAME) - 1, \
45367 @@ -194,26 +210,6 @@ static int proc_root_link(struct inode *inode, struct path *path)
45368 return result;
45369 }
45370
45371 -static struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
45372 -{
45373 - struct mm_struct *mm;
45374 - int err;
45375 -
45376 - err = mutex_lock_killable(&task->signal->cred_guard_mutex);
45377 - if (err)
45378 - return ERR_PTR(err);
45379 -
45380 - mm = get_task_mm(task);
45381 - if (mm && mm != current->mm &&
45382 - !ptrace_may_access(task, mode)) {
45383 - mmput(mm);
45384 - mm = ERR_PTR(-EACCES);
45385 - }
45386 - mutex_unlock(&task->signal->cred_guard_mutex);
45387 -
45388 - return mm;
45389 -}
45390 -
45391 struct mm_struct *mm_for_maps(struct task_struct *task)
45392 {
45393 return mm_access(task, PTRACE_MODE_READ);
45394 @@ -229,6 +225,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
45395 if (!mm->arg_end)
45396 goto out_mm; /* Shh! No looking before we're done */
45397
45398 + if (gr_acl_handle_procpidmem(task))
45399 + goto out_mm;
45400 +
45401 len = mm->arg_end - mm->arg_start;
45402
45403 if (len > PAGE_SIZE)
45404 @@ -256,12 +255,28 @@ out:
45405 return res;
45406 }
45407
45408 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45409 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45410 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
45411 + _mm->pax_flags & MF_PAX_SEGMEXEC))
45412 +#endif
45413 +
45414 static int proc_pid_auxv(struct task_struct *task, char *buffer)
45415 {
45416 struct mm_struct *mm = mm_for_maps(task);
45417 int res = PTR_ERR(mm);
45418 if (mm && !IS_ERR(mm)) {
45419 unsigned int nwords = 0;
45420 +
45421 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45422 + /* allow if we're currently ptracing this task */
45423 + if (PAX_RAND_FLAGS(mm) &&
45424 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
45425 + mmput(mm);
45426 + return 0;
45427 + }
45428 +#endif
45429 +
45430 do {
45431 nwords += 2;
45432 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
45433 @@ -275,7 +290,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
45434 }
45435
45436
45437 -#ifdef CONFIG_KALLSYMS
45438 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45439 /*
45440 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
45441 * Returns the resolved symbol. If that fails, simply return the address.
45442 @@ -314,7 +329,7 @@ static void unlock_trace(struct task_struct *task)
45443 mutex_unlock(&task->signal->cred_guard_mutex);
45444 }
45445
45446 -#ifdef CONFIG_STACKTRACE
45447 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45448
45449 #define MAX_STACK_TRACE_DEPTH 64
45450
45451 @@ -505,7 +520,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
45452 return count;
45453 }
45454
45455 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45456 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45457 static int proc_pid_syscall(struct task_struct *task, char *buffer)
45458 {
45459 long nr;
45460 @@ -534,7 +549,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
45461 /************************************************************************/
45462
45463 /* permission checks */
45464 -static int proc_fd_access_allowed(struct inode *inode)
45465 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
45466 {
45467 struct task_struct *task;
45468 int allowed = 0;
45469 @@ -544,7 +559,10 @@ static int proc_fd_access_allowed(struct inode *inode)
45470 */
45471 task = get_proc_task(inode);
45472 if (task) {
45473 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45474 + if (log)
45475 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
45476 + else
45477 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45478 put_task_struct(task);
45479 }
45480 return allowed;
45481 @@ -775,6 +793,13 @@ static int mem_open(struct inode* inode, struct file* file)
45482 if (IS_ERR(mm))
45483 return PTR_ERR(mm);
45484
45485 + if (mm) {
45486 + /* ensure this mm_struct can't be freed */
45487 + atomic_inc(&mm->mm_count);
45488 + /* but do not pin its memory */
45489 + mmput(mm);
45490 + }
45491 +
45492 /* OK to pass negative loff_t, we can catch out-of-range */
45493 file->f_mode |= FMODE_UNSIGNED_OFFSET;
45494 file->private_data = mm;
45495 @@ -782,57 +807,18 @@ static int mem_open(struct inode* inode, struct file* file)
45496 return 0;
45497 }
45498
45499 -static ssize_t mem_read(struct file * file, char __user * buf,
45500 - size_t count, loff_t *ppos)
45501 +static ssize_t mem_rw(struct file *file, char __user *buf,
45502 + size_t count, loff_t *ppos, int write)
45503 {
45504 - int ret;
45505 - char *page;
45506 - unsigned long src = *ppos;
45507 struct mm_struct *mm = file->private_data;
45508 -
45509 - if (!mm)
45510 - return 0;
45511 -
45512 - page = (char *)__get_free_page(GFP_TEMPORARY);
45513 - if (!page)
45514 - return -ENOMEM;
45515 -
45516 - ret = 0;
45517 -
45518 - while (count > 0) {
45519 - int this_len, retval;
45520 -
45521 - this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
45522 - retval = access_remote_vm(mm, src, page, this_len, 0);
45523 - if (!retval) {
45524 - if (!ret)
45525 - ret = -EIO;
45526 - break;
45527 - }
45528 -
45529 - if (copy_to_user(buf, page, retval)) {
45530 - ret = -EFAULT;
45531 - break;
45532 - }
45533 -
45534 - ret += retval;
45535 - src += retval;
45536 - buf += retval;
45537 - count -= retval;
45538 - }
45539 - *ppos = src;
45540 -
45541 - free_page((unsigned long) page);
45542 - return ret;
45543 -}
45544 -
45545 -static ssize_t mem_write(struct file * file, const char __user *buf,
45546 - size_t count, loff_t *ppos)
45547 -{
45548 - int copied;
45549 + unsigned long addr = *ppos;
45550 + ssize_t copied;
45551 char *page;
45552 - unsigned long dst = *ppos;
45553 - struct mm_struct *mm = file->private_data;
45554 +
45555 +#ifdef CONFIG_GRKERNSEC
45556 + if (write)
45557 + return -EPERM;
45558 +#endif
45559
45560 if (!mm)
45561 return 0;
45562 @@ -842,31 +828,54 @@ static ssize_t mem_write(struct file * file, const char __user *buf,
45563 return -ENOMEM;
45564
45565 copied = 0;
45566 + if (!atomic_inc_not_zero(&mm->mm_users))
45567 + goto free;
45568 +
45569 while (count > 0) {
45570 - int this_len, retval;
45571 + int this_len = min_t(int, count, PAGE_SIZE);
45572
45573 - this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
45574 - if (copy_from_user(page, buf, this_len)) {
45575 + if (write && copy_from_user(page, buf, this_len)) {
45576 copied = -EFAULT;
45577 break;
45578 }
45579 - retval = access_remote_vm(mm, dst, page, this_len, 1);
45580 - if (!retval) {
45581 +
45582 + this_len = access_remote_vm(mm, addr, page, this_len, write);
45583 + if (!this_len) {
45584 if (!copied)
45585 copied = -EIO;
45586 break;
45587 }
45588 - copied += retval;
45589 - buf += retval;
45590 - dst += retval;
45591 - count -= retval;
45592 +
45593 + if (!write && copy_to_user(buf, page, this_len)) {
45594 + copied = -EFAULT;
45595 + break;
45596 + }
45597 +
45598 + buf += this_len;
45599 + addr += this_len;
45600 + copied += this_len;
45601 + count -= this_len;
45602 }
45603 - *ppos = dst;
45604 + *ppos = addr;
45605
45606 + mmput(mm);
45607 +free:
45608 free_page((unsigned long) page);
45609 return copied;
45610 }
45611
45612 +static ssize_t mem_read(struct file *file, char __user *buf,
45613 + size_t count, loff_t *ppos)
45614 +{
45615 + return mem_rw(file, buf, count, ppos, 0);
45616 +}
45617 +
45618 +static ssize_t mem_write(struct file *file, const char __user *buf,
45619 + size_t count, loff_t *ppos)
45620 +{
45621 + return mem_rw(file, (char __user*)buf, count, ppos, 1);
45622 +}
45623 +
45624 loff_t mem_lseek(struct file *file, loff_t offset, int orig)
45625 {
45626 switch (orig) {
45627 @@ -886,8 +895,8 @@ loff_t mem_lseek(struct file *file, loff_t offset, int orig)
45628 static int mem_release(struct inode *inode, struct file *file)
45629 {
45630 struct mm_struct *mm = file->private_data;
45631 -
45632 - mmput(mm);
45633 + if (mm)
45634 + mmdrop(mm);
45635 return 0;
45636 }
45637
45638 @@ -911,6 +920,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
45639 if (!task)
45640 goto out_no_task;
45641
45642 + if (gr_acl_handle_procpidmem(task))
45643 + goto out;
45644 +
45645 ret = -ENOMEM;
45646 page = (char *)__get_free_page(GFP_TEMPORARY);
45647 if (!page)
45648 @@ -1533,7 +1545,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
45649 path_put(&nd->path);
45650
45651 /* Are we allowed to snoop on the tasks file descriptors? */
45652 - if (!proc_fd_access_allowed(inode))
45653 + if (!proc_fd_access_allowed(inode,0))
45654 goto out;
45655
45656 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
45657 @@ -1572,8 +1584,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
45658 struct path path;
45659
45660 /* Are we allowed to snoop on the tasks file descriptors? */
45661 - if (!proc_fd_access_allowed(inode))
45662 - goto out;
45663 + /* logging this is needed for learning on chromium to work properly,
45664 + but we don't want to flood the logs from 'ps' which does a readlink
45665 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
45666 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
45667 + */
45668 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
45669 + if (!proc_fd_access_allowed(inode,0))
45670 + goto out;
45671 + } else {
45672 + if (!proc_fd_access_allowed(inode,1))
45673 + goto out;
45674 + }
45675
45676 error = PROC_I(inode)->op.proc_get_link(inode, &path);
45677 if (error)
45678 @@ -1638,7 +1660,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
45679 rcu_read_lock();
45680 cred = __task_cred(task);
45681 inode->i_uid = cred->euid;
45682 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45683 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45684 +#else
45685 inode->i_gid = cred->egid;
45686 +#endif
45687 rcu_read_unlock();
45688 }
45689 security_task_to_inode(task, inode);
45690 @@ -1656,6 +1682,9 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
45691 struct inode *inode = dentry->d_inode;
45692 struct task_struct *task;
45693 const struct cred *cred;
45694 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45695 + const struct cred *tmpcred = current_cred();
45696 +#endif
45697
45698 generic_fillattr(inode, stat);
45699
45700 @@ -1663,13 +1692,41 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
45701 stat->uid = 0;
45702 stat->gid = 0;
45703 task = pid_task(proc_pid(inode), PIDTYPE_PID);
45704 +
45705 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
45706 + rcu_read_unlock();
45707 + return -ENOENT;
45708 + }
45709 +
45710 if (task) {
45711 + cred = __task_cred(task);
45712 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45713 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
45714 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45715 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
45716 +#endif
45717 + ) {
45718 +#endif
45719 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45720 +#ifdef CONFIG_GRKERNSEC_PROC_USER
45721 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45722 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45723 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45724 +#endif
45725 task_dumpable(task)) {
45726 - cred = __task_cred(task);
45727 stat->uid = cred->euid;
45728 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45729 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
45730 +#else
45731 stat->gid = cred->egid;
45732 +#endif
45733 }
45734 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45735 + } else {
45736 + rcu_read_unlock();
45737 + return -ENOENT;
45738 + }
45739 +#endif
45740 }
45741 rcu_read_unlock();
45742 return 0;
45743 @@ -1706,11 +1763,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
45744
45745 if (task) {
45746 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45747 +#ifdef CONFIG_GRKERNSEC_PROC_USER
45748 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45749 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45750 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45751 +#endif
45752 task_dumpable(task)) {
45753 rcu_read_lock();
45754 cred = __task_cred(task);
45755 inode->i_uid = cred->euid;
45756 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45757 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45758 +#else
45759 inode->i_gid = cred->egid;
45760 +#endif
45761 rcu_read_unlock();
45762 } else {
45763 inode->i_uid = 0;
45764 @@ -1828,7 +1894,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
45765 int fd = proc_fd(inode);
45766
45767 if (task) {
45768 - files = get_files_struct(task);
45769 + if (!gr_acl_handle_procpidmem(task))
45770 + files = get_files_struct(task);
45771 put_task_struct(task);
45772 }
45773 if (files) {
45774 @@ -2096,11 +2163,21 @@ static const struct file_operations proc_fd_operations = {
45775 */
45776 static int proc_fd_permission(struct inode *inode, int mask)
45777 {
45778 + struct task_struct *task;
45779 int rv = generic_permission(inode, mask);
45780 - if (rv == 0)
45781 - return 0;
45782 +
45783 if (task_pid(current) == proc_pid(inode))
45784 rv = 0;
45785 +
45786 + task = get_proc_task(inode);
45787 + if (task == NULL)
45788 + return rv;
45789 +
45790 + if (gr_acl_handle_procpidmem(task))
45791 + rv = -EACCES;
45792 +
45793 + put_task_struct(task);
45794 +
45795 return rv;
45796 }
45797
45798 @@ -2210,6 +2287,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
45799 if (!task)
45800 goto out_no_task;
45801
45802 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45803 + goto out;
45804 +
45805 /*
45806 * Yes, it does not scale. And it should not. Don't add
45807 * new entries into /proc/<tgid>/ without very good reasons.
45808 @@ -2254,6 +2334,9 @@ static int proc_pident_readdir(struct file *filp,
45809 if (!task)
45810 goto out_no_task;
45811
45812 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45813 + goto out;
45814 +
45815 ret = 0;
45816 i = filp->f_pos;
45817 switch (i) {
45818 @@ -2524,7 +2607,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
45819 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
45820 void *cookie)
45821 {
45822 - char *s = nd_get_link(nd);
45823 + const char *s = nd_get_link(nd);
45824 if (!IS_ERR(s))
45825 __putname(s);
45826 }
45827 @@ -2722,7 +2805,7 @@ static const struct pid_entry tgid_base_stuff[] = {
45828 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
45829 #endif
45830 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
45831 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45832 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45833 INF("syscall", S_IRUGO, proc_pid_syscall),
45834 #endif
45835 INF("cmdline", S_IRUGO, proc_pid_cmdline),
45836 @@ -2747,10 +2830,10 @@ static const struct pid_entry tgid_base_stuff[] = {
45837 #ifdef CONFIG_SECURITY
45838 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
45839 #endif
45840 -#ifdef CONFIG_KALLSYMS
45841 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45842 INF("wchan", S_IRUGO, proc_pid_wchan),
45843 #endif
45844 -#ifdef CONFIG_STACKTRACE
45845 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45846 ONE("stack", S_IRUGO, proc_pid_stack),
45847 #endif
45848 #ifdef CONFIG_SCHEDSTATS
45849 @@ -2784,6 +2867,9 @@ static const struct pid_entry tgid_base_stuff[] = {
45850 #ifdef CONFIG_HARDWALL
45851 INF("hardwall", S_IRUGO, proc_pid_hardwall),
45852 #endif
45853 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45854 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
45855 +#endif
45856 };
45857
45858 static int proc_tgid_base_readdir(struct file * filp,
45859 @@ -2909,7 +2995,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
45860 if (!inode)
45861 goto out;
45862
45863 +#ifdef CONFIG_GRKERNSEC_PROC_USER
45864 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
45865 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45866 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45867 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
45868 +#else
45869 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
45870 +#endif
45871 inode->i_op = &proc_tgid_base_inode_operations;
45872 inode->i_fop = &proc_tgid_base_operations;
45873 inode->i_flags|=S_IMMUTABLE;
45874 @@ -2951,7 +3044,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
45875 if (!task)
45876 goto out;
45877
45878 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45879 + goto out_put_task;
45880 +
45881 result = proc_pid_instantiate(dir, dentry, task, NULL);
45882 +out_put_task:
45883 put_task_struct(task);
45884 out:
45885 return result;
45886 @@ -3016,6 +3113,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
45887 {
45888 unsigned int nr;
45889 struct task_struct *reaper;
45890 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45891 + const struct cred *tmpcred = current_cred();
45892 + const struct cred *itercred;
45893 +#endif
45894 + filldir_t __filldir = filldir;
45895 struct tgid_iter iter;
45896 struct pid_namespace *ns;
45897
45898 @@ -3039,8 +3141,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
45899 for (iter = next_tgid(ns, iter);
45900 iter.task;
45901 iter.tgid += 1, iter = next_tgid(ns, iter)) {
45902 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45903 + rcu_read_lock();
45904 + itercred = __task_cred(iter.task);
45905 +#endif
45906 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
45907 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45908 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
45909 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45910 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
45911 +#endif
45912 + )
45913 +#endif
45914 + )
45915 + __filldir = &gr_fake_filldir;
45916 + else
45917 + __filldir = filldir;
45918 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45919 + rcu_read_unlock();
45920 +#endif
45921 filp->f_pos = iter.tgid + TGID_OFFSET;
45922 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
45923 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
45924 put_task_struct(iter.task);
45925 goto out;
45926 }
45927 @@ -3068,7 +3189,7 @@ static const struct pid_entry tid_base_stuff[] = {
45928 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
45929 #endif
45930 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
45931 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45932 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45933 INF("syscall", S_IRUGO, proc_pid_syscall),
45934 #endif
45935 INF("cmdline", S_IRUGO, proc_pid_cmdline),
45936 @@ -3092,10 +3213,10 @@ static const struct pid_entry tid_base_stuff[] = {
45937 #ifdef CONFIG_SECURITY
45938 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
45939 #endif
45940 -#ifdef CONFIG_KALLSYMS
45941 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45942 INF("wchan", S_IRUGO, proc_pid_wchan),
45943 #endif
45944 -#ifdef CONFIG_STACKTRACE
45945 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45946 ONE("stack", S_IRUGO, proc_pid_stack),
45947 #endif
45948 #ifdef CONFIG_SCHEDSTATS
45949 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
45950 index 82676e3..5f8518a 100644
45951 --- a/fs/proc/cmdline.c
45952 +++ b/fs/proc/cmdline.c
45953 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
45954
45955 static int __init proc_cmdline_init(void)
45956 {
45957 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
45958 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
45959 +#else
45960 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
45961 +#endif
45962 return 0;
45963 }
45964 module_init(proc_cmdline_init);
45965 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
45966 index b143471..bb105e5 100644
45967 --- a/fs/proc/devices.c
45968 +++ b/fs/proc/devices.c
45969 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
45970
45971 static int __init proc_devices_init(void)
45972 {
45973 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
45974 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
45975 +#else
45976 proc_create("devices", 0, NULL, &proc_devinfo_operations);
45977 +#endif
45978 return 0;
45979 }
45980 module_init(proc_devices_init);
45981 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
45982 index 7737c54..7172574 100644
45983 --- a/fs/proc/inode.c
45984 +++ b/fs/proc/inode.c
45985 @@ -18,12 +18,18 @@
45986 #include <linux/module.h>
45987 #include <linux/sysctl.h>
45988 #include <linux/slab.h>
45989 +#include <linux/grsecurity.h>
45990
45991 #include <asm/system.h>
45992 #include <asm/uaccess.h>
45993
45994 #include "internal.h"
45995
45996 +#ifdef CONFIG_PROC_SYSCTL
45997 +extern const struct inode_operations proc_sys_inode_operations;
45998 +extern const struct inode_operations proc_sys_dir_operations;
45999 +#endif
46000 +
46001 static void proc_evict_inode(struct inode *inode)
46002 {
46003 struct proc_dir_entry *de;
46004 @@ -49,6 +55,13 @@ static void proc_evict_inode(struct inode *inode)
46005 ns_ops = PROC_I(inode)->ns_ops;
46006 if (ns_ops && ns_ops->put)
46007 ns_ops->put(PROC_I(inode)->ns);
46008 +
46009 +#ifdef CONFIG_PROC_SYSCTL
46010 + if (inode->i_op == &proc_sys_inode_operations ||
46011 + inode->i_op == &proc_sys_dir_operations)
46012 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
46013 +#endif
46014 +
46015 }
46016
46017 static struct kmem_cache * proc_inode_cachep;
46018 @@ -440,7 +453,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
46019 if (de->mode) {
46020 inode->i_mode = de->mode;
46021 inode->i_uid = de->uid;
46022 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
46023 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
46024 +#else
46025 inode->i_gid = de->gid;
46026 +#endif
46027 }
46028 if (de->size)
46029 inode->i_size = de->size;
46030 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
46031 index 7838e5c..ff92cbc 100644
46032 --- a/fs/proc/internal.h
46033 +++ b/fs/proc/internal.h
46034 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
46035 struct pid *pid, struct task_struct *task);
46036 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
46037 struct pid *pid, struct task_struct *task);
46038 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
46039 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
46040 +#endif
46041 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
46042
46043 extern const struct file_operations proc_maps_operations;
46044 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
46045 index d245cb2..f4e8498 100644
46046 --- a/fs/proc/kcore.c
46047 +++ b/fs/proc/kcore.c
46048 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46049 * the addresses in the elf_phdr on our list.
46050 */
46051 start = kc_offset_to_vaddr(*fpos - elf_buflen);
46052 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
46053 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
46054 + if (tsz > buflen)
46055 tsz = buflen;
46056 -
46057 +
46058 while (buflen) {
46059 struct kcore_list *m;
46060
46061 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46062 kfree(elf_buf);
46063 } else {
46064 if (kern_addr_valid(start)) {
46065 - unsigned long n;
46066 + char *elf_buf;
46067 + mm_segment_t oldfs;
46068
46069 - n = copy_to_user(buffer, (char *)start, tsz);
46070 - /*
46071 - * We cannot distingush between fault on source
46072 - * and fault on destination. When this happens
46073 - * we clear too and hope it will trigger the
46074 - * EFAULT again.
46075 - */
46076 - if (n) {
46077 - if (clear_user(buffer + tsz - n,
46078 - n))
46079 + elf_buf = kmalloc(tsz, GFP_KERNEL);
46080 + if (!elf_buf)
46081 + return -ENOMEM;
46082 + oldfs = get_fs();
46083 + set_fs(KERNEL_DS);
46084 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
46085 + set_fs(oldfs);
46086 + if (copy_to_user(buffer, elf_buf, tsz)) {
46087 + kfree(elf_buf);
46088 return -EFAULT;
46089 + }
46090 }
46091 + set_fs(oldfs);
46092 + kfree(elf_buf);
46093 } else {
46094 if (clear_user(buffer, tsz))
46095 return -EFAULT;
46096 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46097
46098 static int open_kcore(struct inode *inode, struct file *filp)
46099 {
46100 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
46101 + return -EPERM;
46102 +#endif
46103 if (!capable(CAP_SYS_RAWIO))
46104 return -EPERM;
46105 if (kcore_need_update)
46106 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
46107 index 80e4645..53e5fcf 100644
46108 --- a/fs/proc/meminfo.c
46109 +++ b/fs/proc/meminfo.c
46110 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
46111 vmi.used >> 10,
46112 vmi.largest_chunk >> 10
46113 #ifdef CONFIG_MEMORY_FAILURE
46114 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
46115 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
46116 #endif
46117 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
46118 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
46119 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
46120 index b1822dd..df622cb 100644
46121 --- a/fs/proc/nommu.c
46122 +++ b/fs/proc/nommu.c
46123 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
46124 if (len < 1)
46125 len = 1;
46126 seq_printf(m, "%*c", len, ' ');
46127 - seq_path(m, &file->f_path, "");
46128 + seq_path(m, &file->f_path, "\n\\");
46129 }
46130
46131 seq_putc(m, '\n');
46132 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
46133 index f738024..876984a 100644
46134 --- a/fs/proc/proc_net.c
46135 +++ b/fs/proc/proc_net.c
46136 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
46137 struct task_struct *task;
46138 struct nsproxy *ns;
46139 struct net *net = NULL;
46140 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46141 + const struct cred *cred = current_cred();
46142 +#endif
46143 +
46144 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46145 + if (cred->fsuid)
46146 + return net;
46147 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46148 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
46149 + return net;
46150 +#endif
46151
46152 rcu_read_lock();
46153 task = pid_task(proc_pid(dir), PIDTYPE_PID);
46154 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
46155 index a6b6217..1e0579d 100644
46156 --- a/fs/proc/proc_sysctl.c
46157 +++ b/fs/proc/proc_sysctl.c
46158 @@ -9,11 +9,13 @@
46159 #include <linux/namei.h>
46160 #include "internal.h"
46161
46162 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
46163 +
46164 static const struct dentry_operations proc_sys_dentry_operations;
46165 static const struct file_operations proc_sys_file_operations;
46166 -static const struct inode_operations proc_sys_inode_operations;
46167 +const struct inode_operations proc_sys_inode_operations;
46168 static const struct file_operations proc_sys_dir_file_operations;
46169 -static const struct inode_operations proc_sys_dir_operations;
46170 +const struct inode_operations proc_sys_dir_operations;
46171
46172 void proc_sys_poll_notify(struct ctl_table_poll *poll)
46173 {
46174 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
46175
46176 err = NULL;
46177 d_set_d_op(dentry, &proc_sys_dentry_operations);
46178 +
46179 + gr_handle_proc_create(dentry, inode);
46180 +
46181 d_add(dentry, inode);
46182
46183 + if (gr_handle_sysctl(p, MAY_EXEC))
46184 + err = ERR_PTR(-ENOENT);
46185 +
46186 out:
46187 sysctl_head_finish(head);
46188 return err;
46189 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
46190 if (!table->proc_handler)
46191 goto out;
46192
46193 +#ifdef CONFIG_GRKERNSEC
46194 + error = -EPERM;
46195 + if (write && !capable(CAP_SYS_ADMIN))
46196 + goto out;
46197 +#endif
46198 +
46199 /* careful: calling conventions are nasty here */
46200 res = count;
46201 error = table->proc_handler(table, write, buf, &res, ppos);
46202 @@ -245,6 +259,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
46203 return -ENOMEM;
46204 } else {
46205 d_set_d_op(child, &proc_sys_dentry_operations);
46206 +
46207 + gr_handle_proc_create(child, inode);
46208 +
46209 d_add(child, inode);
46210 }
46211 } else {
46212 @@ -273,6 +290,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
46213 if (*pos < file->f_pos)
46214 continue;
46215
46216 + if (gr_handle_sysctl(table, 0))
46217 + continue;
46218 +
46219 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
46220 if (res)
46221 return res;
46222 @@ -398,6 +418,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
46223 if (IS_ERR(head))
46224 return PTR_ERR(head);
46225
46226 + if (table && gr_handle_sysctl(table, MAY_EXEC))
46227 + return -ENOENT;
46228 +
46229 generic_fillattr(inode, stat);
46230 if (table)
46231 stat->mode = (stat->mode & S_IFMT) | table->mode;
46232 @@ -420,13 +443,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
46233 .llseek = generic_file_llseek,
46234 };
46235
46236 -static const struct inode_operations proc_sys_inode_operations = {
46237 +const struct inode_operations proc_sys_inode_operations = {
46238 .permission = proc_sys_permission,
46239 .setattr = proc_sys_setattr,
46240 .getattr = proc_sys_getattr,
46241 };
46242
46243 -static const struct inode_operations proc_sys_dir_operations = {
46244 +const struct inode_operations proc_sys_dir_operations = {
46245 .lookup = proc_sys_lookup,
46246 .permission = proc_sys_permission,
46247 .setattr = proc_sys_setattr,
46248 diff --git a/fs/proc/root.c b/fs/proc/root.c
46249 index 03102d9..4ae347e 100644
46250 --- a/fs/proc/root.c
46251 +++ b/fs/proc/root.c
46252 @@ -121,7 +121,15 @@ void __init proc_root_init(void)
46253 #ifdef CONFIG_PROC_DEVICETREE
46254 proc_device_tree_init();
46255 #endif
46256 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46257 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46258 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
46259 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46260 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
46261 +#endif
46262 +#else
46263 proc_mkdir("bus", NULL);
46264 +#endif
46265 proc_sys_init();
46266 }
46267
46268 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
46269 index 7dcd2a2..b2f410e 100644
46270 --- a/fs/proc/task_mmu.c
46271 +++ b/fs/proc/task_mmu.c
46272 @@ -11,6 +11,7 @@
46273 #include <linux/rmap.h>
46274 #include <linux/swap.h>
46275 #include <linux/swapops.h>
46276 +#include <linux/grsecurity.h>
46277
46278 #include <asm/elf.h>
46279 #include <asm/uaccess.h>
46280 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46281 "VmExe:\t%8lu kB\n"
46282 "VmLib:\t%8lu kB\n"
46283 "VmPTE:\t%8lu kB\n"
46284 - "VmSwap:\t%8lu kB\n",
46285 - hiwater_vm << (PAGE_SHIFT-10),
46286 + "VmSwap:\t%8lu kB\n"
46287 +
46288 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46289 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
46290 +#endif
46291 +
46292 + ,hiwater_vm << (PAGE_SHIFT-10),
46293 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
46294 mm->locked_vm << (PAGE_SHIFT-10),
46295 mm->pinned_vm << (PAGE_SHIFT-10),
46296 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46297 data << (PAGE_SHIFT-10),
46298 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
46299 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
46300 - swap << (PAGE_SHIFT-10));
46301 + swap << (PAGE_SHIFT-10)
46302 +
46303 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46304 + , mm->context.user_cs_base, mm->context.user_cs_limit
46305 +#endif
46306 +
46307 + );
46308 }
46309
46310 unsigned long task_vsize(struct mm_struct *mm)
46311 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
46312 return ret;
46313 }
46314
46315 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46316 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46317 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
46318 + _mm->pax_flags & MF_PAX_SEGMEXEC))
46319 +#endif
46320 +
46321 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46322 {
46323 struct mm_struct *mm = vma->vm_mm;
46324 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46325 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
46326 }
46327
46328 - /* We don't show the stack guard page in /proc/maps */
46329 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46330 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
46331 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
46332 +#else
46333 start = vma->vm_start;
46334 - if (stack_guard_page_start(vma, start))
46335 - start += PAGE_SIZE;
46336 end = vma->vm_end;
46337 - if (stack_guard_page_end(vma, end))
46338 - end -= PAGE_SIZE;
46339 +#endif
46340
46341 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
46342 start,
46343 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46344 flags & VM_WRITE ? 'w' : '-',
46345 flags & VM_EXEC ? 'x' : '-',
46346 flags & VM_MAYSHARE ? 's' : 'p',
46347 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46348 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
46349 +#else
46350 pgoff,
46351 +#endif
46352 MAJOR(dev), MINOR(dev), ino, &len);
46353
46354 /*
46355 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46356 */
46357 if (file) {
46358 pad_len_spaces(m, len);
46359 - seq_path(m, &file->f_path, "\n");
46360 + seq_path(m, &file->f_path, "\n\\");
46361 } else {
46362 const char *name = arch_vma_name(vma);
46363 if (!name) {
46364 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46365 if (vma->vm_start <= mm->brk &&
46366 vma->vm_end >= mm->start_brk) {
46367 name = "[heap]";
46368 - } else if (vma->vm_start <= mm->start_stack &&
46369 - vma->vm_end >= mm->start_stack) {
46370 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
46371 + (vma->vm_start <= mm->start_stack &&
46372 + vma->vm_end >= mm->start_stack)) {
46373 name = "[stack]";
46374 }
46375 } else {
46376 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
46377 struct proc_maps_private *priv = m->private;
46378 struct task_struct *task = priv->task;
46379
46380 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46381 + if (current->exec_id != m->exec_id) {
46382 + gr_log_badprocpid("maps");
46383 + return 0;
46384 + }
46385 +#endif
46386 +
46387 show_map_vma(m, vma);
46388
46389 if (m->count < m->size) /* vma is copied successfully */
46390 @@ -434,12 +464,23 @@ static int show_smap(struct seq_file *m, void *v)
46391 .private = &mss,
46392 };
46393
46394 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46395 + if (current->exec_id != m->exec_id) {
46396 + gr_log_badprocpid("smaps");
46397 + return 0;
46398 + }
46399 +#endif
46400 memset(&mss, 0, sizeof mss);
46401 - mss.vma = vma;
46402 - /* mmap_sem is held in m_start */
46403 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
46404 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
46405 -
46406 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46407 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
46408 +#endif
46409 + mss.vma = vma;
46410 + /* mmap_sem is held in m_start */
46411 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
46412 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
46413 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46414 + }
46415 +#endif
46416 show_map_vma(m, vma);
46417
46418 seq_printf(m,
46419 @@ -457,7 +498,11 @@ static int show_smap(struct seq_file *m, void *v)
46420 "KernelPageSize: %8lu kB\n"
46421 "MMUPageSize: %8lu kB\n"
46422 "Locked: %8lu kB\n",
46423 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46424 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
46425 +#else
46426 (vma->vm_end - vma->vm_start) >> 10,
46427 +#endif
46428 mss.resident >> 10,
46429 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
46430 mss.shared_clean >> 10,
46431 @@ -1015,6 +1060,13 @@ static int show_numa_map(struct seq_file *m, void *v)
46432 int n;
46433 char buffer[50];
46434
46435 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46436 + if (current->exec_id != m->exec_id) {
46437 + gr_log_badprocpid("numa_maps");
46438 + return 0;
46439 + }
46440 +#endif
46441 +
46442 if (!mm)
46443 return 0;
46444
46445 @@ -1032,11 +1084,15 @@ static int show_numa_map(struct seq_file *m, void *v)
46446 mpol_to_str(buffer, sizeof(buffer), pol, 0);
46447 mpol_cond_put(pol);
46448
46449 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46450 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
46451 +#else
46452 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
46453 +#endif
46454
46455 if (file) {
46456 seq_printf(m, " file=");
46457 - seq_path(m, &file->f_path, "\n\t= ");
46458 + seq_path(m, &file->f_path, "\n\t\\= ");
46459 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
46460 seq_printf(m, " heap");
46461 } else if (vma->vm_start <= mm->start_stack &&
46462 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
46463 index 980de54..2a4db5f 100644
46464 --- a/fs/proc/task_nommu.c
46465 +++ b/fs/proc/task_nommu.c
46466 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46467 else
46468 bytes += kobjsize(mm);
46469
46470 - if (current->fs && current->fs->users > 1)
46471 + if (current->fs && atomic_read(&current->fs->users) > 1)
46472 sbytes += kobjsize(current->fs);
46473 else
46474 bytes += kobjsize(current->fs);
46475 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
46476
46477 if (file) {
46478 pad_len_spaces(m, len);
46479 - seq_path(m, &file->f_path, "");
46480 + seq_path(m, &file->f_path, "\n\\");
46481 } else if (mm) {
46482 if (vma->vm_start <= mm->start_stack &&
46483 vma->vm_end >= mm->start_stack) {
46484 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
46485 index d67908b..d13f6a6 100644
46486 --- a/fs/quota/netlink.c
46487 +++ b/fs/quota/netlink.c
46488 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
46489 void quota_send_warning(short type, unsigned int id, dev_t dev,
46490 const char warntype)
46491 {
46492 - static atomic_t seq;
46493 + static atomic_unchecked_t seq;
46494 struct sk_buff *skb;
46495 void *msg_head;
46496 int ret;
46497 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
46498 "VFS: Not enough memory to send quota warning.\n");
46499 return;
46500 }
46501 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
46502 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
46503 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
46504 if (!msg_head) {
46505 printk(KERN_ERR
46506 diff --git a/fs/readdir.c b/fs/readdir.c
46507 index 356f715..c918d38 100644
46508 --- a/fs/readdir.c
46509 +++ b/fs/readdir.c
46510 @@ -17,6 +17,7 @@
46511 #include <linux/security.h>
46512 #include <linux/syscalls.h>
46513 #include <linux/unistd.h>
46514 +#include <linux/namei.h>
46515
46516 #include <asm/uaccess.h>
46517
46518 @@ -67,6 +68,7 @@ struct old_linux_dirent {
46519
46520 struct readdir_callback {
46521 struct old_linux_dirent __user * dirent;
46522 + struct file * file;
46523 int result;
46524 };
46525
46526 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
46527 buf->result = -EOVERFLOW;
46528 return -EOVERFLOW;
46529 }
46530 +
46531 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46532 + return 0;
46533 +
46534 buf->result++;
46535 dirent = buf->dirent;
46536 if (!access_ok(VERIFY_WRITE, dirent,
46537 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
46538
46539 buf.result = 0;
46540 buf.dirent = dirent;
46541 + buf.file = file;
46542
46543 error = vfs_readdir(file, fillonedir, &buf);
46544 if (buf.result)
46545 @@ -142,6 +149,7 @@ struct linux_dirent {
46546 struct getdents_callback {
46547 struct linux_dirent __user * current_dir;
46548 struct linux_dirent __user * previous;
46549 + struct file * file;
46550 int count;
46551 int error;
46552 };
46553 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
46554 buf->error = -EOVERFLOW;
46555 return -EOVERFLOW;
46556 }
46557 +
46558 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46559 + return 0;
46560 +
46561 dirent = buf->previous;
46562 if (dirent) {
46563 if (__put_user(offset, &dirent->d_off))
46564 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
46565 buf.previous = NULL;
46566 buf.count = count;
46567 buf.error = 0;
46568 + buf.file = file;
46569
46570 error = vfs_readdir(file, filldir, &buf);
46571 if (error >= 0)
46572 @@ -229,6 +242,7 @@ out:
46573 struct getdents_callback64 {
46574 struct linux_dirent64 __user * current_dir;
46575 struct linux_dirent64 __user * previous;
46576 + struct file *file;
46577 int count;
46578 int error;
46579 };
46580 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
46581 buf->error = -EINVAL; /* only used if we fail.. */
46582 if (reclen > buf->count)
46583 return -EINVAL;
46584 +
46585 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46586 + return 0;
46587 +
46588 dirent = buf->previous;
46589 if (dirent) {
46590 if (__put_user(offset, &dirent->d_off))
46591 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
46592
46593 buf.current_dir = dirent;
46594 buf.previous = NULL;
46595 + buf.file = file;
46596 buf.count = count;
46597 buf.error = 0;
46598
46599 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
46600 error = buf.error;
46601 lastdirent = buf.previous;
46602 if (lastdirent) {
46603 - typeof(lastdirent->d_off) d_off = file->f_pos;
46604 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
46605 if (__put_user(d_off, &lastdirent->d_off))
46606 error = -EFAULT;
46607 else
46608 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
46609 index 60c0804..d814f98 100644
46610 --- a/fs/reiserfs/do_balan.c
46611 +++ b/fs/reiserfs/do_balan.c
46612 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
46613 return;
46614 }
46615
46616 - atomic_inc(&(fs_generation(tb->tb_sb)));
46617 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
46618 do_balance_starts(tb);
46619
46620 /* balance leaf returns 0 except if combining L R and S into
46621 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
46622 index 7a99811..a7c96c4 100644
46623 --- a/fs/reiserfs/procfs.c
46624 +++ b/fs/reiserfs/procfs.c
46625 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
46626 "SMALL_TAILS " : "NO_TAILS ",
46627 replay_only(sb) ? "REPLAY_ONLY " : "",
46628 convert_reiserfs(sb) ? "CONV " : "",
46629 - atomic_read(&r->s_generation_counter),
46630 + atomic_read_unchecked(&r->s_generation_counter),
46631 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
46632 SF(s_do_balance), SF(s_unneeded_left_neighbor),
46633 SF(s_good_search_by_key_reada), SF(s_bmaps),
46634 diff --git a/fs/select.c b/fs/select.c
46635 index d33418f..2a5345e 100644
46636 --- a/fs/select.c
46637 +++ b/fs/select.c
46638 @@ -20,6 +20,7 @@
46639 #include <linux/module.h>
46640 #include <linux/slab.h>
46641 #include <linux/poll.h>
46642 +#include <linux/security.h>
46643 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
46644 #include <linux/file.h>
46645 #include <linux/fdtable.h>
46646 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
46647 struct poll_list *walk = head;
46648 unsigned long todo = nfds;
46649
46650 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
46651 if (nfds > rlimit(RLIMIT_NOFILE))
46652 return -EINVAL;
46653
46654 diff --git a/fs/seq_file.c b/fs/seq_file.c
46655 index dba43c3..1dfaf14 100644
46656 --- a/fs/seq_file.c
46657 +++ b/fs/seq_file.c
46658 @@ -40,6 +40,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
46659 memset(p, 0, sizeof(*p));
46660 mutex_init(&p->lock);
46661 p->op = op;
46662 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46663 + p->exec_id = current->exec_id;
46664 +#endif
46665
46666 /*
46667 * Wrappers around seq_open(e.g. swaps_open) need to be
46668 @@ -76,7 +79,8 @@ static int traverse(struct seq_file *m, loff_t offset)
46669 return 0;
46670 }
46671 if (!m->buf) {
46672 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46673 + m->size = PAGE_SIZE;
46674 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46675 if (!m->buf)
46676 return -ENOMEM;
46677 }
46678 @@ -116,7 +120,8 @@ static int traverse(struct seq_file *m, loff_t offset)
46679 Eoverflow:
46680 m->op->stop(m, p);
46681 kfree(m->buf);
46682 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46683 + m->size <<= 1;
46684 + m->buf = kmalloc(m->size, GFP_KERNEL);
46685 return !m->buf ? -ENOMEM : -EAGAIN;
46686 }
46687
46688 @@ -169,7 +174,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
46689 m->version = file->f_version;
46690 /* grab buffer if we didn't have one */
46691 if (!m->buf) {
46692 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46693 + m->size = PAGE_SIZE;
46694 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46695 if (!m->buf)
46696 goto Enomem;
46697 }
46698 @@ -210,7 +216,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
46699 goto Fill;
46700 m->op->stop(m, p);
46701 kfree(m->buf);
46702 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46703 + m->size <<= 1;
46704 + m->buf = kmalloc(m->size, GFP_KERNEL);
46705 if (!m->buf)
46706 goto Enomem;
46707 m->count = 0;
46708 @@ -549,7 +556,7 @@ static void single_stop(struct seq_file *p, void *v)
46709 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
46710 void *data)
46711 {
46712 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
46713 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
46714 int res = -ENOMEM;
46715
46716 if (op) {
46717 diff --git a/fs/splice.c b/fs/splice.c
46718 index fa2defa..8601650 100644
46719 --- a/fs/splice.c
46720 +++ b/fs/splice.c
46721 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
46722 pipe_lock(pipe);
46723
46724 for (;;) {
46725 - if (!pipe->readers) {
46726 + if (!atomic_read(&pipe->readers)) {
46727 send_sig(SIGPIPE, current, 0);
46728 if (!ret)
46729 ret = -EPIPE;
46730 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
46731 do_wakeup = 0;
46732 }
46733
46734 - pipe->waiting_writers++;
46735 + atomic_inc(&pipe->waiting_writers);
46736 pipe_wait(pipe);
46737 - pipe->waiting_writers--;
46738 + atomic_dec(&pipe->waiting_writers);
46739 }
46740
46741 pipe_unlock(pipe);
46742 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
46743 old_fs = get_fs();
46744 set_fs(get_ds());
46745 /* The cast to a user pointer is valid due to the set_fs() */
46746 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
46747 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
46748 set_fs(old_fs);
46749
46750 return res;
46751 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
46752 old_fs = get_fs();
46753 set_fs(get_ds());
46754 /* The cast to a user pointer is valid due to the set_fs() */
46755 - res = vfs_write(file, (const char __user *)buf, count, &pos);
46756 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
46757 set_fs(old_fs);
46758
46759 return res;
46760 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
46761 goto err;
46762
46763 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
46764 - vec[i].iov_base = (void __user *) page_address(page);
46765 + vec[i].iov_base = (void __force_user *) page_address(page);
46766 vec[i].iov_len = this_len;
46767 spd.pages[i] = page;
46768 spd.nr_pages++;
46769 @@ -846,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
46770 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
46771 {
46772 while (!pipe->nrbufs) {
46773 - if (!pipe->writers)
46774 + if (!atomic_read(&pipe->writers))
46775 return 0;
46776
46777 - if (!pipe->waiting_writers && sd->num_spliced)
46778 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
46779 return 0;
46780
46781 if (sd->flags & SPLICE_F_NONBLOCK)
46782 @@ -1182,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
46783 * out of the pipe right after the splice_to_pipe(). So set
46784 * PIPE_READERS appropriately.
46785 */
46786 - pipe->readers = 1;
46787 + atomic_set(&pipe->readers, 1);
46788
46789 current->splice_pipe = pipe;
46790 }
46791 @@ -1734,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
46792 ret = -ERESTARTSYS;
46793 break;
46794 }
46795 - if (!pipe->writers)
46796 + if (!atomic_read(&pipe->writers))
46797 break;
46798 - if (!pipe->waiting_writers) {
46799 + if (!atomic_read(&pipe->waiting_writers)) {
46800 if (flags & SPLICE_F_NONBLOCK) {
46801 ret = -EAGAIN;
46802 break;
46803 @@ -1768,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
46804 pipe_lock(pipe);
46805
46806 while (pipe->nrbufs >= pipe->buffers) {
46807 - if (!pipe->readers) {
46808 + if (!atomic_read(&pipe->readers)) {
46809 send_sig(SIGPIPE, current, 0);
46810 ret = -EPIPE;
46811 break;
46812 @@ -1781,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
46813 ret = -ERESTARTSYS;
46814 break;
46815 }
46816 - pipe->waiting_writers++;
46817 + atomic_inc(&pipe->waiting_writers);
46818 pipe_wait(pipe);
46819 - pipe->waiting_writers--;
46820 + atomic_dec(&pipe->waiting_writers);
46821 }
46822
46823 pipe_unlock(pipe);
46824 @@ -1819,14 +1819,14 @@ retry:
46825 pipe_double_lock(ipipe, opipe);
46826
46827 do {
46828 - if (!opipe->readers) {
46829 + if (!atomic_read(&opipe->readers)) {
46830 send_sig(SIGPIPE, current, 0);
46831 if (!ret)
46832 ret = -EPIPE;
46833 break;
46834 }
46835
46836 - if (!ipipe->nrbufs && !ipipe->writers)
46837 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
46838 break;
46839
46840 /*
46841 @@ -1923,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
46842 pipe_double_lock(ipipe, opipe);
46843
46844 do {
46845 - if (!opipe->readers) {
46846 + if (!atomic_read(&opipe->readers)) {
46847 send_sig(SIGPIPE, current, 0);
46848 if (!ret)
46849 ret = -EPIPE;
46850 @@ -1968,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
46851 * return EAGAIN if we have the potential of some data in the
46852 * future, otherwise just return 0
46853 */
46854 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
46855 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
46856 ret = -EAGAIN;
46857
46858 pipe_unlock(ipipe);
46859 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
46860 index 7fdf6a7..e6cd8ad 100644
46861 --- a/fs/sysfs/dir.c
46862 +++ b/fs/sysfs/dir.c
46863 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
46864 struct sysfs_dirent *sd;
46865 int rc;
46866
46867 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46868 + const char *parent_name = parent_sd->s_name;
46869 +
46870 + mode = S_IFDIR | S_IRWXU;
46871 +
46872 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
46873 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
46874 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
46875 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
46876 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
46877 +#endif
46878 +
46879 /* allocate */
46880 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
46881 if (!sd)
46882 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
46883 index 779789a..f58193c 100644
46884 --- a/fs/sysfs/file.c
46885 +++ b/fs/sysfs/file.c
46886 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
46887
46888 struct sysfs_open_dirent {
46889 atomic_t refcnt;
46890 - atomic_t event;
46891 + atomic_unchecked_t event;
46892 wait_queue_head_t poll;
46893 struct list_head buffers; /* goes through sysfs_buffer.list */
46894 };
46895 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
46896 if (!sysfs_get_active(attr_sd))
46897 return -ENODEV;
46898
46899 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
46900 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
46901 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
46902
46903 sysfs_put_active(attr_sd);
46904 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
46905 return -ENOMEM;
46906
46907 atomic_set(&new_od->refcnt, 0);
46908 - atomic_set(&new_od->event, 1);
46909 + atomic_set_unchecked(&new_od->event, 1);
46910 init_waitqueue_head(&new_od->poll);
46911 INIT_LIST_HEAD(&new_od->buffers);
46912 goto retry;
46913 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
46914
46915 sysfs_put_active(attr_sd);
46916
46917 - if (buffer->event != atomic_read(&od->event))
46918 + if (buffer->event != atomic_read_unchecked(&od->event))
46919 goto trigger;
46920
46921 return DEFAULT_POLLMASK;
46922 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
46923
46924 od = sd->s_attr.open;
46925 if (od) {
46926 - atomic_inc(&od->event);
46927 + atomic_inc_unchecked(&od->event);
46928 wake_up_interruptible(&od->poll);
46929 }
46930
46931 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
46932 index a7ac78f..02158e1 100644
46933 --- a/fs/sysfs/symlink.c
46934 +++ b/fs/sysfs/symlink.c
46935 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
46936
46937 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
46938 {
46939 - char *page = nd_get_link(nd);
46940 + const char *page = nd_get_link(nd);
46941 if (!IS_ERR(page))
46942 free_page((unsigned long)page);
46943 }
46944 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
46945 index c175b4d..8f36a16 100644
46946 --- a/fs/udf/misc.c
46947 +++ b/fs/udf/misc.c
46948 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
46949
46950 u8 udf_tag_checksum(const struct tag *t)
46951 {
46952 - u8 *data = (u8 *)t;
46953 + const u8 *data = (const u8 *)t;
46954 u8 checksum = 0;
46955 int i;
46956 for (i = 0; i < sizeof(struct tag); ++i)
46957 diff --git a/fs/utimes.c b/fs/utimes.c
46958 index ba653f3..06ea4b1 100644
46959 --- a/fs/utimes.c
46960 +++ b/fs/utimes.c
46961 @@ -1,6 +1,7 @@
46962 #include <linux/compiler.h>
46963 #include <linux/file.h>
46964 #include <linux/fs.h>
46965 +#include <linux/security.h>
46966 #include <linux/linkage.h>
46967 #include <linux/mount.h>
46968 #include <linux/namei.h>
46969 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
46970 goto mnt_drop_write_and_out;
46971 }
46972 }
46973 +
46974 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
46975 + error = -EACCES;
46976 + goto mnt_drop_write_and_out;
46977 + }
46978 +
46979 mutex_lock(&inode->i_mutex);
46980 error = notify_change(path->dentry, &newattrs);
46981 mutex_unlock(&inode->i_mutex);
46982 diff --git a/fs/xattr.c b/fs/xattr.c
46983 index 67583de..c5aad14 100644
46984 --- a/fs/xattr.c
46985 +++ b/fs/xattr.c
46986 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
46987 * Extended attribute SET operations
46988 */
46989 static long
46990 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
46991 +setxattr(struct path *path, const char __user *name, const void __user *value,
46992 size_t size, int flags)
46993 {
46994 int error;
46995 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
46996 return PTR_ERR(kvalue);
46997 }
46998
46999 - error = vfs_setxattr(d, kname, kvalue, size, flags);
47000 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
47001 + error = -EACCES;
47002 + goto out;
47003 + }
47004 +
47005 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
47006 +out:
47007 kfree(kvalue);
47008 return error;
47009 }
47010 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
47011 return error;
47012 error = mnt_want_write(path.mnt);
47013 if (!error) {
47014 - error = setxattr(path.dentry, name, value, size, flags);
47015 + error = setxattr(&path, name, value, size, flags);
47016 mnt_drop_write(path.mnt);
47017 }
47018 path_put(&path);
47019 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
47020 return error;
47021 error = mnt_want_write(path.mnt);
47022 if (!error) {
47023 - error = setxattr(path.dentry, name, value, size, flags);
47024 + error = setxattr(&path, name, value, size, flags);
47025 mnt_drop_write(path.mnt);
47026 }
47027 path_put(&path);
47028 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
47029 const void __user *,value, size_t, size, int, flags)
47030 {
47031 struct file *f;
47032 - struct dentry *dentry;
47033 int error = -EBADF;
47034
47035 f = fget(fd);
47036 if (!f)
47037 return error;
47038 - dentry = f->f_path.dentry;
47039 - audit_inode(NULL, dentry);
47040 + audit_inode(NULL, f->f_path.dentry);
47041 error = mnt_want_write_file(f);
47042 if (!error) {
47043 - error = setxattr(dentry, name, value, size, flags);
47044 + error = setxattr(&f->f_path, name, value, size, flags);
47045 mnt_drop_write(f->f_path.mnt);
47046 }
47047 fput(f);
47048 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
47049 index 8d5a506..7f62712 100644
47050 --- a/fs/xattr_acl.c
47051 +++ b/fs/xattr_acl.c
47052 @@ -17,8 +17,8 @@
47053 struct posix_acl *
47054 posix_acl_from_xattr(const void *value, size_t size)
47055 {
47056 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
47057 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
47058 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
47059 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
47060 int count;
47061 struct posix_acl *acl;
47062 struct posix_acl_entry *acl_e;
47063 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
47064 index d0ab788..827999b 100644
47065 --- a/fs/xfs/xfs_bmap.c
47066 +++ b/fs/xfs/xfs_bmap.c
47067 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
47068 int nmap,
47069 int ret_nmap);
47070 #else
47071 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
47072 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
47073 #endif /* DEBUG */
47074
47075 STATIC int
47076 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
47077 index 79d05e8..e3e5861 100644
47078 --- a/fs/xfs/xfs_dir2_sf.c
47079 +++ b/fs/xfs/xfs_dir2_sf.c
47080 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
47081 }
47082
47083 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
47084 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
47085 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
47086 + char name[sfep->namelen];
47087 + memcpy(name, sfep->name, sfep->namelen);
47088 + if (filldir(dirent, name, sfep->namelen,
47089 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
47090 + *offset = off & 0x7fffffff;
47091 + return 0;
47092 + }
47093 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
47094 off & 0x7fffffff, ino, DT_UNKNOWN)) {
47095 *offset = off & 0x7fffffff;
47096 return 0;
47097 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
47098 index d99a905..9f88202 100644
47099 --- a/fs/xfs/xfs_ioctl.c
47100 +++ b/fs/xfs/xfs_ioctl.c
47101 @@ -128,7 +128,7 @@ xfs_find_handle(
47102 }
47103
47104 error = -EFAULT;
47105 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
47106 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
47107 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
47108 goto out_put;
47109
47110 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
47111 index 23ce927..e274cc1 100644
47112 --- a/fs/xfs/xfs_iops.c
47113 +++ b/fs/xfs/xfs_iops.c
47114 @@ -447,7 +447,7 @@ xfs_vn_put_link(
47115 struct nameidata *nd,
47116 void *p)
47117 {
47118 - char *s = nd_get_link(nd);
47119 + const char *s = nd_get_link(nd);
47120
47121 if (!IS_ERR(s))
47122 kfree(s);
47123 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
47124 new file mode 100644
47125 index 0000000..8faa28b
47126 --- /dev/null
47127 +++ b/grsecurity/Kconfig
47128 @@ -0,0 +1,1073 @@
47129 +#
47130 +# grecurity configuration
47131 +#
47132 +
47133 +menu "Grsecurity"
47134 +
47135 +config GRKERNSEC
47136 + bool "Grsecurity"
47137 + select CRYPTO
47138 + select CRYPTO_SHA256
47139 + help
47140 + If you say Y here, you will be able to configure many features
47141 + that will enhance the security of your system. It is highly
47142 + recommended that you say Y here and read through the help
47143 + for each option so that you fully understand the features and
47144 + can evaluate their usefulness for your machine.
47145 +
47146 +choice
47147 + prompt "Security Level"
47148 + depends on GRKERNSEC
47149 + default GRKERNSEC_CUSTOM
47150 +
47151 +config GRKERNSEC_LOW
47152 + bool "Low"
47153 + select GRKERNSEC_LINK
47154 + select GRKERNSEC_FIFO
47155 + select GRKERNSEC_RANDNET
47156 + select GRKERNSEC_DMESG
47157 + select GRKERNSEC_CHROOT
47158 + select GRKERNSEC_CHROOT_CHDIR
47159 +
47160 + help
47161 + If you choose this option, several of the grsecurity options will
47162 + be enabled that will give you greater protection against a number
47163 + of attacks, while assuring that none of your software will have any
47164 + conflicts with the additional security measures. If you run a lot
47165 + of unusual software, or you are having problems with the higher
47166 + security levels, you should say Y here. With this option, the
47167 + following features are enabled:
47168 +
47169 + - Linking restrictions
47170 + - FIFO restrictions
47171 + - Restricted dmesg
47172 + - Enforced chdir("/") on chroot
47173 + - Runtime module disabling
47174 +
47175 +config GRKERNSEC_MEDIUM
47176 + bool "Medium"
47177 + select PAX
47178 + select PAX_EI_PAX
47179 + select PAX_PT_PAX_FLAGS
47180 + select PAX_HAVE_ACL_FLAGS
47181 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
47182 + select GRKERNSEC_CHROOT
47183 + select GRKERNSEC_CHROOT_SYSCTL
47184 + select GRKERNSEC_LINK
47185 + select GRKERNSEC_FIFO
47186 + select GRKERNSEC_DMESG
47187 + select GRKERNSEC_RANDNET
47188 + select GRKERNSEC_FORKFAIL
47189 + select GRKERNSEC_TIME
47190 + select GRKERNSEC_SIGNAL
47191 + select GRKERNSEC_CHROOT
47192 + select GRKERNSEC_CHROOT_UNIX
47193 + select GRKERNSEC_CHROOT_MOUNT
47194 + select GRKERNSEC_CHROOT_PIVOT
47195 + select GRKERNSEC_CHROOT_DOUBLE
47196 + select GRKERNSEC_CHROOT_CHDIR
47197 + select GRKERNSEC_CHROOT_MKNOD
47198 + select GRKERNSEC_PROC
47199 + select GRKERNSEC_PROC_USERGROUP
47200 + select PAX_RANDUSTACK
47201 + select PAX_ASLR
47202 + select PAX_RANDMMAP
47203 + select PAX_REFCOUNT if (X86 || SPARC64)
47204 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
47205 +
47206 + help
47207 + If you say Y here, several features in addition to those included
47208 + in the low additional security level will be enabled. These
47209 + features provide even more security to your system, though in rare
47210 + cases they may be incompatible with very old or poorly written
47211 + software. If you enable this option, make sure that your auth
47212 + service (identd) is running as gid 1001. With this option,
47213 + the following features (in addition to those provided in the
47214 + low additional security level) will be enabled:
47215 +
47216 + - Failed fork logging
47217 + - Time change logging
47218 + - Signal logging
47219 + - Deny mounts in chroot
47220 + - Deny double chrooting
47221 + - Deny sysctl writes in chroot
47222 + - Deny mknod in chroot
47223 + - Deny access to abstract AF_UNIX sockets out of chroot
47224 + - Deny pivot_root in chroot
47225 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
47226 + - /proc restrictions with special GID set to 10 (usually wheel)
47227 + - Address Space Layout Randomization (ASLR)
47228 + - Prevent exploitation of most refcount overflows
47229 + - Bounds checking of copying between the kernel and userland
47230 +
47231 +config GRKERNSEC_HIGH
47232 + bool "High"
47233 + select GRKERNSEC_LINK
47234 + select GRKERNSEC_FIFO
47235 + select GRKERNSEC_DMESG
47236 + select GRKERNSEC_FORKFAIL
47237 + select GRKERNSEC_TIME
47238 + select GRKERNSEC_SIGNAL
47239 + select GRKERNSEC_CHROOT
47240 + select GRKERNSEC_CHROOT_SHMAT
47241 + select GRKERNSEC_CHROOT_UNIX
47242 + select GRKERNSEC_CHROOT_MOUNT
47243 + select GRKERNSEC_CHROOT_FCHDIR
47244 + select GRKERNSEC_CHROOT_PIVOT
47245 + select GRKERNSEC_CHROOT_DOUBLE
47246 + select GRKERNSEC_CHROOT_CHDIR
47247 + select GRKERNSEC_CHROOT_MKNOD
47248 + select GRKERNSEC_CHROOT_CAPS
47249 + select GRKERNSEC_CHROOT_SYSCTL
47250 + select GRKERNSEC_CHROOT_FINDTASK
47251 + select GRKERNSEC_SYSFS_RESTRICT
47252 + select GRKERNSEC_PROC
47253 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
47254 + select GRKERNSEC_HIDESYM
47255 + select GRKERNSEC_BRUTE
47256 + select GRKERNSEC_PROC_USERGROUP
47257 + select GRKERNSEC_KMEM
47258 + select GRKERNSEC_RESLOG
47259 + select GRKERNSEC_RANDNET
47260 + select GRKERNSEC_PROC_ADD
47261 + select GRKERNSEC_CHROOT_CHMOD
47262 + select GRKERNSEC_CHROOT_NICE
47263 + select GRKERNSEC_SETXID
47264 + select GRKERNSEC_AUDIT_MOUNT
47265 + select GRKERNSEC_MODHARDEN if (MODULES)
47266 + select GRKERNSEC_HARDEN_PTRACE
47267 + select GRKERNSEC_PTRACE_READEXEC
47268 + select GRKERNSEC_VM86 if (X86_32)
47269 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
47270 + select PAX
47271 + select PAX_RANDUSTACK
47272 + select PAX_ASLR
47273 + select PAX_RANDMMAP
47274 + select PAX_NOEXEC
47275 + select PAX_MPROTECT
47276 + select PAX_EI_PAX
47277 + select PAX_PT_PAX_FLAGS
47278 + select PAX_HAVE_ACL_FLAGS
47279 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
47280 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
47281 + select PAX_RANDKSTACK if (X86_TSC && X86)
47282 + select PAX_SEGMEXEC if (X86_32)
47283 + select PAX_PAGEEXEC
47284 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
47285 + select PAX_EMUTRAMP if (PARISC)
47286 + select PAX_EMUSIGRT if (PARISC)
47287 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
47288 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
47289 + select PAX_REFCOUNT if (X86 || SPARC64)
47290 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
47291 + help
47292 + If you say Y here, many of the features of grsecurity will be
47293 + enabled, which will protect you against many kinds of attacks
47294 + against your system. The heightened security comes at a cost
47295 + of an increased chance of incompatibilities with rare software
47296 + on your machine. Since this security level enables PaX, you should
47297 + view <http://pax.grsecurity.net> and read about the PaX
47298 + project. While you are there, download chpax and run it on
47299 + binaries that cause problems with PaX. Also remember that
47300 + since the /proc restrictions are enabled, you must run your
47301 + identd as gid 1001. This security level enables the following
47302 + features in addition to those listed in the low and medium
47303 + security levels:
47304 +
47305 + - Additional /proc restrictions
47306 + - Chmod restrictions in chroot
47307 + - No signals, ptrace, or viewing of processes outside of chroot
47308 + - Capability restrictions in chroot
47309 + - Deny fchdir out of chroot
47310 + - Priority restrictions in chroot
47311 + - Segmentation-based implementation of PaX
47312 + - Mprotect restrictions
47313 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
47314 + - Kernel stack randomization
47315 + - Mount/unmount/remount logging
47316 + - Kernel symbol hiding
47317 + - Hardening of module auto-loading
47318 + - Ptrace restrictions
47319 + - Restricted vm86 mode
47320 + - Restricted sysfs/debugfs
47321 + - Active kernel exploit response
47322 +
47323 +config GRKERNSEC_CUSTOM
47324 + bool "Custom"
47325 + help
47326 + If you say Y here, you will be able to configure every grsecurity
47327 + option, which allows you to enable many more features that aren't
47328 + covered in the basic security levels. These additional features
47329 + include TPE, socket restrictions, and the sysctl system for
47330 + grsecurity. It is advised that you read through the help for
47331 + each option to determine its usefulness in your situation.
47332 +
47333 +endchoice
47334 +
47335 +menu "Address Space Protection"
47336 +depends on GRKERNSEC
47337 +
47338 +config GRKERNSEC_KMEM
47339 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
47340 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
47341 + help
47342 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
47343 + be written to or read from to modify or leak the contents of the running
47344 + kernel. /dev/port will also not be allowed to be opened. If you have module
47345 + support disabled, enabling this will close up four ways that are
47346 + currently used to insert malicious code into the running kernel.
47347 + Even with all these features enabled, we still highly recommend that
47348 + you use the RBAC system, as it is still possible for an attacker to
47349 + modify the running kernel through privileged I/O granted by ioperm/iopl.
47350 + If you are not using XFree86, you may be able to stop this additional
47351 + case by enabling the 'Disable privileged I/O' option. Though nothing
47352 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
47353 + but only to video memory, which is the only writing we allow in this
47354 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
47355 + not be allowed to mprotect it with PROT_WRITE later.
47356 + It is highly recommended that you say Y here if you meet all the
47357 + conditions above.
47358 +
47359 +config GRKERNSEC_VM86
47360 + bool "Restrict VM86 mode"
47361 + depends on X86_32
47362 +
47363 + help
47364 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
47365 + make use of a special execution mode on 32bit x86 processors called
47366 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
47367 + video cards and will still work with this option enabled. The purpose
47368 + of the option is to prevent exploitation of emulation errors in
47369 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
47370 + Nearly all users should be able to enable this option.
47371 +
47372 +config GRKERNSEC_IO
47373 + bool "Disable privileged I/O"
47374 + depends on X86
47375 + select RTC_CLASS
47376 + select RTC_INTF_DEV
47377 + select RTC_DRV_CMOS
47378 +
47379 + help
47380 + If you say Y here, all ioperm and iopl calls will return an error.
47381 + Ioperm and iopl can be used to modify the running kernel.
47382 + Unfortunately, some programs need this access to operate properly,
47383 + the most notable of which are XFree86 and hwclock. hwclock can be
47384 + remedied by having RTC support in the kernel, so real-time
47385 + clock support is enabled if this option is enabled, to ensure
47386 + that hwclock operates correctly. XFree86 still will not
47387 + operate correctly with this option enabled, so DO NOT CHOOSE Y
47388 + IF YOU USE XFree86. If you use XFree86 and you still want to
47389 + protect your kernel against modification, use the RBAC system.
47390 +
47391 +config GRKERNSEC_PROC_MEMMAP
47392 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
47393 + default y if (PAX_NOEXEC || PAX_ASLR)
47394 + depends on PAX_NOEXEC || PAX_ASLR
47395 + help
47396 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
47397 + give no information about the addresses of its mappings if
47398 + PaX features that rely on random addresses are enabled on the task.
47399 + In addition to sanitizing this information and disabling other
47400 + dangerous sources of information, this option causes reads of sensitive
47401 + /proc/<pid> entries where the file descriptor was opened in a different
47402 + task than the one performing the read. Such attempts are logged.
47403 + If you use PaX it is greatly recommended that you say Y here as it
47404 + closes up a hole that makes the full ASLR useless for suid
47405 + binaries.
47406 +
47407 +config GRKERNSEC_BRUTE
47408 + bool "Deter exploit bruteforcing"
47409 + help
47410 + If you say Y here, attempts to bruteforce exploits against forking
47411 + daemons such as apache or sshd, as well as against suid/sgid binaries
47412 + will be deterred. When a child of a forking daemon is killed by PaX
47413 + or crashes due to an illegal instruction or other suspicious signal,
47414 + the parent process will be delayed 30 seconds upon every subsequent
47415 + fork until the administrator is able to assess the situation and
47416 + restart the daemon.
47417 + In the suid/sgid case, the attempt is logged, the user has all their
47418 + processes terminated, and they are prevented from executing any further
47419 + processes for 15 minutes.
47420 + It is recommended that you also enable signal logging in the auditing
47421 + section so that logs are generated when a process triggers a suspicious
47422 + signal.
47423 + If the sysctl option is enabled, a sysctl option with name
47424 + "deter_bruteforce" is created.
47425 +
47426 +
47427 +config GRKERNSEC_MODHARDEN
47428 + bool "Harden module auto-loading"
47429 + depends on MODULES
47430 + help
47431 + If you say Y here, module auto-loading in response to use of some
47432 + feature implemented by an unloaded module will be restricted to
47433 + root users. Enabling this option helps defend against attacks
47434 + by unprivileged users who abuse the auto-loading behavior to
47435 + cause a vulnerable module to load that is then exploited.
47436 +
47437 + If this option prevents a legitimate use of auto-loading for a
47438 + non-root user, the administrator can execute modprobe manually
47439 + with the exact name of the module mentioned in the alert log.
47440 + Alternatively, the administrator can add the module to the list
47441 + of modules loaded at boot by modifying init scripts.
47442 +
47443 + Modification of init scripts will most likely be needed on
47444 + Ubuntu servers with encrypted home directory support enabled,
47445 + as the first non-root user logging in will cause the ecb(aes),
47446 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
47447 +
47448 +config GRKERNSEC_HIDESYM
47449 + bool "Hide kernel symbols"
47450 + help
47451 + If you say Y here, getting information on loaded modules, and
47452 + displaying all kernel symbols through a syscall will be restricted
47453 + to users with CAP_SYS_MODULE. For software compatibility reasons,
47454 + /proc/kallsyms will be restricted to the root user. The RBAC
47455 + system can hide that entry even from root.
47456 +
47457 + This option also prevents leaking of kernel addresses through
47458 + several /proc entries.
47459 +
47460 + Note that this option is only effective provided the following
47461 + conditions are met:
47462 + 1) The kernel using grsecurity is not precompiled by some distribution
47463 + 2) You have also enabled GRKERNSEC_DMESG
47464 + 3) You are using the RBAC system and hiding other files such as your
47465 + kernel image and System.map. Alternatively, enabling this option
47466 + causes the permissions on /boot, /lib/modules, and the kernel
47467 + source directory to change at compile time to prevent
47468 + reading by non-root users.
47469 + If the above conditions are met, this option will aid in providing a
47470 + useful protection against local kernel exploitation of overflows
47471 + and arbitrary read/write vulnerabilities.
47472 +
47473 +config GRKERNSEC_KERN_LOCKOUT
47474 + bool "Active kernel exploit response"
47475 + depends on X86 || ARM || PPC || SPARC
47476 + help
47477 + If you say Y here, when a PaX alert is triggered due to suspicious
47478 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
47479 + or an OOPs occurs due to bad memory accesses, instead of just
47480 + terminating the offending process (and potentially allowing
47481 + a subsequent exploit from the same user), we will take one of two
47482 + actions:
47483 + If the user was root, we will panic the system
47484 + If the user was non-root, we will log the attempt, terminate
47485 + all processes owned by the user, then prevent them from creating
47486 + any new processes until the system is restarted
47487 + This deters repeated kernel exploitation/bruteforcing attempts
47488 + and is useful for later forensics.
47489 +
47490 +endmenu
47491 +menu "Role Based Access Control Options"
47492 +depends on GRKERNSEC
47493 +
47494 +config GRKERNSEC_RBAC_DEBUG
47495 + bool
47496 +
47497 +config GRKERNSEC_NO_RBAC
47498 + bool "Disable RBAC system"
47499 + help
47500 + If you say Y here, the /dev/grsec device will be removed from the kernel,
47501 + preventing the RBAC system from being enabled. You should only say Y
47502 + here if you have no intention of using the RBAC system, so as to prevent
47503 + an attacker with root access from misusing the RBAC system to hide files
47504 + and processes when loadable module support and /dev/[k]mem have been
47505 + locked down.
47506 +
47507 +config GRKERNSEC_ACL_HIDEKERN
47508 + bool "Hide kernel processes"
47509 + help
47510 + If you say Y here, all kernel threads will be hidden to all
47511 + processes but those whose subject has the "view hidden processes"
47512 + flag.
47513 +
47514 +config GRKERNSEC_ACL_MAXTRIES
47515 + int "Maximum tries before password lockout"
47516 + default 3
47517 + help
47518 + This option enforces the maximum number of times a user can attempt
47519 + to authorize themselves with the grsecurity RBAC system before being
47520 + denied the ability to attempt authorization again for a specified time.
47521 + The lower the number, the harder it will be to brute-force a password.
47522 +
47523 +config GRKERNSEC_ACL_TIMEOUT
47524 + int "Time to wait after max password tries, in seconds"
47525 + default 30
47526 + help
47527 + This option specifies the time the user must wait after attempting to
47528 + authorize to the RBAC system with the maximum number of invalid
47529 + passwords. The higher the number, the harder it will be to brute-force
47530 + a password.
47531 +
47532 +endmenu
47533 +menu "Filesystem Protections"
47534 +depends on GRKERNSEC
47535 +
47536 +config GRKERNSEC_PROC
47537 + bool "Proc restrictions"
47538 + help
47539 + If you say Y here, the permissions of the /proc filesystem
47540 + will be altered to enhance system security and privacy. You MUST
47541 + choose either a user only restriction or a user and group restriction.
47542 + Depending upon the option you choose, you can either restrict users to
47543 + see only the processes they themselves run, or choose a group that can
47544 + view all processes and files normally restricted to root if you choose
47545 + the "restrict to user only" option. NOTE: If you're running identd as
47546 + a non-root user, you will have to run it as the group you specify here.
47547 +
47548 +config GRKERNSEC_PROC_USER
47549 + bool "Restrict /proc to user only"
47550 + depends on GRKERNSEC_PROC
47551 + help
47552 + If you say Y here, non-root users will only be able to view their own
47553 + processes, and restricts them from viewing network-related information,
47554 + and viewing kernel symbol and module information.
47555 +
47556 +config GRKERNSEC_PROC_USERGROUP
47557 + bool "Allow special group"
47558 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
47559 + help
47560 + If you say Y here, you will be able to select a group that will be
47561 + able to view all processes and network-related information. If you've
47562 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
47563 + remain hidden. This option is useful if you want to run identd as
47564 + a non-root user.
47565 +
47566 +config GRKERNSEC_PROC_GID
47567 + int "GID for special group"
47568 + depends on GRKERNSEC_PROC_USERGROUP
47569 + default 1001
47570 +
47571 +config GRKERNSEC_PROC_ADD
47572 + bool "Additional restrictions"
47573 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
47574 + help
47575 + If you say Y here, additional restrictions will be placed on
47576 + /proc that keep normal users from viewing device information and
47577 + slabinfo information that could be useful for exploits.
47578 +
47579 +config GRKERNSEC_LINK
47580 + bool "Linking restrictions"
47581 + help
47582 + If you say Y here, /tmp race exploits will be prevented, since users
47583 + will no longer be able to follow symlinks owned by other users in
47584 + world-writable +t directories (e.g. /tmp), unless the owner of the
47585 + symlink is the owner of the directory. users will also not be
47586 + able to hardlink to files they do not own. If the sysctl option is
47587 + enabled, a sysctl option with name "linking_restrictions" is created.
47588 +
47589 +config GRKERNSEC_FIFO
47590 + bool "FIFO restrictions"
47591 + help
47592 + If you say Y here, users will not be able to write to FIFOs they don't
47593 + own in world-writable +t directories (e.g. /tmp), unless the owner of
47594 + the FIFO is the same owner of the directory it's held in. If the sysctl
47595 + option is enabled, a sysctl option with name "fifo_restrictions" is
47596 + created.
47597 +
47598 +config GRKERNSEC_SYSFS_RESTRICT
47599 + bool "Sysfs/debugfs restriction"
47600 + depends on SYSFS
47601 + help
47602 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
47603 + any filesystem normally mounted under it (e.g. debugfs) will be
47604 + mostly accessible only by root. These filesystems generally provide access
47605 + to hardware and debug information that isn't appropriate for unprivileged
47606 + users of the system. Sysfs and debugfs have also become a large source
47607 + of new vulnerabilities, ranging from infoleaks to local compromise.
47608 + There has been very little oversight with an eye toward security involved
47609 + in adding new exporters of information to these filesystems, so their
47610 + use is discouraged.
47611 + For reasons of compatibility, a few directories have been whitelisted
47612 + for access by non-root users:
47613 + /sys/fs/selinux
47614 + /sys/fs/fuse
47615 + /sys/devices/system/cpu
47616 +
47617 +config GRKERNSEC_ROFS
47618 + bool "Runtime read-only mount protection"
47619 + help
47620 + If you say Y here, a sysctl option with name "romount_protect" will
47621 + be created. By setting this option to 1 at runtime, filesystems
47622 + will be protected in the following ways:
47623 + * No new writable mounts will be allowed
47624 + * Existing read-only mounts won't be able to be remounted read/write
47625 + * Write operations will be denied on all block devices
47626 + This option acts independently of grsec_lock: once it is set to 1,
47627 + it cannot be turned off. Therefore, please be mindful of the resulting
47628 + behavior if this option is enabled in an init script on a read-only
47629 + filesystem. This feature is mainly intended for secure embedded systems.
47630 +
47631 +config GRKERNSEC_CHROOT
47632 + bool "Chroot jail restrictions"
47633 + help
47634 + If you say Y here, you will be able to choose several options that will
47635 + make breaking out of a chrooted jail much more difficult. If you
47636 + encounter no software incompatibilities with the following options, it
47637 + is recommended that you enable each one.
47638 +
47639 +config GRKERNSEC_CHROOT_MOUNT
47640 + bool "Deny mounts"
47641 + depends on GRKERNSEC_CHROOT
47642 + help
47643 + If you say Y here, processes inside a chroot will not be able to
47644 + mount or remount filesystems. If the sysctl option is enabled, a
47645 + sysctl option with name "chroot_deny_mount" is created.
47646 +
47647 +config GRKERNSEC_CHROOT_DOUBLE
47648 + bool "Deny double-chroots"
47649 + depends on GRKERNSEC_CHROOT
47650 + help
47651 + If you say Y here, processes inside a chroot will not be able to chroot
47652 + again outside the chroot. This is a widely used method of breaking
47653 + out of a chroot jail and should not be allowed. If the sysctl
47654 + option is enabled, a sysctl option with name
47655 + "chroot_deny_chroot" is created.
47656 +
47657 +config GRKERNSEC_CHROOT_PIVOT
47658 + bool "Deny pivot_root in chroot"
47659 + depends on GRKERNSEC_CHROOT
47660 + help
47661 + If you say Y here, processes inside a chroot will not be able to use
47662 + a function called pivot_root() that was introduced in Linux 2.3.41. It
47663 + works similar to chroot in that it changes the root filesystem. This
47664 + function could be misused in a chrooted process to attempt to break out
47665 + of the chroot, and therefore should not be allowed. If the sysctl
47666 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
47667 + created.
47668 +
47669 +config GRKERNSEC_CHROOT_CHDIR
47670 + bool "Enforce chdir(\"/\") on all chroots"
47671 + depends on GRKERNSEC_CHROOT
47672 + help
47673 + If you say Y here, the current working directory of all newly-chrooted
47674 + applications will be set to the the root directory of the chroot.
47675 + The man page on chroot(2) states:
47676 + Note that this call does not change the current working
47677 + directory, so that `.' can be outside the tree rooted at
47678 + `/'. In particular, the super-user can escape from a
47679 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
47680 +
47681 + It is recommended that you say Y here, since it's not known to break
47682 + any software. If the sysctl option is enabled, a sysctl option with
47683 + name "chroot_enforce_chdir" is created.
47684 +
47685 +config GRKERNSEC_CHROOT_CHMOD
47686 + bool "Deny (f)chmod +s"
47687 + depends on GRKERNSEC_CHROOT
47688 + help
47689 + If you say Y here, processes inside a chroot will not be able to chmod
47690 + or fchmod files to make them have suid or sgid bits. This protects
47691 + against another published method of breaking a chroot. If the sysctl
47692 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
47693 + created.
47694 +
47695 +config GRKERNSEC_CHROOT_FCHDIR
47696 + bool "Deny fchdir out of chroot"
47697 + depends on GRKERNSEC_CHROOT
47698 + help
47699 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
47700 + to a file descriptor of the chrooting process that points to a directory
47701 + outside the filesystem will be stopped. If the sysctl option
47702 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
47703 +
47704 +config GRKERNSEC_CHROOT_MKNOD
47705 + bool "Deny mknod"
47706 + depends on GRKERNSEC_CHROOT
47707 + help
47708 + If you say Y here, processes inside a chroot will not be allowed to
47709 + mknod. The problem with using mknod inside a chroot is that it
47710 + would allow an attacker to create a device entry that is the same
47711 + as one on the physical root of your system, which could range from
47712 + anything from the console device to a device for your harddrive (which
47713 + they could then use to wipe the drive or steal data). It is recommended
47714 + that you say Y here, unless you run into software incompatibilities.
47715 + If the sysctl option is enabled, a sysctl option with name
47716 + "chroot_deny_mknod" is created.
47717 +
47718 +config GRKERNSEC_CHROOT_SHMAT
47719 + bool "Deny shmat() out of chroot"
47720 + depends on GRKERNSEC_CHROOT
47721 + help
47722 + If you say Y here, processes inside a chroot will not be able to attach
47723 + to shared memory segments that were created outside of the chroot jail.
47724 + It is recommended that you say Y here. If the sysctl option is enabled,
47725 + a sysctl option with name "chroot_deny_shmat" is created.
47726 +
47727 +config GRKERNSEC_CHROOT_UNIX
47728 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
47729 + depends on GRKERNSEC_CHROOT
47730 + help
47731 + If you say Y here, processes inside a chroot will not be able to
47732 + connect to abstract (meaning not belonging to a filesystem) Unix
47733 + domain sockets that were bound outside of a chroot. It is recommended
47734 + that you say Y here. If the sysctl option is enabled, a sysctl option
47735 + with name "chroot_deny_unix" is created.
47736 +
47737 +config GRKERNSEC_CHROOT_FINDTASK
47738 + bool "Protect outside processes"
47739 + depends on GRKERNSEC_CHROOT
47740 + help
47741 + If you say Y here, processes inside a chroot will not be able to
47742 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
47743 + getsid, or view any process outside of the chroot. If the sysctl
47744 + option is enabled, a sysctl option with name "chroot_findtask" is
47745 + created.
47746 +
47747 +config GRKERNSEC_CHROOT_NICE
47748 + bool "Restrict priority changes"
47749 + depends on GRKERNSEC_CHROOT
47750 + help
47751 + If you say Y here, processes inside a chroot will not be able to raise
47752 + the priority of processes in the chroot, or alter the priority of
47753 + processes outside the chroot. This provides more security than simply
47754 + removing CAP_SYS_NICE from the process' capability set. If the
47755 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
47756 + is created.
47757 +
47758 +config GRKERNSEC_CHROOT_SYSCTL
47759 + bool "Deny sysctl writes"
47760 + depends on GRKERNSEC_CHROOT
47761 + help
47762 + If you say Y here, an attacker in a chroot will not be able to
47763 + write to sysctl entries, either by sysctl(2) or through a /proc
47764 + interface. It is strongly recommended that you say Y here. If the
47765 + sysctl option is enabled, a sysctl option with name
47766 + "chroot_deny_sysctl" is created.
47767 +
47768 +config GRKERNSEC_CHROOT_CAPS
47769 + bool "Capability restrictions"
47770 + depends on GRKERNSEC_CHROOT
47771 + help
47772 + If you say Y here, the capabilities on all processes within a
47773 + chroot jail will be lowered to stop module insertion, raw i/o,
47774 + system and net admin tasks, rebooting the system, modifying immutable
47775 + files, modifying IPC owned by another, and changing the system time.
47776 + This is left an option because it can break some apps. Disable this
47777 + if your chrooted apps are having problems performing those kinds of
47778 + tasks. If the sysctl option is enabled, a sysctl option with
47779 + name "chroot_caps" is created.
47780 +
47781 +endmenu
47782 +menu "Kernel Auditing"
47783 +depends on GRKERNSEC
47784 +
47785 +config GRKERNSEC_AUDIT_GROUP
47786 + bool "Single group for auditing"
47787 + help
47788 + If you say Y here, the exec, chdir, and (un)mount logging features
47789 + will only operate on a group you specify. This option is recommended
47790 + if you only want to watch certain users instead of having a large
47791 + amount of logs from the entire system. If the sysctl option is enabled,
47792 + a sysctl option with name "audit_group" is created.
47793 +
47794 +config GRKERNSEC_AUDIT_GID
47795 + int "GID for auditing"
47796 + depends on GRKERNSEC_AUDIT_GROUP
47797 + default 1007
47798 +
47799 +config GRKERNSEC_EXECLOG
47800 + bool "Exec logging"
47801 + help
47802 + If you say Y here, all execve() calls will be logged (since the
47803 + other exec*() calls are frontends to execve(), all execution
47804 + will be logged). Useful for shell-servers that like to keep track
47805 + of their users. If the sysctl option is enabled, a sysctl option with
47806 + name "exec_logging" is created.
47807 + WARNING: This option when enabled will produce a LOT of logs, especially
47808 + on an active system.
47809 +
47810 +config GRKERNSEC_RESLOG
47811 + bool "Resource logging"
47812 + help
47813 + If you say Y here, all attempts to overstep resource limits will
47814 + be logged with the resource name, the requested size, and the current
47815 + limit. It is highly recommended that you say Y here. If the sysctl
47816 + option is enabled, a sysctl option with name "resource_logging" is
47817 + created. If the RBAC system is enabled, the sysctl value is ignored.
47818 +
47819 +config GRKERNSEC_CHROOT_EXECLOG
47820 + bool "Log execs within chroot"
47821 + help
47822 + If you say Y here, all executions inside a chroot jail will be logged
47823 + to syslog. This can cause a large amount of logs if certain
47824 + applications (eg. djb's daemontools) are installed on the system, and
47825 + is therefore left as an option. If the sysctl option is enabled, a
47826 + sysctl option with name "chroot_execlog" is created.
47827 +
47828 +config GRKERNSEC_AUDIT_PTRACE
47829 + bool "Ptrace logging"
47830 + help
47831 + If you say Y here, all attempts to attach to a process via ptrace
47832 + will be logged. If the sysctl option is enabled, a sysctl option
47833 + with name "audit_ptrace" is created.
47834 +
47835 +config GRKERNSEC_AUDIT_CHDIR
47836 + bool "Chdir logging"
47837 + help
47838 + If you say Y here, all chdir() calls will be logged. If the sysctl
47839 + option is enabled, a sysctl option with name "audit_chdir" is created.
47840 +
47841 +config GRKERNSEC_AUDIT_MOUNT
47842 + bool "(Un)Mount logging"
47843 + help
47844 + If you say Y here, all mounts and unmounts will be logged. If the
47845 + sysctl option is enabled, a sysctl option with name "audit_mount" is
47846 + created.
47847 +
47848 +config GRKERNSEC_SIGNAL
47849 + bool "Signal logging"
47850 + help
47851 + If you say Y here, certain important signals will be logged, such as
47852 + SIGSEGV, which will as a result inform you of when a error in a program
47853 + occurred, which in some cases could mean a possible exploit attempt.
47854 + If the sysctl option is enabled, a sysctl option with name
47855 + "signal_logging" is created.
47856 +
47857 +config GRKERNSEC_FORKFAIL
47858 + bool "Fork failure logging"
47859 + help
47860 + If you say Y here, all failed fork() attempts will be logged.
47861 + This could suggest a fork bomb, or someone attempting to overstep
47862 + their process limit. If the sysctl option is enabled, a sysctl option
47863 + with name "forkfail_logging" is created.
47864 +
47865 +config GRKERNSEC_TIME
47866 + bool "Time change logging"
47867 + help
47868 + If you say Y here, any changes of the system clock will be logged.
47869 + If the sysctl option is enabled, a sysctl option with name
47870 + "timechange_logging" is created.
47871 +
47872 +config GRKERNSEC_PROC_IPADDR
47873 + bool "/proc/<pid>/ipaddr support"
47874 + help
47875 + If you say Y here, a new entry will be added to each /proc/<pid>
47876 + directory that contains the IP address of the person using the task.
47877 + The IP is carried across local TCP and AF_UNIX stream sockets.
47878 + This information can be useful for IDS/IPSes to perform remote response
47879 + to a local attack. The entry is readable by only the owner of the
47880 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
47881 + the RBAC system), and thus does not create privacy concerns.
47882 +
47883 +config GRKERNSEC_RWXMAP_LOG
47884 + bool 'Denied RWX mmap/mprotect logging'
47885 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
47886 + help
47887 + If you say Y here, calls to mmap() and mprotect() with explicit
47888 + usage of PROT_WRITE and PROT_EXEC together will be logged when
47889 + denied by the PAX_MPROTECT feature. If the sysctl option is
47890 + enabled, a sysctl option with name "rwxmap_logging" is created.
47891 +
47892 +config GRKERNSEC_AUDIT_TEXTREL
47893 + bool 'ELF text relocations logging (READ HELP)'
47894 + depends on PAX_MPROTECT
47895 + help
47896 + If you say Y here, text relocations will be logged with the filename
47897 + of the offending library or binary. The purpose of the feature is
47898 + to help Linux distribution developers get rid of libraries and
47899 + binaries that need text relocations which hinder the future progress
47900 + of PaX. Only Linux distribution developers should say Y here, and
47901 + never on a production machine, as this option creates an information
47902 + leak that could aid an attacker in defeating the randomization of
47903 + a single memory region. If the sysctl option is enabled, a sysctl
47904 + option with name "audit_textrel" is created.
47905 +
47906 +endmenu
47907 +
47908 +menu "Executable Protections"
47909 +depends on GRKERNSEC
47910 +
47911 +config GRKERNSEC_DMESG
47912 + bool "Dmesg(8) restriction"
47913 + help
47914 + If you say Y here, non-root users will not be able to use dmesg(8)
47915 + to view up to the last 4kb of messages in the kernel's log buffer.
47916 + The kernel's log buffer often contains kernel addresses and other
47917 + identifying information useful to an attacker in fingerprinting a
47918 + system for a targeted exploit.
47919 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
47920 + created.
47921 +
47922 +config GRKERNSEC_HARDEN_PTRACE
47923 + bool "Deter ptrace-based process snooping"
47924 + help
47925 + If you say Y here, TTY sniffers and other malicious monitoring
47926 + programs implemented through ptrace will be defeated. If you
47927 + have been using the RBAC system, this option has already been
47928 + enabled for several years for all users, with the ability to make
47929 + fine-grained exceptions.
47930 +
47931 + This option only affects the ability of non-root users to ptrace
47932 + processes that are not a descendent of the ptracing process.
47933 + This means that strace ./binary and gdb ./binary will still work,
47934 + but attaching to arbitrary processes will not. If the sysctl
47935 + option is enabled, a sysctl option with name "harden_ptrace" is
47936 + created.
47937 +
47938 +config GRKERNSEC_PTRACE_READEXEC
47939 + bool "Require read access to ptrace sensitive binaries"
47940 + help
47941 + If you say Y here, unprivileged users will not be able to ptrace unreadable
47942 + binaries. This option is useful in environments that
47943 + remove the read bits (e.g. file mode 4711) from suid binaries to
47944 + prevent infoleaking of their contents. This option adds
47945 + consistency to the use of that file mode, as the binary could normally
47946 + be read out when run without privileges while ptracing.
47947 +
47948 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
47949 + is created.
47950 +
47951 +config GRKERNSEC_SETXID
47952 + bool "Enforce consistent multithreaded privileges"
47953 + help
47954 + If you say Y here, a change from a root uid to a non-root uid
47955 + in a multithreaded application will cause the resulting uids,
47956 + gids, supplementary groups, and capabilities in that thread
47957 + to be propagated to the other threads of the process. In most
47958 + cases this is unnecessary, as glibc will emulate this behavior
47959 + on behalf of the application. Other libcs do not act in the
47960 + same way, allowing the other threads of the process to continue
47961 + running with root privileges. If the sysctl option is enabled,
47962 + a sysctl option with name "consistent_setxid" is created.
47963 +
47964 +config GRKERNSEC_TPE
47965 + bool "Trusted Path Execution (TPE)"
47966 + help
47967 + If you say Y here, you will be able to choose a gid to add to the
47968 + supplementary groups of users you want to mark as "untrusted."
47969 + These users will not be able to execute any files that are not in
47970 + root-owned directories writable only by root. If the sysctl option
47971 + is enabled, a sysctl option with name "tpe" is created.
47972 +
47973 +config GRKERNSEC_TPE_ALL
47974 + bool "Partially restrict all non-root users"
47975 + depends on GRKERNSEC_TPE
47976 + help
47977 + If you say Y here, all non-root users will be covered under
47978 + a weaker TPE restriction. This is separate from, and in addition to,
47979 + the main TPE options that you have selected elsewhere. Thus, if a
47980 + "trusted" GID is chosen, this restriction applies to even that GID.
47981 + Under this restriction, all non-root users will only be allowed to
47982 + execute files in directories they own that are not group or
47983 + world-writable, or in directories owned by root and writable only by
47984 + root. If the sysctl option is enabled, a sysctl option with name
47985 + "tpe_restrict_all" is created.
47986 +
47987 +config GRKERNSEC_TPE_INVERT
47988 + bool "Invert GID option"
47989 + depends on GRKERNSEC_TPE
47990 + help
47991 + If you say Y here, the group you specify in the TPE configuration will
47992 + decide what group TPE restrictions will be *disabled* for. This
47993 + option is useful if you want TPE restrictions to be applied to most
47994 + users on the system. If the sysctl option is enabled, a sysctl option
47995 + with name "tpe_invert" is created. Unlike other sysctl options, this
47996 + entry will default to on for backward-compatibility.
47997 +
47998 +config GRKERNSEC_TPE_GID
47999 + int "GID for untrusted users"
48000 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
48001 + default 1005
48002 + help
48003 + Setting this GID determines what group TPE restrictions will be
48004 + *enabled* for. If the sysctl option is enabled, a sysctl option
48005 + with name "tpe_gid" is created.
48006 +
48007 +config GRKERNSEC_TPE_GID
48008 + int "GID for trusted users"
48009 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
48010 + default 1005
48011 + help
48012 + Setting this GID determines what group TPE restrictions will be
48013 + *disabled* for. If the sysctl option is enabled, a sysctl option
48014 + with name "tpe_gid" is created.
48015 +
48016 +endmenu
48017 +menu "Network Protections"
48018 +depends on GRKERNSEC
48019 +
48020 +config GRKERNSEC_RANDNET
48021 + bool "Larger entropy pools"
48022 + help
48023 + If you say Y here, the entropy pools used for many features of Linux
48024 + and grsecurity will be doubled in size. Since several grsecurity
48025 + features use additional randomness, it is recommended that you say Y
48026 + here. Saying Y here has a similar effect as modifying
48027 + /proc/sys/kernel/random/poolsize.
48028 +
48029 +config GRKERNSEC_BLACKHOLE
48030 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
48031 + depends on NET
48032 + help
48033 + If you say Y here, neither TCP resets nor ICMP
48034 + destination-unreachable packets will be sent in response to packets
48035 + sent to ports for which no associated listening process exists.
48036 + This feature supports both IPV4 and IPV6 and exempts the
48037 + loopback interface from blackholing. Enabling this feature
48038 + makes a host more resilient to DoS attacks and reduces network
48039 + visibility against scanners.
48040 +
48041 + The blackhole feature as-implemented is equivalent to the FreeBSD
48042 + blackhole feature, as it prevents RST responses to all packets, not
48043 + just SYNs. Under most application behavior this causes no
48044 + problems, but applications (like haproxy) may not close certain
48045 + connections in a way that cleanly terminates them on the remote
48046 + end, leaving the remote host in LAST_ACK state. Because of this
48047 + side-effect and to prevent intentional LAST_ACK DoSes, this
48048 + feature also adds automatic mitigation against such attacks.
48049 + The mitigation drastically reduces the amount of time a socket
48050 + can spend in LAST_ACK state. If you're using haproxy and not
48051 + all servers it connects to have this option enabled, consider
48052 + disabling this feature on the haproxy host.
48053 +
48054 + If the sysctl option is enabled, two sysctl options with names
48055 + "ip_blackhole" and "lastack_retries" will be created.
48056 + While "ip_blackhole" takes the standard zero/non-zero on/off
48057 + toggle, "lastack_retries" uses the same kinds of values as
48058 + "tcp_retries1" and "tcp_retries2". The default value of 4
48059 + prevents a socket from lasting more than 45 seconds in LAST_ACK
48060 + state.
48061 +
48062 +config GRKERNSEC_SOCKET
48063 + bool "Socket restrictions"
48064 + depends on NET
48065 + help
48066 + If you say Y here, you will be able to choose from several options.
48067 + If you assign a GID on your system and add it to the supplementary
48068 + groups of users you want to restrict socket access to, this patch
48069 + will perform up to three things, based on the option(s) you choose.
48070 +
48071 +config GRKERNSEC_SOCKET_ALL
48072 + bool "Deny any sockets to group"
48073 + depends on GRKERNSEC_SOCKET
48074 + help
48075 + If you say Y here, you will be able to choose a GID of whose users will
48076 + be unable to connect to other hosts from your machine or run server
48077 + applications from your machine. If the sysctl option is enabled, a
48078 + sysctl option with name "socket_all" is created.
48079 +
48080 +config GRKERNSEC_SOCKET_ALL_GID
48081 + int "GID to deny all sockets for"
48082 + depends on GRKERNSEC_SOCKET_ALL
48083 + default 1004
48084 + help
48085 + Here you can choose the GID to disable socket access for. Remember to
48086 + add the users you want socket access disabled for to the GID
48087 + specified here. If the sysctl option is enabled, a sysctl option
48088 + with name "socket_all_gid" is created.
48089 +
48090 +config GRKERNSEC_SOCKET_CLIENT
48091 + bool "Deny client sockets to group"
48092 + depends on GRKERNSEC_SOCKET
48093 + help
48094 + If you say Y here, you will be able to choose a GID of whose users will
48095 + be unable to connect to other hosts from your machine, but will be
48096 + able to run servers. If this option is enabled, all users in the group
48097 + you specify will have to use passive mode when initiating ftp transfers
48098 + from the shell on your machine. If the sysctl option is enabled, a
48099 + sysctl option with name "socket_client" is created.
48100 +
48101 +config GRKERNSEC_SOCKET_CLIENT_GID
48102 + int "GID to deny client sockets for"
48103 + depends on GRKERNSEC_SOCKET_CLIENT
48104 + default 1003
48105 + help
48106 + Here you can choose the GID to disable client socket access for.
48107 + Remember to add the users you want client socket access disabled for to
48108 + the GID specified here. If the sysctl option is enabled, a sysctl
48109 + option with name "socket_client_gid" is created.
48110 +
48111 +config GRKERNSEC_SOCKET_SERVER
48112 + bool "Deny server sockets to group"
48113 + depends on GRKERNSEC_SOCKET
48114 + help
48115 + If you say Y here, you will be able to choose a GID of whose users will
48116 + be unable to run server applications from your machine. If the sysctl
48117 + option is enabled, a sysctl option with name "socket_server" is created.
48118 +
48119 +config GRKERNSEC_SOCKET_SERVER_GID
48120 + int "GID to deny server sockets for"
48121 + depends on GRKERNSEC_SOCKET_SERVER
48122 + default 1002
48123 + help
48124 + Here you can choose the GID to disable server socket access for.
48125 + Remember to add the users you want server socket access disabled for to
48126 + the GID specified here. If the sysctl option is enabled, a sysctl
48127 + option with name "socket_server_gid" is created.
48128 +
48129 +endmenu
48130 +menu "Sysctl support"
48131 +depends on GRKERNSEC && SYSCTL
48132 +
48133 +config GRKERNSEC_SYSCTL
48134 + bool "Sysctl support"
48135 + help
48136 + If you say Y here, you will be able to change the options that
48137 + grsecurity runs with at bootup, without having to recompile your
48138 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
48139 + to enable (1) or disable (0) various features. All the sysctl entries
48140 + are mutable until the "grsec_lock" entry is set to a non-zero value.
48141 + All features enabled in the kernel configuration are disabled at boot
48142 + if you do not say Y to the "Turn on features by default" option.
48143 + All options should be set at startup, and the grsec_lock entry should
48144 + be set to a non-zero value after all the options are set.
48145 + *THIS IS EXTREMELY IMPORTANT*
48146 +
48147 +config GRKERNSEC_SYSCTL_DISTRO
48148 + bool "Extra sysctl support for distro makers (READ HELP)"
48149 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
48150 + help
48151 + If you say Y here, additional sysctl options will be created
48152 + for features that affect processes running as root. Therefore,
48153 + it is critical when using this option that the grsec_lock entry be
48154 + enabled after boot. Only distros with prebuilt kernel packages
48155 + with this option enabled that can ensure grsec_lock is enabled
48156 + after boot should use this option.
48157 + *Failure to set grsec_lock after boot makes all grsec features
48158 + this option covers useless*
48159 +
48160 + Currently this option creates the following sysctl entries:
48161 + "Disable Privileged I/O": "disable_priv_io"
48162 +
48163 +config GRKERNSEC_SYSCTL_ON
48164 + bool "Turn on features by default"
48165 + depends on GRKERNSEC_SYSCTL
48166 + help
48167 + If you say Y here, instead of having all features enabled in the
48168 + kernel configuration disabled at boot time, the features will be
48169 + enabled at boot time. It is recommended you say Y here unless
48170 + there is some reason you would want all sysctl-tunable features to
48171 + be disabled by default. As mentioned elsewhere, it is important
48172 + to enable the grsec_lock entry once you have finished modifying
48173 + the sysctl entries.
48174 +
48175 +endmenu
48176 +menu "Logging Options"
48177 +depends on GRKERNSEC
48178 +
48179 +config GRKERNSEC_FLOODTIME
48180 + int "Seconds in between log messages (minimum)"
48181 + default 10
48182 + help
48183 + This option allows you to enforce the number of seconds between
48184 + grsecurity log messages. The default should be suitable for most
48185 + people, however, if you choose to change it, choose a value small enough
48186 + to allow informative logs to be produced, but large enough to
48187 + prevent flooding.
48188 +
48189 +config GRKERNSEC_FLOODBURST
48190 + int "Number of messages in a burst (maximum)"
48191 + default 6
48192 + help
48193 + This option allows you to choose the maximum number of messages allowed
48194 + within the flood time interval you chose in a separate option. The
48195 + default should be suitable for most people, however if you find that
48196 + many of your logs are being interpreted as flooding, you may want to
48197 + raise this value.
48198 +
48199 +endmenu
48200 +
48201 +endmenu
48202 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
48203 new file mode 100644
48204 index 0000000..1b9afa9
48205 --- /dev/null
48206 +++ b/grsecurity/Makefile
48207 @@ -0,0 +1,38 @@
48208 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
48209 +# during 2001-2009 it has been completely redesigned by Brad Spengler
48210 +# into an RBAC system
48211 +#
48212 +# All code in this directory and various hooks inserted throughout the kernel
48213 +# are copyright Brad Spengler - Open Source Security, Inc., and released
48214 +# under the GPL v2 or higher
48215 +
48216 +KBUILD_CFLAGS += -Werror
48217 +
48218 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
48219 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
48220 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
48221 +
48222 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
48223 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
48224 + gracl_learn.o grsec_log.o
48225 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
48226 +
48227 +ifdef CONFIG_NET
48228 +obj-y += grsec_sock.o
48229 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
48230 +endif
48231 +
48232 +ifndef CONFIG_GRKERNSEC
48233 +obj-y += grsec_disabled.o
48234 +endif
48235 +
48236 +ifdef CONFIG_GRKERNSEC_HIDESYM
48237 +extra-y := grsec_hidesym.o
48238 +$(obj)/grsec_hidesym.o:
48239 + @-chmod -f 500 /boot
48240 + @-chmod -f 500 /lib/modules
48241 + @-chmod -f 500 /lib64/modules
48242 + @-chmod -f 500 /lib32/modules
48243 + @-chmod -f 700 .
48244 + @echo ' grsec: protected kernel image paths'
48245 +endif
48246 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
48247 new file mode 100644
48248 index 0000000..6e989da
48249 --- /dev/null
48250 +++ b/grsecurity/gracl.c
48251 @@ -0,0 +1,4163 @@
48252 +#include <linux/kernel.h>
48253 +#include <linux/module.h>
48254 +#include <linux/sched.h>
48255 +#include <linux/mm.h>
48256 +#include <linux/file.h>
48257 +#include <linux/fs.h>
48258 +#include <linux/namei.h>
48259 +#include <linux/mount.h>
48260 +#include <linux/tty.h>
48261 +#include <linux/proc_fs.h>
48262 +#include <linux/lglock.h>
48263 +#include <linux/slab.h>
48264 +#include <linux/vmalloc.h>
48265 +#include <linux/types.h>
48266 +#include <linux/sysctl.h>
48267 +#include <linux/netdevice.h>
48268 +#include <linux/ptrace.h>
48269 +#include <linux/gracl.h>
48270 +#include <linux/gralloc.h>
48271 +#include <linux/security.h>
48272 +#include <linux/grinternal.h>
48273 +#include <linux/pid_namespace.h>
48274 +#include <linux/fdtable.h>
48275 +#include <linux/percpu.h>
48276 +
48277 +#include <asm/uaccess.h>
48278 +#include <asm/errno.h>
48279 +#include <asm/mman.h>
48280 +
48281 +static struct acl_role_db acl_role_set;
48282 +static struct name_db name_set;
48283 +static struct inodev_db inodev_set;
48284 +
48285 +/* for keeping track of userspace pointers used for subjects, so we
48286 + can share references in the kernel as well
48287 +*/
48288 +
48289 +static struct path real_root;
48290 +
48291 +static struct acl_subj_map_db subj_map_set;
48292 +
48293 +static struct acl_role_label *default_role;
48294 +
48295 +static struct acl_role_label *role_list;
48296 +
48297 +static u16 acl_sp_role_value;
48298 +
48299 +extern char *gr_shared_page[4];
48300 +static DEFINE_MUTEX(gr_dev_mutex);
48301 +DEFINE_RWLOCK(gr_inode_lock);
48302 +
48303 +struct gr_arg *gr_usermode;
48304 +
48305 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
48306 +
48307 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
48308 +extern void gr_clear_learn_entries(void);
48309 +
48310 +#ifdef CONFIG_GRKERNSEC_RESLOG
48311 +extern void gr_log_resource(const struct task_struct *task,
48312 + const int res, const unsigned long wanted, const int gt);
48313 +#endif
48314 +
48315 +unsigned char *gr_system_salt;
48316 +unsigned char *gr_system_sum;
48317 +
48318 +static struct sprole_pw **acl_special_roles = NULL;
48319 +static __u16 num_sprole_pws = 0;
48320 +
48321 +static struct acl_role_label *kernel_role = NULL;
48322 +
48323 +static unsigned int gr_auth_attempts = 0;
48324 +static unsigned long gr_auth_expires = 0UL;
48325 +
48326 +#ifdef CONFIG_NET
48327 +extern struct vfsmount *sock_mnt;
48328 +#endif
48329 +
48330 +extern struct vfsmount *pipe_mnt;
48331 +extern struct vfsmount *shm_mnt;
48332 +#ifdef CONFIG_HUGETLBFS
48333 +extern struct vfsmount *hugetlbfs_vfsmount;
48334 +#endif
48335 +
48336 +static struct acl_object_label *fakefs_obj_rw;
48337 +static struct acl_object_label *fakefs_obj_rwx;
48338 +
48339 +extern int gr_init_uidset(void);
48340 +extern void gr_free_uidset(void);
48341 +extern void gr_remove_uid(uid_t uid);
48342 +extern int gr_find_uid(uid_t uid);
48343 +
48344 +DECLARE_BRLOCK(vfsmount_lock);
48345 +
48346 +__inline__ int
48347 +gr_acl_is_enabled(void)
48348 +{
48349 + return (gr_status & GR_READY);
48350 +}
48351 +
48352 +#ifdef CONFIG_BTRFS_FS
48353 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
48354 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
48355 +#endif
48356 +
48357 +static inline dev_t __get_dev(const struct dentry *dentry)
48358 +{
48359 +#ifdef CONFIG_BTRFS_FS
48360 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
48361 + return get_btrfs_dev_from_inode(dentry->d_inode);
48362 + else
48363 +#endif
48364 + return dentry->d_inode->i_sb->s_dev;
48365 +}
48366 +
48367 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
48368 +{
48369 + return __get_dev(dentry);
48370 +}
48371 +
48372 +static char gr_task_roletype_to_char(struct task_struct *task)
48373 +{
48374 + switch (task->role->roletype &
48375 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
48376 + GR_ROLE_SPECIAL)) {
48377 + case GR_ROLE_DEFAULT:
48378 + return 'D';
48379 + case GR_ROLE_USER:
48380 + return 'U';
48381 + case GR_ROLE_GROUP:
48382 + return 'G';
48383 + case GR_ROLE_SPECIAL:
48384 + return 'S';
48385 + }
48386 +
48387 + return 'X';
48388 +}
48389 +
48390 +char gr_roletype_to_char(void)
48391 +{
48392 + return gr_task_roletype_to_char(current);
48393 +}
48394 +
48395 +__inline__ int
48396 +gr_acl_tpe_check(void)
48397 +{
48398 + if (unlikely(!(gr_status & GR_READY)))
48399 + return 0;
48400 + if (current->role->roletype & GR_ROLE_TPE)
48401 + return 1;
48402 + else
48403 + return 0;
48404 +}
48405 +
48406 +int
48407 +gr_handle_rawio(const struct inode *inode)
48408 +{
48409 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
48410 + if (inode && S_ISBLK(inode->i_mode) &&
48411 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
48412 + !capable(CAP_SYS_RAWIO))
48413 + return 1;
48414 +#endif
48415 + return 0;
48416 +}
48417 +
48418 +static int
48419 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
48420 +{
48421 + if (likely(lena != lenb))
48422 + return 0;
48423 +
48424 + return !memcmp(a, b, lena);
48425 +}
48426 +
48427 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
48428 +{
48429 + *buflen -= namelen;
48430 + if (*buflen < 0)
48431 + return -ENAMETOOLONG;
48432 + *buffer -= namelen;
48433 + memcpy(*buffer, str, namelen);
48434 + return 0;
48435 +}
48436 +
48437 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
48438 +{
48439 + return prepend(buffer, buflen, name->name, name->len);
48440 +}
48441 +
48442 +static int prepend_path(const struct path *path, struct path *root,
48443 + char **buffer, int *buflen)
48444 +{
48445 + struct dentry *dentry = path->dentry;
48446 + struct vfsmount *vfsmnt = path->mnt;
48447 + bool slash = false;
48448 + int error = 0;
48449 +
48450 + while (dentry != root->dentry || vfsmnt != root->mnt) {
48451 + struct dentry * parent;
48452 +
48453 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
48454 + /* Global root? */
48455 + if (vfsmnt->mnt_parent == vfsmnt) {
48456 + goto out;
48457 + }
48458 + dentry = vfsmnt->mnt_mountpoint;
48459 + vfsmnt = vfsmnt->mnt_parent;
48460 + continue;
48461 + }
48462 + parent = dentry->d_parent;
48463 + prefetch(parent);
48464 + spin_lock(&dentry->d_lock);
48465 + error = prepend_name(buffer, buflen, &dentry->d_name);
48466 + spin_unlock(&dentry->d_lock);
48467 + if (!error)
48468 + error = prepend(buffer, buflen, "/", 1);
48469 + if (error)
48470 + break;
48471 +
48472 + slash = true;
48473 + dentry = parent;
48474 + }
48475 +
48476 +out:
48477 + if (!error && !slash)
48478 + error = prepend(buffer, buflen, "/", 1);
48479 +
48480 + return error;
48481 +}
48482 +
48483 +/* this must be called with vfsmount_lock and rename_lock held */
48484 +
48485 +static char *__our_d_path(const struct path *path, struct path *root,
48486 + char *buf, int buflen)
48487 +{
48488 + char *res = buf + buflen;
48489 + int error;
48490 +
48491 + prepend(&res, &buflen, "\0", 1);
48492 + error = prepend_path(path, root, &res, &buflen);
48493 + if (error)
48494 + return ERR_PTR(error);
48495 +
48496 + return res;
48497 +}
48498 +
48499 +static char *
48500 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
48501 +{
48502 + char *retval;
48503 +
48504 + retval = __our_d_path(path, root, buf, buflen);
48505 + if (unlikely(IS_ERR(retval)))
48506 + retval = strcpy(buf, "<path too long>");
48507 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
48508 + retval[1] = '\0';
48509 +
48510 + return retval;
48511 +}
48512 +
48513 +static char *
48514 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
48515 + char *buf, int buflen)
48516 +{
48517 + struct path path;
48518 + char *res;
48519 +
48520 + path.dentry = (struct dentry *)dentry;
48521 + path.mnt = (struct vfsmount *)vfsmnt;
48522 +
48523 + /* we can use real_root.dentry, real_root.mnt, because this is only called
48524 + by the RBAC system */
48525 + res = gen_full_path(&path, &real_root, buf, buflen);
48526 +
48527 + return res;
48528 +}
48529 +
48530 +static char *
48531 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
48532 + char *buf, int buflen)
48533 +{
48534 + char *res;
48535 + struct path path;
48536 + struct path root;
48537 + struct task_struct *reaper = &init_task;
48538 +
48539 + path.dentry = (struct dentry *)dentry;
48540 + path.mnt = (struct vfsmount *)vfsmnt;
48541 +
48542 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
48543 + get_fs_root(reaper->fs, &root);
48544 +
48545 + write_seqlock(&rename_lock);
48546 + br_read_lock(vfsmount_lock);
48547 + res = gen_full_path(&path, &root, buf, buflen);
48548 + br_read_unlock(vfsmount_lock);
48549 + write_sequnlock(&rename_lock);
48550 +
48551 + path_put(&root);
48552 + return res;
48553 +}
48554 +
48555 +static char *
48556 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
48557 +{
48558 + char *ret;
48559 + write_seqlock(&rename_lock);
48560 + br_read_lock(vfsmount_lock);
48561 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
48562 + PAGE_SIZE);
48563 + br_read_unlock(vfsmount_lock);
48564 + write_sequnlock(&rename_lock);
48565 + return ret;
48566 +}
48567 +
48568 +static char *
48569 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
48570 +{
48571 + char *ret;
48572 + char *buf;
48573 + int buflen;
48574 +
48575 + write_seqlock(&rename_lock);
48576 + br_read_lock(vfsmount_lock);
48577 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
48578 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
48579 + buflen = (int)(ret - buf);
48580 + if (buflen >= 5)
48581 + prepend(&ret, &buflen, "/proc", 5);
48582 + else
48583 + ret = strcpy(buf, "<path too long>");
48584 + br_read_unlock(vfsmount_lock);
48585 + write_sequnlock(&rename_lock);
48586 + return ret;
48587 +}
48588 +
48589 +char *
48590 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
48591 +{
48592 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
48593 + PAGE_SIZE);
48594 +}
48595 +
48596 +char *
48597 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
48598 +{
48599 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
48600 + PAGE_SIZE);
48601 +}
48602 +
48603 +char *
48604 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
48605 +{
48606 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
48607 + PAGE_SIZE);
48608 +}
48609 +
48610 +char *
48611 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
48612 +{
48613 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
48614 + PAGE_SIZE);
48615 +}
48616 +
48617 +char *
48618 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
48619 +{
48620 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
48621 + PAGE_SIZE);
48622 +}
48623 +
48624 +__inline__ __u32
48625 +to_gr_audit(const __u32 reqmode)
48626 +{
48627 + /* masks off auditable permission flags, then shifts them to create
48628 + auditing flags, and adds the special case of append auditing if
48629 + we're requesting write */
48630 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
48631 +}
48632 +
48633 +struct acl_subject_label *
48634 +lookup_subject_map(const struct acl_subject_label *userp)
48635 +{
48636 + unsigned int index = shash(userp, subj_map_set.s_size);
48637 + struct subject_map *match;
48638 +
48639 + match = subj_map_set.s_hash[index];
48640 +
48641 + while (match && match->user != userp)
48642 + match = match->next;
48643 +
48644 + if (match != NULL)
48645 + return match->kernel;
48646 + else
48647 + return NULL;
48648 +}
48649 +
48650 +static void
48651 +insert_subj_map_entry(struct subject_map *subjmap)
48652 +{
48653 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
48654 + struct subject_map **curr;
48655 +
48656 + subjmap->prev = NULL;
48657 +
48658 + curr = &subj_map_set.s_hash[index];
48659 + if (*curr != NULL)
48660 + (*curr)->prev = subjmap;
48661 +
48662 + subjmap->next = *curr;
48663 + *curr = subjmap;
48664 +
48665 + return;
48666 +}
48667 +
48668 +static struct acl_role_label *
48669 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
48670 + const gid_t gid)
48671 +{
48672 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
48673 + struct acl_role_label *match;
48674 + struct role_allowed_ip *ipp;
48675 + unsigned int x;
48676 + u32 curr_ip = task->signal->curr_ip;
48677 +
48678 + task->signal->saved_ip = curr_ip;
48679 +
48680 + match = acl_role_set.r_hash[index];
48681 +
48682 + while (match) {
48683 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
48684 + for (x = 0; x < match->domain_child_num; x++) {
48685 + if (match->domain_children[x] == uid)
48686 + goto found;
48687 + }
48688 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
48689 + break;
48690 + match = match->next;
48691 + }
48692 +found:
48693 + if (match == NULL) {
48694 + try_group:
48695 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
48696 + match = acl_role_set.r_hash[index];
48697 +
48698 + while (match) {
48699 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
48700 + for (x = 0; x < match->domain_child_num; x++) {
48701 + if (match->domain_children[x] == gid)
48702 + goto found2;
48703 + }
48704 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
48705 + break;
48706 + match = match->next;
48707 + }
48708 +found2:
48709 + if (match == NULL)
48710 + match = default_role;
48711 + if (match->allowed_ips == NULL)
48712 + return match;
48713 + else {
48714 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
48715 + if (likely
48716 + ((ntohl(curr_ip) & ipp->netmask) ==
48717 + (ntohl(ipp->addr) & ipp->netmask)))
48718 + return match;
48719 + }
48720 + match = default_role;
48721 + }
48722 + } else if (match->allowed_ips == NULL) {
48723 + return match;
48724 + } else {
48725 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
48726 + if (likely
48727 + ((ntohl(curr_ip) & ipp->netmask) ==
48728 + (ntohl(ipp->addr) & ipp->netmask)))
48729 + return match;
48730 + }
48731 + goto try_group;
48732 + }
48733 +
48734 + return match;
48735 +}
48736 +
48737 +struct acl_subject_label *
48738 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
48739 + const struct acl_role_label *role)
48740 +{
48741 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
48742 + struct acl_subject_label *match;
48743 +
48744 + match = role->subj_hash[index];
48745 +
48746 + while (match && (match->inode != ino || match->device != dev ||
48747 + (match->mode & GR_DELETED))) {
48748 + match = match->next;
48749 + }
48750 +
48751 + if (match && !(match->mode & GR_DELETED))
48752 + return match;
48753 + else
48754 + return NULL;
48755 +}
48756 +
48757 +struct acl_subject_label *
48758 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
48759 + const struct acl_role_label *role)
48760 +{
48761 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
48762 + struct acl_subject_label *match;
48763 +
48764 + match = role->subj_hash[index];
48765 +
48766 + while (match && (match->inode != ino || match->device != dev ||
48767 + !(match->mode & GR_DELETED))) {
48768 + match = match->next;
48769 + }
48770 +
48771 + if (match && (match->mode & GR_DELETED))
48772 + return match;
48773 + else
48774 + return NULL;
48775 +}
48776 +
48777 +static struct acl_object_label *
48778 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
48779 + const struct acl_subject_label *subj)
48780 +{
48781 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
48782 + struct acl_object_label *match;
48783 +
48784 + match = subj->obj_hash[index];
48785 +
48786 + while (match && (match->inode != ino || match->device != dev ||
48787 + (match->mode & GR_DELETED))) {
48788 + match = match->next;
48789 + }
48790 +
48791 + if (match && !(match->mode & GR_DELETED))
48792 + return match;
48793 + else
48794 + return NULL;
48795 +}
48796 +
48797 +static struct acl_object_label *
48798 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
48799 + const struct acl_subject_label *subj)
48800 +{
48801 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
48802 + struct acl_object_label *match;
48803 +
48804 + match = subj->obj_hash[index];
48805 +
48806 + while (match && (match->inode != ino || match->device != dev ||
48807 + !(match->mode & GR_DELETED))) {
48808 + match = match->next;
48809 + }
48810 +
48811 + if (match && (match->mode & GR_DELETED))
48812 + return match;
48813 +
48814 + match = subj->obj_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 name_entry *
48828 +lookup_name_entry(const char *name)
48829 +{
48830 + unsigned int len = strlen(name);
48831 + unsigned int key = full_name_hash(name, len);
48832 + unsigned int index = key % name_set.n_size;
48833 + struct name_entry *match;
48834 +
48835 + match = name_set.n_hash[index];
48836 +
48837 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
48838 + match = match->next;
48839 +
48840 + return match;
48841 +}
48842 +
48843 +static struct name_entry *
48844 +lookup_name_entry_create(const char *name)
48845 +{
48846 + unsigned int len = strlen(name);
48847 + unsigned int key = full_name_hash(name, len);
48848 + unsigned int index = key % name_set.n_size;
48849 + struct name_entry *match;
48850 +
48851 + match = name_set.n_hash[index];
48852 +
48853 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
48854 + !match->deleted))
48855 + match = match->next;
48856 +
48857 + if (match && match->deleted)
48858 + return match;
48859 +
48860 + match = name_set.n_hash[index];
48861 +
48862 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
48863 + match->deleted))
48864 + match = match->next;
48865 +
48866 + if (match && !match->deleted)
48867 + return match;
48868 + else
48869 + return NULL;
48870 +}
48871 +
48872 +static struct inodev_entry *
48873 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
48874 +{
48875 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
48876 + struct inodev_entry *match;
48877 +
48878 + match = inodev_set.i_hash[index];
48879 +
48880 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
48881 + match = match->next;
48882 +
48883 + return match;
48884 +}
48885 +
48886 +static void
48887 +insert_inodev_entry(struct inodev_entry *entry)
48888 +{
48889 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
48890 + inodev_set.i_size);
48891 + struct inodev_entry **curr;
48892 +
48893 + entry->prev = NULL;
48894 +
48895 + curr = &inodev_set.i_hash[index];
48896 + if (*curr != NULL)
48897 + (*curr)->prev = entry;
48898 +
48899 + entry->next = *curr;
48900 + *curr = entry;
48901 +
48902 + return;
48903 +}
48904 +
48905 +static void
48906 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
48907 +{
48908 + unsigned int index =
48909 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
48910 + struct acl_role_label **curr;
48911 + struct acl_role_label *tmp;
48912 +
48913 + curr = &acl_role_set.r_hash[index];
48914 +
48915 + /* if role was already inserted due to domains and already has
48916 + a role in the same bucket as it attached, then we need to
48917 + combine these two buckets
48918 + */
48919 + if (role->next) {
48920 + tmp = role->next;
48921 + while (tmp->next)
48922 + tmp = tmp->next;
48923 + tmp->next = *curr;
48924 + } else
48925 + role->next = *curr;
48926 + *curr = role;
48927 +
48928 + return;
48929 +}
48930 +
48931 +static void
48932 +insert_acl_role_label(struct acl_role_label *role)
48933 +{
48934 + int i;
48935 +
48936 + if (role_list == NULL) {
48937 + role_list = role;
48938 + role->prev = NULL;
48939 + } else {
48940 + role->prev = role_list;
48941 + role_list = role;
48942 + }
48943 +
48944 + /* used for hash chains */
48945 + role->next = NULL;
48946 +
48947 + if (role->roletype & GR_ROLE_DOMAIN) {
48948 + for (i = 0; i < role->domain_child_num; i++)
48949 + __insert_acl_role_label(role, role->domain_children[i]);
48950 + } else
48951 + __insert_acl_role_label(role, role->uidgid);
48952 +}
48953 +
48954 +static int
48955 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
48956 +{
48957 + struct name_entry **curr, *nentry;
48958 + struct inodev_entry *ientry;
48959 + unsigned int len = strlen(name);
48960 + unsigned int key = full_name_hash(name, len);
48961 + unsigned int index = key % name_set.n_size;
48962 +
48963 + curr = &name_set.n_hash[index];
48964 +
48965 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
48966 + curr = &((*curr)->next);
48967 +
48968 + if (*curr != NULL)
48969 + return 1;
48970 +
48971 + nentry = acl_alloc(sizeof (struct name_entry));
48972 + if (nentry == NULL)
48973 + return 0;
48974 + ientry = acl_alloc(sizeof (struct inodev_entry));
48975 + if (ientry == NULL)
48976 + return 0;
48977 + ientry->nentry = nentry;
48978 +
48979 + nentry->key = key;
48980 + nentry->name = name;
48981 + nentry->inode = inode;
48982 + nentry->device = device;
48983 + nentry->len = len;
48984 + nentry->deleted = deleted;
48985 +
48986 + nentry->prev = NULL;
48987 + curr = &name_set.n_hash[index];
48988 + if (*curr != NULL)
48989 + (*curr)->prev = nentry;
48990 + nentry->next = *curr;
48991 + *curr = nentry;
48992 +
48993 + /* insert us into the table searchable by inode/dev */
48994 + insert_inodev_entry(ientry);
48995 +
48996 + return 1;
48997 +}
48998 +
48999 +static void
49000 +insert_acl_obj_label(struct acl_object_label *obj,
49001 + struct acl_subject_label *subj)
49002 +{
49003 + unsigned int index =
49004 + fhash(obj->inode, obj->device, subj->obj_hash_size);
49005 + struct acl_object_label **curr;
49006 +
49007 +
49008 + obj->prev = NULL;
49009 +
49010 + curr = &subj->obj_hash[index];
49011 + if (*curr != NULL)
49012 + (*curr)->prev = obj;
49013 +
49014 + obj->next = *curr;
49015 + *curr = obj;
49016 +
49017 + return;
49018 +}
49019 +
49020 +static void
49021 +insert_acl_subj_label(struct acl_subject_label *obj,
49022 + struct acl_role_label *role)
49023 +{
49024 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
49025 + struct acl_subject_label **curr;
49026 +
49027 + obj->prev = NULL;
49028 +
49029 + curr = &role->subj_hash[index];
49030 + if (*curr != NULL)
49031 + (*curr)->prev = obj;
49032 +
49033 + obj->next = *curr;
49034 + *curr = obj;
49035 +
49036 + return;
49037 +}
49038 +
49039 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
49040 +
49041 +static void *
49042 +create_table(__u32 * len, int elementsize)
49043 +{
49044 + unsigned int table_sizes[] = {
49045 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
49046 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
49047 + 4194301, 8388593, 16777213, 33554393, 67108859
49048 + };
49049 + void *newtable = NULL;
49050 + unsigned int pwr = 0;
49051 +
49052 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
49053 + table_sizes[pwr] <= *len)
49054 + pwr++;
49055 +
49056 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
49057 + return newtable;
49058 +
49059 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
49060 + newtable =
49061 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
49062 + else
49063 + newtable = vmalloc(table_sizes[pwr] * elementsize);
49064 +
49065 + *len = table_sizes[pwr];
49066 +
49067 + return newtable;
49068 +}
49069 +
49070 +static int
49071 +init_variables(const struct gr_arg *arg)
49072 +{
49073 + struct task_struct *reaper = &init_task;
49074 + unsigned int stacksize;
49075 +
49076 + subj_map_set.s_size = arg->role_db.num_subjects;
49077 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
49078 + name_set.n_size = arg->role_db.num_objects;
49079 + inodev_set.i_size = arg->role_db.num_objects;
49080 +
49081 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
49082 + !name_set.n_size || !inodev_set.i_size)
49083 + return 1;
49084 +
49085 + if (!gr_init_uidset())
49086 + return 1;
49087 +
49088 + /* set up the stack that holds allocation info */
49089 +
49090 + stacksize = arg->role_db.num_pointers + 5;
49091 +
49092 + if (!acl_alloc_stack_init(stacksize))
49093 + return 1;
49094 +
49095 + /* grab reference for the real root dentry and vfsmount */
49096 + get_fs_root(reaper->fs, &real_root);
49097 +
49098 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49099 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
49100 +#endif
49101 +
49102 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
49103 + if (fakefs_obj_rw == NULL)
49104 + return 1;
49105 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
49106 +
49107 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
49108 + if (fakefs_obj_rwx == NULL)
49109 + return 1;
49110 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
49111 +
49112 + subj_map_set.s_hash =
49113 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
49114 + acl_role_set.r_hash =
49115 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
49116 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
49117 + inodev_set.i_hash =
49118 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
49119 +
49120 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
49121 + !name_set.n_hash || !inodev_set.i_hash)
49122 + return 1;
49123 +
49124 + memset(subj_map_set.s_hash, 0,
49125 + sizeof(struct subject_map *) * subj_map_set.s_size);
49126 + memset(acl_role_set.r_hash, 0,
49127 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
49128 + memset(name_set.n_hash, 0,
49129 + sizeof (struct name_entry *) * name_set.n_size);
49130 + memset(inodev_set.i_hash, 0,
49131 + sizeof (struct inodev_entry *) * inodev_set.i_size);
49132 +
49133 + return 0;
49134 +}
49135 +
49136 +/* free information not needed after startup
49137 + currently contains user->kernel pointer mappings for subjects
49138 +*/
49139 +
49140 +static void
49141 +free_init_variables(void)
49142 +{
49143 + __u32 i;
49144 +
49145 + if (subj_map_set.s_hash) {
49146 + for (i = 0; i < subj_map_set.s_size; i++) {
49147 + if (subj_map_set.s_hash[i]) {
49148 + kfree(subj_map_set.s_hash[i]);
49149 + subj_map_set.s_hash[i] = NULL;
49150 + }
49151 + }
49152 +
49153 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
49154 + PAGE_SIZE)
49155 + kfree(subj_map_set.s_hash);
49156 + else
49157 + vfree(subj_map_set.s_hash);
49158 + }
49159 +
49160 + return;
49161 +}
49162 +
49163 +static void
49164 +free_variables(void)
49165 +{
49166 + struct acl_subject_label *s;
49167 + struct acl_role_label *r;
49168 + struct task_struct *task, *task2;
49169 + unsigned int x;
49170 +
49171 + gr_clear_learn_entries();
49172 +
49173 + read_lock(&tasklist_lock);
49174 + do_each_thread(task2, task) {
49175 + task->acl_sp_role = 0;
49176 + task->acl_role_id = 0;
49177 + task->acl = NULL;
49178 + task->role = NULL;
49179 + } while_each_thread(task2, task);
49180 + read_unlock(&tasklist_lock);
49181 +
49182 + /* release the reference to the real root dentry and vfsmount */
49183 + path_put(&real_root);
49184 +
49185 + /* free all object hash tables */
49186 +
49187 + FOR_EACH_ROLE_START(r)
49188 + if (r->subj_hash == NULL)
49189 + goto next_role;
49190 + FOR_EACH_SUBJECT_START(r, s, x)
49191 + if (s->obj_hash == NULL)
49192 + break;
49193 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
49194 + kfree(s->obj_hash);
49195 + else
49196 + vfree(s->obj_hash);
49197 + FOR_EACH_SUBJECT_END(s, x)
49198 + FOR_EACH_NESTED_SUBJECT_START(r, s)
49199 + if (s->obj_hash == NULL)
49200 + break;
49201 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
49202 + kfree(s->obj_hash);
49203 + else
49204 + vfree(s->obj_hash);
49205 + FOR_EACH_NESTED_SUBJECT_END(s)
49206 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
49207 + kfree(r->subj_hash);
49208 + else
49209 + vfree(r->subj_hash);
49210 + r->subj_hash = NULL;
49211 +next_role:
49212 + FOR_EACH_ROLE_END(r)
49213 +
49214 + acl_free_all();
49215 +
49216 + if (acl_role_set.r_hash) {
49217 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
49218 + PAGE_SIZE)
49219 + kfree(acl_role_set.r_hash);
49220 + else
49221 + vfree(acl_role_set.r_hash);
49222 + }
49223 + if (name_set.n_hash) {
49224 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
49225 + PAGE_SIZE)
49226 + kfree(name_set.n_hash);
49227 + else
49228 + vfree(name_set.n_hash);
49229 + }
49230 +
49231 + if (inodev_set.i_hash) {
49232 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
49233 + PAGE_SIZE)
49234 + kfree(inodev_set.i_hash);
49235 + else
49236 + vfree(inodev_set.i_hash);
49237 + }
49238 +
49239 + gr_free_uidset();
49240 +
49241 + memset(&name_set, 0, sizeof (struct name_db));
49242 + memset(&inodev_set, 0, sizeof (struct inodev_db));
49243 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
49244 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
49245 +
49246 + default_role = NULL;
49247 + role_list = NULL;
49248 +
49249 + return;
49250 +}
49251 +
49252 +static __u32
49253 +count_user_objs(struct acl_object_label *userp)
49254 +{
49255 + struct acl_object_label o_tmp;
49256 + __u32 num = 0;
49257 +
49258 + while (userp) {
49259 + if (copy_from_user(&o_tmp, userp,
49260 + sizeof (struct acl_object_label)))
49261 + break;
49262 +
49263 + userp = o_tmp.prev;
49264 + num++;
49265 + }
49266 +
49267 + return num;
49268 +}
49269 +
49270 +static struct acl_subject_label *
49271 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
49272 +
49273 +static int
49274 +copy_user_glob(struct acl_object_label *obj)
49275 +{
49276 + struct acl_object_label *g_tmp, **guser;
49277 + unsigned int len;
49278 + char *tmp;
49279 +
49280 + if (obj->globbed == NULL)
49281 + return 0;
49282 +
49283 + guser = &obj->globbed;
49284 + while (*guser) {
49285 + g_tmp = (struct acl_object_label *)
49286 + acl_alloc(sizeof (struct acl_object_label));
49287 + if (g_tmp == NULL)
49288 + return -ENOMEM;
49289 +
49290 + if (copy_from_user(g_tmp, *guser,
49291 + sizeof (struct acl_object_label)))
49292 + return -EFAULT;
49293 +
49294 + len = strnlen_user(g_tmp->filename, PATH_MAX);
49295 +
49296 + if (!len || len >= PATH_MAX)
49297 + return -EINVAL;
49298 +
49299 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49300 + return -ENOMEM;
49301 +
49302 + if (copy_from_user(tmp, g_tmp->filename, len))
49303 + return -EFAULT;
49304 + tmp[len-1] = '\0';
49305 + g_tmp->filename = tmp;
49306 +
49307 + *guser = g_tmp;
49308 + guser = &(g_tmp->next);
49309 + }
49310 +
49311 + return 0;
49312 +}
49313 +
49314 +static int
49315 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
49316 + struct acl_role_label *role)
49317 +{
49318 + struct acl_object_label *o_tmp;
49319 + unsigned int len;
49320 + int ret;
49321 + char *tmp;
49322 +
49323 + while (userp) {
49324 + if ((o_tmp = (struct acl_object_label *)
49325 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
49326 + return -ENOMEM;
49327 +
49328 + if (copy_from_user(o_tmp, userp,
49329 + sizeof (struct acl_object_label)))
49330 + return -EFAULT;
49331 +
49332 + userp = o_tmp->prev;
49333 +
49334 + len = strnlen_user(o_tmp->filename, PATH_MAX);
49335 +
49336 + if (!len || len >= PATH_MAX)
49337 + return -EINVAL;
49338 +
49339 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49340 + return -ENOMEM;
49341 +
49342 + if (copy_from_user(tmp, o_tmp->filename, len))
49343 + return -EFAULT;
49344 + tmp[len-1] = '\0';
49345 + o_tmp->filename = tmp;
49346 +
49347 + insert_acl_obj_label(o_tmp, subj);
49348 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
49349 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
49350 + return -ENOMEM;
49351 +
49352 + ret = copy_user_glob(o_tmp);
49353 + if (ret)
49354 + return ret;
49355 +
49356 + if (o_tmp->nested) {
49357 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
49358 + if (IS_ERR(o_tmp->nested))
49359 + return PTR_ERR(o_tmp->nested);
49360 +
49361 + /* insert into nested subject list */
49362 + o_tmp->nested->next = role->hash->first;
49363 + role->hash->first = o_tmp->nested;
49364 + }
49365 + }
49366 +
49367 + return 0;
49368 +}
49369 +
49370 +static __u32
49371 +count_user_subjs(struct acl_subject_label *userp)
49372 +{
49373 + struct acl_subject_label s_tmp;
49374 + __u32 num = 0;
49375 +
49376 + while (userp) {
49377 + if (copy_from_user(&s_tmp, userp,
49378 + sizeof (struct acl_subject_label)))
49379 + break;
49380 +
49381 + userp = s_tmp.prev;
49382 + /* do not count nested subjects against this count, since
49383 + they are not included in the hash table, but are
49384 + attached to objects. We have already counted
49385 + the subjects in userspace for the allocation
49386 + stack
49387 + */
49388 + if (!(s_tmp.mode & GR_NESTED))
49389 + num++;
49390 + }
49391 +
49392 + return num;
49393 +}
49394 +
49395 +static int
49396 +copy_user_allowedips(struct acl_role_label *rolep)
49397 +{
49398 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
49399 +
49400 + ruserip = rolep->allowed_ips;
49401 +
49402 + while (ruserip) {
49403 + rlast = rtmp;
49404 +
49405 + if ((rtmp = (struct role_allowed_ip *)
49406 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
49407 + return -ENOMEM;
49408 +
49409 + if (copy_from_user(rtmp, ruserip,
49410 + sizeof (struct role_allowed_ip)))
49411 + return -EFAULT;
49412 +
49413 + ruserip = rtmp->prev;
49414 +
49415 + if (!rlast) {
49416 + rtmp->prev = NULL;
49417 + rolep->allowed_ips = rtmp;
49418 + } else {
49419 + rlast->next = rtmp;
49420 + rtmp->prev = rlast;
49421 + }
49422 +
49423 + if (!ruserip)
49424 + rtmp->next = NULL;
49425 + }
49426 +
49427 + return 0;
49428 +}
49429 +
49430 +static int
49431 +copy_user_transitions(struct acl_role_label *rolep)
49432 +{
49433 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
49434 +
49435 + unsigned int len;
49436 + char *tmp;
49437 +
49438 + rusertp = rolep->transitions;
49439 +
49440 + while (rusertp) {
49441 + rlast = rtmp;
49442 +
49443 + if ((rtmp = (struct role_transition *)
49444 + acl_alloc(sizeof (struct role_transition))) == NULL)
49445 + return -ENOMEM;
49446 +
49447 + if (copy_from_user(rtmp, rusertp,
49448 + sizeof (struct role_transition)))
49449 + return -EFAULT;
49450 +
49451 + rusertp = rtmp->prev;
49452 +
49453 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
49454 +
49455 + if (!len || len >= GR_SPROLE_LEN)
49456 + return -EINVAL;
49457 +
49458 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49459 + return -ENOMEM;
49460 +
49461 + if (copy_from_user(tmp, rtmp->rolename, len))
49462 + return -EFAULT;
49463 + tmp[len-1] = '\0';
49464 + rtmp->rolename = tmp;
49465 +
49466 + if (!rlast) {
49467 + rtmp->prev = NULL;
49468 + rolep->transitions = rtmp;
49469 + } else {
49470 + rlast->next = rtmp;
49471 + rtmp->prev = rlast;
49472 + }
49473 +
49474 + if (!rusertp)
49475 + rtmp->next = NULL;
49476 + }
49477 +
49478 + return 0;
49479 +}
49480 +
49481 +static struct acl_subject_label *
49482 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
49483 +{
49484 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
49485 + unsigned int len;
49486 + char *tmp;
49487 + __u32 num_objs;
49488 + struct acl_ip_label **i_tmp, *i_utmp2;
49489 + struct gr_hash_struct ghash;
49490 + struct subject_map *subjmap;
49491 + unsigned int i_num;
49492 + int err;
49493 +
49494 + s_tmp = lookup_subject_map(userp);
49495 +
49496 + /* we've already copied this subject into the kernel, just return
49497 + the reference to it, and don't copy it over again
49498 + */
49499 + if (s_tmp)
49500 + return(s_tmp);
49501 +
49502 + if ((s_tmp = (struct acl_subject_label *)
49503 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
49504 + return ERR_PTR(-ENOMEM);
49505 +
49506 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
49507 + if (subjmap == NULL)
49508 + return ERR_PTR(-ENOMEM);
49509 +
49510 + subjmap->user = userp;
49511 + subjmap->kernel = s_tmp;
49512 + insert_subj_map_entry(subjmap);
49513 +
49514 + if (copy_from_user(s_tmp, userp,
49515 + sizeof (struct acl_subject_label)))
49516 + return ERR_PTR(-EFAULT);
49517 +
49518 + len = strnlen_user(s_tmp->filename, PATH_MAX);
49519 +
49520 + if (!len || len >= PATH_MAX)
49521 + return ERR_PTR(-EINVAL);
49522 +
49523 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49524 + return ERR_PTR(-ENOMEM);
49525 +
49526 + if (copy_from_user(tmp, s_tmp->filename, len))
49527 + return ERR_PTR(-EFAULT);
49528 + tmp[len-1] = '\0';
49529 + s_tmp->filename = tmp;
49530 +
49531 + if (!strcmp(s_tmp->filename, "/"))
49532 + role->root_label = s_tmp;
49533 +
49534 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
49535 + return ERR_PTR(-EFAULT);
49536 +
49537 + /* copy user and group transition tables */
49538 +
49539 + if (s_tmp->user_trans_num) {
49540 + uid_t *uidlist;
49541 +
49542 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
49543 + if (uidlist == NULL)
49544 + return ERR_PTR(-ENOMEM);
49545 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
49546 + return ERR_PTR(-EFAULT);
49547 +
49548 + s_tmp->user_transitions = uidlist;
49549 + }
49550 +
49551 + if (s_tmp->group_trans_num) {
49552 + gid_t *gidlist;
49553 +
49554 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
49555 + if (gidlist == NULL)
49556 + return ERR_PTR(-ENOMEM);
49557 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
49558 + return ERR_PTR(-EFAULT);
49559 +
49560 + s_tmp->group_transitions = gidlist;
49561 + }
49562 +
49563 + /* set up object hash table */
49564 + num_objs = count_user_objs(ghash.first);
49565 +
49566 + s_tmp->obj_hash_size = num_objs;
49567 + s_tmp->obj_hash =
49568 + (struct acl_object_label **)
49569 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
49570 +
49571 + if (!s_tmp->obj_hash)
49572 + return ERR_PTR(-ENOMEM);
49573 +
49574 + memset(s_tmp->obj_hash, 0,
49575 + s_tmp->obj_hash_size *
49576 + sizeof (struct acl_object_label *));
49577 +
49578 + /* add in objects */
49579 + err = copy_user_objs(ghash.first, s_tmp, role);
49580 +
49581 + if (err)
49582 + return ERR_PTR(err);
49583 +
49584 + /* set pointer for parent subject */
49585 + if (s_tmp->parent_subject) {
49586 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
49587 +
49588 + if (IS_ERR(s_tmp2))
49589 + return s_tmp2;
49590 +
49591 + s_tmp->parent_subject = s_tmp2;
49592 + }
49593 +
49594 + /* add in ip acls */
49595 +
49596 + if (!s_tmp->ip_num) {
49597 + s_tmp->ips = NULL;
49598 + goto insert;
49599 + }
49600 +
49601 + i_tmp =
49602 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
49603 + sizeof (struct acl_ip_label *));
49604 +
49605 + if (!i_tmp)
49606 + return ERR_PTR(-ENOMEM);
49607 +
49608 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
49609 + *(i_tmp + i_num) =
49610 + (struct acl_ip_label *)
49611 + acl_alloc(sizeof (struct acl_ip_label));
49612 + if (!*(i_tmp + i_num))
49613 + return ERR_PTR(-ENOMEM);
49614 +
49615 + if (copy_from_user
49616 + (&i_utmp2, s_tmp->ips + i_num,
49617 + sizeof (struct acl_ip_label *)))
49618 + return ERR_PTR(-EFAULT);
49619 +
49620 + if (copy_from_user
49621 + (*(i_tmp + i_num), i_utmp2,
49622 + sizeof (struct acl_ip_label)))
49623 + return ERR_PTR(-EFAULT);
49624 +
49625 + if ((*(i_tmp + i_num))->iface == NULL)
49626 + continue;
49627 +
49628 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
49629 + if (!len || len >= IFNAMSIZ)
49630 + return ERR_PTR(-EINVAL);
49631 + tmp = acl_alloc(len);
49632 + if (tmp == NULL)
49633 + return ERR_PTR(-ENOMEM);
49634 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
49635 + return ERR_PTR(-EFAULT);
49636 + (*(i_tmp + i_num))->iface = tmp;
49637 + }
49638 +
49639 + s_tmp->ips = i_tmp;
49640 +
49641 +insert:
49642 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
49643 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
49644 + return ERR_PTR(-ENOMEM);
49645 +
49646 + return s_tmp;
49647 +}
49648 +
49649 +static int
49650 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
49651 +{
49652 + struct acl_subject_label s_pre;
49653 + struct acl_subject_label * ret;
49654 + int err;
49655 +
49656 + while (userp) {
49657 + if (copy_from_user(&s_pre, userp,
49658 + sizeof (struct acl_subject_label)))
49659 + return -EFAULT;
49660 +
49661 + /* do not add nested subjects here, add
49662 + while parsing objects
49663 + */
49664 +
49665 + if (s_pre.mode & GR_NESTED) {
49666 + userp = s_pre.prev;
49667 + continue;
49668 + }
49669 +
49670 + ret = do_copy_user_subj(userp, role);
49671 +
49672 + err = PTR_ERR(ret);
49673 + if (IS_ERR(ret))
49674 + return err;
49675 +
49676 + insert_acl_subj_label(ret, role);
49677 +
49678 + userp = s_pre.prev;
49679 + }
49680 +
49681 + return 0;
49682 +}
49683 +
49684 +static int
49685 +copy_user_acl(struct gr_arg *arg)
49686 +{
49687 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
49688 + struct sprole_pw *sptmp;
49689 + struct gr_hash_struct *ghash;
49690 + uid_t *domainlist;
49691 + unsigned int r_num;
49692 + unsigned int len;
49693 + char *tmp;
49694 + int err = 0;
49695 + __u16 i;
49696 + __u32 num_subjs;
49697 +
49698 + /* we need a default and kernel role */
49699 + if (arg->role_db.num_roles < 2)
49700 + return -EINVAL;
49701 +
49702 + /* copy special role authentication info from userspace */
49703 +
49704 + num_sprole_pws = arg->num_sprole_pws;
49705 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
49706 +
49707 + if (!acl_special_roles) {
49708 + err = -ENOMEM;
49709 + goto cleanup;
49710 + }
49711 +
49712 + for (i = 0; i < num_sprole_pws; i++) {
49713 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
49714 + if (!sptmp) {
49715 + err = -ENOMEM;
49716 + goto cleanup;
49717 + }
49718 + if (copy_from_user(sptmp, arg->sprole_pws + i,
49719 + sizeof (struct sprole_pw))) {
49720 + err = -EFAULT;
49721 + goto cleanup;
49722 + }
49723 +
49724 + len =
49725 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
49726 +
49727 + if (!len || len >= GR_SPROLE_LEN) {
49728 + err = -EINVAL;
49729 + goto cleanup;
49730 + }
49731 +
49732 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
49733 + err = -ENOMEM;
49734 + goto cleanup;
49735 + }
49736 +
49737 + if (copy_from_user(tmp, sptmp->rolename, len)) {
49738 + err = -EFAULT;
49739 + goto cleanup;
49740 + }
49741 + tmp[len-1] = '\0';
49742 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49743 + printk(KERN_ALERT "Copying special role %s\n", tmp);
49744 +#endif
49745 + sptmp->rolename = tmp;
49746 + acl_special_roles[i] = sptmp;
49747 + }
49748 +
49749 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
49750 +
49751 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
49752 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
49753 +
49754 + if (!r_tmp) {
49755 + err = -ENOMEM;
49756 + goto cleanup;
49757 + }
49758 +
49759 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
49760 + sizeof (struct acl_role_label *))) {
49761 + err = -EFAULT;
49762 + goto cleanup;
49763 + }
49764 +
49765 + if (copy_from_user(r_tmp, r_utmp2,
49766 + sizeof (struct acl_role_label))) {
49767 + err = -EFAULT;
49768 + goto cleanup;
49769 + }
49770 +
49771 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
49772 +
49773 + if (!len || len >= PATH_MAX) {
49774 + err = -EINVAL;
49775 + goto cleanup;
49776 + }
49777 +
49778 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
49779 + err = -ENOMEM;
49780 + goto cleanup;
49781 + }
49782 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
49783 + err = -EFAULT;
49784 + goto cleanup;
49785 + }
49786 + tmp[len-1] = '\0';
49787 + r_tmp->rolename = tmp;
49788 +
49789 + if (!strcmp(r_tmp->rolename, "default")
49790 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
49791 + default_role = r_tmp;
49792 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
49793 + kernel_role = r_tmp;
49794 + }
49795 +
49796 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
49797 + err = -ENOMEM;
49798 + goto cleanup;
49799 + }
49800 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
49801 + err = -EFAULT;
49802 + goto cleanup;
49803 + }
49804 +
49805 + r_tmp->hash = ghash;
49806 +
49807 + num_subjs = count_user_subjs(r_tmp->hash->first);
49808 +
49809 + r_tmp->subj_hash_size = num_subjs;
49810 + r_tmp->subj_hash =
49811 + (struct acl_subject_label **)
49812 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
49813 +
49814 + if (!r_tmp->subj_hash) {
49815 + err = -ENOMEM;
49816 + goto cleanup;
49817 + }
49818 +
49819 + err = copy_user_allowedips(r_tmp);
49820 + if (err)
49821 + goto cleanup;
49822 +
49823 + /* copy domain info */
49824 + if (r_tmp->domain_children != NULL) {
49825 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
49826 + if (domainlist == NULL) {
49827 + err = -ENOMEM;
49828 + goto cleanup;
49829 + }
49830 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
49831 + err = -EFAULT;
49832 + goto cleanup;
49833 + }
49834 + r_tmp->domain_children = domainlist;
49835 + }
49836 +
49837 + err = copy_user_transitions(r_tmp);
49838 + if (err)
49839 + goto cleanup;
49840 +
49841 + memset(r_tmp->subj_hash, 0,
49842 + r_tmp->subj_hash_size *
49843 + sizeof (struct acl_subject_label *));
49844 +
49845 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
49846 +
49847 + if (err)
49848 + goto cleanup;
49849 +
49850 + /* set nested subject list to null */
49851 + r_tmp->hash->first = NULL;
49852 +
49853 + insert_acl_role_label(r_tmp);
49854 + }
49855 +
49856 + goto return_err;
49857 + cleanup:
49858 + free_variables();
49859 + return_err:
49860 + return err;
49861 +
49862 +}
49863 +
49864 +static int
49865 +gracl_init(struct gr_arg *args)
49866 +{
49867 + int error = 0;
49868 +
49869 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
49870 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
49871 +
49872 + if (init_variables(args)) {
49873 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
49874 + error = -ENOMEM;
49875 + free_variables();
49876 + goto out;
49877 + }
49878 +
49879 + error = copy_user_acl(args);
49880 + free_init_variables();
49881 + if (error) {
49882 + free_variables();
49883 + goto out;
49884 + }
49885 +
49886 + if ((error = gr_set_acls(0))) {
49887 + free_variables();
49888 + goto out;
49889 + }
49890 +
49891 + pax_open_kernel();
49892 + gr_status |= GR_READY;
49893 + pax_close_kernel();
49894 +
49895 + out:
49896 + return error;
49897 +}
49898 +
49899 +/* derived from glibc fnmatch() 0: match, 1: no match*/
49900 +
49901 +static int
49902 +glob_match(const char *p, const char *n)
49903 +{
49904 + char c;
49905 +
49906 + while ((c = *p++) != '\0') {
49907 + switch (c) {
49908 + case '?':
49909 + if (*n == '\0')
49910 + return 1;
49911 + else if (*n == '/')
49912 + return 1;
49913 + break;
49914 + case '\\':
49915 + if (*n != c)
49916 + return 1;
49917 + break;
49918 + case '*':
49919 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
49920 + if (*n == '/')
49921 + return 1;
49922 + else if (c == '?') {
49923 + if (*n == '\0')
49924 + return 1;
49925 + else
49926 + ++n;
49927 + }
49928 + }
49929 + if (c == '\0') {
49930 + return 0;
49931 + } else {
49932 + const char *endp;
49933 +
49934 + if ((endp = strchr(n, '/')) == NULL)
49935 + endp = n + strlen(n);
49936 +
49937 + if (c == '[') {
49938 + for (--p; n < endp; ++n)
49939 + if (!glob_match(p, n))
49940 + return 0;
49941 + } else if (c == '/') {
49942 + while (*n != '\0' && *n != '/')
49943 + ++n;
49944 + if (*n == '/' && !glob_match(p, n + 1))
49945 + return 0;
49946 + } else {
49947 + for (--p; n < endp; ++n)
49948 + if (*n == c && !glob_match(p, n))
49949 + return 0;
49950 + }
49951 +
49952 + return 1;
49953 + }
49954 + case '[':
49955 + {
49956 + int not;
49957 + char cold;
49958 +
49959 + if (*n == '\0' || *n == '/')
49960 + return 1;
49961 +
49962 + not = (*p == '!' || *p == '^');
49963 + if (not)
49964 + ++p;
49965 +
49966 + c = *p++;
49967 + for (;;) {
49968 + unsigned char fn = (unsigned char)*n;
49969 +
49970 + if (c == '\0')
49971 + return 1;
49972 + else {
49973 + if (c == fn)
49974 + goto matched;
49975 + cold = c;
49976 + c = *p++;
49977 +
49978 + if (c == '-' && *p != ']') {
49979 + unsigned char cend = *p++;
49980 +
49981 + if (cend == '\0')
49982 + return 1;
49983 +
49984 + if (cold <= fn && fn <= cend)
49985 + goto matched;
49986 +
49987 + c = *p++;
49988 + }
49989 + }
49990 +
49991 + if (c == ']')
49992 + break;
49993 + }
49994 + if (!not)
49995 + return 1;
49996 + break;
49997 + matched:
49998 + while (c != ']') {
49999 + if (c == '\0')
50000 + return 1;
50001 +
50002 + c = *p++;
50003 + }
50004 + if (not)
50005 + return 1;
50006 + }
50007 + break;
50008 + default:
50009 + if (c != *n)
50010 + return 1;
50011 + }
50012 +
50013 + ++n;
50014 + }
50015 +
50016 + if (*n == '\0')
50017 + return 0;
50018 +
50019 + if (*n == '/')
50020 + return 0;
50021 +
50022 + return 1;
50023 +}
50024 +
50025 +static struct acl_object_label *
50026 +chk_glob_label(struct acl_object_label *globbed,
50027 + struct dentry *dentry, struct vfsmount *mnt, char **path)
50028 +{
50029 + struct acl_object_label *tmp;
50030 +
50031 + if (*path == NULL)
50032 + *path = gr_to_filename_nolock(dentry, mnt);
50033 +
50034 + tmp = globbed;
50035 +
50036 + while (tmp) {
50037 + if (!glob_match(tmp->filename, *path))
50038 + return tmp;
50039 + tmp = tmp->next;
50040 + }
50041 +
50042 + return NULL;
50043 +}
50044 +
50045 +static struct acl_object_label *
50046 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
50047 + const ino_t curr_ino, const dev_t curr_dev,
50048 + const struct acl_subject_label *subj, char **path, const int checkglob)
50049 +{
50050 + struct acl_subject_label *tmpsubj;
50051 + struct acl_object_label *retval;
50052 + struct acl_object_label *retval2;
50053 +
50054 + tmpsubj = (struct acl_subject_label *) subj;
50055 + read_lock(&gr_inode_lock);
50056 + do {
50057 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
50058 + if (retval) {
50059 + if (checkglob && retval->globbed) {
50060 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
50061 + (struct vfsmount *)orig_mnt, path);
50062 + if (retval2)
50063 + retval = retval2;
50064 + }
50065 + break;
50066 + }
50067 + } while ((tmpsubj = tmpsubj->parent_subject));
50068 + read_unlock(&gr_inode_lock);
50069 +
50070 + return retval;
50071 +}
50072 +
50073 +static __inline__ struct acl_object_label *
50074 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
50075 + struct dentry *curr_dentry,
50076 + const struct acl_subject_label *subj, char **path, const int checkglob)
50077 +{
50078 + int newglob = checkglob;
50079 + ino_t inode;
50080 + dev_t device;
50081 +
50082 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
50083 + as we don't want a / * rule to match instead of the / object
50084 + don't do this for create lookups that call this function though, since they're looking up
50085 + on the parent and thus need globbing checks on all paths
50086 + */
50087 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
50088 + newglob = GR_NO_GLOB;
50089 +
50090 + spin_lock(&curr_dentry->d_lock);
50091 + inode = curr_dentry->d_inode->i_ino;
50092 + device = __get_dev(curr_dentry);
50093 + spin_unlock(&curr_dentry->d_lock);
50094 +
50095 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
50096 +}
50097 +
50098 +static struct acl_object_label *
50099 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50100 + const struct acl_subject_label *subj, char *path, const int checkglob)
50101 +{
50102 + struct dentry *dentry = (struct dentry *) l_dentry;
50103 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
50104 + struct acl_object_label *retval;
50105 + struct dentry *parent;
50106 +
50107 + write_seqlock(&rename_lock);
50108 + br_read_lock(vfsmount_lock);
50109 +
50110 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
50111 +#ifdef CONFIG_NET
50112 + mnt == sock_mnt ||
50113 +#endif
50114 +#ifdef CONFIG_HUGETLBFS
50115 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
50116 +#endif
50117 + /* ignore Eric Biederman */
50118 + IS_PRIVATE(l_dentry->d_inode))) {
50119 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
50120 + goto out;
50121 + }
50122 +
50123 + for (;;) {
50124 + if (dentry == real_root.dentry && mnt == real_root.mnt)
50125 + break;
50126 +
50127 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
50128 + if (mnt->mnt_parent == mnt)
50129 + break;
50130 +
50131 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50132 + if (retval != NULL)
50133 + goto out;
50134 +
50135 + dentry = mnt->mnt_mountpoint;
50136 + mnt = mnt->mnt_parent;
50137 + continue;
50138 + }
50139 +
50140 + parent = dentry->d_parent;
50141 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50142 + if (retval != NULL)
50143 + goto out;
50144 +
50145 + dentry = parent;
50146 + }
50147 +
50148 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50149 +
50150 + /* real_root is pinned so we don't have to hold a reference */
50151 + if (retval == NULL)
50152 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
50153 +out:
50154 + br_read_unlock(vfsmount_lock);
50155 + write_sequnlock(&rename_lock);
50156 +
50157 + BUG_ON(retval == NULL);
50158 +
50159 + return retval;
50160 +}
50161 +
50162 +static __inline__ struct acl_object_label *
50163 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50164 + const struct acl_subject_label *subj)
50165 +{
50166 + char *path = NULL;
50167 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
50168 +}
50169 +
50170 +static __inline__ struct acl_object_label *
50171 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50172 + const struct acl_subject_label *subj)
50173 +{
50174 + char *path = NULL;
50175 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
50176 +}
50177 +
50178 +static __inline__ struct acl_object_label *
50179 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50180 + const struct acl_subject_label *subj, char *path)
50181 +{
50182 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
50183 +}
50184 +
50185 +static struct acl_subject_label *
50186 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50187 + const struct acl_role_label *role)
50188 +{
50189 + struct dentry *dentry = (struct dentry *) l_dentry;
50190 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
50191 + struct acl_subject_label *retval;
50192 + struct dentry *parent;
50193 +
50194 + write_seqlock(&rename_lock);
50195 + br_read_lock(vfsmount_lock);
50196 +
50197 + for (;;) {
50198 + if (dentry == real_root.dentry && mnt == real_root.mnt)
50199 + break;
50200 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
50201 + if (mnt->mnt_parent == mnt)
50202 + break;
50203 +
50204 + spin_lock(&dentry->d_lock);
50205 + read_lock(&gr_inode_lock);
50206 + retval =
50207 + lookup_acl_subj_label(dentry->d_inode->i_ino,
50208 + __get_dev(dentry), role);
50209 + read_unlock(&gr_inode_lock);
50210 + spin_unlock(&dentry->d_lock);
50211 + if (retval != NULL)
50212 + goto out;
50213 +
50214 + dentry = mnt->mnt_mountpoint;
50215 + mnt = mnt->mnt_parent;
50216 + continue;
50217 + }
50218 +
50219 + spin_lock(&dentry->d_lock);
50220 + read_lock(&gr_inode_lock);
50221 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
50222 + __get_dev(dentry), role);
50223 + read_unlock(&gr_inode_lock);
50224 + parent = dentry->d_parent;
50225 + spin_unlock(&dentry->d_lock);
50226 +
50227 + if (retval != NULL)
50228 + goto out;
50229 +
50230 + dentry = parent;
50231 + }
50232 +
50233 + spin_lock(&dentry->d_lock);
50234 + read_lock(&gr_inode_lock);
50235 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
50236 + __get_dev(dentry), role);
50237 + read_unlock(&gr_inode_lock);
50238 + spin_unlock(&dentry->d_lock);
50239 +
50240 + if (unlikely(retval == NULL)) {
50241 + /* real_root is pinned, we don't need to hold a reference */
50242 + read_lock(&gr_inode_lock);
50243 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
50244 + __get_dev(real_root.dentry), role);
50245 + read_unlock(&gr_inode_lock);
50246 + }
50247 +out:
50248 + br_read_unlock(vfsmount_lock);
50249 + write_sequnlock(&rename_lock);
50250 +
50251 + BUG_ON(retval == NULL);
50252 +
50253 + return retval;
50254 +}
50255 +
50256 +static void
50257 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
50258 +{
50259 + struct task_struct *task = current;
50260 + const struct cred *cred = current_cred();
50261 +
50262 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
50263 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50264 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50265 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
50266 +
50267 + return;
50268 +}
50269 +
50270 +static void
50271 +gr_log_learn_sysctl(const char *path, const __u32 mode)
50272 +{
50273 + struct task_struct *task = current;
50274 + const struct cred *cred = current_cred();
50275 +
50276 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
50277 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50278 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50279 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
50280 +
50281 + return;
50282 +}
50283 +
50284 +static void
50285 +gr_log_learn_id_change(const char type, const unsigned int real,
50286 + const unsigned int effective, const unsigned int fs)
50287 +{
50288 + struct task_struct *task = current;
50289 + const struct cred *cred = current_cred();
50290 +
50291 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
50292 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50293 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50294 + type, real, effective, fs, &task->signal->saved_ip);
50295 +
50296 + return;
50297 +}
50298 +
50299 +__u32
50300 +gr_search_file(const struct dentry * dentry, const __u32 mode,
50301 + const struct vfsmount * mnt)
50302 +{
50303 + __u32 retval = mode;
50304 + struct acl_subject_label *curracl;
50305 + struct acl_object_label *currobj;
50306 +
50307 + if (unlikely(!(gr_status & GR_READY)))
50308 + return (mode & ~GR_AUDITS);
50309 +
50310 + curracl = current->acl;
50311 +
50312 + currobj = chk_obj_label(dentry, mnt, curracl);
50313 + retval = currobj->mode & mode;
50314 +
50315 + /* if we're opening a specified transfer file for writing
50316 + (e.g. /dev/initctl), then transfer our role to init
50317 + */
50318 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
50319 + current->role->roletype & GR_ROLE_PERSIST)) {
50320 + struct task_struct *task = init_pid_ns.child_reaper;
50321 +
50322 + if (task->role != current->role) {
50323 + task->acl_sp_role = 0;
50324 + task->acl_role_id = current->acl_role_id;
50325 + task->role = current->role;
50326 + rcu_read_lock();
50327 + read_lock(&grsec_exec_file_lock);
50328 + gr_apply_subject_to_task(task);
50329 + read_unlock(&grsec_exec_file_lock);
50330 + rcu_read_unlock();
50331 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
50332 + }
50333 + }
50334 +
50335 + if (unlikely
50336 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
50337 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
50338 + __u32 new_mode = mode;
50339 +
50340 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
50341 +
50342 + retval = new_mode;
50343 +
50344 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
50345 + new_mode |= GR_INHERIT;
50346 +
50347 + if (!(mode & GR_NOLEARN))
50348 + gr_log_learn(dentry, mnt, new_mode);
50349 + }
50350 +
50351 + return retval;
50352 +}
50353 +
50354 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
50355 + const struct dentry *parent,
50356 + const struct vfsmount *mnt)
50357 +{
50358 + struct name_entry *match;
50359 + struct acl_object_label *matchpo;
50360 + struct acl_subject_label *curracl;
50361 + char *path;
50362 +
50363 + if (unlikely(!(gr_status & GR_READY)))
50364 + return NULL;
50365 +
50366 + preempt_disable();
50367 + path = gr_to_filename_rbac(new_dentry, mnt);
50368 + match = lookup_name_entry_create(path);
50369 +
50370 + curracl = current->acl;
50371 +
50372 + if (match) {
50373 + read_lock(&gr_inode_lock);
50374 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
50375 + read_unlock(&gr_inode_lock);
50376 +
50377 + if (matchpo) {
50378 + preempt_enable();
50379 + return matchpo;
50380 + }
50381 + }
50382 +
50383 + // lookup parent
50384 +
50385 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
50386 +
50387 + preempt_enable();
50388 + return matchpo;
50389 +}
50390 +
50391 +__u32
50392 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
50393 + const struct vfsmount * mnt, const __u32 mode)
50394 +{
50395 + struct acl_object_label *matchpo;
50396 + __u32 retval;
50397 +
50398 + if (unlikely(!(gr_status & GR_READY)))
50399 + return (mode & ~GR_AUDITS);
50400 +
50401 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
50402 +
50403 + retval = matchpo->mode & mode;
50404 +
50405 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
50406 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
50407 + __u32 new_mode = mode;
50408 +
50409 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
50410 +
50411 + gr_log_learn(new_dentry, mnt, new_mode);
50412 + return new_mode;
50413 + }
50414 +
50415 + return retval;
50416 +}
50417 +
50418 +__u32
50419 +gr_check_link(const struct dentry * new_dentry,
50420 + const struct dentry * parent_dentry,
50421 + const struct vfsmount * parent_mnt,
50422 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
50423 +{
50424 + struct acl_object_label *obj;
50425 + __u32 oldmode, newmode;
50426 + __u32 needmode;
50427 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
50428 + GR_DELETE | GR_INHERIT;
50429 +
50430 + if (unlikely(!(gr_status & GR_READY)))
50431 + return (GR_CREATE | GR_LINK);
50432 +
50433 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
50434 + oldmode = obj->mode;
50435 +
50436 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
50437 + newmode = obj->mode;
50438 +
50439 + needmode = newmode & checkmodes;
50440 +
50441 + // old name for hardlink must have at least the permissions of the new name
50442 + if ((oldmode & needmode) != needmode)
50443 + goto bad;
50444 +
50445 + // if old name had restrictions/auditing, make sure the new name does as well
50446 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
50447 +
50448 + // don't allow hardlinking of suid/sgid files without permission
50449 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
50450 + needmode |= GR_SETID;
50451 +
50452 + if ((newmode & needmode) != needmode)
50453 + goto bad;
50454 +
50455 + // enforce minimum permissions
50456 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
50457 + return newmode;
50458 +bad:
50459 + needmode = oldmode;
50460 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
50461 + needmode |= GR_SETID;
50462 +
50463 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
50464 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
50465 + return (GR_CREATE | GR_LINK);
50466 + } else if (newmode & GR_SUPPRESS)
50467 + return GR_SUPPRESS;
50468 + else
50469 + return 0;
50470 +}
50471 +
50472 +int
50473 +gr_check_hidden_task(const struct task_struct *task)
50474 +{
50475 + if (unlikely(!(gr_status & GR_READY)))
50476 + return 0;
50477 +
50478 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
50479 + return 1;
50480 +
50481 + return 0;
50482 +}
50483 +
50484 +int
50485 +gr_check_protected_task(const struct task_struct *task)
50486 +{
50487 + if (unlikely(!(gr_status & GR_READY) || !task))
50488 + return 0;
50489 +
50490 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
50491 + task->acl != current->acl)
50492 + return 1;
50493 +
50494 + return 0;
50495 +}
50496 +
50497 +int
50498 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
50499 +{
50500 + struct task_struct *p;
50501 + int ret = 0;
50502 +
50503 + if (unlikely(!(gr_status & GR_READY) || !pid))
50504 + return ret;
50505 +
50506 + read_lock(&tasklist_lock);
50507 + do_each_pid_task(pid, type, p) {
50508 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
50509 + p->acl != current->acl) {
50510 + ret = 1;
50511 + goto out;
50512 + }
50513 + } while_each_pid_task(pid, type, p);
50514 +out:
50515 + read_unlock(&tasklist_lock);
50516 +
50517 + return ret;
50518 +}
50519 +
50520 +void
50521 +gr_copy_label(struct task_struct *tsk)
50522 +{
50523 + tsk->signal->used_accept = 0;
50524 + tsk->acl_sp_role = 0;
50525 + tsk->acl_role_id = current->acl_role_id;
50526 + tsk->acl = current->acl;
50527 + tsk->role = current->role;
50528 + tsk->signal->curr_ip = current->signal->curr_ip;
50529 + tsk->signal->saved_ip = current->signal->saved_ip;
50530 + if (current->exec_file)
50531 + get_file(current->exec_file);
50532 + tsk->exec_file = current->exec_file;
50533 + tsk->is_writable = current->is_writable;
50534 + if (unlikely(current->signal->used_accept)) {
50535 + current->signal->curr_ip = 0;
50536 + current->signal->saved_ip = 0;
50537 + }
50538 +
50539 + return;
50540 +}
50541 +
50542 +static void
50543 +gr_set_proc_res(struct task_struct *task)
50544 +{
50545 + struct acl_subject_label *proc;
50546 + unsigned short i;
50547 +
50548 + proc = task->acl;
50549 +
50550 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
50551 + return;
50552 +
50553 + for (i = 0; i < RLIM_NLIMITS; i++) {
50554 + if (!(proc->resmask & (1 << i)))
50555 + continue;
50556 +
50557 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
50558 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
50559 + }
50560 +
50561 + return;
50562 +}
50563 +
50564 +extern int __gr_process_user_ban(struct user_struct *user);
50565 +
50566 +int
50567 +gr_check_user_change(int real, int effective, int fs)
50568 +{
50569 + unsigned int i;
50570 + __u16 num;
50571 + uid_t *uidlist;
50572 + int curuid;
50573 + int realok = 0;
50574 + int effectiveok = 0;
50575 + int fsok = 0;
50576 +
50577 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
50578 + struct user_struct *user;
50579 +
50580 + if (real == -1)
50581 + goto skipit;
50582 +
50583 + user = find_user(real);
50584 + if (user == NULL)
50585 + goto skipit;
50586 +
50587 + if (__gr_process_user_ban(user)) {
50588 + /* for find_user */
50589 + free_uid(user);
50590 + return 1;
50591 + }
50592 +
50593 + /* for find_user */
50594 + free_uid(user);
50595 +
50596 +skipit:
50597 +#endif
50598 +
50599 + if (unlikely(!(gr_status & GR_READY)))
50600 + return 0;
50601 +
50602 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
50603 + gr_log_learn_id_change('u', real, effective, fs);
50604 +
50605 + num = current->acl->user_trans_num;
50606 + uidlist = current->acl->user_transitions;
50607 +
50608 + if (uidlist == NULL)
50609 + return 0;
50610 +
50611 + if (real == -1)
50612 + realok = 1;
50613 + if (effective == -1)
50614 + effectiveok = 1;
50615 + if (fs == -1)
50616 + fsok = 1;
50617 +
50618 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
50619 + for (i = 0; i < num; i++) {
50620 + curuid = (int)uidlist[i];
50621 + if (real == curuid)
50622 + realok = 1;
50623 + if (effective == curuid)
50624 + effectiveok = 1;
50625 + if (fs == curuid)
50626 + fsok = 1;
50627 + }
50628 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
50629 + for (i = 0; i < num; i++) {
50630 + curuid = (int)uidlist[i];
50631 + if (real == curuid)
50632 + break;
50633 + if (effective == curuid)
50634 + break;
50635 + if (fs == curuid)
50636 + break;
50637 + }
50638 + /* not in deny list */
50639 + if (i == num) {
50640 + realok = 1;
50641 + effectiveok = 1;
50642 + fsok = 1;
50643 + }
50644 + }
50645 +
50646 + if (realok && effectiveok && fsok)
50647 + return 0;
50648 + else {
50649 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
50650 + return 1;
50651 + }
50652 +}
50653 +
50654 +int
50655 +gr_check_group_change(int real, int effective, int fs)
50656 +{
50657 + unsigned int i;
50658 + __u16 num;
50659 + gid_t *gidlist;
50660 + int curgid;
50661 + int realok = 0;
50662 + int effectiveok = 0;
50663 + int fsok = 0;
50664 +
50665 + if (unlikely(!(gr_status & GR_READY)))
50666 + return 0;
50667 +
50668 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
50669 + gr_log_learn_id_change('g', real, effective, fs);
50670 +
50671 + num = current->acl->group_trans_num;
50672 + gidlist = current->acl->group_transitions;
50673 +
50674 + if (gidlist == NULL)
50675 + return 0;
50676 +
50677 + if (real == -1)
50678 + realok = 1;
50679 + if (effective == -1)
50680 + effectiveok = 1;
50681 + if (fs == -1)
50682 + fsok = 1;
50683 +
50684 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
50685 + for (i = 0; i < num; i++) {
50686 + curgid = (int)gidlist[i];
50687 + if (real == curgid)
50688 + realok = 1;
50689 + if (effective == curgid)
50690 + effectiveok = 1;
50691 + if (fs == curgid)
50692 + fsok = 1;
50693 + }
50694 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
50695 + for (i = 0; i < num; i++) {
50696 + curgid = (int)gidlist[i];
50697 + if (real == curgid)
50698 + break;
50699 + if (effective == curgid)
50700 + break;
50701 + if (fs == curgid)
50702 + break;
50703 + }
50704 + /* not in deny list */
50705 + if (i == num) {
50706 + realok = 1;
50707 + effectiveok = 1;
50708 + fsok = 1;
50709 + }
50710 + }
50711 +
50712 + if (realok && effectiveok && fsok)
50713 + return 0;
50714 + else {
50715 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
50716 + return 1;
50717 + }
50718 +}
50719 +
50720 +extern int gr_acl_is_capable(const int cap);
50721 +
50722 +void
50723 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
50724 +{
50725 + struct acl_role_label *role = task->role;
50726 + struct acl_subject_label *subj = NULL;
50727 + struct acl_object_label *obj;
50728 + struct file *filp;
50729 +
50730 + if (unlikely(!(gr_status & GR_READY)))
50731 + return;
50732 +
50733 + filp = task->exec_file;
50734 +
50735 + /* kernel process, we'll give them the kernel role */
50736 + if (unlikely(!filp)) {
50737 + task->role = kernel_role;
50738 + task->acl = kernel_role->root_label;
50739 + return;
50740 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
50741 + role = lookup_acl_role_label(task, uid, gid);
50742 +
50743 + /* don't change the role if we're not a privileged process */
50744 + if (role && task->role != role &&
50745 + (((role->roletype & GR_ROLE_USER) && gr_acl_is_capable(CAP_SETUID)) ||
50746 + ((role->roletype & GR_ROLE_GROUP) && gr_acl_is_capable(CAP_SETGID))))
50747 + return;
50748 +
50749 + /* perform subject lookup in possibly new role
50750 + we can use this result below in the case where role == task->role
50751 + */
50752 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
50753 +
50754 + /* if we changed uid/gid, but result in the same role
50755 + and are using inheritance, don't lose the inherited subject
50756 + if current subject is other than what normal lookup
50757 + would result in, we arrived via inheritance, don't
50758 + lose subject
50759 + */
50760 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
50761 + (subj == task->acl)))
50762 + task->acl = subj;
50763 +
50764 + task->role = role;
50765 +
50766 + task->is_writable = 0;
50767 +
50768 + /* ignore additional mmap checks for processes that are writable
50769 + by the default ACL */
50770 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
50771 + if (unlikely(obj->mode & GR_WRITE))
50772 + task->is_writable = 1;
50773 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
50774 + if (unlikely(obj->mode & GR_WRITE))
50775 + task->is_writable = 1;
50776 +
50777 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50778 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
50779 +#endif
50780 +
50781 + gr_set_proc_res(task);
50782 +
50783 + return;
50784 +}
50785 +
50786 +int
50787 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
50788 + const int unsafe_flags)
50789 +{
50790 + struct task_struct *task = current;
50791 + struct acl_subject_label *newacl;
50792 + struct acl_object_label *obj;
50793 + __u32 retmode;
50794 +
50795 + if (unlikely(!(gr_status & GR_READY)))
50796 + return 0;
50797 +
50798 + newacl = chk_subj_label(dentry, mnt, task->role);
50799 +
50800 + task_lock(task);
50801 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
50802 + !(task->role->roletype & GR_ROLE_GOD) &&
50803 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
50804 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
50805 + task_unlock(task);
50806 + if (unsafe_flags & LSM_UNSAFE_SHARE)
50807 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
50808 + else
50809 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
50810 + return -EACCES;
50811 + }
50812 + task_unlock(task);
50813 +
50814 + obj = chk_obj_label(dentry, mnt, task->acl);
50815 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
50816 +
50817 + if (!(task->acl->mode & GR_INHERITLEARN) &&
50818 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
50819 + if (obj->nested)
50820 + task->acl = obj->nested;
50821 + else
50822 + task->acl = newacl;
50823 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
50824 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
50825 +
50826 + task->is_writable = 0;
50827 +
50828 + /* ignore additional mmap checks for processes that are writable
50829 + by the default ACL */
50830 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
50831 + if (unlikely(obj->mode & GR_WRITE))
50832 + task->is_writable = 1;
50833 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
50834 + if (unlikely(obj->mode & GR_WRITE))
50835 + task->is_writable = 1;
50836 +
50837 + gr_set_proc_res(task);
50838 +
50839 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50840 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
50841 +#endif
50842 + return 0;
50843 +}
50844 +
50845 +/* always called with valid inodev ptr */
50846 +static void
50847 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
50848 +{
50849 + struct acl_object_label *matchpo;
50850 + struct acl_subject_label *matchps;
50851 + struct acl_subject_label *subj;
50852 + struct acl_role_label *role;
50853 + unsigned int x;
50854 +
50855 + FOR_EACH_ROLE_START(role)
50856 + FOR_EACH_SUBJECT_START(role, subj, x)
50857 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
50858 + matchpo->mode |= GR_DELETED;
50859 + FOR_EACH_SUBJECT_END(subj,x)
50860 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
50861 + if (subj->inode == ino && subj->device == dev)
50862 + subj->mode |= GR_DELETED;
50863 + FOR_EACH_NESTED_SUBJECT_END(subj)
50864 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
50865 + matchps->mode |= GR_DELETED;
50866 + FOR_EACH_ROLE_END(role)
50867 +
50868 + inodev->nentry->deleted = 1;
50869 +
50870 + return;
50871 +}
50872 +
50873 +void
50874 +gr_handle_delete(const ino_t ino, const dev_t dev)
50875 +{
50876 + struct inodev_entry *inodev;
50877 +
50878 + if (unlikely(!(gr_status & GR_READY)))
50879 + return;
50880 +
50881 + write_lock(&gr_inode_lock);
50882 + inodev = lookup_inodev_entry(ino, dev);
50883 + if (inodev != NULL)
50884 + do_handle_delete(inodev, ino, dev);
50885 + write_unlock(&gr_inode_lock);
50886 +
50887 + return;
50888 +}
50889 +
50890 +static void
50891 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
50892 + const ino_t newinode, const dev_t newdevice,
50893 + struct acl_subject_label *subj)
50894 +{
50895 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
50896 + struct acl_object_label *match;
50897 +
50898 + match = subj->obj_hash[index];
50899 +
50900 + while (match && (match->inode != oldinode ||
50901 + match->device != olddevice ||
50902 + !(match->mode & GR_DELETED)))
50903 + match = match->next;
50904 +
50905 + if (match && (match->inode == oldinode)
50906 + && (match->device == olddevice)
50907 + && (match->mode & GR_DELETED)) {
50908 + if (match->prev == NULL) {
50909 + subj->obj_hash[index] = match->next;
50910 + if (match->next != NULL)
50911 + match->next->prev = NULL;
50912 + } else {
50913 + match->prev->next = match->next;
50914 + if (match->next != NULL)
50915 + match->next->prev = match->prev;
50916 + }
50917 + match->prev = NULL;
50918 + match->next = NULL;
50919 + match->inode = newinode;
50920 + match->device = newdevice;
50921 + match->mode &= ~GR_DELETED;
50922 +
50923 + insert_acl_obj_label(match, subj);
50924 + }
50925 +
50926 + return;
50927 +}
50928 +
50929 +static void
50930 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
50931 + const ino_t newinode, const dev_t newdevice,
50932 + struct acl_role_label *role)
50933 +{
50934 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
50935 + struct acl_subject_label *match;
50936 +
50937 + match = role->subj_hash[index];
50938 +
50939 + while (match && (match->inode != oldinode ||
50940 + match->device != olddevice ||
50941 + !(match->mode & GR_DELETED)))
50942 + match = match->next;
50943 +
50944 + if (match && (match->inode == oldinode)
50945 + && (match->device == olddevice)
50946 + && (match->mode & GR_DELETED)) {
50947 + if (match->prev == NULL) {
50948 + role->subj_hash[index] = match->next;
50949 + if (match->next != NULL)
50950 + match->next->prev = NULL;
50951 + } else {
50952 + match->prev->next = match->next;
50953 + if (match->next != NULL)
50954 + match->next->prev = match->prev;
50955 + }
50956 + match->prev = NULL;
50957 + match->next = NULL;
50958 + match->inode = newinode;
50959 + match->device = newdevice;
50960 + match->mode &= ~GR_DELETED;
50961 +
50962 + insert_acl_subj_label(match, role);
50963 + }
50964 +
50965 + return;
50966 +}
50967 +
50968 +static void
50969 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
50970 + const ino_t newinode, const dev_t newdevice)
50971 +{
50972 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
50973 + struct inodev_entry *match;
50974 +
50975 + match = inodev_set.i_hash[index];
50976 +
50977 + while (match && (match->nentry->inode != oldinode ||
50978 + match->nentry->device != olddevice || !match->nentry->deleted))
50979 + match = match->next;
50980 +
50981 + if (match && (match->nentry->inode == oldinode)
50982 + && (match->nentry->device == olddevice) &&
50983 + match->nentry->deleted) {
50984 + if (match->prev == NULL) {
50985 + inodev_set.i_hash[index] = match->next;
50986 + if (match->next != NULL)
50987 + match->next->prev = NULL;
50988 + } else {
50989 + match->prev->next = match->next;
50990 + if (match->next != NULL)
50991 + match->next->prev = match->prev;
50992 + }
50993 + match->prev = NULL;
50994 + match->next = NULL;
50995 + match->nentry->inode = newinode;
50996 + match->nentry->device = newdevice;
50997 + match->nentry->deleted = 0;
50998 +
50999 + insert_inodev_entry(match);
51000 + }
51001 +
51002 + return;
51003 +}
51004 +
51005 +static void
51006 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
51007 +{
51008 + struct acl_subject_label *subj;
51009 + struct acl_role_label *role;
51010 + unsigned int x;
51011 +
51012 + FOR_EACH_ROLE_START(role)
51013 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
51014 +
51015 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
51016 + if ((subj->inode == ino) && (subj->device == dev)) {
51017 + subj->inode = ino;
51018 + subj->device = dev;
51019 + }
51020 + FOR_EACH_NESTED_SUBJECT_END(subj)
51021 + FOR_EACH_SUBJECT_START(role, subj, x)
51022 + update_acl_obj_label(matchn->inode, matchn->device,
51023 + ino, dev, subj);
51024 + FOR_EACH_SUBJECT_END(subj,x)
51025 + FOR_EACH_ROLE_END(role)
51026 +
51027 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
51028 +
51029 + return;
51030 +}
51031 +
51032 +static void
51033 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
51034 + const struct vfsmount *mnt)
51035 +{
51036 + ino_t ino = dentry->d_inode->i_ino;
51037 + dev_t dev = __get_dev(dentry);
51038 +
51039 + __do_handle_create(matchn, ino, dev);
51040 +
51041 + return;
51042 +}
51043 +
51044 +void
51045 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
51046 +{
51047 + struct name_entry *matchn;
51048 +
51049 + if (unlikely(!(gr_status & GR_READY)))
51050 + return;
51051 +
51052 + preempt_disable();
51053 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
51054 +
51055 + if (unlikely((unsigned long)matchn)) {
51056 + write_lock(&gr_inode_lock);
51057 + do_handle_create(matchn, dentry, mnt);
51058 + write_unlock(&gr_inode_lock);
51059 + }
51060 + preempt_enable();
51061 +
51062 + return;
51063 +}
51064 +
51065 +void
51066 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
51067 +{
51068 + struct name_entry *matchn;
51069 +
51070 + if (unlikely(!(gr_status & GR_READY)))
51071 + return;
51072 +
51073 + preempt_disable();
51074 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
51075 +
51076 + if (unlikely((unsigned long)matchn)) {
51077 + write_lock(&gr_inode_lock);
51078 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
51079 + write_unlock(&gr_inode_lock);
51080 + }
51081 + preempt_enable();
51082 +
51083 + return;
51084 +}
51085 +
51086 +void
51087 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
51088 + struct dentry *old_dentry,
51089 + struct dentry *new_dentry,
51090 + struct vfsmount *mnt, const __u8 replace)
51091 +{
51092 + struct name_entry *matchn;
51093 + struct inodev_entry *inodev;
51094 + struct inode *inode = new_dentry->d_inode;
51095 + ino_t old_ino = old_dentry->d_inode->i_ino;
51096 + dev_t old_dev = __get_dev(old_dentry);
51097 +
51098 + /* vfs_rename swaps the name and parent link for old_dentry and
51099 + new_dentry
51100 + at this point, old_dentry has the new name, parent link, and inode
51101 + for the renamed file
51102 + if a file is being replaced by a rename, new_dentry has the inode
51103 + and name for the replaced file
51104 + */
51105 +
51106 + if (unlikely(!(gr_status & GR_READY)))
51107 + return;
51108 +
51109 + preempt_disable();
51110 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
51111 +
51112 + /* we wouldn't have to check d_inode if it weren't for
51113 + NFS silly-renaming
51114 + */
51115 +
51116 + write_lock(&gr_inode_lock);
51117 + if (unlikely(replace && inode)) {
51118 + ino_t new_ino = inode->i_ino;
51119 + dev_t new_dev = __get_dev(new_dentry);
51120 +
51121 + inodev = lookup_inodev_entry(new_ino, new_dev);
51122 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
51123 + do_handle_delete(inodev, new_ino, new_dev);
51124 + }
51125 +
51126 + inodev = lookup_inodev_entry(old_ino, old_dev);
51127 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
51128 + do_handle_delete(inodev, old_ino, old_dev);
51129 +
51130 + if (unlikely((unsigned long)matchn))
51131 + do_handle_create(matchn, old_dentry, mnt);
51132 +
51133 + write_unlock(&gr_inode_lock);
51134 + preempt_enable();
51135 +
51136 + return;
51137 +}
51138 +
51139 +static int
51140 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
51141 + unsigned char **sum)
51142 +{
51143 + struct acl_role_label *r;
51144 + struct role_allowed_ip *ipp;
51145 + struct role_transition *trans;
51146 + unsigned int i;
51147 + int found = 0;
51148 + u32 curr_ip = current->signal->curr_ip;
51149 +
51150 + current->signal->saved_ip = curr_ip;
51151 +
51152 + /* check transition table */
51153 +
51154 + for (trans = current->role->transitions; trans; trans = trans->next) {
51155 + if (!strcmp(rolename, trans->rolename)) {
51156 + found = 1;
51157 + break;
51158 + }
51159 + }
51160 +
51161 + if (!found)
51162 + return 0;
51163 +
51164 + /* handle special roles that do not require authentication
51165 + and check ip */
51166 +
51167 + FOR_EACH_ROLE_START(r)
51168 + if (!strcmp(rolename, r->rolename) &&
51169 + (r->roletype & GR_ROLE_SPECIAL)) {
51170 + found = 0;
51171 + if (r->allowed_ips != NULL) {
51172 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
51173 + if ((ntohl(curr_ip) & ipp->netmask) ==
51174 + (ntohl(ipp->addr) & ipp->netmask))
51175 + found = 1;
51176 + }
51177 + } else
51178 + found = 2;
51179 + if (!found)
51180 + return 0;
51181 +
51182 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
51183 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
51184 + *salt = NULL;
51185 + *sum = NULL;
51186 + return 1;
51187 + }
51188 + }
51189 + FOR_EACH_ROLE_END(r)
51190 +
51191 + for (i = 0; i < num_sprole_pws; i++) {
51192 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
51193 + *salt = acl_special_roles[i]->salt;
51194 + *sum = acl_special_roles[i]->sum;
51195 + return 1;
51196 + }
51197 + }
51198 +
51199 + return 0;
51200 +}
51201 +
51202 +static void
51203 +assign_special_role(char *rolename)
51204 +{
51205 + struct acl_object_label *obj;
51206 + struct acl_role_label *r;
51207 + struct acl_role_label *assigned = NULL;
51208 + struct task_struct *tsk;
51209 + struct file *filp;
51210 +
51211 + FOR_EACH_ROLE_START(r)
51212 + if (!strcmp(rolename, r->rolename) &&
51213 + (r->roletype & GR_ROLE_SPECIAL)) {
51214 + assigned = r;
51215 + break;
51216 + }
51217 + FOR_EACH_ROLE_END(r)
51218 +
51219 + if (!assigned)
51220 + return;
51221 +
51222 + read_lock(&tasklist_lock);
51223 + read_lock(&grsec_exec_file_lock);
51224 +
51225 + tsk = current->real_parent;
51226 + if (tsk == NULL)
51227 + goto out_unlock;
51228 +
51229 + filp = tsk->exec_file;
51230 + if (filp == NULL)
51231 + goto out_unlock;
51232 +
51233 + tsk->is_writable = 0;
51234 +
51235 + tsk->acl_sp_role = 1;
51236 + tsk->acl_role_id = ++acl_sp_role_value;
51237 + tsk->role = assigned;
51238 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
51239 +
51240 + /* ignore additional mmap checks for processes that are writable
51241 + by the default ACL */
51242 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
51243 + if (unlikely(obj->mode & GR_WRITE))
51244 + tsk->is_writable = 1;
51245 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
51246 + if (unlikely(obj->mode & GR_WRITE))
51247 + tsk->is_writable = 1;
51248 +
51249 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51250 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
51251 +#endif
51252 +
51253 +out_unlock:
51254 + read_unlock(&grsec_exec_file_lock);
51255 + read_unlock(&tasklist_lock);
51256 + return;
51257 +}
51258 +
51259 +int gr_check_secure_terminal(struct task_struct *task)
51260 +{
51261 + struct task_struct *p, *p2, *p3;
51262 + struct files_struct *files;
51263 + struct fdtable *fdt;
51264 + struct file *our_file = NULL, *file;
51265 + int i;
51266 +
51267 + if (task->signal->tty == NULL)
51268 + return 1;
51269 +
51270 + files = get_files_struct(task);
51271 + if (files != NULL) {
51272 + rcu_read_lock();
51273 + fdt = files_fdtable(files);
51274 + for (i=0; i < fdt->max_fds; i++) {
51275 + file = fcheck_files(files, i);
51276 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
51277 + get_file(file);
51278 + our_file = file;
51279 + }
51280 + }
51281 + rcu_read_unlock();
51282 + put_files_struct(files);
51283 + }
51284 +
51285 + if (our_file == NULL)
51286 + return 1;
51287 +
51288 + read_lock(&tasklist_lock);
51289 + do_each_thread(p2, p) {
51290 + files = get_files_struct(p);
51291 + if (files == NULL ||
51292 + (p->signal && p->signal->tty == task->signal->tty)) {
51293 + if (files != NULL)
51294 + put_files_struct(files);
51295 + continue;
51296 + }
51297 + rcu_read_lock();
51298 + fdt = files_fdtable(files);
51299 + for (i=0; i < fdt->max_fds; i++) {
51300 + file = fcheck_files(files, i);
51301 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
51302 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
51303 + p3 = task;
51304 + while (p3->pid > 0) {
51305 + if (p3 == p)
51306 + break;
51307 + p3 = p3->real_parent;
51308 + }
51309 + if (p3 == p)
51310 + break;
51311 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
51312 + gr_handle_alertkill(p);
51313 + rcu_read_unlock();
51314 + put_files_struct(files);
51315 + read_unlock(&tasklist_lock);
51316 + fput(our_file);
51317 + return 0;
51318 + }
51319 + }
51320 + rcu_read_unlock();
51321 + put_files_struct(files);
51322 + } while_each_thread(p2, p);
51323 + read_unlock(&tasklist_lock);
51324 +
51325 + fput(our_file);
51326 + return 1;
51327 +}
51328 +
51329 +ssize_t
51330 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
51331 +{
51332 + struct gr_arg_wrapper uwrap;
51333 + unsigned char *sprole_salt = NULL;
51334 + unsigned char *sprole_sum = NULL;
51335 + int error = sizeof (struct gr_arg_wrapper);
51336 + int error2 = 0;
51337 +
51338 + mutex_lock(&gr_dev_mutex);
51339 +
51340 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
51341 + error = -EPERM;
51342 + goto out;
51343 + }
51344 +
51345 + if (count != sizeof (struct gr_arg_wrapper)) {
51346 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
51347 + error = -EINVAL;
51348 + goto out;
51349 + }
51350 +
51351 +
51352 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
51353 + gr_auth_expires = 0;
51354 + gr_auth_attempts = 0;
51355 + }
51356 +
51357 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
51358 + error = -EFAULT;
51359 + goto out;
51360 + }
51361 +
51362 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
51363 + error = -EINVAL;
51364 + goto out;
51365 + }
51366 +
51367 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
51368 + error = -EFAULT;
51369 + goto out;
51370 + }
51371 +
51372 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
51373 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
51374 + time_after(gr_auth_expires, get_seconds())) {
51375 + error = -EBUSY;
51376 + goto out;
51377 + }
51378 +
51379 + /* if non-root trying to do anything other than use a special role,
51380 + do not attempt authentication, do not count towards authentication
51381 + locking
51382 + */
51383 +
51384 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
51385 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
51386 + current_uid()) {
51387 + error = -EPERM;
51388 + goto out;
51389 + }
51390 +
51391 + /* ensure pw and special role name are null terminated */
51392 +
51393 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
51394 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
51395 +
51396 + /* Okay.
51397 + * We have our enough of the argument structure..(we have yet
51398 + * to copy_from_user the tables themselves) . Copy the tables
51399 + * only if we need them, i.e. for loading operations. */
51400 +
51401 + switch (gr_usermode->mode) {
51402 + case GR_STATUS:
51403 + if (gr_status & GR_READY) {
51404 + error = 1;
51405 + if (!gr_check_secure_terminal(current))
51406 + error = 3;
51407 + } else
51408 + error = 2;
51409 + goto out;
51410 + case GR_SHUTDOWN:
51411 + if ((gr_status & GR_READY)
51412 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51413 + pax_open_kernel();
51414 + gr_status &= ~GR_READY;
51415 + pax_close_kernel();
51416 +
51417 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
51418 + free_variables();
51419 + memset(gr_usermode, 0, sizeof (struct gr_arg));
51420 + memset(gr_system_salt, 0, GR_SALT_LEN);
51421 + memset(gr_system_sum, 0, GR_SHA_LEN);
51422 + } else if (gr_status & GR_READY) {
51423 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
51424 + error = -EPERM;
51425 + } else {
51426 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
51427 + error = -EAGAIN;
51428 + }
51429 + break;
51430 + case GR_ENABLE:
51431 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
51432 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
51433 + else {
51434 + if (gr_status & GR_READY)
51435 + error = -EAGAIN;
51436 + else
51437 + error = error2;
51438 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
51439 + }
51440 + break;
51441 + case GR_RELOAD:
51442 + if (!(gr_status & GR_READY)) {
51443 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
51444 + error = -EAGAIN;
51445 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51446 + preempt_disable();
51447 +
51448 + pax_open_kernel();
51449 + gr_status &= ~GR_READY;
51450 + pax_close_kernel();
51451 +
51452 + free_variables();
51453 + if (!(error2 = gracl_init(gr_usermode))) {
51454 + preempt_enable();
51455 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
51456 + } else {
51457 + preempt_enable();
51458 + error = error2;
51459 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
51460 + }
51461 + } else {
51462 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
51463 + error = -EPERM;
51464 + }
51465 + break;
51466 + case GR_SEGVMOD:
51467 + if (unlikely(!(gr_status & GR_READY))) {
51468 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
51469 + error = -EAGAIN;
51470 + break;
51471 + }
51472 +
51473 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51474 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
51475 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
51476 + struct acl_subject_label *segvacl;
51477 + segvacl =
51478 + lookup_acl_subj_label(gr_usermode->segv_inode,
51479 + gr_usermode->segv_device,
51480 + current->role);
51481 + if (segvacl) {
51482 + segvacl->crashes = 0;
51483 + segvacl->expires = 0;
51484 + }
51485 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
51486 + gr_remove_uid(gr_usermode->segv_uid);
51487 + }
51488 + } else {
51489 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
51490 + error = -EPERM;
51491 + }
51492 + break;
51493 + case GR_SPROLE:
51494 + case GR_SPROLEPAM:
51495 + if (unlikely(!(gr_status & GR_READY))) {
51496 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
51497 + error = -EAGAIN;
51498 + break;
51499 + }
51500 +
51501 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
51502 + current->role->expires = 0;
51503 + current->role->auth_attempts = 0;
51504 + }
51505 +
51506 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
51507 + time_after(current->role->expires, get_seconds())) {
51508 + error = -EBUSY;
51509 + goto out;
51510 + }
51511 +
51512 + if (lookup_special_role_auth
51513 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
51514 + && ((!sprole_salt && !sprole_sum)
51515 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
51516 + char *p = "";
51517 + assign_special_role(gr_usermode->sp_role);
51518 + read_lock(&tasklist_lock);
51519 + if (current->real_parent)
51520 + p = current->real_parent->role->rolename;
51521 + read_unlock(&tasklist_lock);
51522 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
51523 + p, acl_sp_role_value);
51524 + } else {
51525 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
51526 + error = -EPERM;
51527 + if(!(current->role->auth_attempts++))
51528 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
51529 +
51530 + goto out;
51531 + }
51532 + break;
51533 + case GR_UNSPROLE:
51534 + if (unlikely(!(gr_status & GR_READY))) {
51535 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
51536 + error = -EAGAIN;
51537 + break;
51538 + }
51539 +
51540 + if (current->role->roletype & GR_ROLE_SPECIAL) {
51541 + char *p = "";
51542 + int i = 0;
51543 +
51544 + read_lock(&tasklist_lock);
51545 + if (current->real_parent) {
51546 + p = current->real_parent->role->rolename;
51547 + i = current->real_parent->acl_role_id;
51548 + }
51549 + read_unlock(&tasklist_lock);
51550 +
51551 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
51552 + gr_set_acls(1);
51553 + } else {
51554 + error = -EPERM;
51555 + goto out;
51556 + }
51557 + break;
51558 + default:
51559 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
51560 + error = -EINVAL;
51561 + break;
51562 + }
51563 +
51564 + if (error != -EPERM)
51565 + goto out;
51566 +
51567 + if(!(gr_auth_attempts++))
51568 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
51569 +
51570 + out:
51571 + mutex_unlock(&gr_dev_mutex);
51572 + return error;
51573 +}
51574 +
51575 +/* must be called with
51576 + rcu_read_lock();
51577 + read_lock(&tasklist_lock);
51578 + read_lock(&grsec_exec_file_lock);
51579 +*/
51580 +int gr_apply_subject_to_task(struct task_struct *task)
51581 +{
51582 + struct acl_object_label *obj;
51583 + char *tmpname;
51584 + struct acl_subject_label *tmpsubj;
51585 + struct file *filp;
51586 + struct name_entry *nmatch;
51587 +
51588 + filp = task->exec_file;
51589 + if (filp == NULL)
51590 + return 0;
51591 +
51592 + /* the following is to apply the correct subject
51593 + on binaries running when the RBAC system
51594 + is enabled, when the binaries have been
51595 + replaced or deleted since their execution
51596 + -----
51597 + when the RBAC system starts, the inode/dev
51598 + from exec_file will be one the RBAC system
51599 + is unaware of. It only knows the inode/dev
51600 + of the present file on disk, or the absence
51601 + of it.
51602 + */
51603 + preempt_disable();
51604 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
51605 +
51606 + nmatch = lookup_name_entry(tmpname);
51607 + preempt_enable();
51608 + tmpsubj = NULL;
51609 + if (nmatch) {
51610 + if (nmatch->deleted)
51611 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
51612 + else
51613 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
51614 + if (tmpsubj != NULL)
51615 + task->acl = tmpsubj;
51616 + }
51617 + if (tmpsubj == NULL)
51618 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
51619 + task->role);
51620 + if (task->acl) {
51621 + task->is_writable = 0;
51622 + /* ignore additional mmap checks for processes that are writable
51623 + by the default ACL */
51624 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
51625 + if (unlikely(obj->mode & GR_WRITE))
51626 + task->is_writable = 1;
51627 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
51628 + if (unlikely(obj->mode & GR_WRITE))
51629 + task->is_writable = 1;
51630 +
51631 + gr_set_proc_res(task);
51632 +
51633 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51634 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
51635 +#endif
51636 + } else {
51637 + return 1;
51638 + }
51639 +
51640 + return 0;
51641 +}
51642 +
51643 +int
51644 +gr_set_acls(const int type)
51645 +{
51646 + struct task_struct *task, *task2;
51647 + struct acl_role_label *role = current->role;
51648 + __u16 acl_role_id = current->acl_role_id;
51649 + const struct cred *cred;
51650 + int ret;
51651 +
51652 + rcu_read_lock();
51653 + read_lock(&tasklist_lock);
51654 + read_lock(&grsec_exec_file_lock);
51655 + do_each_thread(task2, task) {
51656 + /* check to see if we're called from the exit handler,
51657 + if so, only replace ACLs that have inherited the admin
51658 + ACL */
51659 +
51660 + if (type && (task->role != role ||
51661 + task->acl_role_id != acl_role_id))
51662 + continue;
51663 +
51664 + task->acl_role_id = 0;
51665 + task->acl_sp_role = 0;
51666 +
51667 + if (task->exec_file) {
51668 + cred = __task_cred(task);
51669 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
51670 + ret = gr_apply_subject_to_task(task);
51671 + if (ret) {
51672 + read_unlock(&grsec_exec_file_lock);
51673 + read_unlock(&tasklist_lock);
51674 + rcu_read_unlock();
51675 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
51676 + return ret;
51677 + }
51678 + } else {
51679 + // it's a kernel process
51680 + task->role = kernel_role;
51681 + task->acl = kernel_role->root_label;
51682 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
51683 + task->acl->mode &= ~GR_PROCFIND;
51684 +#endif
51685 + }
51686 + } while_each_thread(task2, task);
51687 + read_unlock(&grsec_exec_file_lock);
51688 + read_unlock(&tasklist_lock);
51689 + rcu_read_unlock();
51690 +
51691 + return 0;
51692 +}
51693 +
51694 +void
51695 +gr_learn_resource(const struct task_struct *task,
51696 + const int res, const unsigned long wanted, const int gt)
51697 +{
51698 + struct acl_subject_label *acl;
51699 + const struct cred *cred;
51700 +
51701 + if (unlikely((gr_status & GR_READY) &&
51702 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
51703 + goto skip_reslog;
51704 +
51705 +#ifdef CONFIG_GRKERNSEC_RESLOG
51706 + gr_log_resource(task, res, wanted, gt);
51707 +#endif
51708 + skip_reslog:
51709 +
51710 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
51711 + return;
51712 +
51713 + acl = task->acl;
51714 +
51715 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
51716 + !(acl->resmask & (1 << (unsigned short) res))))
51717 + return;
51718 +
51719 + if (wanted >= acl->res[res].rlim_cur) {
51720 + unsigned long res_add;
51721 +
51722 + res_add = wanted;
51723 + switch (res) {
51724 + case RLIMIT_CPU:
51725 + res_add += GR_RLIM_CPU_BUMP;
51726 + break;
51727 + case RLIMIT_FSIZE:
51728 + res_add += GR_RLIM_FSIZE_BUMP;
51729 + break;
51730 + case RLIMIT_DATA:
51731 + res_add += GR_RLIM_DATA_BUMP;
51732 + break;
51733 + case RLIMIT_STACK:
51734 + res_add += GR_RLIM_STACK_BUMP;
51735 + break;
51736 + case RLIMIT_CORE:
51737 + res_add += GR_RLIM_CORE_BUMP;
51738 + break;
51739 + case RLIMIT_RSS:
51740 + res_add += GR_RLIM_RSS_BUMP;
51741 + break;
51742 + case RLIMIT_NPROC:
51743 + res_add += GR_RLIM_NPROC_BUMP;
51744 + break;
51745 + case RLIMIT_NOFILE:
51746 + res_add += GR_RLIM_NOFILE_BUMP;
51747 + break;
51748 + case RLIMIT_MEMLOCK:
51749 + res_add += GR_RLIM_MEMLOCK_BUMP;
51750 + break;
51751 + case RLIMIT_AS:
51752 + res_add += GR_RLIM_AS_BUMP;
51753 + break;
51754 + case RLIMIT_LOCKS:
51755 + res_add += GR_RLIM_LOCKS_BUMP;
51756 + break;
51757 + case RLIMIT_SIGPENDING:
51758 + res_add += GR_RLIM_SIGPENDING_BUMP;
51759 + break;
51760 + case RLIMIT_MSGQUEUE:
51761 + res_add += GR_RLIM_MSGQUEUE_BUMP;
51762 + break;
51763 + case RLIMIT_NICE:
51764 + res_add += GR_RLIM_NICE_BUMP;
51765 + break;
51766 + case RLIMIT_RTPRIO:
51767 + res_add += GR_RLIM_RTPRIO_BUMP;
51768 + break;
51769 + case RLIMIT_RTTIME:
51770 + res_add += GR_RLIM_RTTIME_BUMP;
51771 + break;
51772 + }
51773 +
51774 + acl->res[res].rlim_cur = res_add;
51775 +
51776 + if (wanted > acl->res[res].rlim_max)
51777 + acl->res[res].rlim_max = res_add;
51778 +
51779 + /* only log the subject filename, since resource logging is supported for
51780 + single-subject learning only */
51781 + rcu_read_lock();
51782 + cred = __task_cred(task);
51783 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
51784 + task->role->roletype, cred->uid, cred->gid, acl->filename,
51785 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
51786 + "", (unsigned long) res, &task->signal->saved_ip);
51787 + rcu_read_unlock();
51788 + }
51789 +
51790 + return;
51791 +}
51792 +
51793 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
51794 +void
51795 +pax_set_initial_flags(struct linux_binprm *bprm)
51796 +{
51797 + struct task_struct *task = current;
51798 + struct acl_subject_label *proc;
51799 + unsigned long flags;
51800 +
51801 + if (unlikely(!(gr_status & GR_READY)))
51802 + return;
51803 +
51804 + flags = pax_get_flags(task);
51805 +
51806 + proc = task->acl;
51807 +
51808 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
51809 + flags &= ~MF_PAX_PAGEEXEC;
51810 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
51811 + flags &= ~MF_PAX_SEGMEXEC;
51812 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
51813 + flags &= ~MF_PAX_RANDMMAP;
51814 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
51815 + flags &= ~MF_PAX_EMUTRAMP;
51816 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
51817 + flags &= ~MF_PAX_MPROTECT;
51818 +
51819 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
51820 + flags |= MF_PAX_PAGEEXEC;
51821 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
51822 + flags |= MF_PAX_SEGMEXEC;
51823 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
51824 + flags |= MF_PAX_RANDMMAP;
51825 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
51826 + flags |= MF_PAX_EMUTRAMP;
51827 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
51828 + flags |= MF_PAX_MPROTECT;
51829 +
51830 + pax_set_flags(task, flags);
51831 +
51832 + return;
51833 +}
51834 +#endif
51835 +
51836 +#ifdef CONFIG_SYSCTL
51837 +/* Eric Biederman likes breaking userland ABI and every inode-based security
51838 + system to save 35kb of memory */
51839 +
51840 +/* we modify the passed in filename, but adjust it back before returning */
51841 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
51842 +{
51843 + struct name_entry *nmatch;
51844 + char *p, *lastp = NULL;
51845 + struct acl_object_label *obj = NULL, *tmp;
51846 + struct acl_subject_label *tmpsubj;
51847 + char c = '\0';
51848 +
51849 + read_lock(&gr_inode_lock);
51850 +
51851 + p = name + len - 1;
51852 + do {
51853 + nmatch = lookup_name_entry(name);
51854 + if (lastp != NULL)
51855 + *lastp = c;
51856 +
51857 + if (nmatch == NULL)
51858 + goto next_component;
51859 + tmpsubj = current->acl;
51860 + do {
51861 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
51862 + if (obj != NULL) {
51863 + tmp = obj->globbed;
51864 + while (tmp) {
51865 + if (!glob_match(tmp->filename, name)) {
51866 + obj = tmp;
51867 + goto found_obj;
51868 + }
51869 + tmp = tmp->next;
51870 + }
51871 + goto found_obj;
51872 + }
51873 + } while ((tmpsubj = tmpsubj->parent_subject));
51874 +next_component:
51875 + /* end case */
51876 + if (p == name)
51877 + break;
51878 +
51879 + while (*p != '/')
51880 + p--;
51881 + if (p == name)
51882 + lastp = p + 1;
51883 + else {
51884 + lastp = p;
51885 + p--;
51886 + }
51887 + c = *lastp;
51888 + *lastp = '\0';
51889 + } while (1);
51890 +found_obj:
51891 + read_unlock(&gr_inode_lock);
51892 + /* obj returned will always be non-null */
51893 + return obj;
51894 +}
51895 +
51896 +/* returns 0 when allowing, non-zero on error
51897 + op of 0 is used for readdir, so we don't log the names of hidden files
51898 +*/
51899 +__u32
51900 +gr_handle_sysctl(const struct ctl_table *table, const int op)
51901 +{
51902 + struct ctl_table *tmp;
51903 + const char *proc_sys = "/proc/sys";
51904 + char *path;
51905 + struct acl_object_label *obj;
51906 + unsigned short len = 0, pos = 0, depth = 0, i;
51907 + __u32 err = 0;
51908 + __u32 mode = 0;
51909 +
51910 + if (unlikely(!(gr_status & GR_READY)))
51911 + return 0;
51912 +
51913 + /* for now, ignore operations on non-sysctl entries if it's not a
51914 + readdir*/
51915 + if (table->child != NULL && op != 0)
51916 + return 0;
51917 +
51918 + mode |= GR_FIND;
51919 + /* it's only a read if it's an entry, read on dirs is for readdir */
51920 + if (op & MAY_READ)
51921 + mode |= GR_READ;
51922 + if (op & MAY_WRITE)
51923 + mode |= GR_WRITE;
51924 +
51925 + preempt_disable();
51926 +
51927 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51928 +
51929 + /* it's only a read/write if it's an actual entry, not a dir
51930 + (which are opened for readdir)
51931 + */
51932 +
51933 + /* convert the requested sysctl entry into a pathname */
51934 +
51935 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
51936 + len += strlen(tmp->procname);
51937 + len++;
51938 + depth++;
51939 + }
51940 +
51941 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
51942 + /* deny */
51943 + goto out;
51944 + }
51945 +
51946 + memset(path, 0, PAGE_SIZE);
51947 +
51948 + memcpy(path, proc_sys, strlen(proc_sys));
51949 +
51950 + pos += strlen(proc_sys);
51951 +
51952 + for (; depth > 0; depth--) {
51953 + path[pos] = '/';
51954 + pos++;
51955 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
51956 + if (depth == i) {
51957 + memcpy(path + pos, tmp->procname,
51958 + strlen(tmp->procname));
51959 + pos += strlen(tmp->procname);
51960 + }
51961 + i++;
51962 + }
51963 + }
51964 +
51965 + obj = gr_lookup_by_name(path, pos);
51966 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
51967 +
51968 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
51969 + ((err & mode) != mode))) {
51970 + __u32 new_mode = mode;
51971 +
51972 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
51973 +
51974 + err = 0;
51975 + gr_log_learn_sysctl(path, new_mode);
51976 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
51977 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
51978 + err = -ENOENT;
51979 + } else if (!(err & GR_FIND)) {
51980 + err = -ENOENT;
51981 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
51982 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
51983 + path, (mode & GR_READ) ? " reading" : "",
51984 + (mode & GR_WRITE) ? " writing" : "");
51985 + err = -EACCES;
51986 + } else if ((err & mode) != mode) {
51987 + err = -EACCES;
51988 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
51989 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
51990 + path, (mode & GR_READ) ? " reading" : "",
51991 + (mode & GR_WRITE) ? " writing" : "");
51992 + err = 0;
51993 + } else
51994 + err = 0;
51995 +
51996 + out:
51997 + preempt_enable();
51998 +
51999 + return err;
52000 +}
52001 +#endif
52002 +
52003 +int
52004 +gr_handle_proc_ptrace(struct task_struct *task)
52005 +{
52006 + struct file *filp;
52007 + struct task_struct *tmp = task;
52008 + struct task_struct *curtemp = current;
52009 + __u32 retmode;
52010 +
52011 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
52012 + if (unlikely(!(gr_status & GR_READY)))
52013 + return 0;
52014 +#endif
52015 +
52016 + read_lock(&tasklist_lock);
52017 + read_lock(&grsec_exec_file_lock);
52018 + filp = task->exec_file;
52019 +
52020 + while (tmp->pid > 0) {
52021 + if (tmp == curtemp)
52022 + break;
52023 + tmp = tmp->real_parent;
52024 + }
52025 +
52026 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
52027 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
52028 + read_unlock(&grsec_exec_file_lock);
52029 + read_unlock(&tasklist_lock);
52030 + return 1;
52031 + }
52032 +
52033 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52034 + if (!(gr_status & GR_READY)) {
52035 + read_unlock(&grsec_exec_file_lock);
52036 + read_unlock(&tasklist_lock);
52037 + return 0;
52038 + }
52039 +#endif
52040 +
52041 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
52042 + read_unlock(&grsec_exec_file_lock);
52043 + read_unlock(&tasklist_lock);
52044 +
52045 + if (retmode & GR_NOPTRACE)
52046 + return 1;
52047 +
52048 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
52049 + && (current->acl != task->acl || (current->acl != current->role->root_label
52050 + && current->pid != task->pid)))
52051 + return 1;
52052 +
52053 + return 0;
52054 +}
52055 +
52056 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
52057 +{
52058 + if (unlikely(!(gr_status & GR_READY)))
52059 + return;
52060 +
52061 + if (!(current->role->roletype & GR_ROLE_GOD))
52062 + return;
52063 +
52064 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
52065 + p->role->rolename, gr_task_roletype_to_char(p),
52066 + p->acl->filename);
52067 +}
52068 +
52069 +int
52070 +gr_handle_ptrace(struct task_struct *task, const long request)
52071 +{
52072 + struct task_struct *tmp = task;
52073 + struct task_struct *curtemp = current;
52074 + __u32 retmode;
52075 +
52076 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
52077 + if (unlikely(!(gr_status & GR_READY)))
52078 + return 0;
52079 +#endif
52080 +
52081 + read_lock(&tasklist_lock);
52082 + while (tmp->pid > 0) {
52083 + if (tmp == curtemp)
52084 + break;
52085 + tmp = tmp->real_parent;
52086 + }
52087 +
52088 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
52089 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
52090 + read_unlock(&tasklist_lock);
52091 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52092 + return 1;
52093 + }
52094 + read_unlock(&tasklist_lock);
52095 +
52096 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52097 + if (!(gr_status & GR_READY))
52098 + return 0;
52099 +#endif
52100 +
52101 + read_lock(&grsec_exec_file_lock);
52102 + if (unlikely(!task->exec_file)) {
52103 + read_unlock(&grsec_exec_file_lock);
52104 + return 0;
52105 + }
52106 +
52107 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
52108 + read_unlock(&grsec_exec_file_lock);
52109 +
52110 + if (retmode & GR_NOPTRACE) {
52111 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52112 + return 1;
52113 + }
52114 +
52115 + if (retmode & GR_PTRACERD) {
52116 + switch (request) {
52117 + case PTRACE_SEIZE:
52118 + case PTRACE_POKETEXT:
52119 + case PTRACE_POKEDATA:
52120 + case PTRACE_POKEUSR:
52121 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
52122 + case PTRACE_SETREGS:
52123 + case PTRACE_SETFPREGS:
52124 +#endif
52125 +#ifdef CONFIG_X86
52126 + case PTRACE_SETFPXREGS:
52127 +#endif
52128 +#ifdef CONFIG_ALTIVEC
52129 + case PTRACE_SETVRREGS:
52130 +#endif
52131 + return 1;
52132 + default:
52133 + return 0;
52134 + }
52135 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
52136 + !(current->role->roletype & GR_ROLE_GOD) &&
52137 + (current->acl != task->acl)) {
52138 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52139 + return 1;
52140 + }
52141 +
52142 + return 0;
52143 +}
52144 +
52145 +static int is_writable_mmap(const struct file *filp)
52146 +{
52147 + struct task_struct *task = current;
52148 + struct acl_object_label *obj, *obj2;
52149 +
52150 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
52151 + !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))) {
52152 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52153 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
52154 + task->role->root_label);
52155 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
52156 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
52157 + return 1;
52158 + }
52159 + }
52160 + return 0;
52161 +}
52162 +
52163 +int
52164 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
52165 +{
52166 + __u32 mode;
52167 +
52168 + if (unlikely(!file || !(prot & PROT_EXEC)))
52169 + return 1;
52170 +
52171 + if (is_writable_mmap(file))
52172 + return 0;
52173 +
52174 + mode =
52175 + gr_search_file(file->f_path.dentry,
52176 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
52177 + file->f_path.mnt);
52178 +
52179 + if (!gr_tpe_allow(file))
52180 + return 0;
52181 +
52182 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
52183 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52184 + return 0;
52185 + } else if (unlikely(!(mode & GR_EXEC))) {
52186 + return 0;
52187 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
52188 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52189 + return 1;
52190 + }
52191 +
52192 + return 1;
52193 +}
52194 +
52195 +int
52196 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
52197 +{
52198 + __u32 mode;
52199 +
52200 + if (unlikely(!file || !(prot & PROT_EXEC)))
52201 + return 1;
52202 +
52203 + if (is_writable_mmap(file))
52204 + return 0;
52205 +
52206 + mode =
52207 + gr_search_file(file->f_path.dentry,
52208 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
52209 + file->f_path.mnt);
52210 +
52211 + if (!gr_tpe_allow(file))
52212 + return 0;
52213 +
52214 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
52215 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52216 + return 0;
52217 + } else if (unlikely(!(mode & GR_EXEC))) {
52218 + return 0;
52219 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
52220 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52221 + return 1;
52222 + }
52223 +
52224 + return 1;
52225 +}
52226 +
52227 +void
52228 +gr_acl_handle_psacct(struct task_struct *task, const long code)
52229 +{
52230 + unsigned long runtime;
52231 + unsigned long cputime;
52232 + unsigned int wday, cday;
52233 + __u8 whr, chr;
52234 + __u8 wmin, cmin;
52235 + __u8 wsec, csec;
52236 + struct timespec timeval;
52237 +
52238 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
52239 + !(task->acl->mode & GR_PROCACCT)))
52240 + return;
52241 +
52242 + do_posix_clock_monotonic_gettime(&timeval);
52243 + runtime = timeval.tv_sec - task->start_time.tv_sec;
52244 + wday = runtime / (3600 * 24);
52245 + runtime -= wday * (3600 * 24);
52246 + whr = runtime / 3600;
52247 + runtime -= whr * 3600;
52248 + wmin = runtime / 60;
52249 + runtime -= wmin * 60;
52250 + wsec = runtime;
52251 +
52252 + cputime = (task->utime + task->stime) / HZ;
52253 + cday = cputime / (3600 * 24);
52254 + cputime -= cday * (3600 * 24);
52255 + chr = cputime / 3600;
52256 + cputime -= chr * 3600;
52257 + cmin = cputime / 60;
52258 + cputime -= cmin * 60;
52259 + csec = cputime;
52260 +
52261 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
52262 +
52263 + return;
52264 +}
52265 +
52266 +void gr_set_kernel_label(struct task_struct *task)
52267 +{
52268 + if (gr_status & GR_READY) {
52269 + task->role = kernel_role;
52270 + task->acl = kernel_role->root_label;
52271 + }
52272 + return;
52273 +}
52274 +
52275 +#ifdef CONFIG_TASKSTATS
52276 +int gr_is_taskstats_denied(int pid)
52277 +{
52278 + struct task_struct *task;
52279 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52280 + const struct cred *cred;
52281 +#endif
52282 + int ret = 0;
52283 +
52284 + /* restrict taskstats viewing to un-chrooted root users
52285 + who have the 'view' subject flag if the RBAC system is enabled
52286 + */
52287 +
52288 + rcu_read_lock();
52289 + read_lock(&tasklist_lock);
52290 + task = find_task_by_vpid(pid);
52291 + if (task) {
52292 +#ifdef CONFIG_GRKERNSEC_CHROOT
52293 + if (proc_is_chrooted(task))
52294 + ret = -EACCES;
52295 +#endif
52296 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52297 + cred = __task_cred(task);
52298 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52299 + if (cred->uid != 0)
52300 + ret = -EACCES;
52301 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52302 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
52303 + ret = -EACCES;
52304 +#endif
52305 +#endif
52306 + if (gr_status & GR_READY) {
52307 + if (!(task->acl->mode & GR_VIEW))
52308 + ret = -EACCES;
52309 + }
52310 + } else
52311 + ret = -ENOENT;
52312 +
52313 + read_unlock(&tasklist_lock);
52314 + rcu_read_unlock();
52315 +
52316 + return ret;
52317 +}
52318 +#endif
52319 +
52320 +/* AUXV entries are filled via a descendant of search_binary_handler
52321 + after we've already applied the subject for the target
52322 +*/
52323 +int gr_acl_enable_at_secure(void)
52324 +{
52325 + if (unlikely(!(gr_status & GR_READY)))
52326 + return 0;
52327 +
52328 + if (current->acl->mode & GR_ATSECURE)
52329 + return 1;
52330 +
52331 + return 0;
52332 +}
52333 +
52334 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
52335 +{
52336 + struct task_struct *task = current;
52337 + struct dentry *dentry = file->f_path.dentry;
52338 + struct vfsmount *mnt = file->f_path.mnt;
52339 + struct acl_object_label *obj, *tmp;
52340 + struct acl_subject_label *subj;
52341 + unsigned int bufsize;
52342 + int is_not_root;
52343 + char *path;
52344 + dev_t dev = __get_dev(dentry);
52345 +
52346 + if (unlikely(!(gr_status & GR_READY)))
52347 + return 1;
52348 +
52349 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52350 + return 1;
52351 +
52352 + /* ignore Eric Biederman */
52353 + if (IS_PRIVATE(dentry->d_inode))
52354 + return 1;
52355 +
52356 + subj = task->acl;
52357 + do {
52358 + obj = lookup_acl_obj_label(ino, dev, subj);
52359 + if (obj != NULL)
52360 + return (obj->mode & GR_FIND) ? 1 : 0;
52361 + } while ((subj = subj->parent_subject));
52362 +
52363 + /* this is purely an optimization since we're looking for an object
52364 + for the directory we're doing a readdir on
52365 + if it's possible for any globbed object to match the entry we're
52366 + filling into the directory, then the object we find here will be
52367 + an anchor point with attached globbed objects
52368 + */
52369 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
52370 + if (obj->globbed == NULL)
52371 + return (obj->mode & GR_FIND) ? 1 : 0;
52372 +
52373 + is_not_root = ((obj->filename[0] == '/') &&
52374 + (obj->filename[1] == '\0')) ? 0 : 1;
52375 + bufsize = PAGE_SIZE - namelen - is_not_root;
52376 +
52377 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
52378 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
52379 + return 1;
52380 +
52381 + preempt_disable();
52382 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52383 + bufsize);
52384 +
52385 + bufsize = strlen(path);
52386 +
52387 + /* if base is "/", don't append an additional slash */
52388 + if (is_not_root)
52389 + *(path + bufsize) = '/';
52390 + memcpy(path + bufsize + is_not_root, name, namelen);
52391 + *(path + bufsize + namelen + is_not_root) = '\0';
52392 +
52393 + tmp = obj->globbed;
52394 + while (tmp) {
52395 + if (!glob_match(tmp->filename, path)) {
52396 + preempt_enable();
52397 + return (tmp->mode & GR_FIND) ? 1 : 0;
52398 + }
52399 + tmp = tmp->next;
52400 + }
52401 + preempt_enable();
52402 + return (obj->mode & GR_FIND) ? 1 : 0;
52403 +}
52404 +
52405 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
52406 +EXPORT_SYMBOL(gr_acl_is_enabled);
52407 +#endif
52408 +EXPORT_SYMBOL(gr_learn_resource);
52409 +EXPORT_SYMBOL(gr_set_kernel_label);
52410 +#ifdef CONFIG_SECURITY
52411 +EXPORT_SYMBOL(gr_check_user_change);
52412 +EXPORT_SYMBOL(gr_check_group_change);
52413 +#endif
52414 +
52415 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
52416 new file mode 100644
52417 index 0000000..34fefda
52418 --- /dev/null
52419 +++ b/grsecurity/gracl_alloc.c
52420 @@ -0,0 +1,105 @@
52421 +#include <linux/kernel.h>
52422 +#include <linux/mm.h>
52423 +#include <linux/slab.h>
52424 +#include <linux/vmalloc.h>
52425 +#include <linux/gracl.h>
52426 +#include <linux/grsecurity.h>
52427 +
52428 +static unsigned long alloc_stack_next = 1;
52429 +static unsigned long alloc_stack_size = 1;
52430 +static void **alloc_stack;
52431 +
52432 +static __inline__ int
52433 +alloc_pop(void)
52434 +{
52435 + if (alloc_stack_next == 1)
52436 + return 0;
52437 +
52438 + kfree(alloc_stack[alloc_stack_next - 2]);
52439 +
52440 + alloc_stack_next--;
52441 +
52442 + return 1;
52443 +}
52444 +
52445 +static __inline__ int
52446 +alloc_push(void *buf)
52447 +{
52448 + if (alloc_stack_next >= alloc_stack_size)
52449 + return 1;
52450 +
52451 + alloc_stack[alloc_stack_next - 1] = buf;
52452 +
52453 + alloc_stack_next++;
52454 +
52455 + return 0;
52456 +}
52457 +
52458 +void *
52459 +acl_alloc(unsigned long len)
52460 +{
52461 + void *ret = NULL;
52462 +
52463 + if (!len || len > PAGE_SIZE)
52464 + goto out;
52465 +
52466 + ret = kmalloc(len, GFP_KERNEL);
52467 +
52468 + if (ret) {
52469 + if (alloc_push(ret)) {
52470 + kfree(ret);
52471 + ret = NULL;
52472 + }
52473 + }
52474 +
52475 +out:
52476 + return ret;
52477 +}
52478 +
52479 +void *
52480 +acl_alloc_num(unsigned long num, unsigned long len)
52481 +{
52482 + if (!len || (num > (PAGE_SIZE / len)))
52483 + return NULL;
52484 +
52485 + return acl_alloc(num * len);
52486 +}
52487 +
52488 +void
52489 +acl_free_all(void)
52490 +{
52491 + if (gr_acl_is_enabled() || !alloc_stack)
52492 + return;
52493 +
52494 + while (alloc_pop()) ;
52495 +
52496 + if (alloc_stack) {
52497 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
52498 + kfree(alloc_stack);
52499 + else
52500 + vfree(alloc_stack);
52501 + }
52502 +
52503 + alloc_stack = NULL;
52504 + alloc_stack_size = 1;
52505 + alloc_stack_next = 1;
52506 +
52507 + return;
52508 +}
52509 +
52510 +int
52511 +acl_alloc_stack_init(unsigned long size)
52512 +{
52513 + if ((size * sizeof (void *)) <= PAGE_SIZE)
52514 + alloc_stack =
52515 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
52516 + else
52517 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
52518 +
52519 + alloc_stack_size = size;
52520 +
52521 + if (!alloc_stack)
52522 + return 0;
52523 + else
52524 + return 1;
52525 +}
52526 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
52527 new file mode 100644
52528 index 0000000..955ddfb
52529 --- /dev/null
52530 +++ b/grsecurity/gracl_cap.c
52531 @@ -0,0 +1,101 @@
52532 +#include <linux/kernel.h>
52533 +#include <linux/module.h>
52534 +#include <linux/sched.h>
52535 +#include <linux/gracl.h>
52536 +#include <linux/grsecurity.h>
52537 +#include <linux/grinternal.h>
52538 +
52539 +extern const char *captab_log[];
52540 +extern int captab_log_entries;
52541 +
52542 +int
52543 +gr_acl_is_capable(const int cap)
52544 +{
52545 + struct task_struct *task = current;
52546 + const struct cred *cred = current_cred();
52547 + struct acl_subject_label *curracl;
52548 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
52549 + kernel_cap_t cap_audit = __cap_empty_set;
52550 +
52551 + if (!gr_acl_is_enabled())
52552 + return 1;
52553 +
52554 + curracl = task->acl;
52555 +
52556 + cap_drop = curracl->cap_lower;
52557 + cap_mask = curracl->cap_mask;
52558 + cap_audit = curracl->cap_invert_audit;
52559 +
52560 + while ((curracl = curracl->parent_subject)) {
52561 + /* if the cap isn't specified in the current computed mask but is specified in the
52562 + current level subject, and is lowered in the current level subject, then add
52563 + it to the set of dropped capabilities
52564 + otherwise, add the current level subject's mask to the current computed mask
52565 + */
52566 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
52567 + cap_raise(cap_mask, cap);
52568 + if (cap_raised(curracl->cap_lower, cap))
52569 + cap_raise(cap_drop, cap);
52570 + if (cap_raised(curracl->cap_invert_audit, cap))
52571 + cap_raise(cap_audit, cap);
52572 + }
52573 + }
52574 +
52575 + if (!cap_raised(cap_drop, cap)) {
52576 + if (cap_raised(cap_audit, cap))
52577 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
52578 + return 1;
52579 + }
52580 +
52581 + curracl = task->acl;
52582 +
52583 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
52584 + && cap_raised(cred->cap_effective, cap)) {
52585 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
52586 + task->role->roletype, cred->uid,
52587 + cred->gid, task->exec_file ?
52588 + gr_to_filename(task->exec_file->f_path.dentry,
52589 + task->exec_file->f_path.mnt) : curracl->filename,
52590 + curracl->filename, 0UL,
52591 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
52592 + return 1;
52593 + }
52594 +
52595 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
52596 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
52597 + return 0;
52598 +}
52599 +
52600 +int
52601 +gr_acl_is_capable_nolog(const int cap)
52602 +{
52603 + struct acl_subject_label *curracl;
52604 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
52605 +
52606 + if (!gr_acl_is_enabled())
52607 + return 1;
52608 +
52609 + curracl = current->acl;
52610 +
52611 + cap_drop = curracl->cap_lower;
52612 + cap_mask = curracl->cap_mask;
52613 +
52614 + while ((curracl = curracl->parent_subject)) {
52615 + /* if the cap isn't specified in the current computed mask but is specified in the
52616 + current level subject, and is lowered in the current level subject, then add
52617 + it to the set of dropped capabilities
52618 + otherwise, add the current level subject's mask to the current computed mask
52619 + */
52620 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
52621 + cap_raise(cap_mask, cap);
52622 + if (cap_raised(curracl->cap_lower, cap))
52623 + cap_raise(cap_drop, cap);
52624 + }
52625 + }
52626 +
52627 + if (!cap_raised(cap_drop, cap))
52628 + return 1;
52629 +
52630 + return 0;
52631 +}
52632 +
52633 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
52634 new file mode 100644
52635 index 0000000..4eda5c3
52636 --- /dev/null
52637 +++ b/grsecurity/gracl_fs.c
52638 @@ -0,0 +1,433 @@
52639 +#include <linux/kernel.h>
52640 +#include <linux/sched.h>
52641 +#include <linux/types.h>
52642 +#include <linux/fs.h>
52643 +#include <linux/file.h>
52644 +#include <linux/stat.h>
52645 +#include <linux/grsecurity.h>
52646 +#include <linux/grinternal.h>
52647 +#include <linux/gracl.h>
52648 +
52649 +__u32
52650 +gr_acl_handle_hidden_file(const struct dentry * dentry,
52651 + const struct vfsmount * mnt)
52652 +{
52653 + __u32 mode;
52654 +
52655 + if (unlikely(!dentry->d_inode))
52656 + return GR_FIND;
52657 +
52658 + mode =
52659 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
52660 +
52661 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
52662 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
52663 + return mode;
52664 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
52665 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
52666 + return 0;
52667 + } else if (unlikely(!(mode & GR_FIND)))
52668 + return 0;
52669 +
52670 + return GR_FIND;
52671 +}
52672 +
52673 +__u32
52674 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
52675 + int acc_mode)
52676 +{
52677 + __u32 reqmode = GR_FIND;
52678 + __u32 mode;
52679 +
52680 + if (unlikely(!dentry->d_inode))
52681 + return reqmode;
52682 +
52683 + if (acc_mode & MAY_APPEND)
52684 + reqmode |= GR_APPEND;
52685 + else if (acc_mode & MAY_WRITE)
52686 + reqmode |= GR_WRITE;
52687 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
52688 + reqmode |= GR_READ;
52689 +
52690 + mode =
52691 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
52692 + mnt);
52693 +
52694 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
52695 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
52696 + reqmode & GR_READ ? " reading" : "",
52697 + reqmode & GR_WRITE ? " writing" : reqmode &
52698 + GR_APPEND ? " appending" : "");
52699 + return reqmode;
52700 + } else
52701 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
52702 + {
52703 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
52704 + reqmode & GR_READ ? " reading" : "",
52705 + reqmode & GR_WRITE ? " writing" : reqmode &
52706 + GR_APPEND ? " appending" : "");
52707 + return 0;
52708 + } else if (unlikely((mode & reqmode) != reqmode))
52709 + return 0;
52710 +
52711 + return reqmode;
52712 +}
52713 +
52714 +__u32
52715 +gr_acl_handle_creat(const struct dentry * dentry,
52716 + const struct dentry * p_dentry,
52717 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
52718 + const int imode)
52719 +{
52720 + __u32 reqmode = GR_WRITE | GR_CREATE;
52721 + __u32 mode;
52722 +
52723 + if (acc_mode & MAY_APPEND)
52724 + reqmode |= GR_APPEND;
52725 + // if a directory was required or the directory already exists, then
52726 + // don't count this open as a read
52727 + if ((acc_mode & MAY_READ) &&
52728 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
52729 + reqmode |= GR_READ;
52730 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
52731 + reqmode |= GR_SETID;
52732 +
52733 + mode =
52734 + gr_check_create(dentry, p_dentry, p_mnt,
52735 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
52736 +
52737 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
52738 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_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_CREATE_ACL_MSG, dentry, p_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_access(const struct dentry * dentry, const struct vfsmount * mnt,
52759 + const int fmode)
52760 +{
52761 + __u32 mode, reqmode = GR_FIND;
52762 +
52763 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
52764 + reqmode |= GR_EXEC;
52765 + if (fmode & S_IWOTH)
52766 + reqmode |= GR_WRITE;
52767 + if (fmode & S_IROTH)
52768 + reqmode |= GR_READ;
52769 +
52770 + mode =
52771 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
52772 + mnt);
52773 +
52774 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
52775 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
52776 + reqmode & GR_READ ? " reading" : "",
52777 + reqmode & GR_WRITE ? " writing" : "",
52778 + reqmode & GR_EXEC ? " executing" : "");
52779 + return reqmode;
52780 + } else
52781 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
52782 + {
52783 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
52784 + reqmode & GR_READ ? " reading" : "",
52785 + reqmode & GR_WRITE ? " writing" : "",
52786 + reqmode & GR_EXEC ? " executing" : "");
52787 + return 0;
52788 + } else if (unlikely((mode & reqmode) != reqmode))
52789 + return 0;
52790 +
52791 + return reqmode;
52792 +}
52793 +
52794 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
52795 +{
52796 + __u32 mode;
52797 +
52798 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
52799 +
52800 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
52801 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
52802 + return mode;
52803 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
52804 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
52805 + return 0;
52806 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
52807 + return 0;
52808 +
52809 + return (reqmode);
52810 +}
52811 +
52812 +__u32
52813 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
52814 +{
52815 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
52816 +}
52817 +
52818 +__u32
52819 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
52820 +{
52821 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
52822 +}
52823 +
52824 +__u32
52825 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
52826 +{
52827 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
52828 +}
52829 +
52830 +__u32
52831 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
52832 +{
52833 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
52834 +}
52835 +
52836 +__u32
52837 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
52838 + mode_t mode)
52839 +{
52840 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
52841 + return 1;
52842 +
52843 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
52844 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
52845 + GR_FCHMOD_ACL_MSG);
52846 + } else {
52847 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
52848 + }
52849 +}
52850 +
52851 +__u32
52852 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
52853 + mode_t mode)
52854 +{
52855 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
52856 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
52857 + GR_CHMOD_ACL_MSG);
52858 + } else {
52859 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
52860 + }
52861 +}
52862 +
52863 +__u32
52864 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
52865 +{
52866 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
52867 +}
52868 +
52869 +__u32
52870 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
52871 +{
52872 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
52873 +}
52874 +
52875 +__u32
52876 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
52877 +{
52878 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
52879 +}
52880 +
52881 +__u32
52882 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
52883 +{
52884 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
52885 + GR_UNIXCONNECT_ACL_MSG);
52886 +}
52887 +
52888 +/* hardlinks require at minimum create and link permission,
52889 + any additional privilege required is based on the
52890 + privilege of the file being linked to
52891 +*/
52892 +__u32
52893 +gr_acl_handle_link(const struct dentry * new_dentry,
52894 + const struct dentry * parent_dentry,
52895 + const struct vfsmount * parent_mnt,
52896 + const struct dentry * old_dentry,
52897 + const struct vfsmount * old_mnt, const char *to)
52898 +{
52899 + __u32 mode;
52900 + __u32 needmode = GR_CREATE | GR_LINK;
52901 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
52902 +
52903 + mode =
52904 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
52905 + old_mnt);
52906 +
52907 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
52908 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
52909 + return mode;
52910 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
52911 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
52912 + return 0;
52913 + } else if (unlikely((mode & needmode) != needmode))
52914 + return 0;
52915 +
52916 + return 1;
52917 +}
52918 +
52919 +__u32
52920 +gr_acl_handle_symlink(const struct dentry * new_dentry,
52921 + const struct dentry * parent_dentry,
52922 + const struct vfsmount * parent_mnt, const char *from)
52923 +{
52924 + __u32 needmode = GR_WRITE | GR_CREATE;
52925 + __u32 mode;
52926 +
52927 + mode =
52928 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
52929 + GR_CREATE | GR_AUDIT_CREATE |
52930 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
52931 +
52932 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
52933 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
52934 + return mode;
52935 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
52936 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
52937 + return 0;
52938 + } else if (unlikely((mode & needmode) != needmode))
52939 + return 0;
52940 +
52941 + return (GR_WRITE | GR_CREATE);
52942 +}
52943 +
52944 +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)
52945 +{
52946 + __u32 mode;
52947 +
52948 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
52949 +
52950 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
52951 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
52952 + return mode;
52953 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
52954 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
52955 + return 0;
52956 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
52957 + return 0;
52958 +
52959 + return (reqmode);
52960 +}
52961 +
52962 +__u32
52963 +gr_acl_handle_mknod(const struct dentry * new_dentry,
52964 + const struct dentry * parent_dentry,
52965 + const struct vfsmount * parent_mnt,
52966 + const int mode)
52967 +{
52968 + __u32 reqmode = GR_WRITE | GR_CREATE;
52969 + if (unlikely(mode & (S_ISUID | S_ISGID)))
52970 + reqmode |= GR_SETID;
52971 +
52972 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
52973 + reqmode, GR_MKNOD_ACL_MSG);
52974 +}
52975 +
52976 +__u32
52977 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
52978 + const struct dentry *parent_dentry,
52979 + const struct vfsmount *parent_mnt)
52980 +{
52981 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
52982 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
52983 +}
52984 +
52985 +#define RENAME_CHECK_SUCCESS(old, new) \
52986 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
52987 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
52988 +
52989 +int
52990 +gr_acl_handle_rename(struct dentry *new_dentry,
52991 + struct dentry *parent_dentry,
52992 + const struct vfsmount *parent_mnt,
52993 + struct dentry *old_dentry,
52994 + struct inode *old_parent_inode,
52995 + struct vfsmount *old_mnt, const char *newname)
52996 +{
52997 + __u32 comp1, comp2;
52998 + int error = 0;
52999 +
53000 + if (unlikely(!gr_acl_is_enabled()))
53001 + return 0;
53002 +
53003 + if (!new_dentry->d_inode) {
53004 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
53005 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
53006 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
53007 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
53008 + GR_DELETE | GR_AUDIT_DELETE |
53009 + GR_AUDIT_READ | GR_AUDIT_WRITE |
53010 + GR_SUPPRESS, old_mnt);
53011 + } else {
53012 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
53013 + GR_CREATE | GR_DELETE |
53014 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
53015 + GR_AUDIT_READ | GR_AUDIT_WRITE |
53016 + GR_SUPPRESS, parent_mnt);
53017 + comp2 =
53018 + gr_search_file(old_dentry,
53019 + GR_READ | GR_WRITE | GR_AUDIT_READ |
53020 + GR_DELETE | GR_AUDIT_DELETE |
53021 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
53022 + }
53023 +
53024 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
53025 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
53026 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
53027 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
53028 + && !(comp2 & GR_SUPPRESS)) {
53029 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
53030 + error = -EACCES;
53031 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
53032 + error = -EACCES;
53033 +
53034 + return error;
53035 +}
53036 +
53037 +void
53038 +gr_acl_handle_exit(void)
53039 +{
53040 + u16 id;
53041 + char *rolename;
53042 + struct file *exec_file;
53043 +
53044 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
53045 + !(current->role->roletype & GR_ROLE_PERSIST))) {
53046 + id = current->acl_role_id;
53047 + rolename = current->role->rolename;
53048 + gr_set_acls(1);
53049 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
53050 + }
53051 +
53052 + write_lock(&grsec_exec_file_lock);
53053 + exec_file = current->exec_file;
53054 + current->exec_file = NULL;
53055 + write_unlock(&grsec_exec_file_lock);
53056 +
53057 + if (exec_file)
53058 + fput(exec_file);
53059 +}
53060 +
53061 +int
53062 +gr_acl_handle_procpidmem(const struct task_struct *task)
53063 +{
53064 + if (unlikely(!gr_acl_is_enabled()))
53065 + return 0;
53066 +
53067 + if (task != current && task->acl->mode & GR_PROTPROCFD)
53068 + return -EACCES;
53069 +
53070 + return 0;
53071 +}
53072 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
53073 new file mode 100644
53074 index 0000000..17050ca
53075 --- /dev/null
53076 +++ b/grsecurity/gracl_ip.c
53077 @@ -0,0 +1,381 @@
53078 +#include <linux/kernel.h>
53079 +#include <asm/uaccess.h>
53080 +#include <asm/errno.h>
53081 +#include <net/sock.h>
53082 +#include <linux/file.h>
53083 +#include <linux/fs.h>
53084 +#include <linux/net.h>
53085 +#include <linux/in.h>
53086 +#include <linux/skbuff.h>
53087 +#include <linux/ip.h>
53088 +#include <linux/udp.h>
53089 +#include <linux/types.h>
53090 +#include <linux/sched.h>
53091 +#include <linux/netdevice.h>
53092 +#include <linux/inetdevice.h>
53093 +#include <linux/gracl.h>
53094 +#include <linux/grsecurity.h>
53095 +#include <linux/grinternal.h>
53096 +
53097 +#define GR_BIND 0x01
53098 +#define GR_CONNECT 0x02
53099 +#define GR_INVERT 0x04
53100 +#define GR_BINDOVERRIDE 0x08
53101 +#define GR_CONNECTOVERRIDE 0x10
53102 +#define GR_SOCK_FAMILY 0x20
53103 +
53104 +static const char * gr_protocols[IPPROTO_MAX] = {
53105 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
53106 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
53107 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
53108 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
53109 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
53110 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
53111 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
53112 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
53113 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
53114 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
53115 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
53116 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
53117 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
53118 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
53119 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
53120 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
53121 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
53122 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
53123 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
53124 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
53125 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
53126 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
53127 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
53128 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
53129 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
53130 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
53131 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
53132 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
53133 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
53134 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
53135 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
53136 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
53137 + };
53138 +
53139 +static const char * gr_socktypes[SOCK_MAX] = {
53140 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
53141 + "unknown:7", "unknown:8", "unknown:9", "packet"
53142 + };
53143 +
53144 +static const char * gr_sockfamilies[AF_MAX+1] = {
53145 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
53146 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
53147 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
53148 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
53149 + };
53150 +
53151 +const char *
53152 +gr_proto_to_name(unsigned char proto)
53153 +{
53154 + return gr_protocols[proto];
53155 +}
53156 +
53157 +const char *
53158 +gr_socktype_to_name(unsigned char type)
53159 +{
53160 + return gr_socktypes[type];
53161 +}
53162 +
53163 +const char *
53164 +gr_sockfamily_to_name(unsigned char family)
53165 +{
53166 + return gr_sockfamilies[family];
53167 +}
53168 +
53169 +int
53170 +gr_search_socket(const int domain, const int type, const int protocol)
53171 +{
53172 + struct acl_subject_label *curr;
53173 + const struct cred *cred = current_cred();
53174 +
53175 + if (unlikely(!gr_acl_is_enabled()))
53176 + goto exit;
53177 +
53178 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
53179 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
53180 + goto exit; // let the kernel handle it
53181 +
53182 + curr = current->acl;
53183 +
53184 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
53185 + /* the family is allowed, if this is PF_INET allow it only if
53186 + the extra sock type/protocol checks pass */
53187 + if (domain == PF_INET)
53188 + goto inet_check;
53189 + goto exit;
53190 + } else {
53191 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53192 + __u32 fakeip = 0;
53193 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53194 + current->role->roletype, cred->uid,
53195 + cred->gid, current->exec_file ?
53196 + gr_to_filename(current->exec_file->f_path.dentry,
53197 + current->exec_file->f_path.mnt) :
53198 + curr->filename, curr->filename,
53199 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
53200 + &current->signal->saved_ip);
53201 + goto exit;
53202 + }
53203 + goto exit_fail;
53204 + }
53205 +
53206 +inet_check:
53207 + /* the rest of this checking is for IPv4 only */
53208 + if (!curr->ips)
53209 + goto exit;
53210 +
53211 + if ((curr->ip_type & (1 << type)) &&
53212 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
53213 + goto exit;
53214 +
53215 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53216 + /* we don't place acls on raw sockets , and sometimes
53217 + dgram/ip sockets are opened for ioctl and not
53218 + bind/connect, so we'll fake a bind learn log */
53219 + if (type == SOCK_RAW || type == SOCK_PACKET) {
53220 + __u32 fakeip = 0;
53221 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53222 + current->role->roletype, cred->uid,
53223 + cred->gid, current->exec_file ?
53224 + gr_to_filename(current->exec_file->f_path.dentry,
53225 + current->exec_file->f_path.mnt) :
53226 + curr->filename, curr->filename,
53227 + &fakeip, 0, type,
53228 + protocol, GR_CONNECT, &current->signal->saved_ip);
53229 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
53230 + __u32 fakeip = 0;
53231 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53232 + current->role->roletype, cred->uid,
53233 + cred->gid, current->exec_file ?
53234 + gr_to_filename(current->exec_file->f_path.dentry,
53235 + current->exec_file->f_path.mnt) :
53236 + curr->filename, curr->filename,
53237 + &fakeip, 0, type,
53238 + protocol, GR_BIND, &current->signal->saved_ip);
53239 + }
53240 + /* we'll log when they use connect or bind */
53241 + goto exit;
53242 + }
53243 +
53244 +exit_fail:
53245 + if (domain == PF_INET)
53246 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
53247 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
53248 + else
53249 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
53250 + gr_socktype_to_name(type), protocol);
53251 +
53252 + return 0;
53253 +exit:
53254 + return 1;
53255 +}
53256 +
53257 +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)
53258 +{
53259 + if ((ip->mode & mode) &&
53260 + (ip_port >= ip->low) &&
53261 + (ip_port <= ip->high) &&
53262 + ((ntohl(ip_addr) & our_netmask) ==
53263 + (ntohl(our_addr) & our_netmask))
53264 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
53265 + && (ip->type & (1 << type))) {
53266 + if (ip->mode & GR_INVERT)
53267 + return 2; // specifically denied
53268 + else
53269 + return 1; // allowed
53270 + }
53271 +
53272 + return 0; // not specifically allowed, may continue parsing
53273 +}
53274 +
53275 +static int
53276 +gr_search_connectbind(const int full_mode, struct sock *sk,
53277 + struct sockaddr_in *addr, const int type)
53278 +{
53279 + char iface[IFNAMSIZ] = {0};
53280 + struct acl_subject_label *curr;
53281 + struct acl_ip_label *ip;
53282 + struct inet_sock *isk;
53283 + struct net_device *dev;
53284 + struct in_device *idev;
53285 + unsigned long i;
53286 + int ret;
53287 + int mode = full_mode & (GR_BIND | GR_CONNECT);
53288 + __u32 ip_addr = 0;
53289 + __u32 our_addr;
53290 + __u32 our_netmask;
53291 + char *p;
53292 + __u16 ip_port = 0;
53293 + const struct cred *cred = current_cred();
53294 +
53295 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
53296 + return 0;
53297 +
53298 + curr = current->acl;
53299 + isk = inet_sk(sk);
53300 +
53301 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
53302 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
53303 + addr->sin_addr.s_addr = curr->inaddr_any_override;
53304 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
53305 + struct sockaddr_in saddr;
53306 + int err;
53307 +
53308 + saddr.sin_family = AF_INET;
53309 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
53310 + saddr.sin_port = isk->inet_sport;
53311 +
53312 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
53313 + if (err)
53314 + return err;
53315 +
53316 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
53317 + if (err)
53318 + return err;
53319 + }
53320 +
53321 + if (!curr->ips)
53322 + return 0;
53323 +
53324 + ip_addr = addr->sin_addr.s_addr;
53325 + ip_port = ntohs(addr->sin_port);
53326 +
53327 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53328 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53329 + current->role->roletype, cred->uid,
53330 + cred->gid, current->exec_file ?
53331 + gr_to_filename(current->exec_file->f_path.dentry,
53332 + current->exec_file->f_path.mnt) :
53333 + curr->filename, curr->filename,
53334 + &ip_addr, ip_port, type,
53335 + sk->sk_protocol, mode, &current->signal->saved_ip);
53336 + return 0;
53337 + }
53338 +
53339 + for (i = 0; i < curr->ip_num; i++) {
53340 + ip = *(curr->ips + i);
53341 + if (ip->iface != NULL) {
53342 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
53343 + p = strchr(iface, ':');
53344 + if (p != NULL)
53345 + *p = '\0';
53346 + dev = dev_get_by_name(sock_net(sk), iface);
53347 + if (dev == NULL)
53348 + continue;
53349 + idev = in_dev_get(dev);
53350 + if (idev == NULL) {
53351 + dev_put(dev);
53352 + continue;
53353 + }
53354 + rcu_read_lock();
53355 + for_ifa(idev) {
53356 + if (!strcmp(ip->iface, ifa->ifa_label)) {
53357 + our_addr = ifa->ifa_address;
53358 + our_netmask = 0xffffffff;
53359 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
53360 + if (ret == 1) {
53361 + rcu_read_unlock();
53362 + in_dev_put(idev);
53363 + dev_put(dev);
53364 + return 0;
53365 + } else if (ret == 2) {
53366 + rcu_read_unlock();
53367 + in_dev_put(idev);
53368 + dev_put(dev);
53369 + goto denied;
53370 + }
53371 + }
53372 + } endfor_ifa(idev);
53373 + rcu_read_unlock();
53374 + in_dev_put(idev);
53375 + dev_put(dev);
53376 + } else {
53377 + our_addr = ip->addr;
53378 + our_netmask = ip->netmask;
53379 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
53380 + if (ret == 1)
53381 + return 0;
53382 + else if (ret == 2)
53383 + goto denied;
53384 + }
53385 + }
53386 +
53387 +denied:
53388 + if (mode == GR_BIND)
53389 + 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));
53390 + else if (mode == GR_CONNECT)
53391 + 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));
53392 +
53393 + return -EACCES;
53394 +}
53395 +
53396 +int
53397 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
53398 +{
53399 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
53400 +}
53401 +
53402 +int
53403 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
53404 +{
53405 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
53406 +}
53407 +
53408 +int gr_search_listen(struct socket *sock)
53409 +{
53410 + struct sock *sk = sock->sk;
53411 + struct sockaddr_in addr;
53412 +
53413 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
53414 + addr.sin_port = inet_sk(sk)->inet_sport;
53415 +
53416 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
53417 +}
53418 +
53419 +int gr_search_accept(struct socket *sock)
53420 +{
53421 + struct sock *sk = sock->sk;
53422 + struct sockaddr_in addr;
53423 +
53424 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
53425 + addr.sin_port = inet_sk(sk)->inet_sport;
53426 +
53427 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
53428 +}
53429 +
53430 +int
53431 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
53432 +{
53433 + if (addr)
53434 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
53435 + else {
53436 + struct sockaddr_in sin;
53437 + const struct inet_sock *inet = inet_sk(sk);
53438 +
53439 + sin.sin_addr.s_addr = inet->inet_daddr;
53440 + sin.sin_port = inet->inet_dport;
53441 +
53442 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
53443 + }
53444 +}
53445 +
53446 +int
53447 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
53448 +{
53449 + struct sockaddr_in sin;
53450 +
53451 + if (unlikely(skb->len < sizeof (struct udphdr)))
53452 + return 0; // skip this packet
53453 +
53454 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
53455 + sin.sin_port = udp_hdr(skb)->source;
53456 +
53457 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
53458 +}
53459 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
53460 new file mode 100644
53461 index 0000000..25f54ef
53462 --- /dev/null
53463 +++ b/grsecurity/gracl_learn.c
53464 @@ -0,0 +1,207 @@
53465 +#include <linux/kernel.h>
53466 +#include <linux/mm.h>
53467 +#include <linux/sched.h>
53468 +#include <linux/poll.h>
53469 +#include <linux/string.h>
53470 +#include <linux/file.h>
53471 +#include <linux/types.h>
53472 +#include <linux/vmalloc.h>
53473 +#include <linux/grinternal.h>
53474 +
53475 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
53476 + size_t count, loff_t *ppos);
53477 +extern int gr_acl_is_enabled(void);
53478 +
53479 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
53480 +static int gr_learn_attached;
53481 +
53482 +/* use a 512k buffer */
53483 +#define LEARN_BUFFER_SIZE (512 * 1024)
53484 +
53485 +static DEFINE_SPINLOCK(gr_learn_lock);
53486 +static DEFINE_MUTEX(gr_learn_user_mutex);
53487 +
53488 +/* we need to maintain two buffers, so that the kernel context of grlearn
53489 + uses a semaphore around the userspace copying, and the other kernel contexts
53490 + use a spinlock when copying into the buffer, since they cannot sleep
53491 +*/
53492 +static char *learn_buffer;
53493 +static char *learn_buffer_user;
53494 +static int learn_buffer_len;
53495 +static int learn_buffer_user_len;
53496 +
53497 +static ssize_t
53498 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
53499 +{
53500 + DECLARE_WAITQUEUE(wait, current);
53501 + ssize_t retval = 0;
53502 +
53503 + add_wait_queue(&learn_wait, &wait);
53504 + set_current_state(TASK_INTERRUPTIBLE);
53505 + do {
53506 + mutex_lock(&gr_learn_user_mutex);
53507 + spin_lock(&gr_learn_lock);
53508 + if (learn_buffer_len)
53509 + break;
53510 + spin_unlock(&gr_learn_lock);
53511 + mutex_unlock(&gr_learn_user_mutex);
53512 + if (file->f_flags & O_NONBLOCK) {
53513 + retval = -EAGAIN;
53514 + goto out;
53515 + }
53516 + if (signal_pending(current)) {
53517 + retval = -ERESTARTSYS;
53518 + goto out;
53519 + }
53520 +
53521 + schedule();
53522 + } while (1);
53523 +
53524 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
53525 + learn_buffer_user_len = learn_buffer_len;
53526 + retval = learn_buffer_len;
53527 + learn_buffer_len = 0;
53528 +
53529 + spin_unlock(&gr_learn_lock);
53530 +
53531 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
53532 + retval = -EFAULT;
53533 +
53534 + mutex_unlock(&gr_learn_user_mutex);
53535 +out:
53536 + set_current_state(TASK_RUNNING);
53537 + remove_wait_queue(&learn_wait, &wait);
53538 + return retval;
53539 +}
53540 +
53541 +static unsigned int
53542 +poll_learn(struct file * file, poll_table * wait)
53543 +{
53544 + poll_wait(file, &learn_wait, wait);
53545 +
53546 + if (learn_buffer_len)
53547 + return (POLLIN | POLLRDNORM);
53548 +
53549 + return 0;
53550 +}
53551 +
53552 +void
53553 +gr_clear_learn_entries(void)
53554 +{
53555 + char *tmp;
53556 +
53557 + mutex_lock(&gr_learn_user_mutex);
53558 + spin_lock(&gr_learn_lock);
53559 + tmp = learn_buffer;
53560 + learn_buffer = NULL;
53561 + spin_unlock(&gr_learn_lock);
53562 + if (tmp)
53563 + vfree(tmp);
53564 + if (learn_buffer_user != NULL) {
53565 + vfree(learn_buffer_user);
53566 + learn_buffer_user = NULL;
53567 + }
53568 + learn_buffer_len = 0;
53569 + mutex_unlock(&gr_learn_user_mutex);
53570 +
53571 + return;
53572 +}
53573 +
53574 +void
53575 +gr_add_learn_entry(const char *fmt, ...)
53576 +{
53577 + va_list args;
53578 + unsigned int len;
53579 +
53580 + if (!gr_learn_attached)
53581 + return;
53582 +
53583 + spin_lock(&gr_learn_lock);
53584 +
53585 + /* leave a gap at the end so we know when it's "full" but don't have to
53586 + compute the exact length of the string we're trying to append
53587 + */
53588 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
53589 + spin_unlock(&gr_learn_lock);
53590 + wake_up_interruptible(&learn_wait);
53591 + return;
53592 + }
53593 + if (learn_buffer == NULL) {
53594 + spin_unlock(&gr_learn_lock);
53595 + return;
53596 + }
53597 +
53598 + va_start(args, fmt);
53599 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
53600 + va_end(args);
53601 +
53602 + learn_buffer_len += len + 1;
53603 +
53604 + spin_unlock(&gr_learn_lock);
53605 + wake_up_interruptible(&learn_wait);
53606 +
53607 + return;
53608 +}
53609 +
53610 +static int
53611 +open_learn(struct inode *inode, struct file *file)
53612 +{
53613 + if (file->f_mode & FMODE_READ && gr_learn_attached)
53614 + return -EBUSY;
53615 + if (file->f_mode & FMODE_READ) {
53616 + int retval = 0;
53617 + mutex_lock(&gr_learn_user_mutex);
53618 + if (learn_buffer == NULL)
53619 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
53620 + if (learn_buffer_user == NULL)
53621 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
53622 + if (learn_buffer == NULL) {
53623 + retval = -ENOMEM;
53624 + goto out_error;
53625 + }
53626 + if (learn_buffer_user == NULL) {
53627 + retval = -ENOMEM;
53628 + goto out_error;
53629 + }
53630 + learn_buffer_len = 0;
53631 + learn_buffer_user_len = 0;
53632 + gr_learn_attached = 1;
53633 +out_error:
53634 + mutex_unlock(&gr_learn_user_mutex);
53635 + return retval;
53636 + }
53637 + return 0;
53638 +}
53639 +
53640 +static int
53641 +close_learn(struct inode *inode, struct file *file)
53642 +{
53643 + if (file->f_mode & FMODE_READ) {
53644 + char *tmp = NULL;
53645 + mutex_lock(&gr_learn_user_mutex);
53646 + spin_lock(&gr_learn_lock);
53647 + tmp = learn_buffer;
53648 + learn_buffer = NULL;
53649 + spin_unlock(&gr_learn_lock);
53650 + if (tmp)
53651 + vfree(tmp);
53652 + if (learn_buffer_user != NULL) {
53653 + vfree(learn_buffer_user);
53654 + learn_buffer_user = NULL;
53655 + }
53656 + learn_buffer_len = 0;
53657 + learn_buffer_user_len = 0;
53658 + gr_learn_attached = 0;
53659 + mutex_unlock(&gr_learn_user_mutex);
53660 + }
53661 +
53662 + return 0;
53663 +}
53664 +
53665 +const struct file_operations grsec_fops = {
53666 + .read = read_learn,
53667 + .write = write_grsec_handler,
53668 + .open = open_learn,
53669 + .release = close_learn,
53670 + .poll = poll_learn,
53671 +};
53672 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
53673 new file mode 100644
53674 index 0000000..39645c9
53675 --- /dev/null
53676 +++ b/grsecurity/gracl_res.c
53677 @@ -0,0 +1,68 @@
53678 +#include <linux/kernel.h>
53679 +#include <linux/sched.h>
53680 +#include <linux/gracl.h>
53681 +#include <linux/grinternal.h>
53682 +
53683 +static const char *restab_log[] = {
53684 + [RLIMIT_CPU] = "RLIMIT_CPU",
53685 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
53686 + [RLIMIT_DATA] = "RLIMIT_DATA",
53687 + [RLIMIT_STACK] = "RLIMIT_STACK",
53688 + [RLIMIT_CORE] = "RLIMIT_CORE",
53689 + [RLIMIT_RSS] = "RLIMIT_RSS",
53690 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
53691 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
53692 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
53693 + [RLIMIT_AS] = "RLIMIT_AS",
53694 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
53695 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
53696 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
53697 + [RLIMIT_NICE] = "RLIMIT_NICE",
53698 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
53699 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
53700 + [GR_CRASH_RES] = "RLIMIT_CRASH"
53701 +};
53702 +
53703 +void
53704 +gr_log_resource(const struct task_struct *task,
53705 + const int res, const unsigned long wanted, const int gt)
53706 +{
53707 + const struct cred *cred;
53708 + unsigned long rlim;
53709 +
53710 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
53711 + return;
53712 +
53713 + // not yet supported resource
53714 + if (unlikely(!restab_log[res]))
53715 + return;
53716 +
53717 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
53718 + rlim = task_rlimit_max(task, res);
53719 + else
53720 + rlim = task_rlimit(task, res);
53721 +
53722 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
53723 + return;
53724 +
53725 + rcu_read_lock();
53726 + cred = __task_cred(task);
53727 +
53728 + if (res == RLIMIT_NPROC &&
53729 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
53730 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
53731 + goto out_rcu_unlock;
53732 + else if (res == RLIMIT_MEMLOCK &&
53733 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
53734 + goto out_rcu_unlock;
53735 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
53736 + goto out_rcu_unlock;
53737 + rcu_read_unlock();
53738 +
53739 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
53740 +
53741 + return;
53742 +out_rcu_unlock:
53743 + rcu_read_unlock();
53744 + return;
53745 +}
53746 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
53747 new file mode 100644
53748 index 0000000..5556be3
53749 --- /dev/null
53750 +++ b/grsecurity/gracl_segv.c
53751 @@ -0,0 +1,299 @@
53752 +#include <linux/kernel.h>
53753 +#include <linux/mm.h>
53754 +#include <asm/uaccess.h>
53755 +#include <asm/errno.h>
53756 +#include <asm/mman.h>
53757 +#include <net/sock.h>
53758 +#include <linux/file.h>
53759 +#include <linux/fs.h>
53760 +#include <linux/net.h>
53761 +#include <linux/in.h>
53762 +#include <linux/slab.h>
53763 +#include <linux/types.h>
53764 +#include <linux/sched.h>
53765 +#include <linux/timer.h>
53766 +#include <linux/gracl.h>
53767 +#include <linux/grsecurity.h>
53768 +#include <linux/grinternal.h>
53769 +
53770 +static struct crash_uid *uid_set;
53771 +static unsigned short uid_used;
53772 +static DEFINE_SPINLOCK(gr_uid_lock);
53773 +extern rwlock_t gr_inode_lock;
53774 +extern struct acl_subject_label *
53775 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
53776 + struct acl_role_label *role);
53777 +
53778 +#ifdef CONFIG_BTRFS_FS
53779 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53780 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53781 +#endif
53782 +
53783 +static inline dev_t __get_dev(const struct dentry *dentry)
53784 +{
53785 +#ifdef CONFIG_BTRFS_FS
53786 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53787 + return get_btrfs_dev_from_inode(dentry->d_inode);
53788 + else
53789 +#endif
53790 + return dentry->d_inode->i_sb->s_dev;
53791 +}
53792 +
53793 +int
53794 +gr_init_uidset(void)
53795 +{
53796 + uid_set =
53797 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
53798 + uid_used = 0;
53799 +
53800 + return uid_set ? 1 : 0;
53801 +}
53802 +
53803 +void
53804 +gr_free_uidset(void)
53805 +{
53806 + if (uid_set)
53807 + kfree(uid_set);
53808 +
53809 + return;
53810 +}
53811 +
53812 +int
53813 +gr_find_uid(const uid_t uid)
53814 +{
53815 + struct crash_uid *tmp = uid_set;
53816 + uid_t buid;
53817 + int low = 0, high = uid_used - 1, mid;
53818 +
53819 + while (high >= low) {
53820 + mid = (low + high) >> 1;
53821 + buid = tmp[mid].uid;
53822 + if (buid == uid)
53823 + return mid;
53824 + if (buid > uid)
53825 + high = mid - 1;
53826 + if (buid < uid)
53827 + low = mid + 1;
53828 + }
53829 +
53830 + return -1;
53831 +}
53832 +
53833 +static __inline__ void
53834 +gr_insertsort(void)
53835 +{
53836 + unsigned short i, j;
53837 + struct crash_uid index;
53838 +
53839 + for (i = 1; i < uid_used; i++) {
53840 + index = uid_set[i];
53841 + j = i;
53842 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
53843 + uid_set[j] = uid_set[j - 1];
53844 + j--;
53845 + }
53846 + uid_set[j] = index;
53847 + }
53848 +
53849 + return;
53850 +}
53851 +
53852 +static __inline__ void
53853 +gr_insert_uid(const uid_t uid, const unsigned long expires)
53854 +{
53855 + int loc;
53856 +
53857 + if (uid_used == GR_UIDTABLE_MAX)
53858 + return;
53859 +
53860 + loc = gr_find_uid(uid);
53861 +
53862 + if (loc >= 0) {
53863 + uid_set[loc].expires = expires;
53864 + return;
53865 + }
53866 +
53867 + uid_set[uid_used].uid = uid;
53868 + uid_set[uid_used].expires = expires;
53869 + uid_used++;
53870 +
53871 + gr_insertsort();
53872 +
53873 + return;
53874 +}
53875 +
53876 +void
53877 +gr_remove_uid(const unsigned short loc)
53878 +{
53879 + unsigned short i;
53880 +
53881 + for (i = loc + 1; i < uid_used; i++)
53882 + uid_set[i - 1] = uid_set[i];
53883 +
53884 + uid_used--;
53885 +
53886 + return;
53887 +}
53888 +
53889 +int
53890 +gr_check_crash_uid(const uid_t uid)
53891 +{
53892 + int loc;
53893 + int ret = 0;
53894 +
53895 + if (unlikely(!gr_acl_is_enabled()))
53896 + return 0;
53897 +
53898 + spin_lock(&gr_uid_lock);
53899 + loc = gr_find_uid(uid);
53900 +
53901 + if (loc < 0)
53902 + goto out_unlock;
53903 +
53904 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
53905 + gr_remove_uid(loc);
53906 + else
53907 + ret = 1;
53908 +
53909 +out_unlock:
53910 + spin_unlock(&gr_uid_lock);
53911 + return ret;
53912 +}
53913 +
53914 +static __inline__ int
53915 +proc_is_setxid(const struct cred *cred)
53916 +{
53917 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
53918 + cred->uid != cred->fsuid)
53919 + return 1;
53920 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
53921 + cred->gid != cred->fsgid)
53922 + return 1;
53923 +
53924 + return 0;
53925 +}
53926 +
53927 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
53928 +
53929 +void
53930 +gr_handle_crash(struct task_struct *task, const int sig)
53931 +{
53932 + struct acl_subject_label *curr;
53933 + struct task_struct *tsk, *tsk2;
53934 + const struct cred *cred;
53935 + const struct cred *cred2;
53936 +
53937 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
53938 + return;
53939 +
53940 + if (unlikely(!gr_acl_is_enabled()))
53941 + return;
53942 +
53943 + curr = task->acl;
53944 +
53945 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
53946 + return;
53947 +
53948 + if (time_before_eq(curr->expires, get_seconds())) {
53949 + curr->expires = 0;
53950 + curr->crashes = 0;
53951 + }
53952 +
53953 + curr->crashes++;
53954 +
53955 + if (!curr->expires)
53956 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
53957 +
53958 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
53959 + time_after(curr->expires, get_seconds())) {
53960 + rcu_read_lock();
53961 + cred = __task_cred(task);
53962 + if (cred->uid && proc_is_setxid(cred)) {
53963 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
53964 + spin_lock(&gr_uid_lock);
53965 + gr_insert_uid(cred->uid, curr->expires);
53966 + spin_unlock(&gr_uid_lock);
53967 + curr->expires = 0;
53968 + curr->crashes = 0;
53969 + read_lock(&tasklist_lock);
53970 + do_each_thread(tsk2, tsk) {
53971 + cred2 = __task_cred(tsk);
53972 + if (tsk != task && cred2->uid == cred->uid)
53973 + gr_fake_force_sig(SIGKILL, tsk);
53974 + } while_each_thread(tsk2, tsk);
53975 + read_unlock(&tasklist_lock);
53976 + } else {
53977 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
53978 + read_lock(&tasklist_lock);
53979 + read_lock(&grsec_exec_file_lock);
53980 + do_each_thread(tsk2, tsk) {
53981 + if (likely(tsk != task)) {
53982 + // if this thread has the same subject as the one that triggered
53983 + // RES_CRASH and it's the same binary, kill it
53984 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
53985 + gr_fake_force_sig(SIGKILL, tsk);
53986 + }
53987 + } while_each_thread(tsk2, tsk);
53988 + read_unlock(&grsec_exec_file_lock);
53989 + read_unlock(&tasklist_lock);
53990 + }
53991 + rcu_read_unlock();
53992 + }
53993 +
53994 + return;
53995 +}
53996 +
53997 +int
53998 +gr_check_crash_exec(const struct file *filp)
53999 +{
54000 + struct acl_subject_label *curr;
54001 +
54002 + if (unlikely(!gr_acl_is_enabled()))
54003 + return 0;
54004 +
54005 + read_lock(&gr_inode_lock);
54006 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
54007 + __get_dev(filp->f_path.dentry),
54008 + current->role);
54009 + read_unlock(&gr_inode_lock);
54010 +
54011 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
54012 + (!curr->crashes && !curr->expires))
54013 + return 0;
54014 +
54015 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
54016 + time_after(curr->expires, get_seconds()))
54017 + return 1;
54018 + else if (time_before_eq(curr->expires, get_seconds())) {
54019 + curr->crashes = 0;
54020 + curr->expires = 0;
54021 + }
54022 +
54023 + return 0;
54024 +}
54025 +
54026 +void
54027 +gr_handle_alertkill(struct task_struct *task)
54028 +{
54029 + struct acl_subject_label *curracl;
54030 + __u32 curr_ip;
54031 + struct task_struct *p, *p2;
54032 +
54033 + if (unlikely(!gr_acl_is_enabled()))
54034 + return;
54035 +
54036 + curracl = task->acl;
54037 + curr_ip = task->signal->curr_ip;
54038 +
54039 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
54040 + read_lock(&tasklist_lock);
54041 + do_each_thread(p2, p) {
54042 + if (p->signal->curr_ip == curr_ip)
54043 + gr_fake_force_sig(SIGKILL, p);
54044 + } while_each_thread(p2, p);
54045 + read_unlock(&tasklist_lock);
54046 + } else if (curracl->mode & GR_KILLPROC)
54047 + gr_fake_force_sig(SIGKILL, task);
54048 +
54049 + return;
54050 +}
54051 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
54052 new file mode 100644
54053 index 0000000..9d83a69
54054 --- /dev/null
54055 +++ b/grsecurity/gracl_shm.c
54056 @@ -0,0 +1,40 @@
54057 +#include <linux/kernel.h>
54058 +#include <linux/mm.h>
54059 +#include <linux/sched.h>
54060 +#include <linux/file.h>
54061 +#include <linux/ipc.h>
54062 +#include <linux/gracl.h>
54063 +#include <linux/grsecurity.h>
54064 +#include <linux/grinternal.h>
54065 +
54066 +int
54067 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54068 + const time_t shm_createtime, const uid_t cuid, const int shmid)
54069 +{
54070 + struct task_struct *task;
54071 +
54072 + if (!gr_acl_is_enabled())
54073 + return 1;
54074 +
54075 + rcu_read_lock();
54076 + read_lock(&tasklist_lock);
54077 +
54078 + task = find_task_by_vpid(shm_cprid);
54079 +
54080 + if (unlikely(!task))
54081 + task = find_task_by_vpid(shm_lapid);
54082 +
54083 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
54084 + (task->pid == shm_lapid)) &&
54085 + (task->acl->mode & GR_PROTSHM) &&
54086 + (task->acl != current->acl))) {
54087 + read_unlock(&tasklist_lock);
54088 + rcu_read_unlock();
54089 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
54090 + return 0;
54091 + }
54092 + read_unlock(&tasklist_lock);
54093 + rcu_read_unlock();
54094 +
54095 + return 1;
54096 +}
54097 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
54098 new file mode 100644
54099 index 0000000..bc0be01
54100 --- /dev/null
54101 +++ b/grsecurity/grsec_chdir.c
54102 @@ -0,0 +1,19 @@
54103 +#include <linux/kernel.h>
54104 +#include <linux/sched.h>
54105 +#include <linux/fs.h>
54106 +#include <linux/file.h>
54107 +#include <linux/grsecurity.h>
54108 +#include <linux/grinternal.h>
54109 +
54110 +void
54111 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
54112 +{
54113 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
54114 + if ((grsec_enable_chdir && grsec_enable_group &&
54115 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
54116 + !grsec_enable_group)) {
54117 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
54118 + }
54119 +#endif
54120 + return;
54121 +}
54122 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
54123 new file mode 100644
54124 index 0000000..a2dc675
54125 --- /dev/null
54126 +++ b/grsecurity/grsec_chroot.c
54127 @@ -0,0 +1,351 @@
54128 +#include <linux/kernel.h>
54129 +#include <linux/module.h>
54130 +#include <linux/sched.h>
54131 +#include <linux/file.h>
54132 +#include <linux/fs.h>
54133 +#include <linux/mount.h>
54134 +#include <linux/types.h>
54135 +#include <linux/pid_namespace.h>
54136 +#include <linux/grsecurity.h>
54137 +#include <linux/grinternal.h>
54138 +
54139 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
54140 +{
54141 +#ifdef CONFIG_GRKERNSEC
54142 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
54143 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
54144 + task->gr_is_chrooted = 1;
54145 + else
54146 + task->gr_is_chrooted = 0;
54147 +
54148 + task->gr_chroot_dentry = path->dentry;
54149 +#endif
54150 + return;
54151 +}
54152 +
54153 +void gr_clear_chroot_entries(struct task_struct *task)
54154 +{
54155 +#ifdef CONFIG_GRKERNSEC
54156 + task->gr_is_chrooted = 0;
54157 + task->gr_chroot_dentry = NULL;
54158 +#endif
54159 + return;
54160 +}
54161 +
54162 +int
54163 +gr_handle_chroot_unix(const pid_t pid)
54164 +{
54165 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
54166 + struct task_struct *p;
54167 +
54168 + if (unlikely(!grsec_enable_chroot_unix))
54169 + return 1;
54170 +
54171 + if (likely(!proc_is_chrooted(current)))
54172 + return 1;
54173 +
54174 + rcu_read_lock();
54175 + read_lock(&tasklist_lock);
54176 + p = find_task_by_vpid_unrestricted(pid);
54177 + if (unlikely(p && !have_same_root(current, p))) {
54178 + read_unlock(&tasklist_lock);
54179 + rcu_read_unlock();
54180 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
54181 + return 0;
54182 + }
54183 + read_unlock(&tasklist_lock);
54184 + rcu_read_unlock();
54185 +#endif
54186 + return 1;
54187 +}
54188 +
54189 +int
54190 +gr_handle_chroot_nice(void)
54191 +{
54192 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
54193 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
54194 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
54195 + return -EPERM;
54196 + }
54197 +#endif
54198 + return 0;
54199 +}
54200 +
54201 +int
54202 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
54203 +{
54204 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
54205 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
54206 + && proc_is_chrooted(current)) {
54207 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
54208 + return -EACCES;
54209 + }
54210 +#endif
54211 + return 0;
54212 +}
54213 +
54214 +int
54215 +gr_handle_chroot_rawio(const struct inode *inode)
54216 +{
54217 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54218 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54219 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
54220 + return 1;
54221 +#endif
54222 + return 0;
54223 +}
54224 +
54225 +int
54226 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
54227 +{
54228 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
54229 + struct task_struct *p;
54230 + int ret = 0;
54231 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
54232 + return ret;
54233 +
54234 + read_lock(&tasklist_lock);
54235 + do_each_pid_task(pid, type, p) {
54236 + if (!have_same_root(current, p)) {
54237 + ret = 1;
54238 + goto out;
54239 + }
54240 + } while_each_pid_task(pid, type, p);
54241 +out:
54242 + read_unlock(&tasklist_lock);
54243 + return ret;
54244 +#endif
54245 + return 0;
54246 +}
54247 +
54248 +int
54249 +gr_pid_is_chrooted(struct task_struct *p)
54250 +{
54251 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
54252 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
54253 + return 0;
54254 +
54255 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
54256 + !have_same_root(current, p)) {
54257 + return 1;
54258 + }
54259 +#endif
54260 + return 0;
54261 +}
54262 +
54263 +EXPORT_SYMBOL(gr_pid_is_chrooted);
54264 +
54265 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
54266 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
54267 +{
54268 + struct path path, currentroot;
54269 + int ret = 0;
54270 +
54271 + path.dentry = (struct dentry *)u_dentry;
54272 + path.mnt = (struct vfsmount *)u_mnt;
54273 + get_fs_root(current->fs, &currentroot);
54274 + if (path_is_under(&path, &currentroot))
54275 + ret = 1;
54276 + path_put(&currentroot);
54277 +
54278 + return ret;
54279 +}
54280 +#endif
54281 +
54282 +int
54283 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
54284 +{
54285 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
54286 + if (!grsec_enable_chroot_fchdir)
54287 + return 1;
54288 +
54289 + if (!proc_is_chrooted(current))
54290 + return 1;
54291 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
54292 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
54293 + return 0;
54294 + }
54295 +#endif
54296 + return 1;
54297 +}
54298 +
54299 +int
54300 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54301 + const time_t shm_createtime)
54302 +{
54303 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
54304 + struct task_struct *p;
54305 + time_t starttime;
54306 +
54307 + if (unlikely(!grsec_enable_chroot_shmat))
54308 + return 1;
54309 +
54310 + if (likely(!proc_is_chrooted(current)))
54311 + return 1;
54312 +
54313 + rcu_read_lock();
54314 + read_lock(&tasklist_lock);
54315 +
54316 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
54317 + starttime = p->start_time.tv_sec;
54318 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
54319 + if (have_same_root(current, p)) {
54320 + goto allow;
54321 + } else {
54322 + read_unlock(&tasklist_lock);
54323 + rcu_read_unlock();
54324 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
54325 + return 0;
54326 + }
54327 + }
54328 + /* creator exited, pid reuse, fall through to next check */
54329 + }
54330 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
54331 + if (unlikely(!have_same_root(current, p))) {
54332 + read_unlock(&tasklist_lock);
54333 + rcu_read_unlock();
54334 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
54335 + return 0;
54336 + }
54337 + }
54338 +
54339 +allow:
54340 + read_unlock(&tasklist_lock);
54341 + rcu_read_unlock();
54342 +#endif
54343 + return 1;
54344 +}
54345 +
54346 +void
54347 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
54348 +{
54349 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
54350 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
54351 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
54352 +#endif
54353 + return;
54354 +}
54355 +
54356 +int
54357 +gr_handle_chroot_mknod(const struct dentry *dentry,
54358 + const struct vfsmount *mnt, const int mode)
54359 +{
54360 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
54361 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
54362 + proc_is_chrooted(current)) {
54363 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
54364 + return -EPERM;
54365 + }
54366 +#endif
54367 + return 0;
54368 +}
54369 +
54370 +int
54371 +gr_handle_chroot_mount(const struct dentry *dentry,
54372 + const struct vfsmount *mnt, const char *dev_name)
54373 +{
54374 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
54375 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
54376 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
54377 + return -EPERM;
54378 + }
54379 +#endif
54380 + return 0;
54381 +}
54382 +
54383 +int
54384 +gr_handle_chroot_pivot(void)
54385 +{
54386 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
54387 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
54388 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
54389 + return -EPERM;
54390 + }
54391 +#endif
54392 + return 0;
54393 +}
54394 +
54395 +int
54396 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
54397 +{
54398 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
54399 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
54400 + !gr_is_outside_chroot(dentry, mnt)) {
54401 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
54402 + return -EPERM;
54403 + }
54404 +#endif
54405 + return 0;
54406 +}
54407 +
54408 +extern const char *captab_log[];
54409 +extern int captab_log_entries;
54410 +
54411 +int
54412 +gr_chroot_is_capable(const int cap)
54413 +{
54414 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54415 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
54416 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
54417 + if (cap_raised(chroot_caps, cap)) {
54418 + const struct cred *creds = current_cred();
54419 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
54420 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
54421 + }
54422 + return 0;
54423 + }
54424 + }
54425 +#endif
54426 + return 1;
54427 +}
54428 +
54429 +int
54430 +gr_chroot_is_capable_nolog(const int cap)
54431 +{
54432 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54433 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
54434 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
54435 + if (cap_raised(chroot_caps, cap)) {
54436 + return 0;
54437 + }
54438 + }
54439 +#endif
54440 + return 1;
54441 +}
54442 +
54443 +int
54444 +gr_handle_chroot_sysctl(const int op)
54445 +{
54446 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
54447 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
54448 + proc_is_chrooted(current))
54449 + return -EACCES;
54450 +#endif
54451 + return 0;
54452 +}
54453 +
54454 +void
54455 +gr_handle_chroot_chdir(struct path *path)
54456 +{
54457 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
54458 + if (grsec_enable_chroot_chdir)
54459 + set_fs_pwd(current->fs, path);
54460 +#endif
54461 + return;
54462 +}
54463 +
54464 +int
54465 +gr_handle_chroot_chmod(const struct dentry *dentry,
54466 + const struct vfsmount *mnt, const int mode)
54467 +{
54468 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
54469 + /* allow chmod +s on directories, but not files */
54470 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
54471 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
54472 + proc_is_chrooted(current)) {
54473 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
54474 + return -EPERM;
54475 + }
54476 +#endif
54477 + return 0;
54478 +}
54479 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
54480 new file mode 100644
54481 index 0000000..d81a586
54482 --- /dev/null
54483 +++ b/grsecurity/grsec_disabled.c
54484 @@ -0,0 +1,439 @@
54485 +#include <linux/kernel.h>
54486 +#include <linux/module.h>
54487 +#include <linux/sched.h>
54488 +#include <linux/file.h>
54489 +#include <linux/fs.h>
54490 +#include <linux/kdev_t.h>
54491 +#include <linux/net.h>
54492 +#include <linux/in.h>
54493 +#include <linux/ip.h>
54494 +#include <linux/skbuff.h>
54495 +#include <linux/sysctl.h>
54496 +
54497 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54498 +void
54499 +pax_set_initial_flags(struct linux_binprm *bprm)
54500 +{
54501 + return;
54502 +}
54503 +#endif
54504 +
54505 +#ifdef CONFIG_SYSCTL
54506 +__u32
54507 +gr_handle_sysctl(const struct ctl_table * table, const int op)
54508 +{
54509 + return 0;
54510 +}
54511 +#endif
54512 +
54513 +#ifdef CONFIG_TASKSTATS
54514 +int gr_is_taskstats_denied(int pid)
54515 +{
54516 + return 0;
54517 +}
54518 +#endif
54519 +
54520 +int
54521 +gr_acl_is_enabled(void)
54522 +{
54523 + return 0;
54524 +}
54525 +
54526 +void
54527 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54528 +{
54529 + return;
54530 +}
54531 +
54532 +int
54533 +gr_handle_rawio(const struct inode *inode)
54534 +{
54535 + return 0;
54536 +}
54537 +
54538 +void
54539 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54540 +{
54541 + return;
54542 +}
54543 +
54544 +int
54545 +gr_handle_ptrace(struct task_struct *task, const long request)
54546 +{
54547 + return 0;
54548 +}
54549 +
54550 +int
54551 +gr_handle_proc_ptrace(struct task_struct *task)
54552 +{
54553 + return 0;
54554 +}
54555 +
54556 +void
54557 +gr_learn_resource(const struct task_struct *task,
54558 + const int res, const unsigned long wanted, const int gt)
54559 +{
54560 + return;
54561 +}
54562 +
54563 +int
54564 +gr_set_acls(const int type)
54565 +{
54566 + return 0;
54567 +}
54568 +
54569 +int
54570 +gr_check_hidden_task(const struct task_struct *tsk)
54571 +{
54572 + return 0;
54573 +}
54574 +
54575 +int
54576 +gr_check_protected_task(const struct task_struct *task)
54577 +{
54578 + return 0;
54579 +}
54580 +
54581 +int
54582 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54583 +{
54584 + return 0;
54585 +}
54586 +
54587 +void
54588 +gr_copy_label(struct task_struct *tsk)
54589 +{
54590 + return;
54591 +}
54592 +
54593 +void
54594 +gr_set_pax_flags(struct task_struct *task)
54595 +{
54596 + return;
54597 +}
54598 +
54599 +int
54600 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54601 + const int unsafe_share)
54602 +{
54603 + return 0;
54604 +}
54605 +
54606 +void
54607 +gr_handle_delete(const ino_t ino, const dev_t dev)
54608 +{
54609 + return;
54610 +}
54611 +
54612 +void
54613 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54614 +{
54615 + return;
54616 +}
54617 +
54618 +void
54619 +gr_handle_crash(struct task_struct *task, const int sig)
54620 +{
54621 + return;
54622 +}
54623 +
54624 +int
54625 +gr_check_crash_exec(const struct file *filp)
54626 +{
54627 + return 0;
54628 +}
54629 +
54630 +int
54631 +gr_check_crash_uid(const uid_t uid)
54632 +{
54633 + return 0;
54634 +}
54635 +
54636 +void
54637 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54638 + struct dentry *old_dentry,
54639 + struct dentry *new_dentry,
54640 + struct vfsmount *mnt, const __u8 replace)
54641 +{
54642 + return;
54643 +}
54644 +
54645 +int
54646 +gr_search_socket(const int family, const int type, const int protocol)
54647 +{
54648 + return 1;
54649 +}
54650 +
54651 +int
54652 +gr_search_connectbind(const int mode, const struct socket *sock,
54653 + const struct sockaddr_in *addr)
54654 +{
54655 + return 0;
54656 +}
54657 +
54658 +void
54659 +gr_handle_alertkill(struct task_struct *task)
54660 +{
54661 + return;
54662 +}
54663 +
54664 +__u32
54665 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
54666 +{
54667 + return 1;
54668 +}
54669 +
54670 +__u32
54671 +gr_acl_handle_hidden_file(const struct dentry * dentry,
54672 + const struct vfsmount * mnt)
54673 +{
54674 + return 1;
54675 +}
54676 +
54677 +__u32
54678 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54679 + int acc_mode)
54680 +{
54681 + return 1;
54682 +}
54683 +
54684 +__u32
54685 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54686 +{
54687 + return 1;
54688 +}
54689 +
54690 +__u32
54691 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
54692 +{
54693 + return 1;
54694 +}
54695 +
54696 +int
54697 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
54698 + unsigned int *vm_flags)
54699 +{
54700 + return 1;
54701 +}
54702 +
54703 +__u32
54704 +gr_acl_handle_truncate(const struct dentry * dentry,
54705 + const struct vfsmount * mnt)
54706 +{
54707 + return 1;
54708 +}
54709 +
54710 +__u32
54711 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
54712 +{
54713 + return 1;
54714 +}
54715 +
54716 +__u32
54717 +gr_acl_handle_access(const struct dentry * dentry,
54718 + const struct vfsmount * mnt, const int fmode)
54719 +{
54720 + return 1;
54721 +}
54722 +
54723 +__u32
54724 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
54725 + mode_t mode)
54726 +{
54727 + return 1;
54728 +}
54729 +
54730 +__u32
54731 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
54732 + mode_t mode)
54733 +{
54734 + return 1;
54735 +}
54736 +
54737 +__u32
54738 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
54739 +{
54740 + return 1;
54741 +}
54742 +
54743 +__u32
54744 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
54745 +{
54746 + return 1;
54747 +}
54748 +
54749 +void
54750 +grsecurity_init(void)
54751 +{
54752 + return;
54753 +}
54754 +
54755 +__u32
54756 +gr_acl_handle_mknod(const struct dentry * new_dentry,
54757 + const struct dentry * parent_dentry,
54758 + const struct vfsmount * parent_mnt,
54759 + const int mode)
54760 +{
54761 + return 1;
54762 +}
54763 +
54764 +__u32
54765 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
54766 + const struct dentry * parent_dentry,
54767 + const struct vfsmount * parent_mnt)
54768 +{
54769 + return 1;
54770 +}
54771 +
54772 +__u32
54773 +gr_acl_handle_symlink(const struct dentry * new_dentry,
54774 + const struct dentry * parent_dentry,
54775 + const struct vfsmount * parent_mnt, const char *from)
54776 +{
54777 + return 1;
54778 +}
54779 +
54780 +__u32
54781 +gr_acl_handle_link(const struct dentry * new_dentry,
54782 + const struct dentry * parent_dentry,
54783 + const struct vfsmount * parent_mnt,
54784 + const struct dentry * old_dentry,
54785 + const struct vfsmount * old_mnt, const char *to)
54786 +{
54787 + return 1;
54788 +}
54789 +
54790 +int
54791 +gr_acl_handle_rename(const struct dentry *new_dentry,
54792 + const struct dentry *parent_dentry,
54793 + const struct vfsmount *parent_mnt,
54794 + const struct dentry *old_dentry,
54795 + const struct inode *old_parent_inode,
54796 + const struct vfsmount *old_mnt, const char *newname)
54797 +{
54798 + return 0;
54799 +}
54800 +
54801 +int
54802 +gr_acl_handle_filldir(const struct file *file, const char *name,
54803 + const int namelen, const ino_t ino)
54804 +{
54805 + return 1;
54806 +}
54807 +
54808 +int
54809 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54810 + const time_t shm_createtime, const uid_t cuid, const int shmid)
54811 +{
54812 + return 1;
54813 +}
54814 +
54815 +int
54816 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
54817 +{
54818 + return 0;
54819 +}
54820 +
54821 +int
54822 +gr_search_accept(const struct socket *sock)
54823 +{
54824 + return 0;
54825 +}
54826 +
54827 +int
54828 +gr_search_listen(const struct socket *sock)
54829 +{
54830 + return 0;
54831 +}
54832 +
54833 +int
54834 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
54835 +{
54836 + return 0;
54837 +}
54838 +
54839 +__u32
54840 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
54841 +{
54842 + return 1;
54843 +}
54844 +
54845 +__u32
54846 +gr_acl_handle_creat(const struct dentry * dentry,
54847 + const struct dentry * p_dentry,
54848 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54849 + const int imode)
54850 +{
54851 + return 1;
54852 +}
54853 +
54854 +void
54855 +gr_acl_handle_exit(void)
54856 +{
54857 + return;
54858 +}
54859 +
54860 +int
54861 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54862 +{
54863 + return 1;
54864 +}
54865 +
54866 +void
54867 +gr_set_role_label(const uid_t uid, const gid_t gid)
54868 +{
54869 + return;
54870 +}
54871 +
54872 +int
54873 +gr_acl_handle_procpidmem(const struct task_struct *task)
54874 +{
54875 + return 0;
54876 +}
54877 +
54878 +int
54879 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
54880 +{
54881 + return 0;
54882 +}
54883 +
54884 +int
54885 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
54886 +{
54887 + return 0;
54888 +}
54889 +
54890 +void
54891 +gr_set_kernel_label(struct task_struct *task)
54892 +{
54893 + return;
54894 +}
54895 +
54896 +int
54897 +gr_check_user_change(int real, int effective, int fs)
54898 +{
54899 + return 0;
54900 +}
54901 +
54902 +int
54903 +gr_check_group_change(int real, int effective, int fs)
54904 +{
54905 + return 0;
54906 +}
54907 +
54908 +int gr_acl_enable_at_secure(void)
54909 +{
54910 + return 0;
54911 +}
54912 +
54913 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
54914 +{
54915 + return dentry->d_inode->i_sb->s_dev;
54916 +}
54917 +
54918 +EXPORT_SYMBOL(gr_learn_resource);
54919 +EXPORT_SYMBOL(gr_set_kernel_label);
54920 +#ifdef CONFIG_SECURITY
54921 +EXPORT_SYMBOL(gr_check_user_change);
54922 +EXPORT_SYMBOL(gr_check_group_change);
54923 +#endif
54924 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
54925 new file mode 100644
54926 index 0000000..2b05ada
54927 --- /dev/null
54928 +++ b/grsecurity/grsec_exec.c
54929 @@ -0,0 +1,146 @@
54930 +#include <linux/kernel.h>
54931 +#include <linux/sched.h>
54932 +#include <linux/file.h>
54933 +#include <linux/binfmts.h>
54934 +#include <linux/fs.h>
54935 +#include <linux/types.h>
54936 +#include <linux/grdefs.h>
54937 +#include <linux/grsecurity.h>
54938 +#include <linux/grinternal.h>
54939 +#include <linux/capability.h>
54940 +#include <linux/module.h>
54941 +
54942 +#include <asm/uaccess.h>
54943 +
54944 +#ifdef CONFIG_GRKERNSEC_EXECLOG
54945 +static char gr_exec_arg_buf[132];
54946 +static DEFINE_MUTEX(gr_exec_arg_mutex);
54947 +#endif
54948 +
54949 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
54950 +
54951 +void
54952 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
54953 +{
54954 +#ifdef CONFIG_GRKERNSEC_EXECLOG
54955 + char *grarg = gr_exec_arg_buf;
54956 + unsigned int i, x, execlen = 0;
54957 + char c;
54958 +
54959 + if (!((grsec_enable_execlog && grsec_enable_group &&
54960 + in_group_p(grsec_audit_gid))
54961 + || (grsec_enable_execlog && !grsec_enable_group)))
54962 + return;
54963 +
54964 + mutex_lock(&gr_exec_arg_mutex);
54965 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
54966 +
54967 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
54968 + const char __user *p;
54969 + unsigned int len;
54970 +
54971 + p = get_user_arg_ptr(argv, i);
54972 + if (IS_ERR(p))
54973 + goto log;
54974 +
54975 + len = strnlen_user(p, 128 - execlen);
54976 + if (len > 128 - execlen)
54977 + len = 128 - execlen;
54978 + else if (len > 0)
54979 + len--;
54980 + if (copy_from_user(grarg + execlen, p, len))
54981 + goto log;
54982 +
54983 + /* rewrite unprintable characters */
54984 + for (x = 0; x < len; x++) {
54985 + c = *(grarg + execlen + x);
54986 + if (c < 32 || c > 126)
54987 + *(grarg + execlen + x) = ' ';
54988 + }
54989 +
54990 + execlen += len;
54991 + *(grarg + execlen) = ' ';
54992 + *(grarg + execlen + 1) = '\0';
54993 + execlen++;
54994 + }
54995 +
54996 + log:
54997 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
54998 + bprm->file->f_path.mnt, grarg);
54999 + mutex_unlock(&gr_exec_arg_mutex);
55000 +#endif
55001 + return;
55002 +}
55003 +
55004 +#ifdef CONFIG_GRKERNSEC
55005 +extern int gr_acl_is_capable(const int cap);
55006 +extern int gr_acl_is_capable_nolog(const int cap);
55007 +extern int gr_chroot_is_capable(const int cap);
55008 +extern int gr_chroot_is_capable_nolog(const int cap);
55009 +#endif
55010 +
55011 +const char *captab_log[] = {
55012 + "CAP_CHOWN",
55013 + "CAP_DAC_OVERRIDE",
55014 + "CAP_DAC_READ_SEARCH",
55015 + "CAP_FOWNER",
55016 + "CAP_FSETID",
55017 + "CAP_KILL",
55018 + "CAP_SETGID",
55019 + "CAP_SETUID",
55020 + "CAP_SETPCAP",
55021 + "CAP_LINUX_IMMUTABLE",
55022 + "CAP_NET_BIND_SERVICE",
55023 + "CAP_NET_BROADCAST",
55024 + "CAP_NET_ADMIN",
55025 + "CAP_NET_RAW",
55026 + "CAP_IPC_LOCK",
55027 + "CAP_IPC_OWNER",
55028 + "CAP_SYS_MODULE",
55029 + "CAP_SYS_RAWIO",
55030 + "CAP_SYS_CHROOT",
55031 + "CAP_SYS_PTRACE",
55032 + "CAP_SYS_PACCT",
55033 + "CAP_SYS_ADMIN",
55034 + "CAP_SYS_BOOT",
55035 + "CAP_SYS_NICE",
55036 + "CAP_SYS_RESOURCE",
55037 + "CAP_SYS_TIME",
55038 + "CAP_SYS_TTY_CONFIG",
55039 + "CAP_MKNOD",
55040 + "CAP_LEASE",
55041 + "CAP_AUDIT_WRITE",
55042 + "CAP_AUDIT_CONTROL",
55043 + "CAP_SETFCAP",
55044 + "CAP_MAC_OVERRIDE",
55045 + "CAP_MAC_ADMIN",
55046 + "CAP_SYSLOG",
55047 + "CAP_WAKE_ALARM"
55048 +};
55049 +
55050 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
55051 +
55052 +int gr_is_capable(const int cap)
55053 +{
55054 +#ifdef CONFIG_GRKERNSEC
55055 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
55056 + return 1;
55057 + return 0;
55058 +#else
55059 + return 1;
55060 +#endif
55061 +}
55062 +
55063 +int gr_is_capable_nolog(const int cap)
55064 +{
55065 +#ifdef CONFIG_GRKERNSEC
55066 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
55067 + return 1;
55068 + return 0;
55069 +#else
55070 + return 1;
55071 +#endif
55072 +}
55073 +
55074 +EXPORT_SYMBOL(gr_is_capable);
55075 +EXPORT_SYMBOL(gr_is_capable_nolog);
55076 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
55077 new file mode 100644
55078 index 0000000..d3ee748
55079 --- /dev/null
55080 +++ b/grsecurity/grsec_fifo.c
55081 @@ -0,0 +1,24 @@
55082 +#include <linux/kernel.h>
55083 +#include <linux/sched.h>
55084 +#include <linux/fs.h>
55085 +#include <linux/file.h>
55086 +#include <linux/grinternal.h>
55087 +
55088 +int
55089 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
55090 + const struct dentry *dir, const int flag, const int acc_mode)
55091 +{
55092 +#ifdef CONFIG_GRKERNSEC_FIFO
55093 + const struct cred *cred = current_cred();
55094 +
55095 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
55096 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
55097 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
55098 + (cred->fsuid != dentry->d_inode->i_uid)) {
55099 + if (!inode_permission(dentry->d_inode, acc_mode))
55100 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
55101 + return -EACCES;
55102 + }
55103 +#endif
55104 + return 0;
55105 +}
55106 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
55107 new file mode 100644
55108 index 0000000..8ca18bf
55109 --- /dev/null
55110 +++ b/grsecurity/grsec_fork.c
55111 @@ -0,0 +1,23 @@
55112 +#include <linux/kernel.h>
55113 +#include <linux/sched.h>
55114 +#include <linux/grsecurity.h>
55115 +#include <linux/grinternal.h>
55116 +#include <linux/errno.h>
55117 +
55118 +void
55119 +gr_log_forkfail(const int retval)
55120 +{
55121 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
55122 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
55123 + switch (retval) {
55124 + case -EAGAIN:
55125 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
55126 + break;
55127 + case -ENOMEM:
55128 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
55129 + break;
55130 + }
55131 + }
55132 +#endif
55133 + return;
55134 +}
55135 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
55136 new file mode 100644
55137 index 0000000..01ddde4
55138 --- /dev/null
55139 +++ b/grsecurity/grsec_init.c
55140 @@ -0,0 +1,277 @@
55141 +#include <linux/kernel.h>
55142 +#include <linux/sched.h>
55143 +#include <linux/mm.h>
55144 +#include <linux/gracl.h>
55145 +#include <linux/slab.h>
55146 +#include <linux/vmalloc.h>
55147 +#include <linux/percpu.h>
55148 +#include <linux/module.h>
55149 +
55150 +int grsec_enable_ptrace_readexec;
55151 +int grsec_enable_setxid;
55152 +int grsec_enable_brute;
55153 +int grsec_enable_link;
55154 +int grsec_enable_dmesg;
55155 +int grsec_enable_harden_ptrace;
55156 +int grsec_enable_fifo;
55157 +int grsec_enable_execlog;
55158 +int grsec_enable_signal;
55159 +int grsec_enable_forkfail;
55160 +int grsec_enable_audit_ptrace;
55161 +int grsec_enable_time;
55162 +int grsec_enable_audit_textrel;
55163 +int grsec_enable_group;
55164 +int grsec_audit_gid;
55165 +int grsec_enable_chdir;
55166 +int grsec_enable_mount;
55167 +int grsec_enable_rofs;
55168 +int grsec_enable_chroot_findtask;
55169 +int grsec_enable_chroot_mount;
55170 +int grsec_enable_chroot_shmat;
55171 +int grsec_enable_chroot_fchdir;
55172 +int grsec_enable_chroot_double;
55173 +int grsec_enable_chroot_pivot;
55174 +int grsec_enable_chroot_chdir;
55175 +int grsec_enable_chroot_chmod;
55176 +int grsec_enable_chroot_mknod;
55177 +int grsec_enable_chroot_nice;
55178 +int grsec_enable_chroot_execlog;
55179 +int grsec_enable_chroot_caps;
55180 +int grsec_enable_chroot_sysctl;
55181 +int grsec_enable_chroot_unix;
55182 +int grsec_enable_tpe;
55183 +int grsec_tpe_gid;
55184 +int grsec_enable_blackhole;
55185 +#ifdef CONFIG_IPV6_MODULE
55186 +EXPORT_SYMBOL(grsec_enable_blackhole);
55187 +#endif
55188 +int grsec_lastack_retries;
55189 +int grsec_enable_tpe_all;
55190 +int grsec_enable_tpe_invert;
55191 +int grsec_enable_socket_all;
55192 +int grsec_socket_all_gid;
55193 +int grsec_enable_socket_client;
55194 +int grsec_socket_client_gid;
55195 +int grsec_enable_socket_server;
55196 +int grsec_socket_server_gid;
55197 +int grsec_resource_logging;
55198 +int grsec_disable_privio;
55199 +int grsec_enable_log_rwxmaps;
55200 +int grsec_lock;
55201 +
55202 +DEFINE_SPINLOCK(grsec_alert_lock);
55203 +unsigned long grsec_alert_wtime = 0;
55204 +unsigned long grsec_alert_fyet = 0;
55205 +
55206 +DEFINE_SPINLOCK(grsec_audit_lock);
55207 +
55208 +DEFINE_RWLOCK(grsec_exec_file_lock);
55209 +
55210 +char *gr_shared_page[4];
55211 +
55212 +char *gr_alert_log_fmt;
55213 +char *gr_audit_log_fmt;
55214 +char *gr_alert_log_buf;
55215 +char *gr_audit_log_buf;
55216 +
55217 +extern struct gr_arg *gr_usermode;
55218 +extern unsigned char *gr_system_salt;
55219 +extern unsigned char *gr_system_sum;
55220 +
55221 +void __init
55222 +grsecurity_init(void)
55223 +{
55224 + int j;
55225 + /* create the per-cpu shared pages */
55226 +
55227 +#ifdef CONFIG_X86
55228 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
55229 +#endif
55230 +
55231 + for (j = 0; j < 4; j++) {
55232 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
55233 + if (gr_shared_page[j] == NULL) {
55234 + panic("Unable to allocate grsecurity shared page");
55235 + return;
55236 + }
55237 + }
55238 +
55239 + /* allocate log buffers */
55240 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
55241 + if (!gr_alert_log_fmt) {
55242 + panic("Unable to allocate grsecurity alert log format buffer");
55243 + return;
55244 + }
55245 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
55246 + if (!gr_audit_log_fmt) {
55247 + panic("Unable to allocate grsecurity audit log format buffer");
55248 + return;
55249 + }
55250 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
55251 + if (!gr_alert_log_buf) {
55252 + panic("Unable to allocate grsecurity alert log buffer");
55253 + return;
55254 + }
55255 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
55256 + if (!gr_audit_log_buf) {
55257 + panic("Unable to allocate grsecurity audit log buffer");
55258 + return;
55259 + }
55260 +
55261 + /* allocate memory for authentication structure */
55262 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
55263 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
55264 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
55265 +
55266 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
55267 + panic("Unable to allocate grsecurity authentication structure");
55268 + return;
55269 + }
55270 +
55271 +
55272 +#ifdef CONFIG_GRKERNSEC_IO
55273 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
55274 + grsec_disable_privio = 1;
55275 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
55276 + grsec_disable_privio = 1;
55277 +#else
55278 + grsec_disable_privio = 0;
55279 +#endif
55280 +#endif
55281 +
55282 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
55283 + /* for backward compatibility, tpe_invert always defaults to on if
55284 + enabled in the kernel
55285 + */
55286 + grsec_enable_tpe_invert = 1;
55287 +#endif
55288 +
55289 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
55290 +#ifndef CONFIG_GRKERNSEC_SYSCTL
55291 + grsec_lock = 1;
55292 +#endif
55293 +
55294 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
55295 + grsec_enable_audit_textrel = 1;
55296 +#endif
55297 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55298 + grsec_enable_log_rwxmaps = 1;
55299 +#endif
55300 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
55301 + grsec_enable_group = 1;
55302 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
55303 +#endif
55304 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
55305 + grsec_enable_ptrace_readexec = 1;
55306 +#endif
55307 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55308 + grsec_enable_chdir = 1;
55309 +#endif
55310 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55311 + grsec_enable_harden_ptrace = 1;
55312 +#endif
55313 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55314 + grsec_enable_mount = 1;
55315 +#endif
55316 +#ifdef CONFIG_GRKERNSEC_LINK
55317 + grsec_enable_link = 1;
55318 +#endif
55319 +#ifdef CONFIG_GRKERNSEC_BRUTE
55320 + grsec_enable_brute = 1;
55321 +#endif
55322 +#ifdef CONFIG_GRKERNSEC_DMESG
55323 + grsec_enable_dmesg = 1;
55324 +#endif
55325 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
55326 + grsec_enable_blackhole = 1;
55327 + grsec_lastack_retries = 4;
55328 +#endif
55329 +#ifdef CONFIG_GRKERNSEC_FIFO
55330 + grsec_enable_fifo = 1;
55331 +#endif
55332 +#ifdef CONFIG_GRKERNSEC_EXECLOG
55333 + grsec_enable_execlog = 1;
55334 +#endif
55335 +#ifdef CONFIG_GRKERNSEC_SETXID
55336 + grsec_enable_setxid = 1;
55337 +#endif
55338 +#ifdef CONFIG_GRKERNSEC_SIGNAL
55339 + grsec_enable_signal = 1;
55340 +#endif
55341 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
55342 + grsec_enable_forkfail = 1;
55343 +#endif
55344 +#ifdef CONFIG_GRKERNSEC_TIME
55345 + grsec_enable_time = 1;
55346 +#endif
55347 +#ifdef CONFIG_GRKERNSEC_RESLOG
55348 + grsec_resource_logging = 1;
55349 +#endif
55350 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55351 + grsec_enable_chroot_findtask = 1;
55352 +#endif
55353 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55354 + grsec_enable_chroot_unix = 1;
55355 +#endif
55356 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
55357 + grsec_enable_chroot_mount = 1;
55358 +#endif
55359 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
55360 + grsec_enable_chroot_fchdir = 1;
55361 +#endif
55362 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
55363 + grsec_enable_chroot_shmat = 1;
55364 +#endif
55365 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
55366 + grsec_enable_audit_ptrace = 1;
55367 +#endif
55368 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
55369 + grsec_enable_chroot_double = 1;
55370 +#endif
55371 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
55372 + grsec_enable_chroot_pivot = 1;
55373 +#endif
55374 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
55375 + grsec_enable_chroot_chdir = 1;
55376 +#endif
55377 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
55378 + grsec_enable_chroot_chmod = 1;
55379 +#endif
55380 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
55381 + grsec_enable_chroot_mknod = 1;
55382 +#endif
55383 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55384 + grsec_enable_chroot_nice = 1;
55385 +#endif
55386 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
55387 + grsec_enable_chroot_execlog = 1;
55388 +#endif
55389 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55390 + grsec_enable_chroot_caps = 1;
55391 +#endif
55392 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
55393 + grsec_enable_chroot_sysctl = 1;
55394 +#endif
55395 +#ifdef CONFIG_GRKERNSEC_TPE
55396 + grsec_enable_tpe = 1;
55397 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
55398 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
55399 + grsec_enable_tpe_all = 1;
55400 +#endif
55401 +#endif
55402 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
55403 + grsec_enable_socket_all = 1;
55404 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
55405 +#endif
55406 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
55407 + grsec_enable_socket_client = 1;
55408 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
55409 +#endif
55410 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
55411 + grsec_enable_socket_server = 1;
55412 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
55413 +#endif
55414 +#endif
55415 +
55416 + return;
55417 +}
55418 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
55419 new file mode 100644
55420 index 0000000..3efe141
55421 --- /dev/null
55422 +++ b/grsecurity/grsec_link.c
55423 @@ -0,0 +1,43 @@
55424 +#include <linux/kernel.h>
55425 +#include <linux/sched.h>
55426 +#include <linux/fs.h>
55427 +#include <linux/file.h>
55428 +#include <linux/grinternal.h>
55429 +
55430 +int
55431 +gr_handle_follow_link(const struct inode *parent,
55432 + const struct inode *inode,
55433 + const struct dentry *dentry, const struct vfsmount *mnt)
55434 +{
55435 +#ifdef CONFIG_GRKERNSEC_LINK
55436 + const struct cred *cred = current_cred();
55437 +
55438 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
55439 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
55440 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
55441 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
55442 + return -EACCES;
55443 + }
55444 +#endif
55445 + return 0;
55446 +}
55447 +
55448 +int
55449 +gr_handle_hardlink(const struct dentry *dentry,
55450 + const struct vfsmount *mnt,
55451 + struct inode *inode, const int mode, const char *to)
55452 +{
55453 +#ifdef CONFIG_GRKERNSEC_LINK
55454 + const struct cred *cred = current_cred();
55455 +
55456 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
55457 + (!S_ISREG(mode) || (mode & S_ISUID) ||
55458 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
55459 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
55460 + !capable(CAP_FOWNER) && cred->uid) {
55461 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
55462 + return -EPERM;
55463 + }
55464 +#endif
55465 + return 0;
55466 +}
55467 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
55468 new file mode 100644
55469 index 0000000..a45d2e9
55470 --- /dev/null
55471 +++ b/grsecurity/grsec_log.c
55472 @@ -0,0 +1,322 @@
55473 +#include <linux/kernel.h>
55474 +#include <linux/sched.h>
55475 +#include <linux/file.h>
55476 +#include <linux/tty.h>
55477 +#include <linux/fs.h>
55478 +#include <linux/grinternal.h>
55479 +
55480 +#ifdef CONFIG_TREE_PREEMPT_RCU
55481 +#define DISABLE_PREEMPT() preempt_disable()
55482 +#define ENABLE_PREEMPT() preempt_enable()
55483 +#else
55484 +#define DISABLE_PREEMPT()
55485 +#define ENABLE_PREEMPT()
55486 +#endif
55487 +
55488 +#define BEGIN_LOCKS(x) \
55489 + DISABLE_PREEMPT(); \
55490 + rcu_read_lock(); \
55491 + read_lock(&tasklist_lock); \
55492 + read_lock(&grsec_exec_file_lock); \
55493 + if (x != GR_DO_AUDIT) \
55494 + spin_lock(&grsec_alert_lock); \
55495 + else \
55496 + spin_lock(&grsec_audit_lock)
55497 +
55498 +#define END_LOCKS(x) \
55499 + if (x != GR_DO_AUDIT) \
55500 + spin_unlock(&grsec_alert_lock); \
55501 + else \
55502 + spin_unlock(&grsec_audit_lock); \
55503 + read_unlock(&grsec_exec_file_lock); \
55504 + read_unlock(&tasklist_lock); \
55505 + rcu_read_unlock(); \
55506 + ENABLE_PREEMPT(); \
55507 + if (x == GR_DONT_AUDIT) \
55508 + gr_handle_alertkill(current)
55509 +
55510 +enum {
55511 + FLOODING,
55512 + NO_FLOODING
55513 +};
55514 +
55515 +extern char *gr_alert_log_fmt;
55516 +extern char *gr_audit_log_fmt;
55517 +extern char *gr_alert_log_buf;
55518 +extern char *gr_audit_log_buf;
55519 +
55520 +static int gr_log_start(int audit)
55521 +{
55522 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
55523 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
55524 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55525 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
55526 + unsigned long curr_secs = get_seconds();
55527 +
55528 + if (audit == GR_DO_AUDIT)
55529 + goto set_fmt;
55530 +
55531 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
55532 + grsec_alert_wtime = curr_secs;
55533 + grsec_alert_fyet = 0;
55534 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
55535 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
55536 + grsec_alert_fyet++;
55537 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
55538 + grsec_alert_wtime = curr_secs;
55539 + grsec_alert_fyet++;
55540 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
55541 + return FLOODING;
55542 + }
55543 + else return FLOODING;
55544 +
55545 +set_fmt:
55546 +#endif
55547 + memset(buf, 0, PAGE_SIZE);
55548 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
55549 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
55550 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
55551 + } else if (current->signal->curr_ip) {
55552 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
55553 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
55554 + } else if (gr_acl_is_enabled()) {
55555 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
55556 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
55557 + } else {
55558 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
55559 + strcpy(buf, fmt);
55560 + }
55561 +
55562 + return NO_FLOODING;
55563 +}
55564 +
55565 +static void gr_log_middle(int audit, const char *msg, va_list ap)
55566 + __attribute__ ((format (printf, 2, 0)));
55567 +
55568 +static void gr_log_middle(int audit, const char *msg, va_list ap)
55569 +{
55570 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55571 + unsigned int len = strlen(buf);
55572 +
55573 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
55574 +
55575 + return;
55576 +}
55577 +
55578 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
55579 + __attribute__ ((format (printf, 2, 3)));
55580 +
55581 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
55582 +{
55583 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55584 + unsigned int len = strlen(buf);
55585 + va_list ap;
55586 +
55587 + va_start(ap, msg);
55588 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
55589 + va_end(ap);
55590 +
55591 + return;
55592 +}
55593 +
55594 +static void gr_log_end(int audit, int append_default)
55595 +{
55596 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55597 +
55598 + if (append_default) {
55599 + unsigned int len = strlen(buf);
55600 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
55601 + }
55602 +
55603 + printk("%s\n", buf);
55604 +
55605 + return;
55606 +}
55607 +
55608 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
55609 +{
55610 + int logtype;
55611 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
55612 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
55613 + void *voidptr = NULL;
55614 + int num1 = 0, num2 = 0;
55615 + unsigned long ulong1 = 0, ulong2 = 0;
55616 + struct dentry *dentry = NULL;
55617 + struct vfsmount *mnt = NULL;
55618 + struct file *file = NULL;
55619 + struct task_struct *task = NULL;
55620 + const struct cred *cred, *pcred;
55621 + va_list ap;
55622 +
55623 + BEGIN_LOCKS(audit);
55624 + logtype = gr_log_start(audit);
55625 + if (logtype == FLOODING) {
55626 + END_LOCKS(audit);
55627 + return;
55628 + }
55629 + va_start(ap, argtypes);
55630 + switch (argtypes) {
55631 + case GR_TTYSNIFF:
55632 + task = va_arg(ap, struct task_struct *);
55633 + 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);
55634 + break;
55635 + case GR_SYSCTL_HIDDEN:
55636 + str1 = va_arg(ap, char *);
55637 + gr_log_middle_varargs(audit, msg, result, str1);
55638 + break;
55639 + case GR_RBAC:
55640 + dentry = va_arg(ap, struct dentry *);
55641 + mnt = va_arg(ap, struct vfsmount *);
55642 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
55643 + break;
55644 + case GR_RBAC_STR:
55645 + dentry = va_arg(ap, struct dentry *);
55646 + mnt = va_arg(ap, struct vfsmount *);
55647 + str1 = va_arg(ap, char *);
55648 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
55649 + break;
55650 + case GR_STR_RBAC:
55651 + str1 = va_arg(ap, char *);
55652 + dentry = va_arg(ap, struct dentry *);
55653 + mnt = va_arg(ap, struct vfsmount *);
55654 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
55655 + break;
55656 + case GR_RBAC_MODE2:
55657 + dentry = va_arg(ap, struct dentry *);
55658 + mnt = va_arg(ap, struct vfsmount *);
55659 + str1 = va_arg(ap, char *);
55660 + str2 = va_arg(ap, char *);
55661 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
55662 + break;
55663 + case GR_RBAC_MODE3:
55664 + dentry = va_arg(ap, struct dentry *);
55665 + mnt = va_arg(ap, struct vfsmount *);
55666 + str1 = va_arg(ap, char *);
55667 + str2 = va_arg(ap, char *);
55668 + str3 = va_arg(ap, char *);
55669 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
55670 + break;
55671 + case GR_FILENAME:
55672 + dentry = va_arg(ap, struct dentry *);
55673 + mnt = va_arg(ap, struct vfsmount *);
55674 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
55675 + break;
55676 + case GR_STR_FILENAME:
55677 + str1 = va_arg(ap, char *);
55678 + dentry = va_arg(ap, struct dentry *);
55679 + mnt = va_arg(ap, struct vfsmount *);
55680 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
55681 + break;
55682 + case GR_FILENAME_STR:
55683 + dentry = va_arg(ap, struct dentry *);
55684 + mnt = va_arg(ap, struct vfsmount *);
55685 + str1 = va_arg(ap, char *);
55686 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
55687 + break;
55688 + case GR_FILENAME_TWO_INT:
55689 + dentry = va_arg(ap, struct dentry *);
55690 + mnt = va_arg(ap, struct vfsmount *);
55691 + num1 = va_arg(ap, int);
55692 + num2 = va_arg(ap, int);
55693 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
55694 + break;
55695 + case GR_FILENAME_TWO_INT_STR:
55696 + dentry = va_arg(ap, struct dentry *);
55697 + mnt = va_arg(ap, struct vfsmount *);
55698 + num1 = va_arg(ap, int);
55699 + num2 = va_arg(ap, int);
55700 + str1 = va_arg(ap, char *);
55701 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
55702 + break;
55703 + case GR_TEXTREL:
55704 + file = va_arg(ap, struct file *);
55705 + ulong1 = va_arg(ap, unsigned long);
55706 + ulong2 = va_arg(ap, unsigned long);
55707 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
55708 + break;
55709 + case GR_PTRACE:
55710 + task = va_arg(ap, struct task_struct *);
55711 + 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);
55712 + break;
55713 + case GR_RESOURCE:
55714 + task = va_arg(ap, struct task_struct *);
55715 + cred = __task_cred(task);
55716 + pcred = __task_cred(task->real_parent);
55717 + ulong1 = va_arg(ap, unsigned long);
55718 + str1 = va_arg(ap, char *);
55719 + ulong2 = va_arg(ap, unsigned long);
55720 + 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);
55721 + break;
55722 + case GR_CAP:
55723 + task = va_arg(ap, struct task_struct *);
55724 + cred = __task_cred(task);
55725 + pcred = __task_cred(task->real_parent);
55726 + str1 = va_arg(ap, char *);
55727 + 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);
55728 + break;
55729 + case GR_SIG:
55730 + str1 = va_arg(ap, char *);
55731 + voidptr = va_arg(ap, void *);
55732 + gr_log_middle_varargs(audit, msg, str1, voidptr);
55733 + break;
55734 + case GR_SIG2:
55735 + task = va_arg(ap, struct task_struct *);
55736 + cred = __task_cred(task);
55737 + pcred = __task_cred(task->real_parent);
55738 + num1 = va_arg(ap, int);
55739 + 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);
55740 + break;
55741 + case GR_CRASH1:
55742 + task = va_arg(ap, struct task_struct *);
55743 + cred = __task_cred(task);
55744 + pcred = __task_cred(task->real_parent);
55745 + ulong1 = va_arg(ap, unsigned long);
55746 + 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);
55747 + break;
55748 + case GR_CRASH2:
55749 + task = va_arg(ap, struct task_struct *);
55750 + cred = __task_cred(task);
55751 + pcred = __task_cred(task->real_parent);
55752 + ulong1 = va_arg(ap, unsigned long);
55753 + 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);
55754 + break;
55755 + case GR_RWXMAP:
55756 + file = va_arg(ap, struct file *);
55757 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
55758 + break;
55759 + case GR_PSACCT:
55760 + {
55761 + unsigned int wday, cday;
55762 + __u8 whr, chr;
55763 + __u8 wmin, cmin;
55764 + __u8 wsec, csec;
55765 + char cur_tty[64] = { 0 };
55766 + char parent_tty[64] = { 0 };
55767 +
55768 + task = va_arg(ap, struct task_struct *);
55769 + wday = va_arg(ap, unsigned int);
55770 + cday = va_arg(ap, unsigned int);
55771 + whr = va_arg(ap, int);
55772 + chr = va_arg(ap, int);
55773 + wmin = va_arg(ap, int);
55774 + cmin = va_arg(ap, int);
55775 + wsec = va_arg(ap, int);
55776 + csec = va_arg(ap, int);
55777 + ulong1 = va_arg(ap, unsigned long);
55778 + cred = __task_cred(task);
55779 + pcred = __task_cred(task->real_parent);
55780 +
55781 + 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);
55782 + }
55783 + break;
55784 + default:
55785 + gr_log_middle(audit, msg, ap);
55786 + }
55787 + va_end(ap);
55788 + // these don't need DEFAULTSECARGS printed on the end
55789 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
55790 + gr_log_end(audit, 0);
55791 + else
55792 + gr_log_end(audit, 1);
55793 + END_LOCKS(audit);
55794 +}
55795 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
55796 new file mode 100644
55797 index 0000000..f536303
55798 --- /dev/null
55799 +++ b/grsecurity/grsec_mem.c
55800 @@ -0,0 +1,40 @@
55801 +#include <linux/kernel.h>
55802 +#include <linux/sched.h>
55803 +#include <linux/mm.h>
55804 +#include <linux/mman.h>
55805 +#include <linux/grinternal.h>
55806 +
55807 +void
55808 +gr_handle_ioperm(void)
55809 +{
55810 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
55811 + return;
55812 +}
55813 +
55814 +void
55815 +gr_handle_iopl(void)
55816 +{
55817 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
55818 + return;
55819 +}
55820 +
55821 +void
55822 +gr_handle_mem_readwrite(u64 from, u64 to)
55823 +{
55824 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
55825 + return;
55826 +}
55827 +
55828 +void
55829 +gr_handle_vm86(void)
55830 +{
55831 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
55832 + return;
55833 +}
55834 +
55835 +void
55836 +gr_log_badprocpid(const char *entry)
55837 +{
55838 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
55839 + return;
55840 +}
55841 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
55842 new file mode 100644
55843 index 0000000..2131422
55844 --- /dev/null
55845 +++ b/grsecurity/grsec_mount.c
55846 @@ -0,0 +1,62 @@
55847 +#include <linux/kernel.h>
55848 +#include <linux/sched.h>
55849 +#include <linux/mount.h>
55850 +#include <linux/grsecurity.h>
55851 +#include <linux/grinternal.h>
55852 +
55853 +void
55854 +gr_log_remount(const char *devname, const int retval)
55855 +{
55856 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55857 + if (grsec_enable_mount && (retval >= 0))
55858 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
55859 +#endif
55860 + return;
55861 +}
55862 +
55863 +void
55864 +gr_log_unmount(const char *devname, const int retval)
55865 +{
55866 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55867 + if (grsec_enable_mount && (retval >= 0))
55868 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
55869 +#endif
55870 + return;
55871 +}
55872 +
55873 +void
55874 +gr_log_mount(const char *from, const char *to, const int retval)
55875 +{
55876 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55877 + if (grsec_enable_mount && (retval >= 0))
55878 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
55879 +#endif
55880 + return;
55881 +}
55882 +
55883 +int
55884 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
55885 +{
55886 +#ifdef CONFIG_GRKERNSEC_ROFS
55887 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
55888 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
55889 + return -EPERM;
55890 + } else
55891 + return 0;
55892 +#endif
55893 + return 0;
55894 +}
55895 +
55896 +int
55897 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
55898 +{
55899 +#ifdef CONFIG_GRKERNSEC_ROFS
55900 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
55901 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
55902 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
55903 + return -EPERM;
55904 + } else
55905 + return 0;
55906 +#endif
55907 + return 0;
55908 +}
55909 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
55910 new file mode 100644
55911 index 0000000..a3b12a0
55912 --- /dev/null
55913 +++ b/grsecurity/grsec_pax.c
55914 @@ -0,0 +1,36 @@
55915 +#include <linux/kernel.h>
55916 +#include <linux/sched.h>
55917 +#include <linux/mm.h>
55918 +#include <linux/file.h>
55919 +#include <linux/grinternal.h>
55920 +#include <linux/grsecurity.h>
55921 +
55922 +void
55923 +gr_log_textrel(struct vm_area_struct * vma)
55924 +{
55925 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
55926 + if (grsec_enable_audit_textrel)
55927 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
55928 +#endif
55929 + return;
55930 +}
55931 +
55932 +void
55933 +gr_log_rwxmmap(struct file *file)
55934 +{
55935 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55936 + if (grsec_enable_log_rwxmaps)
55937 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
55938 +#endif
55939 + return;
55940 +}
55941 +
55942 +void
55943 +gr_log_rwxmprotect(struct file *file)
55944 +{
55945 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55946 + if (grsec_enable_log_rwxmaps)
55947 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
55948 +#endif
55949 + return;
55950 +}
55951 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
55952 new file mode 100644
55953 index 0000000..f7f29aa
55954 --- /dev/null
55955 +++ b/grsecurity/grsec_ptrace.c
55956 @@ -0,0 +1,30 @@
55957 +#include <linux/kernel.h>
55958 +#include <linux/sched.h>
55959 +#include <linux/grinternal.h>
55960 +#include <linux/security.h>
55961 +
55962 +void
55963 +gr_audit_ptrace(struct task_struct *task)
55964 +{
55965 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
55966 + if (grsec_enable_audit_ptrace)
55967 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
55968 +#endif
55969 + return;
55970 +}
55971 +
55972 +int
55973 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
55974 +{
55975 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
55976 + const struct dentry *dentry = file->f_path.dentry;
55977 + const struct vfsmount *mnt = file->f_path.mnt;
55978 +
55979 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
55980 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
55981 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
55982 + return -EACCES;
55983 + }
55984 +#endif
55985 + return 0;
55986 +}
55987 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
55988 new file mode 100644
55989 index 0000000..7a5b2de
55990 --- /dev/null
55991 +++ b/grsecurity/grsec_sig.c
55992 @@ -0,0 +1,207 @@
55993 +#include <linux/kernel.h>
55994 +#include <linux/sched.h>
55995 +#include <linux/delay.h>
55996 +#include <linux/grsecurity.h>
55997 +#include <linux/grinternal.h>
55998 +#include <linux/hardirq.h>
55999 +
56000 +char *signames[] = {
56001 + [SIGSEGV] = "Segmentation fault",
56002 + [SIGILL] = "Illegal instruction",
56003 + [SIGABRT] = "Abort",
56004 + [SIGBUS] = "Invalid alignment/Bus error"
56005 +};
56006 +
56007 +void
56008 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
56009 +{
56010 +#ifdef CONFIG_GRKERNSEC_SIGNAL
56011 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
56012 + (sig == SIGABRT) || (sig == SIGBUS))) {
56013 + if (t->pid == current->pid) {
56014 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
56015 + } else {
56016 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
56017 + }
56018 + }
56019 +#endif
56020 + return;
56021 +}
56022 +
56023 +int
56024 +gr_handle_signal(const struct task_struct *p, const int sig)
56025 +{
56026 +#ifdef CONFIG_GRKERNSEC
56027 + /* ignore the 0 signal for protected task checks */
56028 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
56029 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
56030 + return -EPERM;
56031 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
56032 + return -EPERM;
56033 + }
56034 +#endif
56035 + return 0;
56036 +}
56037 +
56038 +#ifdef CONFIG_GRKERNSEC
56039 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
56040 +
56041 +int gr_fake_force_sig(int sig, struct task_struct *t)
56042 +{
56043 + unsigned long int flags;
56044 + int ret, blocked, ignored;
56045 + struct k_sigaction *action;
56046 +
56047 + spin_lock_irqsave(&t->sighand->siglock, flags);
56048 + action = &t->sighand->action[sig-1];
56049 + ignored = action->sa.sa_handler == SIG_IGN;
56050 + blocked = sigismember(&t->blocked, sig);
56051 + if (blocked || ignored) {
56052 + action->sa.sa_handler = SIG_DFL;
56053 + if (blocked) {
56054 + sigdelset(&t->blocked, sig);
56055 + recalc_sigpending_and_wake(t);
56056 + }
56057 + }
56058 + if (action->sa.sa_handler == SIG_DFL)
56059 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
56060 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
56061 +
56062 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
56063 +
56064 + return ret;
56065 +}
56066 +#endif
56067 +
56068 +#ifdef CONFIG_GRKERNSEC_BRUTE
56069 +#define GR_USER_BAN_TIME (15 * 60)
56070 +
56071 +static int __get_dumpable(unsigned long mm_flags)
56072 +{
56073 + int ret;
56074 +
56075 + ret = mm_flags & MMF_DUMPABLE_MASK;
56076 + return (ret >= 2) ? 2 : ret;
56077 +}
56078 +#endif
56079 +
56080 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
56081 +{
56082 +#ifdef CONFIG_GRKERNSEC_BRUTE
56083 + uid_t uid = 0;
56084 +
56085 + if (!grsec_enable_brute)
56086 + return;
56087 +
56088 + rcu_read_lock();
56089 + read_lock(&tasklist_lock);
56090 + read_lock(&grsec_exec_file_lock);
56091 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
56092 + p->real_parent->brute = 1;
56093 + else {
56094 + const struct cred *cred = __task_cred(p), *cred2;
56095 + struct task_struct *tsk, *tsk2;
56096 +
56097 + if (!__get_dumpable(mm_flags) && cred->uid) {
56098 + struct user_struct *user;
56099 +
56100 + uid = cred->uid;
56101 +
56102 + /* this is put upon execution past expiration */
56103 + user = find_user(uid);
56104 + if (user == NULL)
56105 + goto unlock;
56106 + user->banned = 1;
56107 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
56108 + if (user->ban_expires == ~0UL)
56109 + user->ban_expires--;
56110 +
56111 + do_each_thread(tsk2, tsk) {
56112 + cred2 = __task_cred(tsk);
56113 + if (tsk != p && cred2->uid == uid)
56114 + gr_fake_force_sig(SIGKILL, tsk);
56115 + } while_each_thread(tsk2, tsk);
56116 + }
56117 + }
56118 +unlock:
56119 + read_unlock(&grsec_exec_file_lock);
56120 + read_unlock(&tasklist_lock);
56121 + rcu_read_unlock();
56122 +
56123 + if (uid)
56124 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
56125 +
56126 +#endif
56127 + return;
56128 +}
56129 +
56130 +void gr_handle_brute_check(void)
56131 +{
56132 +#ifdef CONFIG_GRKERNSEC_BRUTE
56133 + if (current->brute)
56134 + msleep(30 * 1000);
56135 +#endif
56136 + return;
56137 +}
56138 +
56139 +void gr_handle_kernel_exploit(void)
56140 +{
56141 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
56142 + const struct cred *cred;
56143 + struct task_struct *tsk, *tsk2;
56144 + struct user_struct *user;
56145 + uid_t uid;
56146 +
56147 + if (in_irq() || in_serving_softirq() || in_nmi())
56148 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
56149 +
56150 + uid = current_uid();
56151 +
56152 + if (uid == 0)
56153 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
56154 + else {
56155 + /* kill all the processes of this user, hold a reference
56156 + to their creds struct, and prevent them from creating
56157 + another process until system reset
56158 + */
56159 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
56160 + /* we intentionally leak this ref */
56161 + user = get_uid(current->cred->user);
56162 + if (user) {
56163 + user->banned = 1;
56164 + user->ban_expires = ~0UL;
56165 + }
56166 +
56167 + read_lock(&tasklist_lock);
56168 + do_each_thread(tsk2, tsk) {
56169 + cred = __task_cred(tsk);
56170 + if (cred->uid == uid)
56171 + gr_fake_force_sig(SIGKILL, tsk);
56172 + } while_each_thread(tsk2, tsk);
56173 + read_unlock(&tasklist_lock);
56174 + }
56175 +#endif
56176 +}
56177 +
56178 +int __gr_process_user_ban(struct user_struct *user)
56179 +{
56180 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56181 + if (unlikely(user->banned)) {
56182 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
56183 + user->banned = 0;
56184 + user->ban_expires = 0;
56185 + free_uid(user);
56186 + } else
56187 + return -EPERM;
56188 + }
56189 +#endif
56190 + return 0;
56191 +}
56192 +
56193 +int gr_process_user_ban(void)
56194 +{
56195 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56196 + return __gr_process_user_ban(current->cred->user);
56197 +#endif
56198 + return 0;
56199 +}
56200 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
56201 new file mode 100644
56202 index 0000000..4030d57
56203 --- /dev/null
56204 +++ b/grsecurity/grsec_sock.c
56205 @@ -0,0 +1,244 @@
56206 +#include <linux/kernel.h>
56207 +#include <linux/module.h>
56208 +#include <linux/sched.h>
56209 +#include <linux/file.h>
56210 +#include <linux/net.h>
56211 +#include <linux/in.h>
56212 +#include <linux/ip.h>
56213 +#include <net/sock.h>
56214 +#include <net/inet_sock.h>
56215 +#include <linux/grsecurity.h>
56216 +#include <linux/grinternal.h>
56217 +#include <linux/gracl.h>
56218 +
56219 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
56220 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
56221 +
56222 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
56223 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
56224 +
56225 +#ifdef CONFIG_UNIX_MODULE
56226 +EXPORT_SYMBOL(gr_acl_handle_unix);
56227 +EXPORT_SYMBOL(gr_acl_handle_mknod);
56228 +EXPORT_SYMBOL(gr_handle_chroot_unix);
56229 +EXPORT_SYMBOL(gr_handle_create);
56230 +#endif
56231 +
56232 +#ifdef CONFIG_GRKERNSEC
56233 +#define gr_conn_table_size 32749
56234 +struct conn_table_entry {
56235 + struct conn_table_entry *next;
56236 + struct signal_struct *sig;
56237 +};
56238 +
56239 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
56240 +DEFINE_SPINLOCK(gr_conn_table_lock);
56241 +
56242 +extern const char * gr_socktype_to_name(unsigned char type);
56243 +extern const char * gr_proto_to_name(unsigned char proto);
56244 +extern const char * gr_sockfamily_to_name(unsigned char family);
56245 +
56246 +static __inline__ int
56247 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
56248 +{
56249 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
56250 +}
56251 +
56252 +static __inline__ int
56253 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
56254 + __u16 sport, __u16 dport)
56255 +{
56256 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
56257 + sig->gr_sport == sport && sig->gr_dport == dport))
56258 + return 1;
56259 + else
56260 + return 0;
56261 +}
56262 +
56263 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
56264 +{
56265 + struct conn_table_entry **match;
56266 + unsigned int index;
56267 +
56268 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
56269 + sig->gr_sport, sig->gr_dport,
56270 + gr_conn_table_size);
56271 +
56272 + newent->sig = sig;
56273 +
56274 + match = &gr_conn_table[index];
56275 + newent->next = *match;
56276 + *match = newent;
56277 +
56278 + return;
56279 +}
56280 +
56281 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
56282 +{
56283 + struct conn_table_entry *match, *last = NULL;
56284 + unsigned int index;
56285 +
56286 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
56287 + sig->gr_sport, sig->gr_dport,
56288 + gr_conn_table_size);
56289 +
56290 + match = gr_conn_table[index];
56291 + while (match && !conn_match(match->sig,
56292 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
56293 + sig->gr_dport)) {
56294 + last = match;
56295 + match = match->next;
56296 + }
56297 +
56298 + if (match) {
56299 + if (last)
56300 + last->next = match->next;
56301 + else
56302 + gr_conn_table[index] = NULL;
56303 + kfree(match);
56304 + }
56305 +
56306 + return;
56307 +}
56308 +
56309 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
56310 + __u16 sport, __u16 dport)
56311 +{
56312 + struct conn_table_entry *match;
56313 + unsigned int index;
56314 +
56315 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
56316 +
56317 + match = gr_conn_table[index];
56318 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
56319 + match = match->next;
56320 +
56321 + if (match)
56322 + return match->sig;
56323 + else
56324 + return NULL;
56325 +}
56326 +
56327 +#endif
56328 +
56329 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
56330 +{
56331 +#ifdef CONFIG_GRKERNSEC
56332 + struct signal_struct *sig = task->signal;
56333 + struct conn_table_entry *newent;
56334 +
56335 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
56336 + if (newent == NULL)
56337 + return;
56338 + /* no bh lock needed since we are called with bh disabled */
56339 + spin_lock(&gr_conn_table_lock);
56340 + gr_del_task_from_ip_table_nolock(sig);
56341 + sig->gr_saddr = inet->inet_rcv_saddr;
56342 + sig->gr_daddr = inet->inet_daddr;
56343 + sig->gr_sport = inet->inet_sport;
56344 + sig->gr_dport = inet->inet_dport;
56345 + gr_add_to_task_ip_table_nolock(sig, newent);
56346 + spin_unlock(&gr_conn_table_lock);
56347 +#endif
56348 + return;
56349 +}
56350 +
56351 +void gr_del_task_from_ip_table(struct task_struct *task)
56352 +{
56353 +#ifdef CONFIG_GRKERNSEC
56354 + spin_lock_bh(&gr_conn_table_lock);
56355 + gr_del_task_from_ip_table_nolock(task->signal);
56356 + spin_unlock_bh(&gr_conn_table_lock);
56357 +#endif
56358 + return;
56359 +}
56360 +
56361 +void
56362 +gr_attach_curr_ip(const struct sock *sk)
56363 +{
56364 +#ifdef CONFIG_GRKERNSEC
56365 + struct signal_struct *p, *set;
56366 + const struct inet_sock *inet = inet_sk(sk);
56367 +
56368 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
56369 + return;
56370 +
56371 + set = current->signal;
56372 +
56373 + spin_lock_bh(&gr_conn_table_lock);
56374 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
56375 + inet->inet_dport, inet->inet_sport);
56376 + if (unlikely(p != NULL)) {
56377 + set->curr_ip = p->curr_ip;
56378 + set->used_accept = 1;
56379 + gr_del_task_from_ip_table_nolock(p);
56380 + spin_unlock_bh(&gr_conn_table_lock);
56381 + return;
56382 + }
56383 + spin_unlock_bh(&gr_conn_table_lock);
56384 +
56385 + set->curr_ip = inet->inet_daddr;
56386 + set->used_accept = 1;
56387 +#endif
56388 + return;
56389 +}
56390 +
56391 +int
56392 +gr_handle_sock_all(const int family, const int type, const int protocol)
56393 +{
56394 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
56395 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
56396 + (family != AF_UNIX)) {
56397 + if (family == AF_INET)
56398 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
56399 + else
56400 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
56401 + return -EACCES;
56402 + }
56403 +#endif
56404 + return 0;
56405 +}
56406 +
56407 +int
56408 +gr_handle_sock_server(const struct sockaddr *sck)
56409 +{
56410 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56411 + if (grsec_enable_socket_server &&
56412 + in_group_p(grsec_socket_server_gid) &&
56413 + sck && (sck->sa_family != AF_UNIX) &&
56414 + (sck->sa_family != AF_LOCAL)) {
56415 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
56416 + return -EACCES;
56417 + }
56418 +#endif
56419 + return 0;
56420 +}
56421 +
56422 +int
56423 +gr_handle_sock_server_other(const struct sock *sck)
56424 +{
56425 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56426 + if (grsec_enable_socket_server &&
56427 + in_group_p(grsec_socket_server_gid) &&
56428 + sck && (sck->sk_family != AF_UNIX) &&
56429 + (sck->sk_family != AF_LOCAL)) {
56430 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
56431 + return -EACCES;
56432 + }
56433 +#endif
56434 + return 0;
56435 +}
56436 +
56437 +int
56438 +gr_handle_sock_client(const struct sockaddr *sck)
56439 +{
56440 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
56441 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
56442 + sck && (sck->sa_family != AF_UNIX) &&
56443 + (sck->sa_family != AF_LOCAL)) {
56444 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
56445 + return -EACCES;
56446 + }
56447 +#endif
56448 + return 0;
56449 +}
56450 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
56451 new file mode 100644
56452 index 0000000..a1aedd7
56453 --- /dev/null
56454 +++ b/grsecurity/grsec_sysctl.c
56455 @@ -0,0 +1,451 @@
56456 +#include <linux/kernel.h>
56457 +#include <linux/sched.h>
56458 +#include <linux/sysctl.h>
56459 +#include <linux/grsecurity.h>
56460 +#include <linux/grinternal.h>
56461 +
56462 +int
56463 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
56464 +{
56465 +#ifdef CONFIG_GRKERNSEC_SYSCTL
56466 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
56467 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
56468 + return -EACCES;
56469 + }
56470 +#endif
56471 + return 0;
56472 +}
56473 +
56474 +#ifdef CONFIG_GRKERNSEC_ROFS
56475 +static int __maybe_unused one = 1;
56476 +#endif
56477 +
56478 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
56479 +struct ctl_table grsecurity_table[] = {
56480 +#ifdef CONFIG_GRKERNSEC_SYSCTL
56481 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
56482 +#ifdef CONFIG_GRKERNSEC_IO
56483 + {
56484 + .procname = "disable_priv_io",
56485 + .data = &grsec_disable_privio,
56486 + .maxlen = sizeof(int),
56487 + .mode = 0600,
56488 + .proc_handler = &proc_dointvec,
56489 + },
56490 +#endif
56491 +#endif
56492 +#ifdef CONFIG_GRKERNSEC_LINK
56493 + {
56494 + .procname = "linking_restrictions",
56495 + .data = &grsec_enable_link,
56496 + .maxlen = sizeof(int),
56497 + .mode = 0600,
56498 + .proc_handler = &proc_dointvec,
56499 + },
56500 +#endif
56501 +#ifdef CONFIG_GRKERNSEC_BRUTE
56502 + {
56503 + .procname = "deter_bruteforce",
56504 + .data = &grsec_enable_brute,
56505 + .maxlen = sizeof(int),
56506 + .mode = 0600,
56507 + .proc_handler = &proc_dointvec,
56508 + },
56509 +#endif
56510 +#ifdef CONFIG_GRKERNSEC_FIFO
56511 + {
56512 + .procname = "fifo_restrictions",
56513 + .data = &grsec_enable_fifo,
56514 + .maxlen = sizeof(int),
56515 + .mode = 0600,
56516 + .proc_handler = &proc_dointvec,
56517 + },
56518 +#endif
56519 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56520 + {
56521 + .procname = "ptrace_readexec",
56522 + .data = &grsec_enable_ptrace_readexec,
56523 + .maxlen = sizeof(int),
56524 + .mode = 0600,
56525 + .proc_handler = &proc_dointvec,
56526 + },
56527 +#endif
56528 +#ifdef CONFIG_GRKERNSEC_SETXID
56529 + {
56530 + .procname = "consistent_setxid",
56531 + .data = &grsec_enable_setxid,
56532 + .maxlen = sizeof(int),
56533 + .mode = 0600,
56534 + .proc_handler = &proc_dointvec,
56535 + },
56536 +#endif
56537 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56538 + {
56539 + .procname = "ip_blackhole",
56540 + .data = &grsec_enable_blackhole,
56541 + .maxlen = sizeof(int),
56542 + .mode = 0600,
56543 + .proc_handler = &proc_dointvec,
56544 + },
56545 + {
56546 + .procname = "lastack_retries",
56547 + .data = &grsec_lastack_retries,
56548 + .maxlen = sizeof(int),
56549 + .mode = 0600,
56550 + .proc_handler = &proc_dointvec,
56551 + },
56552 +#endif
56553 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56554 + {
56555 + .procname = "exec_logging",
56556 + .data = &grsec_enable_execlog,
56557 + .maxlen = sizeof(int),
56558 + .mode = 0600,
56559 + .proc_handler = &proc_dointvec,
56560 + },
56561 +#endif
56562 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56563 + {
56564 + .procname = "rwxmap_logging",
56565 + .data = &grsec_enable_log_rwxmaps,
56566 + .maxlen = sizeof(int),
56567 + .mode = 0600,
56568 + .proc_handler = &proc_dointvec,
56569 + },
56570 +#endif
56571 +#ifdef CONFIG_GRKERNSEC_SIGNAL
56572 + {
56573 + .procname = "signal_logging",
56574 + .data = &grsec_enable_signal,
56575 + .maxlen = sizeof(int),
56576 + .mode = 0600,
56577 + .proc_handler = &proc_dointvec,
56578 + },
56579 +#endif
56580 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56581 + {
56582 + .procname = "forkfail_logging",
56583 + .data = &grsec_enable_forkfail,
56584 + .maxlen = sizeof(int),
56585 + .mode = 0600,
56586 + .proc_handler = &proc_dointvec,
56587 + },
56588 +#endif
56589 +#ifdef CONFIG_GRKERNSEC_TIME
56590 + {
56591 + .procname = "timechange_logging",
56592 + .data = &grsec_enable_time,
56593 + .maxlen = sizeof(int),
56594 + .mode = 0600,
56595 + .proc_handler = &proc_dointvec,
56596 + },
56597 +#endif
56598 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56599 + {
56600 + .procname = "chroot_deny_shmat",
56601 + .data = &grsec_enable_chroot_shmat,
56602 + .maxlen = sizeof(int),
56603 + .mode = 0600,
56604 + .proc_handler = &proc_dointvec,
56605 + },
56606 +#endif
56607 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56608 + {
56609 + .procname = "chroot_deny_unix",
56610 + .data = &grsec_enable_chroot_unix,
56611 + .maxlen = sizeof(int),
56612 + .mode = 0600,
56613 + .proc_handler = &proc_dointvec,
56614 + },
56615 +#endif
56616 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56617 + {
56618 + .procname = "chroot_deny_mount",
56619 + .data = &grsec_enable_chroot_mount,
56620 + .maxlen = sizeof(int),
56621 + .mode = 0600,
56622 + .proc_handler = &proc_dointvec,
56623 + },
56624 +#endif
56625 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56626 + {
56627 + .procname = "chroot_deny_fchdir",
56628 + .data = &grsec_enable_chroot_fchdir,
56629 + .maxlen = sizeof(int),
56630 + .mode = 0600,
56631 + .proc_handler = &proc_dointvec,
56632 + },
56633 +#endif
56634 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56635 + {
56636 + .procname = "chroot_deny_chroot",
56637 + .data = &grsec_enable_chroot_double,
56638 + .maxlen = sizeof(int),
56639 + .mode = 0600,
56640 + .proc_handler = &proc_dointvec,
56641 + },
56642 +#endif
56643 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56644 + {
56645 + .procname = "chroot_deny_pivot",
56646 + .data = &grsec_enable_chroot_pivot,
56647 + .maxlen = sizeof(int),
56648 + .mode = 0600,
56649 + .proc_handler = &proc_dointvec,
56650 + },
56651 +#endif
56652 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56653 + {
56654 + .procname = "chroot_enforce_chdir",
56655 + .data = &grsec_enable_chroot_chdir,
56656 + .maxlen = sizeof(int),
56657 + .mode = 0600,
56658 + .proc_handler = &proc_dointvec,
56659 + },
56660 +#endif
56661 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56662 + {
56663 + .procname = "chroot_deny_chmod",
56664 + .data = &grsec_enable_chroot_chmod,
56665 + .maxlen = sizeof(int),
56666 + .mode = 0600,
56667 + .proc_handler = &proc_dointvec,
56668 + },
56669 +#endif
56670 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56671 + {
56672 + .procname = "chroot_deny_mknod",
56673 + .data = &grsec_enable_chroot_mknod,
56674 + .maxlen = sizeof(int),
56675 + .mode = 0600,
56676 + .proc_handler = &proc_dointvec,
56677 + },
56678 +#endif
56679 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56680 + {
56681 + .procname = "chroot_restrict_nice",
56682 + .data = &grsec_enable_chroot_nice,
56683 + .maxlen = sizeof(int),
56684 + .mode = 0600,
56685 + .proc_handler = &proc_dointvec,
56686 + },
56687 +#endif
56688 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56689 + {
56690 + .procname = "chroot_execlog",
56691 + .data = &grsec_enable_chroot_execlog,
56692 + .maxlen = sizeof(int),
56693 + .mode = 0600,
56694 + .proc_handler = &proc_dointvec,
56695 + },
56696 +#endif
56697 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56698 + {
56699 + .procname = "chroot_caps",
56700 + .data = &grsec_enable_chroot_caps,
56701 + .maxlen = sizeof(int),
56702 + .mode = 0600,
56703 + .proc_handler = &proc_dointvec,
56704 + },
56705 +#endif
56706 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56707 + {
56708 + .procname = "chroot_deny_sysctl",
56709 + .data = &grsec_enable_chroot_sysctl,
56710 + .maxlen = sizeof(int),
56711 + .mode = 0600,
56712 + .proc_handler = &proc_dointvec,
56713 + },
56714 +#endif
56715 +#ifdef CONFIG_GRKERNSEC_TPE
56716 + {
56717 + .procname = "tpe",
56718 + .data = &grsec_enable_tpe,
56719 + .maxlen = sizeof(int),
56720 + .mode = 0600,
56721 + .proc_handler = &proc_dointvec,
56722 + },
56723 + {
56724 + .procname = "tpe_gid",
56725 + .data = &grsec_tpe_gid,
56726 + .maxlen = sizeof(int),
56727 + .mode = 0600,
56728 + .proc_handler = &proc_dointvec,
56729 + },
56730 +#endif
56731 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
56732 + {
56733 + .procname = "tpe_invert",
56734 + .data = &grsec_enable_tpe_invert,
56735 + .maxlen = sizeof(int),
56736 + .mode = 0600,
56737 + .proc_handler = &proc_dointvec,
56738 + },
56739 +#endif
56740 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
56741 + {
56742 + .procname = "tpe_restrict_all",
56743 + .data = &grsec_enable_tpe_all,
56744 + .maxlen = sizeof(int),
56745 + .mode = 0600,
56746 + .proc_handler = &proc_dointvec,
56747 + },
56748 +#endif
56749 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
56750 + {
56751 + .procname = "socket_all",
56752 + .data = &grsec_enable_socket_all,
56753 + .maxlen = sizeof(int),
56754 + .mode = 0600,
56755 + .proc_handler = &proc_dointvec,
56756 + },
56757 + {
56758 + .procname = "socket_all_gid",
56759 + .data = &grsec_socket_all_gid,
56760 + .maxlen = sizeof(int),
56761 + .mode = 0600,
56762 + .proc_handler = &proc_dointvec,
56763 + },
56764 +#endif
56765 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
56766 + {
56767 + .procname = "socket_client",
56768 + .data = &grsec_enable_socket_client,
56769 + .maxlen = sizeof(int),
56770 + .mode = 0600,
56771 + .proc_handler = &proc_dointvec,
56772 + },
56773 + {
56774 + .procname = "socket_client_gid",
56775 + .data = &grsec_socket_client_gid,
56776 + .maxlen = sizeof(int),
56777 + .mode = 0600,
56778 + .proc_handler = &proc_dointvec,
56779 + },
56780 +#endif
56781 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56782 + {
56783 + .procname = "socket_server",
56784 + .data = &grsec_enable_socket_server,
56785 + .maxlen = sizeof(int),
56786 + .mode = 0600,
56787 + .proc_handler = &proc_dointvec,
56788 + },
56789 + {
56790 + .procname = "socket_server_gid",
56791 + .data = &grsec_socket_server_gid,
56792 + .maxlen = sizeof(int),
56793 + .mode = 0600,
56794 + .proc_handler = &proc_dointvec,
56795 + },
56796 +#endif
56797 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
56798 + {
56799 + .procname = "audit_group",
56800 + .data = &grsec_enable_group,
56801 + .maxlen = sizeof(int),
56802 + .mode = 0600,
56803 + .proc_handler = &proc_dointvec,
56804 + },
56805 + {
56806 + .procname = "audit_gid",
56807 + .data = &grsec_audit_gid,
56808 + .maxlen = sizeof(int),
56809 + .mode = 0600,
56810 + .proc_handler = &proc_dointvec,
56811 + },
56812 +#endif
56813 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56814 + {
56815 + .procname = "audit_chdir",
56816 + .data = &grsec_enable_chdir,
56817 + .maxlen = sizeof(int),
56818 + .mode = 0600,
56819 + .proc_handler = &proc_dointvec,
56820 + },
56821 +#endif
56822 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56823 + {
56824 + .procname = "audit_mount",
56825 + .data = &grsec_enable_mount,
56826 + .maxlen = sizeof(int),
56827 + .mode = 0600,
56828 + .proc_handler = &proc_dointvec,
56829 + },
56830 +#endif
56831 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
56832 + {
56833 + .procname = "audit_textrel",
56834 + .data = &grsec_enable_audit_textrel,
56835 + .maxlen = sizeof(int),
56836 + .mode = 0600,
56837 + .proc_handler = &proc_dointvec,
56838 + },
56839 +#endif
56840 +#ifdef CONFIG_GRKERNSEC_DMESG
56841 + {
56842 + .procname = "dmesg",
56843 + .data = &grsec_enable_dmesg,
56844 + .maxlen = sizeof(int),
56845 + .mode = 0600,
56846 + .proc_handler = &proc_dointvec,
56847 + },
56848 +#endif
56849 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56850 + {
56851 + .procname = "chroot_findtask",
56852 + .data = &grsec_enable_chroot_findtask,
56853 + .maxlen = sizeof(int),
56854 + .mode = 0600,
56855 + .proc_handler = &proc_dointvec,
56856 + },
56857 +#endif
56858 +#ifdef CONFIG_GRKERNSEC_RESLOG
56859 + {
56860 + .procname = "resource_logging",
56861 + .data = &grsec_resource_logging,
56862 + .maxlen = sizeof(int),
56863 + .mode = 0600,
56864 + .proc_handler = &proc_dointvec,
56865 + },
56866 +#endif
56867 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
56868 + {
56869 + .procname = "audit_ptrace",
56870 + .data = &grsec_enable_audit_ptrace,
56871 + .maxlen = sizeof(int),
56872 + .mode = 0600,
56873 + .proc_handler = &proc_dointvec,
56874 + },
56875 +#endif
56876 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56877 + {
56878 + .procname = "harden_ptrace",
56879 + .data = &grsec_enable_harden_ptrace,
56880 + .maxlen = sizeof(int),
56881 + .mode = 0600,
56882 + .proc_handler = &proc_dointvec,
56883 + },
56884 +#endif
56885 + {
56886 + .procname = "grsec_lock",
56887 + .data = &grsec_lock,
56888 + .maxlen = sizeof(int),
56889 + .mode = 0600,
56890 + .proc_handler = &proc_dointvec,
56891 + },
56892 +#endif
56893 +#ifdef CONFIG_GRKERNSEC_ROFS
56894 + {
56895 + .procname = "romount_protect",
56896 + .data = &grsec_enable_rofs,
56897 + .maxlen = sizeof(int),
56898 + .mode = 0600,
56899 + .proc_handler = &proc_dointvec_minmax,
56900 + .extra1 = &one,
56901 + .extra2 = &one,
56902 + },
56903 +#endif
56904 + { }
56905 +};
56906 +#endif
56907 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
56908 new file mode 100644
56909 index 0000000..0dc13c3
56910 --- /dev/null
56911 +++ b/grsecurity/grsec_time.c
56912 @@ -0,0 +1,16 @@
56913 +#include <linux/kernel.h>
56914 +#include <linux/sched.h>
56915 +#include <linux/grinternal.h>
56916 +#include <linux/module.h>
56917 +
56918 +void
56919 +gr_log_timechange(void)
56920 +{
56921 +#ifdef CONFIG_GRKERNSEC_TIME
56922 + if (grsec_enable_time)
56923 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
56924 +#endif
56925 + return;
56926 +}
56927 +
56928 +EXPORT_SYMBOL(gr_log_timechange);
56929 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
56930 new file mode 100644
56931 index 0000000..07e0dc0
56932 --- /dev/null
56933 +++ b/grsecurity/grsec_tpe.c
56934 @@ -0,0 +1,73 @@
56935 +#include <linux/kernel.h>
56936 +#include <linux/sched.h>
56937 +#include <linux/file.h>
56938 +#include <linux/fs.h>
56939 +#include <linux/grinternal.h>
56940 +
56941 +extern int gr_acl_tpe_check(void);
56942 +
56943 +int
56944 +gr_tpe_allow(const struct file *file)
56945 +{
56946 +#ifdef CONFIG_GRKERNSEC
56947 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
56948 + const struct cred *cred = current_cred();
56949 + char *msg = NULL;
56950 + char *msg2 = NULL;
56951 +
56952 + // never restrict root
56953 + if (!cred->uid)
56954 + return 1;
56955 +
56956 + if (grsec_enable_tpe) {
56957 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
56958 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
56959 + msg = "not being in trusted group";
56960 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
56961 + msg = "being in untrusted group";
56962 +#else
56963 + if (in_group_p(grsec_tpe_gid))
56964 + msg = "being in untrusted group";
56965 +#endif
56966 + }
56967 + if (!msg && gr_acl_tpe_check())
56968 + msg = "being in untrusted role";
56969 +
56970 + // not in any affected group/role
56971 + if (!msg)
56972 + goto next_check;
56973 +
56974 + if (inode->i_uid)
56975 + msg2 = "file in non-root-owned directory";
56976 + else if (inode->i_mode & S_IWOTH)
56977 + msg2 = "file in world-writable directory";
56978 + else if (inode->i_mode & S_IWGRP)
56979 + msg2 = "file in group-writable directory";
56980 +
56981 + if (msg && msg2) {
56982 + char fullmsg[70] = {0};
56983 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
56984 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
56985 + return 0;
56986 + }
56987 + msg = NULL;
56988 +next_check:
56989 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
56990 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
56991 + return 1;
56992 +
56993 + if (inode->i_uid && (inode->i_uid != cred->uid))
56994 + msg = "directory not owned by user";
56995 + else if (inode->i_mode & S_IWOTH)
56996 + msg = "file in world-writable directory";
56997 + else if (inode->i_mode & S_IWGRP)
56998 + msg = "file in group-writable directory";
56999 +
57000 + if (msg) {
57001 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
57002 + return 0;
57003 + }
57004 +#endif
57005 +#endif
57006 + return 1;
57007 +}
57008 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
57009 new file mode 100644
57010 index 0000000..9f7b1ac
57011 --- /dev/null
57012 +++ b/grsecurity/grsum.c
57013 @@ -0,0 +1,61 @@
57014 +#include <linux/err.h>
57015 +#include <linux/kernel.h>
57016 +#include <linux/sched.h>
57017 +#include <linux/mm.h>
57018 +#include <linux/scatterlist.h>
57019 +#include <linux/crypto.h>
57020 +#include <linux/gracl.h>
57021 +
57022 +
57023 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
57024 +#error "crypto and sha256 must be built into the kernel"
57025 +#endif
57026 +
57027 +int
57028 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
57029 +{
57030 + char *p;
57031 + struct crypto_hash *tfm;
57032 + struct hash_desc desc;
57033 + struct scatterlist sg;
57034 + unsigned char temp_sum[GR_SHA_LEN];
57035 + volatile int retval = 0;
57036 + volatile int dummy = 0;
57037 + unsigned int i;
57038 +
57039 + sg_init_table(&sg, 1);
57040 +
57041 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
57042 + if (IS_ERR(tfm)) {
57043 + /* should never happen, since sha256 should be built in */
57044 + return 1;
57045 + }
57046 +
57047 + desc.tfm = tfm;
57048 + desc.flags = 0;
57049 +
57050 + crypto_hash_init(&desc);
57051 +
57052 + p = salt;
57053 + sg_set_buf(&sg, p, GR_SALT_LEN);
57054 + crypto_hash_update(&desc, &sg, sg.length);
57055 +
57056 + p = entry->pw;
57057 + sg_set_buf(&sg, p, strlen(p));
57058 +
57059 + crypto_hash_update(&desc, &sg, sg.length);
57060 +
57061 + crypto_hash_final(&desc, temp_sum);
57062 +
57063 + memset(entry->pw, 0, GR_PW_LEN);
57064 +
57065 + for (i = 0; i < GR_SHA_LEN; i++)
57066 + if (sum[i] != temp_sum[i])
57067 + retval = 1;
57068 + else
57069 + dummy = 1; // waste a cycle
57070 +
57071 + crypto_free_hash(tfm);
57072 +
57073 + return retval;
57074 +}
57075 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
57076 index 6cd5b64..f620d2d 100644
57077 --- a/include/acpi/acpi_bus.h
57078 +++ b/include/acpi/acpi_bus.h
57079 @@ -107,7 +107,7 @@ struct acpi_device_ops {
57080 acpi_op_bind bind;
57081 acpi_op_unbind unbind;
57082 acpi_op_notify notify;
57083 -};
57084 +} __no_const;
57085
57086 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
57087
57088 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
57089 index b7babf0..71e4e74 100644
57090 --- a/include/asm-generic/atomic-long.h
57091 +++ b/include/asm-generic/atomic-long.h
57092 @@ -22,6 +22,12 @@
57093
57094 typedef atomic64_t atomic_long_t;
57095
57096 +#ifdef CONFIG_PAX_REFCOUNT
57097 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
57098 +#else
57099 +typedef atomic64_t atomic_long_unchecked_t;
57100 +#endif
57101 +
57102 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
57103
57104 static inline long atomic_long_read(atomic_long_t *l)
57105 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
57106 return (long)atomic64_read(v);
57107 }
57108
57109 +#ifdef CONFIG_PAX_REFCOUNT
57110 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
57111 +{
57112 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57113 +
57114 + return (long)atomic64_read_unchecked(v);
57115 +}
57116 +#endif
57117 +
57118 static inline void atomic_long_set(atomic_long_t *l, long i)
57119 {
57120 atomic64_t *v = (atomic64_t *)l;
57121 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
57122 atomic64_set(v, i);
57123 }
57124
57125 +#ifdef CONFIG_PAX_REFCOUNT
57126 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
57127 +{
57128 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57129 +
57130 + atomic64_set_unchecked(v, i);
57131 +}
57132 +#endif
57133 +
57134 static inline void atomic_long_inc(atomic_long_t *l)
57135 {
57136 atomic64_t *v = (atomic64_t *)l;
57137 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
57138 atomic64_inc(v);
57139 }
57140
57141 +#ifdef CONFIG_PAX_REFCOUNT
57142 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
57143 +{
57144 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57145 +
57146 + atomic64_inc_unchecked(v);
57147 +}
57148 +#endif
57149 +
57150 static inline void atomic_long_dec(atomic_long_t *l)
57151 {
57152 atomic64_t *v = (atomic64_t *)l;
57153 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
57154 atomic64_dec(v);
57155 }
57156
57157 +#ifdef CONFIG_PAX_REFCOUNT
57158 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
57159 +{
57160 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57161 +
57162 + atomic64_dec_unchecked(v);
57163 +}
57164 +#endif
57165 +
57166 static inline void atomic_long_add(long i, atomic_long_t *l)
57167 {
57168 atomic64_t *v = (atomic64_t *)l;
57169 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
57170 atomic64_add(i, v);
57171 }
57172
57173 +#ifdef CONFIG_PAX_REFCOUNT
57174 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
57175 +{
57176 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57177 +
57178 + atomic64_add_unchecked(i, v);
57179 +}
57180 +#endif
57181 +
57182 static inline void atomic_long_sub(long i, atomic_long_t *l)
57183 {
57184 atomic64_t *v = (atomic64_t *)l;
57185 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
57186 atomic64_sub(i, v);
57187 }
57188
57189 +#ifdef CONFIG_PAX_REFCOUNT
57190 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
57191 +{
57192 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57193 +
57194 + atomic64_sub_unchecked(i, v);
57195 +}
57196 +#endif
57197 +
57198 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
57199 {
57200 atomic64_t *v = (atomic64_t *)l;
57201 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
57202 return (long)atomic64_inc_return(v);
57203 }
57204
57205 +#ifdef CONFIG_PAX_REFCOUNT
57206 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
57207 +{
57208 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57209 +
57210 + return (long)atomic64_inc_return_unchecked(v);
57211 +}
57212 +#endif
57213 +
57214 static inline long atomic_long_dec_return(atomic_long_t *l)
57215 {
57216 atomic64_t *v = (atomic64_t *)l;
57217 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
57218
57219 typedef atomic_t atomic_long_t;
57220
57221 +#ifdef CONFIG_PAX_REFCOUNT
57222 +typedef atomic_unchecked_t atomic_long_unchecked_t;
57223 +#else
57224 +typedef atomic_t atomic_long_unchecked_t;
57225 +#endif
57226 +
57227 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
57228 static inline long atomic_long_read(atomic_long_t *l)
57229 {
57230 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
57231 return (long)atomic_read(v);
57232 }
57233
57234 +#ifdef CONFIG_PAX_REFCOUNT
57235 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
57236 +{
57237 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57238 +
57239 + return (long)atomic_read_unchecked(v);
57240 +}
57241 +#endif
57242 +
57243 static inline void atomic_long_set(atomic_long_t *l, long i)
57244 {
57245 atomic_t *v = (atomic_t *)l;
57246 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
57247 atomic_set(v, i);
57248 }
57249
57250 +#ifdef CONFIG_PAX_REFCOUNT
57251 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
57252 +{
57253 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57254 +
57255 + atomic_set_unchecked(v, i);
57256 +}
57257 +#endif
57258 +
57259 static inline void atomic_long_inc(atomic_long_t *l)
57260 {
57261 atomic_t *v = (atomic_t *)l;
57262 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
57263 atomic_inc(v);
57264 }
57265
57266 +#ifdef CONFIG_PAX_REFCOUNT
57267 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
57268 +{
57269 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57270 +
57271 + atomic_inc_unchecked(v);
57272 +}
57273 +#endif
57274 +
57275 static inline void atomic_long_dec(atomic_long_t *l)
57276 {
57277 atomic_t *v = (atomic_t *)l;
57278 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
57279 atomic_dec(v);
57280 }
57281
57282 +#ifdef CONFIG_PAX_REFCOUNT
57283 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
57284 +{
57285 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57286 +
57287 + atomic_dec_unchecked(v);
57288 +}
57289 +#endif
57290 +
57291 static inline void atomic_long_add(long i, atomic_long_t *l)
57292 {
57293 atomic_t *v = (atomic_t *)l;
57294 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
57295 atomic_add(i, v);
57296 }
57297
57298 +#ifdef CONFIG_PAX_REFCOUNT
57299 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
57300 +{
57301 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57302 +
57303 + atomic_add_unchecked(i, v);
57304 +}
57305 +#endif
57306 +
57307 static inline void atomic_long_sub(long i, atomic_long_t *l)
57308 {
57309 atomic_t *v = (atomic_t *)l;
57310 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
57311 atomic_sub(i, v);
57312 }
57313
57314 +#ifdef CONFIG_PAX_REFCOUNT
57315 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
57316 +{
57317 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57318 +
57319 + atomic_sub_unchecked(i, v);
57320 +}
57321 +#endif
57322 +
57323 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
57324 {
57325 atomic_t *v = (atomic_t *)l;
57326 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
57327 return (long)atomic_inc_return(v);
57328 }
57329
57330 +#ifdef CONFIG_PAX_REFCOUNT
57331 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
57332 +{
57333 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57334 +
57335 + return (long)atomic_inc_return_unchecked(v);
57336 +}
57337 +#endif
57338 +
57339 static inline long atomic_long_dec_return(atomic_long_t *l)
57340 {
57341 atomic_t *v = (atomic_t *)l;
57342 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
57343
57344 #endif /* BITS_PER_LONG == 64 */
57345
57346 +#ifdef CONFIG_PAX_REFCOUNT
57347 +static inline void pax_refcount_needs_these_functions(void)
57348 +{
57349 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
57350 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
57351 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
57352 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
57353 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
57354 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
57355 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
57356 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
57357 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
57358 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
57359 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
57360 +
57361 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
57362 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
57363 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
57364 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
57365 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
57366 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
57367 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
57368 +}
57369 +#else
57370 +#define atomic_read_unchecked(v) atomic_read(v)
57371 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
57372 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
57373 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
57374 +#define atomic_inc_unchecked(v) atomic_inc(v)
57375 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
57376 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
57377 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
57378 +#define atomic_dec_unchecked(v) atomic_dec(v)
57379 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
57380 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
57381 +
57382 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
57383 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
57384 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
57385 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
57386 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
57387 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
57388 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
57389 +#endif
57390 +
57391 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
57392 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
57393 index b18ce4f..2ee2843 100644
57394 --- a/include/asm-generic/atomic64.h
57395 +++ b/include/asm-generic/atomic64.h
57396 @@ -16,6 +16,8 @@ typedef struct {
57397 long long counter;
57398 } atomic64_t;
57399
57400 +typedef atomic64_t atomic64_unchecked_t;
57401 +
57402 #define ATOMIC64_INIT(i) { (i) }
57403
57404 extern long long atomic64_read(const atomic64_t *v);
57405 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
57406 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
57407 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
57408
57409 +#define atomic64_read_unchecked(v) atomic64_read(v)
57410 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
57411 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
57412 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
57413 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
57414 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
57415 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
57416 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
57417 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
57418 +
57419 #endif /* _ASM_GENERIC_ATOMIC64_H */
57420 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
57421 index 1bfcfe5..e04c5c9 100644
57422 --- a/include/asm-generic/cache.h
57423 +++ b/include/asm-generic/cache.h
57424 @@ -6,7 +6,7 @@
57425 * cache lines need to provide their own cache.h.
57426 */
57427
57428 -#define L1_CACHE_SHIFT 5
57429 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
57430 +#define L1_CACHE_SHIFT 5UL
57431 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
57432
57433 #endif /* __ASM_GENERIC_CACHE_H */
57434 diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
57435 index 1ca3efc..e3dc852 100644
57436 --- a/include/asm-generic/int-l64.h
57437 +++ b/include/asm-generic/int-l64.h
57438 @@ -46,6 +46,8 @@ typedef unsigned int u32;
57439 typedef signed long s64;
57440 typedef unsigned long u64;
57441
57442 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
57443 +
57444 #define S8_C(x) x
57445 #define U8_C(x) x ## U
57446 #define S16_C(x) x
57447 diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
57448 index f394147..b6152b9 100644
57449 --- a/include/asm-generic/int-ll64.h
57450 +++ b/include/asm-generic/int-ll64.h
57451 @@ -51,6 +51,8 @@ typedef unsigned int u32;
57452 typedef signed long long s64;
57453 typedef unsigned long long u64;
57454
57455 +typedef unsigned long long intoverflow_t;
57456 +
57457 #define S8_C(x) x
57458 #define U8_C(x) x ## U
57459 #define S16_C(x) x
57460 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
57461 index 0232ccb..13d9165 100644
57462 --- a/include/asm-generic/kmap_types.h
57463 +++ b/include/asm-generic/kmap_types.h
57464 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
57465 KMAP_D(17) KM_NMI,
57466 KMAP_D(18) KM_NMI_PTE,
57467 KMAP_D(19) KM_KDB,
57468 +KMAP_D(20) KM_CLEARPAGE,
57469 /*
57470 * Remember to update debug_kmap_atomic() when adding new kmap types!
57471 */
57472 -KMAP_D(20) KM_TYPE_NR
57473 +KMAP_D(21) KM_TYPE_NR
57474 };
57475
57476 #undef KMAP_D
57477 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
57478 index 725612b..9cc513a 100644
57479 --- a/include/asm-generic/pgtable-nopmd.h
57480 +++ b/include/asm-generic/pgtable-nopmd.h
57481 @@ -1,14 +1,19 @@
57482 #ifndef _PGTABLE_NOPMD_H
57483 #define _PGTABLE_NOPMD_H
57484
57485 -#ifndef __ASSEMBLY__
57486 -
57487 #include <asm-generic/pgtable-nopud.h>
57488
57489 -struct mm_struct;
57490 -
57491 #define __PAGETABLE_PMD_FOLDED
57492
57493 +#define PMD_SHIFT PUD_SHIFT
57494 +#define PTRS_PER_PMD 1
57495 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
57496 +#define PMD_MASK (~(PMD_SIZE-1))
57497 +
57498 +#ifndef __ASSEMBLY__
57499 +
57500 +struct mm_struct;
57501 +
57502 /*
57503 * Having the pmd type consist of a pud gets the size right, and allows
57504 * us to conceptually access the pud entry that this pmd is folded into
57505 @@ -16,11 +21,6 @@ struct mm_struct;
57506 */
57507 typedef struct { pud_t pud; } pmd_t;
57508
57509 -#define PMD_SHIFT PUD_SHIFT
57510 -#define PTRS_PER_PMD 1
57511 -#define PMD_SIZE (1UL << PMD_SHIFT)
57512 -#define PMD_MASK (~(PMD_SIZE-1))
57513 -
57514 /*
57515 * The "pud_xxx()" functions here are trivial for a folded two-level
57516 * setup: the pmd is never bad, and a pmd always exists (as it's folded
57517 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
57518 index 810431d..ccc3638 100644
57519 --- a/include/asm-generic/pgtable-nopud.h
57520 +++ b/include/asm-generic/pgtable-nopud.h
57521 @@ -1,10 +1,15 @@
57522 #ifndef _PGTABLE_NOPUD_H
57523 #define _PGTABLE_NOPUD_H
57524
57525 -#ifndef __ASSEMBLY__
57526 -
57527 #define __PAGETABLE_PUD_FOLDED
57528
57529 +#define PUD_SHIFT PGDIR_SHIFT
57530 +#define PTRS_PER_PUD 1
57531 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
57532 +#define PUD_MASK (~(PUD_SIZE-1))
57533 +
57534 +#ifndef __ASSEMBLY__
57535 +
57536 /*
57537 * Having the pud type consist of a pgd gets the size right, and allows
57538 * us to conceptually access the pgd entry that this pud is folded into
57539 @@ -12,11 +17,6 @@
57540 */
57541 typedef struct { pgd_t pgd; } pud_t;
57542
57543 -#define PUD_SHIFT PGDIR_SHIFT
57544 -#define PTRS_PER_PUD 1
57545 -#define PUD_SIZE (1UL << PUD_SHIFT)
57546 -#define PUD_MASK (~(PUD_SIZE-1))
57547 -
57548 /*
57549 * The "pgd_xxx()" functions here are trivial for a folded two-level
57550 * setup: the pud is never bad, and a pud always exists (as it's folded
57551 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
57552 index 76bff2b..c7a14e2 100644
57553 --- a/include/asm-generic/pgtable.h
57554 +++ b/include/asm-generic/pgtable.h
57555 @@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
57556 #endif /* __HAVE_ARCH_PMD_WRITE */
57557 #endif
57558
57559 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
57560 +static inline unsigned long pax_open_kernel(void) { return 0; }
57561 +#endif
57562 +
57563 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
57564 +static inline unsigned long pax_close_kernel(void) { return 0; }
57565 +#endif
57566 +
57567 #endif /* !__ASSEMBLY__ */
57568
57569 #endif /* _ASM_GENERIC_PGTABLE_H */
57570 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
57571 index b5e2e4c..6a5373e 100644
57572 --- a/include/asm-generic/vmlinux.lds.h
57573 +++ b/include/asm-generic/vmlinux.lds.h
57574 @@ -217,6 +217,7 @@
57575 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
57576 VMLINUX_SYMBOL(__start_rodata) = .; \
57577 *(.rodata) *(.rodata.*) \
57578 + *(.data..read_only) \
57579 *(__vermagic) /* Kernel version magic */ \
57580 . = ALIGN(8); \
57581 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
57582 @@ -722,17 +723,18 @@
57583 * section in the linker script will go there too. @phdr should have
57584 * a leading colon.
57585 *
57586 - * Note that this macros defines __per_cpu_load as an absolute symbol.
57587 + * Note that this macros defines per_cpu_load as an absolute symbol.
57588 * If there is no need to put the percpu section at a predetermined
57589 * address, use PERCPU_SECTION.
57590 */
57591 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
57592 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
57593 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
57594 + per_cpu_load = .; \
57595 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
57596 - LOAD_OFFSET) { \
57597 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
57598 PERCPU_INPUT(cacheline) \
57599 } phdr \
57600 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
57601 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
57602
57603 /**
57604 * PERCPU_SECTION - define output section for percpu area, simple version
57605 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
57606 index bf4b2dc..2d0762f 100644
57607 --- a/include/drm/drmP.h
57608 +++ b/include/drm/drmP.h
57609 @@ -72,6 +72,7 @@
57610 #include <linux/workqueue.h>
57611 #include <linux/poll.h>
57612 #include <asm/pgalloc.h>
57613 +#include <asm/local.h>
57614 #include "drm.h"
57615
57616 #include <linux/idr.h>
57617 @@ -1038,7 +1039,7 @@ struct drm_device {
57618
57619 /** \name Usage Counters */
57620 /*@{ */
57621 - int open_count; /**< Outstanding files open */
57622 + local_t open_count; /**< Outstanding files open */
57623 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
57624 atomic_t vma_count; /**< Outstanding vma areas open */
57625 int buf_use; /**< Buffers in use -- cannot alloc */
57626 @@ -1049,7 +1050,7 @@ struct drm_device {
57627 /*@{ */
57628 unsigned long counters;
57629 enum drm_stat_type types[15];
57630 - atomic_t counts[15];
57631 + atomic_unchecked_t counts[15];
57632 /*@} */
57633
57634 struct list_head filelist;
57635 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
57636 index 73b0712..0b7ef2f 100644
57637 --- a/include/drm/drm_crtc_helper.h
57638 +++ b/include/drm/drm_crtc_helper.h
57639 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
57640
57641 /* disable crtc when not in use - more explicit than dpms off */
57642 void (*disable)(struct drm_crtc *crtc);
57643 -};
57644 +} __no_const;
57645
57646 struct drm_encoder_helper_funcs {
57647 void (*dpms)(struct drm_encoder *encoder, int mode);
57648 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
57649 struct drm_connector *connector);
57650 /* disable encoder when not in use - more explicit than dpms off */
57651 void (*disable)(struct drm_encoder *encoder);
57652 -};
57653 +} __no_const;
57654
57655 struct drm_connector_helper_funcs {
57656 int (*get_modes)(struct drm_connector *connector);
57657 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
57658 index 26c1f78..6722682 100644
57659 --- a/include/drm/ttm/ttm_memory.h
57660 +++ b/include/drm/ttm/ttm_memory.h
57661 @@ -47,7 +47,7 @@
57662
57663 struct ttm_mem_shrink {
57664 int (*do_shrink) (struct ttm_mem_shrink *);
57665 -};
57666 +} __no_const;
57667
57668 /**
57669 * struct ttm_mem_global - Global memory accounting structure.
57670 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
57671 index e86dfca..40cc55f 100644
57672 --- a/include/linux/a.out.h
57673 +++ b/include/linux/a.out.h
57674 @@ -39,6 +39,14 @@ enum machine_type {
57675 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
57676 };
57677
57678 +/* Constants for the N_FLAGS field */
57679 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
57680 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
57681 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
57682 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
57683 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
57684 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
57685 +
57686 #if !defined (N_MAGIC)
57687 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
57688 #endif
57689 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
57690 index 49a83ca..df96b54 100644
57691 --- a/include/linux/atmdev.h
57692 +++ b/include/linux/atmdev.h
57693 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
57694 #endif
57695
57696 struct k_atm_aal_stats {
57697 -#define __HANDLE_ITEM(i) atomic_t i
57698 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
57699 __AAL_STAT_ITEMS
57700 #undef __HANDLE_ITEM
57701 };
57702 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
57703 index fd88a39..f4d0bad 100644
57704 --- a/include/linux/binfmts.h
57705 +++ b/include/linux/binfmts.h
57706 @@ -88,6 +88,7 @@ struct linux_binfmt {
57707 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
57708 int (*load_shlib)(struct file *);
57709 int (*core_dump)(struct coredump_params *cprm);
57710 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
57711 unsigned long min_coredump; /* minimal dump size */
57712 };
57713
57714 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
57715 index 0ed1eb0..3ab569b 100644
57716 --- a/include/linux/blkdev.h
57717 +++ b/include/linux/blkdev.h
57718 @@ -1315,7 +1315,7 @@ struct block_device_operations {
57719 /* this callback is with swap_lock and sometimes page table lock held */
57720 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
57721 struct module *owner;
57722 -};
57723 +} __do_const;
57724
57725 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
57726 unsigned long);
57727 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
57728 index 4d1a074..88f929a 100644
57729 --- a/include/linux/blktrace_api.h
57730 +++ b/include/linux/blktrace_api.h
57731 @@ -162,7 +162,7 @@ struct blk_trace {
57732 struct dentry *dir;
57733 struct dentry *dropped_file;
57734 struct dentry *msg_file;
57735 - atomic_t dropped;
57736 + atomic_unchecked_t dropped;
57737 };
57738
57739 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
57740 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
57741 index 83195fb..0b0f77d 100644
57742 --- a/include/linux/byteorder/little_endian.h
57743 +++ b/include/linux/byteorder/little_endian.h
57744 @@ -42,51 +42,51 @@
57745
57746 static inline __le64 __cpu_to_le64p(const __u64 *p)
57747 {
57748 - return (__force __le64)*p;
57749 + return (__force const __le64)*p;
57750 }
57751 static inline __u64 __le64_to_cpup(const __le64 *p)
57752 {
57753 - return (__force __u64)*p;
57754 + return (__force const __u64)*p;
57755 }
57756 static inline __le32 __cpu_to_le32p(const __u32 *p)
57757 {
57758 - return (__force __le32)*p;
57759 + return (__force const __le32)*p;
57760 }
57761 static inline __u32 __le32_to_cpup(const __le32 *p)
57762 {
57763 - return (__force __u32)*p;
57764 + return (__force const __u32)*p;
57765 }
57766 static inline __le16 __cpu_to_le16p(const __u16 *p)
57767 {
57768 - return (__force __le16)*p;
57769 + return (__force const __le16)*p;
57770 }
57771 static inline __u16 __le16_to_cpup(const __le16 *p)
57772 {
57773 - return (__force __u16)*p;
57774 + return (__force const __u16)*p;
57775 }
57776 static inline __be64 __cpu_to_be64p(const __u64 *p)
57777 {
57778 - return (__force __be64)__swab64p(p);
57779 + return (__force const __be64)__swab64p(p);
57780 }
57781 static inline __u64 __be64_to_cpup(const __be64 *p)
57782 {
57783 - return __swab64p((__u64 *)p);
57784 + return __swab64p((const __u64 *)p);
57785 }
57786 static inline __be32 __cpu_to_be32p(const __u32 *p)
57787 {
57788 - return (__force __be32)__swab32p(p);
57789 + return (__force const __be32)__swab32p(p);
57790 }
57791 static inline __u32 __be32_to_cpup(const __be32 *p)
57792 {
57793 - return __swab32p((__u32 *)p);
57794 + return __swab32p((const __u32 *)p);
57795 }
57796 static inline __be16 __cpu_to_be16p(const __u16 *p)
57797 {
57798 - return (__force __be16)__swab16p(p);
57799 + return (__force const __be16)__swab16p(p);
57800 }
57801 static inline __u16 __be16_to_cpup(const __be16 *p)
57802 {
57803 - return __swab16p((__u16 *)p);
57804 + return __swab16p((const __u16 *)p);
57805 }
57806 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
57807 #define __le64_to_cpus(x) do { (void)(x); } while (0)
57808 diff --git a/include/linux/cache.h b/include/linux/cache.h
57809 index 4c57065..4307975 100644
57810 --- a/include/linux/cache.h
57811 +++ b/include/linux/cache.h
57812 @@ -16,6 +16,10 @@
57813 #define __read_mostly
57814 #endif
57815
57816 +#ifndef __read_only
57817 +#define __read_only __read_mostly
57818 +#endif
57819 +
57820 #ifndef ____cacheline_aligned
57821 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
57822 #endif
57823 diff --git a/include/linux/capability.h b/include/linux/capability.h
57824 index a63d13d..069bfd5 100644
57825 --- a/include/linux/capability.h
57826 +++ b/include/linux/capability.h
57827 @@ -548,6 +548,9 @@ extern bool capable(int cap);
57828 extern bool ns_capable(struct user_namespace *ns, int cap);
57829 extern bool task_ns_capable(struct task_struct *t, int cap);
57830 extern bool nsown_capable(int cap);
57831 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
57832 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
57833 +extern bool capable_nolog(int cap);
57834
57835 /* audit system wants to get cap info from files as well */
57836 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
57837 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
57838 index 04ffb2e..6799180 100644
57839 --- a/include/linux/cleancache.h
57840 +++ b/include/linux/cleancache.h
57841 @@ -31,7 +31,7 @@ struct cleancache_ops {
57842 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
57843 void (*flush_inode)(int, struct cleancache_filekey);
57844 void (*flush_fs)(int);
57845 -};
57846 +} __no_const;
57847
57848 extern struct cleancache_ops
57849 cleancache_register_ops(struct cleancache_ops *ops);
57850 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
57851 index dfadc96..c0e70c1 100644
57852 --- a/include/linux/compiler-gcc4.h
57853 +++ b/include/linux/compiler-gcc4.h
57854 @@ -31,6 +31,12 @@
57855
57856
57857 #if __GNUC_MINOR__ >= 5
57858 +
57859 +#ifdef CONSTIFY_PLUGIN
57860 +#define __no_const __attribute__((no_const))
57861 +#define __do_const __attribute__((do_const))
57862 +#endif
57863 +
57864 /*
57865 * Mark a position in code as unreachable. This can be used to
57866 * suppress control flow warnings after asm blocks that transfer
57867 @@ -46,6 +52,11 @@
57868 #define __noclone __attribute__((__noclone__))
57869
57870 #endif
57871 +
57872 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
57873 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
57874 +#define __bos0(ptr) __bos((ptr), 0)
57875 +#define __bos1(ptr) __bos((ptr), 1)
57876 #endif
57877
57878 #if __GNUC_MINOR__ > 0
57879 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
57880 index 320d6c9..8573a1c 100644
57881 --- a/include/linux/compiler.h
57882 +++ b/include/linux/compiler.h
57883 @@ -5,31 +5,62 @@
57884
57885 #ifdef __CHECKER__
57886 # define __user __attribute__((noderef, address_space(1)))
57887 +# define __force_user __force __user
57888 # define __kernel __attribute__((address_space(0)))
57889 +# define __force_kernel __force __kernel
57890 # define __safe __attribute__((safe))
57891 # define __force __attribute__((force))
57892 # define __nocast __attribute__((nocast))
57893 # define __iomem __attribute__((noderef, address_space(2)))
57894 +# define __force_iomem __force __iomem
57895 # define __acquires(x) __attribute__((context(x,0,1)))
57896 # define __releases(x) __attribute__((context(x,1,0)))
57897 # define __acquire(x) __context__(x,1)
57898 # define __release(x) __context__(x,-1)
57899 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
57900 # define __percpu __attribute__((noderef, address_space(3)))
57901 +# define __force_percpu __force __percpu
57902 #ifdef CONFIG_SPARSE_RCU_POINTER
57903 # define __rcu __attribute__((noderef, address_space(4)))
57904 +# define __force_rcu __force __rcu
57905 #else
57906 # define __rcu
57907 +# define __force_rcu
57908 #endif
57909 extern void __chk_user_ptr(const volatile void __user *);
57910 extern void __chk_io_ptr(const volatile void __iomem *);
57911 +#elif defined(CHECKER_PLUGIN)
57912 +//# define __user
57913 +//# define __force_user
57914 +//# define __kernel
57915 +//# define __force_kernel
57916 +# define __safe
57917 +# define __force
57918 +# define __nocast
57919 +# define __iomem
57920 +# define __force_iomem
57921 +# define __chk_user_ptr(x) (void)0
57922 +# define __chk_io_ptr(x) (void)0
57923 +# define __builtin_warning(x, y...) (1)
57924 +# define __acquires(x)
57925 +# define __releases(x)
57926 +# define __acquire(x) (void)0
57927 +# define __release(x) (void)0
57928 +# define __cond_lock(x,c) (c)
57929 +# define __percpu
57930 +# define __force_percpu
57931 +# define __rcu
57932 +# define __force_rcu
57933 #else
57934 # define __user
57935 +# define __force_user
57936 # define __kernel
57937 +# define __force_kernel
57938 # define __safe
57939 # define __force
57940 # define __nocast
57941 # define __iomem
57942 +# define __force_iomem
57943 # define __chk_user_ptr(x) (void)0
57944 # define __chk_io_ptr(x) (void)0
57945 # define __builtin_warning(x, y...) (1)
57946 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
57947 # define __release(x) (void)0
57948 # define __cond_lock(x,c) (c)
57949 # define __percpu
57950 +# define __force_percpu
57951 # define __rcu
57952 +# define __force_rcu
57953 #endif
57954
57955 #ifdef __KERNEL__
57956 @@ -264,6 +297,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
57957 # define __attribute_const__ /* unimplemented */
57958 #endif
57959
57960 +#ifndef __no_const
57961 +# define __no_const
57962 +#endif
57963 +
57964 +#ifndef __do_const
57965 +# define __do_const
57966 +#endif
57967 +
57968 /*
57969 * Tell gcc if a function is cold. The compiler will assume any path
57970 * directly leading to the call is unlikely.
57971 @@ -273,6 +314,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
57972 #define __cold
57973 #endif
57974
57975 +#ifndef __alloc_size
57976 +#define __alloc_size(...)
57977 +#endif
57978 +
57979 +#ifndef __bos
57980 +#define __bos(ptr, arg)
57981 +#endif
57982 +
57983 +#ifndef __bos0
57984 +#define __bos0(ptr)
57985 +#endif
57986 +
57987 +#ifndef __bos1
57988 +#define __bos1(ptr)
57989 +#endif
57990 +
57991 /* Simple shorthand for a section definition */
57992 #ifndef __section
57993 # define __section(S) __attribute__ ((__section__(#S)))
57994 @@ -306,6 +363,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
57995 * use is to mediate communication between process-level code and irq/NMI
57996 * handlers, all running on the same CPU.
57997 */
57998 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
57999 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
58000 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
58001
58002 #endif /* __LINUX_COMPILER_H */
58003 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
58004 index e9eaec5..bfeb9bb 100644
58005 --- a/include/linux/cpuset.h
58006 +++ b/include/linux/cpuset.h
58007 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
58008 * nodemask.
58009 */
58010 smp_mb();
58011 - --ACCESS_ONCE(current->mems_allowed_change_disable);
58012 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
58013 }
58014
58015 static inline void set_mems_allowed(nodemask_t nodemask)
58016 diff --git a/include/linux/cred.h b/include/linux/cred.h
58017 index 4030896..8d6f342 100644
58018 --- a/include/linux/cred.h
58019 +++ b/include/linux/cred.h
58020 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
58021 static inline void validate_process_creds(void)
58022 {
58023 }
58024 +static inline void validate_task_creds(struct task_struct *task)
58025 +{
58026 +}
58027 #endif
58028
58029 /**
58030 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
58031 index 8a94217..15d49e3 100644
58032 --- a/include/linux/crypto.h
58033 +++ b/include/linux/crypto.h
58034 @@ -365,7 +365,7 @@ struct cipher_tfm {
58035 const u8 *key, unsigned int keylen);
58036 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
58037 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
58038 -};
58039 +} __no_const;
58040
58041 struct hash_tfm {
58042 int (*init)(struct hash_desc *desc);
58043 @@ -386,13 +386,13 @@ struct compress_tfm {
58044 int (*cot_decompress)(struct crypto_tfm *tfm,
58045 const u8 *src, unsigned int slen,
58046 u8 *dst, unsigned int *dlen);
58047 -};
58048 +} __no_const;
58049
58050 struct rng_tfm {
58051 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
58052 unsigned int dlen);
58053 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
58054 -};
58055 +} __no_const;
58056
58057 #define crt_ablkcipher crt_u.ablkcipher
58058 #define crt_aead crt_u.aead
58059 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
58060 index 7925bf0..d5143d2 100644
58061 --- a/include/linux/decompress/mm.h
58062 +++ b/include/linux/decompress/mm.h
58063 @@ -77,7 +77,7 @@ static void free(void *where)
58064 * warnings when not needed (indeed large_malloc / large_free are not
58065 * needed by inflate */
58066
58067 -#define malloc(a) kmalloc(a, GFP_KERNEL)
58068 +#define malloc(a) kmalloc((a), GFP_KERNEL)
58069 #define free(a) kfree(a)
58070
58071 #define large_malloc(a) vmalloc(a)
58072 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
58073 index e13117c..e9fc938 100644
58074 --- a/include/linux/dma-mapping.h
58075 +++ b/include/linux/dma-mapping.h
58076 @@ -46,7 +46,7 @@ struct dma_map_ops {
58077 u64 (*get_required_mask)(struct device *dev);
58078 #endif
58079 int is_phys;
58080 -};
58081 +} __do_const;
58082
58083 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
58084
58085 diff --git a/include/linux/efi.h b/include/linux/efi.h
58086 index 2362a0b..cfaf8fcc 100644
58087 --- a/include/linux/efi.h
58088 +++ b/include/linux/efi.h
58089 @@ -446,7 +446,7 @@ struct efivar_operations {
58090 efi_get_variable_t *get_variable;
58091 efi_get_next_variable_t *get_next_variable;
58092 efi_set_variable_t *set_variable;
58093 -};
58094 +} __no_const;
58095
58096 struct efivars {
58097 /*
58098 diff --git a/include/linux/elf.h b/include/linux/elf.h
58099 index 31f0508..5421c01 100644
58100 --- a/include/linux/elf.h
58101 +++ b/include/linux/elf.h
58102 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
58103 #define PT_GNU_EH_FRAME 0x6474e550
58104
58105 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
58106 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
58107 +
58108 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
58109 +
58110 +/* Constants for the e_flags field */
58111 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
58112 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
58113 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
58114 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
58115 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
58116 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
58117
58118 /*
58119 * Extended Numbering
58120 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
58121 #define DT_DEBUG 21
58122 #define DT_TEXTREL 22
58123 #define DT_JMPREL 23
58124 +#define DT_FLAGS 30
58125 + #define DF_TEXTREL 0x00000004
58126 #define DT_ENCODING 32
58127 #define OLD_DT_LOOS 0x60000000
58128 #define DT_LOOS 0x6000000d
58129 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
58130 #define PF_W 0x2
58131 #define PF_X 0x1
58132
58133 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
58134 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
58135 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
58136 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
58137 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
58138 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
58139 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
58140 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
58141 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
58142 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
58143 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
58144 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
58145 +
58146 typedef struct elf32_phdr{
58147 Elf32_Word p_type;
58148 Elf32_Off p_offset;
58149 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
58150 #define EI_OSABI 7
58151 #define EI_PAD 8
58152
58153 +#define EI_PAX 14
58154 +
58155 #define ELFMAG0 0x7f /* EI_MAG */
58156 #define ELFMAG1 'E'
58157 #define ELFMAG2 'L'
58158 @@ -423,6 +451,7 @@ extern Elf32_Dyn _DYNAMIC [];
58159 #define elf_note elf32_note
58160 #define elf_addr_t Elf32_Off
58161 #define Elf_Half Elf32_Half
58162 +#define elf_dyn Elf32_Dyn
58163
58164 #else
58165
58166 @@ -433,6 +462,7 @@ extern Elf64_Dyn _DYNAMIC [];
58167 #define elf_note elf64_note
58168 #define elf_addr_t Elf64_Off
58169 #define Elf_Half Elf64_Half
58170 +#define elf_dyn Elf64_Dyn
58171
58172 #endif
58173
58174 diff --git a/include/linux/filter.h b/include/linux/filter.h
58175 index 8eeb205..d59bfa2 100644
58176 --- a/include/linux/filter.h
58177 +++ b/include/linux/filter.h
58178 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
58179
58180 struct sk_buff;
58181 struct sock;
58182 +struct bpf_jit_work;
58183
58184 struct sk_filter
58185 {
58186 @@ -141,6 +142,9 @@ struct sk_filter
58187 unsigned int len; /* Number of filter blocks */
58188 unsigned int (*bpf_func)(const struct sk_buff *skb,
58189 const struct sock_filter *filter);
58190 +#ifdef CONFIG_BPF_JIT
58191 + struct bpf_jit_work *work;
58192 +#endif
58193 struct rcu_head rcu;
58194 struct sock_filter insns[0];
58195 };
58196 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
58197 index 84ccf8e..2e9b14c 100644
58198 --- a/include/linux/firewire.h
58199 +++ b/include/linux/firewire.h
58200 @@ -428,7 +428,7 @@ struct fw_iso_context {
58201 union {
58202 fw_iso_callback_t sc;
58203 fw_iso_mc_callback_t mc;
58204 - } callback;
58205 + } __no_const callback;
58206 void *callback_data;
58207 };
58208
58209 diff --git a/include/linux/fs.h b/include/linux/fs.h
58210 index e0bc4ff..d79c2fa 100644
58211 --- a/include/linux/fs.h
58212 +++ b/include/linux/fs.h
58213 @@ -1608,7 +1608,8 @@ struct file_operations {
58214 int (*setlease)(struct file *, long, struct file_lock **);
58215 long (*fallocate)(struct file *file, int mode, loff_t offset,
58216 loff_t len);
58217 -};
58218 +} __do_const;
58219 +typedef struct file_operations __no_const file_operations_no_const;
58220
58221 struct inode_operations {
58222 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
58223 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
58224 index 003dc0f..3c4ea97 100644
58225 --- a/include/linux/fs_struct.h
58226 +++ b/include/linux/fs_struct.h
58227 @@ -6,7 +6,7 @@
58228 #include <linux/seqlock.h>
58229
58230 struct fs_struct {
58231 - int users;
58232 + atomic_t users;
58233 spinlock_t lock;
58234 seqcount_t seq;
58235 int umask;
58236 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
58237 index ce31408..b1ad003 100644
58238 --- a/include/linux/fscache-cache.h
58239 +++ b/include/linux/fscache-cache.h
58240 @@ -102,7 +102,7 @@ struct fscache_operation {
58241 fscache_operation_release_t release;
58242 };
58243
58244 -extern atomic_t fscache_op_debug_id;
58245 +extern atomic_unchecked_t fscache_op_debug_id;
58246 extern void fscache_op_work_func(struct work_struct *work);
58247
58248 extern void fscache_enqueue_operation(struct fscache_operation *);
58249 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
58250 {
58251 INIT_WORK(&op->work, fscache_op_work_func);
58252 atomic_set(&op->usage, 1);
58253 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58254 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58255 op->processor = processor;
58256 op->release = release;
58257 INIT_LIST_HEAD(&op->pend_link);
58258 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
58259 index 2a53f10..0187fdf 100644
58260 --- a/include/linux/fsnotify.h
58261 +++ b/include/linux/fsnotify.h
58262 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
58263 */
58264 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
58265 {
58266 - return kstrdup(name, GFP_KERNEL);
58267 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
58268 }
58269
58270 /*
58271 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
58272 index 91d0e0a3..035666b 100644
58273 --- a/include/linux/fsnotify_backend.h
58274 +++ b/include/linux/fsnotify_backend.h
58275 @@ -105,6 +105,7 @@ struct fsnotify_ops {
58276 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
58277 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
58278 };
58279 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
58280
58281 /*
58282 * A group is a "thing" that wants to receive notification about filesystem
58283 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
58284 index c3da42d..c70e0df 100644
58285 --- a/include/linux/ftrace_event.h
58286 +++ b/include/linux/ftrace_event.h
58287 @@ -97,7 +97,7 @@ struct trace_event_functions {
58288 trace_print_func raw;
58289 trace_print_func hex;
58290 trace_print_func binary;
58291 -};
58292 +} __no_const;
58293
58294 struct trace_event {
58295 struct hlist_node node;
58296 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
58297 extern int trace_add_event_call(struct ftrace_event_call *call);
58298 extern void trace_remove_event_call(struct ftrace_event_call *call);
58299
58300 -#define is_signed_type(type) (((type)(-1)) < 0)
58301 +#define is_signed_type(type) (((type)(-1)) < (type)1)
58302
58303 int trace_set_clr_event(const char *system, const char *event, int set);
58304
58305 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
58306 index 6d18f35..ab71e2c 100644
58307 --- a/include/linux/genhd.h
58308 +++ b/include/linux/genhd.h
58309 @@ -185,7 +185,7 @@ struct gendisk {
58310 struct kobject *slave_dir;
58311
58312 struct timer_rand_state *random;
58313 - atomic_t sync_io; /* RAID */
58314 + atomic_unchecked_t sync_io; /* RAID */
58315 struct disk_events *ev;
58316 #ifdef CONFIG_BLK_DEV_INTEGRITY
58317 struct blk_integrity *integrity;
58318 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
58319 new file mode 100644
58320 index 0000000..0dc3943
58321 --- /dev/null
58322 +++ b/include/linux/gracl.h
58323 @@ -0,0 +1,317 @@
58324 +#ifndef GR_ACL_H
58325 +#define GR_ACL_H
58326 +
58327 +#include <linux/grdefs.h>
58328 +#include <linux/resource.h>
58329 +#include <linux/capability.h>
58330 +#include <linux/dcache.h>
58331 +#include <asm/resource.h>
58332 +
58333 +/* Major status information */
58334 +
58335 +#define GR_VERSION "grsecurity 2.2.2"
58336 +#define GRSECURITY_VERSION 0x2202
58337 +
58338 +enum {
58339 + GR_SHUTDOWN = 0,
58340 + GR_ENABLE = 1,
58341 + GR_SPROLE = 2,
58342 + GR_RELOAD = 3,
58343 + GR_SEGVMOD = 4,
58344 + GR_STATUS = 5,
58345 + GR_UNSPROLE = 6,
58346 + GR_PASSSET = 7,
58347 + GR_SPROLEPAM = 8,
58348 +};
58349 +
58350 +/* Password setup definitions
58351 + * kernel/grhash.c */
58352 +enum {
58353 + GR_PW_LEN = 128,
58354 + GR_SALT_LEN = 16,
58355 + GR_SHA_LEN = 32,
58356 +};
58357 +
58358 +enum {
58359 + GR_SPROLE_LEN = 64,
58360 +};
58361 +
58362 +enum {
58363 + GR_NO_GLOB = 0,
58364 + GR_REG_GLOB,
58365 + GR_CREATE_GLOB
58366 +};
58367 +
58368 +#define GR_NLIMITS 32
58369 +
58370 +/* Begin Data Structures */
58371 +
58372 +struct sprole_pw {
58373 + unsigned char *rolename;
58374 + unsigned char salt[GR_SALT_LEN];
58375 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
58376 +};
58377 +
58378 +struct name_entry {
58379 + __u32 key;
58380 + ino_t inode;
58381 + dev_t device;
58382 + char *name;
58383 + __u16 len;
58384 + __u8 deleted;
58385 + struct name_entry *prev;
58386 + struct name_entry *next;
58387 +};
58388 +
58389 +struct inodev_entry {
58390 + struct name_entry *nentry;
58391 + struct inodev_entry *prev;
58392 + struct inodev_entry *next;
58393 +};
58394 +
58395 +struct acl_role_db {
58396 + struct acl_role_label **r_hash;
58397 + __u32 r_size;
58398 +};
58399 +
58400 +struct inodev_db {
58401 + struct inodev_entry **i_hash;
58402 + __u32 i_size;
58403 +};
58404 +
58405 +struct name_db {
58406 + struct name_entry **n_hash;
58407 + __u32 n_size;
58408 +};
58409 +
58410 +struct crash_uid {
58411 + uid_t uid;
58412 + unsigned long expires;
58413 +};
58414 +
58415 +struct gr_hash_struct {
58416 + void **table;
58417 + void **nametable;
58418 + void *first;
58419 + __u32 table_size;
58420 + __u32 used_size;
58421 + int type;
58422 +};
58423 +
58424 +/* Userspace Grsecurity ACL data structures */
58425 +
58426 +struct acl_subject_label {
58427 + char *filename;
58428 + ino_t inode;
58429 + dev_t device;
58430 + __u32 mode;
58431 + kernel_cap_t cap_mask;
58432 + kernel_cap_t cap_lower;
58433 + kernel_cap_t cap_invert_audit;
58434 +
58435 + struct rlimit res[GR_NLIMITS];
58436 + __u32 resmask;
58437 +
58438 + __u8 user_trans_type;
58439 + __u8 group_trans_type;
58440 + uid_t *user_transitions;
58441 + gid_t *group_transitions;
58442 + __u16 user_trans_num;
58443 + __u16 group_trans_num;
58444 +
58445 + __u32 sock_families[2];
58446 + __u32 ip_proto[8];
58447 + __u32 ip_type;
58448 + struct acl_ip_label **ips;
58449 + __u32 ip_num;
58450 + __u32 inaddr_any_override;
58451 +
58452 + __u32 crashes;
58453 + unsigned long expires;
58454 +
58455 + struct acl_subject_label *parent_subject;
58456 + struct gr_hash_struct *hash;
58457 + struct acl_subject_label *prev;
58458 + struct acl_subject_label *next;
58459 +
58460 + struct acl_object_label **obj_hash;
58461 + __u32 obj_hash_size;
58462 + __u16 pax_flags;
58463 +};
58464 +
58465 +struct role_allowed_ip {
58466 + __u32 addr;
58467 + __u32 netmask;
58468 +
58469 + struct role_allowed_ip *prev;
58470 + struct role_allowed_ip *next;
58471 +};
58472 +
58473 +struct role_transition {
58474 + char *rolename;
58475 +
58476 + struct role_transition *prev;
58477 + struct role_transition *next;
58478 +};
58479 +
58480 +struct acl_role_label {
58481 + char *rolename;
58482 + uid_t uidgid;
58483 + __u16 roletype;
58484 +
58485 + __u16 auth_attempts;
58486 + unsigned long expires;
58487 +
58488 + struct acl_subject_label *root_label;
58489 + struct gr_hash_struct *hash;
58490 +
58491 + struct acl_role_label *prev;
58492 + struct acl_role_label *next;
58493 +
58494 + struct role_transition *transitions;
58495 + struct role_allowed_ip *allowed_ips;
58496 + uid_t *domain_children;
58497 + __u16 domain_child_num;
58498 +
58499 + struct acl_subject_label **subj_hash;
58500 + __u32 subj_hash_size;
58501 +};
58502 +
58503 +struct user_acl_role_db {
58504 + struct acl_role_label **r_table;
58505 + __u32 num_pointers; /* Number of allocations to track */
58506 + __u32 num_roles; /* Number of roles */
58507 + __u32 num_domain_children; /* Number of domain children */
58508 + __u32 num_subjects; /* Number of subjects */
58509 + __u32 num_objects; /* Number of objects */
58510 +};
58511 +
58512 +struct acl_object_label {
58513 + char *filename;
58514 + ino_t inode;
58515 + dev_t device;
58516 + __u32 mode;
58517 +
58518 + struct acl_subject_label *nested;
58519 + struct acl_object_label *globbed;
58520 +
58521 + /* next two structures not used */
58522 +
58523 + struct acl_object_label *prev;
58524 + struct acl_object_label *next;
58525 +};
58526 +
58527 +struct acl_ip_label {
58528 + char *iface;
58529 + __u32 addr;
58530 + __u32 netmask;
58531 + __u16 low, high;
58532 + __u8 mode;
58533 + __u32 type;
58534 + __u32 proto[8];
58535 +
58536 + /* next two structures not used */
58537 +
58538 + struct acl_ip_label *prev;
58539 + struct acl_ip_label *next;
58540 +};
58541 +
58542 +struct gr_arg {
58543 + struct user_acl_role_db role_db;
58544 + unsigned char pw[GR_PW_LEN];
58545 + unsigned char salt[GR_SALT_LEN];
58546 + unsigned char sum[GR_SHA_LEN];
58547 + unsigned char sp_role[GR_SPROLE_LEN];
58548 + struct sprole_pw *sprole_pws;
58549 + dev_t segv_device;
58550 + ino_t segv_inode;
58551 + uid_t segv_uid;
58552 + __u16 num_sprole_pws;
58553 + __u16 mode;
58554 +};
58555 +
58556 +struct gr_arg_wrapper {
58557 + struct gr_arg *arg;
58558 + __u32 version;
58559 + __u32 size;
58560 +};
58561 +
58562 +struct subject_map {
58563 + struct acl_subject_label *user;
58564 + struct acl_subject_label *kernel;
58565 + struct subject_map *prev;
58566 + struct subject_map *next;
58567 +};
58568 +
58569 +struct acl_subj_map_db {
58570 + struct subject_map **s_hash;
58571 + __u32 s_size;
58572 +};
58573 +
58574 +/* End Data Structures Section */
58575 +
58576 +/* Hash functions generated by empirical testing by Brad Spengler
58577 + Makes good use of the low bits of the inode. Generally 0-1 times
58578 + in loop for successful match. 0-3 for unsuccessful match.
58579 + Shift/add algorithm with modulus of table size and an XOR*/
58580 +
58581 +static __inline__ unsigned int
58582 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
58583 +{
58584 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
58585 +}
58586 +
58587 + static __inline__ unsigned int
58588 +shash(const struct acl_subject_label *userp, const unsigned int sz)
58589 +{
58590 + return ((const unsigned long)userp % sz);
58591 +}
58592 +
58593 +static __inline__ unsigned int
58594 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
58595 +{
58596 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
58597 +}
58598 +
58599 +static __inline__ unsigned int
58600 +nhash(const char *name, const __u16 len, const unsigned int sz)
58601 +{
58602 + return full_name_hash((const unsigned char *)name, len) % sz;
58603 +}
58604 +
58605 +#define FOR_EACH_ROLE_START(role) \
58606 + role = role_list; \
58607 + while (role) {
58608 +
58609 +#define FOR_EACH_ROLE_END(role) \
58610 + role = role->prev; \
58611 + }
58612 +
58613 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
58614 + subj = NULL; \
58615 + iter = 0; \
58616 + while (iter < role->subj_hash_size) { \
58617 + if (subj == NULL) \
58618 + subj = role->subj_hash[iter]; \
58619 + if (subj == NULL) { \
58620 + iter++; \
58621 + continue; \
58622 + }
58623 +
58624 +#define FOR_EACH_SUBJECT_END(subj,iter) \
58625 + subj = subj->next; \
58626 + if (subj == NULL) \
58627 + iter++; \
58628 + }
58629 +
58630 +
58631 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
58632 + subj = role->hash->first; \
58633 + while (subj != NULL) {
58634 +
58635 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
58636 + subj = subj->next; \
58637 + }
58638 +
58639 +#endif
58640 +
58641 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
58642 new file mode 100644
58643 index 0000000..323ecf2
58644 --- /dev/null
58645 +++ b/include/linux/gralloc.h
58646 @@ -0,0 +1,9 @@
58647 +#ifndef __GRALLOC_H
58648 +#define __GRALLOC_H
58649 +
58650 +void acl_free_all(void);
58651 +int acl_alloc_stack_init(unsigned long size);
58652 +void *acl_alloc(unsigned long len);
58653 +void *acl_alloc_num(unsigned long num, unsigned long len);
58654 +
58655 +#endif
58656 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
58657 new file mode 100644
58658 index 0000000..b30e9bc
58659 --- /dev/null
58660 +++ b/include/linux/grdefs.h
58661 @@ -0,0 +1,140 @@
58662 +#ifndef GRDEFS_H
58663 +#define GRDEFS_H
58664 +
58665 +/* Begin grsecurity status declarations */
58666 +
58667 +enum {
58668 + GR_READY = 0x01,
58669 + GR_STATUS_INIT = 0x00 // disabled state
58670 +};
58671 +
58672 +/* Begin ACL declarations */
58673 +
58674 +/* Role flags */
58675 +
58676 +enum {
58677 + GR_ROLE_USER = 0x0001,
58678 + GR_ROLE_GROUP = 0x0002,
58679 + GR_ROLE_DEFAULT = 0x0004,
58680 + GR_ROLE_SPECIAL = 0x0008,
58681 + GR_ROLE_AUTH = 0x0010,
58682 + GR_ROLE_NOPW = 0x0020,
58683 + GR_ROLE_GOD = 0x0040,
58684 + GR_ROLE_LEARN = 0x0080,
58685 + GR_ROLE_TPE = 0x0100,
58686 + GR_ROLE_DOMAIN = 0x0200,
58687 + GR_ROLE_PAM = 0x0400,
58688 + GR_ROLE_PERSIST = 0x0800
58689 +};
58690 +
58691 +/* ACL Subject and Object mode flags */
58692 +enum {
58693 + GR_DELETED = 0x80000000
58694 +};
58695 +
58696 +/* ACL Object-only mode flags */
58697 +enum {
58698 + GR_READ = 0x00000001,
58699 + GR_APPEND = 0x00000002,
58700 + GR_WRITE = 0x00000004,
58701 + GR_EXEC = 0x00000008,
58702 + GR_FIND = 0x00000010,
58703 + GR_INHERIT = 0x00000020,
58704 + GR_SETID = 0x00000040,
58705 + GR_CREATE = 0x00000080,
58706 + GR_DELETE = 0x00000100,
58707 + GR_LINK = 0x00000200,
58708 + GR_AUDIT_READ = 0x00000400,
58709 + GR_AUDIT_APPEND = 0x00000800,
58710 + GR_AUDIT_WRITE = 0x00001000,
58711 + GR_AUDIT_EXEC = 0x00002000,
58712 + GR_AUDIT_FIND = 0x00004000,
58713 + GR_AUDIT_INHERIT= 0x00008000,
58714 + GR_AUDIT_SETID = 0x00010000,
58715 + GR_AUDIT_CREATE = 0x00020000,
58716 + GR_AUDIT_DELETE = 0x00040000,
58717 + GR_AUDIT_LINK = 0x00080000,
58718 + GR_PTRACERD = 0x00100000,
58719 + GR_NOPTRACE = 0x00200000,
58720 + GR_SUPPRESS = 0x00400000,
58721 + GR_NOLEARN = 0x00800000,
58722 + GR_INIT_TRANSFER= 0x01000000
58723 +};
58724 +
58725 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
58726 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
58727 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
58728 +
58729 +/* ACL subject-only mode flags */
58730 +enum {
58731 + GR_KILL = 0x00000001,
58732 + GR_VIEW = 0x00000002,
58733 + GR_PROTECTED = 0x00000004,
58734 + GR_LEARN = 0x00000008,
58735 + GR_OVERRIDE = 0x00000010,
58736 + /* just a placeholder, this mode is only used in userspace */
58737 + GR_DUMMY = 0x00000020,
58738 + GR_PROTSHM = 0x00000040,
58739 + GR_KILLPROC = 0x00000080,
58740 + GR_KILLIPPROC = 0x00000100,
58741 + /* just a placeholder, this mode is only used in userspace */
58742 + GR_NOTROJAN = 0x00000200,
58743 + GR_PROTPROCFD = 0x00000400,
58744 + GR_PROCACCT = 0x00000800,
58745 + GR_RELAXPTRACE = 0x00001000,
58746 + GR_NESTED = 0x00002000,
58747 + GR_INHERITLEARN = 0x00004000,
58748 + GR_PROCFIND = 0x00008000,
58749 + GR_POVERRIDE = 0x00010000,
58750 + GR_KERNELAUTH = 0x00020000,
58751 + GR_ATSECURE = 0x00040000,
58752 + GR_SHMEXEC = 0x00080000
58753 +};
58754 +
58755 +enum {
58756 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
58757 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
58758 + GR_PAX_ENABLE_MPROTECT = 0x0004,
58759 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
58760 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
58761 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
58762 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
58763 + GR_PAX_DISABLE_MPROTECT = 0x0400,
58764 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
58765 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
58766 +};
58767 +
58768 +enum {
58769 + GR_ID_USER = 0x01,
58770 + GR_ID_GROUP = 0x02,
58771 +};
58772 +
58773 +enum {
58774 + GR_ID_ALLOW = 0x01,
58775 + GR_ID_DENY = 0x02,
58776 +};
58777 +
58778 +#define GR_CRASH_RES 31
58779 +#define GR_UIDTABLE_MAX 500
58780 +
58781 +/* begin resource learning section */
58782 +enum {
58783 + GR_RLIM_CPU_BUMP = 60,
58784 + GR_RLIM_FSIZE_BUMP = 50000,
58785 + GR_RLIM_DATA_BUMP = 10000,
58786 + GR_RLIM_STACK_BUMP = 1000,
58787 + GR_RLIM_CORE_BUMP = 10000,
58788 + GR_RLIM_RSS_BUMP = 500000,
58789 + GR_RLIM_NPROC_BUMP = 1,
58790 + GR_RLIM_NOFILE_BUMP = 5,
58791 + GR_RLIM_MEMLOCK_BUMP = 50000,
58792 + GR_RLIM_AS_BUMP = 500000,
58793 + GR_RLIM_LOCKS_BUMP = 2,
58794 + GR_RLIM_SIGPENDING_BUMP = 5,
58795 + GR_RLIM_MSGQUEUE_BUMP = 10000,
58796 + GR_RLIM_NICE_BUMP = 1,
58797 + GR_RLIM_RTPRIO_BUMP = 1,
58798 + GR_RLIM_RTTIME_BUMP = 1000000
58799 +};
58800 +
58801 +#endif
58802 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
58803 new file mode 100644
58804 index 0000000..da390f1
58805 --- /dev/null
58806 +++ b/include/linux/grinternal.h
58807 @@ -0,0 +1,221 @@
58808 +#ifndef __GRINTERNAL_H
58809 +#define __GRINTERNAL_H
58810 +
58811 +#ifdef CONFIG_GRKERNSEC
58812 +
58813 +#include <linux/fs.h>
58814 +#include <linux/mnt_namespace.h>
58815 +#include <linux/nsproxy.h>
58816 +#include <linux/gracl.h>
58817 +#include <linux/grdefs.h>
58818 +#include <linux/grmsg.h>
58819 +
58820 +void gr_add_learn_entry(const char *fmt, ...)
58821 + __attribute__ ((format (printf, 1, 2)));
58822 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
58823 + const struct vfsmount *mnt);
58824 +__u32 gr_check_create(const struct dentry *new_dentry,
58825 + const struct dentry *parent,
58826 + const struct vfsmount *mnt, const __u32 mode);
58827 +int gr_check_protected_task(const struct task_struct *task);
58828 +__u32 to_gr_audit(const __u32 reqmode);
58829 +int gr_set_acls(const int type);
58830 +int gr_apply_subject_to_task(struct task_struct *task);
58831 +int gr_acl_is_enabled(void);
58832 +char gr_roletype_to_char(void);
58833 +
58834 +void gr_handle_alertkill(struct task_struct *task);
58835 +char *gr_to_filename(const struct dentry *dentry,
58836 + const struct vfsmount *mnt);
58837 +char *gr_to_filename1(const struct dentry *dentry,
58838 + const struct vfsmount *mnt);
58839 +char *gr_to_filename2(const struct dentry *dentry,
58840 + const struct vfsmount *mnt);
58841 +char *gr_to_filename3(const struct dentry *dentry,
58842 + const struct vfsmount *mnt);
58843 +
58844 +extern int grsec_enable_ptrace_readexec;
58845 +extern int grsec_enable_harden_ptrace;
58846 +extern int grsec_enable_link;
58847 +extern int grsec_enable_fifo;
58848 +extern int grsec_enable_execve;
58849 +extern int grsec_enable_shm;
58850 +extern int grsec_enable_execlog;
58851 +extern int grsec_enable_signal;
58852 +extern int grsec_enable_audit_ptrace;
58853 +extern int grsec_enable_forkfail;
58854 +extern int grsec_enable_time;
58855 +extern int grsec_enable_rofs;
58856 +extern int grsec_enable_chroot_shmat;
58857 +extern int grsec_enable_chroot_mount;
58858 +extern int grsec_enable_chroot_double;
58859 +extern int grsec_enable_chroot_pivot;
58860 +extern int grsec_enable_chroot_chdir;
58861 +extern int grsec_enable_chroot_chmod;
58862 +extern int grsec_enable_chroot_mknod;
58863 +extern int grsec_enable_chroot_fchdir;
58864 +extern int grsec_enable_chroot_nice;
58865 +extern int grsec_enable_chroot_execlog;
58866 +extern int grsec_enable_chroot_caps;
58867 +extern int grsec_enable_chroot_sysctl;
58868 +extern int grsec_enable_chroot_unix;
58869 +extern int grsec_enable_tpe;
58870 +extern int grsec_tpe_gid;
58871 +extern int grsec_enable_tpe_all;
58872 +extern int grsec_enable_tpe_invert;
58873 +extern int grsec_enable_socket_all;
58874 +extern int grsec_socket_all_gid;
58875 +extern int grsec_enable_socket_client;
58876 +extern int grsec_socket_client_gid;
58877 +extern int grsec_enable_socket_server;
58878 +extern int grsec_socket_server_gid;
58879 +extern int grsec_audit_gid;
58880 +extern int grsec_enable_group;
58881 +extern int grsec_enable_audit_textrel;
58882 +extern int grsec_enable_log_rwxmaps;
58883 +extern int grsec_enable_mount;
58884 +extern int grsec_enable_chdir;
58885 +extern int grsec_resource_logging;
58886 +extern int grsec_enable_blackhole;
58887 +extern int grsec_lastack_retries;
58888 +extern int grsec_enable_brute;
58889 +extern int grsec_lock;
58890 +
58891 +extern spinlock_t grsec_alert_lock;
58892 +extern unsigned long grsec_alert_wtime;
58893 +extern unsigned long grsec_alert_fyet;
58894 +
58895 +extern spinlock_t grsec_audit_lock;
58896 +
58897 +extern rwlock_t grsec_exec_file_lock;
58898 +
58899 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
58900 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
58901 + (tsk)->exec_file->f_vfsmnt) : "/")
58902 +
58903 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
58904 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
58905 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
58906 +
58907 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
58908 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
58909 + (tsk)->exec_file->f_vfsmnt) : "/")
58910 +
58911 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
58912 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
58913 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
58914 +
58915 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
58916 +
58917 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
58918 +
58919 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
58920 + (task)->pid, (cred)->uid, \
58921 + (cred)->euid, (cred)->gid, (cred)->egid, \
58922 + gr_parent_task_fullpath(task), \
58923 + (task)->real_parent->comm, (task)->real_parent->pid, \
58924 + (pcred)->uid, (pcred)->euid, \
58925 + (pcred)->gid, (pcred)->egid
58926 +
58927 +#define GR_CHROOT_CAPS {{ \
58928 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
58929 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
58930 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
58931 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
58932 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
58933 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
58934 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
58935 +
58936 +#define security_learn(normal_msg,args...) \
58937 +({ \
58938 + read_lock(&grsec_exec_file_lock); \
58939 + gr_add_learn_entry(normal_msg "\n", ## args); \
58940 + read_unlock(&grsec_exec_file_lock); \
58941 +})
58942 +
58943 +enum {
58944 + GR_DO_AUDIT,
58945 + GR_DONT_AUDIT,
58946 + /* used for non-audit messages that we shouldn't kill the task on */
58947 + GR_DONT_AUDIT_GOOD
58948 +};
58949 +
58950 +enum {
58951 + GR_TTYSNIFF,
58952 + GR_RBAC,
58953 + GR_RBAC_STR,
58954 + GR_STR_RBAC,
58955 + GR_RBAC_MODE2,
58956 + GR_RBAC_MODE3,
58957 + GR_FILENAME,
58958 + GR_SYSCTL_HIDDEN,
58959 + GR_NOARGS,
58960 + GR_ONE_INT,
58961 + GR_ONE_INT_TWO_STR,
58962 + GR_ONE_STR,
58963 + GR_STR_INT,
58964 + GR_TWO_STR_INT,
58965 + GR_TWO_INT,
58966 + GR_TWO_U64,
58967 + GR_THREE_INT,
58968 + GR_FIVE_INT_TWO_STR,
58969 + GR_TWO_STR,
58970 + GR_THREE_STR,
58971 + GR_FOUR_STR,
58972 + GR_STR_FILENAME,
58973 + GR_FILENAME_STR,
58974 + GR_FILENAME_TWO_INT,
58975 + GR_FILENAME_TWO_INT_STR,
58976 + GR_TEXTREL,
58977 + GR_PTRACE,
58978 + GR_RESOURCE,
58979 + GR_CAP,
58980 + GR_SIG,
58981 + GR_SIG2,
58982 + GR_CRASH1,
58983 + GR_CRASH2,
58984 + GR_PSACCT,
58985 + GR_RWXMAP
58986 +};
58987 +
58988 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
58989 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
58990 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
58991 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
58992 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
58993 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
58994 +#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)
58995 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
58996 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
58997 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
58998 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
58999 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
59000 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
59001 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
59002 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
59003 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
59004 +#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)
59005 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
59006 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
59007 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
59008 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
59009 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
59010 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
59011 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
59012 +#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)
59013 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
59014 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
59015 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
59016 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
59017 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
59018 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
59019 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
59020 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
59021 +#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)
59022 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
59023 +
59024 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
59025 +
59026 +#endif
59027 +
59028 +#endif
59029 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
59030 new file mode 100644
59031 index 0000000..8b9ed56
59032 --- /dev/null
59033 +++ b/include/linux/grmsg.h
59034 @@ -0,0 +1,110 @@
59035 +#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"
59036 +#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"
59037 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
59038 +#define GR_STOPMOD_MSG "denied modification of module state by "
59039 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
59040 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
59041 +#define GR_IOPERM_MSG "denied use of ioperm() by "
59042 +#define GR_IOPL_MSG "denied use of iopl() by "
59043 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
59044 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
59045 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
59046 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
59047 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
59048 +#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"
59049 +#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"
59050 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
59051 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
59052 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
59053 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
59054 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
59055 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
59056 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
59057 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
59058 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
59059 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
59060 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
59061 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
59062 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
59063 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
59064 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
59065 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
59066 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
59067 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
59068 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
59069 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
59070 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
59071 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
59072 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
59073 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
59074 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
59075 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
59076 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
59077 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
59078 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
59079 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
59080 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
59081 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
59082 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
59083 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
59084 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
59085 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
59086 +#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"
59087 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
59088 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
59089 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
59090 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
59091 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
59092 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
59093 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
59094 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
59095 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
59096 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
59097 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
59098 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
59099 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
59100 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
59101 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
59102 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
59103 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
59104 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
59105 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
59106 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
59107 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
59108 +#define GR_NICE_CHROOT_MSG "denied priority change by "
59109 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
59110 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
59111 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
59112 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
59113 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
59114 +#define GR_TIME_MSG "time set by "
59115 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
59116 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
59117 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
59118 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
59119 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
59120 +#define GR_BIND_MSG "denied bind() by "
59121 +#define GR_CONNECT_MSG "denied connect() by "
59122 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
59123 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
59124 +#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"
59125 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
59126 +#define GR_CAP_ACL_MSG "use of %s denied for "
59127 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
59128 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
59129 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
59130 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
59131 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
59132 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
59133 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
59134 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
59135 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
59136 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
59137 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
59138 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
59139 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
59140 +#define GR_VM86_MSG "denied use of vm86 by "
59141 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
59142 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
59143 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
59144 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
59145 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
59146 new file mode 100644
59147 index 0000000..10c8ced
59148 --- /dev/null
59149 +++ b/include/linux/grsecurity.h
59150 @@ -0,0 +1,229 @@
59151 +#ifndef GR_SECURITY_H
59152 +#define GR_SECURITY_H
59153 +#include <linux/fs.h>
59154 +#include <linux/fs_struct.h>
59155 +#include <linux/binfmts.h>
59156 +#include <linux/gracl.h>
59157 +
59158 +/* notify of brain-dead configs */
59159 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59160 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
59161 +#endif
59162 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
59163 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
59164 +#endif
59165 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
59166 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
59167 +#endif
59168 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
59169 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
59170 +#endif
59171 +
59172 +#include <linux/compat.h>
59173 +
59174 +struct user_arg_ptr {
59175 +#ifdef CONFIG_COMPAT
59176 + bool is_compat;
59177 +#endif
59178 + union {
59179 + const char __user *const __user *native;
59180 +#ifdef CONFIG_COMPAT
59181 + compat_uptr_t __user *compat;
59182 +#endif
59183 + } ptr;
59184 +};
59185 +
59186 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
59187 +void gr_handle_brute_check(void);
59188 +void gr_handle_kernel_exploit(void);
59189 +int gr_process_user_ban(void);
59190 +
59191 +char gr_roletype_to_char(void);
59192 +
59193 +int gr_acl_enable_at_secure(void);
59194 +
59195 +int gr_check_user_change(int real, int effective, int fs);
59196 +int gr_check_group_change(int real, int effective, int fs);
59197 +
59198 +void gr_del_task_from_ip_table(struct task_struct *p);
59199 +
59200 +int gr_pid_is_chrooted(struct task_struct *p);
59201 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
59202 +int gr_handle_chroot_nice(void);
59203 +int gr_handle_chroot_sysctl(const int op);
59204 +int gr_handle_chroot_setpriority(struct task_struct *p,
59205 + const int niceval);
59206 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
59207 +int gr_handle_chroot_chroot(const struct dentry *dentry,
59208 + const struct vfsmount *mnt);
59209 +void gr_handle_chroot_chdir(struct path *path);
59210 +int gr_handle_chroot_chmod(const struct dentry *dentry,
59211 + const struct vfsmount *mnt, const int mode);
59212 +int gr_handle_chroot_mknod(const struct dentry *dentry,
59213 + const struct vfsmount *mnt, const int mode);
59214 +int gr_handle_chroot_mount(const struct dentry *dentry,
59215 + const struct vfsmount *mnt,
59216 + const char *dev_name);
59217 +int gr_handle_chroot_pivot(void);
59218 +int gr_handle_chroot_unix(const pid_t pid);
59219 +
59220 +int gr_handle_rawio(const struct inode *inode);
59221 +
59222 +void gr_handle_ioperm(void);
59223 +void gr_handle_iopl(void);
59224 +
59225 +int gr_tpe_allow(const struct file *file);
59226 +
59227 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
59228 +void gr_clear_chroot_entries(struct task_struct *task);
59229 +
59230 +void gr_log_forkfail(const int retval);
59231 +void gr_log_timechange(void);
59232 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
59233 +void gr_log_chdir(const struct dentry *dentry,
59234 + const struct vfsmount *mnt);
59235 +void gr_log_chroot_exec(const struct dentry *dentry,
59236 + const struct vfsmount *mnt);
59237 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
59238 +void gr_log_remount(const char *devname, const int retval);
59239 +void gr_log_unmount(const char *devname, const int retval);
59240 +void gr_log_mount(const char *from, const char *to, const int retval);
59241 +void gr_log_textrel(struct vm_area_struct *vma);
59242 +void gr_log_rwxmmap(struct file *file);
59243 +void gr_log_rwxmprotect(struct file *file);
59244 +
59245 +int gr_handle_follow_link(const struct inode *parent,
59246 + const struct inode *inode,
59247 + const struct dentry *dentry,
59248 + const struct vfsmount *mnt);
59249 +int gr_handle_fifo(const struct dentry *dentry,
59250 + const struct vfsmount *mnt,
59251 + const struct dentry *dir, const int flag,
59252 + const int acc_mode);
59253 +int gr_handle_hardlink(const struct dentry *dentry,
59254 + const struct vfsmount *mnt,
59255 + struct inode *inode,
59256 + const int mode, const char *to);
59257 +
59258 +int gr_is_capable(const int cap);
59259 +int gr_is_capable_nolog(const int cap);
59260 +void gr_learn_resource(const struct task_struct *task, const int limit,
59261 + const unsigned long wanted, const int gt);
59262 +void gr_copy_label(struct task_struct *tsk);
59263 +void gr_handle_crash(struct task_struct *task, const int sig);
59264 +int gr_handle_signal(const struct task_struct *p, const int sig);
59265 +int gr_check_crash_uid(const uid_t uid);
59266 +int gr_check_protected_task(const struct task_struct *task);
59267 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
59268 +int gr_acl_handle_mmap(const struct file *file,
59269 + const unsigned long prot);
59270 +int gr_acl_handle_mprotect(const struct file *file,
59271 + const unsigned long prot);
59272 +int gr_check_hidden_task(const struct task_struct *tsk);
59273 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
59274 + const struct vfsmount *mnt);
59275 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
59276 + const struct vfsmount *mnt);
59277 +__u32 gr_acl_handle_access(const struct dentry *dentry,
59278 + const struct vfsmount *mnt, const int fmode);
59279 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
59280 + const struct vfsmount *mnt, mode_t mode);
59281 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
59282 + const struct vfsmount *mnt, mode_t mode);
59283 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
59284 + const struct vfsmount *mnt);
59285 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
59286 + const struct vfsmount *mnt);
59287 +int gr_handle_ptrace(struct task_struct *task, const long request);
59288 +int gr_handle_proc_ptrace(struct task_struct *task);
59289 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
59290 + const struct vfsmount *mnt);
59291 +int gr_check_crash_exec(const struct file *filp);
59292 +int gr_acl_is_enabled(void);
59293 +void gr_set_kernel_label(struct task_struct *task);
59294 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
59295 + const gid_t gid);
59296 +int gr_set_proc_label(const struct dentry *dentry,
59297 + const struct vfsmount *mnt,
59298 + const int unsafe_flags);
59299 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
59300 + const struct vfsmount *mnt);
59301 +__u32 gr_acl_handle_open(const struct dentry *dentry,
59302 + const struct vfsmount *mnt, int acc_mode);
59303 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
59304 + const struct dentry *p_dentry,
59305 + const struct vfsmount *p_mnt,
59306 + int open_flags, int acc_mode, const int imode);
59307 +void gr_handle_create(const struct dentry *dentry,
59308 + const struct vfsmount *mnt);
59309 +void gr_handle_proc_create(const struct dentry *dentry,
59310 + const struct inode *inode);
59311 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
59312 + const struct dentry *parent_dentry,
59313 + const struct vfsmount *parent_mnt,
59314 + const int mode);
59315 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
59316 + const struct dentry *parent_dentry,
59317 + const struct vfsmount *parent_mnt);
59318 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
59319 + const struct vfsmount *mnt);
59320 +void gr_handle_delete(const ino_t ino, const dev_t dev);
59321 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
59322 + const struct vfsmount *mnt);
59323 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
59324 + const struct dentry *parent_dentry,
59325 + const struct vfsmount *parent_mnt,
59326 + const char *from);
59327 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
59328 + const struct dentry *parent_dentry,
59329 + const struct vfsmount *parent_mnt,
59330 + const struct dentry *old_dentry,
59331 + const struct vfsmount *old_mnt, const char *to);
59332 +int gr_acl_handle_rename(struct dentry *new_dentry,
59333 + struct dentry *parent_dentry,
59334 + const struct vfsmount *parent_mnt,
59335 + struct dentry *old_dentry,
59336 + struct inode *old_parent_inode,
59337 + struct vfsmount *old_mnt, const char *newname);
59338 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59339 + struct dentry *old_dentry,
59340 + struct dentry *new_dentry,
59341 + struct vfsmount *mnt, const __u8 replace);
59342 +__u32 gr_check_link(const struct dentry *new_dentry,
59343 + const struct dentry *parent_dentry,
59344 + const struct vfsmount *parent_mnt,
59345 + const struct dentry *old_dentry,
59346 + const struct vfsmount *old_mnt);
59347 +int gr_acl_handle_filldir(const struct file *file, const char *name,
59348 + const unsigned int namelen, const ino_t ino);
59349 +
59350 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
59351 + const struct vfsmount *mnt);
59352 +void gr_acl_handle_exit(void);
59353 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
59354 +int gr_acl_handle_procpidmem(const struct task_struct *task);
59355 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
59356 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
59357 +void gr_audit_ptrace(struct task_struct *task);
59358 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
59359 +
59360 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
59361 +
59362 +#ifdef CONFIG_GRKERNSEC
59363 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
59364 +void gr_handle_vm86(void);
59365 +void gr_handle_mem_readwrite(u64 from, u64 to);
59366 +
59367 +void gr_log_badprocpid(const char *entry);
59368 +
59369 +extern int grsec_enable_dmesg;
59370 +extern int grsec_disable_privio;
59371 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59372 +extern int grsec_enable_chroot_findtask;
59373 +#endif
59374 +#ifdef CONFIG_GRKERNSEC_SETXID
59375 +extern int grsec_enable_setxid;
59376 +#endif
59377 +#endif
59378 +
59379 +#endif
59380 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
59381 new file mode 100644
59382 index 0000000..e7ffaaf
59383 --- /dev/null
59384 +++ b/include/linux/grsock.h
59385 @@ -0,0 +1,19 @@
59386 +#ifndef __GRSOCK_H
59387 +#define __GRSOCK_H
59388 +
59389 +extern void gr_attach_curr_ip(const struct sock *sk);
59390 +extern int gr_handle_sock_all(const int family, const int type,
59391 + const int protocol);
59392 +extern int gr_handle_sock_server(const struct sockaddr *sck);
59393 +extern int gr_handle_sock_server_other(const struct sock *sck);
59394 +extern int gr_handle_sock_client(const struct sockaddr *sck);
59395 +extern int gr_search_connect(struct socket * sock,
59396 + struct sockaddr_in * addr);
59397 +extern int gr_search_bind(struct socket * sock,
59398 + struct sockaddr_in * addr);
59399 +extern int gr_search_listen(struct socket * sock);
59400 +extern int gr_search_accept(struct socket * sock);
59401 +extern int gr_search_socket(const int domain, const int type,
59402 + const int protocol);
59403 +
59404 +#endif
59405 diff --git a/include/linux/hid.h b/include/linux/hid.h
59406 index c235e4e..f0cf7a0 100644
59407 --- a/include/linux/hid.h
59408 +++ b/include/linux/hid.h
59409 @@ -679,7 +679,7 @@ struct hid_ll_driver {
59410 unsigned int code, int value);
59411
59412 int (*parse)(struct hid_device *hdev);
59413 -};
59414 +} __no_const;
59415
59416 #define PM_HINT_FULLON 1<<5
59417 #define PM_HINT_NORMAL 1<<1
59418 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
59419 index 3a93f73..b19d0b3 100644
59420 --- a/include/linux/highmem.h
59421 +++ b/include/linux/highmem.h
59422 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
59423 kunmap_atomic(kaddr, KM_USER0);
59424 }
59425
59426 +static inline void sanitize_highpage(struct page *page)
59427 +{
59428 + void *kaddr;
59429 + unsigned long flags;
59430 +
59431 + local_irq_save(flags);
59432 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
59433 + clear_page(kaddr);
59434 + kunmap_atomic(kaddr, KM_CLEARPAGE);
59435 + local_irq_restore(flags);
59436 +}
59437 +
59438 static inline void zero_user_segments(struct page *page,
59439 unsigned start1, unsigned end1,
59440 unsigned start2, unsigned end2)
59441 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
59442 index 07d103a..04ec65b 100644
59443 --- a/include/linux/i2c.h
59444 +++ b/include/linux/i2c.h
59445 @@ -364,6 +364,7 @@ struct i2c_algorithm {
59446 /* To determine what the adapter supports */
59447 u32 (*functionality) (struct i2c_adapter *);
59448 };
59449 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
59450
59451 /*
59452 * i2c_adapter is the structure used to identify a physical i2c bus along
59453 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
59454 index a6deef4..c56a7f2 100644
59455 --- a/include/linux/i2o.h
59456 +++ b/include/linux/i2o.h
59457 @@ -564,7 +564,7 @@ struct i2o_controller {
59458 struct i2o_device *exec; /* Executive */
59459 #if BITS_PER_LONG == 64
59460 spinlock_t context_list_lock; /* lock for context_list */
59461 - atomic_t context_list_counter; /* needed for unique contexts */
59462 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
59463 struct list_head context_list; /* list of context id's
59464 and pointers */
59465 #endif
59466 diff --git a/include/linux/init.h b/include/linux/init.h
59467 index 9146f39..885354d 100644
59468 --- a/include/linux/init.h
59469 +++ b/include/linux/init.h
59470 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cmdline);
59471
59472 /* Each module must use one module_init(). */
59473 #define module_init(initfn) \
59474 - static inline initcall_t __inittest(void) \
59475 + static inline __used initcall_t __inittest(void) \
59476 { return initfn; } \
59477 int init_module(void) __attribute__((alias(#initfn)));
59478
59479 /* This is only required if you want to be unloadable. */
59480 #define module_exit(exitfn) \
59481 - static inline exitcall_t __exittest(void) \
59482 + static inline __used exitcall_t __exittest(void) \
59483 { return exitfn; } \
59484 void cleanup_module(void) __attribute__((alias(#exitfn)));
59485
59486 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
59487 index 32574ee..00d4ef1 100644
59488 --- a/include/linux/init_task.h
59489 +++ b/include/linux/init_task.h
59490 @@ -128,6 +128,12 @@ extern struct cred init_cred;
59491
59492 #define INIT_TASK_COMM "swapper"
59493
59494 +#ifdef CONFIG_X86
59495 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
59496 +#else
59497 +#define INIT_TASK_THREAD_INFO
59498 +#endif
59499 +
59500 /*
59501 * INIT_TASK is used to set up the first task table, touch at
59502 * your own risk!. Base=0, limit=0x1fffff (=2MB)
59503 @@ -166,6 +172,7 @@ extern struct cred init_cred;
59504 RCU_INIT_POINTER(.cred, &init_cred), \
59505 .comm = INIT_TASK_COMM, \
59506 .thread = INIT_THREAD, \
59507 + INIT_TASK_THREAD_INFO \
59508 .fs = &init_fs, \
59509 .files = &init_files, \
59510 .signal = &init_signals, \
59511 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
59512 index e6ca56d..8583707 100644
59513 --- a/include/linux/intel-iommu.h
59514 +++ b/include/linux/intel-iommu.h
59515 @@ -296,7 +296,7 @@ struct iommu_flush {
59516 u8 fm, u64 type);
59517 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
59518 unsigned int size_order, u64 type);
59519 -};
59520 +} __no_const;
59521
59522 enum {
59523 SR_DMAR_FECTL_REG,
59524 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
59525 index a64b00e..464d8bc 100644
59526 --- a/include/linux/interrupt.h
59527 +++ b/include/linux/interrupt.h
59528 @@ -441,7 +441,7 @@ enum
59529 /* map softirq index to softirq name. update 'softirq_to_name' in
59530 * kernel/softirq.c when adding a new softirq.
59531 */
59532 -extern char *softirq_to_name[NR_SOFTIRQS];
59533 +extern const char * const softirq_to_name[NR_SOFTIRQS];
59534
59535 /* softirq mask and active fields moved to irq_cpustat_t in
59536 * asm/hardirq.h to get better cache usage. KAO
59537 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
59538
59539 struct softirq_action
59540 {
59541 - void (*action)(struct softirq_action *);
59542 + void (*action)(void);
59543 };
59544
59545 asmlinkage void do_softirq(void);
59546 asmlinkage void __do_softirq(void);
59547 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
59548 +extern void open_softirq(int nr, void (*action)(void));
59549 extern void softirq_init(void);
59550 static inline void __raise_softirq_irqoff(unsigned int nr)
59551 {
59552 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
59553 index 3875719..4cd454c 100644
59554 --- a/include/linux/kallsyms.h
59555 +++ b/include/linux/kallsyms.h
59556 @@ -15,7 +15,8 @@
59557
59558 struct module;
59559
59560 -#ifdef CONFIG_KALLSYMS
59561 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
59562 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59563 /* Lookup the address for a symbol. Returns 0 if not found. */
59564 unsigned long kallsyms_lookup_name(const char *name);
59565
59566 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
59567 /* Stupid that this does nothing, but I didn't create this mess. */
59568 #define __print_symbol(fmt, addr)
59569 #endif /*CONFIG_KALLSYMS*/
59570 +#else /* when included by kallsyms.c, vsnprintf.c, or
59571 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
59572 +extern void __print_symbol(const char *fmt, unsigned long address);
59573 +extern int sprint_backtrace(char *buffer, unsigned long address);
59574 +extern int sprint_symbol(char *buffer, unsigned long address);
59575 +const char *kallsyms_lookup(unsigned long addr,
59576 + unsigned long *symbolsize,
59577 + unsigned long *offset,
59578 + char **modname, char *namebuf);
59579 +#endif
59580
59581 /* This macro allows us to keep printk typechecking */
59582 static __printf(1, 2)
59583 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
59584 index fa39183..40160be 100644
59585 --- a/include/linux/kgdb.h
59586 +++ b/include/linux/kgdb.h
59587 @@ -53,7 +53,7 @@ extern int kgdb_connected;
59588 extern int kgdb_io_module_registered;
59589
59590 extern atomic_t kgdb_setting_breakpoint;
59591 -extern atomic_t kgdb_cpu_doing_single_step;
59592 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
59593
59594 extern struct task_struct *kgdb_usethread;
59595 extern struct task_struct *kgdb_contthread;
59596 @@ -251,7 +251,7 @@ struct kgdb_arch {
59597 void (*disable_hw_break)(struct pt_regs *regs);
59598 void (*remove_all_hw_break)(void);
59599 void (*correct_hw_break)(void);
59600 -};
59601 +} __do_const;
59602
59603 /**
59604 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
59605 @@ -276,7 +276,7 @@ struct kgdb_io {
59606 void (*pre_exception) (void);
59607 void (*post_exception) (void);
59608 int is_console;
59609 -};
59610 +} __do_const;
59611
59612 extern struct kgdb_arch arch_kgdb_ops;
59613
59614 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
59615 index b16f653..eb908f4 100644
59616 --- a/include/linux/kmod.h
59617 +++ b/include/linux/kmod.h
59618 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
59619 * usually useless though. */
59620 extern __printf(2, 3)
59621 int __request_module(bool wait, const char *name, ...);
59622 +extern __printf(3, 4)
59623 +int ___request_module(bool wait, char *param_name, const char *name, ...);
59624 #define request_module(mod...) __request_module(true, mod)
59625 #define request_module_nowait(mod...) __request_module(false, mod)
59626 #define try_then_request_module(x, mod...) \
59627 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
59628 index d526231..086e89b 100644
59629 --- a/include/linux/kvm_host.h
59630 +++ b/include/linux/kvm_host.h
59631 @@ -308,7 +308,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
59632 void vcpu_load(struct kvm_vcpu *vcpu);
59633 void vcpu_put(struct kvm_vcpu *vcpu);
59634
59635 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
59636 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
59637 struct module *module);
59638 void kvm_exit(void);
59639
59640 @@ -454,7 +454,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
59641 struct kvm_guest_debug *dbg);
59642 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
59643
59644 -int kvm_arch_init(void *opaque);
59645 +int kvm_arch_init(const void *opaque);
59646 void kvm_arch_exit(void);
59647
59648 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
59649 diff --git a/include/linux/libata.h b/include/linux/libata.h
59650 index cafc09a..d7e7829 100644
59651 --- a/include/linux/libata.h
59652 +++ b/include/linux/libata.h
59653 @@ -909,7 +909,7 @@ struct ata_port_operations {
59654 * fields must be pointers.
59655 */
59656 const struct ata_port_operations *inherits;
59657 -};
59658 +} __do_const;
59659
59660 struct ata_port_info {
59661 unsigned long flags;
59662 diff --git a/include/linux/mca.h b/include/linux/mca.h
59663 index 3797270..7765ede 100644
59664 --- a/include/linux/mca.h
59665 +++ b/include/linux/mca.h
59666 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
59667 int region);
59668 void * (*mca_transform_memory)(struct mca_device *,
59669 void *memory);
59670 -};
59671 +} __no_const;
59672
59673 struct mca_bus {
59674 u64 default_dma_mask;
59675 diff --git a/include/linux/memory.h b/include/linux/memory.h
59676 index 935699b..11042cc 100644
59677 --- a/include/linux/memory.h
59678 +++ b/include/linux/memory.h
59679 @@ -144,7 +144,7 @@ struct memory_accessor {
59680 size_t count);
59681 ssize_t (*write)(struct memory_accessor *, const char *buf,
59682 off_t offset, size_t count);
59683 -};
59684 +} __no_const;
59685
59686 /*
59687 * Kernel text modification mutex, used for code patching. Users of this lock
59688 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
59689 index 9970337..9444122 100644
59690 --- a/include/linux/mfd/abx500.h
59691 +++ b/include/linux/mfd/abx500.h
59692 @@ -188,6 +188,7 @@ struct abx500_ops {
59693 int (*event_registers_startup_state_get) (struct device *, u8 *);
59694 int (*startup_irq_enabled) (struct device *, unsigned int);
59695 };
59696 +typedef struct abx500_ops __no_const abx500_ops_no_const;
59697
59698 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
59699 void abx500_remove_ops(struct device *dev);
59700 diff --git a/include/linux/mm.h b/include/linux/mm.h
59701 index 4baadd1..2e0b45e 100644
59702 --- a/include/linux/mm.h
59703 +++ b/include/linux/mm.h
59704 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
59705
59706 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
59707 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
59708 +
59709 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
59710 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
59711 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
59712 +#else
59713 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
59714 +#endif
59715 +
59716 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
59717 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
59718
59719 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
59720 int set_page_dirty_lock(struct page *page);
59721 int clear_page_dirty_for_io(struct page *page);
59722
59723 -/* Is the vma a continuation of the stack vma above it? */
59724 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
59725 -{
59726 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
59727 -}
59728 -
59729 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
59730 - unsigned long addr)
59731 -{
59732 - return (vma->vm_flags & VM_GROWSDOWN) &&
59733 - (vma->vm_start == addr) &&
59734 - !vma_growsdown(vma->vm_prev, addr);
59735 -}
59736 -
59737 -/* Is the vma a continuation of the stack vma below it? */
59738 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
59739 -{
59740 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
59741 -}
59742 -
59743 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
59744 - unsigned long addr)
59745 -{
59746 - return (vma->vm_flags & VM_GROWSUP) &&
59747 - (vma->vm_end == addr) &&
59748 - !vma_growsup(vma->vm_next, addr);
59749 -}
59750 -
59751 extern unsigned long move_page_tables(struct vm_area_struct *vma,
59752 unsigned long old_addr, struct vm_area_struct *new_vma,
59753 unsigned long new_addr, unsigned long len);
59754 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
59755 }
59756 #endif
59757
59758 +#ifdef CONFIG_MMU
59759 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
59760 +#else
59761 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
59762 +{
59763 + return __pgprot(0);
59764 +}
59765 +#endif
59766 +
59767 int vma_wants_writenotify(struct vm_area_struct *vma);
59768
59769 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
59770 @@ -1419,6 +1407,7 @@ out:
59771 }
59772
59773 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
59774 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
59775
59776 extern unsigned long do_brk(unsigned long, unsigned long);
59777
59778 @@ -1476,6 +1465,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
59779 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
59780 struct vm_area_struct **pprev);
59781
59782 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
59783 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
59784 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
59785 +
59786 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
59787 NULL if none. Assume start_addr < end_addr. */
59788 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
59789 @@ -1492,15 +1485,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
59790 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
59791 }
59792
59793 -#ifdef CONFIG_MMU
59794 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
59795 -#else
59796 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
59797 -{
59798 - return __pgprot(0);
59799 -}
59800 -#endif
59801 -
59802 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
59803 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
59804 unsigned long pfn, unsigned long size, pgprot_t);
59805 @@ -1614,7 +1598,7 @@ extern int unpoison_memory(unsigned long pfn);
59806 extern int sysctl_memory_failure_early_kill;
59807 extern int sysctl_memory_failure_recovery;
59808 extern void shake_page(struct page *p, int access);
59809 -extern atomic_long_t mce_bad_pages;
59810 +extern atomic_long_unchecked_t mce_bad_pages;
59811 extern int soft_offline_page(struct page *page, int flags);
59812
59813 extern void dump_page(struct page *page);
59814 @@ -1628,5 +1612,11 @@ extern void copy_user_huge_page(struct page *dst, struct page *src,
59815 unsigned int pages_per_huge_page);
59816 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
59817
59818 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59819 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
59820 +#else
59821 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
59822 +#endif
59823 +
59824 #endif /* __KERNEL__ */
59825 #endif /* _LINUX_MM_H */
59826 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
59827 index 5b42f1b..759e4b4 100644
59828 --- a/include/linux/mm_types.h
59829 +++ b/include/linux/mm_types.h
59830 @@ -253,6 +253,8 @@ struct vm_area_struct {
59831 #ifdef CONFIG_NUMA
59832 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
59833 #endif
59834 +
59835 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
59836 };
59837
59838 struct core_thread {
59839 @@ -389,6 +391,24 @@ struct mm_struct {
59840 #ifdef CONFIG_CPUMASK_OFFSTACK
59841 struct cpumask cpumask_allocation;
59842 #endif
59843 +
59844 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59845 + unsigned long pax_flags;
59846 +#endif
59847 +
59848 +#ifdef CONFIG_PAX_DLRESOLVE
59849 + unsigned long call_dl_resolve;
59850 +#endif
59851 +
59852 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59853 + unsigned long call_syscall;
59854 +#endif
59855 +
59856 +#ifdef CONFIG_PAX_ASLR
59857 + unsigned long delta_mmap; /* randomized offset */
59858 + unsigned long delta_stack; /* randomized offset */
59859 +#endif
59860 +
59861 };
59862
59863 static inline void mm_init_cpumask(struct mm_struct *mm)
59864 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
59865 index 1d1b1e1..2a13c78 100644
59866 --- a/include/linux/mmu_notifier.h
59867 +++ b/include/linux/mmu_notifier.h
59868 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
59869 */
59870 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
59871 ({ \
59872 - pte_t __pte; \
59873 + pte_t ___pte; \
59874 struct vm_area_struct *___vma = __vma; \
59875 unsigned long ___address = __address; \
59876 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
59877 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
59878 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
59879 - __pte; \
59880 + ___pte; \
59881 })
59882
59883 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
59884 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
59885 index 188cb2f..d78409b 100644
59886 --- a/include/linux/mmzone.h
59887 +++ b/include/linux/mmzone.h
59888 @@ -369,7 +369,7 @@ struct zone {
59889 unsigned long flags; /* zone flags, see below */
59890
59891 /* Zone statistics */
59892 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
59893 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
59894
59895 /*
59896 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
59897 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
59898 index 468819c..17b9db3 100644
59899 --- a/include/linux/mod_devicetable.h
59900 +++ b/include/linux/mod_devicetable.h
59901 @@ -12,7 +12,7 @@
59902 typedef unsigned long kernel_ulong_t;
59903 #endif
59904
59905 -#define PCI_ANY_ID (~0)
59906 +#define PCI_ANY_ID ((__u16)~0)
59907
59908 struct pci_device_id {
59909 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
59910 @@ -131,7 +131,7 @@ struct usb_device_id {
59911 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
59912 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
59913
59914 -#define HID_ANY_ID (~0)
59915 +#define HID_ANY_ID (~0U)
59916
59917 struct hid_device_id {
59918 __u16 bus;
59919 diff --git a/include/linux/module.h b/include/linux/module.h
59920 index 3cb7839..511cb87 100644
59921 --- a/include/linux/module.h
59922 +++ b/include/linux/module.h
59923 @@ -17,6 +17,7 @@
59924 #include <linux/moduleparam.h>
59925 #include <linux/tracepoint.h>
59926 #include <linux/export.h>
59927 +#include <linux/fs.h>
59928
59929 #include <linux/percpu.h>
59930 #include <asm/module.h>
59931 @@ -261,19 +262,16 @@ struct module
59932 int (*init)(void);
59933
59934 /* If this is non-NULL, vfree after init() returns */
59935 - void *module_init;
59936 + void *module_init_rx, *module_init_rw;
59937
59938 /* Here is the actual code + data, vfree'd on unload. */
59939 - void *module_core;
59940 + void *module_core_rx, *module_core_rw;
59941
59942 /* Here are the sizes of the init and core sections */
59943 - unsigned int init_size, core_size;
59944 + unsigned int init_size_rw, core_size_rw;
59945
59946 /* The size of the executable code in each section. */
59947 - unsigned int init_text_size, core_text_size;
59948 -
59949 - /* Size of RO sections of the module (text+rodata) */
59950 - unsigned int init_ro_size, core_ro_size;
59951 + unsigned int init_size_rx, core_size_rx;
59952
59953 /* Arch-specific module values */
59954 struct mod_arch_specific arch;
59955 @@ -329,6 +327,10 @@ struct module
59956 #ifdef CONFIG_EVENT_TRACING
59957 struct ftrace_event_call **trace_events;
59958 unsigned int num_trace_events;
59959 + struct file_operations trace_id;
59960 + struct file_operations trace_enable;
59961 + struct file_operations trace_format;
59962 + struct file_operations trace_filter;
59963 #endif
59964 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
59965 unsigned int num_ftrace_callsites;
59966 @@ -379,16 +381,46 @@ bool is_module_address(unsigned long addr);
59967 bool is_module_percpu_address(unsigned long addr);
59968 bool is_module_text_address(unsigned long addr);
59969
59970 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
59971 +{
59972 +
59973 +#ifdef CONFIG_PAX_KERNEXEC
59974 + if (ktla_ktva(addr) >= (unsigned long)start &&
59975 + ktla_ktva(addr) < (unsigned long)start + size)
59976 + return 1;
59977 +#endif
59978 +
59979 + return ((void *)addr >= start && (void *)addr < start + size);
59980 +}
59981 +
59982 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
59983 +{
59984 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
59985 +}
59986 +
59987 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
59988 +{
59989 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
59990 +}
59991 +
59992 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
59993 +{
59994 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
59995 +}
59996 +
59997 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
59998 +{
59999 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
60000 +}
60001 +
60002 static inline int within_module_core(unsigned long addr, struct module *mod)
60003 {
60004 - return (unsigned long)mod->module_core <= addr &&
60005 - addr < (unsigned long)mod->module_core + mod->core_size;
60006 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
60007 }
60008
60009 static inline int within_module_init(unsigned long addr, struct module *mod)
60010 {
60011 - return (unsigned long)mod->module_init <= addr &&
60012 - addr < (unsigned long)mod->module_init + mod->init_size;
60013 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
60014 }
60015
60016 /* Search for module by name: must hold module_mutex. */
60017 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
60018 index b2be02e..6a9fdb1 100644
60019 --- a/include/linux/moduleloader.h
60020 +++ b/include/linux/moduleloader.h
60021 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
60022 sections. Returns NULL on failure. */
60023 void *module_alloc(unsigned long size);
60024
60025 +#ifdef CONFIG_PAX_KERNEXEC
60026 +void *module_alloc_exec(unsigned long size);
60027 +#else
60028 +#define module_alloc_exec(x) module_alloc(x)
60029 +#endif
60030 +
60031 /* Free memory returned from module_alloc. */
60032 void module_free(struct module *mod, void *module_region);
60033
60034 +#ifdef CONFIG_PAX_KERNEXEC
60035 +void module_free_exec(struct module *mod, void *module_region);
60036 +#else
60037 +#define module_free_exec(x, y) module_free((x), (y))
60038 +#endif
60039 +
60040 /* Apply the given relocation to the (simplified) ELF. Return -error
60041 or 0. */
60042 int apply_relocate(Elf_Shdr *sechdrs,
60043 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
60044 index 7939f63..ec6df57 100644
60045 --- a/include/linux/moduleparam.h
60046 +++ b/include/linux/moduleparam.h
60047 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
60048 * @len is usually just sizeof(string).
60049 */
60050 #define module_param_string(name, string, len, perm) \
60051 - static const struct kparam_string __param_string_##name \
60052 + static const struct kparam_string __param_string_##name __used \
60053 = { len, string }; \
60054 __module_param_call(MODULE_PARAM_PREFIX, name, \
60055 &param_ops_string, \
60056 @@ -395,7 +395,7 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
60057 * module_param_named() for why this might be necessary.
60058 */
60059 #define module_param_array_named(name, array, type, nump, perm) \
60060 - static const struct kparam_array __param_arr_##name \
60061 + static const struct kparam_array __param_arr_##name __used \
60062 = { .max = ARRAY_SIZE(array), .num = nump, \
60063 .ops = &param_ops_##type, \
60064 .elemsize = sizeof(array[0]), .elem = array }; \
60065 diff --git a/include/linux/namei.h b/include/linux/namei.h
60066 index ffc0213..2c1f2cb 100644
60067 --- a/include/linux/namei.h
60068 +++ b/include/linux/namei.h
60069 @@ -24,7 +24,7 @@ struct nameidata {
60070 unsigned seq;
60071 int last_type;
60072 unsigned depth;
60073 - char *saved_names[MAX_NESTED_LINKS + 1];
60074 + const char *saved_names[MAX_NESTED_LINKS + 1];
60075
60076 /* Intent data */
60077 union {
60078 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
60079 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
60080 extern void unlock_rename(struct dentry *, struct dentry *);
60081
60082 -static inline void nd_set_link(struct nameidata *nd, char *path)
60083 +static inline void nd_set_link(struct nameidata *nd, const char *path)
60084 {
60085 nd->saved_names[nd->depth] = path;
60086 }
60087
60088 -static inline char *nd_get_link(struct nameidata *nd)
60089 +static inline const char *nd_get_link(const struct nameidata *nd)
60090 {
60091 return nd->saved_names[nd->depth];
60092 }
60093 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
60094 index a82ad4d..90d15b7 100644
60095 --- a/include/linux/netdevice.h
60096 +++ b/include/linux/netdevice.h
60097 @@ -949,6 +949,7 @@ struct net_device_ops {
60098 int (*ndo_set_features)(struct net_device *dev,
60099 u32 features);
60100 };
60101 +typedef struct net_device_ops __no_const net_device_ops_no_const;
60102
60103 /*
60104 * The DEVICE structure.
60105 @@ -1088,7 +1089,7 @@ struct net_device {
60106 int iflink;
60107
60108 struct net_device_stats stats;
60109 - atomic_long_t rx_dropped; /* dropped packets by core network
60110 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
60111 * Do not use this in drivers.
60112 */
60113
60114 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
60115 new file mode 100644
60116 index 0000000..33f4af8
60117 --- /dev/null
60118 +++ b/include/linux/netfilter/xt_gradm.h
60119 @@ -0,0 +1,9 @@
60120 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
60121 +#define _LINUX_NETFILTER_XT_GRADM_H 1
60122 +
60123 +struct xt_gradm_mtinfo {
60124 + __u16 flags;
60125 + __u16 invflags;
60126 +};
60127 +
60128 +#endif
60129 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
60130 index c65a18a..0c05f3a 100644
60131 --- a/include/linux/of_pdt.h
60132 +++ b/include/linux/of_pdt.h
60133 @@ -32,7 +32,7 @@ struct of_pdt_ops {
60134
60135 /* return 0 on success; fill in 'len' with number of bytes in path */
60136 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
60137 -};
60138 +} __no_const;
60139
60140 extern void *prom_early_alloc(unsigned long size);
60141
60142 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
60143 index a4c5624..79d6d88 100644
60144 --- a/include/linux/oprofile.h
60145 +++ b/include/linux/oprofile.h
60146 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
60147 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
60148 char const * name, ulong * val);
60149
60150 -/** Create a file for read-only access to an atomic_t. */
60151 +/** Create a file for read-only access to an atomic_unchecked_t. */
60152 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
60153 - char const * name, atomic_t * val);
60154 + char const * name, atomic_unchecked_t * val);
60155
60156 /** create a directory */
60157 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
60158 diff --git a/include/linux/padata.h b/include/linux/padata.h
60159 index 4633b2f..988bc08 100644
60160 --- a/include/linux/padata.h
60161 +++ b/include/linux/padata.h
60162 @@ -129,7 +129,7 @@ struct parallel_data {
60163 struct padata_instance *pinst;
60164 struct padata_parallel_queue __percpu *pqueue;
60165 struct padata_serial_queue __percpu *squeue;
60166 - atomic_t seq_nr;
60167 + atomic_unchecked_t seq_nr;
60168 atomic_t reorder_objects;
60169 atomic_t refcnt;
60170 unsigned int max_seq_nr;
60171 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
60172 index b1f8912..c955bff 100644
60173 --- a/include/linux/perf_event.h
60174 +++ b/include/linux/perf_event.h
60175 @@ -748,8 +748,8 @@ struct perf_event {
60176
60177 enum perf_event_active_state state;
60178 unsigned int attach_state;
60179 - local64_t count;
60180 - atomic64_t child_count;
60181 + local64_t count; /* PaX: fix it one day */
60182 + atomic64_unchecked_t child_count;
60183
60184 /*
60185 * These are the total time in nanoseconds that the event
60186 @@ -800,8 +800,8 @@ struct perf_event {
60187 * These accumulate total time (in nanoseconds) that children
60188 * events have been enabled and running, respectively.
60189 */
60190 - atomic64_t child_total_time_enabled;
60191 - atomic64_t child_total_time_running;
60192 + atomic64_unchecked_t child_total_time_enabled;
60193 + atomic64_unchecked_t child_total_time_running;
60194
60195 /*
60196 * Protect attach/detach and child_list:
60197 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
60198 index 77257c9..51d473a 100644
60199 --- a/include/linux/pipe_fs_i.h
60200 +++ b/include/linux/pipe_fs_i.h
60201 @@ -46,9 +46,9 @@ struct pipe_buffer {
60202 struct pipe_inode_info {
60203 wait_queue_head_t wait;
60204 unsigned int nrbufs, curbuf, buffers;
60205 - unsigned int readers;
60206 - unsigned int writers;
60207 - unsigned int waiting_writers;
60208 + atomic_t readers;
60209 + atomic_t writers;
60210 + atomic_t waiting_writers;
60211 unsigned int r_counter;
60212 unsigned int w_counter;
60213 struct page *tmp_page;
60214 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
60215 index d3085e7..fd01052 100644
60216 --- a/include/linux/pm_runtime.h
60217 +++ b/include/linux/pm_runtime.h
60218 @@ -95,7 +95,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
60219
60220 static inline void pm_runtime_mark_last_busy(struct device *dev)
60221 {
60222 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
60223 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
60224 }
60225
60226 #else /* !CONFIG_PM_RUNTIME */
60227 diff --git a/include/linux/poison.h b/include/linux/poison.h
60228 index 79159de..f1233a9 100644
60229 --- a/include/linux/poison.h
60230 +++ b/include/linux/poison.h
60231 @@ -19,8 +19,8 @@
60232 * under normal circumstances, used to verify that nobody uses
60233 * non-initialized list entries.
60234 */
60235 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
60236 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
60237 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
60238 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
60239
60240 /********** include/linux/timer.h **********/
60241 /*
60242 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
60243 index 58969b2..ead129b 100644
60244 --- a/include/linux/preempt.h
60245 +++ b/include/linux/preempt.h
60246 @@ -123,7 +123,7 @@ struct preempt_ops {
60247 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
60248 void (*sched_out)(struct preempt_notifier *notifier,
60249 struct task_struct *next);
60250 -};
60251 +} __no_const;
60252
60253 /**
60254 * preempt_notifier - key for installing preemption notifiers
60255 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
60256 index 643b96c..ef55a9c 100644
60257 --- a/include/linux/proc_fs.h
60258 +++ b/include/linux/proc_fs.h
60259 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
60260 return proc_create_data(name, mode, parent, proc_fops, NULL);
60261 }
60262
60263 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
60264 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
60265 +{
60266 +#ifdef CONFIG_GRKERNSEC_PROC_USER
60267 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
60268 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60269 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
60270 +#else
60271 + return proc_create_data(name, mode, parent, proc_fops, NULL);
60272 +#endif
60273 +}
60274 +
60275 +
60276 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
60277 mode_t mode, struct proc_dir_entry *base,
60278 read_proc_t *read_proc, void * data)
60279 @@ -258,7 +271,7 @@ union proc_op {
60280 int (*proc_show)(struct seq_file *m,
60281 struct pid_namespace *ns, struct pid *pid,
60282 struct task_struct *task);
60283 -};
60284 +} __no_const;
60285
60286 struct ctl_table_header;
60287 struct ctl_table;
60288 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
60289 index 800f113..e9ee2e3 100644
60290 --- a/include/linux/ptrace.h
60291 +++ b/include/linux/ptrace.h
60292 @@ -129,10 +129,12 @@ extern void __ptrace_unlink(struct task_struct *child);
60293 extern void exit_ptrace(struct task_struct *tracer);
60294 #define PTRACE_MODE_READ 1
60295 #define PTRACE_MODE_ATTACH 2
60296 -/* Returns 0 on success, -errno on denial. */
60297 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
60298 /* Returns true on success, false on denial. */
60299 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
60300 +/* Returns true on success, false on denial. */
60301 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
60302 +/* Returns true on success, false on denial. */
60303 +extern bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode);
60304
60305 static inline int ptrace_reparented(struct task_struct *child)
60306 {
60307 diff --git a/include/linux/random.h b/include/linux/random.h
60308 index 8f74538..02a1012 100644
60309 --- a/include/linux/random.h
60310 +++ b/include/linux/random.h
60311 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
60312
60313 u32 prandom32(struct rnd_state *);
60314
60315 +static inline unsigned long pax_get_random_long(void)
60316 +{
60317 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
60318 +}
60319 +
60320 /*
60321 * Handle minimum values for seeds
60322 */
60323 static inline u32 __seed(u32 x, u32 m)
60324 {
60325 - return (x < m) ? x + m : x;
60326 + return (x <= m) ? x + m + 1 : x;
60327 }
60328
60329 /**
60330 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
60331 index e0879a7..a12f962 100644
60332 --- a/include/linux/reboot.h
60333 +++ b/include/linux/reboot.h
60334 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
60335 * Architecture-specific implementations of sys_reboot commands.
60336 */
60337
60338 -extern void machine_restart(char *cmd);
60339 -extern void machine_halt(void);
60340 -extern void machine_power_off(void);
60341 +extern void machine_restart(char *cmd) __noreturn;
60342 +extern void machine_halt(void) __noreturn;
60343 +extern void machine_power_off(void) __noreturn;
60344
60345 extern void machine_shutdown(void);
60346 struct pt_regs;
60347 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
60348 */
60349
60350 extern void kernel_restart_prepare(char *cmd);
60351 -extern void kernel_restart(char *cmd);
60352 -extern void kernel_halt(void);
60353 -extern void kernel_power_off(void);
60354 +extern void kernel_restart(char *cmd) __noreturn;
60355 +extern void kernel_halt(void) __noreturn;
60356 +extern void kernel_power_off(void) __noreturn;
60357
60358 extern int C_A_D; /* for sysctl */
60359 void ctrl_alt_del(void);
60360 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
60361 * Emergency restart, callable from an interrupt handler.
60362 */
60363
60364 -extern void emergency_restart(void);
60365 +extern void emergency_restart(void) __noreturn;
60366 #include <asm/emergency-restart.h>
60367
60368 #endif
60369 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
60370 index 96d465f..b084e05 100644
60371 --- a/include/linux/reiserfs_fs.h
60372 +++ b/include/linux/reiserfs_fs.h
60373 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60374 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60375
60376 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60377 -#define get_generation(s) atomic_read (&fs_generation(s))
60378 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60379 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60380 #define __fs_changed(gen,s) (gen != get_generation (s))
60381 #define fs_changed(gen,s) \
60382 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
60383 index 52c83b6..18ed7eb 100644
60384 --- a/include/linux/reiserfs_fs_sb.h
60385 +++ b/include/linux/reiserfs_fs_sb.h
60386 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
60387 /* Comment? -Hans */
60388 wait_queue_head_t s_wait;
60389 /* To be obsoleted soon by per buffer seals.. -Hans */
60390 - atomic_t s_generation_counter; // increased by one every time the
60391 + atomic_unchecked_t s_generation_counter; // increased by one every time the
60392 // tree gets re-balanced
60393 unsigned long s_properties; /* File system properties. Currently holds
60394 on-disk FS format */
60395 diff --git a/include/linux/relay.h b/include/linux/relay.h
60396 index 14a86bc..17d0700 100644
60397 --- a/include/linux/relay.h
60398 +++ b/include/linux/relay.h
60399 @@ -159,7 +159,7 @@ struct rchan_callbacks
60400 * The callback should return 0 if successful, negative if not.
60401 */
60402 int (*remove_buf_file)(struct dentry *dentry);
60403 -};
60404 +} __no_const;
60405
60406 /*
60407 * CONFIG_RELAY kernel API, kernel/relay.c
60408 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
60409 index c6c6084..5bf1212 100644
60410 --- a/include/linux/rfkill.h
60411 +++ b/include/linux/rfkill.h
60412 @@ -147,6 +147,7 @@ struct rfkill_ops {
60413 void (*query)(struct rfkill *rfkill, void *data);
60414 int (*set_block)(void *data, bool blocked);
60415 };
60416 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
60417
60418 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
60419 /**
60420 diff --git a/include/linux/rio.h b/include/linux/rio.h
60421 index 4d50611..c6858a2 100644
60422 --- a/include/linux/rio.h
60423 +++ b/include/linux/rio.h
60424 @@ -315,7 +315,7 @@ struct rio_ops {
60425 int mbox, void *buffer, size_t len);
60426 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
60427 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
60428 -};
60429 +} __no_const;
60430
60431 #define RIO_RESOURCE_MEM 0x00000100
60432 #define RIO_RESOURCE_DOORBELL 0x00000200
60433 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
60434 index 2148b12..519b820 100644
60435 --- a/include/linux/rmap.h
60436 +++ b/include/linux/rmap.h
60437 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
60438 void anon_vma_init(void); /* create anon_vma_cachep */
60439 int anon_vma_prepare(struct vm_area_struct *);
60440 void unlink_anon_vmas(struct vm_area_struct *);
60441 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
60442 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
60443 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
60444 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
60445 void __anon_vma_link(struct vm_area_struct *);
60446
60447 static inline void anon_vma_merge(struct vm_area_struct *vma,
60448 diff --git a/include/linux/sched.h b/include/linux/sched.h
60449 index 1c4f3e9..dafcd27 100644
60450 --- a/include/linux/sched.h
60451 +++ b/include/linux/sched.h
60452 @@ -101,6 +101,7 @@ struct bio_list;
60453 struct fs_struct;
60454 struct perf_event_context;
60455 struct blk_plug;
60456 +struct linux_binprm;
60457
60458 /*
60459 * List of flags we want to share for kernel threads,
60460 @@ -380,10 +381,13 @@ struct user_namespace;
60461 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
60462
60463 extern int sysctl_max_map_count;
60464 +extern unsigned long sysctl_heap_stack_gap;
60465
60466 #include <linux/aio.h>
60467
60468 #ifdef CONFIG_MMU
60469 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
60470 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
60471 extern void arch_pick_mmap_layout(struct mm_struct *mm);
60472 extern unsigned long
60473 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
60474 @@ -629,6 +633,17 @@ struct signal_struct {
60475 #ifdef CONFIG_TASKSTATS
60476 struct taskstats *stats;
60477 #endif
60478 +
60479 +#ifdef CONFIG_GRKERNSEC
60480 + u32 curr_ip;
60481 + u32 saved_ip;
60482 + u32 gr_saddr;
60483 + u32 gr_daddr;
60484 + u16 gr_sport;
60485 + u16 gr_dport;
60486 + u8 used_accept:1;
60487 +#endif
60488 +
60489 #ifdef CONFIG_AUDIT
60490 unsigned audit_tty;
60491 struct tty_audit_buf *tty_audit_buf;
60492 @@ -710,6 +725,11 @@ struct user_struct {
60493 struct key *session_keyring; /* UID's default session keyring */
60494 #endif
60495
60496 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60497 + unsigned int banned;
60498 + unsigned long ban_expires;
60499 +#endif
60500 +
60501 /* Hash table maintenance information */
60502 struct hlist_node uidhash_node;
60503 uid_t uid;
60504 @@ -1337,8 +1357,8 @@ struct task_struct {
60505 struct list_head thread_group;
60506
60507 struct completion *vfork_done; /* for vfork() */
60508 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
60509 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60510 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
60511 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60512
60513 cputime_t utime, stime, utimescaled, stimescaled;
60514 cputime_t gtime;
60515 @@ -1354,13 +1374,6 @@ struct task_struct {
60516 struct task_cputime cputime_expires;
60517 struct list_head cpu_timers[3];
60518
60519 -/* process credentials */
60520 - const struct cred __rcu *real_cred; /* objective and real subjective task
60521 - * credentials (COW) */
60522 - const struct cred __rcu *cred; /* effective (overridable) subjective task
60523 - * credentials (COW) */
60524 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60525 -
60526 char comm[TASK_COMM_LEN]; /* executable name excluding path
60527 - access with [gs]et_task_comm (which lock
60528 it with task_lock())
60529 @@ -1377,8 +1390,16 @@ struct task_struct {
60530 #endif
60531 /* CPU-specific state of this task */
60532 struct thread_struct thread;
60533 +/* thread_info moved to task_struct */
60534 +#ifdef CONFIG_X86
60535 + struct thread_info tinfo;
60536 +#endif
60537 /* filesystem information */
60538 struct fs_struct *fs;
60539 +
60540 + const struct cred __rcu *cred; /* effective (overridable) subjective task
60541 + * credentials (COW) */
60542 +
60543 /* open file information */
60544 struct files_struct *files;
60545 /* namespaces */
60546 @@ -1425,6 +1446,11 @@ struct task_struct {
60547 struct rt_mutex_waiter *pi_blocked_on;
60548 #endif
60549
60550 +/* process credentials */
60551 + const struct cred __rcu *real_cred; /* objective and real subjective task
60552 + * credentials (COW) */
60553 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60554 +
60555 #ifdef CONFIG_DEBUG_MUTEXES
60556 /* mutex deadlock detection */
60557 struct mutex_waiter *blocked_on;
60558 @@ -1540,6 +1566,27 @@ struct task_struct {
60559 unsigned long default_timer_slack_ns;
60560
60561 struct list_head *scm_work_list;
60562 +
60563 +#ifdef CONFIG_GRKERNSEC
60564 + /* grsecurity */
60565 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60566 + long long exec_id;
60567 +#endif
60568 +#ifdef CONFIG_GRKERNSEC_SETXID
60569 + const struct cred *delayed_cred;
60570 +#endif
60571 + struct dentry *gr_chroot_dentry;
60572 + struct acl_subject_label *acl;
60573 + struct acl_role_label *role;
60574 + struct file *exec_file;
60575 + u16 acl_role_id;
60576 + /* is this the task that authenticated to the special role */
60577 + u8 acl_sp_role;
60578 + u8 is_writable;
60579 + u8 brute;
60580 + u8 gr_is_chrooted;
60581 +#endif
60582 +
60583 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
60584 /* Index of current stored address in ret_stack */
60585 int curr_ret_stack;
60586 @@ -1574,6 +1621,51 @@ struct task_struct {
60587 #endif
60588 };
60589
60590 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
60591 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
60592 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
60593 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
60594 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
60595 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
60596 +
60597 +#ifdef CONFIG_PAX_SOFTMODE
60598 +extern int pax_softmode;
60599 +#endif
60600 +
60601 +extern int pax_check_flags(unsigned long *);
60602 +
60603 +/* if tsk != current then task_lock must be held on it */
60604 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60605 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
60606 +{
60607 + if (likely(tsk->mm))
60608 + return tsk->mm->pax_flags;
60609 + else
60610 + return 0UL;
60611 +}
60612 +
60613 +/* if tsk != current then task_lock must be held on it */
60614 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
60615 +{
60616 + if (likely(tsk->mm)) {
60617 + tsk->mm->pax_flags = flags;
60618 + return 0;
60619 + }
60620 + return -EINVAL;
60621 +}
60622 +#endif
60623 +
60624 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60625 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
60626 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60627 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60628 +#endif
60629 +
60630 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
60631 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
60632 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
60633 +extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
60634 +
60635 /* Future-safe accessor for struct task_struct's cpus_allowed. */
60636 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
60637
60638 @@ -2081,7 +2173,9 @@ void yield(void);
60639 extern struct exec_domain default_exec_domain;
60640
60641 union thread_union {
60642 +#ifndef CONFIG_X86
60643 struct thread_info thread_info;
60644 +#endif
60645 unsigned long stack[THREAD_SIZE/sizeof(long)];
60646 };
60647
60648 @@ -2114,6 +2208,7 @@ extern struct pid_namespace init_pid_ns;
60649 */
60650
60651 extern struct task_struct *find_task_by_vpid(pid_t nr);
60652 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
60653 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
60654 struct pid_namespace *ns);
60655
60656 @@ -2235,6 +2330,12 @@ static inline void mmdrop(struct mm_struct * mm)
60657 extern void mmput(struct mm_struct *);
60658 /* Grab a reference to a task's mm, if it is not already going away */
60659 extern struct mm_struct *get_task_mm(struct task_struct *task);
60660 +/*
60661 + * Grab a reference to a task's mm, if it is not already going away
60662 + * and ptrace_may_access with the mode parameter passed to it
60663 + * succeeds.
60664 + */
60665 +extern struct mm_struct *mm_access(struct task_struct *task, unsigned int mode);
60666 /* Remove the current tasks stale references to the old mm_struct */
60667 extern void mm_release(struct task_struct *, struct mm_struct *);
60668 /* Allocate a new mm structure and copy contents from tsk->mm */
60669 @@ -2251,7 +2352,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
60670 extern void exit_itimers(struct signal_struct *);
60671 extern void flush_itimer_signals(void);
60672
60673 -extern NORET_TYPE void do_group_exit(int);
60674 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
60675
60676 extern void daemonize(const char *, ...);
60677 extern int allow_signal(int);
60678 @@ -2416,13 +2517,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
60679
60680 #endif
60681
60682 -static inline int object_is_on_stack(void *obj)
60683 +static inline int object_starts_on_stack(void *obj)
60684 {
60685 - void *stack = task_stack_page(current);
60686 + const void *stack = task_stack_page(current);
60687
60688 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
60689 }
60690
60691 +#ifdef CONFIG_PAX_USERCOPY
60692 +extern int object_is_on_stack(const void *obj, unsigned long len);
60693 +#endif
60694 +
60695 extern void thread_info_cache_init(void);
60696
60697 #ifdef CONFIG_DEBUG_STACK_USAGE
60698 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
60699 index 899fbb4..1cb4138 100644
60700 --- a/include/linux/screen_info.h
60701 +++ b/include/linux/screen_info.h
60702 @@ -43,7 +43,8 @@ struct screen_info {
60703 __u16 pages; /* 0x32 */
60704 __u16 vesa_attributes; /* 0x34 */
60705 __u32 capabilities; /* 0x36 */
60706 - __u8 _reserved[6]; /* 0x3a */
60707 + __u16 vesapm_size; /* 0x3a */
60708 + __u8 _reserved[4]; /* 0x3c */
60709 } __attribute__((packed));
60710
60711 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
60712 diff --git a/include/linux/security.h b/include/linux/security.h
60713 index e8c619d..e0cbd1c 100644
60714 --- a/include/linux/security.h
60715 +++ b/include/linux/security.h
60716 @@ -37,6 +37,7 @@
60717 #include <linux/xfrm.h>
60718 #include <linux/slab.h>
60719 #include <linux/xattr.h>
60720 +#include <linux/grsecurity.h>
60721 #include <net/flow.h>
60722
60723 /* Maximum number of letters for an LSM name string */
60724 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
60725 index 0b69a46..4796016 100644
60726 --- a/include/linux/seq_file.h
60727 +++ b/include/linux/seq_file.h
60728 @@ -24,6 +24,9 @@ struct seq_file {
60729 struct mutex lock;
60730 const struct seq_operations *op;
60731 int poll_event;
60732 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60733 + long long exec_id;
60734 +#endif
60735 void *private;
60736 };
60737
60738 @@ -33,6 +36,7 @@ struct seq_operations {
60739 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
60740 int (*show) (struct seq_file *m, void *v);
60741 };
60742 +typedef struct seq_operations __no_const seq_operations_no_const;
60743
60744 #define SEQ_SKIP 1
60745
60746 diff --git a/include/linux/shm.h b/include/linux/shm.h
60747 index 92808b8..c28cac4 100644
60748 --- a/include/linux/shm.h
60749 +++ b/include/linux/shm.h
60750 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
60751
60752 /* The task created the shm object. NULL if the task is dead. */
60753 struct task_struct *shm_creator;
60754 +#ifdef CONFIG_GRKERNSEC
60755 + time_t shm_createtime;
60756 + pid_t shm_lapid;
60757 +#endif
60758 };
60759
60760 /* shm_mode upper byte flags */
60761 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
60762 index fe86488..1563c1c 100644
60763 --- a/include/linux/skbuff.h
60764 +++ b/include/linux/skbuff.h
60765 @@ -642,7 +642,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
60766 */
60767 static inline int skb_queue_empty(const struct sk_buff_head *list)
60768 {
60769 - return list->next == (struct sk_buff *)list;
60770 + return list->next == (const struct sk_buff *)list;
60771 }
60772
60773 /**
60774 @@ -655,7 +655,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
60775 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
60776 const struct sk_buff *skb)
60777 {
60778 - return skb->next == (struct sk_buff *)list;
60779 + return skb->next == (const struct sk_buff *)list;
60780 }
60781
60782 /**
60783 @@ -668,7 +668,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
60784 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
60785 const struct sk_buff *skb)
60786 {
60787 - return skb->prev == (struct sk_buff *)list;
60788 + return skb->prev == (const struct sk_buff *)list;
60789 }
60790
60791 /**
60792 @@ -1523,7 +1523,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
60793 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
60794 */
60795 #ifndef NET_SKB_PAD
60796 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
60797 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
60798 #endif
60799
60800 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
60801 diff --git a/include/linux/slab.h b/include/linux/slab.h
60802 index 573c809..e84c132 100644
60803 --- a/include/linux/slab.h
60804 +++ b/include/linux/slab.h
60805 @@ -11,12 +11,20 @@
60806
60807 #include <linux/gfp.h>
60808 #include <linux/types.h>
60809 +#include <linux/err.h>
60810
60811 /*
60812 * Flags to pass to kmem_cache_create().
60813 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
60814 */
60815 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
60816 +
60817 +#ifdef CONFIG_PAX_USERCOPY
60818 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
60819 +#else
60820 +#define SLAB_USERCOPY 0x00000000UL
60821 +#endif
60822 +
60823 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
60824 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
60825 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
60826 @@ -87,10 +95,13 @@
60827 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
60828 * Both make kfree a no-op.
60829 */
60830 -#define ZERO_SIZE_PTR ((void *)16)
60831 +#define ZERO_SIZE_PTR \
60832 +({ \
60833 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
60834 + (void *)(-MAX_ERRNO-1L); \
60835 +})
60836
60837 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
60838 - (unsigned long)ZERO_SIZE_PTR)
60839 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
60840
60841 /*
60842 * struct kmem_cache related prototypes
60843 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
60844 void kfree(const void *);
60845 void kzfree(const void *);
60846 size_t ksize(const void *);
60847 +void check_object_size(const void *ptr, unsigned long n, bool to);
60848
60849 /*
60850 * Allocator specific definitions. These are mainly used to establish optimized
60851 @@ -353,4 +365,59 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
60852
60853 void __init kmem_cache_init_late(void);
60854
60855 +#define kmalloc(x, y) \
60856 +({ \
60857 + void *___retval; \
60858 + intoverflow_t ___x = (intoverflow_t)x; \
60859 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
60860 + ___retval = NULL; \
60861 + else \
60862 + ___retval = kmalloc((size_t)___x, (y)); \
60863 + ___retval; \
60864 +})
60865 +
60866 +#define kmalloc_node(x, y, z) \
60867 +({ \
60868 + void *___retval; \
60869 + intoverflow_t ___x = (intoverflow_t)x; \
60870 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
60871 + ___retval = NULL; \
60872 + else \
60873 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
60874 + ___retval; \
60875 +})
60876 +
60877 +#define kzalloc(x, y) \
60878 +({ \
60879 + void *___retval; \
60880 + intoverflow_t ___x = (intoverflow_t)x; \
60881 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
60882 + ___retval = NULL; \
60883 + else \
60884 + ___retval = kzalloc((size_t)___x, (y)); \
60885 + ___retval; \
60886 +})
60887 +
60888 +#define __krealloc(x, y, z) \
60889 +({ \
60890 + void *___retval; \
60891 + intoverflow_t ___y = (intoverflow_t)y; \
60892 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
60893 + ___retval = NULL; \
60894 + else \
60895 + ___retval = __krealloc((x), (size_t)___y, (z)); \
60896 + ___retval; \
60897 +})
60898 +
60899 +#define krealloc(x, y, z) \
60900 +({ \
60901 + void *___retval; \
60902 + intoverflow_t ___y = (intoverflow_t)y; \
60903 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
60904 + ___retval = NULL; \
60905 + else \
60906 + ___retval = krealloc((x), (size_t)___y, (z)); \
60907 + ___retval; \
60908 +})
60909 +
60910 #endif /* _LINUX_SLAB_H */
60911 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
60912 index d00e0ba..1b3bf7b 100644
60913 --- a/include/linux/slab_def.h
60914 +++ b/include/linux/slab_def.h
60915 @@ -68,10 +68,10 @@ struct kmem_cache {
60916 unsigned long node_allocs;
60917 unsigned long node_frees;
60918 unsigned long node_overflow;
60919 - atomic_t allochit;
60920 - atomic_t allocmiss;
60921 - atomic_t freehit;
60922 - atomic_t freemiss;
60923 + atomic_unchecked_t allochit;
60924 + atomic_unchecked_t allocmiss;
60925 + atomic_unchecked_t freehit;
60926 + atomic_unchecked_t freemiss;
60927
60928 /*
60929 * If debugging is enabled, then the allocator can add additional
60930 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
60931 index a32bcfd..53b71f4 100644
60932 --- a/include/linux/slub_def.h
60933 +++ b/include/linux/slub_def.h
60934 @@ -89,7 +89,7 @@ struct kmem_cache {
60935 struct kmem_cache_order_objects max;
60936 struct kmem_cache_order_objects min;
60937 gfp_t allocflags; /* gfp flags to use on each alloc */
60938 - int refcount; /* Refcount for slab cache destroy */
60939 + atomic_t refcount; /* Refcount for slab cache destroy */
60940 void (*ctor)(void *);
60941 int inuse; /* Offset to metadata */
60942 int align; /* Alignment */
60943 @@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
60944 }
60945
60946 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
60947 -void *__kmalloc(size_t size, gfp_t flags);
60948 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
60949
60950 static __always_inline void *
60951 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
60952 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
60953 index de8832d..0147b46 100644
60954 --- a/include/linux/sonet.h
60955 +++ b/include/linux/sonet.h
60956 @@ -61,7 +61,7 @@ struct sonet_stats {
60957 #include <linux/atomic.h>
60958
60959 struct k_sonet_stats {
60960 -#define __HANDLE_ITEM(i) atomic_t i
60961 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60962 __SONET_ITEMS
60963 #undef __HANDLE_ITEM
60964 };
60965 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
60966 index 3d8f9c4..69f1c0a 100644
60967 --- a/include/linux/sunrpc/clnt.h
60968 +++ b/include/linux/sunrpc/clnt.h
60969 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
60970 {
60971 switch (sap->sa_family) {
60972 case AF_INET:
60973 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
60974 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
60975 case AF_INET6:
60976 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
60977 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
60978 }
60979 return 0;
60980 }
60981 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
60982 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
60983 const struct sockaddr *src)
60984 {
60985 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
60986 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
60987 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
60988
60989 dsin->sin_family = ssin->sin_family;
60990 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
60991 if (sa->sa_family != AF_INET6)
60992 return 0;
60993
60994 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
60995 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
60996 }
60997
60998 #endif /* __KERNEL__ */
60999 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
61000 index e775689..9e206d9 100644
61001 --- a/include/linux/sunrpc/sched.h
61002 +++ b/include/linux/sunrpc/sched.h
61003 @@ -105,6 +105,7 @@ struct rpc_call_ops {
61004 void (*rpc_call_done)(struct rpc_task *, void *);
61005 void (*rpc_release)(void *);
61006 };
61007 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
61008
61009 struct rpc_task_setup {
61010 struct rpc_task *task;
61011 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
61012 index c14fe86..393245e 100644
61013 --- a/include/linux/sunrpc/svc_rdma.h
61014 +++ b/include/linux/sunrpc/svc_rdma.h
61015 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
61016 extern unsigned int svcrdma_max_requests;
61017 extern unsigned int svcrdma_max_req_size;
61018
61019 -extern atomic_t rdma_stat_recv;
61020 -extern atomic_t rdma_stat_read;
61021 -extern atomic_t rdma_stat_write;
61022 -extern atomic_t rdma_stat_sq_starve;
61023 -extern atomic_t rdma_stat_rq_starve;
61024 -extern atomic_t rdma_stat_rq_poll;
61025 -extern atomic_t rdma_stat_rq_prod;
61026 -extern atomic_t rdma_stat_sq_poll;
61027 -extern atomic_t rdma_stat_sq_prod;
61028 +extern atomic_unchecked_t rdma_stat_recv;
61029 +extern atomic_unchecked_t rdma_stat_read;
61030 +extern atomic_unchecked_t rdma_stat_write;
61031 +extern atomic_unchecked_t rdma_stat_sq_starve;
61032 +extern atomic_unchecked_t rdma_stat_rq_starve;
61033 +extern atomic_unchecked_t rdma_stat_rq_poll;
61034 +extern atomic_unchecked_t rdma_stat_rq_prod;
61035 +extern atomic_unchecked_t rdma_stat_sq_poll;
61036 +extern atomic_unchecked_t rdma_stat_sq_prod;
61037
61038 #define RPCRDMA_VERSION 1
61039
61040 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
61041 index 703cfa3..0b8ca72ac 100644
61042 --- a/include/linux/sysctl.h
61043 +++ b/include/linux/sysctl.h
61044 @@ -155,7 +155,11 @@ enum
61045 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
61046 };
61047
61048 -
61049 +#ifdef CONFIG_PAX_SOFTMODE
61050 +enum {
61051 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
61052 +};
61053 +#endif
61054
61055 /* CTL_VM names: */
61056 enum
61057 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
61058
61059 extern int proc_dostring(struct ctl_table *, int,
61060 void __user *, size_t *, loff_t *);
61061 +extern int proc_dostring_modpriv(struct ctl_table *, int,
61062 + void __user *, size_t *, loff_t *);
61063 extern int proc_dointvec(struct ctl_table *, int,
61064 void __user *, size_t *, loff_t *);
61065 extern int proc_dointvec_minmax(struct ctl_table *, int,
61066 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
61067 index a71a292..51bd91d 100644
61068 --- a/include/linux/tracehook.h
61069 +++ b/include/linux/tracehook.h
61070 @@ -54,12 +54,12 @@ struct linux_binprm;
61071 /*
61072 * ptrace report for syscall entry and exit looks identical.
61073 */
61074 -static inline void ptrace_report_syscall(struct pt_regs *regs)
61075 +static inline int ptrace_report_syscall(struct pt_regs *regs)
61076 {
61077 int ptrace = current->ptrace;
61078
61079 if (!(ptrace & PT_PTRACED))
61080 - return;
61081 + return 0;
61082
61083 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
61084
61085 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
61086 send_sig(current->exit_code, current, 1);
61087 current->exit_code = 0;
61088 }
61089 +
61090 + return fatal_signal_pending(current);
61091 }
61092
61093 /**
61094 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
61095 static inline __must_check int tracehook_report_syscall_entry(
61096 struct pt_regs *regs)
61097 {
61098 - ptrace_report_syscall(regs);
61099 - return 0;
61100 + return ptrace_report_syscall(regs);
61101 }
61102
61103 /**
61104 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
61105 index ff7dc08..893e1bd 100644
61106 --- a/include/linux/tty_ldisc.h
61107 +++ b/include/linux/tty_ldisc.h
61108 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
61109
61110 struct module *owner;
61111
61112 - int refcount;
61113 + atomic_t refcount;
61114 };
61115
61116 struct tty_ldisc {
61117 diff --git a/include/linux/types.h b/include/linux/types.h
61118 index 57a9723..dbe234a 100644
61119 --- a/include/linux/types.h
61120 +++ b/include/linux/types.h
61121 @@ -213,10 +213,26 @@ typedef struct {
61122 int counter;
61123 } atomic_t;
61124
61125 +#ifdef CONFIG_PAX_REFCOUNT
61126 +typedef struct {
61127 + int counter;
61128 +} atomic_unchecked_t;
61129 +#else
61130 +typedef atomic_t atomic_unchecked_t;
61131 +#endif
61132 +
61133 #ifdef CONFIG_64BIT
61134 typedef struct {
61135 long counter;
61136 } atomic64_t;
61137 +
61138 +#ifdef CONFIG_PAX_REFCOUNT
61139 +typedef struct {
61140 + long counter;
61141 +} atomic64_unchecked_t;
61142 +#else
61143 +typedef atomic64_t atomic64_unchecked_t;
61144 +#endif
61145 #endif
61146
61147 struct list_head {
61148 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
61149 index 5ca0951..ab496a5 100644
61150 --- a/include/linux/uaccess.h
61151 +++ b/include/linux/uaccess.h
61152 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
61153 long ret; \
61154 mm_segment_t old_fs = get_fs(); \
61155 \
61156 - set_fs(KERNEL_DS); \
61157 pagefault_disable(); \
61158 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
61159 - pagefault_enable(); \
61160 + set_fs(KERNEL_DS); \
61161 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
61162 set_fs(old_fs); \
61163 + pagefault_enable(); \
61164 ret; \
61165 })
61166
61167 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
61168 index 99c1b4d..bb94261 100644
61169 --- a/include/linux/unaligned/access_ok.h
61170 +++ b/include/linux/unaligned/access_ok.h
61171 @@ -6,32 +6,32 @@
61172
61173 static inline u16 get_unaligned_le16(const void *p)
61174 {
61175 - return le16_to_cpup((__le16 *)p);
61176 + return le16_to_cpup((const __le16 *)p);
61177 }
61178
61179 static inline u32 get_unaligned_le32(const void *p)
61180 {
61181 - return le32_to_cpup((__le32 *)p);
61182 + return le32_to_cpup((const __le32 *)p);
61183 }
61184
61185 static inline u64 get_unaligned_le64(const void *p)
61186 {
61187 - return le64_to_cpup((__le64 *)p);
61188 + return le64_to_cpup((const __le64 *)p);
61189 }
61190
61191 static inline u16 get_unaligned_be16(const void *p)
61192 {
61193 - return be16_to_cpup((__be16 *)p);
61194 + return be16_to_cpup((const __be16 *)p);
61195 }
61196
61197 static inline u32 get_unaligned_be32(const void *p)
61198 {
61199 - return be32_to_cpup((__be32 *)p);
61200 + return be32_to_cpup((const __be32 *)p);
61201 }
61202
61203 static inline u64 get_unaligned_be64(const void *p)
61204 {
61205 - return be64_to_cpup((__be64 *)p);
61206 + return be64_to_cpup((const __be64 *)p);
61207 }
61208
61209 static inline void put_unaligned_le16(u16 val, void *p)
61210 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
61211 index e5a40c3..20ab0f6 100644
61212 --- a/include/linux/usb/renesas_usbhs.h
61213 +++ b/include/linux/usb/renesas_usbhs.h
61214 @@ -39,7 +39,7 @@ enum {
61215 */
61216 struct renesas_usbhs_driver_callback {
61217 int (*notify_hotplug)(struct platform_device *pdev);
61218 -};
61219 +} __no_const;
61220
61221 /*
61222 * callback functions for platform
61223 @@ -89,7 +89,7 @@ struct renesas_usbhs_platform_callback {
61224 * VBUS control is needed for Host
61225 */
61226 int (*set_vbus)(struct platform_device *pdev, int enable);
61227 -};
61228 +} __no_const;
61229
61230 /*
61231 * parameters for renesas usbhs
61232 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
61233 index 6f8fbcf..8259001 100644
61234 --- a/include/linux/vermagic.h
61235 +++ b/include/linux/vermagic.h
61236 @@ -25,9 +25,35 @@
61237 #define MODULE_ARCH_VERMAGIC ""
61238 #endif
61239
61240 +#ifdef CONFIG_PAX_REFCOUNT
61241 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
61242 +#else
61243 +#define MODULE_PAX_REFCOUNT ""
61244 +#endif
61245 +
61246 +#ifdef CONSTIFY_PLUGIN
61247 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
61248 +#else
61249 +#define MODULE_CONSTIFY_PLUGIN ""
61250 +#endif
61251 +
61252 +#ifdef STACKLEAK_PLUGIN
61253 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
61254 +#else
61255 +#define MODULE_STACKLEAK_PLUGIN ""
61256 +#endif
61257 +
61258 +#ifdef CONFIG_GRKERNSEC
61259 +#define MODULE_GRSEC "GRSEC "
61260 +#else
61261 +#define MODULE_GRSEC ""
61262 +#endif
61263 +
61264 #define VERMAGIC_STRING \
61265 UTS_RELEASE " " \
61266 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
61267 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
61268 - MODULE_ARCH_VERMAGIC
61269 + MODULE_ARCH_VERMAGIC \
61270 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
61271 + MODULE_GRSEC
61272
61273 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
61274 index 4bde182..aec92c1 100644
61275 --- a/include/linux/vmalloc.h
61276 +++ b/include/linux/vmalloc.h
61277 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
61278 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
61279 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
61280 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
61281 +
61282 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
61283 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
61284 +#endif
61285 +
61286 /* bits [20..32] reserved for arch specific ioremap internals */
61287
61288 /*
61289 @@ -156,4 +161,103 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
61290 # endif
61291 #endif
61292
61293 +#define vmalloc(x) \
61294 +({ \
61295 + void *___retval; \
61296 + intoverflow_t ___x = (intoverflow_t)x; \
61297 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
61298 + ___retval = NULL; \
61299 + else \
61300 + ___retval = vmalloc((unsigned long)___x); \
61301 + ___retval; \
61302 +})
61303 +
61304 +#define vzalloc(x) \
61305 +({ \
61306 + void *___retval; \
61307 + intoverflow_t ___x = (intoverflow_t)x; \
61308 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
61309 + ___retval = NULL; \
61310 + else \
61311 + ___retval = vzalloc((unsigned long)___x); \
61312 + ___retval; \
61313 +})
61314 +
61315 +#define __vmalloc(x, y, z) \
61316 +({ \
61317 + void *___retval; \
61318 + intoverflow_t ___x = (intoverflow_t)x; \
61319 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
61320 + ___retval = NULL; \
61321 + else \
61322 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
61323 + ___retval; \
61324 +})
61325 +
61326 +#define vmalloc_user(x) \
61327 +({ \
61328 + void *___retval; \
61329 + intoverflow_t ___x = (intoverflow_t)x; \
61330 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
61331 + ___retval = NULL; \
61332 + else \
61333 + ___retval = vmalloc_user((unsigned long)___x); \
61334 + ___retval; \
61335 +})
61336 +
61337 +#define vmalloc_exec(x) \
61338 +({ \
61339 + void *___retval; \
61340 + intoverflow_t ___x = (intoverflow_t)x; \
61341 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
61342 + ___retval = NULL; \
61343 + else \
61344 + ___retval = vmalloc_exec((unsigned long)___x); \
61345 + ___retval; \
61346 +})
61347 +
61348 +#define vmalloc_node(x, y) \
61349 +({ \
61350 + void *___retval; \
61351 + intoverflow_t ___x = (intoverflow_t)x; \
61352 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
61353 + ___retval = NULL; \
61354 + else \
61355 + ___retval = vmalloc_node((unsigned long)___x, (y));\
61356 + ___retval; \
61357 +})
61358 +
61359 +#define vzalloc_node(x, y) \
61360 +({ \
61361 + void *___retval; \
61362 + intoverflow_t ___x = (intoverflow_t)x; \
61363 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
61364 + ___retval = NULL; \
61365 + else \
61366 + ___retval = vzalloc_node((unsigned long)___x, (y));\
61367 + ___retval; \
61368 +})
61369 +
61370 +#define vmalloc_32(x) \
61371 +({ \
61372 + void *___retval; \
61373 + intoverflow_t ___x = (intoverflow_t)x; \
61374 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
61375 + ___retval = NULL; \
61376 + else \
61377 + ___retval = vmalloc_32((unsigned long)___x); \
61378 + ___retval; \
61379 +})
61380 +
61381 +#define vmalloc_32_user(x) \
61382 +({ \
61383 +void *___retval; \
61384 + intoverflow_t ___x = (intoverflow_t)x; \
61385 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
61386 + ___retval = NULL; \
61387 + else \
61388 + ___retval = vmalloc_32_user((unsigned long)___x);\
61389 + ___retval; \
61390 +})
61391 +
61392 #endif /* _LINUX_VMALLOC_H */
61393 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
61394 index 65efb92..137adbb 100644
61395 --- a/include/linux/vmstat.h
61396 +++ b/include/linux/vmstat.h
61397 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
61398 /*
61399 * Zone based page accounting with per cpu differentials.
61400 */
61401 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61402 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61403
61404 static inline void zone_page_state_add(long x, struct zone *zone,
61405 enum zone_stat_item item)
61406 {
61407 - atomic_long_add(x, &zone->vm_stat[item]);
61408 - atomic_long_add(x, &vm_stat[item]);
61409 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
61410 + atomic_long_add_unchecked(x, &vm_stat[item]);
61411 }
61412
61413 static inline unsigned long global_page_state(enum zone_stat_item item)
61414 {
61415 - long x = atomic_long_read(&vm_stat[item]);
61416 + long x = atomic_long_read_unchecked(&vm_stat[item]);
61417 #ifdef CONFIG_SMP
61418 if (x < 0)
61419 x = 0;
61420 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
61421 static inline unsigned long zone_page_state(struct zone *zone,
61422 enum zone_stat_item item)
61423 {
61424 - long x = atomic_long_read(&zone->vm_stat[item]);
61425 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61426 #ifdef CONFIG_SMP
61427 if (x < 0)
61428 x = 0;
61429 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
61430 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
61431 enum zone_stat_item item)
61432 {
61433 - long x = atomic_long_read(&zone->vm_stat[item]);
61434 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61435
61436 #ifdef CONFIG_SMP
61437 int cpu;
61438 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
61439
61440 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
61441 {
61442 - atomic_long_inc(&zone->vm_stat[item]);
61443 - atomic_long_inc(&vm_stat[item]);
61444 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
61445 + atomic_long_inc_unchecked(&vm_stat[item]);
61446 }
61447
61448 static inline void __inc_zone_page_state(struct page *page,
61449 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
61450
61451 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
61452 {
61453 - atomic_long_dec(&zone->vm_stat[item]);
61454 - atomic_long_dec(&vm_stat[item]);
61455 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
61456 + atomic_long_dec_unchecked(&vm_stat[item]);
61457 }
61458
61459 static inline void __dec_zone_page_state(struct page *page,
61460 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
61461 index e5d1220..ef6e406 100644
61462 --- a/include/linux/xattr.h
61463 +++ b/include/linux/xattr.h
61464 @@ -57,6 +57,11 @@
61465 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
61466 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
61467
61468 +/* User namespace */
61469 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
61470 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
61471 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
61472 +
61473 #ifdef __KERNEL__
61474
61475 #include <linux/types.h>
61476 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
61477 index 4aeff96..b378cdc 100644
61478 --- a/include/media/saa7146_vv.h
61479 +++ b/include/media/saa7146_vv.h
61480 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
61481 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
61482
61483 /* the extension can override this */
61484 - struct v4l2_ioctl_ops ops;
61485 + v4l2_ioctl_ops_no_const ops;
61486 /* pointer to the saa7146 core ops */
61487 const struct v4l2_ioctl_ops *core_ops;
61488
61489 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
61490 index c7c40f1..4f01585 100644
61491 --- a/include/media/v4l2-dev.h
61492 +++ b/include/media/v4l2-dev.h
61493 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
61494
61495
61496 struct v4l2_file_operations {
61497 - struct module *owner;
61498 + struct module * const owner;
61499 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
61500 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
61501 unsigned int (*poll) (struct file *, struct poll_table_struct *);
61502 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
61503 int (*open) (struct file *);
61504 int (*release) (struct file *);
61505 };
61506 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
61507
61508 /*
61509 * Newer version of video_device, handled by videodev2.c
61510 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
61511 index 4d1c74a..65e1221 100644
61512 --- a/include/media/v4l2-ioctl.h
61513 +++ b/include/media/v4l2-ioctl.h
61514 @@ -274,7 +274,7 @@ struct v4l2_ioctl_ops {
61515 long (*vidioc_default) (struct file *file, void *fh,
61516 bool valid_prio, int cmd, void *arg);
61517 };
61518 -
61519 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
61520
61521 /* v4l debugging and diagnostics */
61522
61523 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
61524 index 8d55251..dfe5b0a 100644
61525 --- a/include/net/caif/caif_hsi.h
61526 +++ b/include/net/caif/caif_hsi.h
61527 @@ -98,7 +98,7 @@ struct cfhsi_drv {
61528 void (*rx_done_cb) (struct cfhsi_drv *drv);
61529 void (*wake_up_cb) (struct cfhsi_drv *drv);
61530 void (*wake_down_cb) (struct cfhsi_drv *drv);
61531 -};
61532 +} __no_const;
61533
61534 /* Structure implemented by HSI device. */
61535 struct cfhsi_dev {
61536 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
61537 index 9e5425b..8136ffc 100644
61538 --- a/include/net/caif/cfctrl.h
61539 +++ b/include/net/caif/cfctrl.h
61540 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
61541 void (*radioset_rsp)(void);
61542 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
61543 struct cflayer *client_layer);
61544 -};
61545 +} __no_const;
61546
61547 /* Link Setup Parameters for CAIF-Links. */
61548 struct cfctrl_link_param {
61549 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
61550 struct cfctrl {
61551 struct cfsrvl serv;
61552 struct cfctrl_rsp res;
61553 - atomic_t req_seq_no;
61554 - atomic_t rsp_seq_no;
61555 + atomic_unchecked_t req_seq_no;
61556 + atomic_unchecked_t rsp_seq_no;
61557 struct list_head list;
61558 /* Protects from simultaneous access to first_req list */
61559 spinlock_t info_list_lock;
61560 diff --git a/include/net/flow.h b/include/net/flow.h
61561 index 57f15a7..0de26c6 100644
61562 --- a/include/net/flow.h
61563 +++ b/include/net/flow.h
61564 @@ -208,6 +208,6 @@ extern struct flow_cache_object *flow_cache_lookup(
61565
61566 extern void flow_cache_flush(void);
61567 extern void flow_cache_flush_deferred(void);
61568 -extern atomic_t flow_cache_genid;
61569 +extern atomic_unchecked_t flow_cache_genid;
61570
61571 #endif
61572 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
61573 index e9ff3fc..9d3e5c7 100644
61574 --- a/include/net/inetpeer.h
61575 +++ b/include/net/inetpeer.h
61576 @@ -48,8 +48,8 @@ struct inet_peer {
61577 */
61578 union {
61579 struct {
61580 - atomic_t rid; /* Frag reception counter */
61581 - atomic_t ip_id_count; /* IP ID for the next packet */
61582 + atomic_unchecked_t rid; /* Frag reception counter */
61583 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
61584 __u32 tcp_ts;
61585 __u32 tcp_ts_stamp;
61586 };
61587 @@ -113,11 +113,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
61588 more++;
61589 inet_peer_refcheck(p);
61590 do {
61591 - old = atomic_read(&p->ip_id_count);
61592 + old = atomic_read_unchecked(&p->ip_id_count);
61593 new = old + more;
61594 if (!new)
61595 new = 1;
61596 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
61597 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
61598 return new;
61599 }
61600
61601 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
61602 index 10422ef..662570f 100644
61603 --- a/include/net/ip_fib.h
61604 +++ b/include/net/ip_fib.h
61605 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
61606
61607 #define FIB_RES_SADDR(net, res) \
61608 ((FIB_RES_NH(res).nh_saddr_genid == \
61609 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
61610 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
61611 FIB_RES_NH(res).nh_saddr : \
61612 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
61613 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
61614 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
61615 index e5a7b9a..f4fc44b 100644
61616 --- a/include/net/ip_vs.h
61617 +++ b/include/net/ip_vs.h
61618 @@ -509,7 +509,7 @@ struct ip_vs_conn {
61619 struct ip_vs_conn *control; /* Master control connection */
61620 atomic_t n_control; /* Number of controlled ones */
61621 struct ip_vs_dest *dest; /* real server */
61622 - atomic_t in_pkts; /* incoming packet counter */
61623 + atomic_unchecked_t in_pkts; /* incoming packet counter */
61624
61625 /* packet transmitter for different forwarding methods. If it
61626 mangles the packet, it must return NF_DROP or better NF_STOLEN,
61627 @@ -647,7 +647,7 @@ struct ip_vs_dest {
61628 __be16 port; /* port number of the server */
61629 union nf_inet_addr addr; /* IP address of the server */
61630 volatile unsigned flags; /* dest status flags */
61631 - atomic_t conn_flags; /* flags to copy to conn */
61632 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
61633 atomic_t weight; /* server weight */
61634
61635 atomic_t refcnt; /* reference counter */
61636 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
61637 index 69b610a..fe3962c 100644
61638 --- a/include/net/irda/ircomm_core.h
61639 +++ b/include/net/irda/ircomm_core.h
61640 @@ -51,7 +51,7 @@ typedef struct {
61641 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
61642 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
61643 struct ircomm_info *);
61644 -} call_t;
61645 +} __no_const call_t;
61646
61647 struct ircomm_cb {
61648 irda_queue_t queue;
61649 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
61650 index 59ba38bc..d515662 100644
61651 --- a/include/net/irda/ircomm_tty.h
61652 +++ b/include/net/irda/ircomm_tty.h
61653 @@ -35,6 +35,7 @@
61654 #include <linux/termios.h>
61655 #include <linux/timer.h>
61656 #include <linux/tty.h> /* struct tty_struct */
61657 +#include <asm/local.h>
61658
61659 #include <net/irda/irias_object.h>
61660 #include <net/irda/ircomm_core.h>
61661 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
61662 unsigned short close_delay;
61663 unsigned short closing_wait; /* time to wait before closing */
61664
61665 - int open_count;
61666 - int blocked_open; /* # of blocked opens */
61667 + local_t open_count;
61668 + local_t blocked_open; /* # of blocked opens */
61669
61670 /* Protect concurent access to :
61671 * o self->open_count
61672 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
61673 index f2419cf..473679f 100644
61674 --- a/include/net/iucv/af_iucv.h
61675 +++ b/include/net/iucv/af_iucv.h
61676 @@ -139,7 +139,7 @@ struct iucv_sock {
61677 struct iucv_sock_list {
61678 struct hlist_head head;
61679 rwlock_t lock;
61680 - atomic_t autobind_name;
61681 + atomic_unchecked_t autobind_name;
61682 };
61683
61684 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
61685 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
61686 index 2720884..3aa5c25 100644
61687 --- a/include/net/neighbour.h
61688 +++ b/include/net/neighbour.h
61689 @@ -122,7 +122,7 @@ struct neigh_ops {
61690 void (*error_report)(struct neighbour *, struct sk_buff *);
61691 int (*output)(struct neighbour *, struct sk_buff *);
61692 int (*connected_output)(struct neighbour *, struct sk_buff *);
61693 -};
61694 +} __do_const;
61695
61696 struct pneigh_entry {
61697 struct pneigh_entry *next;
61698 diff --git a/include/net/netlink.h b/include/net/netlink.h
61699 index cb1f350..3279d2c 100644
61700 --- a/include/net/netlink.h
61701 +++ b/include/net/netlink.h
61702 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
61703 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
61704 {
61705 if (mark)
61706 - skb_trim(skb, (unsigned char *) mark - skb->data);
61707 + skb_trim(skb, (const unsigned char *) mark - skb->data);
61708 }
61709
61710 /**
61711 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
61712 index d786b4f..4c3dd41 100644
61713 --- a/include/net/netns/ipv4.h
61714 +++ b/include/net/netns/ipv4.h
61715 @@ -56,8 +56,8 @@ struct netns_ipv4 {
61716
61717 unsigned int sysctl_ping_group_range[2];
61718
61719 - atomic_t rt_genid;
61720 - atomic_t dev_addr_genid;
61721 + atomic_unchecked_t rt_genid;
61722 + atomic_unchecked_t dev_addr_genid;
61723
61724 #ifdef CONFIG_IP_MROUTE
61725 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
61726 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
61727 index 6a72a58..e6a127d 100644
61728 --- a/include/net/sctp/sctp.h
61729 +++ b/include/net/sctp/sctp.h
61730 @@ -318,9 +318,9 @@ do { \
61731
61732 #else /* SCTP_DEBUG */
61733
61734 -#define SCTP_DEBUG_PRINTK(whatever...)
61735 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
61736 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
61737 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
61738 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
61739 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
61740 #define SCTP_ENABLE_DEBUG
61741 #define SCTP_DISABLE_DEBUG
61742 #define SCTP_ASSERT(expr, str, func)
61743 diff --git a/include/net/sock.h b/include/net/sock.h
61744 index 32e3937..87a1dbc 100644
61745 --- a/include/net/sock.h
61746 +++ b/include/net/sock.h
61747 @@ -277,7 +277,7 @@ struct sock {
61748 #ifdef CONFIG_RPS
61749 __u32 sk_rxhash;
61750 #endif
61751 - atomic_t sk_drops;
61752 + atomic_unchecked_t sk_drops;
61753 int sk_rcvbuf;
61754
61755 struct sk_filter __rcu *sk_filter;
61756 @@ -1402,7 +1402,7 @@ static inline void sk_nocaps_add(struct sock *sk, int flags)
61757 }
61758
61759 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
61760 - char __user *from, char *to,
61761 + char __user *from, unsigned char *to,
61762 int copy, int offset)
61763 {
61764 if (skb->ip_summed == CHECKSUM_NONE) {
61765 diff --git a/include/net/tcp.h b/include/net/tcp.h
61766 index bb18c4d..bb87972 100644
61767 --- a/include/net/tcp.h
61768 +++ b/include/net/tcp.h
61769 @@ -1409,7 +1409,7 @@ struct tcp_seq_afinfo {
61770 char *name;
61771 sa_family_t family;
61772 const struct file_operations *seq_fops;
61773 - struct seq_operations seq_ops;
61774 + seq_operations_no_const seq_ops;
61775 };
61776
61777 struct tcp_iter_state {
61778 diff --git a/include/net/udp.h b/include/net/udp.h
61779 index 3b285f4..0219639 100644
61780 --- a/include/net/udp.h
61781 +++ b/include/net/udp.h
61782 @@ -237,7 +237,7 @@ struct udp_seq_afinfo {
61783 sa_family_t family;
61784 struct udp_table *udp_table;
61785 const struct file_operations *seq_fops;
61786 - struct seq_operations seq_ops;
61787 + seq_operations_no_const seq_ops;
61788 };
61789
61790 struct udp_iter_state {
61791 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
61792 index b203e14..1df3991 100644
61793 --- a/include/net/xfrm.h
61794 +++ b/include/net/xfrm.h
61795 @@ -505,7 +505,7 @@ struct xfrm_policy {
61796 struct timer_list timer;
61797
61798 struct flow_cache_object flo;
61799 - atomic_t genid;
61800 + atomic_unchecked_t genid;
61801 u32 priority;
61802 u32 index;
61803 struct xfrm_mark mark;
61804 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
61805 index 1a046b1..ee0bef0 100644
61806 --- a/include/rdma/iw_cm.h
61807 +++ b/include/rdma/iw_cm.h
61808 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
61809 int backlog);
61810
61811 int (*destroy_listen)(struct iw_cm_id *cm_id);
61812 -};
61813 +} __no_const;
61814
61815 /**
61816 * iw_create_cm_id - Create an IW CM identifier.
61817 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
61818 index 5d1a758..1dbf795 100644
61819 --- a/include/scsi/libfc.h
61820 +++ b/include/scsi/libfc.h
61821 @@ -748,6 +748,7 @@ struct libfc_function_template {
61822 */
61823 void (*disc_stop_final) (struct fc_lport *);
61824 };
61825 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
61826
61827 /**
61828 * struct fc_disc - Discovery context
61829 @@ -851,7 +852,7 @@ struct fc_lport {
61830 struct fc_vport *vport;
61831
61832 /* Operational Information */
61833 - struct libfc_function_template tt;
61834 + libfc_function_template_no_const tt;
61835 u8 link_up;
61836 u8 qfull;
61837 enum fc_lport_state state;
61838 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
61839 index 5591ed5..13eb457 100644
61840 --- a/include/scsi/scsi_device.h
61841 +++ b/include/scsi/scsi_device.h
61842 @@ -161,9 +161,9 @@ struct scsi_device {
61843 unsigned int max_device_blocked; /* what device_blocked counts down from */
61844 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
61845
61846 - atomic_t iorequest_cnt;
61847 - atomic_t iodone_cnt;
61848 - atomic_t ioerr_cnt;
61849 + atomic_unchecked_t iorequest_cnt;
61850 + atomic_unchecked_t iodone_cnt;
61851 + atomic_unchecked_t ioerr_cnt;
61852
61853 struct device sdev_gendev,
61854 sdev_dev;
61855 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
61856 index 2a65167..91e01f8 100644
61857 --- a/include/scsi/scsi_transport_fc.h
61858 +++ b/include/scsi/scsi_transport_fc.h
61859 @@ -711,7 +711,7 @@ struct fc_function_template {
61860 unsigned long show_host_system_hostname:1;
61861
61862 unsigned long disable_target_scan:1;
61863 -};
61864 +} __do_const;
61865
61866
61867 /**
61868 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
61869 index 030b87c..98a6954 100644
61870 --- a/include/sound/ak4xxx-adda.h
61871 +++ b/include/sound/ak4xxx-adda.h
61872 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
61873 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
61874 unsigned char val);
61875 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
61876 -};
61877 +} __no_const;
61878
61879 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
61880
61881 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
61882 index 8c05e47..2b5df97 100644
61883 --- a/include/sound/hwdep.h
61884 +++ b/include/sound/hwdep.h
61885 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
61886 struct snd_hwdep_dsp_status *status);
61887 int (*dsp_load)(struct snd_hwdep *hw,
61888 struct snd_hwdep_dsp_image *image);
61889 -};
61890 +} __no_const;
61891
61892 struct snd_hwdep {
61893 struct snd_card *card;
61894 diff --git a/include/sound/info.h b/include/sound/info.h
61895 index 5492cc4..1a65278 100644
61896 --- a/include/sound/info.h
61897 +++ b/include/sound/info.h
61898 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
61899 struct snd_info_buffer *buffer);
61900 void (*write)(struct snd_info_entry *entry,
61901 struct snd_info_buffer *buffer);
61902 -};
61903 +} __no_const;
61904
61905 struct snd_info_entry_ops {
61906 int (*open)(struct snd_info_entry *entry,
61907 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
61908 index 0cf91b2..b70cae4 100644
61909 --- a/include/sound/pcm.h
61910 +++ b/include/sound/pcm.h
61911 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
61912 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
61913 int (*ack)(struct snd_pcm_substream *substream);
61914 };
61915 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
61916
61917 /*
61918 *
61919 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
61920 index af1b49e..a5d55a5 100644
61921 --- a/include/sound/sb16_csp.h
61922 +++ b/include/sound/sb16_csp.h
61923 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
61924 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
61925 int (*csp_stop) (struct snd_sb_csp * p);
61926 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
61927 -};
61928 +} __no_const;
61929
61930 /*
61931 * CSP private data
61932 diff --git a/include/sound/soc.h b/include/sound/soc.h
61933 index 11cfb59..e3f93f4 100644
61934 --- a/include/sound/soc.h
61935 +++ b/include/sound/soc.h
61936 @@ -683,7 +683,7 @@ struct snd_soc_platform_driver {
61937 /* platform IO - used for platform DAPM */
61938 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
61939 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
61940 -};
61941 +} __do_const;
61942
61943 struct snd_soc_platform {
61944 const char *name;
61945 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
61946 index 444cd6b..3327cc5 100644
61947 --- a/include/sound/ymfpci.h
61948 +++ b/include/sound/ymfpci.h
61949 @@ -358,7 +358,7 @@ struct snd_ymfpci {
61950 spinlock_t reg_lock;
61951 spinlock_t voice_lock;
61952 wait_queue_head_t interrupt_sleep;
61953 - atomic_t interrupt_sleep_count;
61954 + atomic_unchecked_t interrupt_sleep_count;
61955 struct snd_info_entry *proc_entry;
61956 const struct firmware *dsp_microcode;
61957 const struct firmware *controller_microcode;
61958 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
61959 index a79886c..b483af6 100644
61960 --- a/include/target/target_core_base.h
61961 +++ b/include/target/target_core_base.h
61962 @@ -346,7 +346,7 @@ struct t10_reservation_ops {
61963 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
61964 int (*t10_pr_register)(struct se_cmd *);
61965 int (*t10_pr_clear)(struct se_cmd *);
61966 -};
61967 +} __no_const;
61968
61969 struct t10_reservation {
61970 /* Reservation effects all target ports */
61971 @@ -465,8 +465,8 @@ struct se_cmd {
61972 atomic_t t_se_count;
61973 atomic_t t_task_cdbs_left;
61974 atomic_t t_task_cdbs_ex_left;
61975 - atomic_t t_task_cdbs_sent;
61976 - atomic_t t_transport_aborted;
61977 + atomic_unchecked_t t_task_cdbs_sent;
61978 + atomic_unchecked_t t_transport_aborted;
61979 atomic_t t_transport_active;
61980 atomic_t t_transport_complete;
61981 atomic_t t_transport_queue_active;
61982 @@ -704,7 +704,7 @@ struct se_device {
61983 /* Active commands on this virtual SE device */
61984 atomic_t simple_cmds;
61985 atomic_t depth_left;
61986 - atomic_t dev_ordered_id;
61987 + atomic_unchecked_t dev_ordered_id;
61988 atomic_t execute_tasks;
61989 atomic_t dev_ordered_sync;
61990 atomic_t dev_qf_count;
61991 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
61992 index 1c09820..7f5ec79 100644
61993 --- a/include/trace/events/irq.h
61994 +++ b/include/trace/events/irq.h
61995 @@ -36,7 +36,7 @@ struct softirq_action;
61996 */
61997 TRACE_EVENT(irq_handler_entry,
61998
61999 - TP_PROTO(int irq, struct irqaction *action),
62000 + TP_PROTO(int irq, const struct irqaction *action),
62001
62002 TP_ARGS(irq, action),
62003
62004 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
62005 */
62006 TRACE_EVENT(irq_handler_exit,
62007
62008 - TP_PROTO(int irq, struct irqaction *action, int ret),
62009 + TP_PROTO(int irq, const struct irqaction *action, int ret),
62010
62011 TP_ARGS(irq, action, ret),
62012
62013 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
62014 index c41f308..6918de3 100644
62015 --- a/include/video/udlfb.h
62016 +++ b/include/video/udlfb.h
62017 @@ -52,10 +52,10 @@ struct dlfb_data {
62018 u32 pseudo_palette[256];
62019 int blank_mode; /*one of FB_BLANK_ */
62020 /* blit-only rendering path metrics, exposed through sysfs */
62021 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
62022 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
62023 - atomic_t bytes_sent; /* to usb, after compression including overhead */
62024 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
62025 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
62026 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
62027 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
62028 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
62029 };
62030
62031 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
62032 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
62033 index 0993a22..32ba2fe 100644
62034 --- a/include/video/uvesafb.h
62035 +++ b/include/video/uvesafb.h
62036 @@ -177,6 +177,7 @@ struct uvesafb_par {
62037 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
62038 u8 pmi_setpal; /* PMI for palette changes */
62039 u16 *pmi_base; /* protected mode interface location */
62040 + u8 *pmi_code; /* protected mode code location */
62041 void *pmi_start;
62042 void *pmi_pal;
62043 u8 *vbe_state_orig; /*
62044 diff --git a/init/Kconfig b/init/Kconfig
62045 index 43298f9..2f56c12 100644
62046 --- a/init/Kconfig
62047 +++ b/init/Kconfig
62048 @@ -1214,7 +1214,7 @@ config SLUB_DEBUG
62049
62050 config COMPAT_BRK
62051 bool "Disable heap randomization"
62052 - default y
62053 + default n
62054 help
62055 Randomizing heap placement makes heap exploits harder, but it
62056 also breaks ancient binaries (including anything libc5 based).
62057 diff --git a/init/do_mounts.c b/init/do_mounts.c
62058 index db6e5ee..7677ff7 100644
62059 --- a/init/do_mounts.c
62060 +++ b/init/do_mounts.c
62061 @@ -325,11 +325,11 @@ static void __init get_fs_names(char *page)
62062
62063 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
62064 {
62065 - int err = sys_mount(name, "/root", fs, flags, data);
62066 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
62067 if (err)
62068 return err;
62069
62070 - sys_chdir((const char __user __force *)"/root");
62071 + sys_chdir((const char __force_user*)"/root");
62072 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
62073 printk(KERN_INFO
62074 "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
62075 @@ -448,18 +448,18 @@ void __init change_floppy(char *fmt, ...)
62076 va_start(args, fmt);
62077 vsprintf(buf, fmt, args);
62078 va_end(args);
62079 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
62080 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
62081 if (fd >= 0) {
62082 sys_ioctl(fd, FDEJECT, 0);
62083 sys_close(fd);
62084 }
62085 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
62086 - fd = sys_open("/dev/console", O_RDWR, 0);
62087 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
62088 if (fd >= 0) {
62089 sys_ioctl(fd, TCGETS, (long)&termios);
62090 termios.c_lflag &= ~ICANON;
62091 sys_ioctl(fd, TCSETSF, (long)&termios);
62092 - sys_read(fd, &c, 1);
62093 + sys_read(fd, (char __user *)&c, 1);
62094 termios.c_lflag |= ICANON;
62095 sys_ioctl(fd, TCSETSF, (long)&termios);
62096 sys_close(fd);
62097 @@ -553,6 +553,6 @@ void __init prepare_namespace(void)
62098 mount_root();
62099 out:
62100 devtmpfs_mount("dev");
62101 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
62102 - sys_chroot((const char __user __force *)".");
62103 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
62104 + sys_chroot((const char __force_user *)".");
62105 }
62106 diff --git a/init/do_mounts.h b/init/do_mounts.h
62107 index f5b978a..69dbfe8 100644
62108 --- a/init/do_mounts.h
62109 +++ b/init/do_mounts.h
62110 @@ -15,15 +15,15 @@ extern int root_mountflags;
62111
62112 static inline int create_dev(char *name, dev_t dev)
62113 {
62114 - sys_unlink(name);
62115 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
62116 + sys_unlink((char __force_user *)name);
62117 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
62118 }
62119
62120 #if BITS_PER_LONG == 32
62121 static inline u32 bstat(char *name)
62122 {
62123 struct stat64 stat;
62124 - if (sys_stat64(name, &stat) != 0)
62125 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
62126 return 0;
62127 if (!S_ISBLK(stat.st_mode))
62128 return 0;
62129 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
62130 static inline u32 bstat(char *name)
62131 {
62132 struct stat stat;
62133 - if (sys_newstat(name, &stat) != 0)
62134 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
62135 return 0;
62136 if (!S_ISBLK(stat.st_mode))
62137 return 0;
62138 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
62139 index 3098a38..253064e 100644
62140 --- a/init/do_mounts_initrd.c
62141 +++ b/init/do_mounts_initrd.c
62142 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
62143 create_dev("/dev/root.old", Root_RAM0);
62144 /* mount initrd on rootfs' /root */
62145 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
62146 - sys_mkdir("/old", 0700);
62147 - root_fd = sys_open("/", 0, 0);
62148 - old_fd = sys_open("/old", 0, 0);
62149 + sys_mkdir((const char __force_user *)"/old", 0700);
62150 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
62151 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
62152 /* move initrd over / and chdir/chroot in initrd root */
62153 - sys_chdir("/root");
62154 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
62155 - sys_chroot(".");
62156 + sys_chdir((const char __force_user *)"/root");
62157 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
62158 + sys_chroot((const char __force_user *)".");
62159
62160 /*
62161 * In case that a resume from disk is carried out by linuxrc or one of
62162 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
62163
62164 /* move initrd to rootfs' /old */
62165 sys_fchdir(old_fd);
62166 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
62167 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
62168 /* switch root and cwd back to / of rootfs */
62169 sys_fchdir(root_fd);
62170 - sys_chroot(".");
62171 + sys_chroot((const char __force_user *)".");
62172 sys_close(old_fd);
62173 sys_close(root_fd);
62174
62175 if (new_decode_dev(real_root_dev) == Root_RAM0) {
62176 - sys_chdir("/old");
62177 + sys_chdir((const char __force_user *)"/old");
62178 return;
62179 }
62180
62181 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
62182 mount_root();
62183
62184 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
62185 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
62186 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
62187 if (!error)
62188 printk("okay\n");
62189 else {
62190 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
62191 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
62192 if (error == -ENOENT)
62193 printk("/initrd does not exist. Ignored.\n");
62194 else
62195 printk("failed\n");
62196 printk(KERN_NOTICE "Unmounting old root\n");
62197 - sys_umount("/old", MNT_DETACH);
62198 + sys_umount((char __force_user *)"/old", MNT_DETACH);
62199 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
62200 if (fd < 0) {
62201 error = fd;
62202 @@ -116,11 +116,11 @@ int __init initrd_load(void)
62203 * mounted in the normal path.
62204 */
62205 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
62206 - sys_unlink("/initrd.image");
62207 + sys_unlink((const char __force_user *)"/initrd.image");
62208 handle_initrd();
62209 return 1;
62210 }
62211 }
62212 - sys_unlink("/initrd.image");
62213 + sys_unlink((const char __force_user *)"/initrd.image");
62214 return 0;
62215 }
62216 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
62217 index 32c4799..c27ee74 100644
62218 --- a/init/do_mounts_md.c
62219 +++ b/init/do_mounts_md.c
62220 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
62221 partitioned ? "_d" : "", minor,
62222 md_setup_args[ent].device_names);
62223
62224 - fd = sys_open(name, 0, 0);
62225 + fd = sys_open((char __force_user *)name, 0, 0);
62226 if (fd < 0) {
62227 printk(KERN_ERR "md: open failed - cannot start "
62228 "array %s\n", name);
62229 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
62230 * array without it
62231 */
62232 sys_close(fd);
62233 - fd = sys_open(name, 0, 0);
62234 + fd = sys_open((char __force_user *)name, 0, 0);
62235 sys_ioctl(fd, BLKRRPART, 0);
62236 }
62237 sys_close(fd);
62238 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
62239
62240 wait_for_device_probe();
62241
62242 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
62243 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
62244 if (fd >= 0) {
62245 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
62246 sys_close(fd);
62247 diff --git a/init/initramfs.c b/init/initramfs.c
62248 index 2531811..040d4d4 100644
62249 --- a/init/initramfs.c
62250 +++ b/init/initramfs.c
62251 @@ -74,7 +74,7 @@ static void __init free_hash(void)
62252 }
62253 }
62254
62255 -static long __init do_utime(char __user *filename, time_t mtime)
62256 +static long __init do_utime(__force char __user *filename, time_t mtime)
62257 {
62258 struct timespec t[2];
62259
62260 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
62261 struct dir_entry *de, *tmp;
62262 list_for_each_entry_safe(de, tmp, &dir_list, list) {
62263 list_del(&de->list);
62264 - do_utime(de->name, de->mtime);
62265 + do_utime((char __force_user *)de->name, de->mtime);
62266 kfree(de->name);
62267 kfree(de);
62268 }
62269 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
62270 if (nlink >= 2) {
62271 char *old = find_link(major, minor, ino, mode, collected);
62272 if (old)
62273 - return (sys_link(old, collected) < 0) ? -1 : 1;
62274 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
62275 }
62276 return 0;
62277 }
62278 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
62279 {
62280 struct stat st;
62281
62282 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
62283 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
62284 if (S_ISDIR(st.st_mode))
62285 - sys_rmdir(path);
62286 + sys_rmdir((char __force_user *)path);
62287 else
62288 - sys_unlink(path);
62289 + sys_unlink((char __force_user *)path);
62290 }
62291 }
62292
62293 @@ -305,7 +305,7 @@ static int __init do_name(void)
62294 int openflags = O_WRONLY|O_CREAT;
62295 if (ml != 1)
62296 openflags |= O_TRUNC;
62297 - wfd = sys_open(collected, openflags, mode);
62298 + wfd = sys_open((char __force_user *)collected, openflags, mode);
62299
62300 if (wfd >= 0) {
62301 sys_fchown(wfd, uid, gid);
62302 @@ -317,17 +317,17 @@ static int __init do_name(void)
62303 }
62304 }
62305 } else if (S_ISDIR(mode)) {
62306 - sys_mkdir(collected, mode);
62307 - sys_chown(collected, uid, gid);
62308 - sys_chmod(collected, mode);
62309 + sys_mkdir((char __force_user *)collected, mode);
62310 + sys_chown((char __force_user *)collected, uid, gid);
62311 + sys_chmod((char __force_user *)collected, mode);
62312 dir_add(collected, mtime);
62313 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
62314 S_ISFIFO(mode) || S_ISSOCK(mode)) {
62315 if (maybe_link() == 0) {
62316 - sys_mknod(collected, mode, rdev);
62317 - sys_chown(collected, uid, gid);
62318 - sys_chmod(collected, mode);
62319 - do_utime(collected, mtime);
62320 + sys_mknod((char __force_user *)collected, mode, rdev);
62321 + sys_chown((char __force_user *)collected, uid, gid);
62322 + sys_chmod((char __force_user *)collected, mode);
62323 + do_utime((char __force_user *)collected, mtime);
62324 }
62325 }
62326 return 0;
62327 @@ -336,15 +336,15 @@ static int __init do_name(void)
62328 static int __init do_copy(void)
62329 {
62330 if (count >= body_len) {
62331 - sys_write(wfd, victim, body_len);
62332 + sys_write(wfd, (char __force_user *)victim, body_len);
62333 sys_close(wfd);
62334 - do_utime(vcollected, mtime);
62335 + do_utime((char __force_user *)vcollected, mtime);
62336 kfree(vcollected);
62337 eat(body_len);
62338 state = SkipIt;
62339 return 0;
62340 } else {
62341 - sys_write(wfd, victim, count);
62342 + sys_write(wfd, (char __force_user *)victim, count);
62343 body_len -= count;
62344 eat(count);
62345 return 1;
62346 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
62347 {
62348 collected[N_ALIGN(name_len) + body_len] = '\0';
62349 clean_path(collected, 0);
62350 - sys_symlink(collected + N_ALIGN(name_len), collected);
62351 - sys_lchown(collected, uid, gid);
62352 - do_utime(collected, mtime);
62353 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
62354 + sys_lchown((char __force_user *)collected, uid, gid);
62355 + do_utime((char __force_user *)collected, mtime);
62356 state = SkipIt;
62357 next_state = Reset;
62358 return 0;
62359 diff --git a/init/main.c b/init/main.c
62360 index 217ed23..ec5406f 100644
62361 --- a/init/main.c
62362 +++ b/init/main.c
62363 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
62364 extern void tc_init(void);
62365 #endif
62366
62367 +extern void grsecurity_init(void);
62368 +
62369 /*
62370 * Debug helper: via this flag we know that we are in 'early bootup code'
62371 * where only the boot processor is running with IRQ disabled. This means
62372 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
62373
62374 __setup("reset_devices", set_reset_devices);
62375
62376 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
62377 +extern char pax_enter_kernel_user[];
62378 +extern char pax_exit_kernel_user[];
62379 +extern pgdval_t clone_pgd_mask;
62380 +#endif
62381 +
62382 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
62383 +static int __init setup_pax_nouderef(char *str)
62384 +{
62385 +#ifdef CONFIG_X86_32
62386 + unsigned int cpu;
62387 + struct desc_struct *gdt;
62388 +
62389 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
62390 + gdt = get_cpu_gdt_table(cpu);
62391 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
62392 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
62393 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
62394 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
62395 + }
62396 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
62397 +#else
62398 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
62399 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
62400 + clone_pgd_mask = ~(pgdval_t)0UL;
62401 +#endif
62402 +
62403 + return 0;
62404 +}
62405 +early_param("pax_nouderef", setup_pax_nouderef);
62406 +#endif
62407 +
62408 +#ifdef CONFIG_PAX_SOFTMODE
62409 +int pax_softmode;
62410 +
62411 +static int __init setup_pax_softmode(char *str)
62412 +{
62413 + get_option(&str, &pax_softmode);
62414 + return 1;
62415 +}
62416 +__setup("pax_softmode=", setup_pax_softmode);
62417 +#endif
62418 +
62419 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
62420 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
62421 static const char *panic_later, *panic_param;
62422 @@ -681,6 +726,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
62423 {
62424 int count = preempt_count();
62425 int ret;
62426 + const char *msg1 = "", *msg2 = "";
62427
62428 if (initcall_debug)
62429 ret = do_one_initcall_debug(fn);
62430 @@ -693,15 +739,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
62431 sprintf(msgbuf, "error code %d ", ret);
62432
62433 if (preempt_count() != count) {
62434 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
62435 + msg1 = " preemption imbalance";
62436 preempt_count() = count;
62437 }
62438 if (irqs_disabled()) {
62439 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
62440 + msg2 = " disabled interrupts";
62441 local_irq_enable();
62442 }
62443 - if (msgbuf[0]) {
62444 - printk("initcall %pF returned with %s\n", fn, msgbuf);
62445 + if (msgbuf[0] || *msg1 || *msg2) {
62446 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
62447 }
62448
62449 return ret;
62450 @@ -820,7 +866,7 @@ static int __init kernel_init(void * unused)
62451 do_basic_setup();
62452
62453 /* Open the /dev/console on the rootfs, this should never fail */
62454 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
62455 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
62456 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
62457
62458 (void) sys_dup(0);
62459 @@ -833,11 +879,13 @@ static int __init kernel_init(void * unused)
62460 if (!ramdisk_execute_command)
62461 ramdisk_execute_command = "/init";
62462
62463 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
62464 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
62465 ramdisk_execute_command = NULL;
62466 prepare_namespace();
62467 }
62468
62469 + grsecurity_init();
62470 +
62471 /*
62472 * Ok, we have completed the initial bootup, and
62473 * we're essentially up and running. Get rid of the
62474 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
62475 index 5b4293d..f179875 100644
62476 --- a/ipc/mqueue.c
62477 +++ b/ipc/mqueue.c
62478 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
62479 mq_bytes = (mq_msg_tblsz +
62480 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
62481
62482 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
62483 spin_lock(&mq_lock);
62484 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
62485 u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
62486 diff --git a/ipc/msg.c b/ipc/msg.c
62487 index 7385de2..a8180e0 100644
62488 --- a/ipc/msg.c
62489 +++ b/ipc/msg.c
62490 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
62491 return security_msg_queue_associate(msq, msgflg);
62492 }
62493
62494 +static struct ipc_ops msg_ops = {
62495 + .getnew = newque,
62496 + .associate = msg_security,
62497 + .more_checks = NULL
62498 +};
62499 +
62500 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
62501 {
62502 struct ipc_namespace *ns;
62503 - struct ipc_ops msg_ops;
62504 struct ipc_params msg_params;
62505
62506 ns = current->nsproxy->ipc_ns;
62507
62508 - msg_ops.getnew = newque;
62509 - msg_ops.associate = msg_security;
62510 - msg_ops.more_checks = NULL;
62511 -
62512 msg_params.key = key;
62513 msg_params.flg = msgflg;
62514
62515 diff --git a/ipc/sem.c b/ipc/sem.c
62516 index 5215a81..cfc0cac 100644
62517 --- a/ipc/sem.c
62518 +++ b/ipc/sem.c
62519 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
62520 return 0;
62521 }
62522
62523 +static struct ipc_ops sem_ops = {
62524 + .getnew = newary,
62525 + .associate = sem_security,
62526 + .more_checks = sem_more_checks
62527 +};
62528 +
62529 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
62530 {
62531 struct ipc_namespace *ns;
62532 - struct ipc_ops sem_ops;
62533 struct ipc_params sem_params;
62534
62535 ns = current->nsproxy->ipc_ns;
62536 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
62537 if (nsems < 0 || nsems > ns->sc_semmsl)
62538 return -EINVAL;
62539
62540 - sem_ops.getnew = newary;
62541 - sem_ops.associate = sem_security;
62542 - sem_ops.more_checks = sem_more_checks;
62543 -
62544 sem_params.key = key;
62545 sem_params.flg = semflg;
62546 sem_params.u.nsems = nsems;
62547 diff --git a/ipc/shm.c b/ipc/shm.c
62548 index b76be5b..859e750 100644
62549 --- a/ipc/shm.c
62550 +++ b/ipc/shm.c
62551 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
62552 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
62553 #endif
62554
62555 +#ifdef CONFIG_GRKERNSEC
62556 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62557 + const time_t shm_createtime, const uid_t cuid,
62558 + const int shmid);
62559 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62560 + const time_t shm_createtime);
62561 +#endif
62562 +
62563 void shm_init_ns(struct ipc_namespace *ns)
62564 {
62565 ns->shm_ctlmax = SHMMAX;
62566 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
62567 shp->shm_lprid = 0;
62568 shp->shm_atim = shp->shm_dtim = 0;
62569 shp->shm_ctim = get_seconds();
62570 +#ifdef CONFIG_GRKERNSEC
62571 + {
62572 + struct timespec timeval;
62573 + do_posix_clock_monotonic_gettime(&timeval);
62574 +
62575 + shp->shm_createtime = timeval.tv_sec;
62576 + }
62577 +#endif
62578 shp->shm_segsz = size;
62579 shp->shm_nattch = 0;
62580 shp->shm_file = file;
62581 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
62582 return 0;
62583 }
62584
62585 +static struct ipc_ops shm_ops = {
62586 + .getnew = newseg,
62587 + .associate = shm_security,
62588 + .more_checks = shm_more_checks
62589 +};
62590 +
62591 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
62592 {
62593 struct ipc_namespace *ns;
62594 - struct ipc_ops shm_ops;
62595 struct ipc_params shm_params;
62596
62597 ns = current->nsproxy->ipc_ns;
62598
62599 - shm_ops.getnew = newseg;
62600 - shm_ops.associate = shm_security;
62601 - shm_ops.more_checks = shm_more_checks;
62602 -
62603 shm_params.key = key;
62604 shm_params.flg = shmflg;
62605 shm_params.u.size = size;
62606 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
62607 f_mode = FMODE_READ | FMODE_WRITE;
62608 }
62609 if (shmflg & SHM_EXEC) {
62610 +
62611 +#ifdef CONFIG_PAX_MPROTECT
62612 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
62613 + goto out;
62614 +#endif
62615 +
62616 prot |= PROT_EXEC;
62617 acc_mode |= S_IXUGO;
62618 }
62619 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
62620 if (err)
62621 goto out_unlock;
62622
62623 +#ifdef CONFIG_GRKERNSEC
62624 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
62625 + shp->shm_perm.cuid, shmid) ||
62626 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
62627 + err = -EACCES;
62628 + goto out_unlock;
62629 + }
62630 +#endif
62631 +
62632 path = shp->shm_file->f_path;
62633 path_get(&path);
62634 shp->shm_nattch++;
62635 +#ifdef CONFIG_GRKERNSEC
62636 + shp->shm_lapid = current->pid;
62637 +#endif
62638 size = i_size_read(path.dentry->d_inode);
62639 shm_unlock(shp);
62640
62641 diff --git a/kernel/acct.c b/kernel/acct.c
62642 index fa7eb3d..7faf116 100644
62643 --- a/kernel/acct.c
62644 +++ b/kernel/acct.c
62645 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
62646 */
62647 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
62648 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
62649 - file->f_op->write(file, (char *)&ac,
62650 + file->f_op->write(file, (char __force_user *)&ac,
62651 sizeof(acct_t), &file->f_pos);
62652 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
62653 set_fs(fs);
62654 diff --git a/kernel/audit.c b/kernel/audit.c
62655 index 09fae26..ed71d5b 100644
62656 --- a/kernel/audit.c
62657 +++ b/kernel/audit.c
62658 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
62659 3) suppressed due to audit_rate_limit
62660 4) suppressed due to audit_backlog_limit
62661 */
62662 -static atomic_t audit_lost = ATOMIC_INIT(0);
62663 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
62664
62665 /* The netlink socket. */
62666 static struct sock *audit_sock;
62667 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
62668 unsigned long now;
62669 int print;
62670
62671 - atomic_inc(&audit_lost);
62672 + atomic_inc_unchecked(&audit_lost);
62673
62674 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
62675
62676 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
62677 printk(KERN_WARNING
62678 "audit: audit_lost=%d audit_rate_limit=%d "
62679 "audit_backlog_limit=%d\n",
62680 - atomic_read(&audit_lost),
62681 + atomic_read_unchecked(&audit_lost),
62682 audit_rate_limit,
62683 audit_backlog_limit);
62684 audit_panic(message);
62685 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
62686 status_set.pid = audit_pid;
62687 status_set.rate_limit = audit_rate_limit;
62688 status_set.backlog_limit = audit_backlog_limit;
62689 - status_set.lost = atomic_read(&audit_lost);
62690 + status_set.lost = atomic_read_unchecked(&audit_lost);
62691 status_set.backlog = skb_queue_len(&audit_skb_queue);
62692 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
62693 &status_set, sizeof(status_set));
62694 @@ -1260,12 +1260,13 @@ static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
62695 avail = audit_expand(ab,
62696 max_t(unsigned, AUDIT_BUFSIZ, 1+len-avail));
62697 if (!avail)
62698 - goto out;
62699 + goto out_va_end;
62700 len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2);
62701 }
62702 - va_end(args2);
62703 if (len > 0)
62704 skb_put(skb, len);
62705 +out_va_end:
62706 + va_end(args2);
62707 out:
62708 return;
62709 }
62710 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
62711 index 47b7fc1..c003c33 100644
62712 --- a/kernel/auditsc.c
62713 +++ b/kernel/auditsc.c
62714 @@ -1166,8 +1166,8 @@ static void audit_log_execve_info(struct audit_context *context,
62715 struct audit_buffer **ab,
62716 struct audit_aux_data_execve *axi)
62717 {
62718 - int i;
62719 - size_t len, len_sent = 0;
62720 + int i, len;
62721 + size_t len_sent = 0;
62722 const char __user *p;
62723 char *buf;
62724
62725 @@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
62726 }
62727
62728 /* global counter which is incremented every time something logs in */
62729 -static atomic_t session_id = ATOMIC_INIT(0);
62730 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
62731
62732 /**
62733 * audit_set_loginuid - set a task's audit_context loginuid
62734 @@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
62735 */
62736 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
62737 {
62738 - unsigned int sessionid = atomic_inc_return(&session_id);
62739 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
62740 struct audit_context *context = task->audit_context;
62741
62742 if (context && context->in_syscall) {
62743 diff --git a/kernel/capability.c b/kernel/capability.c
62744 index b463871..fa3ea1f 100644
62745 --- a/kernel/capability.c
62746 +++ b/kernel/capability.c
62747 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
62748 * before modification is attempted and the application
62749 * fails.
62750 */
62751 + if (tocopy > ARRAY_SIZE(kdata))
62752 + return -EFAULT;
62753 +
62754 if (copy_to_user(dataptr, kdata, tocopy
62755 * sizeof(struct __user_cap_data_struct))) {
62756 return -EFAULT;
62757 @@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
62758 BUG();
62759 }
62760
62761 - if (security_capable(ns, current_cred(), cap) == 0) {
62762 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
62763 current->flags |= PF_SUPERPRIV;
62764 return true;
62765 }
62766 @@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *ns, int cap)
62767 }
62768 EXPORT_SYMBOL(ns_capable);
62769
62770 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
62771 +{
62772 + if (unlikely(!cap_valid(cap))) {
62773 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
62774 + BUG();
62775 + }
62776 +
62777 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
62778 + current->flags |= PF_SUPERPRIV;
62779 + return true;
62780 + }
62781 + return false;
62782 +}
62783 +EXPORT_SYMBOL(ns_capable_nolog);
62784 +
62785 +bool capable_nolog(int cap)
62786 +{
62787 + return ns_capable_nolog(&init_user_ns, cap);
62788 +}
62789 +EXPORT_SYMBOL(capable_nolog);
62790 +
62791 /**
62792 * task_ns_capable - Determine whether current task has a superior
62793 * capability targeted at a specific task's user namespace.
62794 @@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct *t, int cap)
62795 }
62796 EXPORT_SYMBOL(task_ns_capable);
62797
62798 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
62799 +{
62800 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
62801 +}
62802 +EXPORT_SYMBOL(task_ns_capable_nolog);
62803 +
62804 /**
62805 * nsown_capable - Check superior capability to one's own user_ns
62806 * @cap: The capability in question
62807 diff --git a/kernel/compat.c b/kernel/compat.c
62808 index f346ced..aa2b1f4 100644
62809 --- a/kernel/compat.c
62810 +++ b/kernel/compat.c
62811 @@ -13,6 +13,7 @@
62812
62813 #include <linux/linkage.h>
62814 #include <linux/compat.h>
62815 +#include <linux/module.h>
62816 #include <linux/errno.h>
62817 #include <linux/time.h>
62818 #include <linux/signal.h>
62819 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
62820 mm_segment_t oldfs;
62821 long ret;
62822
62823 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
62824 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
62825 oldfs = get_fs();
62826 set_fs(KERNEL_DS);
62827 ret = hrtimer_nanosleep_restart(restart);
62828 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
62829 oldfs = get_fs();
62830 set_fs(KERNEL_DS);
62831 ret = hrtimer_nanosleep(&tu,
62832 - rmtp ? (struct timespec __user *)&rmt : NULL,
62833 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
62834 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
62835 set_fs(oldfs);
62836
62837 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
62838 mm_segment_t old_fs = get_fs();
62839
62840 set_fs(KERNEL_DS);
62841 - ret = sys_sigpending((old_sigset_t __user *) &s);
62842 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
62843 set_fs(old_fs);
62844 if (ret == 0)
62845 ret = put_user(s, set);
62846 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
62847 old_fs = get_fs();
62848 set_fs(KERNEL_DS);
62849 ret = sys_sigprocmask(how,
62850 - set ? (old_sigset_t __user *) &s : NULL,
62851 - oset ? (old_sigset_t __user *) &s : NULL);
62852 + set ? (old_sigset_t __force_user *) &s : NULL,
62853 + oset ? (old_sigset_t __force_user *) &s : NULL);
62854 set_fs(old_fs);
62855 if (ret == 0)
62856 if (oset)
62857 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
62858 mm_segment_t old_fs = get_fs();
62859
62860 set_fs(KERNEL_DS);
62861 - ret = sys_old_getrlimit(resource, &r);
62862 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
62863 set_fs(old_fs);
62864
62865 if (!ret) {
62866 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
62867 mm_segment_t old_fs = get_fs();
62868
62869 set_fs(KERNEL_DS);
62870 - ret = sys_getrusage(who, (struct rusage __user *) &r);
62871 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
62872 set_fs(old_fs);
62873
62874 if (ret)
62875 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
62876 set_fs (KERNEL_DS);
62877 ret = sys_wait4(pid,
62878 (stat_addr ?
62879 - (unsigned int __user *) &status : NULL),
62880 - options, (struct rusage __user *) &r);
62881 + (unsigned int __force_user *) &status : NULL),
62882 + options, (struct rusage __force_user *) &r);
62883 set_fs (old_fs);
62884
62885 if (ret > 0) {
62886 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
62887 memset(&info, 0, sizeof(info));
62888
62889 set_fs(KERNEL_DS);
62890 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
62891 - uru ? (struct rusage __user *)&ru : NULL);
62892 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
62893 + uru ? (struct rusage __force_user *)&ru : NULL);
62894 set_fs(old_fs);
62895
62896 if ((ret < 0) || (info.si_signo == 0))
62897 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
62898 oldfs = get_fs();
62899 set_fs(KERNEL_DS);
62900 err = sys_timer_settime(timer_id, flags,
62901 - (struct itimerspec __user *) &newts,
62902 - (struct itimerspec __user *) &oldts);
62903 + (struct itimerspec __force_user *) &newts,
62904 + (struct itimerspec __force_user *) &oldts);
62905 set_fs(oldfs);
62906 if (!err && old && put_compat_itimerspec(old, &oldts))
62907 return -EFAULT;
62908 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
62909 oldfs = get_fs();
62910 set_fs(KERNEL_DS);
62911 err = sys_timer_gettime(timer_id,
62912 - (struct itimerspec __user *) &ts);
62913 + (struct itimerspec __force_user *) &ts);
62914 set_fs(oldfs);
62915 if (!err && put_compat_itimerspec(setting, &ts))
62916 return -EFAULT;
62917 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
62918 oldfs = get_fs();
62919 set_fs(KERNEL_DS);
62920 err = sys_clock_settime(which_clock,
62921 - (struct timespec __user *) &ts);
62922 + (struct timespec __force_user *) &ts);
62923 set_fs(oldfs);
62924 return err;
62925 }
62926 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
62927 oldfs = get_fs();
62928 set_fs(KERNEL_DS);
62929 err = sys_clock_gettime(which_clock,
62930 - (struct timespec __user *) &ts);
62931 + (struct timespec __force_user *) &ts);
62932 set_fs(oldfs);
62933 if (!err && put_compat_timespec(&ts, tp))
62934 return -EFAULT;
62935 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
62936
62937 oldfs = get_fs();
62938 set_fs(KERNEL_DS);
62939 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
62940 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
62941 set_fs(oldfs);
62942
62943 err = compat_put_timex(utp, &txc);
62944 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
62945 oldfs = get_fs();
62946 set_fs(KERNEL_DS);
62947 err = sys_clock_getres(which_clock,
62948 - (struct timespec __user *) &ts);
62949 + (struct timespec __force_user *) &ts);
62950 set_fs(oldfs);
62951 if (!err && tp && put_compat_timespec(&ts, tp))
62952 return -EFAULT;
62953 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
62954 long err;
62955 mm_segment_t oldfs;
62956 struct timespec tu;
62957 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
62958 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
62959
62960 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
62961 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
62962 oldfs = get_fs();
62963 set_fs(KERNEL_DS);
62964 err = clock_nanosleep_restart(restart);
62965 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
62966 oldfs = get_fs();
62967 set_fs(KERNEL_DS);
62968 err = sys_clock_nanosleep(which_clock, flags,
62969 - (struct timespec __user *) &in,
62970 - (struct timespec __user *) &out);
62971 + (struct timespec __force_user *) &in,
62972 + (struct timespec __force_user *) &out);
62973 set_fs(oldfs);
62974
62975 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
62976 diff --git a/kernel/configs.c b/kernel/configs.c
62977 index 42e8fa0..9e7406b 100644
62978 --- a/kernel/configs.c
62979 +++ b/kernel/configs.c
62980 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
62981 struct proc_dir_entry *entry;
62982
62983 /* create the current config file */
62984 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
62985 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
62986 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
62987 + &ikconfig_file_ops);
62988 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62989 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
62990 + &ikconfig_file_ops);
62991 +#endif
62992 +#else
62993 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
62994 &ikconfig_file_ops);
62995 +#endif
62996 +
62997 if (!entry)
62998 return -ENOMEM;
62999
63000 diff --git a/kernel/cred.c b/kernel/cred.c
63001 index 5791612..a3c04dc 100644
63002 --- a/kernel/cred.c
63003 +++ b/kernel/cred.c
63004 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
63005 validate_creds(cred);
63006 put_cred(cred);
63007 }
63008 +
63009 +#ifdef CONFIG_GRKERNSEC_SETXID
63010 + cred = (struct cred *) tsk->delayed_cred;
63011 + if (cred) {
63012 + tsk->delayed_cred = NULL;
63013 + validate_creds(cred);
63014 + put_cred(cred);
63015 + }
63016 +#endif
63017 }
63018
63019 /**
63020 @@ -470,7 +479,7 @@ error_put:
63021 * Always returns 0 thus allowing this function to be tail-called at the end
63022 * of, say, sys_setgid().
63023 */
63024 -int commit_creds(struct cred *new)
63025 +static int __commit_creds(struct cred *new)
63026 {
63027 struct task_struct *task = current;
63028 const struct cred *old = task->real_cred;
63029 @@ -489,6 +498,8 @@ int commit_creds(struct cred *new)
63030
63031 get_cred(new); /* we will require a ref for the subj creds too */
63032
63033 + gr_set_role_label(task, new->uid, new->gid);
63034 +
63035 /* dumpability changes */
63036 if (old->euid != new->euid ||
63037 old->egid != new->egid ||
63038 @@ -538,6 +549,92 @@ int commit_creds(struct cred *new)
63039 put_cred(old);
63040 return 0;
63041 }
63042 +#ifdef CONFIG_GRKERNSEC_SETXID
63043 +extern int set_user(struct cred *new);
63044 +
63045 +void gr_delayed_cred_worker(void)
63046 +{
63047 + const struct cred *new = current->delayed_cred;
63048 + struct cred *ncred;
63049 +
63050 + current->delayed_cred = NULL;
63051 +
63052 + if (current_uid() && new != NULL) {
63053 + // from doing get_cred on it when queueing this
63054 + put_cred(new);
63055 + return;
63056 + } else if (new == NULL)
63057 + return;
63058 +
63059 + ncred = prepare_creds();
63060 + if (!ncred)
63061 + goto die;
63062 + // uids
63063 + ncred->uid = new->uid;
63064 + ncred->euid = new->euid;
63065 + ncred->suid = new->suid;
63066 + ncred->fsuid = new->fsuid;
63067 + // gids
63068 + ncred->gid = new->gid;
63069 + ncred->egid = new->egid;
63070 + ncred->sgid = new->sgid;
63071 + ncred->fsgid = new->fsgid;
63072 + // groups
63073 + if (set_groups(ncred, new->group_info) < 0) {
63074 + abort_creds(ncred);
63075 + goto die;
63076 + }
63077 + // caps
63078 + ncred->securebits = new->securebits;
63079 + ncred->cap_inheritable = new->cap_inheritable;
63080 + ncred->cap_permitted = new->cap_permitted;
63081 + ncred->cap_effective = new->cap_effective;
63082 + ncred->cap_bset = new->cap_bset;
63083 +
63084 + if (set_user(ncred)) {
63085 + abort_creds(ncred);
63086 + goto die;
63087 + }
63088 +
63089 + // from doing get_cred on it when queueing this
63090 + put_cred(new);
63091 +
63092 + __commit_creds(ncred);
63093 + return;
63094 +die:
63095 + // from doing get_cred on it when queueing this
63096 + put_cred(new);
63097 + do_group_exit(SIGKILL);
63098 +}
63099 +#endif
63100 +
63101 +int commit_creds(struct cred *new)
63102 +{
63103 +#ifdef CONFIG_GRKERNSEC_SETXID
63104 + struct task_struct *t;
63105 +
63106 + /* we won't get called with tasklist_lock held for writing
63107 + and interrupts disabled as the cred struct in that case is
63108 + init_cred
63109 + */
63110 + if (grsec_enable_setxid && !current_is_single_threaded() &&
63111 + !current_uid() && new->uid) {
63112 + rcu_read_lock();
63113 + read_lock(&tasklist_lock);
63114 + for (t = next_thread(current); t != current;
63115 + t = next_thread(t)) {
63116 + if (t->delayed_cred == NULL) {
63117 + t->delayed_cred = get_cred(new);
63118 + set_tsk_need_resched(t);
63119 + }
63120 + }
63121 + read_unlock(&tasklist_lock);
63122 + rcu_read_unlock();
63123 + }
63124 +#endif
63125 + return __commit_creds(new);
63126 +}
63127 +
63128 EXPORT_SYMBOL(commit_creds);
63129
63130 /**
63131 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
63132 index 0d7c087..01b8cef 100644
63133 --- a/kernel/debug/debug_core.c
63134 +++ b/kernel/debug/debug_core.c
63135 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
63136 */
63137 static atomic_t masters_in_kgdb;
63138 static atomic_t slaves_in_kgdb;
63139 -static atomic_t kgdb_break_tasklet_var;
63140 +static atomic_unchecked_t kgdb_break_tasklet_var;
63141 atomic_t kgdb_setting_breakpoint;
63142
63143 struct task_struct *kgdb_usethread;
63144 @@ -129,7 +129,7 @@ int kgdb_single_step;
63145 static pid_t kgdb_sstep_pid;
63146
63147 /* to keep track of the CPU which is doing the single stepping*/
63148 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63149 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63150
63151 /*
63152 * If you are debugging a problem where roundup (the collection of
63153 @@ -542,7 +542,7 @@ return_normal:
63154 * kernel will only try for the value of sstep_tries before
63155 * giving up and continuing on.
63156 */
63157 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
63158 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
63159 (kgdb_info[cpu].task &&
63160 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
63161 atomic_set(&kgdb_active, -1);
63162 @@ -636,8 +636,8 @@ cpu_master_loop:
63163 }
63164
63165 kgdb_restore:
63166 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
63167 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
63168 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
63169 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
63170 if (kgdb_info[sstep_cpu].task)
63171 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
63172 else
63173 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
63174 static void kgdb_tasklet_bpt(unsigned long ing)
63175 {
63176 kgdb_breakpoint();
63177 - atomic_set(&kgdb_break_tasklet_var, 0);
63178 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
63179 }
63180
63181 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
63182
63183 void kgdb_schedule_breakpoint(void)
63184 {
63185 - if (atomic_read(&kgdb_break_tasklet_var) ||
63186 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
63187 atomic_read(&kgdb_active) != -1 ||
63188 atomic_read(&kgdb_setting_breakpoint))
63189 return;
63190 - atomic_inc(&kgdb_break_tasklet_var);
63191 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
63192 tasklet_schedule(&kgdb_tasklet_breakpoint);
63193 }
63194 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
63195 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
63196 index 63786e7..0780cac 100644
63197 --- a/kernel/debug/kdb/kdb_main.c
63198 +++ b/kernel/debug/kdb/kdb_main.c
63199 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
63200 list_for_each_entry(mod, kdb_modules, list) {
63201
63202 kdb_printf("%-20s%8u 0x%p ", mod->name,
63203 - mod->core_size, (void *)mod);
63204 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
63205 #ifdef CONFIG_MODULE_UNLOAD
63206 kdb_printf("%4d ", module_refcount(mod));
63207 #endif
63208 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
63209 kdb_printf(" (Loading)");
63210 else
63211 kdb_printf(" (Live)");
63212 - kdb_printf(" 0x%p", mod->module_core);
63213 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
63214
63215 #ifdef CONFIG_MODULE_UNLOAD
63216 {
63217 diff --git a/kernel/events/core.c b/kernel/events/core.c
63218 index 58690af..d903d75 100644
63219 --- a/kernel/events/core.c
63220 +++ b/kernel/events/core.c
63221 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
63222 return 0;
63223 }
63224
63225 -static atomic64_t perf_event_id;
63226 +static atomic64_unchecked_t perf_event_id;
63227
63228 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
63229 enum event_type_t event_type);
63230 @@ -2540,7 +2540,7 @@ static void __perf_event_read(void *info)
63231
63232 static inline u64 perf_event_count(struct perf_event *event)
63233 {
63234 - return local64_read(&event->count) + atomic64_read(&event->child_count);
63235 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
63236 }
63237
63238 static u64 perf_event_read(struct perf_event *event)
63239 @@ -3065,9 +3065,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
63240 mutex_lock(&event->child_mutex);
63241 total += perf_event_read(event);
63242 *enabled += event->total_time_enabled +
63243 - atomic64_read(&event->child_total_time_enabled);
63244 + atomic64_read_unchecked(&event->child_total_time_enabled);
63245 *running += event->total_time_running +
63246 - atomic64_read(&event->child_total_time_running);
63247 + atomic64_read_unchecked(&event->child_total_time_running);
63248
63249 list_for_each_entry(child, &event->child_list, child_list) {
63250 total += perf_event_read(child);
63251 @@ -3474,10 +3474,10 @@ void perf_event_update_userpage(struct perf_event *event)
63252 userpg->offset -= local64_read(&event->hw.prev_count);
63253
63254 userpg->time_enabled = enabled +
63255 - atomic64_read(&event->child_total_time_enabled);
63256 + atomic64_read_unchecked(&event->child_total_time_enabled);
63257
63258 userpg->time_running = running +
63259 - atomic64_read(&event->child_total_time_running);
63260 + atomic64_read_unchecked(&event->child_total_time_running);
63261
63262 barrier();
63263 ++userpg->lock;
63264 @@ -3906,11 +3906,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
63265 values[n++] = perf_event_count(event);
63266 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
63267 values[n++] = enabled +
63268 - atomic64_read(&event->child_total_time_enabled);
63269 + atomic64_read_unchecked(&event->child_total_time_enabled);
63270 }
63271 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
63272 values[n++] = running +
63273 - atomic64_read(&event->child_total_time_running);
63274 + atomic64_read_unchecked(&event->child_total_time_running);
63275 }
63276 if (read_format & PERF_FORMAT_ID)
63277 values[n++] = primary_event_id(event);
63278 @@ -4561,12 +4561,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
63279 * need to add enough zero bytes after the string to handle
63280 * the 64bit alignment we do later.
63281 */
63282 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
63283 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
63284 if (!buf) {
63285 name = strncpy(tmp, "//enomem", sizeof(tmp));
63286 goto got_name;
63287 }
63288 - name = d_path(&file->f_path, buf, PATH_MAX);
63289 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
63290 if (IS_ERR(name)) {
63291 name = strncpy(tmp, "//toolong", sizeof(tmp));
63292 goto got_name;
63293 @@ -5921,7 +5921,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
63294 event->parent = parent_event;
63295
63296 event->ns = get_pid_ns(current->nsproxy->pid_ns);
63297 - event->id = atomic64_inc_return(&perf_event_id);
63298 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
63299
63300 event->state = PERF_EVENT_STATE_INACTIVE;
63301
63302 @@ -6443,10 +6443,10 @@ static void sync_child_event(struct perf_event *child_event,
63303 /*
63304 * Add back the child's count to the parent's count:
63305 */
63306 - atomic64_add(child_val, &parent_event->child_count);
63307 - atomic64_add(child_event->total_time_enabled,
63308 + atomic64_add_unchecked(child_val, &parent_event->child_count);
63309 + atomic64_add_unchecked(child_event->total_time_enabled,
63310 &parent_event->child_total_time_enabled);
63311 - atomic64_add(child_event->total_time_running,
63312 + atomic64_add_unchecked(child_event->total_time_running,
63313 &parent_event->child_total_time_running);
63314
63315 /*
63316 diff --git a/kernel/exit.c b/kernel/exit.c
63317 index e6e01b9..619f837 100644
63318 --- a/kernel/exit.c
63319 +++ b/kernel/exit.c
63320 @@ -57,6 +57,10 @@
63321 #include <asm/pgtable.h>
63322 #include <asm/mmu_context.h>
63323
63324 +#ifdef CONFIG_GRKERNSEC
63325 +extern rwlock_t grsec_exec_file_lock;
63326 +#endif
63327 +
63328 static void exit_mm(struct task_struct * tsk);
63329
63330 static void __unhash_process(struct task_struct *p, bool group_dead)
63331 @@ -168,6 +172,10 @@ void release_task(struct task_struct * p)
63332 struct task_struct *leader;
63333 int zap_leader;
63334 repeat:
63335 +#ifdef CONFIG_NET
63336 + gr_del_task_from_ip_table(p);
63337 +#endif
63338 +
63339 /* don't need to get the RCU readlock here - the process is dead and
63340 * can't be modifying its own credentials. But shut RCU-lockdep up */
63341 rcu_read_lock();
63342 @@ -380,7 +388,7 @@ int allow_signal(int sig)
63343 * know it'll be handled, so that they don't get converted to
63344 * SIGKILL or just silently dropped.
63345 */
63346 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
63347 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
63348 recalc_sigpending();
63349 spin_unlock_irq(&current->sighand->siglock);
63350 return 0;
63351 @@ -416,6 +424,17 @@ void daemonize(const char *name, ...)
63352 vsnprintf(current->comm, sizeof(current->comm), name, args);
63353 va_end(args);
63354
63355 +#ifdef CONFIG_GRKERNSEC
63356 + write_lock(&grsec_exec_file_lock);
63357 + if (current->exec_file) {
63358 + fput(current->exec_file);
63359 + current->exec_file = NULL;
63360 + }
63361 + write_unlock(&grsec_exec_file_lock);
63362 +#endif
63363 +
63364 + gr_set_kernel_label(current);
63365 +
63366 /*
63367 * If we were started as result of loading a module, close all of the
63368 * user space pages. We don't need them, and if we didn't close them
63369 @@ -893,6 +912,8 @@ NORET_TYPE void do_exit(long code)
63370 struct task_struct *tsk = current;
63371 int group_dead;
63372
63373 + set_fs(USER_DS);
63374 +
63375 profile_task_exit(tsk);
63376
63377 WARN_ON(blk_needs_flush_plug(tsk));
63378 @@ -909,7 +930,6 @@ NORET_TYPE void do_exit(long code)
63379 * mm_release()->clear_child_tid() from writing to a user-controlled
63380 * kernel address.
63381 */
63382 - set_fs(USER_DS);
63383
63384 ptrace_event(PTRACE_EVENT_EXIT, code);
63385
63386 @@ -971,6 +991,9 @@ NORET_TYPE void do_exit(long code)
63387 tsk->exit_code = code;
63388 taskstats_exit(tsk, group_dead);
63389
63390 + gr_acl_handle_psacct(tsk, code);
63391 + gr_acl_handle_exit();
63392 +
63393 exit_mm(tsk);
63394
63395 if (group_dead)
63396 diff --git a/kernel/fork.c b/kernel/fork.c
63397 index da4a6a1..0483b61 100644
63398 --- a/kernel/fork.c
63399 +++ b/kernel/fork.c
63400 @@ -280,7 +280,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
63401 *stackend = STACK_END_MAGIC; /* for overflow detection */
63402
63403 #ifdef CONFIG_CC_STACKPROTECTOR
63404 - tsk->stack_canary = get_random_int();
63405 + tsk->stack_canary = pax_get_random_long();
63406 #endif
63407
63408 /*
63409 @@ -304,13 +304,77 @@ out:
63410 }
63411
63412 #ifdef CONFIG_MMU
63413 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
63414 +{
63415 + struct vm_area_struct *tmp;
63416 + unsigned long charge;
63417 + struct mempolicy *pol;
63418 + struct file *file;
63419 +
63420 + charge = 0;
63421 + if (mpnt->vm_flags & VM_ACCOUNT) {
63422 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
63423 + if (security_vm_enough_memory(len))
63424 + goto fail_nomem;
63425 + charge = len;
63426 + }
63427 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
63428 + if (!tmp)
63429 + goto fail_nomem;
63430 + *tmp = *mpnt;
63431 + tmp->vm_mm = mm;
63432 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
63433 + pol = mpol_dup(vma_policy(mpnt));
63434 + if (IS_ERR(pol))
63435 + goto fail_nomem_policy;
63436 + vma_set_policy(tmp, pol);
63437 + if (anon_vma_fork(tmp, mpnt))
63438 + goto fail_nomem_anon_vma_fork;
63439 + tmp->vm_flags &= ~VM_LOCKED;
63440 + tmp->vm_next = tmp->vm_prev = NULL;
63441 + tmp->vm_mirror = NULL;
63442 + file = tmp->vm_file;
63443 + if (file) {
63444 + struct inode *inode = file->f_path.dentry->d_inode;
63445 + struct address_space *mapping = file->f_mapping;
63446 +
63447 + get_file(file);
63448 + if (tmp->vm_flags & VM_DENYWRITE)
63449 + atomic_dec(&inode->i_writecount);
63450 + mutex_lock(&mapping->i_mmap_mutex);
63451 + if (tmp->vm_flags & VM_SHARED)
63452 + mapping->i_mmap_writable++;
63453 + flush_dcache_mmap_lock(mapping);
63454 + /* insert tmp into the share list, just after mpnt */
63455 + vma_prio_tree_add(tmp, mpnt);
63456 + flush_dcache_mmap_unlock(mapping);
63457 + mutex_unlock(&mapping->i_mmap_mutex);
63458 + }
63459 +
63460 + /*
63461 + * Clear hugetlb-related page reserves for children. This only
63462 + * affects MAP_PRIVATE mappings. Faults generated by the child
63463 + * are not guaranteed to succeed, even if read-only
63464 + */
63465 + if (is_vm_hugetlb_page(tmp))
63466 + reset_vma_resv_huge_pages(tmp);
63467 +
63468 + return tmp;
63469 +
63470 +fail_nomem_anon_vma_fork:
63471 + mpol_put(pol);
63472 +fail_nomem_policy:
63473 + kmem_cache_free(vm_area_cachep, tmp);
63474 +fail_nomem:
63475 + vm_unacct_memory(charge);
63476 + return NULL;
63477 +}
63478 +
63479 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63480 {
63481 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
63482 struct rb_node **rb_link, *rb_parent;
63483 int retval;
63484 - unsigned long charge;
63485 - struct mempolicy *pol;
63486
63487 down_write(&oldmm->mmap_sem);
63488 flush_cache_dup_mm(oldmm);
63489 @@ -322,8 +386,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63490 mm->locked_vm = 0;
63491 mm->mmap = NULL;
63492 mm->mmap_cache = NULL;
63493 - mm->free_area_cache = oldmm->mmap_base;
63494 - mm->cached_hole_size = ~0UL;
63495 + mm->free_area_cache = oldmm->free_area_cache;
63496 + mm->cached_hole_size = oldmm->cached_hole_size;
63497 mm->map_count = 0;
63498 cpumask_clear(mm_cpumask(mm));
63499 mm->mm_rb = RB_ROOT;
63500 @@ -339,8 +403,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63501
63502 prev = NULL;
63503 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
63504 - struct file *file;
63505 -
63506 if (mpnt->vm_flags & VM_DONTCOPY) {
63507 long pages = vma_pages(mpnt);
63508 mm->total_vm -= pages;
63509 @@ -348,53 +410,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63510 -pages);
63511 continue;
63512 }
63513 - charge = 0;
63514 - if (mpnt->vm_flags & VM_ACCOUNT) {
63515 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
63516 - if (security_vm_enough_memory(len))
63517 - goto fail_nomem;
63518 - charge = len;
63519 + tmp = dup_vma(mm, mpnt);
63520 + if (!tmp) {
63521 + retval = -ENOMEM;
63522 + goto out;
63523 }
63524 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
63525 - if (!tmp)
63526 - goto fail_nomem;
63527 - *tmp = *mpnt;
63528 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
63529 - pol = mpol_dup(vma_policy(mpnt));
63530 - retval = PTR_ERR(pol);
63531 - if (IS_ERR(pol))
63532 - goto fail_nomem_policy;
63533 - vma_set_policy(tmp, pol);
63534 - tmp->vm_mm = mm;
63535 - if (anon_vma_fork(tmp, mpnt))
63536 - goto fail_nomem_anon_vma_fork;
63537 - tmp->vm_flags &= ~VM_LOCKED;
63538 - tmp->vm_next = tmp->vm_prev = NULL;
63539 - file = tmp->vm_file;
63540 - if (file) {
63541 - struct inode *inode = file->f_path.dentry->d_inode;
63542 - struct address_space *mapping = file->f_mapping;
63543 -
63544 - get_file(file);
63545 - if (tmp->vm_flags & VM_DENYWRITE)
63546 - atomic_dec(&inode->i_writecount);
63547 - mutex_lock(&mapping->i_mmap_mutex);
63548 - if (tmp->vm_flags & VM_SHARED)
63549 - mapping->i_mmap_writable++;
63550 - flush_dcache_mmap_lock(mapping);
63551 - /* insert tmp into the share list, just after mpnt */
63552 - vma_prio_tree_add(tmp, mpnt);
63553 - flush_dcache_mmap_unlock(mapping);
63554 - mutex_unlock(&mapping->i_mmap_mutex);
63555 - }
63556 -
63557 - /*
63558 - * Clear hugetlb-related page reserves for children. This only
63559 - * affects MAP_PRIVATE mappings. Faults generated by the child
63560 - * are not guaranteed to succeed, even if read-only
63561 - */
63562 - if (is_vm_hugetlb_page(tmp))
63563 - reset_vma_resv_huge_pages(tmp);
63564
63565 /*
63566 * Link in the new vma and copy the page table entries.
63567 @@ -417,6 +437,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63568 if (retval)
63569 goto out;
63570 }
63571 +
63572 +#ifdef CONFIG_PAX_SEGMEXEC
63573 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
63574 + struct vm_area_struct *mpnt_m;
63575 +
63576 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
63577 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
63578 +
63579 + if (!mpnt->vm_mirror)
63580 + continue;
63581 +
63582 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
63583 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
63584 + mpnt->vm_mirror = mpnt_m;
63585 + } else {
63586 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
63587 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
63588 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
63589 + mpnt->vm_mirror->vm_mirror = mpnt;
63590 + }
63591 + }
63592 + BUG_ON(mpnt_m);
63593 + }
63594 +#endif
63595 +
63596 /* a new mm has just been created */
63597 arch_dup_mmap(oldmm, mm);
63598 retval = 0;
63599 @@ -425,14 +470,6 @@ out:
63600 flush_tlb_mm(oldmm);
63601 up_write(&oldmm->mmap_sem);
63602 return retval;
63603 -fail_nomem_anon_vma_fork:
63604 - mpol_put(pol);
63605 -fail_nomem_policy:
63606 - kmem_cache_free(vm_area_cachep, tmp);
63607 -fail_nomem:
63608 - retval = -ENOMEM;
63609 - vm_unacct_memory(charge);
63610 - goto out;
63611 }
63612
63613 static inline int mm_alloc_pgd(struct mm_struct *mm)
63614 @@ -644,6 +681,26 @@ struct mm_struct *get_task_mm(struct task_struct *task)
63615 }
63616 EXPORT_SYMBOL_GPL(get_task_mm);
63617
63618 +struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
63619 +{
63620 + struct mm_struct *mm;
63621 + int err;
63622 +
63623 + err = mutex_lock_killable(&task->signal->cred_guard_mutex);
63624 + if (err)
63625 + return ERR_PTR(err);
63626 +
63627 + mm = get_task_mm(task);
63628 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
63629 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
63630 + mmput(mm);
63631 + mm = ERR_PTR(-EACCES);
63632 + }
63633 + mutex_unlock(&task->signal->cred_guard_mutex);
63634 +
63635 + return mm;
63636 +}
63637 +
63638 /* Please note the differences between mmput and mm_release.
63639 * mmput is called whenever we stop holding onto a mm_struct,
63640 * error success whatever.
63641 @@ -829,13 +886,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
63642 spin_unlock(&fs->lock);
63643 return -EAGAIN;
63644 }
63645 - fs->users++;
63646 + atomic_inc(&fs->users);
63647 spin_unlock(&fs->lock);
63648 return 0;
63649 }
63650 tsk->fs = copy_fs_struct(fs);
63651 if (!tsk->fs)
63652 return -ENOMEM;
63653 + gr_set_chroot_entries(tsk, &tsk->fs->root);
63654 return 0;
63655 }
63656
63657 @@ -1097,6 +1155,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
63658 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
63659 #endif
63660 retval = -EAGAIN;
63661 +
63662 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
63663 +
63664 if (atomic_read(&p->real_cred->user->processes) >=
63665 task_rlimit(p, RLIMIT_NPROC)) {
63666 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
63667 @@ -1256,6 +1317,12 @@ static struct task_struct *copy_process(unsigned long clone_flags,
63668 if (clone_flags & CLONE_THREAD)
63669 p->tgid = current->tgid;
63670
63671 + gr_copy_label(p);
63672 +
63673 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63674 + p->exec_id = current->exec_id;
63675 +#endif
63676 +
63677 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
63678 /*
63679 * Clear TID on mm_release()?
63680 @@ -1418,6 +1485,8 @@ bad_fork_cleanup_count:
63681 bad_fork_free:
63682 free_task(p);
63683 fork_out:
63684 + gr_log_forkfail(retval);
63685 +
63686 return ERR_PTR(retval);
63687 }
63688
63689 @@ -1518,6 +1587,8 @@ long do_fork(unsigned long clone_flags,
63690 if (clone_flags & CLONE_PARENT_SETTID)
63691 put_user(nr, parent_tidptr);
63692
63693 + gr_handle_brute_check();
63694 +
63695 if (clone_flags & CLONE_VFORK) {
63696 p->vfork_done = &vfork;
63697 init_completion(&vfork);
63698 @@ -1627,7 +1698,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
63699 return 0;
63700
63701 /* don't need lock here; in the worst case we'll do useless copy */
63702 - if (fs->users == 1)
63703 + if (atomic_read(&fs->users) == 1)
63704 return 0;
63705
63706 *new_fsp = copy_fs_struct(fs);
63707 @@ -1716,7 +1787,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
63708 fs = current->fs;
63709 spin_lock(&fs->lock);
63710 current->fs = new_fs;
63711 - if (--fs->users)
63712 + gr_set_chroot_entries(current, &current->fs->root);
63713 + if (atomic_dec_return(&fs->users))
63714 new_fs = NULL;
63715 else
63716 new_fs = fs;
63717 diff --git a/kernel/futex.c b/kernel/futex.c
63718 index 1614be2..37abc7e 100644
63719 --- a/kernel/futex.c
63720 +++ b/kernel/futex.c
63721 @@ -54,6 +54,7 @@
63722 #include <linux/mount.h>
63723 #include <linux/pagemap.h>
63724 #include <linux/syscalls.h>
63725 +#include <linux/ptrace.h>
63726 #include <linux/signal.h>
63727 #include <linux/export.h>
63728 #include <linux/magic.h>
63729 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
63730 struct page *page, *page_head;
63731 int err, ro = 0;
63732
63733 +#ifdef CONFIG_PAX_SEGMEXEC
63734 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
63735 + return -EFAULT;
63736 +#endif
63737 +
63738 /*
63739 * The futex address must be "naturally" aligned.
63740 */
63741 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
63742 if (!p)
63743 goto err_unlock;
63744 ret = -EPERM;
63745 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63746 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
63747 + goto err_unlock;
63748 +#endif
63749 pcred = __task_cred(p);
63750 /* If victim is in different user_ns, then uids are not
63751 comparable, so we must have CAP_SYS_PTRACE */
63752 @@ -2724,6 +2734,7 @@ static int __init futex_init(void)
63753 {
63754 u32 curval;
63755 int i;
63756 + mm_segment_t oldfs;
63757
63758 /*
63759 * This will fail and we want it. Some arch implementations do
63760 @@ -2735,8 +2746,11 @@ static int __init futex_init(void)
63761 * implementation, the non-functional ones will return
63762 * -ENOSYS.
63763 */
63764 + oldfs = get_fs();
63765 + set_fs(USER_DS);
63766 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
63767 futex_cmpxchg_enabled = 1;
63768 + set_fs(oldfs);
63769
63770 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
63771 plist_head_init(&futex_queues[i].chain);
63772 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
63773 index 5f9e689..582d46d 100644
63774 --- a/kernel/futex_compat.c
63775 +++ b/kernel/futex_compat.c
63776 @@ -10,6 +10,7 @@
63777 #include <linux/compat.h>
63778 #include <linux/nsproxy.h>
63779 #include <linux/futex.h>
63780 +#include <linux/ptrace.h>
63781
63782 #include <asm/uaccess.h>
63783
63784 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
63785 {
63786 struct compat_robust_list_head __user *head;
63787 unsigned long ret;
63788 - const struct cred *cred = current_cred(), *pcred;
63789 + const struct cred *cred = current_cred();
63790 + const struct cred *pcred;
63791
63792 if (!futex_cmpxchg_enabled)
63793 return -ENOSYS;
63794 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
63795 if (!p)
63796 goto err_unlock;
63797 ret = -EPERM;
63798 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63799 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
63800 + goto err_unlock;
63801 +#endif
63802 pcred = __task_cred(p);
63803 /* If victim is in different user_ns, then uids are not
63804 comparable, so we must have CAP_SYS_PTRACE */
63805 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
63806 index 9b22d03..6295b62 100644
63807 --- a/kernel/gcov/base.c
63808 +++ b/kernel/gcov/base.c
63809 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
63810 }
63811
63812 #ifdef CONFIG_MODULES
63813 -static inline int within(void *addr, void *start, unsigned long size)
63814 -{
63815 - return ((addr >= start) && (addr < start + size));
63816 -}
63817 -
63818 /* Update list and generate events when modules are unloaded. */
63819 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
63820 void *data)
63821 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
63822 prev = NULL;
63823 /* Remove entries located in module from linked list. */
63824 for (info = gcov_info_head; info; info = info->next) {
63825 - if (within(info, mod->module_core, mod->core_size)) {
63826 + if (within_module_core_rw((unsigned long)info, mod)) {
63827 if (prev)
63828 prev->next = info->next;
63829 else
63830 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
63831 index ae34bf5..4e2f3d0 100644
63832 --- a/kernel/hrtimer.c
63833 +++ b/kernel/hrtimer.c
63834 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
63835 local_irq_restore(flags);
63836 }
63837
63838 -static void run_hrtimer_softirq(struct softirq_action *h)
63839 +static void run_hrtimer_softirq(void)
63840 {
63841 hrtimer_peek_ahead_timers();
63842 }
63843 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
63844 index 66ff710..05a5128 100644
63845 --- a/kernel/jump_label.c
63846 +++ b/kernel/jump_label.c
63847 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
63848
63849 size = (((unsigned long)stop - (unsigned long)start)
63850 / sizeof(struct jump_entry));
63851 + pax_open_kernel();
63852 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
63853 + pax_close_kernel();
63854 }
63855
63856 static void jump_label_update(struct jump_label_key *key, int enable);
63857 @@ -303,10 +305,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
63858 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
63859 struct jump_entry *iter;
63860
63861 + pax_open_kernel();
63862 for (iter = iter_start; iter < iter_stop; iter++) {
63863 if (within_module_init(iter->code, mod))
63864 iter->code = 0;
63865 }
63866 + pax_close_kernel();
63867 }
63868
63869 static int
63870 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
63871 index 079f1d3..a407562 100644
63872 --- a/kernel/kallsyms.c
63873 +++ b/kernel/kallsyms.c
63874 @@ -11,6 +11,9 @@
63875 * Changed the compression method from stem compression to "table lookup"
63876 * compression (see scripts/kallsyms.c for a more complete description)
63877 */
63878 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63879 +#define __INCLUDED_BY_HIDESYM 1
63880 +#endif
63881 #include <linux/kallsyms.h>
63882 #include <linux/module.h>
63883 #include <linux/init.h>
63884 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
63885
63886 static inline int is_kernel_inittext(unsigned long addr)
63887 {
63888 + if (system_state != SYSTEM_BOOTING)
63889 + return 0;
63890 +
63891 if (addr >= (unsigned long)_sinittext
63892 && addr <= (unsigned long)_einittext)
63893 return 1;
63894 return 0;
63895 }
63896
63897 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63898 +#ifdef CONFIG_MODULES
63899 +static inline int is_module_text(unsigned long addr)
63900 +{
63901 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
63902 + return 1;
63903 +
63904 + addr = ktla_ktva(addr);
63905 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
63906 +}
63907 +#else
63908 +static inline int is_module_text(unsigned long addr)
63909 +{
63910 + return 0;
63911 +}
63912 +#endif
63913 +#endif
63914 +
63915 static inline int is_kernel_text(unsigned long addr)
63916 {
63917 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
63918 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
63919
63920 static inline int is_kernel(unsigned long addr)
63921 {
63922 +
63923 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63924 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
63925 + return 1;
63926 +
63927 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
63928 +#else
63929 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
63930 +#endif
63931 +
63932 return 1;
63933 return in_gate_area_no_mm(addr);
63934 }
63935
63936 static int is_ksym_addr(unsigned long addr)
63937 {
63938 +
63939 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63940 + if (is_module_text(addr))
63941 + return 0;
63942 +#endif
63943 +
63944 if (all_var)
63945 return is_kernel(addr);
63946
63947 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
63948
63949 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
63950 {
63951 - iter->name[0] = '\0';
63952 iter->nameoff = get_symbol_offset(new_pos);
63953 iter->pos = new_pos;
63954 }
63955 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
63956 {
63957 struct kallsym_iter *iter = m->private;
63958
63959 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63960 + if (current_uid())
63961 + return 0;
63962 +#endif
63963 +
63964 /* Some debugging symbols have no name. Ignore them. */
63965 if (!iter->name[0])
63966 return 0;
63967 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
63968 struct kallsym_iter *iter;
63969 int ret;
63970
63971 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
63972 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
63973 if (!iter)
63974 return -ENOMEM;
63975 reset_iter(iter, 0);
63976 diff --git a/kernel/kexec.c b/kernel/kexec.c
63977 index dc7bc08..4601964 100644
63978 --- a/kernel/kexec.c
63979 +++ b/kernel/kexec.c
63980 @@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
63981 unsigned long flags)
63982 {
63983 struct compat_kexec_segment in;
63984 - struct kexec_segment out, __user *ksegments;
63985 + struct kexec_segment out;
63986 + struct kexec_segment __user *ksegments;
63987 unsigned long i, result;
63988
63989 /* Don't allow clients that don't understand the native
63990 diff --git a/kernel/kmod.c b/kernel/kmod.c
63991 index a4bea97..7a1ae9a 100644
63992 --- a/kernel/kmod.c
63993 +++ b/kernel/kmod.c
63994 @@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
63995 * If module auto-loading support is disabled then this function
63996 * becomes a no-operation.
63997 */
63998 -int __request_module(bool wait, const char *fmt, ...)
63999 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
64000 {
64001 - va_list args;
64002 char module_name[MODULE_NAME_LEN];
64003 unsigned int max_modprobes;
64004 int ret;
64005 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
64006 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
64007 static char *envp[] = { "HOME=/",
64008 "TERM=linux",
64009 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
64010 @@ -88,9 +87,7 @@ int __request_module(bool wait, const char *fmt, ...)
64011 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
64012 static int kmod_loop_msg;
64013
64014 - va_start(args, fmt);
64015 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
64016 - va_end(args);
64017 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
64018 if (ret >= MODULE_NAME_LEN)
64019 return -ENAMETOOLONG;
64020
64021 @@ -98,6 +95,20 @@ int __request_module(bool wait, const char *fmt, ...)
64022 if (ret)
64023 return ret;
64024
64025 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64026 + if (!current_uid()) {
64027 + /* hack to workaround consolekit/udisks stupidity */
64028 + read_lock(&tasklist_lock);
64029 + if (!strcmp(current->comm, "mount") &&
64030 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
64031 + read_unlock(&tasklist_lock);
64032 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
64033 + return -EPERM;
64034 + }
64035 + read_unlock(&tasklist_lock);
64036 + }
64037 +#endif
64038 +
64039 /* If modprobe needs a service that is in a module, we get a recursive
64040 * loop. Limit the number of running kmod threads to max_threads/2 or
64041 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
64042 @@ -133,6 +144,47 @@ int __request_module(bool wait, const char *fmt, ...)
64043 atomic_dec(&kmod_concurrent);
64044 return ret;
64045 }
64046 +
64047 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
64048 +{
64049 + va_list args;
64050 + int ret;
64051 +
64052 + va_start(args, fmt);
64053 + ret = ____request_module(wait, module_param, fmt, args);
64054 + va_end(args);
64055 +
64056 + return ret;
64057 +}
64058 +
64059 +int __request_module(bool wait, const char *fmt, ...)
64060 +{
64061 + va_list args;
64062 + int ret;
64063 +
64064 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64065 + if (current_uid()) {
64066 + char module_param[MODULE_NAME_LEN];
64067 +
64068 + memset(module_param, 0, sizeof(module_param));
64069 +
64070 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
64071 +
64072 + va_start(args, fmt);
64073 + ret = ____request_module(wait, module_param, fmt, args);
64074 + va_end(args);
64075 +
64076 + return ret;
64077 + }
64078 +#endif
64079 +
64080 + va_start(args, fmt);
64081 + ret = ____request_module(wait, NULL, fmt, args);
64082 + va_end(args);
64083 +
64084 + return ret;
64085 +}
64086 +
64087 EXPORT_SYMBOL(__request_module);
64088 #endif /* CONFIG_MODULES */
64089
64090 @@ -222,7 +274,7 @@ static int wait_for_helper(void *data)
64091 *
64092 * Thus the __user pointer cast is valid here.
64093 */
64094 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
64095 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
64096
64097 /*
64098 * If ret is 0, either ____call_usermodehelper failed and the
64099 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
64100 index 52fd049..3def6a8 100644
64101 --- a/kernel/kprobes.c
64102 +++ b/kernel/kprobes.c
64103 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
64104 * kernel image and loaded module images reside. This is required
64105 * so x86_64 can correctly handle the %rip-relative fixups.
64106 */
64107 - kip->insns = module_alloc(PAGE_SIZE);
64108 + kip->insns = module_alloc_exec(PAGE_SIZE);
64109 if (!kip->insns) {
64110 kfree(kip);
64111 return NULL;
64112 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
64113 */
64114 if (!list_is_singular(&kip->list)) {
64115 list_del(&kip->list);
64116 - module_free(NULL, kip->insns);
64117 + module_free_exec(NULL, kip->insns);
64118 kfree(kip);
64119 }
64120 return 1;
64121 @@ -1949,7 +1949,7 @@ static int __init init_kprobes(void)
64122 {
64123 int i, err = 0;
64124 unsigned long offset = 0, size = 0;
64125 - char *modname, namebuf[128];
64126 + char *modname, namebuf[KSYM_NAME_LEN];
64127 const char *symbol_name;
64128 void *addr;
64129 struct kprobe_blackpoint *kb;
64130 @@ -2075,7 +2075,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
64131 const char *sym = NULL;
64132 unsigned int i = *(loff_t *) v;
64133 unsigned long offset = 0;
64134 - char *modname, namebuf[128];
64135 + char *modname, namebuf[KSYM_NAME_LEN];
64136
64137 head = &kprobe_table[i];
64138 preempt_disable();
64139 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
64140 index b2e08c9..01d8049 100644
64141 --- a/kernel/lockdep.c
64142 +++ b/kernel/lockdep.c
64143 @@ -592,6 +592,10 @@ static int static_obj(void *obj)
64144 end = (unsigned long) &_end,
64145 addr = (unsigned long) obj;
64146
64147 +#ifdef CONFIG_PAX_KERNEXEC
64148 + start = ktla_ktva(start);
64149 +#endif
64150 +
64151 /*
64152 * static variable?
64153 */
64154 @@ -731,6 +735,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
64155 if (!static_obj(lock->key)) {
64156 debug_locks_off();
64157 printk("INFO: trying to register non-static key.\n");
64158 + printk("lock:%pS key:%pS.\n", lock, lock->key);
64159 printk("the code is fine but needs lockdep annotation.\n");
64160 printk("turning off the locking correctness validator.\n");
64161 dump_stack();
64162 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
64163 if (!class)
64164 return 0;
64165 }
64166 - atomic_inc((atomic_t *)&class->ops);
64167 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
64168 if (very_verbose(class)) {
64169 printk("\nacquire class [%p] %s", class->key, class->name);
64170 if (class->name_version > 1)
64171 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
64172 index 91c32a0..b2c71c5 100644
64173 --- a/kernel/lockdep_proc.c
64174 +++ b/kernel/lockdep_proc.c
64175 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
64176
64177 static void print_name(struct seq_file *m, struct lock_class *class)
64178 {
64179 - char str[128];
64180 + char str[KSYM_NAME_LEN];
64181 const char *name = class->name;
64182
64183 if (!name) {
64184 diff --git a/kernel/module.c b/kernel/module.c
64185 index 178333c..04e3408 100644
64186 --- a/kernel/module.c
64187 +++ b/kernel/module.c
64188 @@ -58,6 +58,7 @@
64189 #include <linux/jump_label.h>
64190 #include <linux/pfn.h>
64191 #include <linux/bsearch.h>
64192 +#include <linux/grsecurity.h>
64193
64194 #define CREATE_TRACE_POINTS
64195 #include <trace/events/module.h>
64196 @@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
64197
64198 /* Bounds of module allocation, for speeding __module_address.
64199 * Protected by module_mutex. */
64200 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
64201 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
64202 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
64203
64204 int register_module_notifier(struct notifier_block * nb)
64205 {
64206 @@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
64207 return true;
64208
64209 list_for_each_entry_rcu(mod, &modules, list) {
64210 - struct symsearch arr[] = {
64211 + struct symsearch modarr[] = {
64212 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
64213 NOT_GPL_ONLY, false },
64214 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
64215 @@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
64216 #endif
64217 };
64218
64219 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
64220 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
64221 return true;
64222 }
64223 return false;
64224 @@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
64225 static int percpu_modalloc(struct module *mod,
64226 unsigned long size, unsigned long align)
64227 {
64228 - if (align > PAGE_SIZE) {
64229 + if (align-1 >= PAGE_SIZE) {
64230 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
64231 mod->name, align, PAGE_SIZE);
64232 align = PAGE_SIZE;
64233 @@ -1183,7 +1185,7 @@ resolve_symbol_wait(struct module *mod,
64234 */
64235 #ifdef CONFIG_SYSFS
64236
64237 -#ifdef CONFIG_KALLSYMS
64238 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64239 static inline bool sect_empty(const Elf_Shdr *sect)
64240 {
64241 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
64242 @@ -1649,21 +1651,21 @@ static void set_section_ro_nx(void *base,
64243
64244 static void unset_module_core_ro_nx(struct module *mod)
64245 {
64246 - set_page_attributes(mod->module_core + mod->core_text_size,
64247 - mod->module_core + mod->core_size,
64248 + set_page_attributes(mod->module_core_rw,
64249 + mod->module_core_rw + mod->core_size_rw,
64250 set_memory_x);
64251 - set_page_attributes(mod->module_core,
64252 - mod->module_core + mod->core_ro_size,
64253 + set_page_attributes(mod->module_core_rx,
64254 + mod->module_core_rx + mod->core_size_rx,
64255 set_memory_rw);
64256 }
64257
64258 static void unset_module_init_ro_nx(struct module *mod)
64259 {
64260 - set_page_attributes(mod->module_init + mod->init_text_size,
64261 - mod->module_init + mod->init_size,
64262 + set_page_attributes(mod->module_init_rw,
64263 + mod->module_init_rw + mod->init_size_rw,
64264 set_memory_x);
64265 - set_page_attributes(mod->module_init,
64266 - mod->module_init + mod->init_ro_size,
64267 + set_page_attributes(mod->module_init_rx,
64268 + mod->module_init_rx + mod->init_size_rx,
64269 set_memory_rw);
64270 }
64271
64272 @@ -1674,14 +1676,14 @@ void set_all_modules_text_rw(void)
64273
64274 mutex_lock(&module_mutex);
64275 list_for_each_entry_rcu(mod, &modules, list) {
64276 - if ((mod->module_core) && (mod->core_text_size)) {
64277 - set_page_attributes(mod->module_core,
64278 - mod->module_core + mod->core_text_size,
64279 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
64280 + set_page_attributes(mod->module_core_rx,
64281 + mod->module_core_rx + mod->core_size_rx,
64282 set_memory_rw);
64283 }
64284 - if ((mod->module_init) && (mod->init_text_size)) {
64285 - set_page_attributes(mod->module_init,
64286 - mod->module_init + mod->init_text_size,
64287 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
64288 + set_page_attributes(mod->module_init_rx,
64289 + mod->module_init_rx + mod->init_size_rx,
64290 set_memory_rw);
64291 }
64292 }
64293 @@ -1695,14 +1697,14 @@ void set_all_modules_text_ro(void)
64294
64295 mutex_lock(&module_mutex);
64296 list_for_each_entry_rcu(mod, &modules, list) {
64297 - if ((mod->module_core) && (mod->core_text_size)) {
64298 - set_page_attributes(mod->module_core,
64299 - mod->module_core + mod->core_text_size,
64300 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
64301 + set_page_attributes(mod->module_core_rx,
64302 + mod->module_core_rx + mod->core_size_rx,
64303 set_memory_ro);
64304 }
64305 - if ((mod->module_init) && (mod->init_text_size)) {
64306 - set_page_attributes(mod->module_init,
64307 - mod->module_init + mod->init_text_size,
64308 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
64309 + set_page_attributes(mod->module_init_rx,
64310 + mod->module_init_rx + mod->init_size_rx,
64311 set_memory_ro);
64312 }
64313 }
64314 @@ -1748,16 +1750,19 @@ static void free_module(struct module *mod)
64315
64316 /* This may be NULL, but that's OK */
64317 unset_module_init_ro_nx(mod);
64318 - module_free(mod, mod->module_init);
64319 + module_free(mod, mod->module_init_rw);
64320 + module_free_exec(mod, mod->module_init_rx);
64321 kfree(mod->args);
64322 percpu_modfree(mod);
64323
64324 /* Free lock-classes: */
64325 - lockdep_free_key_range(mod->module_core, mod->core_size);
64326 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
64327 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
64328
64329 /* Finally, free the core (containing the module structure) */
64330 unset_module_core_ro_nx(mod);
64331 - module_free(mod, mod->module_core);
64332 + module_free_exec(mod, mod->module_core_rx);
64333 + module_free(mod, mod->module_core_rw);
64334
64335 #ifdef CONFIG_MPU
64336 update_protections(current->mm);
64337 @@ -1826,10 +1831,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64338 unsigned int i;
64339 int ret = 0;
64340 const struct kernel_symbol *ksym;
64341 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64342 + int is_fs_load = 0;
64343 + int register_filesystem_found = 0;
64344 + char *p;
64345 +
64346 + p = strstr(mod->args, "grsec_modharden_fs");
64347 + if (p) {
64348 + char *endptr = p + strlen("grsec_modharden_fs");
64349 + /* copy \0 as well */
64350 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
64351 + is_fs_load = 1;
64352 + }
64353 +#endif
64354
64355 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
64356 const char *name = info->strtab + sym[i].st_name;
64357
64358 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64359 + /* it's a real shame this will never get ripped and copied
64360 + upstream! ;(
64361 + */
64362 + if (is_fs_load && !strcmp(name, "register_filesystem"))
64363 + register_filesystem_found = 1;
64364 +#endif
64365 +
64366 switch (sym[i].st_shndx) {
64367 case SHN_COMMON:
64368 /* We compiled with -fno-common. These are not
64369 @@ -1850,7 +1876,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64370 ksym = resolve_symbol_wait(mod, info, name);
64371 /* Ok if resolved. */
64372 if (ksym && !IS_ERR(ksym)) {
64373 + pax_open_kernel();
64374 sym[i].st_value = ksym->value;
64375 + pax_close_kernel();
64376 break;
64377 }
64378
64379 @@ -1869,11 +1897,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64380 secbase = (unsigned long)mod_percpu(mod);
64381 else
64382 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
64383 + pax_open_kernel();
64384 sym[i].st_value += secbase;
64385 + pax_close_kernel();
64386 break;
64387 }
64388 }
64389
64390 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64391 + if (is_fs_load && !register_filesystem_found) {
64392 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
64393 + ret = -EPERM;
64394 + }
64395 +#endif
64396 +
64397 return ret;
64398 }
64399
64400 @@ -1977,22 +2014,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
64401 || s->sh_entsize != ~0UL
64402 || strstarts(sname, ".init"))
64403 continue;
64404 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
64405 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
64406 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
64407 + else
64408 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
64409 DEBUGP("\t%s\n", name);
64410 }
64411 - switch (m) {
64412 - case 0: /* executable */
64413 - mod->core_size = debug_align(mod->core_size);
64414 - mod->core_text_size = mod->core_size;
64415 - break;
64416 - case 1: /* RO: text and ro-data */
64417 - mod->core_size = debug_align(mod->core_size);
64418 - mod->core_ro_size = mod->core_size;
64419 - break;
64420 - case 3: /* whole core */
64421 - mod->core_size = debug_align(mod->core_size);
64422 - break;
64423 - }
64424 }
64425
64426 DEBUGP("Init section allocation order:\n");
64427 @@ -2006,23 +2033,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
64428 || s->sh_entsize != ~0UL
64429 || !strstarts(sname, ".init"))
64430 continue;
64431 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
64432 - | INIT_OFFSET_MASK);
64433 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
64434 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
64435 + else
64436 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
64437 + s->sh_entsize |= INIT_OFFSET_MASK;
64438 DEBUGP("\t%s\n", sname);
64439 }
64440 - switch (m) {
64441 - case 0: /* executable */
64442 - mod->init_size = debug_align(mod->init_size);
64443 - mod->init_text_size = mod->init_size;
64444 - break;
64445 - case 1: /* RO: text and ro-data */
64446 - mod->init_size = debug_align(mod->init_size);
64447 - mod->init_ro_size = mod->init_size;
64448 - break;
64449 - case 3: /* whole init */
64450 - mod->init_size = debug_align(mod->init_size);
64451 - break;
64452 - }
64453 }
64454 }
64455
64456 @@ -2187,7 +2204,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
64457
64458 /* Put symbol section at end of init part of module. */
64459 symsect->sh_flags |= SHF_ALLOC;
64460 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
64461 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
64462 info->index.sym) | INIT_OFFSET_MASK;
64463 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
64464
64465 @@ -2204,19 +2221,19 @@ static void layout_symtab(struct module *mod, struct load_info *info)
64466 }
64467
64468 /* Append room for core symbols at end of core part. */
64469 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
64470 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
64471 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
64472 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
64473
64474 /* Put string table section at end of init part of module. */
64475 strsect->sh_flags |= SHF_ALLOC;
64476 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
64477 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
64478 info->index.str) | INIT_OFFSET_MASK;
64479 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
64480
64481 /* Append room for core symbols' strings at end of core part. */
64482 - info->stroffs = mod->core_size;
64483 + info->stroffs = mod->core_size_rx;
64484 __set_bit(0, info->strmap);
64485 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
64486 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
64487 }
64488
64489 static void add_kallsyms(struct module *mod, const struct load_info *info)
64490 @@ -2232,11 +2249,13 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
64491 /* Make sure we get permanent strtab: don't use info->strtab. */
64492 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
64493
64494 + pax_open_kernel();
64495 +
64496 /* Set types up while we still have access to sections. */
64497 for (i = 0; i < mod->num_symtab; i++)
64498 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
64499
64500 - mod->core_symtab = dst = mod->module_core + info->symoffs;
64501 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
64502 src = mod->symtab;
64503 *dst = *src;
64504 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
64505 @@ -2249,10 +2268,12 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
64506 }
64507 mod->core_num_syms = ndst;
64508
64509 - mod->core_strtab = s = mod->module_core + info->stroffs;
64510 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
64511 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
64512 if (test_bit(i, info->strmap))
64513 *++s = mod->strtab[i];
64514 +
64515 + pax_close_kernel();
64516 }
64517 #else
64518 static inline void layout_symtab(struct module *mod, struct load_info *info)
64519 @@ -2286,17 +2307,33 @@ void * __weak module_alloc(unsigned long size)
64520 return size == 0 ? NULL : vmalloc_exec(size);
64521 }
64522
64523 -static void *module_alloc_update_bounds(unsigned long size)
64524 +static void *module_alloc_update_bounds_rw(unsigned long size)
64525 {
64526 void *ret = module_alloc(size);
64527
64528 if (ret) {
64529 mutex_lock(&module_mutex);
64530 /* Update module bounds. */
64531 - if ((unsigned long)ret < module_addr_min)
64532 - module_addr_min = (unsigned long)ret;
64533 - if ((unsigned long)ret + size > module_addr_max)
64534 - module_addr_max = (unsigned long)ret + size;
64535 + if ((unsigned long)ret < module_addr_min_rw)
64536 + module_addr_min_rw = (unsigned long)ret;
64537 + if ((unsigned long)ret + size > module_addr_max_rw)
64538 + module_addr_max_rw = (unsigned long)ret + size;
64539 + mutex_unlock(&module_mutex);
64540 + }
64541 + return ret;
64542 +}
64543 +
64544 +static void *module_alloc_update_bounds_rx(unsigned long size)
64545 +{
64546 + void *ret = module_alloc_exec(size);
64547 +
64548 + if (ret) {
64549 + mutex_lock(&module_mutex);
64550 + /* Update module bounds. */
64551 + if ((unsigned long)ret < module_addr_min_rx)
64552 + module_addr_min_rx = (unsigned long)ret;
64553 + if ((unsigned long)ret + size > module_addr_max_rx)
64554 + module_addr_max_rx = (unsigned long)ret + size;
64555 mutex_unlock(&module_mutex);
64556 }
64557 return ret;
64558 @@ -2474,8 +2511,14 @@ static struct module *setup_load_info(struct load_info *info)
64559 static int check_modinfo(struct module *mod, struct load_info *info)
64560 {
64561 const char *modmagic = get_modinfo(info, "vermagic");
64562 + const char *license = get_modinfo(info, "license");
64563 int err;
64564
64565 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
64566 + if (!license || !license_is_gpl_compatible(license))
64567 + return -ENOEXEC;
64568 +#endif
64569 +
64570 /* This is allowed: modprobe --force will invalidate it. */
64571 if (!modmagic) {
64572 err = try_to_force_load(mod, "bad vermagic");
64573 @@ -2498,7 +2541,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
64574 }
64575
64576 /* Set up license info based on the info section */
64577 - set_license(mod, get_modinfo(info, "license"));
64578 + set_license(mod, license);
64579
64580 return 0;
64581 }
64582 @@ -2592,7 +2635,7 @@ static int move_module(struct module *mod, struct load_info *info)
64583 void *ptr;
64584
64585 /* Do the allocs. */
64586 - ptr = module_alloc_update_bounds(mod->core_size);
64587 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
64588 /*
64589 * The pointer to this block is stored in the module structure
64590 * which is inside the block. Just mark it as not being a
64591 @@ -2602,23 +2645,50 @@ static int move_module(struct module *mod, struct load_info *info)
64592 if (!ptr)
64593 return -ENOMEM;
64594
64595 - memset(ptr, 0, mod->core_size);
64596 - mod->module_core = ptr;
64597 + memset(ptr, 0, mod->core_size_rw);
64598 + mod->module_core_rw = ptr;
64599
64600 - ptr = module_alloc_update_bounds(mod->init_size);
64601 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
64602 /*
64603 * The pointer to this block is stored in the module structure
64604 * which is inside the block. This block doesn't need to be
64605 * scanned as it contains data and code that will be freed
64606 * after the module is initialized.
64607 */
64608 - kmemleak_ignore(ptr);
64609 - if (!ptr && mod->init_size) {
64610 - module_free(mod, mod->module_core);
64611 + kmemleak_not_leak(ptr);
64612 + if (!ptr && mod->init_size_rw) {
64613 + module_free(mod, mod->module_core_rw);
64614 return -ENOMEM;
64615 }
64616 - memset(ptr, 0, mod->init_size);
64617 - mod->module_init = ptr;
64618 + memset(ptr, 0, mod->init_size_rw);
64619 + mod->module_init_rw = ptr;
64620 +
64621 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
64622 + kmemleak_not_leak(ptr);
64623 + if (!ptr) {
64624 + module_free(mod, mod->module_init_rw);
64625 + module_free(mod, mod->module_core_rw);
64626 + return -ENOMEM;
64627 + }
64628 +
64629 + pax_open_kernel();
64630 + memset(ptr, 0, mod->core_size_rx);
64631 + pax_close_kernel();
64632 + mod->module_core_rx = ptr;
64633 +
64634 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
64635 + kmemleak_not_leak(ptr);
64636 + if (!ptr && mod->init_size_rx) {
64637 + module_free_exec(mod, mod->module_core_rx);
64638 + module_free(mod, mod->module_init_rw);
64639 + module_free(mod, mod->module_core_rw);
64640 + return -ENOMEM;
64641 + }
64642 +
64643 + pax_open_kernel();
64644 + memset(ptr, 0, mod->init_size_rx);
64645 + pax_close_kernel();
64646 + mod->module_init_rx = ptr;
64647
64648 /* Transfer each section which specifies SHF_ALLOC */
64649 DEBUGP("final section addresses:\n");
64650 @@ -2629,16 +2699,45 @@ static int move_module(struct module *mod, struct load_info *info)
64651 if (!(shdr->sh_flags & SHF_ALLOC))
64652 continue;
64653
64654 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
64655 - dest = mod->module_init
64656 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64657 - else
64658 - dest = mod->module_core + shdr->sh_entsize;
64659 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
64660 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
64661 + dest = mod->module_init_rw
64662 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64663 + else
64664 + dest = mod->module_init_rx
64665 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64666 + } else {
64667 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
64668 + dest = mod->module_core_rw + shdr->sh_entsize;
64669 + else
64670 + dest = mod->module_core_rx + shdr->sh_entsize;
64671 + }
64672 +
64673 + if (shdr->sh_type != SHT_NOBITS) {
64674 +
64675 +#ifdef CONFIG_PAX_KERNEXEC
64676 +#ifdef CONFIG_X86_64
64677 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
64678 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
64679 +#endif
64680 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
64681 + pax_open_kernel();
64682 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
64683 + pax_close_kernel();
64684 + } else
64685 +#endif
64686
64687 - if (shdr->sh_type != SHT_NOBITS)
64688 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
64689 + }
64690 /* Update sh_addr to point to copy in image. */
64691 - shdr->sh_addr = (unsigned long)dest;
64692 +
64693 +#ifdef CONFIG_PAX_KERNEXEC
64694 + if (shdr->sh_flags & SHF_EXECINSTR)
64695 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
64696 + else
64697 +#endif
64698 +
64699 + shdr->sh_addr = (unsigned long)dest;
64700 DEBUGP("\t0x%lx %s\n",
64701 shdr->sh_addr, info->secstrings + shdr->sh_name);
64702 }
64703 @@ -2689,12 +2788,12 @@ static void flush_module_icache(const struct module *mod)
64704 * Do it before processing of module parameters, so the module
64705 * can provide parameter accessor functions of its own.
64706 */
64707 - if (mod->module_init)
64708 - flush_icache_range((unsigned long)mod->module_init,
64709 - (unsigned long)mod->module_init
64710 - + mod->init_size);
64711 - flush_icache_range((unsigned long)mod->module_core,
64712 - (unsigned long)mod->module_core + mod->core_size);
64713 + if (mod->module_init_rx)
64714 + flush_icache_range((unsigned long)mod->module_init_rx,
64715 + (unsigned long)mod->module_init_rx
64716 + + mod->init_size_rx);
64717 + flush_icache_range((unsigned long)mod->module_core_rx,
64718 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
64719
64720 set_fs(old_fs);
64721 }
64722 @@ -2774,8 +2873,10 @@ static void module_deallocate(struct module *mod, struct load_info *info)
64723 {
64724 kfree(info->strmap);
64725 percpu_modfree(mod);
64726 - module_free(mod, mod->module_init);
64727 - module_free(mod, mod->module_core);
64728 + module_free_exec(mod, mod->module_init_rx);
64729 + module_free_exec(mod, mod->module_core_rx);
64730 + module_free(mod, mod->module_init_rw);
64731 + module_free(mod, mod->module_core_rw);
64732 }
64733
64734 int __weak module_finalize(const Elf_Ehdr *hdr,
64735 @@ -2839,9 +2940,38 @@ static struct module *load_module(void __user *umod,
64736 if (err)
64737 goto free_unload;
64738
64739 + /* Now copy in args */
64740 + mod->args = strndup_user(uargs, ~0UL >> 1);
64741 + if (IS_ERR(mod->args)) {
64742 + err = PTR_ERR(mod->args);
64743 + goto free_unload;
64744 + }
64745 +
64746 /* Set up MODINFO_ATTR fields */
64747 setup_modinfo(mod, &info);
64748
64749 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64750 + {
64751 + char *p, *p2;
64752 +
64753 + if (strstr(mod->args, "grsec_modharden_netdev")) {
64754 + 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);
64755 + err = -EPERM;
64756 + goto free_modinfo;
64757 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
64758 + p += strlen("grsec_modharden_normal");
64759 + p2 = strstr(p, "_");
64760 + if (p2) {
64761 + *p2 = '\0';
64762 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
64763 + *p2 = '_';
64764 + }
64765 + err = -EPERM;
64766 + goto free_modinfo;
64767 + }
64768 + }
64769 +#endif
64770 +
64771 /* Fix up syms, so that st_value is a pointer to location. */
64772 err = simplify_symbols(mod, &info);
64773 if (err < 0)
64774 @@ -2857,13 +2987,6 @@ static struct module *load_module(void __user *umod,
64775
64776 flush_module_icache(mod);
64777
64778 - /* Now copy in args */
64779 - mod->args = strndup_user(uargs, ~0UL >> 1);
64780 - if (IS_ERR(mod->args)) {
64781 - err = PTR_ERR(mod->args);
64782 - goto free_arch_cleanup;
64783 - }
64784 -
64785 /* Mark state as coming so strong_try_module_get() ignores us. */
64786 mod->state = MODULE_STATE_COMING;
64787
64788 @@ -2921,11 +3044,10 @@ static struct module *load_module(void __user *umod,
64789 unlock:
64790 mutex_unlock(&module_mutex);
64791 synchronize_sched();
64792 - kfree(mod->args);
64793 - free_arch_cleanup:
64794 module_arch_cleanup(mod);
64795 free_modinfo:
64796 free_modinfo(mod);
64797 + kfree(mod->args);
64798 free_unload:
64799 module_unload_free(mod);
64800 free_module:
64801 @@ -2966,16 +3088,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
64802 MODULE_STATE_COMING, mod);
64803
64804 /* Set RO and NX regions for core */
64805 - set_section_ro_nx(mod->module_core,
64806 - mod->core_text_size,
64807 - mod->core_ro_size,
64808 - mod->core_size);
64809 + set_section_ro_nx(mod->module_core_rx,
64810 + mod->core_size_rx,
64811 + mod->core_size_rx,
64812 + mod->core_size_rx);
64813
64814 /* Set RO and NX regions for init */
64815 - set_section_ro_nx(mod->module_init,
64816 - mod->init_text_size,
64817 - mod->init_ro_size,
64818 - mod->init_size);
64819 + set_section_ro_nx(mod->module_init_rx,
64820 + mod->init_size_rx,
64821 + mod->init_size_rx,
64822 + mod->init_size_rx);
64823
64824 do_mod_ctors(mod);
64825 /* Start the module */
64826 @@ -3021,11 +3143,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
64827 mod->strtab = mod->core_strtab;
64828 #endif
64829 unset_module_init_ro_nx(mod);
64830 - module_free(mod, mod->module_init);
64831 - mod->module_init = NULL;
64832 - mod->init_size = 0;
64833 - mod->init_ro_size = 0;
64834 - mod->init_text_size = 0;
64835 + module_free(mod, mod->module_init_rw);
64836 + module_free_exec(mod, mod->module_init_rx);
64837 + mod->module_init_rw = NULL;
64838 + mod->module_init_rx = NULL;
64839 + mod->init_size_rw = 0;
64840 + mod->init_size_rx = 0;
64841 mutex_unlock(&module_mutex);
64842
64843 return 0;
64844 @@ -3056,10 +3179,16 @@ static const char *get_ksymbol(struct module *mod,
64845 unsigned long nextval;
64846
64847 /* At worse, next value is at end of module */
64848 - if (within_module_init(addr, mod))
64849 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
64850 + if (within_module_init_rx(addr, mod))
64851 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
64852 + else if (within_module_init_rw(addr, mod))
64853 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
64854 + else if (within_module_core_rx(addr, mod))
64855 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
64856 + else if (within_module_core_rw(addr, mod))
64857 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
64858 else
64859 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
64860 + return NULL;
64861
64862 /* Scan for closest preceding symbol, and next symbol. (ELF
64863 starts real symbols at 1). */
64864 @@ -3307,7 +3436,7 @@ static int m_show(struct seq_file *m, void *p)
64865 char buf[8];
64866
64867 seq_printf(m, "%s %u",
64868 - mod->name, mod->init_size + mod->core_size);
64869 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
64870 print_unload_info(m, mod);
64871
64872 /* Informative for users. */
64873 @@ -3316,7 +3445,7 @@ static int m_show(struct seq_file *m, void *p)
64874 mod->state == MODULE_STATE_COMING ? "Loading":
64875 "Live");
64876 /* Used by oprofile and other similar tools. */
64877 - seq_printf(m, " 0x%pK", mod->module_core);
64878 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
64879
64880 /* Taints info */
64881 if (mod->taints)
64882 @@ -3352,7 +3481,17 @@ static const struct file_operations proc_modules_operations = {
64883
64884 static int __init proc_modules_init(void)
64885 {
64886 +#ifndef CONFIG_GRKERNSEC_HIDESYM
64887 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64888 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
64889 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64890 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
64891 +#else
64892 proc_create("modules", 0, NULL, &proc_modules_operations);
64893 +#endif
64894 +#else
64895 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
64896 +#endif
64897 return 0;
64898 }
64899 module_init(proc_modules_init);
64900 @@ -3411,12 +3550,12 @@ struct module *__module_address(unsigned long addr)
64901 {
64902 struct module *mod;
64903
64904 - if (addr < module_addr_min || addr > module_addr_max)
64905 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
64906 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
64907 return NULL;
64908
64909 list_for_each_entry_rcu(mod, &modules, list)
64910 - if (within_module_core(addr, mod)
64911 - || within_module_init(addr, mod))
64912 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
64913 return mod;
64914 return NULL;
64915 }
64916 @@ -3450,11 +3589,20 @@ bool is_module_text_address(unsigned long addr)
64917 */
64918 struct module *__module_text_address(unsigned long addr)
64919 {
64920 - struct module *mod = __module_address(addr);
64921 + struct module *mod;
64922 +
64923 +#ifdef CONFIG_X86_32
64924 + addr = ktla_ktva(addr);
64925 +#endif
64926 +
64927 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
64928 + return NULL;
64929 +
64930 + mod = __module_address(addr);
64931 +
64932 if (mod) {
64933 /* Make sure it's within the text section. */
64934 - if (!within(addr, mod->module_init, mod->init_text_size)
64935 - && !within(addr, mod->module_core, mod->core_text_size))
64936 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
64937 mod = NULL;
64938 }
64939 return mod;
64940 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
64941 index 7e3443f..b2a1e6b 100644
64942 --- a/kernel/mutex-debug.c
64943 +++ b/kernel/mutex-debug.c
64944 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
64945 }
64946
64947 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64948 - struct thread_info *ti)
64949 + struct task_struct *task)
64950 {
64951 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
64952
64953 /* Mark the current thread as blocked on the lock: */
64954 - ti->task->blocked_on = waiter;
64955 + task->blocked_on = waiter;
64956 }
64957
64958 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64959 - struct thread_info *ti)
64960 + struct task_struct *task)
64961 {
64962 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
64963 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
64964 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
64965 - ti->task->blocked_on = NULL;
64966 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
64967 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
64968 + task->blocked_on = NULL;
64969
64970 list_del_init(&waiter->list);
64971 waiter->task = NULL;
64972 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
64973 index 0799fd3..d06ae3b 100644
64974 --- a/kernel/mutex-debug.h
64975 +++ b/kernel/mutex-debug.h
64976 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
64977 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
64978 extern void debug_mutex_add_waiter(struct mutex *lock,
64979 struct mutex_waiter *waiter,
64980 - struct thread_info *ti);
64981 + struct task_struct *task);
64982 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64983 - struct thread_info *ti);
64984 + struct task_struct *task);
64985 extern void debug_mutex_unlock(struct mutex *lock);
64986 extern void debug_mutex_init(struct mutex *lock, const char *name,
64987 struct lock_class_key *key);
64988 diff --git a/kernel/mutex.c b/kernel/mutex.c
64989 index 89096dd..f91ebc5 100644
64990 --- a/kernel/mutex.c
64991 +++ b/kernel/mutex.c
64992 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
64993 spin_lock_mutex(&lock->wait_lock, flags);
64994
64995 debug_mutex_lock_common(lock, &waiter);
64996 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
64997 + debug_mutex_add_waiter(lock, &waiter, task);
64998
64999 /* add waiting tasks to the end of the waitqueue (FIFO): */
65000 list_add_tail(&waiter.list, &lock->wait_list);
65001 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
65002 * TASK_UNINTERRUPTIBLE case.)
65003 */
65004 if (unlikely(signal_pending_state(state, task))) {
65005 - mutex_remove_waiter(lock, &waiter,
65006 - task_thread_info(task));
65007 + mutex_remove_waiter(lock, &waiter, task);
65008 mutex_release(&lock->dep_map, 1, ip);
65009 spin_unlock_mutex(&lock->wait_lock, flags);
65010
65011 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
65012 done:
65013 lock_acquired(&lock->dep_map, ip);
65014 /* got the lock - rejoice! */
65015 - mutex_remove_waiter(lock, &waiter, current_thread_info());
65016 + mutex_remove_waiter(lock, &waiter, task);
65017 mutex_set_owner(lock);
65018
65019 /* set it to 0 if there are no waiters left: */
65020 diff --git a/kernel/padata.c b/kernel/padata.c
65021 index b452599..5d68f4e 100644
65022 --- a/kernel/padata.c
65023 +++ b/kernel/padata.c
65024 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
65025 padata->pd = pd;
65026 padata->cb_cpu = cb_cpu;
65027
65028 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
65029 - atomic_set(&pd->seq_nr, -1);
65030 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
65031 + atomic_set_unchecked(&pd->seq_nr, -1);
65032
65033 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
65034 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
65035
65036 target_cpu = padata_cpu_hash(padata);
65037 queue = per_cpu_ptr(pd->pqueue, target_cpu);
65038 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
65039 padata_init_pqueues(pd);
65040 padata_init_squeues(pd);
65041 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
65042 - atomic_set(&pd->seq_nr, -1);
65043 + atomic_set_unchecked(&pd->seq_nr, -1);
65044 atomic_set(&pd->reorder_objects, 0);
65045 atomic_set(&pd->refcnt, 0);
65046 pd->pinst = pinst;
65047 diff --git a/kernel/panic.c b/kernel/panic.c
65048 index b2659360..5972a0f 100644
65049 --- a/kernel/panic.c
65050 +++ b/kernel/panic.c
65051 @@ -78,7 +78,11 @@ NORET_TYPE void panic(const char * fmt, ...)
65052 va_end(args);
65053 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
65054 #ifdef CONFIG_DEBUG_BUGVERBOSE
65055 - dump_stack();
65056 + /*
65057 + * Avoid nested stack-dumping if a panic occurs during oops processing
65058 + */
65059 + if (!oops_in_progress)
65060 + dump_stack();
65061 #endif
65062
65063 /*
65064 @@ -373,7 +377,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
65065 const char *board;
65066
65067 printk(KERN_WARNING "------------[ cut here ]------------\n");
65068 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
65069 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
65070 board = dmi_get_system_info(DMI_PRODUCT_NAME);
65071 if (board)
65072 printk(KERN_WARNING "Hardware name: %s\n", board);
65073 @@ -428,7 +432,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
65074 */
65075 void __stack_chk_fail(void)
65076 {
65077 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
65078 + dump_stack();
65079 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
65080 __builtin_return_address(0));
65081 }
65082 EXPORT_SYMBOL(__stack_chk_fail);
65083 diff --git a/kernel/pid.c b/kernel/pid.c
65084 index fa5f722..0c93e57 100644
65085 --- a/kernel/pid.c
65086 +++ b/kernel/pid.c
65087 @@ -33,6 +33,7 @@
65088 #include <linux/rculist.h>
65089 #include <linux/bootmem.h>
65090 #include <linux/hash.h>
65091 +#include <linux/security.h>
65092 #include <linux/pid_namespace.h>
65093 #include <linux/init_task.h>
65094 #include <linux/syscalls.h>
65095 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
65096
65097 int pid_max = PID_MAX_DEFAULT;
65098
65099 -#define RESERVED_PIDS 300
65100 +#define RESERVED_PIDS 500
65101
65102 int pid_max_min = RESERVED_PIDS + 1;
65103 int pid_max_max = PID_MAX_LIMIT;
65104 @@ -418,10 +419,18 @@ EXPORT_SYMBOL(pid_task);
65105 */
65106 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
65107 {
65108 + struct task_struct *task;
65109 +
65110 rcu_lockdep_assert(rcu_read_lock_held(),
65111 "find_task_by_pid_ns() needs rcu_read_lock()"
65112 " protection");
65113 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
65114 +
65115 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
65116 +
65117 + if (gr_pid_is_chrooted(task))
65118 + return NULL;
65119 +
65120 + return task;
65121 }
65122
65123 struct task_struct *find_task_by_vpid(pid_t vnr)
65124 @@ -429,6 +438,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
65125 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
65126 }
65127
65128 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
65129 +{
65130 + rcu_lockdep_assert(rcu_read_lock_held(),
65131 + "find_task_by_pid_ns() needs rcu_read_lock()"
65132 + " protection");
65133 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
65134 +}
65135 +
65136 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
65137 {
65138 struct pid *pid;
65139 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
65140 index e7cb76d..75eceb3 100644
65141 --- a/kernel/posix-cpu-timers.c
65142 +++ b/kernel/posix-cpu-timers.c
65143 @@ -6,6 +6,7 @@
65144 #include <linux/posix-timers.h>
65145 #include <linux/errno.h>
65146 #include <linux/math64.h>
65147 +#include <linux/security.h>
65148 #include <asm/uaccess.h>
65149 #include <linux/kernel_stat.h>
65150 #include <trace/events/timer.h>
65151 @@ -1606,14 +1607,14 @@ struct k_clock clock_posix_cpu = {
65152
65153 static __init int init_posix_cpu_timers(void)
65154 {
65155 - struct k_clock process = {
65156 + static struct k_clock process = {
65157 .clock_getres = process_cpu_clock_getres,
65158 .clock_get = process_cpu_clock_get,
65159 .timer_create = process_cpu_timer_create,
65160 .nsleep = process_cpu_nsleep,
65161 .nsleep_restart = process_cpu_nsleep_restart,
65162 };
65163 - struct k_clock thread = {
65164 + static struct k_clock thread = {
65165 .clock_getres = thread_cpu_clock_getres,
65166 .clock_get = thread_cpu_clock_get,
65167 .timer_create = thread_cpu_timer_create,
65168 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
65169 index 69185ae..cc2847a 100644
65170 --- a/kernel/posix-timers.c
65171 +++ b/kernel/posix-timers.c
65172 @@ -43,6 +43,7 @@
65173 #include <linux/idr.h>
65174 #include <linux/posix-clock.h>
65175 #include <linux/posix-timers.h>
65176 +#include <linux/grsecurity.h>
65177 #include <linux/syscalls.h>
65178 #include <linux/wait.h>
65179 #include <linux/workqueue.h>
65180 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
65181 * which we beg off on and pass to do_sys_settimeofday().
65182 */
65183
65184 -static struct k_clock posix_clocks[MAX_CLOCKS];
65185 +static struct k_clock *posix_clocks[MAX_CLOCKS];
65186
65187 /*
65188 * These ones are defined below.
65189 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
65190 */
65191 static __init int init_posix_timers(void)
65192 {
65193 - struct k_clock clock_realtime = {
65194 + static struct k_clock clock_realtime = {
65195 .clock_getres = hrtimer_get_res,
65196 .clock_get = posix_clock_realtime_get,
65197 .clock_set = posix_clock_realtime_set,
65198 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
65199 .timer_get = common_timer_get,
65200 .timer_del = common_timer_del,
65201 };
65202 - struct k_clock clock_monotonic = {
65203 + static struct k_clock clock_monotonic = {
65204 .clock_getres = hrtimer_get_res,
65205 .clock_get = posix_ktime_get_ts,
65206 .nsleep = common_nsleep,
65207 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
65208 .timer_get = common_timer_get,
65209 .timer_del = common_timer_del,
65210 };
65211 - struct k_clock clock_monotonic_raw = {
65212 + static struct k_clock clock_monotonic_raw = {
65213 .clock_getres = hrtimer_get_res,
65214 .clock_get = posix_get_monotonic_raw,
65215 };
65216 - struct k_clock clock_realtime_coarse = {
65217 + static struct k_clock clock_realtime_coarse = {
65218 .clock_getres = posix_get_coarse_res,
65219 .clock_get = posix_get_realtime_coarse,
65220 };
65221 - struct k_clock clock_monotonic_coarse = {
65222 + static struct k_clock clock_monotonic_coarse = {
65223 .clock_getres = posix_get_coarse_res,
65224 .clock_get = posix_get_monotonic_coarse,
65225 };
65226 - struct k_clock clock_boottime = {
65227 + static struct k_clock clock_boottime = {
65228 .clock_getres = hrtimer_get_res,
65229 .clock_get = posix_get_boottime,
65230 .nsleep = common_nsleep,
65231 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
65232 return;
65233 }
65234
65235 - posix_clocks[clock_id] = *new_clock;
65236 + posix_clocks[clock_id] = new_clock;
65237 }
65238 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
65239
65240 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
65241 return (id & CLOCKFD_MASK) == CLOCKFD ?
65242 &clock_posix_dynamic : &clock_posix_cpu;
65243
65244 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
65245 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
65246 return NULL;
65247 - return &posix_clocks[id];
65248 + return posix_clocks[id];
65249 }
65250
65251 static int common_timer_create(struct k_itimer *new_timer)
65252 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
65253 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
65254 return -EFAULT;
65255
65256 + /* only the CLOCK_REALTIME clock can be set, all other clocks
65257 + have their clock_set fptr set to a nosettime dummy function
65258 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
65259 + call common_clock_set, which calls do_sys_settimeofday, which
65260 + we hook
65261 + */
65262 +
65263 return kc->clock_set(which_clock, &new_tp);
65264 }
65265
65266 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
65267 index d523593..68197a4 100644
65268 --- a/kernel/power/poweroff.c
65269 +++ b/kernel/power/poweroff.c
65270 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
65271 .enable_mask = SYSRQ_ENABLE_BOOT,
65272 };
65273
65274 -static int pm_sysrq_init(void)
65275 +static int __init pm_sysrq_init(void)
65276 {
65277 register_sysrq_key('o', &sysrq_poweroff_op);
65278 return 0;
65279 diff --git a/kernel/power/process.c b/kernel/power/process.c
65280 index addbbe5..f9e32e0 100644
65281 --- a/kernel/power/process.c
65282 +++ b/kernel/power/process.c
65283 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_only)
65284 u64 elapsed_csecs64;
65285 unsigned int elapsed_csecs;
65286 bool wakeup = false;
65287 + bool timedout = false;
65288
65289 do_gettimeofday(&start);
65290
65291 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_only)
65292
65293 while (true) {
65294 todo = 0;
65295 + if (time_after(jiffies, end_time))
65296 + timedout = true;
65297 read_lock(&tasklist_lock);
65298 do_each_thread(g, p) {
65299 if (frozen(p) || !freezable(p))
65300 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_only)
65301 * try_to_stop() after schedule() in ptrace/signal
65302 * stop sees TIF_FREEZE.
65303 */
65304 - if (!task_is_stopped_or_traced(p) &&
65305 - !freezer_should_skip(p))
65306 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
65307 todo++;
65308 + if (timedout) {
65309 + printk(KERN_ERR "Task refusing to freeze:\n");
65310 + sched_show_task(p);
65311 + }
65312 + }
65313 } while_each_thread(g, p);
65314 read_unlock(&tasklist_lock);
65315
65316 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_only)
65317 todo += wq_busy;
65318 }
65319
65320 - if (!todo || time_after(jiffies, end_time))
65321 + if (!todo || timedout)
65322 break;
65323
65324 if (pm_wakeup_pending()) {
65325 diff --git a/kernel/printk.c b/kernel/printk.c
65326 index 7982a0a..2095fdc 100644
65327 --- a/kernel/printk.c
65328 +++ b/kernel/printk.c
65329 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
65330 if (from_file && type != SYSLOG_ACTION_OPEN)
65331 return 0;
65332
65333 +#ifdef CONFIG_GRKERNSEC_DMESG
65334 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
65335 + return -EPERM;
65336 +#endif
65337 +
65338 if (syslog_action_restricted(type)) {
65339 if (capable(CAP_SYSLOG))
65340 return 0;
65341 diff --git a/kernel/profile.c b/kernel/profile.c
65342 index 76b8e77..a2930e8 100644
65343 --- a/kernel/profile.c
65344 +++ b/kernel/profile.c
65345 @@ -39,7 +39,7 @@ struct profile_hit {
65346 /* Oprofile timer tick hook */
65347 static int (*timer_hook)(struct pt_regs *) __read_mostly;
65348
65349 -static atomic_t *prof_buffer;
65350 +static atomic_unchecked_t *prof_buffer;
65351 static unsigned long prof_len, prof_shift;
65352
65353 int prof_on __read_mostly;
65354 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
65355 hits[i].pc = 0;
65356 continue;
65357 }
65358 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
65359 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
65360 hits[i].hits = hits[i].pc = 0;
65361 }
65362 }
65363 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
65364 * Add the current hit(s) and flush the write-queue out
65365 * to the global buffer:
65366 */
65367 - atomic_add(nr_hits, &prof_buffer[pc]);
65368 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
65369 for (i = 0; i < NR_PROFILE_HIT; ++i) {
65370 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
65371 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
65372 hits[i].pc = hits[i].hits = 0;
65373 }
65374 out:
65375 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
65376 {
65377 unsigned long pc;
65378 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
65379 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
65380 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
65381 }
65382 #endif /* !CONFIG_SMP */
65383
65384 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
65385 return -EFAULT;
65386 buf++; p++; count--; read++;
65387 }
65388 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
65389 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
65390 if (copy_to_user(buf, (void *)pnt, count))
65391 return -EFAULT;
65392 read += count;
65393 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
65394 }
65395 #endif
65396 profile_discard_flip_buffers();
65397 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
65398 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
65399 return count;
65400 }
65401
65402 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
65403 index 78ab24a..332c915 100644
65404 --- a/kernel/ptrace.c
65405 +++ b/kernel/ptrace.c
65406 @@ -172,7 +172,8 @@ int ptrace_check_attach(struct task_struct *child, bool ignore_state)
65407 return ret;
65408 }
65409
65410 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
65411 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
65412 + unsigned int log)
65413 {
65414 const struct cred *cred = current_cred(), *tcred;
65415
65416 @@ -198,7 +199,8 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
65417 cred->gid == tcred->sgid &&
65418 cred->gid == tcred->gid))
65419 goto ok;
65420 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
65421 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
65422 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
65423 goto ok;
65424 rcu_read_unlock();
65425 return -EPERM;
65426 @@ -207,7 +209,9 @@ ok:
65427 smp_rmb();
65428 if (task->mm)
65429 dumpable = get_dumpable(task->mm);
65430 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
65431 + if (!dumpable &&
65432 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
65433 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
65434 return -EPERM;
65435
65436 return security_ptrace_access_check(task, mode);
65437 @@ -217,7 +221,21 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
65438 {
65439 int err;
65440 task_lock(task);
65441 - err = __ptrace_may_access(task, mode);
65442 + err = __ptrace_may_access(task, mode, 0);
65443 + task_unlock(task);
65444 + return !err;
65445 +}
65446 +
65447 +bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode)
65448 +{
65449 + return __ptrace_may_access(task, mode, 0);
65450 +}
65451 +
65452 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
65453 +{
65454 + int err;
65455 + task_lock(task);
65456 + err = __ptrace_may_access(task, mode, 1);
65457 task_unlock(task);
65458 return !err;
65459 }
65460 @@ -262,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
65461 goto out;
65462
65463 task_lock(task);
65464 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
65465 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
65466 task_unlock(task);
65467 if (retval)
65468 goto unlock_creds;
65469 @@ -277,7 +295,7 @@ static int ptrace_attach(struct task_struct *task, long request,
65470 task->ptrace = PT_PTRACED;
65471 if (seize)
65472 task->ptrace |= PT_SEIZED;
65473 - if (task_ns_capable(task, CAP_SYS_PTRACE))
65474 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
65475 task->ptrace |= PT_PTRACE_CAP;
65476
65477 __ptrace_link(task, current);
65478 @@ -483,7 +501,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
65479 break;
65480 return -EIO;
65481 }
65482 - if (copy_to_user(dst, buf, retval))
65483 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
65484 return -EFAULT;
65485 copied += retval;
65486 src += retval;
65487 @@ -680,7 +698,7 @@ int ptrace_request(struct task_struct *child, long request,
65488 bool seized = child->ptrace & PT_SEIZED;
65489 int ret = -EIO;
65490 siginfo_t siginfo, *si;
65491 - void __user *datavp = (void __user *) data;
65492 + void __user *datavp = (__force void __user *) data;
65493 unsigned long __user *datalp = datavp;
65494 unsigned long flags;
65495
65496 @@ -882,14 +900,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
65497 goto out;
65498 }
65499
65500 + if (gr_handle_ptrace(child, request)) {
65501 + ret = -EPERM;
65502 + goto out_put_task_struct;
65503 + }
65504 +
65505 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65506 ret = ptrace_attach(child, request, data);
65507 /*
65508 * Some architectures need to do book-keeping after
65509 * a ptrace attach.
65510 */
65511 - if (!ret)
65512 + if (!ret) {
65513 arch_ptrace_attach(child);
65514 + gr_audit_ptrace(child);
65515 + }
65516 goto out_put_task_struct;
65517 }
65518
65519 @@ -915,7 +940,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
65520 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
65521 if (copied != sizeof(tmp))
65522 return -EIO;
65523 - return put_user(tmp, (unsigned long __user *)data);
65524 + return put_user(tmp, (__force unsigned long __user *)data);
65525 }
65526
65527 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
65528 @@ -1025,14 +1050,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
65529 goto out;
65530 }
65531
65532 + if (gr_handle_ptrace(child, request)) {
65533 + ret = -EPERM;
65534 + goto out_put_task_struct;
65535 + }
65536 +
65537 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65538 ret = ptrace_attach(child, request, data);
65539 /*
65540 * Some architectures need to do book-keeping after
65541 * a ptrace attach.
65542 */
65543 - if (!ret)
65544 + if (!ret) {
65545 arch_ptrace_attach(child);
65546 + gr_audit_ptrace(child);
65547 + }
65548 goto out_put_task_struct;
65549 }
65550
65551 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
65552 index 764825c..3aa6ac4 100644
65553 --- a/kernel/rcutorture.c
65554 +++ b/kernel/rcutorture.c
65555 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
65556 { 0 };
65557 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
65558 { 0 };
65559 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65560 -static atomic_t n_rcu_torture_alloc;
65561 -static atomic_t n_rcu_torture_alloc_fail;
65562 -static atomic_t n_rcu_torture_free;
65563 -static atomic_t n_rcu_torture_mberror;
65564 -static atomic_t n_rcu_torture_error;
65565 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65566 +static atomic_unchecked_t n_rcu_torture_alloc;
65567 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
65568 +static atomic_unchecked_t n_rcu_torture_free;
65569 +static atomic_unchecked_t n_rcu_torture_mberror;
65570 +static atomic_unchecked_t n_rcu_torture_error;
65571 static long n_rcu_torture_boost_ktrerror;
65572 static long n_rcu_torture_boost_rterror;
65573 static long n_rcu_torture_boost_failure;
65574 @@ -223,11 +223,11 @@ rcu_torture_alloc(void)
65575
65576 spin_lock_bh(&rcu_torture_lock);
65577 if (list_empty(&rcu_torture_freelist)) {
65578 - atomic_inc(&n_rcu_torture_alloc_fail);
65579 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
65580 spin_unlock_bh(&rcu_torture_lock);
65581 return NULL;
65582 }
65583 - atomic_inc(&n_rcu_torture_alloc);
65584 + atomic_inc_unchecked(&n_rcu_torture_alloc);
65585 p = rcu_torture_freelist.next;
65586 list_del_init(p);
65587 spin_unlock_bh(&rcu_torture_lock);
65588 @@ -240,7 +240,7 @@ rcu_torture_alloc(void)
65589 static void
65590 rcu_torture_free(struct rcu_torture *p)
65591 {
65592 - atomic_inc(&n_rcu_torture_free);
65593 + atomic_inc_unchecked(&n_rcu_torture_free);
65594 spin_lock_bh(&rcu_torture_lock);
65595 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
65596 spin_unlock_bh(&rcu_torture_lock);
65597 @@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
65598 i = rp->rtort_pipe_count;
65599 if (i > RCU_TORTURE_PIPE_LEN)
65600 i = RCU_TORTURE_PIPE_LEN;
65601 - atomic_inc(&rcu_torture_wcount[i]);
65602 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65603 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65604 rp->rtort_mbtest = 0;
65605 rcu_torture_free(rp);
65606 @@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
65607 i = rp->rtort_pipe_count;
65608 if (i > RCU_TORTURE_PIPE_LEN)
65609 i = RCU_TORTURE_PIPE_LEN;
65610 - atomic_inc(&rcu_torture_wcount[i]);
65611 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65612 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65613 rp->rtort_mbtest = 0;
65614 list_del(&rp->rtort_free);
65615 @@ -872,7 +872,7 @@ rcu_torture_writer(void *arg)
65616 i = old_rp->rtort_pipe_count;
65617 if (i > RCU_TORTURE_PIPE_LEN)
65618 i = RCU_TORTURE_PIPE_LEN;
65619 - atomic_inc(&rcu_torture_wcount[i]);
65620 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65621 old_rp->rtort_pipe_count++;
65622 cur_ops->deferred_free(old_rp);
65623 }
65624 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
65625 return;
65626 }
65627 if (p->rtort_mbtest == 0)
65628 - atomic_inc(&n_rcu_torture_mberror);
65629 + atomic_inc_unchecked(&n_rcu_torture_mberror);
65630 spin_lock(&rand_lock);
65631 cur_ops->read_delay(&rand);
65632 n_rcu_torture_timers++;
65633 @@ -1001,7 +1001,7 @@ rcu_torture_reader(void *arg)
65634 continue;
65635 }
65636 if (p->rtort_mbtest == 0)
65637 - atomic_inc(&n_rcu_torture_mberror);
65638 + atomic_inc_unchecked(&n_rcu_torture_mberror);
65639 cur_ops->read_delay(&rand);
65640 preempt_disable();
65641 pipe_count = p->rtort_pipe_count;
65642 @@ -1060,16 +1060,16 @@ rcu_torture_printk(char *page)
65643 rcu_torture_current,
65644 rcu_torture_current_version,
65645 list_empty(&rcu_torture_freelist),
65646 - atomic_read(&n_rcu_torture_alloc),
65647 - atomic_read(&n_rcu_torture_alloc_fail),
65648 - atomic_read(&n_rcu_torture_free),
65649 - atomic_read(&n_rcu_torture_mberror),
65650 + atomic_read_unchecked(&n_rcu_torture_alloc),
65651 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
65652 + atomic_read_unchecked(&n_rcu_torture_free),
65653 + atomic_read_unchecked(&n_rcu_torture_mberror),
65654 n_rcu_torture_boost_ktrerror,
65655 n_rcu_torture_boost_rterror,
65656 n_rcu_torture_boost_failure,
65657 n_rcu_torture_boosts,
65658 n_rcu_torture_timers);
65659 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
65660 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
65661 n_rcu_torture_boost_ktrerror != 0 ||
65662 n_rcu_torture_boost_rterror != 0 ||
65663 n_rcu_torture_boost_failure != 0)
65664 @@ -1077,7 +1077,7 @@ rcu_torture_printk(char *page)
65665 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
65666 if (i > 1) {
65667 cnt += sprintf(&page[cnt], "!!! ");
65668 - atomic_inc(&n_rcu_torture_error);
65669 + atomic_inc_unchecked(&n_rcu_torture_error);
65670 WARN_ON_ONCE(1);
65671 }
65672 cnt += sprintf(&page[cnt], "Reader Pipe: ");
65673 @@ -1091,7 +1091,7 @@ rcu_torture_printk(char *page)
65674 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
65675 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65676 cnt += sprintf(&page[cnt], " %d",
65677 - atomic_read(&rcu_torture_wcount[i]));
65678 + atomic_read_unchecked(&rcu_torture_wcount[i]));
65679 }
65680 cnt += sprintf(&page[cnt], "\n");
65681 if (cur_ops->stats)
65682 @@ -1401,7 +1401,7 @@ rcu_torture_cleanup(void)
65683
65684 if (cur_ops->cleanup)
65685 cur_ops->cleanup();
65686 - if (atomic_read(&n_rcu_torture_error))
65687 + if (atomic_read_unchecked(&n_rcu_torture_error))
65688 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
65689 else
65690 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
65691 @@ -1465,17 +1465,17 @@ rcu_torture_init(void)
65692
65693 rcu_torture_current = NULL;
65694 rcu_torture_current_version = 0;
65695 - atomic_set(&n_rcu_torture_alloc, 0);
65696 - atomic_set(&n_rcu_torture_alloc_fail, 0);
65697 - atomic_set(&n_rcu_torture_free, 0);
65698 - atomic_set(&n_rcu_torture_mberror, 0);
65699 - atomic_set(&n_rcu_torture_error, 0);
65700 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
65701 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
65702 + atomic_set_unchecked(&n_rcu_torture_free, 0);
65703 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
65704 + atomic_set_unchecked(&n_rcu_torture_error, 0);
65705 n_rcu_torture_boost_ktrerror = 0;
65706 n_rcu_torture_boost_rterror = 0;
65707 n_rcu_torture_boost_failure = 0;
65708 n_rcu_torture_boosts = 0;
65709 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
65710 - atomic_set(&rcu_torture_wcount[i], 0);
65711 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
65712 for_each_possible_cpu(cpu) {
65713 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65714 per_cpu(rcu_torture_count, cpu)[i] = 0;
65715 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
65716 index 6b76d81..7afc1b3 100644
65717 --- a/kernel/rcutree.c
65718 +++ b/kernel/rcutree.c
65719 @@ -367,9 +367,9 @@ void rcu_enter_nohz(void)
65720 trace_rcu_dyntick("Start");
65721 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
65722 smp_mb__before_atomic_inc(); /* See above. */
65723 - atomic_inc(&rdtp->dynticks);
65724 + atomic_inc_unchecked(&rdtp->dynticks);
65725 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
65726 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
65727 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
65728 local_irq_restore(flags);
65729 }
65730
65731 @@ -391,10 +391,10 @@ void rcu_exit_nohz(void)
65732 return;
65733 }
65734 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
65735 - atomic_inc(&rdtp->dynticks);
65736 + atomic_inc_unchecked(&rdtp->dynticks);
65737 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
65738 smp_mb__after_atomic_inc(); /* See above. */
65739 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
65740 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
65741 trace_rcu_dyntick("End");
65742 local_irq_restore(flags);
65743 }
65744 @@ -411,14 +411,14 @@ void rcu_nmi_enter(void)
65745 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
65746
65747 if (rdtp->dynticks_nmi_nesting == 0 &&
65748 - (atomic_read(&rdtp->dynticks) & 0x1))
65749 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
65750 return;
65751 rdtp->dynticks_nmi_nesting++;
65752 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
65753 - atomic_inc(&rdtp->dynticks);
65754 + atomic_inc_unchecked(&rdtp->dynticks);
65755 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
65756 smp_mb__after_atomic_inc(); /* See above. */
65757 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
65758 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
65759 }
65760
65761 /**
65762 @@ -437,9 +437,9 @@ void rcu_nmi_exit(void)
65763 return;
65764 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
65765 smp_mb__before_atomic_inc(); /* See above. */
65766 - atomic_inc(&rdtp->dynticks);
65767 + atomic_inc_unchecked(&rdtp->dynticks);
65768 smp_mb__after_atomic_inc(); /* Force delay to next write. */
65769 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
65770 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
65771 }
65772
65773 /**
65774 @@ -474,7 +474,7 @@ void rcu_irq_exit(void)
65775 */
65776 static int dyntick_save_progress_counter(struct rcu_data *rdp)
65777 {
65778 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
65779 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
65780 return 0;
65781 }
65782
65783 @@ -489,7 +489,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
65784 unsigned int curr;
65785 unsigned int snap;
65786
65787 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
65788 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
65789 snap = (unsigned int)rdp->dynticks_snap;
65790
65791 /*
65792 @@ -1552,7 +1552,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
65793 /*
65794 * Do RCU core processing for the current CPU.
65795 */
65796 -static void rcu_process_callbacks(struct softirq_action *unused)
65797 +static void rcu_process_callbacks(void)
65798 {
65799 trace_rcu_utilization("Start RCU core");
65800 __rcu_process_callbacks(&rcu_sched_state,
65801 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
65802 index 849ce9e..74bc9de 100644
65803 --- a/kernel/rcutree.h
65804 +++ b/kernel/rcutree.h
65805 @@ -86,7 +86,7 @@
65806 struct rcu_dynticks {
65807 int dynticks_nesting; /* Track irq/process nesting level. */
65808 int dynticks_nmi_nesting; /* Track NMI nesting level. */
65809 - atomic_t dynticks; /* Even value for dynticks-idle, else odd. */
65810 + atomic_unchecked_t dynticks; /* Even value for dynticks-idle, else odd. */
65811 };
65812
65813 /* RCU's kthread states for tracing. */
65814 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
65815 index 4b9b9f8..2326053 100644
65816 --- a/kernel/rcutree_plugin.h
65817 +++ b/kernel/rcutree_plugin.h
65818 @@ -842,7 +842,7 @@ void synchronize_rcu_expedited(void)
65819
65820 /* Clean up and exit. */
65821 smp_mb(); /* ensure expedited GP seen before counter increment. */
65822 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
65823 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
65824 unlock_mb_ret:
65825 mutex_unlock(&sync_rcu_preempt_exp_mutex);
65826 mb_ret:
65827 @@ -1815,8 +1815,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
65828
65829 #else /* #ifndef CONFIG_SMP */
65830
65831 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
65832 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
65833 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
65834 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
65835
65836 static int synchronize_sched_expedited_cpu_stop(void *data)
65837 {
65838 @@ -1871,7 +1871,7 @@ void synchronize_sched_expedited(void)
65839 int firstsnap, s, snap, trycount = 0;
65840
65841 /* Note that atomic_inc_return() implies full memory barrier. */
65842 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
65843 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
65844 get_online_cpus();
65845
65846 /*
65847 @@ -1892,7 +1892,7 @@ void synchronize_sched_expedited(void)
65848 }
65849
65850 /* Check to see if someone else did our work for us. */
65851 - s = atomic_read(&sync_sched_expedited_done);
65852 + s = atomic_read_unchecked(&sync_sched_expedited_done);
65853 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
65854 smp_mb(); /* ensure test happens before caller kfree */
65855 return;
65856 @@ -1907,7 +1907,7 @@ void synchronize_sched_expedited(void)
65857 * grace period works for us.
65858 */
65859 get_online_cpus();
65860 - snap = atomic_read(&sync_sched_expedited_started) - 1;
65861 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
65862 smp_mb(); /* ensure read is before try_stop_cpus(). */
65863 }
65864
65865 @@ -1918,12 +1918,12 @@ void synchronize_sched_expedited(void)
65866 * than we did beat us to the punch.
65867 */
65868 do {
65869 - s = atomic_read(&sync_sched_expedited_done);
65870 + s = atomic_read_unchecked(&sync_sched_expedited_done);
65871 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
65872 smp_mb(); /* ensure test happens before caller kfree */
65873 break;
65874 }
65875 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
65876 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
65877
65878 put_online_cpus();
65879 }
65880 @@ -1985,7 +1985,7 @@ int rcu_needs_cpu(int cpu)
65881 for_each_online_cpu(thatcpu) {
65882 if (thatcpu == cpu)
65883 continue;
65884 - snap = atomic_add_return(0, &per_cpu(rcu_dynticks,
65885 + snap = atomic_add_return_unchecked(0, &per_cpu(rcu_dynticks,
65886 thatcpu).dynticks);
65887 smp_mb(); /* Order sampling of snap with end of grace period. */
65888 if ((snap & 0x1) != 0) {
65889 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
65890 index 9feffa4..54058df 100644
65891 --- a/kernel/rcutree_trace.c
65892 +++ b/kernel/rcutree_trace.c
65893 @@ -69,7 +69,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
65894 rdp->qs_pending);
65895 #ifdef CONFIG_NO_HZ
65896 seq_printf(m, " dt=%d/%d/%d df=%lu",
65897 - atomic_read(&rdp->dynticks->dynticks),
65898 + atomic_read_unchecked(&rdp->dynticks->dynticks),
65899 rdp->dynticks->dynticks_nesting,
65900 rdp->dynticks->dynticks_nmi_nesting,
65901 rdp->dynticks_fqs);
65902 @@ -143,7 +143,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
65903 rdp->qs_pending);
65904 #ifdef CONFIG_NO_HZ
65905 seq_printf(m, ",%d,%d,%d,%lu",
65906 - atomic_read(&rdp->dynticks->dynticks),
65907 + atomic_read_unchecked(&rdp->dynticks->dynticks),
65908 rdp->dynticks->dynticks_nesting,
65909 rdp->dynticks->dynticks_nmi_nesting,
65910 rdp->dynticks_fqs);
65911 diff --git a/kernel/resource.c b/kernel/resource.c
65912 index 7640b3a..5879283 100644
65913 --- a/kernel/resource.c
65914 +++ b/kernel/resource.c
65915 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
65916
65917 static int __init ioresources_init(void)
65918 {
65919 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
65920 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65921 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
65922 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
65923 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65924 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
65925 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
65926 +#endif
65927 +#else
65928 proc_create("ioports", 0, NULL, &proc_ioports_operations);
65929 proc_create("iomem", 0, NULL, &proc_iomem_operations);
65930 +#endif
65931 return 0;
65932 }
65933 __initcall(ioresources_init);
65934 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
65935 index 3d9f31c..7fefc9e 100644
65936 --- a/kernel/rtmutex-tester.c
65937 +++ b/kernel/rtmutex-tester.c
65938 @@ -20,7 +20,7 @@
65939 #define MAX_RT_TEST_MUTEXES 8
65940
65941 static spinlock_t rttest_lock;
65942 -static atomic_t rttest_event;
65943 +static atomic_unchecked_t rttest_event;
65944
65945 struct test_thread_data {
65946 int opcode;
65947 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
65948
65949 case RTTEST_LOCKCONT:
65950 td->mutexes[td->opdata] = 1;
65951 - td->event = atomic_add_return(1, &rttest_event);
65952 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65953 return 0;
65954
65955 case RTTEST_RESET:
65956 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
65957 return 0;
65958
65959 case RTTEST_RESETEVENT:
65960 - atomic_set(&rttest_event, 0);
65961 + atomic_set_unchecked(&rttest_event, 0);
65962 return 0;
65963
65964 default:
65965 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
65966 return ret;
65967
65968 td->mutexes[id] = 1;
65969 - td->event = atomic_add_return(1, &rttest_event);
65970 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65971 rt_mutex_lock(&mutexes[id]);
65972 - td->event = atomic_add_return(1, &rttest_event);
65973 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65974 td->mutexes[id] = 4;
65975 return 0;
65976
65977 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
65978 return ret;
65979
65980 td->mutexes[id] = 1;
65981 - td->event = atomic_add_return(1, &rttest_event);
65982 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65983 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
65984 - td->event = atomic_add_return(1, &rttest_event);
65985 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65986 td->mutexes[id] = ret ? 0 : 4;
65987 return ret ? -EINTR : 0;
65988
65989 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
65990 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
65991 return ret;
65992
65993 - td->event = atomic_add_return(1, &rttest_event);
65994 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65995 rt_mutex_unlock(&mutexes[id]);
65996 - td->event = atomic_add_return(1, &rttest_event);
65997 + td->event = atomic_add_return_unchecked(1, &rttest_event);
65998 td->mutexes[id] = 0;
65999 return 0;
66000
66001 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
66002 break;
66003
66004 td->mutexes[dat] = 2;
66005 - td->event = atomic_add_return(1, &rttest_event);
66006 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66007 break;
66008
66009 default:
66010 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
66011 return;
66012
66013 td->mutexes[dat] = 3;
66014 - td->event = atomic_add_return(1, &rttest_event);
66015 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66016 break;
66017
66018 case RTTEST_LOCKNOWAIT:
66019 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
66020 return;
66021
66022 td->mutexes[dat] = 1;
66023 - td->event = atomic_add_return(1, &rttest_event);
66024 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66025 return;
66026
66027 default:
66028 diff --git a/kernel/sched.c b/kernel/sched.c
66029 index d6b149c..896cbb8 100644
66030 --- a/kernel/sched.c
66031 +++ b/kernel/sched.c
66032 @@ -4389,6 +4389,19 @@ pick_next_task(struct rq *rq)
66033 BUG(); /* the idle class will always have a runnable task */
66034 }
66035
66036 +#ifdef CONFIG_GRKERNSEC_SETXID
66037 +extern void gr_delayed_cred_worker(void);
66038 +static inline void gr_cred_schedule(void)
66039 +{
66040 + if (unlikely(current->delayed_cred))
66041 + gr_delayed_cred_worker();
66042 +}
66043 +#else
66044 +static inline void gr_cred_schedule(void)
66045 +{
66046 +}
66047 +#endif
66048 +
66049 /*
66050 * __schedule() is the main scheduler function.
66051 */
66052 @@ -4408,6 +4421,8 @@ need_resched:
66053
66054 schedule_debug(prev);
66055
66056 + gr_cred_schedule();
66057 +
66058 if (sched_feat(HRTICK))
66059 hrtick_clear(rq);
66060
66061 @@ -5098,6 +5113,8 @@ int can_nice(const struct task_struct *p, const int nice)
66062 /* convert nice value [19,-20] to rlimit style value [1,40] */
66063 int nice_rlim = 20 - nice;
66064
66065 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
66066 +
66067 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
66068 capable(CAP_SYS_NICE));
66069 }
66070 @@ -5131,7 +5148,8 @@ SYSCALL_DEFINE1(nice, int, increment)
66071 if (nice > 19)
66072 nice = 19;
66073
66074 - if (increment < 0 && !can_nice(current, nice))
66075 + if (increment < 0 && (!can_nice(current, nice) ||
66076 + gr_handle_chroot_nice()))
66077 return -EPERM;
66078
66079 retval = security_task_setnice(current, nice);
66080 @@ -5288,6 +5306,7 @@ recheck:
66081 unsigned long rlim_rtprio =
66082 task_rlimit(p, RLIMIT_RTPRIO);
66083
66084 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
66085 /* can't set/change the rt policy */
66086 if (policy != p->policy && !rlim_rtprio)
66087 return -EPERM;
66088 diff --git a/kernel/sched_autogroup.c b/kernel/sched_autogroup.c
66089 index 429242f..d7cca82 100644
66090 --- a/kernel/sched_autogroup.c
66091 +++ b/kernel/sched_autogroup.c
66092 @@ -7,7 +7,7 @@
66093
66094 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
66095 static struct autogroup autogroup_default;
66096 -static atomic_t autogroup_seq_nr;
66097 +static atomic_unchecked_t autogroup_seq_nr;
66098
66099 static void __init autogroup_init(struct task_struct *init_task)
66100 {
66101 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
66102
66103 kref_init(&ag->kref);
66104 init_rwsem(&ag->lock);
66105 - ag->id = atomic_inc_return(&autogroup_seq_nr);
66106 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
66107 ag->tg = tg;
66108 #ifdef CONFIG_RT_GROUP_SCHED
66109 /*
66110 diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
66111 index 8a39fa3..34f3dbc 100644
66112 --- a/kernel/sched_fair.c
66113 +++ b/kernel/sched_fair.c
66114 @@ -4801,7 +4801,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
66115 * run_rebalance_domains is triggered when needed from the scheduler tick.
66116 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
66117 */
66118 -static void run_rebalance_domains(struct softirq_action *h)
66119 +static void run_rebalance_domains(void)
66120 {
66121 int this_cpu = smp_processor_id();
66122 struct rq *this_rq = cpu_rq(this_cpu);
66123 diff --git a/kernel/signal.c b/kernel/signal.c
66124 index 2065515..aed2987 100644
66125 --- a/kernel/signal.c
66126 +++ b/kernel/signal.c
66127 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cachep;
66128
66129 int print_fatal_signals __read_mostly;
66130
66131 -static void __user *sig_handler(struct task_struct *t, int sig)
66132 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
66133 {
66134 return t->sighand->action[sig - 1].sa.sa_handler;
66135 }
66136
66137 -static int sig_handler_ignored(void __user *handler, int sig)
66138 +static int sig_handler_ignored(__sighandler_t handler, int sig)
66139 {
66140 /* Is it explicitly or implicitly ignored? */
66141 return handler == SIG_IGN ||
66142 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
66143 static int sig_task_ignored(struct task_struct *t, int sig,
66144 int from_ancestor_ns)
66145 {
66146 - void __user *handler;
66147 + __sighandler_t handler;
66148
66149 handler = sig_handler(t, sig);
66150
66151 @@ -364,6 +364,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
66152 atomic_inc(&user->sigpending);
66153 rcu_read_unlock();
66154
66155 + if (!override_rlimit)
66156 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
66157 +
66158 if (override_rlimit ||
66159 atomic_read(&user->sigpending) <=
66160 task_rlimit(t, RLIMIT_SIGPENDING)) {
66161 @@ -488,7 +491,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
66162
66163 int unhandled_signal(struct task_struct *tsk, int sig)
66164 {
66165 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
66166 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
66167 if (is_global_init(tsk))
66168 return 1;
66169 if (handler != SIG_IGN && handler != SIG_DFL)
66170 @@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
66171 }
66172 }
66173
66174 + /* allow glibc communication via tgkill to other threads in our
66175 + thread group */
66176 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
66177 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
66178 + && gr_handle_signal(t, sig))
66179 + return -EPERM;
66180 +
66181 return security_task_kill(t, info, sig, 0);
66182 }
66183
66184 @@ -1165,7 +1175,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
66185 return send_signal(sig, info, p, 1);
66186 }
66187
66188 -static int
66189 +int
66190 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66191 {
66192 return send_signal(sig, info, t, 0);
66193 @@ -1202,6 +1212,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66194 unsigned long int flags;
66195 int ret, blocked, ignored;
66196 struct k_sigaction *action;
66197 + int is_unhandled = 0;
66198
66199 spin_lock_irqsave(&t->sighand->siglock, flags);
66200 action = &t->sighand->action[sig-1];
66201 @@ -1216,9 +1227,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66202 }
66203 if (action->sa.sa_handler == SIG_DFL)
66204 t->signal->flags &= ~SIGNAL_UNKILLABLE;
66205 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
66206 + is_unhandled = 1;
66207 ret = specific_send_sig_info(sig, info, t);
66208 spin_unlock_irqrestore(&t->sighand->siglock, flags);
66209
66210 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
66211 + normal operation */
66212 + if (is_unhandled) {
66213 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
66214 + gr_handle_crash(t, sig);
66215 + }
66216 +
66217 return ret;
66218 }
66219
66220 @@ -1285,8 +1305,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
66221 ret = check_kill_permission(sig, info, p);
66222 rcu_read_unlock();
66223
66224 - if (!ret && sig)
66225 + if (!ret && sig) {
66226 ret = do_send_sig_info(sig, info, p, true);
66227 + if (!ret)
66228 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
66229 + }
66230
66231 return ret;
66232 }
66233 @@ -2754,7 +2777,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
66234 int error = -ESRCH;
66235
66236 rcu_read_lock();
66237 - p = find_task_by_vpid(pid);
66238 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66239 + /* allow glibc communication via tgkill to other threads in our
66240 + thread group */
66241 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
66242 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
66243 + p = find_task_by_vpid_unrestricted(pid);
66244 + else
66245 +#endif
66246 + p = find_task_by_vpid(pid);
66247 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
66248 error = check_kill_permission(sig, info, p);
66249 /*
66250 diff --git a/kernel/smp.c b/kernel/smp.c
66251 index db197d6..17aef0b 100644
66252 --- a/kernel/smp.c
66253 +++ b/kernel/smp.c
66254 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
66255 }
66256 EXPORT_SYMBOL(smp_call_function);
66257
66258 -void ipi_call_lock(void)
66259 +void ipi_call_lock(void) __acquires(call_function.lock)
66260 {
66261 raw_spin_lock(&call_function.lock);
66262 }
66263
66264 -void ipi_call_unlock(void)
66265 +void ipi_call_unlock(void) __releases(call_function.lock)
66266 {
66267 raw_spin_unlock(&call_function.lock);
66268 }
66269
66270 -void ipi_call_lock_irq(void)
66271 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
66272 {
66273 raw_spin_lock_irq(&call_function.lock);
66274 }
66275
66276 -void ipi_call_unlock_irq(void)
66277 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
66278 {
66279 raw_spin_unlock_irq(&call_function.lock);
66280 }
66281 diff --git a/kernel/softirq.c b/kernel/softirq.c
66282 index 2c71d91..1021f81 100644
66283 --- a/kernel/softirq.c
66284 +++ b/kernel/softirq.c
66285 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
66286
66287 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
66288
66289 -char *softirq_to_name[NR_SOFTIRQS] = {
66290 +const char * const softirq_to_name[NR_SOFTIRQS] = {
66291 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
66292 "TASKLET", "SCHED", "HRTIMER", "RCU"
66293 };
66294 @@ -235,7 +235,7 @@ restart:
66295 kstat_incr_softirqs_this_cpu(vec_nr);
66296
66297 trace_softirq_entry(vec_nr);
66298 - h->action(h);
66299 + h->action();
66300 trace_softirq_exit(vec_nr);
66301 if (unlikely(prev_count != preempt_count())) {
66302 printk(KERN_ERR "huh, entered softirq %u %s %p"
66303 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
66304 local_irq_restore(flags);
66305 }
66306
66307 -void open_softirq(int nr, void (*action)(struct softirq_action *))
66308 +void open_softirq(int nr, void (*action)(void))
66309 {
66310 - softirq_vec[nr].action = action;
66311 + pax_open_kernel();
66312 + *(void **)&softirq_vec[nr].action = action;
66313 + pax_close_kernel();
66314 }
66315
66316 /*
66317 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
66318
66319 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
66320
66321 -static void tasklet_action(struct softirq_action *a)
66322 +static void tasklet_action(void)
66323 {
66324 struct tasklet_struct *list;
66325
66326 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
66327 }
66328 }
66329
66330 -static void tasklet_hi_action(struct softirq_action *a)
66331 +static void tasklet_hi_action(void)
66332 {
66333 struct tasklet_struct *list;
66334
66335 diff --git a/kernel/sys.c b/kernel/sys.c
66336 index 481611f..0754d86 100644
66337 --- a/kernel/sys.c
66338 +++ b/kernel/sys.c
66339 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
66340 error = -EACCES;
66341 goto out;
66342 }
66343 +
66344 + if (gr_handle_chroot_setpriority(p, niceval)) {
66345 + error = -EACCES;
66346 + goto out;
66347 + }
66348 +
66349 no_nice = security_task_setnice(p, niceval);
66350 if (no_nice) {
66351 error = no_nice;
66352 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
66353 goto error;
66354 }
66355
66356 + if (gr_check_group_change(new->gid, new->egid, -1))
66357 + goto error;
66358 +
66359 if (rgid != (gid_t) -1 ||
66360 (egid != (gid_t) -1 && egid != old->gid))
66361 new->sgid = new->egid;
66362 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
66363 old = current_cred();
66364
66365 retval = -EPERM;
66366 +
66367 + if (gr_check_group_change(gid, gid, gid))
66368 + goto error;
66369 +
66370 if (nsown_capable(CAP_SETGID))
66371 new->gid = new->egid = new->sgid = new->fsgid = gid;
66372 else if (gid == old->gid || gid == old->sgid)
66373 @@ -618,7 +631,7 @@ error:
66374 /*
66375 * change the user struct in a credentials set to match the new UID
66376 */
66377 -static int set_user(struct cred *new)
66378 +int set_user(struct cred *new)
66379 {
66380 struct user_struct *new_user;
66381
66382 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
66383 goto error;
66384 }
66385
66386 + if (gr_check_user_change(new->uid, new->euid, -1))
66387 + goto error;
66388 +
66389 if (new->uid != old->uid) {
66390 retval = set_user(new);
66391 if (retval < 0)
66392 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
66393 old = current_cred();
66394
66395 retval = -EPERM;
66396 +
66397 + if (gr_check_crash_uid(uid))
66398 + goto error;
66399 + if (gr_check_user_change(uid, uid, uid))
66400 + goto error;
66401 +
66402 if (nsown_capable(CAP_SETUID)) {
66403 new->suid = new->uid = uid;
66404 if (uid != old->uid) {
66405 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
66406 goto error;
66407 }
66408
66409 + if (gr_check_user_change(ruid, euid, -1))
66410 + goto error;
66411 +
66412 if (ruid != (uid_t) -1) {
66413 new->uid = ruid;
66414 if (ruid != old->uid) {
66415 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
66416 goto error;
66417 }
66418
66419 + if (gr_check_group_change(rgid, egid, -1))
66420 + goto error;
66421 +
66422 if (rgid != (gid_t) -1)
66423 new->gid = rgid;
66424 if (egid != (gid_t) -1)
66425 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
66426 old = current_cred();
66427 old_fsuid = old->fsuid;
66428
66429 + if (gr_check_user_change(-1, -1, uid))
66430 + goto error;
66431 +
66432 if (uid == old->uid || uid == old->euid ||
66433 uid == old->suid || uid == old->fsuid ||
66434 nsown_capable(CAP_SETUID)) {
66435 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
66436 }
66437 }
66438
66439 +error:
66440 abort_creds(new);
66441 return old_fsuid;
66442
66443 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
66444 if (gid == old->gid || gid == old->egid ||
66445 gid == old->sgid || gid == old->fsgid ||
66446 nsown_capable(CAP_SETGID)) {
66447 + if (gr_check_group_change(-1, -1, gid))
66448 + goto error;
66449 +
66450 if (gid != old_fsgid) {
66451 new->fsgid = gid;
66452 goto change_okay;
66453 }
66454 }
66455
66456 +error:
66457 abort_creds(new);
66458 return old_fsgid;
66459
66460 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
66461 }
66462 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
66463 snprintf(buf, len, "2.6.%u%s", v, rest);
66464 - ret = copy_to_user(release, buf, len);
66465 + if (len > sizeof(buf))
66466 + ret = -EFAULT;
66467 + else
66468 + ret = copy_to_user(release, buf, len);
66469 }
66470 return ret;
66471 }
66472 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
66473 return -EFAULT;
66474
66475 down_read(&uts_sem);
66476 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
66477 + error = __copy_to_user(name->sysname, &utsname()->sysname,
66478 __OLD_UTS_LEN);
66479 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
66480 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
66481 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
66482 __OLD_UTS_LEN);
66483 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
66484 - error |= __copy_to_user(&name->release, &utsname()->release,
66485 + error |= __copy_to_user(name->release, &utsname()->release,
66486 __OLD_UTS_LEN);
66487 error |= __put_user(0, name->release + __OLD_UTS_LEN);
66488 - error |= __copy_to_user(&name->version, &utsname()->version,
66489 + error |= __copy_to_user(name->version, &utsname()->version,
66490 __OLD_UTS_LEN);
66491 error |= __put_user(0, name->version + __OLD_UTS_LEN);
66492 - error |= __copy_to_user(&name->machine, &utsname()->machine,
66493 + error |= __copy_to_user(name->machine, &utsname()->machine,
66494 __OLD_UTS_LEN);
66495 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
66496 up_read(&uts_sem);
66497 @@ -1720,7 +1759,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
66498 error = get_dumpable(me->mm);
66499 break;
66500 case PR_SET_DUMPABLE:
66501 - if (arg2 < 0 || arg2 > 1) {
66502 + if (arg2 > 1) {
66503 error = -EINVAL;
66504 break;
66505 }
66506 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
66507 index ae27196..7506d69 100644
66508 --- a/kernel/sysctl.c
66509 +++ b/kernel/sysctl.c
66510 @@ -86,6 +86,13 @@
66511
66512
66513 #if defined(CONFIG_SYSCTL)
66514 +#include <linux/grsecurity.h>
66515 +#include <linux/grinternal.h>
66516 +
66517 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
66518 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66519 + const int op);
66520 +extern int gr_handle_chroot_sysctl(const int op);
66521
66522 /* External variables not in a header file. */
66523 extern int sysctl_overcommit_memory;
66524 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
66525 }
66526
66527 #endif
66528 +extern struct ctl_table grsecurity_table[];
66529
66530 static struct ctl_table root_table[];
66531 static struct ctl_table_root sysctl_table_root;
66532 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
66533 int sysctl_legacy_va_layout;
66534 #endif
66535
66536 +#ifdef CONFIG_PAX_SOFTMODE
66537 +static ctl_table pax_table[] = {
66538 + {
66539 + .procname = "softmode",
66540 + .data = &pax_softmode,
66541 + .maxlen = sizeof(unsigned int),
66542 + .mode = 0600,
66543 + .proc_handler = &proc_dointvec,
66544 + },
66545 +
66546 + { }
66547 +};
66548 +#endif
66549 +
66550 /* The default sysctl tables: */
66551
66552 static struct ctl_table root_table[] = {
66553 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
66554 #endif
66555
66556 static struct ctl_table kern_table[] = {
66557 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66558 + {
66559 + .procname = "grsecurity",
66560 + .mode = 0500,
66561 + .child = grsecurity_table,
66562 + },
66563 +#endif
66564 +
66565 +#ifdef CONFIG_PAX_SOFTMODE
66566 + {
66567 + .procname = "pax",
66568 + .mode = 0500,
66569 + .child = pax_table,
66570 + },
66571 +#endif
66572 +
66573 {
66574 .procname = "sched_child_runs_first",
66575 .data = &sysctl_sched_child_runs_first,
66576 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
66577 .data = &modprobe_path,
66578 .maxlen = KMOD_PATH_LEN,
66579 .mode = 0644,
66580 - .proc_handler = proc_dostring,
66581 + .proc_handler = proc_dostring_modpriv,
66582 },
66583 {
66584 .procname = "modules_disabled",
66585 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
66586 .extra1 = &zero,
66587 .extra2 = &one,
66588 },
66589 +#endif
66590 {
66591 .procname = "kptr_restrict",
66592 .data = &kptr_restrict,
66593 .maxlen = sizeof(int),
66594 .mode = 0644,
66595 .proc_handler = proc_dmesg_restrict,
66596 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66597 + .extra1 = &two,
66598 +#else
66599 .extra1 = &zero,
66600 +#endif
66601 .extra2 = &two,
66602 },
66603 -#endif
66604 {
66605 .procname = "ngroups_max",
66606 .data = &ngroups_max,
66607 @@ -1216,6 +1258,13 @@ static struct ctl_table vm_table[] = {
66608 .proc_handler = proc_dointvec_minmax,
66609 .extra1 = &zero,
66610 },
66611 + {
66612 + .procname = "heap_stack_gap",
66613 + .data = &sysctl_heap_stack_gap,
66614 + .maxlen = sizeof(sysctl_heap_stack_gap),
66615 + .mode = 0644,
66616 + .proc_handler = proc_doulongvec_minmax,
66617 + },
66618 #else
66619 {
66620 .procname = "nr_trim_pages",
66621 @@ -1720,6 +1769,17 @@ static int test_perm(int mode, int op)
66622 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
66623 {
66624 int mode;
66625 + int error;
66626 +
66627 + if (table->parent != NULL && table->parent->procname != NULL &&
66628 + table->procname != NULL &&
66629 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
66630 + return -EACCES;
66631 + if (gr_handle_chroot_sysctl(op))
66632 + return -EACCES;
66633 + error = gr_handle_sysctl(table, op);
66634 + if (error)
66635 + return error;
66636
66637 if (root->permissions)
66638 mode = root->permissions(root, current->nsproxy, table);
66639 @@ -2124,6 +2184,16 @@ int proc_dostring(struct ctl_table *table, int write,
66640 buffer, lenp, ppos);
66641 }
66642
66643 +int proc_dostring_modpriv(struct ctl_table *table, int write,
66644 + void __user *buffer, size_t *lenp, loff_t *ppos)
66645 +{
66646 + if (write && !capable(CAP_SYS_MODULE))
66647 + return -EPERM;
66648 +
66649 + return _proc_do_string(table->data, table->maxlen, write,
66650 + buffer, lenp, ppos);
66651 +}
66652 +
66653 static size_t proc_skip_spaces(char **buf)
66654 {
66655 size_t ret;
66656 @@ -2229,6 +2299,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
66657 len = strlen(tmp);
66658 if (len > *size)
66659 len = *size;
66660 + if (len > sizeof(tmp))
66661 + len = sizeof(tmp);
66662 if (copy_to_user(*buf, tmp, len))
66663 return -EFAULT;
66664 *size -= len;
66665 @@ -2545,8 +2617,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
66666 *i = val;
66667 } else {
66668 val = convdiv * (*i) / convmul;
66669 - if (!first)
66670 + if (!first) {
66671 err = proc_put_char(&buffer, &left, '\t');
66672 + if (err)
66673 + break;
66674 + }
66675 err = proc_put_long(&buffer, &left, val, false);
66676 if (err)
66677 break;
66678 @@ -2941,6 +3016,12 @@ int proc_dostring(struct ctl_table *table, int write,
66679 return -ENOSYS;
66680 }
66681
66682 +int proc_dostring_modpriv(struct ctl_table *table, int write,
66683 + void __user *buffer, size_t *lenp, loff_t *ppos)
66684 +{
66685 + return -ENOSYS;
66686 +}
66687 +
66688 int proc_dointvec(struct ctl_table *table, int write,
66689 void __user *buffer, size_t *lenp, loff_t *ppos)
66690 {
66691 @@ -2997,6 +3078,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
66692 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
66693 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
66694 EXPORT_SYMBOL(proc_dostring);
66695 +EXPORT_SYMBOL(proc_dostring_modpriv);
66696 EXPORT_SYMBOL(proc_doulongvec_minmax);
66697 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
66698 EXPORT_SYMBOL(register_sysctl_table);
66699 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
66700 index a650694..aaeeb20 100644
66701 --- a/kernel/sysctl_binary.c
66702 +++ b/kernel/sysctl_binary.c
66703 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
66704 int i;
66705
66706 set_fs(KERNEL_DS);
66707 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
66708 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
66709 set_fs(old_fs);
66710 if (result < 0)
66711 goto out_kfree;
66712 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
66713 }
66714
66715 set_fs(KERNEL_DS);
66716 - result = vfs_write(file, buffer, str - buffer, &pos);
66717 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
66718 set_fs(old_fs);
66719 if (result < 0)
66720 goto out_kfree;
66721 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
66722 int i;
66723
66724 set_fs(KERNEL_DS);
66725 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
66726 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
66727 set_fs(old_fs);
66728 if (result < 0)
66729 goto out_kfree;
66730 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
66731 }
66732
66733 set_fs(KERNEL_DS);
66734 - result = vfs_write(file, buffer, str - buffer, &pos);
66735 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
66736 set_fs(old_fs);
66737 if (result < 0)
66738 goto out_kfree;
66739 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
66740 int i;
66741
66742 set_fs(KERNEL_DS);
66743 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
66744 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
66745 set_fs(old_fs);
66746 if (result < 0)
66747 goto out;
66748 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
66749 __le16 dnaddr;
66750
66751 set_fs(KERNEL_DS);
66752 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
66753 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
66754 set_fs(old_fs);
66755 if (result < 0)
66756 goto out;
66757 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
66758 le16_to_cpu(dnaddr) & 0x3ff);
66759
66760 set_fs(KERNEL_DS);
66761 - result = vfs_write(file, buf, len, &pos);
66762 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
66763 set_fs(old_fs);
66764 if (result < 0)
66765 goto out;
66766 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
66767 index 362da65..ab8ef8c 100644
66768 --- a/kernel/sysctl_check.c
66769 +++ b/kernel/sysctl_check.c
66770 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
66771 set_fail(&fail, table, "Directory with extra2");
66772 } else {
66773 if ((table->proc_handler == proc_dostring) ||
66774 + (table->proc_handler == proc_dostring_modpriv) ||
66775 (table->proc_handler == proc_dointvec) ||
66776 (table->proc_handler == proc_dointvec_minmax) ||
66777 (table->proc_handler == proc_dointvec_jiffies) ||
66778 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
66779 index e660464..c8b9e67 100644
66780 --- a/kernel/taskstats.c
66781 +++ b/kernel/taskstats.c
66782 @@ -27,9 +27,12 @@
66783 #include <linux/cgroup.h>
66784 #include <linux/fs.h>
66785 #include <linux/file.h>
66786 +#include <linux/grsecurity.h>
66787 #include <net/genetlink.h>
66788 #include <linux/atomic.h>
66789
66790 +extern int gr_is_taskstats_denied(int pid);
66791 +
66792 /*
66793 * Maximum length of a cpumask that can be specified in
66794 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
66795 @@ -556,6 +559,9 @@ err:
66796
66797 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
66798 {
66799 + if (gr_is_taskstats_denied(current->pid))
66800 + return -EACCES;
66801 +
66802 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
66803 return cmd_attr_register_cpumask(info);
66804 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
66805 diff --git a/kernel/time.c b/kernel/time.c
66806 index 73e416d..cfc6f69 100644
66807 --- a/kernel/time.c
66808 +++ b/kernel/time.c
66809 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
66810 return error;
66811
66812 if (tz) {
66813 + /* we log in do_settimeofday called below, so don't log twice
66814 + */
66815 + if (!tv)
66816 + gr_log_timechange();
66817 +
66818 /* SMP safe, global irq locking makes it work. */
66819 sys_tz = *tz;
66820 update_vsyscall_tz();
66821 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
66822 index 8a46f5d..bbe6f9c 100644
66823 --- a/kernel/time/alarmtimer.c
66824 +++ b/kernel/time/alarmtimer.c
66825 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
66826 struct platform_device *pdev;
66827 int error = 0;
66828 int i;
66829 - struct k_clock alarm_clock = {
66830 + static struct k_clock alarm_clock = {
66831 .clock_getres = alarm_clock_getres,
66832 .clock_get = alarm_clock_get,
66833 .timer_create = alarm_timer_create,
66834 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
66835 index fd4a7b1..fae5c2a 100644
66836 --- a/kernel/time/tick-broadcast.c
66837 +++ b/kernel/time/tick-broadcast.c
66838 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
66839 * then clear the broadcast bit.
66840 */
66841 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
66842 - int cpu = smp_processor_id();
66843 + cpu = smp_processor_id();
66844
66845 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
66846 tick_broadcast_clear_oneshot(cpu);
66847 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
66848 index 2378413..be455fd 100644
66849 --- a/kernel/time/timekeeping.c
66850 +++ b/kernel/time/timekeeping.c
66851 @@ -14,6 +14,7 @@
66852 #include <linux/init.h>
66853 #include <linux/mm.h>
66854 #include <linux/sched.h>
66855 +#include <linux/grsecurity.h>
66856 #include <linux/syscore_ops.h>
66857 #include <linux/clocksource.h>
66858 #include <linux/jiffies.h>
66859 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
66860 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
66861 return -EINVAL;
66862
66863 + gr_log_timechange();
66864 +
66865 write_seqlock_irqsave(&xtime_lock, flags);
66866
66867 timekeeping_forward_now();
66868 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
66869 index 3258455..f35227d 100644
66870 --- a/kernel/time/timer_list.c
66871 +++ b/kernel/time/timer_list.c
66872 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
66873
66874 static void print_name_offset(struct seq_file *m, void *sym)
66875 {
66876 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66877 + SEQ_printf(m, "<%p>", NULL);
66878 +#else
66879 char symname[KSYM_NAME_LEN];
66880
66881 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
66882 SEQ_printf(m, "<%pK>", sym);
66883 else
66884 SEQ_printf(m, "%s", symname);
66885 +#endif
66886 }
66887
66888 static void
66889 @@ -112,7 +116,11 @@ next_one:
66890 static void
66891 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
66892 {
66893 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66894 + SEQ_printf(m, " .base: %p\n", NULL);
66895 +#else
66896 SEQ_printf(m, " .base: %pK\n", base);
66897 +#endif
66898 SEQ_printf(m, " .index: %d\n",
66899 base->index);
66900 SEQ_printf(m, " .resolution: %Lu nsecs\n",
66901 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
66902 {
66903 struct proc_dir_entry *pe;
66904
66905 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66906 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
66907 +#else
66908 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
66909 +#endif
66910 if (!pe)
66911 return -ENOMEM;
66912 return 0;
66913 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
66914 index 0b537f2..9e71eca 100644
66915 --- a/kernel/time/timer_stats.c
66916 +++ b/kernel/time/timer_stats.c
66917 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
66918 static unsigned long nr_entries;
66919 static struct entry entries[MAX_ENTRIES];
66920
66921 -static atomic_t overflow_count;
66922 +static atomic_unchecked_t overflow_count;
66923
66924 /*
66925 * The entries are in a hash-table, for fast lookup:
66926 @@ -140,7 +140,7 @@ static void reset_entries(void)
66927 nr_entries = 0;
66928 memset(entries, 0, sizeof(entries));
66929 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
66930 - atomic_set(&overflow_count, 0);
66931 + atomic_set_unchecked(&overflow_count, 0);
66932 }
66933
66934 static struct entry *alloc_entry(void)
66935 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
66936 if (likely(entry))
66937 entry->count++;
66938 else
66939 - atomic_inc(&overflow_count);
66940 + atomic_inc_unchecked(&overflow_count);
66941
66942 out_unlock:
66943 raw_spin_unlock_irqrestore(lock, flags);
66944 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
66945
66946 static void print_name_offset(struct seq_file *m, unsigned long addr)
66947 {
66948 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66949 + seq_printf(m, "<%p>", NULL);
66950 +#else
66951 char symname[KSYM_NAME_LEN];
66952
66953 if (lookup_symbol_name(addr, symname) < 0)
66954 seq_printf(m, "<%p>", (void *)addr);
66955 else
66956 seq_printf(m, "%s", symname);
66957 +#endif
66958 }
66959
66960 static int tstats_show(struct seq_file *m, void *v)
66961 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
66962
66963 seq_puts(m, "Timer Stats Version: v0.2\n");
66964 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
66965 - if (atomic_read(&overflow_count))
66966 + if (atomic_read_unchecked(&overflow_count))
66967 seq_printf(m, "Overflow: %d entries\n",
66968 - atomic_read(&overflow_count));
66969 + atomic_read_unchecked(&overflow_count));
66970
66971 for (i = 0; i < nr_entries; i++) {
66972 entry = entries + i;
66973 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
66974 {
66975 struct proc_dir_entry *pe;
66976
66977 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66978 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
66979 +#else
66980 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
66981 +#endif
66982 if (!pe)
66983 return -ENOMEM;
66984 return 0;
66985 diff --git a/kernel/timer.c b/kernel/timer.c
66986 index 9c3c62b..441690e 100644
66987 --- a/kernel/timer.c
66988 +++ b/kernel/timer.c
66989 @@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
66990 /*
66991 * This function runs timers and the timer-tq in bottom half context.
66992 */
66993 -static void run_timer_softirq(struct softirq_action *h)
66994 +static void run_timer_softirq(void)
66995 {
66996 struct tvec_base *base = __this_cpu_read(tvec_bases);
66997
66998 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
66999 index 16fc34a..efd8bb8 100644
67000 --- a/kernel/trace/blktrace.c
67001 +++ b/kernel/trace/blktrace.c
67002 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
67003 struct blk_trace *bt = filp->private_data;
67004 char buf[16];
67005
67006 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
67007 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
67008
67009 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
67010 }
67011 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
67012 return 1;
67013
67014 bt = buf->chan->private_data;
67015 - atomic_inc(&bt->dropped);
67016 + atomic_inc_unchecked(&bt->dropped);
67017 return 0;
67018 }
67019
67020 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
67021
67022 bt->dir = dir;
67023 bt->dev = dev;
67024 - atomic_set(&bt->dropped, 0);
67025 + atomic_set_unchecked(&bt->dropped, 0);
67026
67027 ret = -EIO;
67028 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
67029 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
67030 index 25b4f4d..6f4772d 100644
67031 --- a/kernel/trace/ftrace.c
67032 +++ b/kernel/trace/ftrace.c
67033 @@ -1587,12 +1587,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
67034 if (unlikely(ftrace_disabled))
67035 return 0;
67036
67037 + ret = ftrace_arch_code_modify_prepare();
67038 + FTRACE_WARN_ON(ret);
67039 + if (ret)
67040 + return 0;
67041 +
67042 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
67043 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
67044 if (ret) {
67045 ftrace_bug(ret, ip);
67046 - return 0;
67047 }
67048 - return 1;
67049 + return ret ? 0 : 1;
67050 }
67051
67052 /*
67053 @@ -2608,7 +2613,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
67054
67055 int
67056 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
67057 - void *data)
67058 + void *data)
67059 {
67060 struct ftrace_func_probe *entry;
67061 struct ftrace_page *pg;
67062 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
67063 index f2bd275..adaf3a2 100644
67064 --- a/kernel/trace/trace.c
67065 +++ b/kernel/trace/trace.c
67066 @@ -4201,10 +4201,9 @@ static const struct file_operations tracing_dyn_info_fops = {
67067 };
67068 #endif
67069
67070 -static struct dentry *d_tracer;
67071 -
67072 struct dentry *tracing_init_dentry(void)
67073 {
67074 + static struct dentry *d_tracer;
67075 static int once;
67076
67077 if (d_tracer)
67078 @@ -4224,10 +4223,9 @@ struct dentry *tracing_init_dentry(void)
67079 return d_tracer;
67080 }
67081
67082 -static struct dentry *d_percpu;
67083 -
67084 struct dentry *tracing_dentry_percpu(void)
67085 {
67086 + static struct dentry *d_percpu;
67087 static int once;
67088 struct dentry *d_tracer;
67089
67090 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
67091 index c212a7f..7b02394 100644
67092 --- a/kernel/trace/trace_events.c
67093 +++ b/kernel/trace/trace_events.c
67094 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
67095 struct ftrace_module_file_ops {
67096 struct list_head list;
67097 struct module *mod;
67098 - struct file_operations id;
67099 - struct file_operations enable;
67100 - struct file_operations format;
67101 - struct file_operations filter;
67102 };
67103
67104 static struct ftrace_module_file_ops *
67105 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
67106
67107 file_ops->mod = mod;
67108
67109 - file_ops->id = ftrace_event_id_fops;
67110 - file_ops->id.owner = mod;
67111 -
67112 - file_ops->enable = ftrace_enable_fops;
67113 - file_ops->enable.owner = mod;
67114 -
67115 - file_ops->filter = ftrace_event_filter_fops;
67116 - file_ops->filter.owner = mod;
67117 -
67118 - file_ops->format = ftrace_event_format_fops;
67119 - file_ops->format.owner = mod;
67120 + pax_open_kernel();
67121 + *(void **)&mod->trace_id.owner = mod;
67122 + *(void **)&mod->trace_enable.owner = mod;
67123 + *(void **)&mod->trace_filter.owner = mod;
67124 + *(void **)&mod->trace_format.owner = mod;
67125 + pax_close_kernel();
67126
67127 list_add(&file_ops->list, &ftrace_module_file_list);
67128
67129 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
67130
67131 for_each_event(call, start, end) {
67132 __trace_add_event_call(*call, mod,
67133 - &file_ops->id, &file_ops->enable,
67134 - &file_ops->filter, &file_ops->format);
67135 + &mod->trace_id, &mod->trace_enable,
67136 + &mod->trace_filter, &mod->trace_format);
67137 }
67138 }
67139
67140 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
67141 index 00d527c..7c5b1a3 100644
67142 --- a/kernel/trace/trace_kprobe.c
67143 +++ b/kernel/trace/trace_kprobe.c
67144 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67145 long ret;
67146 int maxlen = get_rloc_len(*(u32 *)dest);
67147 u8 *dst = get_rloc_data(dest);
67148 - u8 *src = addr;
67149 + const u8 __user *src = (const u8 __force_user *)addr;
67150 mm_segment_t old_fs = get_fs();
67151 if (!maxlen)
67152 return;
67153 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67154 pagefault_disable();
67155 do
67156 ret = __copy_from_user_inatomic(dst++, src++, 1);
67157 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
67158 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
67159 dst[-1] = '\0';
67160 pagefault_enable();
67161 set_fs(old_fs);
67162 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67163 ((u8 *)get_rloc_data(dest))[0] = '\0';
67164 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
67165 } else
67166 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
67167 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
67168 get_rloc_offs(*(u32 *)dest));
67169 }
67170 /* Return the length of string -- including null terminal byte */
67171 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
67172 set_fs(KERNEL_DS);
67173 pagefault_disable();
67174 do {
67175 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
67176 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
67177 len++;
67178 } while (c && ret == 0 && len < MAX_STRING_SIZE);
67179 pagefault_enable();
67180 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
67181 index fd3c8aa..5f324a6 100644
67182 --- a/kernel/trace/trace_mmiotrace.c
67183 +++ b/kernel/trace/trace_mmiotrace.c
67184 @@ -24,7 +24,7 @@ struct header_iter {
67185 static struct trace_array *mmio_trace_array;
67186 static bool overrun_detected;
67187 static unsigned long prev_overruns;
67188 -static atomic_t dropped_count;
67189 +static atomic_unchecked_t dropped_count;
67190
67191 static void mmio_reset_data(struct trace_array *tr)
67192 {
67193 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
67194
67195 static unsigned long count_overruns(struct trace_iterator *iter)
67196 {
67197 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
67198 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
67199 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
67200
67201 if (over > prev_overruns)
67202 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
67203 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
67204 sizeof(*entry), 0, pc);
67205 if (!event) {
67206 - atomic_inc(&dropped_count);
67207 + atomic_inc_unchecked(&dropped_count);
67208 return;
67209 }
67210 entry = ring_buffer_event_data(event);
67211 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
67212 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
67213 sizeof(*entry), 0, pc);
67214 if (!event) {
67215 - atomic_inc(&dropped_count);
67216 + atomic_inc_unchecked(&dropped_count);
67217 return;
67218 }
67219 entry = ring_buffer_event_data(event);
67220 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
67221 index 5199930..26c73a0 100644
67222 --- a/kernel/trace/trace_output.c
67223 +++ b/kernel/trace/trace_output.c
67224 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
67225
67226 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
67227 if (!IS_ERR(p)) {
67228 - p = mangle_path(s->buffer + s->len, p, "\n");
67229 + p = mangle_path(s->buffer + s->len, p, "\n\\");
67230 if (p) {
67231 s->len = p - s->buffer;
67232 return 1;
67233 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
67234 index 77575b3..6e623d1 100644
67235 --- a/kernel/trace/trace_stack.c
67236 +++ b/kernel/trace/trace_stack.c
67237 @@ -50,7 +50,7 @@ static inline void check_stack(void)
67238 return;
67239
67240 /* we do not handle interrupt stacks yet */
67241 - if (!object_is_on_stack(&this_size))
67242 + if (!object_starts_on_stack(&this_size))
67243 return;
67244
67245 local_irq_save(flags);
67246 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
67247 index 209b379..7f76423 100644
67248 --- a/kernel/trace/trace_workqueue.c
67249 +++ b/kernel/trace/trace_workqueue.c
67250 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
67251 int cpu;
67252 pid_t pid;
67253 /* Can be inserted from interrupt or user context, need to be atomic */
67254 - atomic_t inserted;
67255 + atomic_unchecked_t inserted;
67256 /*
67257 * Don't need to be atomic, works are serialized in a single workqueue thread
67258 * on a single CPU.
67259 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
67260 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
67261 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
67262 if (node->pid == wq_thread->pid) {
67263 - atomic_inc(&node->inserted);
67264 + atomic_inc_unchecked(&node->inserted);
67265 goto found;
67266 }
67267 }
67268 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
67269 tsk = get_pid_task(pid, PIDTYPE_PID);
67270 if (tsk) {
67271 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
67272 - atomic_read(&cws->inserted), cws->executed,
67273 + atomic_read_unchecked(&cws->inserted), cws->executed,
67274 tsk->comm);
67275 put_task_struct(tsk);
67276 }
67277 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
67278 index 82928f5..92da771 100644
67279 --- a/lib/Kconfig.debug
67280 +++ b/lib/Kconfig.debug
67281 @@ -1103,6 +1103,7 @@ config LATENCYTOP
67282 depends on DEBUG_KERNEL
67283 depends on STACKTRACE_SUPPORT
67284 depends on PROC_FS
67285 + depends on !GRKERNSEC_HIDESYM
67286 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
67287 select KALLSYMS
67288 select KALLSYMS_ALL
67289 diff --git a/lib/bitmap.c b/lib/bitmap.c
67290 index 0d4a127..33a06c7 100644
67291 --- a/lib/bitmap.c
67292 +++ b/lib/bitmap.c
67293 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
67294 {
67295 int c, old_c, totaldigits, ndigits, nchunks, nbits;
67296 u32 chunk;
67297 - const char __user __force *ubuf = (const char __user __force *)buf;
67298 + const char __user *ubuf = (const char __force_user *)buf;
67299
67300 bitmap_zero(maskp, nmaskbits);
67301
67302 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
67303 {
67304 if (!access_ok(VERIFY_READ, ubuf, ulen))
67305 return -EFAULT;
67306 - return __bitmap_parse((const char __force *)ubuf,
67307 + return __bitmap_parse((const char __force_kernel *)ubuf,
67308 ulen, 1, maskp, nmaskbits);
67309
67310 }
67311 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
67312 {
67313 unsigned a, b;
67314 int c, old_c, totaldigits;
67315 - const char __user __force *ubuf = (const char __user __force *)buf;
67316 + const char __user *ubuf = (const char __force_user *)buf;
67317 int exp_digit, in_range;
67318
67319 totaldigits = c = 0;
67320 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
67321 {
67322 if (!access_ok(VERIFY_READ, ubuf, ulen))
67323 return -EFAULT;
67324 - return __bitmap_parselist((const char __force *)ubuf,
67325 + return __bitmap_parselist((const char __force_kernel *)ubuf,
67326 ulen, 1, maskp, nmaskbits);
67327 }
67328 EXPORT_SYMBOL(bitmap_parselist_user);
67329 diff --git a/lib/bug.c b/lib/bug.c
67330 index 1955209..cbbb2ad 100644
67331 --- a/lib/bug.c
67332 +++ b/lib/bug.c
67333 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
67334 return BUG_TRAP_TYPE_NONE;
67335
67336 bug = find_bug(bugaddr);
67337 + if (!bug)
67338 + return BUG_TRAP_TYPE_NONE;
67339
67340 file = NULL;
67341 line = 0;
67342 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
67343 index a78b7c6..2c73084 100644
67344 --- a/lib/debugobjects.c
67345 +++ b/lib/debugobjects.c
67346 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
67347 if (limit > 4)
67348 return;
67349
67350 - is_on_stack = object_is_on_stack(addr);
67351 + is_on_stack = object_starts_on_stack(addr);
67352 if (is_on_stack == onstack)
67353 return;
67354
67355 diff --git a/lib/devres.c b/lib/devres.c
67356 index 7c0e953..f642b5c 100644
67357 --- a/lib/devres.c
67358 +++ b/lib/devres.c
67359 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
67360 void devm_iounmap(struct device *dev, void __iomem *addr)
67361 {
67362 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
67363 - (void *)addr));
67364 + (void __force *)addr));
67365 iounmap(addr);
67366 }
67367 EXPORT_SYMBOL(devm_iounmap);
67368 @@ -141,7 +141,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
67369 {
67370 ioport_unmap(addr);
67371 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
67372 - devm_ioport_map_match, (void *)addr));
67373 + devm_ioport_map_match, (void __force *)addr));
67374 }
67375 EXPORT_SYMBOL(devm_ioport_unmap);
67376
67377 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
67378 index fea790a..ebb0e82 100644
67379 --- a/lib/dma-debug.c
67380 +++ b/lib/dma-debug.c
67381 @@ -925,7 +925,7 @@ out:
67382
67383 static void check_for_stack(struct device *dev, void *addr)
67384 {
67385 - if (object_is_on_stack(addr))
67386 + if (object_starts_on_stack(addr))
67387 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
67388 "stack [addr=%p]\n", addr);
67389 }
67390 diff --git a/lib/extable.c b/lib/extable.c
67391 index 4cac81e..63e9b8f 100644
67392 --- a/lib/extable.c
67393 +++ b/lib/extable.c
67394 @@ -13,6 +13,7 @@
67395 #include <linux/init.h>
67396 #include <linux/sort.h>
67397 #include <asm/uaccess.h>
67398 +#include <asm/pgtable.h>
67399
67400 #ifndef ARCH_HAS_SORT_EXTABLE
67401 /*
67402 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
67403 void sort_extable(struct exception_table_entry *start,
67404 struct exception_table_entry *finish)
67405 {
67406 + pax_open_kernel();
67407 sort(start, finish - start, sizeof(struct exception_table_entry),
67408 cmp_ex, NULL);
67409 + pax_close_kernel();
67410 }
67411
67412 #ifdef CONFIG_MODULES
67413 diff --git a/lib/inflate.c b/lib/inflate.c
67414 index 013a761..c28f3fc 100644
67415 --- a/lib/inflate.c
67416 +++ b/lib/inflate.c
67417 @@ -269,7 +269,7 @@ static void free(void *where)
67418 malloc_ptr = free_mem_ptr;
67419 }
67420 #else
67421 -#define malloc(a) kmalloc(a, GFP_KERNEL)
67422 +#define malloc(a) kmalloc((a), GFP_KERNEL)
67423 #define free(a) kfree(a)
67424 #endif
67425
67426 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
67427 index bd2bea9..6b3c95e 100644
67428 --- a/lib/is_single_threaded.c
67429 +++ b/lib/is_single_threaded.c
67430 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
67431 struct task_struct *p, *t;
67432 bool ret;
67433
67434 + if (!mm)
67435 + return true;
67436 +
67437 if (atomic_read(&task->signal->live) != 1)
67438 return false;
67439
67440 diff --git a/lib/kref.c b/lib/kref.c
67441 index 3efb882..8492f4c 100644
67442 --- a/lib/kref.c
67443 +++ b/lib/kref.c
67444 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
67445 */
67446 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
67447 {
67448 - WARN_ON(release == NULL);
67449 + BUG_ON(release == NULL);
67450 WARN_ON(release == (void (*)(struct kref *))kfree);
67451
67452 if (atomic_dec_and_test(&kref->refcount)) {
67453 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
67454 index d9df745..e73c2fe 100644
67455 --- a/lib/radix-tree.c
67456 +++ b/lib/radix-tree.c
67457 @@ -80,7 +80,7 @@ struct radix_tree_preload {
67458 int nr;
67459 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
67460 };
67461 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
67462 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
67463
67464 static inline void *ptr_to_indirect(void *ptr)
67465 {
67466 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
67467 index 993599e..84dc70e 100644
67468 --- a/lib/vsprintf.c
67469 +++ b/lib/vsprintf.c
67470 @@ -16,6 +16,9 @@
67471 * - scnprintf and vscnprintf
67472 */
67473
67474 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67475 +#define __INCLUDED_BY_HIDESYM 1
67476 +#endif
67477 #include <stdarg.h>
67478 #include <linux/module.h>
67479 #include <linux/types.h>
67480 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
67481 char sym[KSYM_SYMBOL_LEN];
67482 if (ext == 'B')
67483 sprint_backtrace(sym, value);
67484 - else if (ext != 'f' && ext != 's')
67485 + else if (ext != 'f' && ext != 's' && ext != 'a')
67486 sprint_symbol(sym, value);
67487 else
67488 kallsyms_lookup(value, NULL, NULL, NULL, sym);
67489 @@ -777,7 +780,11 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
67490 return string(buf, end, uuid, spec);
67491 }
67492
67493 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67494 +int kptr_restrict __read_mostly = 2;
67495 +#else
67496 int kptr_restrict __read_mostly;
67497 +#endif
67498
67499 /*
67500 * Show a '%p' thing. A kernel extension is that the '%p' is followed
67501 @@ -791,6 +798,8 @@ int kptr_restrict __read_mostly;
67502 * - 'S' For symbolic direct pointers with offset
67503 * - 's' For symbolic direct pointers without offset
67504 * - 'B' For backtraced symbolic direct pointers with offset
67505 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
67506 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
67507 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
67508 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
67509 * - 'M' For a 6-byte MAC address, it prints the address in the
67510 @@ -835,12 +844,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
67511 {
67512 if (!ptr && *fmt != 'K') {
67513 /*
67514 - * Print (null) with the same width as a pointer so it makes
67515 + * Print (nil) with the same width as a pointer so it makes
67516 * tabular output look nice.
67517 */
67518 if (spec.field_width == -1)
67519 spec.field_width = 2 * sizeof(void *);
67520 - return string(buf, end, "(null)", spec);
67521 + return string(buf, end, "(nil)", spec);
67522 }
67523
67524 switch (*fmt) {
67525 @@ -850,6 +859,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
67526 /* Fallthrough */
67527 case 'S':
67528 case 's':
67529 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67530 + break;
67531 +#else
67532 + return symbol_string(buf, end, ptr, spec, *fmt);
67533 +#endif
67534 + case 'A':
67535 + case 'a':
67536 case 'B':
67537 return symbol_string(buf, end, ptr, spec, *fmt);
67538 case 'R':
67539 @@ -1608,11 +1624,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
67540 typeof(type) value; \
67541 if (sizeof(type) == 8) { \
67542 args = PTR_ALIGN(args, sizeof(u32)); \
67543 - *(u32 *)&value = *(u32 *)args; \
67544 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
67545 + *(u32 *)&value = *(const u32 *)args; \
67546 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
67547 } else { \
67548 args = PTR_ALIGN(args, sizeof(type)); \
67549 - value = *(typeof(type) *)args; \
67550 + value = *(const typeof(type) *)args; \
67551 } \
67552 args += sizeof(type); \
67553 value; \
67554 @@ -1675,7 +1691,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
67555 case FORMAT_TYPE_STR: {
67556 const char *str_arg = args;
67557 args += strlen(str_arg) + 1;
67558 - str = string(str, end, (char *)str_arg, spec);
67559 + str = string(str, end, str_arg, spec);
67560 break;
67561 }
67562
67563 diff --git a/localversion-grsec b/localversion-grsec
67564 new file mode 100644
67565 index 0000000..7cd6065
67566 --- /dev/null
67567 +++ b/localversion-grsec
67568 @@ -0,0 +1 @@
67569 +-grsec
67570 diff --git a/mm/Kconfig b/mm/Kconfig
67571 index 011b110..b492af2 100644
67572 --- a/mm/Kconfig
67573 +++ b/mm/Kconfig
67574 @@ -241,10 +241,10 @@ config KSM
67575 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
67576
67577 config DEFAULT_MMAP_MIN_ADDR
67578 - int "Low address space to protect from user allocation"
67579 + int "Low address space to protect from user allocation"
67580 depends on MMU
67581 - default 4096
67582 - help
67583 + default 65536
67584 + help
67585 This is the portion of low virtual memory which should be protected
67586 from userspace allocation. Keeping a user from writing to low pages
67587 can help reduce the impact of kernel NULL pointer bugs.
67588 diff --git a/mm/filemap.c b/mm/filemap.c
67589 index 90286a4..f441caa 100644
67590 --- a/mm/filemap.c
67591 +++ b/mm/filemap.c
67592 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
67593 struct address_space *mapping = file->f_mapping;
67594
67595 if (!mapping->a_ops->readpage)
67596 - return -ENOEXEC;
67597 + return -ENODEV;
67598 file_accessed(file);
67599 vma->vm_ops = &generic_file_vm_ops;
67600 vma->vm_flags |= VM_CAN_NONLINEAR;
67601 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
67602 *pos = i_size_read(inode);
67603
67604 if (limit != RLIM_INFINITY) {
67605 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
67606 if (*pos >= limit) {
67607 send_sig(SIGXFSZ, current, 0);
67608 return -EFBIG;
67609 diff --git a/mm/fremap.c b/mm/fremap.c
67610 index 9ed4fd4..c42648d 100644
67611 --- a/mm/fremap.c
67612 +++ b/mm/fremap.c
67613 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
67614 retry:
67615 vma = find_vma(mm, start);
67616
67617 +#ifdef CONFIG_PAX_SEGMEXEC
67618 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
67619 + goto out;
67620 +#endif
67621 +
67622 /*
67623 * Make sure the vma is shared, that it supports prefaulting,
67624 * and that the remapped range is valid and fully within
67625 diff --git a/mm/highmem.c b/mm/highmem.c
67626 index 57d82c6..e9e0552 100644
67627 --- a/mm/highmem.c
67628 +++ b/mm/highmem.c
67629 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
67630 * So no dangers, even with speculative execution.
67631 */
67632 page = pte_page(pkmap_page_table[i]);
67633 + pax_open_kernel();
67634 pte_clear(&init_mm, (unsigned long)page_address(page),
67635 &pkmap_page_table[i]);
67636 -
67637 + pax_close_kernel();
67638 set_page_address(page, NULL);
67639 need_flush = 1;
67640 }
67641 @@ -186,9 +187,11 @@ start:
67642 }
67643 }
67644 vaddr = PKMAP_ADDR(last_pkmap_nr);
67645 +
67646 + pax_open_kernel();
67647 set_pte_at(&init_mm, vaddr,
67648 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
67649 -
67650 + pax_close_kernel();
67651 pkmap_count[last_pkmap_nr] = 1;
67652 set_page_address(page, (void *)vaddr);
67653
67654 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
67655 index 36b3d98..584cb54 100644
67656 --- a/mm/huge_memory.c
67657 +++ b/mm/huge_memory.c
67658 @@ -703,7 +703,7 @@ out:
67659 * run pte_offset_map on the pmd, if an huge pmd could
67660 * materialize from under us from a different thread.
67661 */
67662 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
67663 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
67664 return VM_FAULT_OOM;
67665 /* if an huge pmd materialized from under us just retry later */
67666 if (unlikely(pmd_trans_huge(*pmd)))
67667 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
67668 index 2316840..b418671 100644
67669 --- a/mm/hugetlb.c
67670 +++ b/mm/hugetlb.c
67671 @@ -2347,6 +2347,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
67672 return 1;
67673 }
67674
67675 +#ifdef CONFIG_PAX_SEGMEXEC
67676 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
67677 +{
67678 + struct mm_struct *mm = vma->vm_mm;
67679 + struct vm_area_struct *vma_m;
67680 + unsigned long address_m;
67681 + pte_t *ptep_m;
67682 +
67683 + vma_m = pax_find_mirror_vma(vma);
67684 + if (!vma_m)
67685 + return;
67686 +
67687 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
67688 + address_m = address + SEGMEXEC_TASK_SIZE;
67689 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
67690 + get_page(page_m);
67691 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
67692 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
67693 +}
67694 +#endif
67695 +
67696 /*
67697 * Hugetlb_cow() should be called with page lock of the original hugepage held.
67698 */
67699 @@ -2450,6 +2471,11 @@ retry_avoidcopy:
67700 make_huge_pte(vma, new_page, 1));
67701 page_remove_rmap(old_page);
67702 hugepage_add_new_anon_rmap(new_page, vma, address);
67703 +
67704 +#ifdef CONFIG_PAX_SEGMEXEC
67705 + pax_mirror_huge_pte(vma, address, new_page);
67706 +#endif
67707 +
67708 /* Make the old page be freed below */
67709 new_page = old_page;
67710 mmu_notifier_invalidate_range_end(mm,
67711 @@ -2601,6 +2627,10 @@ retry:
67712 && (vma->vm_flags & VM_SHARED)));
67713 set_huge_pte_at(mm, address, ptep, new_pte);
67714
67715 +#ifdef CONFIG_PAX_SEGMEXEC
67716 + pax_mirror_huge_pte(vma, address, page);
67717 +#endif
67718 +
67719 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
67720 /* Optimization, do the COW without a second fault */
67721 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
67722 @@ -2630,6 +2660,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
67723 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
67724 struct hstate *h = hstate_vma(vma);
67725
67726 +#ifdef CONFIG_PAX_SEGMEXEC
67727 + struct vm_area_struct *vma_m;
67728 +#endif
67729 +
67730 ptep = huge_pte_offset(mm, address);
67731 if (ptep) {
67732 entry = huge_ptep_get(ptep);
67733 @@ -2641,6 +2675,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
67734 VM_FAULT_SET_HINDEX(h - hstates);
67735 }
67736
67737 +#ifdef CONFIG_PAX_SEGMEXEC
67738 + vma_m = pax_find_mirror_vma(vma);
67739 + if (vma_m) {
67740 + unsigned long address_m;
67741 +
67742 + if (vma->vm_start > vma_m->vm_start) {
67743 + address_m = address;
67744 + address -= SEGMEXEC_TASK_SIZE;
67745 + vma = vma_m;
67746 + h = hstate_vma(vma);
67747 + } else
67748 + address_m = address + SEGMEXEC_TASK_SIZE;
67749 +
67750 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
67751 + return VM_FAULT_OOM;
67752 + address_m &= HPAGE_MASK;
67753 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
67754 + }
67755 +#endif
67756 +
67757 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
67758 if (!ptep)
67759 return VM_FAULT_OOM;
67760 diff --git a/mm/internal.h b/mm/internal.h
67761 index 2189af4..f2ca332 100644
67762 --- a/mm/internal.h
67763 +++ b/mm/internal.h
67764 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
67765 * in mm/page_alloc.c
67766 */
67767 extern void __free_pages_bootmem(struct page *page, unsigned int order);
67768 +extern void free_compound_page(struct page *page);
67769 extern void prep_compound_page(struct page *page, unsigned long order);
67770 #ifdef CONFIG_MEMORY_FAILURE
67771 extern bool is_free_buddy_page(struct page *page);
67772 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
67773 index f3b2a00..61da94d 100644
67774 --- a/mm/kmemleak.c
67775 +++ b/mm/kmemleak.c
67776 @@ -357,7 +357,7 @@ static void print_unreferenced(struct seq_file *seq,
67777
67778 for (i = 0; i < object->trace_len; i++) {
67779 void *ptr = (void *)object->trace[i];
67780 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
67781 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
67782 }
67783 }
67784
67785 diff --git a/mm/maccess.c b/mm/maccess.c
67786 index d53adf9..03a24bf 100644
67787 --- a/mm/maccess.c
67788 +++ b/mm/maccess.c
67789 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
67790 set_fs(KERNEL_DS);
67791 pagefault_disable();
67792 ret = __copy_from_user_inatomic(dst,
67793 - (__force const void __user *)src, size);
67794 + (const void __force_user *)src, size);
67795 pagefault_enable();
67796 set_fs(old_fs);
67797
67798 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
67799
67800 set_fs(KERNEL_DS);
67801 pagefault_disable();
67802 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
67803 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
67804 pagefault_enable();
67805 set_fs(old_fs);
67806
67807 diff --git a/mm/madvise.c b/mm/madvise.c
67808 index 74bf193..feb6fd3 100644
67809 --- a/mm/madvise.c
67810 +++ b/mm/madvise.c
67811 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
67812 pgoff_t pgoff;
67813 unsigned long new_flags = vma->vm_flags;
67814
67815 +#ifdef CONFIG_PAX_SEGMEXEC
67816 + struct vm_area_struct *vma_m;
67817 +#endif
67818 +
67819 switch (behavior) {
67820 case MADV_NORMAL:
67821 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
67822 @@ -110,6 +114,13 @@ success:
67823 /*
67824 * vm_flags is protected by the mmap_sem held in write mode.
67825 */
67826 +
67827 +#ifdef CONFIG_PAX_SEGMEXEC
67828 + vma_m = pax_find_mirror_vma(vma);
67829 + if (vma_m)
67830 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
67831 +#endif
67832 +
67833 vma->vm_flags = new_flags;
67834
67835 out:
67836 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
67837 struct vm_area_struct ** prev,
67838 unsigned long start, unsigned long end)
67839 {
67840 +
67841 +#ifdef CONFIG_PAX_SEGMEXEC
67842 + struct vm_area_struct *vma_m;
67843 +#endif
67844 +
67845 *prev = vma;
67846 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
67847 return -EINVAL;
67848 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
67849 zap_page_range(vma, start, end - start, &details);
67850 } else
67851 zap_page_range(vma, start, end - start, NULL);
67852 +
67853 +#ifdef CONFIG_PAX_SEGMEXEC
67854 + vma_m = pax_find_mirror_vma(vma);
67855 + if (vma_m) {
67856 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
67857 + struct zap_details details = {
67858 + .nonlinear_vma = vma_m,
67859 + .last_index = ULONG_MAX,
67860 + };
67861 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
67862 + } else
67863 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
67864 + }
67865 +#endif
67866 +
67867 return 0;
67868 }
67869
67870 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
67871 if (end < start)
67872 goto out;
67873
67874 +#ifdef CONFIG_PAX_SEGMEXEC
67875 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
67876 + if (end > SEGMEXEC_TASK_SIZE)
67877 + goto out;
67878 + } else
67879 +#endif
67880 +
67881 + if (end > TASK_SIZE)
67882 + goto out;
67883 +
67884 error = 0;
67885 if (end == start)
67886 goto out;
67887 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
67888 index 06d3479..0778eef 100644
67889 --- a/mm/memory-failure.c
67890 +++ b/mm/memory-failure.c
67891 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
67892
67893 int sysctl_memory_failure_recovery __read_mostly = 1;
67894
67895 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
67896 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
67897
67898 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
67899
67900 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
67901 si.si_signo = SIGBUS;
67902 si.si_errno = 0;
67903 si.si_code = BUS_MCEERR_AO;
67904 - si.si_addr = (void *)addr;
67905 + si.si_addr = (void __user *)addr;
67906 #ifdef __ARCH_SI_TRAPNO
67907 si.si_trapno = trapno;
67908 #endif
67909 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
67910 }
67911
67912 nr_pages = 1 << compound_trans_order(hpage);
67913 - atomic_long_add(nr_pages, &mce_bad_pages);
67914 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
67915
67916 /*
67917 * We need/can do nothing about count=0 pages.
67918 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
67919 if (!PageHWPoison(hpage)
67920 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
67921 || (p != hpage && TestSetPageHWPoison(hpage))) {
67922 - atomic_long_sub(nr_pages, &mce_bad_pages);
67923 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
67924 return 0;
67925 }
67926 set_page_hwpoison_huge_page(hpage);
67927 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
67928 }
67929 if (hwpoison_filter(p)) {
67930 if (TestClearPageHWPoison(p))
67931 - atomic_long_sub(nr_pages, &mce_bad_pages);
67932 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
67933 unlock_page(hpage);
67934 put_page(hpage);
67935 return 0;
67936 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
67937 return 0;
67938 }
67939 if (TestClearPageHWPoison(p))
67940 - atomic_long_sub(nr_pages, &mce_bad_pages);
67941 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
67942 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
67943 return 0;
67944 }
67945 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
67946 */
67947 if (TestClearPageHWPoison(page)) {
67948 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
67949 - atomic_long_sub(nr_pages, &mce_bad_pages);
67950 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
67951 freeit = 1;
67952 if (PageHuge(page))
67953 clear_page_hwpoison_huge_page(page);
67954 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
67955 }
67956 done:
67957 if (!PageHWPoison(hpage))
67958 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
67959 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
67960 set_page_hwpoison_huge_page(hpage);
67961 dequeue_hwpoisoned_huge_page(hpage);
67962 /* keep elevated page count for bad page */
67963 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
67964 return ret;
67965
67966 done:
67967 - atomic_long_add(1, &mce_bad_pages);
67968 + atomic_long_add_unchecked(1, &mce_bad_pages);
67969 SetPageHWPoison(page);
67970 /* keep elevated page count for bad page */
67971 return ret;
67972 diff --git a/mm/memory.c b/mm/memory.c
67973 index 829d437..3d3926a 100644
67974 --- a/mm/memory.c
67975 +++ b/mm/memory.c
67976 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
67977 return;
67978
67979 pmd = pmd_offset(pud, start);
67980 +
67981 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
67982 pud_clear(pud);
67983 pmd_free_tlb(tlb, pmd, start);
67984 +#endif
67985 +
67986 }
67987
67988 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
67989 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
67990 if (end - 1 > ceiling - 1)
67991 return;
67992
67993 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
67994 pud = pud_offset(pgd, start);
67995 pgd_clear(pgd);
67996 pud_free_tlb(tlb, pud, start);
67997 +#endif
67998 +
67999 }
68000
68001 /*
68002 @@ -1566,12 +1573,6 @@ no_page_table:
68003 return page;
68004 }
68005
68006 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
68007 -{
68008 - return stack_guard_page_start(vma, addr) ||
68009 - stack_guard_page_end(vma, addr+PAGE_SIZE);
68010 -}
68011 -
68012 /**
68013 * __get_user_pages() - pin user pages in memory
68014 * @tsk: task_struct of target task
68015 @@ -1644,10 +1645,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
68016 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
68017 i = 0;
68018
68019 - do {
68020 + while (nr_pages) {
68021 struct vm_area_struct *vma;
68022
68023 - vma = find_extend_vma(mm, start);
68024 + vma = find_vma(mm, start);
68025 if (!vma && in_gate_area(mm, start)) {
68026 unsigned long pg = start & PAGE_MASK;
68027 pgd_t *pgd;
68028 @@ -1695,7 +1696,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
68029 goto next_page;
68030 }
68031
68032 - if (!vma ||
68033 + if (!vma || start < vma->vm_start ||
68034 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
68035 !(vm_flags & vma->vm_flags))
68036 return i ? : -EFAULT;
68037 @@ -1722,11 +1723,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
68038 int ret;
68039 unsigned int fault_flags = 0;
68040
68041 - /* For mlock, just skip the stack guard page. */
68042 - if (foll_flags & FOLL_MLOCK) {
68043 - if (stack_guard_page(vma, start))
68044 - goto next_page;
68045 - }
68046 if (foll_flags & FOLL_WRITE)
68047 fault_flags |= FAULT_FLAG_WRITE;
68048 if (nonblocking)
68049 @@ -1800,7 +1796,7 @@ next_page:
68050 start += PAGE_SIZE;
68051 nr_pages--;
68052 } while (nr_pages && start < vma->vm_end);
68053 - } while (nr_pages);
68054 + }
68055 return i;
68056 }
68057 EXPORT_SYMBOL(__get_user_pages);
68058 @@ -2007,6 +2003,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
68059 page_add_file_rmap(page);
68060 set_pte_at(mm, addr, pte, mk_pte(page, prot));
68061
68062 +#ifdef CONFIG_PAX_SEGMEXEC
68063 + pax_mirror_file_pte(vma, addr, page, ptl);
68064 +#endif
68065 +
68066 retval = 0;
68067 pte_unmap_unlock(pte, ptl);
68068 return retval;
68069 @@ -2041,10 +2041,22 @@ out:
68070 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
68071 struct page *page)
68072 {
68073 +
68074 +#ifdef CONFIG_PAX_SEGMEXEC
68075 + struct vm_area_struct *vma_m;
68076 +#endif
68077 +
68078 if (addr < vma->vm_start || addr >= vma->vm_end)
68079 return -EFAULT;
68080 if (!page_count(page))
68081 return -EINVAL;
68082 +
68083 +#ifdef CONFIG_PAX_SEGMEXEC
68084 + vma_m = pax_find_mirror_vma(vma);
68085 + if (vma_m)
68086 + vma_m->vm_flags |= VM_INSERTPAGE;
68087 +#endif
68088 +
68089 vma->vm_flags |= VM_INSERTPAGE;
68090 return insert_page(vma, addr, page, vma->vm_page_prot);
68091 }
68092 @@ -2130,6 +2142,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
68093 unsigned long pfn)
68094 {
68095 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
68096 + BUG_ON(vma->vm_mirror);
68097
68098 if (addr < vma->vm_start || addr >= vma->vm_end)
68099 return -EFAULT;
68100 @@ -2445,6 +2458,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
68101 copy_user_highpage(dst, src, va, vma);
68102 }
68103
68104 +#ifdef CONFIG_PAX_SEGMEXEC
68105 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
68106 +{
68107 + struct mm_struct *mm = vma->vm_mm;
68108 + spinlock_t *ptl;
68109 + pte_t *pte, entry;
68110 +
68111 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
68112 + entry = *pte;
68113 + if (!pte_present(entry)) {
68114 + if (!pte_none(entry)) {
68115 + BUG_ON(pte_file(entry));
68116 + free_swap_and_cache(pte_to_swp_entry(entry));
68117 + pte_clear_not_present_full(mm, address, pte, 0);
68118 + }
68119 + } else {
68120 + struct page *page;
68121 +
68122 + flush_cache_page(vma, address, pte_pfn(entry));
68123 + entry = ptep_clear_flush(vma, address, pte);
68124 + BUG_ON(pte_dirty(entry));
68125 + page = vm_normal_page(vma, address, entry);
68126 + if (page) {
68127 + update_hiwater_rss(mm);
68128 + if (PageAnon(page))
68129 + dec_mm_counter_fast(mm, MM_ANONPAGES);
68130 + else
68131 + dec_mm_counter_fast(mm, MM_FILEPAGES);
68132 + page_remove_rmap(page);
68133 + page_cache_release(page);
68134 + }
68135 + }
68136 + pte_unmap_unlock(pte, ptl);
68137 +}
68138 +
68139 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
68140 + *
68141 + * the ptl of the lower mapped page is held on entry and is not released on exit
68142 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
68143 + */
68144 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
68145 +{
68146 + struct mm_struct *mm = vma->vm_mm;
68147 + unsigned long address_m;
68148 + spinlock_t *ptl_m;
68149 + struct vm_area_struct *vma_m;
68150 + pmd_t *pmd_m;
68151 + pte_t *pte_m, entry_m;
68152 +
68153 + BUG_ON(!page_m || !PageAnon(page_m));
68154 +
68155 + vma_m = pax_find_mirror_vma(vma);
68156 + if (!vma_m)
68157 + return;
68158 +
68159 + BUG_ON(!PageLocked(page_m));
68160 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68161 + address_m = address + SEGMEXEC_TASK_SIZE;
68162 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68163 + pte_m = pte_offset_map(pmd_m, address_m);
68164 + ptl_m = pte_lockptr(mm, pmd_m);
68165 + if (ptl != ptl_m) {
68166 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68167 + if (!pte_none(*pte_m))
68168 + goto out;
68169 + }
68170 +
68171 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
68172 + page_cache_get(page_m);
68173 + page_add_anon_rmap(page_m, vma_m, address_m);
68174 + inc_mm_counter_fast(mm, MM_ANONPAGES);
68175 + set_pte_at(mm, address_m, pte_m, entry_m);
68176 + update_mmu_cache(vma_m, address_m, entry_m);
68177 +out:
68178 + if (ptl != ptl_m)
68179 + spin_unlock(ptl_m);
68180 + pte_unmap(pte_m);
68181 + unlock_page(page_m);
68182 +}
68183 +
68184 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
68185 +{
68186 + struct mm_struct *mm = vma->vm_mm;
68187 + unsigned long address_m;
68188 + spinlock_t *ptl_m;
68189 + struct vm_area_struct *vma_m;
68190 + pmd_t *pmd_m;
68191 + pte_t *pte_m, entry_m;
68192 +
68193 + BUG_ON(!page_m || PageAnon(page_m));
68194 +
68195 + vma_m = pax_find_mirror_vma(vma);
68196 + if (!vma_m)
68197 + return;
68198 +
68199 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68200 + address_m = address + SEGMEXEC_TASK_SIZE;
68201 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68202 + pte_m = pte_offset_map(pmd_m, address_m);
68203 + ptl_m = pte_lockptr(mm, pmd_m);
68204 + if (ptl != ptl_m) {
68205 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68206 + if (!pte_none(*pte_m))
68207 + goto out;
68208 + }
68209 +
68210 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
68211 + page_cache_get(page_m);
68212 + page_add_file_rmap(page_m);
68213 + inc_mm_counter_fast(mm, MM_FILEPAGES);
68214 + set_pte_at(mm, address_m, pte_m, entry_m);
68215 + update_mmu_cache(vma_m, address_m, entry_m);
68216 +out:
68217 + if (ptl != ptl_m)
68218 + spin_unlock(ptl_m);
68219 + pte_unmap(pte_m);
68220 +}
68221 +
68222 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
68223 +{
68224 + struct mm_struct *mm = vma->vm_mm;
68225 + unsigned long address_m;
68226 + spinlock_t *ptl_m;
68227 + struct vm_area_struct *vma_m;
68228 + pmd_t *pmd_m;
68229 + pte_t *pte_m, entry_m;
68230 +
68231 + vma_m = pax_find_mirror_vma(vma);
68232 + if (!vma_m)
68233 + return;
68234 +
68235 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68236 + address_m = address + SEGMEXEC_TASK_SIZE;
68237 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68238 + pte_m = pte_offset_map(pmd_m, address_m);
68239 + ptl_m = pte_lockptr(mm, pmd_m);
68240 + if (ptl != ptl_m) {
68241 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68242 + if (!pte_none(*pte_m))
68243 + goto out;
68244 + }
68245 +
68246 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
68247 + set_pte_at(mm, address_m, pte_m, entry_m);
68248 +out:
68249 + if (ptl != ptl_m)
68250 + spin_unlock(ptl_m);
68251 + pte_unmap(pte_m);
68252 +}
68253 +
68254 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
68255 +{
68256 + struct page *page_m;
68257 + pte_t entry;
68258 +
68259 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
68260 + goto out;
68261 +
68262 + entry = *pte;
68263 + page_m = vm_normal_page(vma, address, entry);
68264 + if (!page_m)
68265 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
68266 + else if (PageAnon(page_m)) {
68267 + if (pax_find_mirror_vma(vma)) {
68268 + pte_unmap_unlock(pte, ptl);
68269 + lock_page(page_m);
68270 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
68271 + if (pte_same(entry, *pte))
68272 + pax_mirror_anon_pte(vma, address, page_m, ptl);
68273 + else
68274 + unlock_page(page_m);
68275 + }
68276 + } else
68277 + pax_mirror_file_pte(vma, address, page_m, ptl);
68278 +
68279 +out:
68280 + pte_unmap_unlock(pte, ptl);
68281 +}
68282 +#endif
68283 +
68284 /*
68285 * This routine handles present pages, when users try to write
68286 * to a shared page. It is done by copying the page to a new address
68287 @@ -2656,6 +2849,12 @@ gotten:
68288 */
68289 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
68290 if (likely(pte_same(*page_table, orig_pte))) {
68291 +
68292 +#ifdef CONFIG_PAX_SEGMEXEC
68293 + if (pax_find_mirror_vma(vma))
68294 + BUG_ON(!trylock_page(new_page));
68295 +#endif
68296 +
68297 if (old_page) {
68298 if (!PageAnon(old_page)) {
68299 dec_mm_counter_fast(mm, MM_FILEPAGES);
68300 @@ -2707,6 +2906,10 @@ gotten:
68301 page_remove_rmap(old_page);
68302 }
68303
68304 +#ifdef CONFIG_PAX_SEGMEXEC
68305 + pax_mirror_anon_pte(vma, address, new_page, ptl);
68306 +#endif
68307 +
68308 /* Free the old page.. */
68309 new_page = old_page;
68310 ret |= VM_FAULT_WRITE;
68311 @@ -2986,6 +3189,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
68312 swap_free(entry);
68313 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
68314 try_to_free_swap(page);
68315 +
68316 +#ifdef CONFIG_PAX_SEGMEXEC
68317 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
68318 +#endif
68319 +
68320 unlock_page(page);
68321 if (swapcache) {
68322 /*
68323 @@ -3009,6 +3217,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
68324
68325 /* No need to invalidate - it was non-present before */
68326 update_mmu_cache(vma, address, page_table);
68327 +
68328 +#ifdef CONFIG_PAX_SEGMEXEC
68329 + pax_mirror_anon_pte(vma, address, page, ptl);
68330 +#endif
68331 +
68332 unlock:
68333 pte_unmap_unlock(page_table, ptl);
68334 out:
68335 @@ -3028,40 +3241,6 @@ out_release:
68336 }
68337
68338 /*
68339 - * This is like a special single-page "expand_{down|up}wards()",
68340 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
68341 - * doesn't hit another vma.
68342 - */
68343 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
68344 -{
68345 - address &= PAGE_MASK;
68346 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
68347 - struct vm_area_struct *prev = vma->vm_prev;
68348 -
68349 - /*
68350 - * Is there a mapping abutting this one below?
68351 - *
68352 - * That's only ok if it's the same stack mapping
68353 - * that has gotten split..
68354 - */
68355 - if (prev && prev->vm_end == address)
68356 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
68357 -
68358 - expand_downwards(vma, address - PAGE_SIZE);
68359 - }
68360 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
68361 - struct vm_area_struct *next = vma->vm_next;
68362 -
68363 - /* As VM_GROWSDOWN but s/below/above/ */
68364 - if (next && next->vm_start == address + PAGE_SIZE)
68365 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
68366 -
68367 - expand_upwards(vma, address + PAGE_SIZE);
68368 - }
68369 - return 0;
68370 -}
68371 -
68372 -/*
68373 * We enter with non-exclusive mmap_sem (to exclude vma changes,
68374 * but allow concurrent faults), and pte mapped but not yet locked.
68375 * We return with mmap_sem still held, but pte unmapped and unlocked.
68376 @@ -3070,27 +3249,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
68377 unsigned long address, pte_t *page_table, pmd_t *pmd,
68378 unsigned int flags)
68379 {
68380 - struct page *page;
68381 + struct page *page = NULL;
68382 spinlock_t *ptl;
68383 pte_t entry;
68384
68385 - pte_unmap(page_table);
68386 -
68387 - /* Check if we need to add a guard page to the stack */
68388 - if (check_stack_guard_page(vma, address) < 0)
68389 - return VM_FAULT_SIGBUS;
68390 -
68391 - /* Use the zero-page for reads */
68392 if (!(flags & FAULT_FLAG_WRITE)) {
68393 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
68394 vma->vm_page_prot));
68395 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
68396 + ptl = pte_lockptr(mm, pmd);
68397 + spin_lock(ptl);
68398 if (!pte_none(*page_table))
68399 goto unlock;
68400 goto setpte;
68401 }
68402
68403 /* Allocate our own private page. */
68404 + pte_unmap(page_table);
68405 +
68406 if (unlikely(anon_vma_prepare(vma)))
68407 goto oom;
68408 page = alloc_zeroed_user_highpage_movable(vma, address);
68409 @@ -3109,6 +3284,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
68410 if (!pte_none(*page_table))
68411 goto release;
68412
68413 +#ifdef CONFIG_PAX_SEGMEXEC
68414 + if (pax_find_mirror_vma(vma))
68415 + BUG_ON(!trylock_page(page));
68416 +#endif
68417 +
68418 inc_mm_counter_fast(mm, MM_ANONPAGES);
68419 page_add_new_anon_rmap(page, vma, address);
68420 setpte:
68421 @@ -3116,6 +3296,12 @@ setpte:
68422
68423 /* No need to invalidate - it was non-present before */
68424 update_mmu_cache(vma, address, page_table);
68425 +
68426 +#ifdef CONFIG_PAX_SEGMEXEC
68427 + if (page)
68428 + pax_mirror_anon_pte(vma, address, page, ptl);
68429 +#endif
68430 +
68431 unlock:
68432 pte_unmap_unlock(page_table, ptl);
68433 return 0;
68434 @@ -3259,6 +3445,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68435 */
68436 /* Only go through if we didn't race with anybody else... */
68437 if (likely(pte_same(*page_table, orig_pte))) {
68438 +
68439 +#ifdef CONFIG_PAX_SEGMEXEC
68440 + if (anon && pax_find_mirror_vma(vma))
68441 + BUG_ON(!trylock_page(page));
68442 +#endif
68443 +
68444 flush_icache_page(vma, page);
68445 entry = mk_pte(page, vma->vm_page_prot);
68446 if (flags & FAULT_FLAG_WRITE)
68447 @@ -3278,6 +3470,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68448
68449 /* no need to invalidate: a not-present page won't be cached */
68450 update_mmu_cache(vma, address, page_table);
68451 +
68452 +#ifdef CONFIG_PAX_SEGMEXEC
68453 + if (anon)
68454 + pax_mirror_anon_pte(vma, address, page, ptl);
68455 + else
68456 + pax_mirror_file_pte(vma, address, page, ptl);
68457 +#endif
68458 +
68459 } else {
68460 if (cow_page)
68461 mem_cgroup_uncharge_page(cow_page);
68462 @@ -3431,6 +3631,12 @@ int handle_pte_fault(struct mm_struct *mm,
68463 if (flags & FAULT_FLAG_WRITE)
68464 flush_tlb_fix_spurious_fault(vma, address);
68465 }
68466 +
68467 +#ifdef CONFIG_PAX_SEGMEXEC
68468 + pax_mirror_pte(vma, address, pte, pmd, ptl);
68469 + return 0;
68470 +#endif
68471 +
68472 unlock:
68473 pte_unmap_unlock(pte, ptl);
68474 return 0;
68475 @@ -3447,6 +3653,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68476 pmd_t *pmd;
68477 pte_t *pte;
68478
68479 +#ifdef CONFIG_PAX_SEGMEXEC
68480 + struct vm_area_struct *vma_m;
68481 +#endif
68482 +
68483 __set_current_state(TASK_RUNNING);
68484
68485 count_vm_event(PGFAULT);
68486 @@ -3458,6 +3668,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68487 if (unlikely(is_vm_hugetlb_page(vma)))
68488 return hugetlb_fault(mm, vma, address, flags);
68489
68490 +#ifdef CONFIG_PAX_SEGMEXEC
68491 + vma_m = pax_find_mirror_vma(vma);
68492 + if (vma_m) {
68493 + unsigned long address_m;
68494 + pgd_t *pgd_m;
68495 + pud_t *pud_m;
68496 + pmd_t *pmd_m;
68497 +
68498 + if (vma->vm_start > vma_m->vm_start) {
68499 + address_m = address;
68500 + address -= SEGMEXEC_TASK_SIZE;
68501 + vma = vma_m;
68502 + } else
68503 + address_m = address + SEGMEXEC_TASK_SIZE;
68504 +
68505 + pgd_m = pgd_offset(mm, address_m);
68506 + pud_m = pud_alloc(mm, pgd_m, address_m);
68507 + if (!pud_m)
68508 + return VM_FAULT_OOM;
68509 + pmd_m = pmd_alloc(mm, pud_m, address_m);
68510 + if (!pmd_m)
68511 + return VM_FAULT_OOM;
68512 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
68513 + return VM_FAULT_OOM;
68514 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
68515 + }
68516 +#endif
68517 +
68518 pgd = pgd_offset(mm, address);
68519 pud = pud_alloc(mm, pgd, address);
68520 if (!pud)
68521 @@ -3487,7 +3725,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68522 * run pte_offset_map on the pmd, if an huge pmd could
68523 * materialize from under us from a different thread.
68524 */
68525 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
68526 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
68527 return VM_FAULT_OOM;
68528 /* if an huge pmd materialized from under us just retry later */
68529 if (unlikely(pmd_trans_huge(*pmd)))
68530 @@ -3591,7 +3829,7 @@ static int __init gate_vma_init(void)
68531 gate_vma.vm_start = FIXADDR_USER_START;
68532 gate_vma.vm_end = FIXADDR_USER_END;
68533 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
68534 - gate_vma.vm_page_prot = __P101;
68535 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
68536 /*
68537 * Make sure the vDSO gets into every core dump.
68538 * Dumping its contents makes post-mortem fully interpretable later
68539 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
68540 index c3fdbcb..2e8ef90 100644
68541 --- a/mm/mempolicy.c
68542 +++ b/mm/mempolicy.c
68543 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
68544 unsigned long vmstart;
68545 unsigned long vmend;
68546
68547 +#ifdef CONFIG_PAX_SEGMEXEC
68548 + struct vm_area_struct *vma_m;
68549 +#endif
68550 +
68551 vma = find_vma_prev(mm, start, &prev);
68552 if (!vma || vma->vm_start > start)
68553 return -EFAULT;
68554 @@ -678,6 +682,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
68555 err = policy_vma(vma, new_pol);
68556 if (err)
68557 goto out;
68558 +
68559 +#ifdef CONFIG_PAX_SEGMEXEC
68560 + vma_m = pax_find_mirror_vma(vma);
68561 + if (vma_m) {
68562 + err = policy_vma(vma_m, new_pol);
68563 + if (err)
68564 + goto out;
68565 + }
68566 +#endif
68567 +
68568 }
68569
68570 out:
68571 @@ -1111,6 +1125,17 @@ static long do_mbind(unsigned long start, unsigned long len,
68572
68573 if (end < start)
68574 return -EINVAL;
68575 +
68576 +#ifdef CONFIG_PAX_SEGMEXEC
68577 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
68578 + if (end > SEGMEXEC_TASK_SIZE)
68579 + return -EINVAL;
68580 + } else
68581 +#endif
68582 +
68583 + if (end > TASK_SIZE)
68584 + return -EINVAL;
68585 +
68586 if (end == start)
68587 return 0;
68588
68589 @@ -1329,6 +1354,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
68590 if (!mm)
68591 goto out;
68592
68593 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68594 + if (mm != current->mm &&
68595 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
68596 + err = -EPERM;
68597 + goto out;
68598 + }
68599 +#endif
68600 +
68601 /*
68602 * Check if this process has the right to modify the specified
68603 * process. The right exists if the process has administrative
68604 @@ -1338,8 +1371,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
68605 rcu_read_lock();
68606 tcred = __task_cred(task);
68607 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
68608 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
68609 - !capable(CAP_SYS_NICE)) {
68610 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
68611 rcu_read_unlock();
68612 err = -EPERM;
68613 goto out;
68614 diff --git a/mm/migrate.c b/mm/migrate.c
68615 index 177aca4..ab3a744 100644
68616 --- a/mm/migrate.c
68617 +++ b/mm/migrate.c
68618 @@ -1313,6 +1313,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
68619 if (!mm)
68620 return -EINVAL;
68621
68622 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68623 + if (mm != current->mm &&
68624 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
68625 + err = -EPERM;
68626 + goto out;
68627 + }
68628 +#endif
68629 +
68630 /*
68631 * Check if this process has the right to modify the specified
68632 * process. The right exists if the process has administrative
68633 @@ -1322,8 +1330,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
68634 rcu_read_lock();
68635 tcred = __task_cred(task);
68636 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
68637 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
68638 - !capable(CAP_SYS_NICE)) {
68639 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
68640 rcu_read_unlock();
68641 err = -EPERM;
68642 goto out;
68643 diff --git a/mm/mlock.c b/mm/mlock.c
68644 index 4f4f53b..9511904 100644
68645 --- a/mm/mlock.c
68646 +++ b/mm/mlock.c
68647 @@ -13,6 +13,7 @@
68648 #include <linux/pagemap.h>
68649 #include <linux/mempolicy.h>
68650 #include <linux/syscalls.h>
68651 +#include <linux/security.h>
68652 #include <linux/sched.h>
68653 #include <linux/export.h>
68654 #include <linux/rmap.h>
68655 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
68656 return -EINVAL;
68657 if (end == start)
68658 return 0;
68659 + if (end > TASK_SIZE)
68660 + return -EINVAL;
68661 +
68662 vma = find_vma_prev(current->mm, start, &prev);
68663 if (!vma || vma->vm_start > start)
68664 return -ENOMEM;
68665 @@ -395,6 +399,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
68666 for (nstart = start ; ; ) {
68667 vm_flags_t newflags;
68668
68669 +#ifdef CONFIG_PAX_SEGMEXEC
68670 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
68671 + break;
68672 +#endif
68673 +
68674 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
68675
68676 newflags = vma->vm_flags | VM_LOCKED;
68677 @@ -500,6 +509,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
68678 lock_limit >>= PAGE_SHIFT;
68679
68680 /* check against resource limits */
68681 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
68682 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
68683 error = do_mlock(start, len, 1);
68684 up_write(&current->mm->mmap_sem);
68685 @@ -523,17 +533,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
68686 static int do_mlockall(int flags)
68687 {
68688 struct vm_area_struct * vma, * prev = NULL;
68689 - unsigned int def_flags = 0;
68690
68691 if (flags & MCL_FUTURE)
68692 - def_flags = VM_LOCKED;
68693 - current->mm->def_flags = def_flags;
68694 + current->mm->def_flags |= VM_LOCKED;
68695 + else
68696 + current->mm->def_flags &= ~VM_LOCKED;
68697 if (flags == MCL_FUTURE)
68698 goto out;
68699
68700 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
68701 vm_flags_t newflags;
68702
68703 +#ifdef CONFIG_PAX_SEGMEXEC
68704 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
68705 + break;
68706 +#endif
68707 +
68708 + BUG_ON(vma->vm_end > TASK_SIZE);
68709 newflags = vma->vm_flags | VM_LOCKED;
68710 if (!(flags & MCL_CURRENT))
68711 newflags &= ~VM_LOCKED;
68712 @@ -566,6 +582,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
68713 lock_limit >>= PAGE_SHIFT;
68714
68715 ret = -ENOMEM;
68716 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
68717 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
68718 capable(CAP_IPC_LOCK))
68719 ret = do_mlockall(flags);
68720 diff --git a/mm/mmap.c b/mm/mmap.c
68721 index eae90af..51ca80b 100644
68722 --- a/mm/mmap.c
68723 +++ b/mm/mmap.c
68724 @@ -46,6 +46,16 @@
68725 #define arch_rebalance_pgtables(addr, len) (addr)
68726 #endif
68727
68728 +static inline void verify_mm_writelocked(struct mm_struct *mm)
68729 +{
68730 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
68731 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
68732 + up_read(&mm->mmap_sem);
68733 + BUG();
68734 + }
68735 +#endif
68736 +}
68737 +
68738 static void unmap_region(struct mm_struct *mm,
68739 struct vm_area_struct *vma, struct vm_area_struct *prev,
68740 unsigned long start, unsigned long end);
68741 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
68742 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
68743 *
68744 */
68745 -pgprot_t protection_map[16] = {
68746 +pgprot_t protection_map[16] __read_only = {
68747 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
68748 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
68749 };
68750
68751 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
68752 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
68753 {
68754 - return __pgprot(pgprot_val(protection_map[vm_flags &
68755 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
68756 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
68757 pgprot_val(arch_vm_get_page_prot(vm_flags)));
68758 +
68759 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68760 + if (!(__supported_pte_mask & _PAGE_NX) &&
68761 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
68762 + (vm_flags & (VM_READ | VM_WRITE)))
68763 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
68764 +#endif
68765 +
68766 + return prot;
68767 }
68768 EXPORT_SYMBOL(vm_get_page_prot);
68769
68770 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
68771 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
68772 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
68773 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
68774 /*
68775 * Make sure vm_committed_as in one cacheline and not cacheline shared with
68776 * other variables. It can be updated by several CPUs frequently.
68777 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
68778 struct vm_area_struct *next = vma->vm_next;
68779
68780 might_sleep();
68781 + BUG_ON(vma->vm_mirror);
68782 if (vma->vm_ops && vma->vm_ops->close)
68783 vma->vm_ops->close(vma);
68784 if (vma->vm_file) {
68785 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
68786 * not page aligned -Ram Gupta
68787 */
68788 rlim = rlimit(RLIMIT_DATA);
68789 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
68790 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
68791 (mm->end_data - mm->start_data) > rlim)
68792 goto out;
68793 @@ -689,6 +711,12 @@ static int
68794 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
68795 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
68796 {
68797 +
68798 +#ifdef CONFIG_PAX_SEGMEXEC
68799 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
68800 + return 0;
68801 +#endif
68802 +
68803 if (is_mergeable_vma(vma, file, vm_flags) &&
68804 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
68805 if (vma->vm_pgoff == vm_pgoff)
68806 @@ -708,6 +736,12 @@ static int
68807 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
68808 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
68809 {
68810 +
68811 +#ifdef CONFIG_PAX_SEGMEXEC
68812 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
68813 + return 0;
68814 +#endif
68815 +
68816 if (is_mergeable_vma(vma, file, vm_flags) &&
68817 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
68818 pgoff_t vm_pglen;
68819 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
68820 struct vm_area_struct *vma_merge(struct mm_struct *mm,
68821 struct vm_area_struct *prev, unsigned long addr,
68822 unsigned long end, unsigned long vm_flags,
68823 - struct anon_vma *anon_vma, struct file *file,
68824 + struct anon_vma *anon_vma, struct file *file,
68825 pgoff_t pgoff, struct mempolicy *policy)
68826 {
68827 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
68828 struct vm_area_struct *area, *next;
68829 int err;
68830
68831 +#ifdef CONFIG_PAX_SEGMEXEC
68832 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
68833 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
68834 +
68835 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
68836 +#endif
68837 +
68838 /*
68839 * We later require that vma->vm_flags == vm_flags,
68840 * so this tests vma->vm_flags & VM_SPECIAL, too.
68841 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
68842 if (next && next->vm_end == end) /* cases 6, 7, 8 */
68843 next = next->vm_next;
68844
68845 +#ifdef CONFIG_PAX_SEGMEXEC
68846 + if (prev)
68847 + prev_m = pax_find_mirror_vma(prev);
68848 + if (area)
68849 + area_m = pax_find_mirror_vma(area);
68850 + if (next)
68851 + next_m = pax_find_mirror_vma(next);
68852 +#endif
68853 +
68854 /*
68855 * Can it merge with the predecessor?
68856 */
68857 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
68858 /* cases 1, 6 */
68859 err = vma_adjust(prev, prev->vm_start,
68860 next->vm_end, prev->vm_pgoff, NULL);
68861 - } else /* cases 2, 5, 7 */
68862 +
68863 +#ifdef CONFIG_PAX_SEGMEXEC
68864 + if (!err && prev_m)
68865 + err = vma_adjust(prev_m, prev_m->vm_start,
68866 + next_m->vm_end, prev_m->vm_pgoff, NULL);
68867 +#endif
68868 +
68869 + } else { /* cases 2, 5, 7 */
68870 err = vma_adjust(prev, prev->vm_start,
68871 end, prev->vm_pgoff, NULL);
68872 +
68873 +#ifdef CONFIG_PAX_SEGMEXEC
68874 + if (!err && prev_m)
68875 + err = vma_adjust(prev_m, prev_m->vm_start,
68876 + end_m, prev_m->vm_pgoff, NULL);
68877 +#endif
68878 +
68879 + }
68880 if (err)
68881 return NULL;
68882 khugepaged_enter_vma_merge(prev);
68883 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
68884 mpol_equal(policy, vma_policy(next)) &&
68885 can_vma_merge_before(next, vm_flags,
68886 anon_vma, file, pgoff+pglen)) {
68887 - if (prev && addr < prev->vm_end) /* case 4 */
68888 + if (prev && addr < prev->vm_end) { /* case 4 */
68889 err = vma_adjust(prev, prev->vm_start,
68890 addr, prev->vm_pgoff, NULL);
68891 - else /* cases 3, 8 */
68892 +
68893 +#ifdef CONFIG_PAX_SEGMEXEC
68894 + if (!err && prev_m)
68895 + err = vma_adjust(prev_m, prev_m->vm_start,
68896 + addr_m, prev_m->vm_pgoff, NULL);
68897 +#endif
68898 +
68899 + } else { /* cases 3, 8 */
68900 err = vma_adjust(area, addr, next->vm_end,
68901 next->vm_pgoff - pglen, NULL);
68902 +
68903 +#ifdef CONFIG_PAX_SEGMEXEC
68904 + if (!err && area_m)
68905 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
68906 + next_m->vm_pgoff - pglen, NULL);
68907 +#endif
68908 +
68909 + }
68910 if (err)
68911 return NULL;
68912 khugepaged_enter_vma_merge(area);
68913 @@ -921,14 +1001,11 @@ none:
68914 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
68915 struct file *file, long pages)
68916 {
68917 - const unsigned long stack_flags
68918 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
68919 -
68920 if (file) {
68921 mm->shared_vm += pages;
68922 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
68923 mm->exec_vm += pages;
68924 - } else if (flags & stack_flags)
68925 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
68926 mm->stack_vm += pages;
68927 if (flags & (VM_RESERVED|VM_IO))
68928 mm->reserved_vm += pages;
68929 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
68930 * (the exception is when the underlying filesystem is noexec
68931 * mounted, in which case we dont add PROT_EXEC.)
68932 */
68933 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
68934 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
68935 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
68936 prot |= PROT_EXEC;
68937
68938 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
68939 /* Obtain the address to map to. we verify (or select) it and ensure
68940 * that it represents a valid section of the address space.
68941 */
68942 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
68943 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
68944 if (addr & ~PAGE_MASK)
68945 return addr;
68946
68947 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
68948 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
68949 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
68950
68951 +#ifdef CONFIG_PAX_MPROTECT
68952 + if (mm->pax_flags & MF_PAX_MPROTECT) {
68953 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
68954 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
68955 + gr_log_rwxmmap(file);
68956 +
68957 +#ifdef CONFIG_PAX_EMUPLT
68958 + vm_flags &= ~VM_EXEC;
68959 +#else
68960 + return -EPERM;
68961 +#endif
68962 +
68963 + }
68964 +
68965 + if (!(vm_flags & VM_EXEC))
68966 + vm_flags &= ~VM_MAYEXEC;
68967 +#else
68968 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
68969 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
68970 +#endif
68971 + else
68972 + vm_flags &= ~VM_MAYWRITE;
68973 + }
68974 +#endif
68975 +
68976 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68977 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
68978 + vm_flags &= ~VM_PAGEEXEC;
68979 +#endif
68980 +
68981 if (flags & MAP_LOCKED)
68982 if (!can_do_mlock())
68983 return -EPERM;
68984 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
68985 locked += mm->locked_vm;
68986 lock_limit = rlimit(RLIMIT_MEMLOCK);
68987 lock_limit >>= PAGE_SHIFT;
68988 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
68989 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
68990 return -EAGAIN;
68991 }
68992 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
68993 if (error)
68994 return error;
68995
68996 + if (!gr_acl_handle_mmap(file, prot))
68997 + return -EACCES;
68998 +
68999 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
69000 }
69001 EXPORT_SYMBOL(do_mmap_pgoff);
69002 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
69003 vm_flags_t vm_flags = vma->vm_flags;
69004
69005 /* If it was private or non-writable, the write bit is already clear */
69006 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
69007 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
69008 return 0;
69009
69010 /* The backer wishes to know when pages are first written to? */
69011 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
69012 unsigned long charged = 0;
69013 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
69014
69015 +#ifdef CONFIG_PAX_SEGMEXEC
69016 + struct vm_area_struct *vma_m = NULL;
69017 +#endif
69018 +
69019 + /*
69020 + * mm->mmap_sem is required to protect against another thread
69021 + * changing the mappings in case we sleep.
69022 + */
69023 + verify_mm_writelocked(mm);
69024 +
69025 /* Clear old maps */
69026 error = -ENOMEM;
69027 -munmap_back:
69028 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69029 if (vma && vma->vm_start < addr + len) {
69030 if (do_munmap(mm, addr, len))
69031 return -ENOMEM;
69032 - goto munmap_back;
69033 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69034 + BUG_ON(vma && vma->vm_start < addr + len);
69035 }
69036
69037 /* Check against address space limit. */
69038 @@ -1258,6 +1379,16 @@ munmap_back:
69039 goto unacct_error;
69040 }
69041
69042 +#ifdef CONFIG_PAX_SEGMEXEC
69043 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
69044 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69045 + if (!vma_m) {
69046 + error = -ENOMEM;
69047 + goto free_vma;
69048 + }
69049 + }
69050 +#endif
69051 +
69052 vma->vm_mm = mm;
69053 vma->vm_start = addr;
69054 vma->vm_end = addr + len;
69055 @@ -1281,6 +1412,19 @@ munmap_back:
69056 error = file->f_op->mmap(file, vma);
69057 if (error)
69058 goto unmap_and_free_vma;
69059 +
69060 +#ifdef CONFIG_PAX_SEGMEXEC
69061 + if (vma_m && (vm_flags & VM_EXECUTABLE))
69062 + added_exe_file_vma(mm);
69063 +#endif
69064 +
69065 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69066 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
69067 + vma->vm_flags |= VM_PAGEEXEC;
69068 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
69069 + }
69070 +#endif
69071 +
69072 if (vm_flags & VM_EXECUTABLE)
69073 added_exe_file_vma(mm);
69074
69075 @@ -1316,6 +1460,11 @@ munmap_back:
69076 vma_link(mm, vma, prev, rb_link, rb_parent);
69077 file = vma->vm_file;
69078
69079 +#ifdef CONFIG_PAX_SEGMEXEC
69080 + if (vma_m)
69081 + BUG_ON(pax_mirror_vma(vma_m, vma));
69082 +#endif
69083 +
69084 /* Once vma denies write, undo our temporary denial count */
69085 if (correct_wcount)
69086 atomic_inc(&inode->i_writecount);
69087 @@ -1324,6 +1473,7 @@ out:
69088
69089 mm->total_vm += len >> PAGE_SHIFT;
69090 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
69091 + track_exec_limit(mm, addr, addr + len, vm_flags);
69092 if (vm_flags & VM_LOCKED) {
69093 if (!mlock_vma_pages_range(vma, addr, addr + len))
69094 mm->locked_vm += (len >> PAGE_SHIFT);
69095 @@ -1341,6 +1491,12 @@ unmap_and_free_vma:
69096 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
69097 charged = 0;
69098 free_vma:
69099 +
69100 +#ifdef CONFIG_PAX_SEGMEXEC
69101 + if (vma_m)
69102 + kmem_cache_free(vm_area_cachep, vma_m);
69103 +#endif
69104 +
69105 kmem_cache_free(vm_area_cachep, vma);
69106 unacct_error:
69107 if (charged)
69108 @@ -1348,6 +1504,44 @@ unacct_error:
69109 return error;
69110 }
69111
69112 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
69113 +{
69114 + if (!vma) {
69115 +#ifdef CONFIG_STACK_GROWSUP
69116 + if (addr > sysctl_heap_stack_gap)
69117 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
69118 + else
69119 + vma = find_vma(current->mm, 0);
69120 + if (vma && (vma->vm_flags & VM_GROWSUP))
69121 + return false;
69122 +#endif
69123 + return true;
69124 + }
69125 +
69126 + if (addr + len > vma->vm_start)
69127 + return false;
69128 +
69129 + if (vma->vm_flags & VM_GROWSDOWN)
69130 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
69131 +#ifdef CONFIG_STACK_GROWSUP
69132 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
69133 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
69134 +#endif
69135 +
69136 + return true;
69137 +}
69138 +
69139 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
69140 +{
69141 + if (vma->vm_start < len)
69142 + return -ENOMEM;
69143 + if (!(vma->vm_flags & VM_GROWSDOWN))
69144 + return vma->vm_start - len;
69145 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
69146 + return vma->vm_start - len - sysctl_heap_stack_gap;
69147 + return -ENOMEM;
69148 +}
69149 +
69150 /* Get an address range which is currently unmapped.
69151 * For shmat() with addr=0.
69152 *
69153 @@ -1374,18 +1568,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
69154 if (flags & MAP_FIXED)
69155 return addr;
69156
69157 +#ifdef CONFIG_PAX_RANDMMAP
69158 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
69159 +#endif
69160 +
69161 if (addr) {
69162 addr = PAGE_ALIGN(addr);
69163 - vma = find_vma(mm, addr);
69164 - if (TASK_SIZE - len >= addr &&
69165 - (!vma || addr + len <= vma->vm_start))
69166 - return addr;
69167 + if (TASK_SIZE - len >= addr) {
69168 + vma = find_vma(mm, addr);
69169 + if (check_heap_stack_gap(vma, addr, len))
69170 + return addr;
69171 + }
69172 }
69173 if (len > mm->cached_hole_size) {
69174 - start_addr = addr = mm->free_area_cache;
69175 + start_addr = addr = mm->free_area_cache;
69176 } else {
69177 - start_addr = addr = TASK_UNMAPPED_BASE;
69178 - mm->cached_hole_size = 0;
69179 + start_addr = addr = mm->mmap_base;
69180 + mm->cached_hole_size = 0;
69181 }
69182
69183 full_search:
69184 @@ -1396,34 +1595,40 @@ full_search:
69185 * Start a new search - just in case we missed
69186 * some holes.
69187 */
69188 - if (start_addr != TASK_UNMAPPED_BASE) {
69189 - addr = TASK_UNMAPPED_BASE;
69190 - start_addr = addr;
69191 + if (start_addr != mm->mmap_base) {
69192 + start_addr = addr = mm->mmap_base;
69193 mm->cached_hole_size = 0;
69194 goto full_search;
69195 }
69196 return -ENOMEM;
69197 }
69198 - if (!vma || addr + len <= vma->vm_start) {
69199 - /*
69200 - * Remember the place where we stopped the search:
69201 - */
69202 - mm->free_area_cache = addr + len;
69203 - return addr;
69204 - }
69205 + if (check_heap_stack_gap(vma, addr, len))
69206 + break;
69207 if (addr + mm->cached_hole_size < vma->vm_start)
69208 mm->cached_hole_size = vma->vm_start - addr;
69209 addr = vma->vm_end;
69210 }
69211 +
69212 + /*
69213 + * Remember the place where we stopped the search:
69214 + */
69215 + mm->free_area_cache = addr + len;
69216 + return addr;
69217 }
69218 #endif
69219
69220 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
69221 {
69222 +
69223 +#ifdef CONFIG_PAX_SEGMEXEC
69224 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
69225 + return;
69226 +#endif
69227 +
69228 /*
69229 * Is this a new hole at the lowest possible address?
69230 */
69231 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
69232 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
69233 mm->free_area_cache = addr;
69234 mm->cached_hole_size = ~0UL;
69235 }
69236 @@ -1441,7 +1646,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69237 {
69238 struct vm_area_struct *vma;
69239 struct mm_struct *mm = current->mm;
69240 - unsigned long addr = addr0;
69241 + unsigned long base = mm->mmap_base, addr = addr0;
69242
69243 /* requested length too big for entire address space */
69244 if (len > TASK_SIZE)
69245 @@ -1450,13 +1655,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69246 if (flags & MAP_FIXED)
69247 return addr;
69248
69249 +#ifdef CONFIG_PAX_RANDMMAP
69250 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
69251 +#endif
69252 +
69253 /* requesting a specific address */
69254 if (addr) {
69255 addr = PAGE_ALIGN(addr);
69256 - vma = find_vma(mm, addr);
69257 - if (TASK_SIZE - len >= addr &&
69258 - (!vma || addr + len <= vma->vm_start))
69259 - return addr;
69260 + if (TASK_SIZE - len >= addr) {
69261 + vma = find_vma(mm, addr);
69262 + if (check_heap_stack_gap(vma, addr, len))
69263 + return addr;
69264 + }
69265 }
69266
69267 /* check if free_area_cache is useful for us */
69268 @@ -1471,7 +1681,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69269 /* make sure it can fit in the remaining address space */
69270 if (addr > len) {
69271 vma = find_vma(mm, addr-len);
69272 - if (!vma || addr <= vma->vm_start)
69273 + if (check_heap_stack_gap(vma, addr - len, len))
69274 /* remember the address as a hint for next time */
69275 return (mm->free_area_cache = addr-len);
69276 }
69277 @@ -1488,7 +1698,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69278 * return with success:
69279 */
69280 vma = find_vma(mm, addr);
69281 - if (!vma || addr+len <= vma->vm_start)
69282 + if (check_heap_stack_gap(vma, addr, len))
69283 /* remember the address as a hint for next time */
69284 return (mm->free_area_cache = addr);
69285
69286 @@ -1497,8 +1707,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69287 mm->cached_hole_size = vma->vm_start - addr;
69288
69289 /* try just below the current vma->vm_start */
69290 - addr = vma->vm_start-len;
69291 - } while (len < vma->vm_start);
69292 + addr = skip_heap_stack_gap(vma, len);
69293 + } while (!IS_ERR_VALUE(addr));
69294
69295 bottomup:
69296 /*
69297 @@ -1507,13 +1717,21 @@ bottomup:
69298 * can happen with large stack limits and large mmap()
69299 * allocations.
69300 */
69301 + mm->mmap_base = TASK_UNMAPPED_BASE;
69302 +
69303 +#ifdef CONFIG_PAX_RANDMMAP
69304 + if (mm->pax_flags & MF_PAX_RANDMMAP)
69305 + mm->mmap_base += mm->delta_mmap;
69306 +#endif
69307 +
69308 + mm->free_area_cache = mm->mmap_base;
69309 mm->cached_hole_size = ~0UL;
69310 - mm->free_area_cache = TASK_UNMAPPED_BASE;
69311 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
69312 /*
69313 * Restore the topdown base:
69314 */
69315 - mm->free_area_cache = mm->mmap_base;
69316 + mm->mmap_base = base;
69317 + mm->free_area_cache = base;
69318 mm->cached_hole_size = ~0UL;
69319
69320 return addr;
69321 @@ -1522,6 +1740,12 @@ bottomup:
69322
69323 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
69324 {
69325 +
69326 +#ifdef CONFIG_PAX_SEGMEXEC
69327 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
69328 + return;
69329 +#endif
69330 +
69331 /*
69332 * Is this a new hole at the highest possible address?
69333 */
69334 @@ -1529,8 +1753,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
69335 mm->free_area_cache = addr;
69336
69337 /* dont allow allocations above current base */
69338 - if (mm->free_area_cache > mm->mmap_base)
69339 + if (mm->free_area_cache > mm->mmap_base) {
69340 mm->free_area_cache = mm->mmap_base;
69341 + mm->cached_hole_size = ~0UL;
69342 + }
69343 }
69344
69345 unsigned long
69346 @@ -1638,6 +1864,28 @@ out:
69347 return prev ? prev->vm_next : vma;
69348 }
69349
69350 +#ifdef CONFIG_PAX_SEGMEXEC
69351 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
69352 +{
69353 + struct vm_area_struct *vma_m;
69354 +
69355 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
69356 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
69357 + BUG_ON(vma->vm_mirror);
69358 + return NULL;
69359 + }
69360 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
69361 + vma_m = vma->vm_mirror;
69362 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
69363 + BUG_ON(vma->vm_file != vma_m->vm_file);
69364 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
69365 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
69366 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
69367 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
69368 + return vma_m;
69369 +}
69370 +#endif
69371 +
69372 /*
69373 * Verify that the stack growth is acceptable and
69374 * update accounting. This is shared with both the
69375 @@ -1654,6 +1902,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69376 return -ENOMEM;
69377
69378 /* Stack limit test */
69379 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
69380 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
69381 return -ENOMEM;
69382
69383 @@ -1664,6 +1913,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69384 locked = mm->locked_vm + grow;
69385 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
69386 limit >>= PAGE_SHIFT;
69387 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
69388 if (locked > limit && !capable(CAP_IPC_LOCK))
69389 return -ENOMEM;
69390 }
69391 @@ -1694,37 +1944,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69392 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
69393 * vma is the last one with address > vma->vm_end. Have to extend vma.
69394 */
69395 +#ifndef CONFIG_IA64
69396 +static
69397 +#endif
69398 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
69399 {
69400 int error;
69401 + bool locknext;
69402
69403 if (!(vma->vm_flags & VM_GROWSUP))
69404 return -EFAULT;
69405
69406 + /* Also guard against wrapping around to address 0. */
69407 + if (address < PAGE_ALIGN(address+1))
69408 + address = PAGE_ALIGN(address+1);
69409 + else
69410 + return -ENOMEM;
69411 +
69412 /*
69413 * We must make sure the anon_vma is allocated
69414 * so that the anon_vma locking is not a noop.
69415 */
69416 if (unlikely(anon_vma_prepare(vma)))
69417 return -ENOMEM;
69418 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
69419 + if (locknext && anon_vma_prepare(vma->vm_next))
69420 + return -ENOMEM;
69421 vma_lock_anon_vma(vma);
69422 + if (locknext)
69423 + vma_lock_anon_vma(vma->vm_next);
69424
69425 /*
69426 * vma->vm_start/vm_end cannot change under us because the caller
69427 * is required to hold the mmap_sem in read mode. We need the
69428 - * anon_vma lock to serialize against concurrent expand_stacks.
69429 - * Also guard against wrapping around to address 0.
69430 + * anon_vma locks to serialize against concurrent expand_stacks
69431 + * and expand_upwards.
69432 */
69433 - if (address < PAGE_ALIGN(address+4))
69434 - address = PAGE_ALIGN(address+4);
69435 - else {
69436 - vma_unlock_anon_vma(vma);
69437 - return -ENOMEM;
69438 - }
69439 error = 0;
69440
69441 /* Somebody else might have raced and expanded it already */
69442 - if (address > vma->vm_end) {
69443 + 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)
69444 + error = -ENOMEM;
69445 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
69446 unsigned long size, grow;
69447
69448 size = address - vma->vm_start;
69449 @@ -1739,6 +2000,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
69450 }
69451 }
69452 }
69453 + if (locknext)
69454 + vma_unlock_anon_vma(vma->vm_next);
69455 vma_unlock_anon_vma(vma);
69456 khugepaged_enter_vma_merge(vma);
69457 return error;
69458 @@ -1752,6 +2015,8 @@ int expand_downwards(struct vm_area_struct *vma,
69459 unsigned long address)
69460 {
69461 int error;
69462 + bool lockprev = false;
69463 + struct vm_area_struct *prev;
69464
69465 /*
69466 * We must make sure the anon_vma is allocated
69467 @@ -1765,6 +2030,15 @@ int expand_downwards(struct vm_area_struct *vma,
69468 if (error)
69469 return error;
69470
69471 + prev = vma->vm_prev;
69472 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
69473 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
69474 +#endif
69475 + if (lockprev && anon_vma_prepare(prev))
69476 + return -ENOMEM;
69477 + if (lockprev)
69478 + vma_lock_anon_vma(prev);
69479 +
69480 vma_lock_anon_vma(vma);
69481
69482 /*
69483 @@ -1774,9 +2048,17 @@ int expand_downwards(struct vm_area_struct *vma,
69484 */
69485
69486 /* Somebody else might have raced and expanded it already */
69487 - if (address < vma->vm_start) {
69488 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
69489 + error = -ENOMEM;
69490 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
69491 unsigned long size, grow;
69492
69493 +#ifdef CONFIG_PAX_SEGMEXEC
69494 + struct vm_area_struct *vma_m;
69495 +
69496 + vma_m = pax_find_mirror_vma(vma);
69497 +#endif
69498 +
69499 size = vma->vm_end - address;
69500 grow = (vma->vm_start - address) >> PAGE_SHIFT;
69501
69502 @@ -1786,11 +2068,22 @@ int expand_downwards(struct vm_area_struct *vma,
69503 if (!error) {
69504 vma->vm_start = address;
69505 vma->vm_pgoff -= grow;
69506 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
69507 +
69508 +#ifdef CONFIG_PAX_SEGMEXEC
69509 + if (vma_m) {
69510 + vma_m->vm_start -= grow << PAGE_SHIFT;
69511 + vma_m->vm_pgoff -= grow;
69512 + }
69513 +#endif
69514 +
69515 perf_event_mmap(vma);
69516 }
69517 }
69518 }
69519 vma_unlock_anon_vma(vma);
69520 + if (lockprev)
69521 + vma_unlock_anon_vma(prev);
69522 khugepaged_enter_vma_merge(vma);
69523 return error;
69524 }
69525 @@ -1860,6 +2153,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
69526 do {
69527 long nrpages = vma_pages(vma);
69528
69529 +#ifdef CONFIG_PAX_SEGMEXEC
69530 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
69531 + vma = remove_vma(vma);
69532 + continue;
69533 + }
69534 +#endif
69535 +
69536 mm->total_vm -= nrpages;
69537 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
69538 vma = remove_vma(vma);
69539 @@ -1905,6 +2205,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
69540 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
69541 vma->vm_prev = NULL;
69542 do {
69543 +
69544 +#ifdef CONFIG_PAX_SEGMEXEC
69545 + if (vma->vm_mirror) {
69546 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
69547 + vma->vm_mirror->vm_mirror = NULL;
69548 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
69549 + vma->vm_mirror = NULL;
69550 + }
69551 +#endif
69552 +
69553 rb_erase(&vma->vm_rb, &mm->mm_rb);
69554 mm->map_count--;
69555 tail_vma = vma;
69556 @@ -1933,14 +2243,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69557 struct vm_area_struct *new;
69558 int err = -ENOMEM;
69559
69560 +#ifdef CONFIG_PAX_SEGMEXEC
69561 + struct vm_area_struct *vma_m, *new_m = NULL;
69562 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
69563 +#endif
69564 +
69565 if (is_vm_hugetlb_page(vma) && (addr &
69566 ~(huge_page_mask(hstate_vma(vma)))))
69567 return -EINVAL;
69568
69569 +#ifdef CONFIG_PAX_SEGMEXEC
69570 + vma_m = pax_find_mirror_vma(vma);
69571 +#endif
69572 +
69573 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69574 if (!new)
69575 goto out_err;
69576
69577 +#ifdef CONFIG_PAX_SEGMEXEC
69578 + if (vma_m) {
69579 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69580 + if (!new_m) {
69581 + kmem_cache_free(vm_area_cachep, new);
69582 + goto out_err;
69583 + }
69584 + }
69585 +#endif
69586 +
69587 /* most fields are the same, copy all, and then fixup */
69588 *new = *vma;
69589
69590 @@ -1953,6 +2282,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69591 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
69592 }
69593
69594 +#ifdef CONFIG_PAX_SEGMEXEC
69595 + if (vma_m) {
69596 + *new_m = *vma_m;
69597 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
69598 + new_m->vm_mirror = new;
69599 + new->vm_mirror = new_m;
69600 +
69601 + if (new_below)
69602 + new_m->vm_end = addr_m;
69603 + else {
69604 + new_m->vm_start = addr_m;
69605 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
69606 + }
69607 + }
69608 +#endif
69609 +
69610 pol = mpol_dup(vma_policy(vma));
69611 if (IS_ERR(pol)) {
69612 err = PTR_ERR(pol);
69613 @@ -1978,6 +2323,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69614 else
69615 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
69616
69617 +#ifdef CONFIG_PAX_SEGMEXEC
69618 + if (!err && vma_m) {
69619 + if (anon_vma_clone(new_m, vma_m))
69620 + goto out_free_mpol;
69621 +
69622 + mpol_get(pol);
69623 + vma_set_policy(new_m, pol);
69624 +
69625 + if (new_m->vm_file) {
69626 + get_file(new_m->vm_file);
69627 + if (vma_m->vm_flags & VM_EXECUTABLE)
69628 + added_exe_file_vma(mm);
69629 + }
69630 +
69631 + if (new_m->vm_ops && new_m->vm_ops->open)
69632 + new_m->vm_ops->open(new_m);
69633 +
69634 + if (new_below)
69635 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
69636 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
69637 + else
69638 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
69639 +
69640 + if (err) {
69641 + if (new_m->vm_ops && new_m->vm_ops->close)
69642 + new_m->vm_ops->close(new_m);
69643 + if (new_m->vm_file) {
69644 + if (vma_m->vm_flags & VM_EXECUTABLE)
69645 + removed_exe_file_vma(mm);
69646 + fput(new_m->vm_file);
69647 + }
69648 + mpol_put(pol);
69649 + }
69650 + }
69651 +#endif
69652 +
69653 /* Success. */
69654 if (!err)
69655 return 0;
69656 @@ -1990,10 +2371,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69657 removed_exe_file_vma(mm);
69658 fput(new->vm_file);
69659 }
69660 - unlink_anon_vmas(new);
69661 out_free_mpol:
69662 mpol_put(pol);
69663 out_free_vma:
69664 +
69665 +#ifdef CONFIG_PAX_SEGMEXEC
69666 + if (new_m) {
69667 + unlink_anon_vmas(new_m);
69668 + kmem_cache_free(vm_area_cachep, new_m);
69669 + }
69670 +#endif
69671 +
69672 + unlink_anon_vmas(new);
69673 kmem_cache_free(vm_area_cachep, new);
69674 out_err:
69675 return err;
69676 @@ -2006,6 +2395,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69677 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
69678 unsigned long addr, int new_below)
69679 {
69680 +
69681 +#ifdef CONFIG_PAX_SEGMEXEC
69682 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
69683 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
69684 + if (mm->map_count >= sysctl_max_map_count-1)
69685 + return -ENOMEM;
69686 + } else
69687 +#endif
69688 +
69689 if (mm->map_count >= sysctl_max_map_count)
69690 return -ENOMEM;
69691
69692 @@ -2017,11 +2415,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
69693 * work. This now handles partial unmappings.
69694 * Jeremy Fitzhardinge <jeremy@goop.org>
69695 */
69696 +#ifdef CONFIG_PAX_SEGMEXEC
69697 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69698 {
69699 + int ret = __do_munmap(mm, start, len);
69700 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
69701 + return ret;
69702 +
69703 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
69704 +}
69705 +
69706 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69707 +#else
69708 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69709 +#endif
69710 +{
69711 unsigned long end;
69712 struct vm_area_struct *vma, *prev, *last;
69713
69714 + /*
69715 + * mm->mmap_sem is required to protect against another thread
69716 + * changing the mappings in case we sleep.
69717 + */
69718 + verify_mm_writelocked(mm);
69719 +
69720 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
69721 return -EINVAL;
69722
69723 @@ -2096,6 +2513,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69724 /* Fix up all other VM information */
69725 remove_vma_list(mm, vma);
69726
69727 + track_exec_limit(mm, start, end, 0UL);
69728 +
69729 return 0;
69730 }
69731
69732 @@ -2108,22 +2527,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
69733
69734 profile_munmap(addr);
69735
69736 +#ifdef CONFIG_PAX_SEGMEXEC
69737 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
69738 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
69739 + return -EINVAL;
69740 +#endif
69741 +
69742 down_write(&mm->mmap_sem);
69743 ret = do_munmap(mm, addr, len);
69744 up_write(&mm->mmap_sem);
69745 return ret;
69746 }
69747
69748 -static inline void verify_mm_writelocked(struct mm_struct *mm)
69749 -{
69750 -#ifdef CONFIG_DEBUG_VM
69751 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
69752 - WARN_ON(1);
69753 - up_read(&mm->mmap_sem);
69754 - }
69755 -#endif
69756 -}
69757 -
69758 /*
69759 * this is really a simplified "do_mmap". it only handles
69760 * anonymous maps. eventually we may be able to do some
69761 @@ -2137,6 +2552,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69762 struct rb_node ** rb_link, * rb_parent;
69763 pgoff_t pgoff = addr >> PAGE_SHIFT;
69764 int error;
69765 + unsigned long charged;
69766
69767 len = PAGE_ALIGN(len);
69768 if (!len)
69769 @@ -2148,16 +2564,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69770
69771 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
69772
69773 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
69774 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
69775 + flags &= ~VM_EXEC;
69776 +
69777 +#ifdef CONFIG_PAX_MPROTECT
69778 + if (mm->pax_flags & MF_PAX_MPROTECT)
69779 + flags &= ~VM_MAYEXEC;
69780 +#endif
69781 +
69782 + }
69783 +#endif
69784 +
69785 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
69786 if (error & ~PAGE_MASK)
69787 return error;
69788
69789 + charged = len >> PAGE_SHIFT;
69790 +
69791 /*
69792 * mlock MCL_FUTURE?
69793 */
69794 if (mm->def_flags & VM_LOCKED) {
69795 unsigned long locked, lock_limit;
69796 - locked = len >> PAGE_SHIFT;
69797 + locked = charged;
69798 locked += mm->locked_vm;
69799 lock_limit = rlimit(RLIMIT_MEMLOCK);
69800 lock_limit >>= PAGE_SHIFT;
69801 @@ -2174,22 +2604,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69802 /*
69803 * Clear old maps. this also does some error checking for us
69804 */
69805 - munmap_back:
69806 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69807 if (vma && vma->vm_start < addr + len) {
69808 if (do_munmap(mm, addr, len))
69809 return -ENOMEM;
69810 - goto munmap_back;
69811 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69812 + BUG_ON(vma && vma->vm_start < addr + len);
69813 }
69814
69815 /* Check against address space limits *after* clearing old maps... */
69816 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
69817 + if (!may_expand_vm(mm, charged))
69818 return -ENOMEM;
69819
69820 if (mm->map_count > sysctl_max_map_count)
69821 return -ENOMEM;
69822
69823 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
69824 + if (security_vm_enough_memory(charged))
69825 return -ENOMEM;
69826
69827 /* Can we just expand an old private anonymous mapping? */
69828 @@ -2203,7 +2633,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69829 */
69830 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69831 if (!vma) {
69832 - vm_unacct_memory(len >> PAGE_SHIFT);
69833 + vm_unacct_memory(charged);
69834 return -ENOMEM;
69835 }
69836
69837 @@ -2217,11 +2647,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69838 vma_link(mm, vma, prev, rb_link, rb_parent);
69839 out:
69840 perf_event_mmap(vma);
69841 - mm->total_vm += len >> PAGE_SHIFT;
69842 + mm->total_vm += charged;
69843 if (flags & VM_LOCKED) {
69844 if (!mlock_vma_pages_range(vma, addr, addr + len))
69845 - mm->locked_vm += (len >> PAGE_SHIFT);
69846 + mm->locked_vm += charged;
69847 }
69848 + track_exec_limit(mm, addr, addr + len, flags);
69849 return addr;
69850 }
69851
69852 @@ -2268,8 +2699,10 @@ void exit_mmap(struct mm_struct *mm)
69853 * Walk the list again, actually closing and freeing it,
69854 * with preemption enabled, without holding any MM locks.
69855 */
69856 - while (vma)
69857 + while (vma) {
69858 + vma->vm_mirror = NULL;
69859 vma = remove_vma(vma);
69860 + }
69861
69862 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
69863 }
69864 @@ -2283,6 +2716,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
69865 struct vm_area_struct * __vma, * prev;
69866 struct rb_node ** rb_link, * rb_parent;
69867
69868 +#ifdef CONFIG_PAX_SEGMEXEC
69869 + struct vm_area_struct *vma_m = NULL;
69870 +#endif
69871 +
69872 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
69873 + return -EPERM;
69874 +
69875 /*
69876 * The vm_pgoff of a purely anonymous vma should be irrelevant
69877 * until its first write fault, when page's anon_vma and index
69878 @@ -2305,7 +2745,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
69879 if ((vma->vm_flags & VM_ACCOUNT) &&
69880 security_vm_enough_memory_mm(mm, vma_pages(vma)))
69881 return -ENOMEM;
69882 +
69883 +#ifdef CONFIG_PAX_SEGMEXEC
69884 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
69885 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69886 + if (!vma_m)
69887 + return -ENOMEM;
69888 + }
69889 +#endif
69890 +
69891 vma_link(mm, vma, prev, rb_link, rb_parent);
69892 +
69893 +#ifdef CONFIG_PAX_SEGMEXEC
69894 + if (vma_m)
69895 + BUG_ON(pax_mirror_vma(vma_m, vma));
69896 +#endif
69897 +
69898 return 0;
69899 }
69900
69901 @@ -2323,6 +2778,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
69902 struct rb_node **rb_link, *rb_parent;
69903 struct mempolicy *pol;
69904
69905 + BUG_ON(vma->vm_mirror);
69906 +
69907 /*
69908 * If anonymous vma has not yet been faulted, update new pgoff
69909 * to match new location, to increase its chance of merging.
69910 @@ -2373,6 +2830,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
69911 return NULL;
69912 }
69913
69914 +#ifdef CONFIG_PAX_SEGMEXEC
69915 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
69916 +{
69917 + struct vm_area_struct *prev_m;
69918 + struct rb_node **rb_link_m, *rb_parent_m;
69919 + struct mempolicy *pol_m;
69920 +
69921 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
69922 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
69923 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
69924 + *vma_m = *vma;
69925 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
69926 + if (anon_vma_clone(vma_m, vma))
69927 + return -ENOMEM;
69928 + pol_m = vma_policy(vma_m);
69929 + mpol_get(pol_m);
69930 + vma_set_policy(vma_m, pol_m);
69931 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
69932 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
69933 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
69934 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
69935 + if (vma_m->vm_file)
69936 + get_file(vma_m->vm_file);
69937 + if (vma_m->vm_ops && vma_m->vm_ops->open)
69938 + vma_m->vm_ops->open(vma_m);
69939 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
69940 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
69941 + vma_m->vm_mirror = vma;
69942 + vma->vm_mirror = vma_m;
69943 + return 0;
69944 +}
69945 +#endif
69946 +
69947 /*
69948 * Return true if the calling process may expand its vm space by the passed
69949 * number of pages
69950 @@ -2383,7 +2873,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
69951 unsigned long lim;
69952
69953 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
69954 -
69955 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
69956 if (cur + npages > lim)
69957 return 0;
69958 return 1;
69959 @@ -2454,6 +2944,22 @@ int install_special_mapping(struct mm_struct *mm,
69960 vma->vm_start = addr;
69961 vma->vm_end = addr + len;
69962
69963 +#ifdef CONFIG_PAX_MPROTECT
69964 + if (mm->pax_flags & MF_PAX_MPROTECT) {
69965 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
69966 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
69967 + return -EPERM;
69968 + if (!(vm_flags & VM_EXEC))
69969 + vm_flags &= ~VM_MAYEXEC;
69970 +#else
69971 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
69972 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
69973 +#endif
69974 + else
69975 + vm_flags &= ~VM_MAYWRITE;
69976 + }
69977 +#endif
69978 +
69979 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
69980 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
69981
69982 diff --git a/mm/mprotect.c b/mm/mprotect.c
69983 index 5a688a2..27e031c 100644
69984 --- a/mm/mprotect.c
69985 +++ b/mm/mprotect.c
69986 @@ -23,10 +23,16 @@
69987 #include <linux/mmu_notifier.h>
69988 #include <linux/migrate.h>
69989 #include <linux/perf_event.h>
69990 +
69991 +#ifdef CONFIG_PAX_MPROTECT
69992 +#include <linux/elf.h>
69993 +#endif
69994 +
69995 #include <asm/uaccess.h>
69996 #include <asm/pgtable.h>
69997 #include <asm/cacheflush.h>
69998 #include <asm/tlbflush.h>
69999 +#include <asm/mmu_context.h>
70000
70001 #ifndef pgprot_modify
70002 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
70003 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
70004 flush_tlb_range(vma, start, end);
70005 }
70006
70007 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70008 +/* called while holding the mmap semaphor for writing except stack expansion */
70009 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
70010 +{
70011 + unsigned long oldlimit, newlimit = 0UL;
70012 +
70013 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
70014 + return;
70015 +
70016 + spin_lock(&mm->page_table_lock);
70017 + oldlimit = mm->context.user_cs_limit;
70018 + if ((prot & VM_EXEC) && oldlimit < end)
70019 + /* USER_CS limit moved up */
70020 + newlimit = end;
70021 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
70022 + /* USER_CS limit moved down */
70023 + newlimit = start;
70024 +
70025 + if (newlimit) {
70026 + mm->context.user_cs_limit = newlimit;
70027 +
70028 +#ifdef CONFIG_SMP
70029 + wmb();
70030 + cpus_clear(mm->context.cpu_user_cs_mask);
70031 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
70032 +#endif
70033 +
70034 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
70035 + }
70036 + spin_unlock(&mm->page_table_lock);
70037 + if (newlimit == end) {
70038 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
70039 +
70040 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
70041 + if (is_vm_hugetlb_page(vma))
70042 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
70043 + else
70044 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
70045 + }
70046 +}
70047 +#endif
70048 +
70049 int
70050 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70051 unsigned long start, unsigned long end, unsigned long newflags)
70052 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70053 int error;
70054 int dirty_accountable = 0;
70055
70056 +#ifdef CONFIG_PAX_SEGMEXEC
70057 + struct vm_area_struct *vma_m = NULL;
70058 + unsigned long start_m, end_m;
70059 +
70060 + start_m = start + SEGMEXEC_TASK_SIZE;
70061 + end_m = end + SEGMEXEC_TASK_SIZE;
70062 +#endif
70063 +
70064 if (newflags == oldflags) {
70065 *pprev = vma;
70066 return 0;
70067 }
70068
70069 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
70070 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
70071 +
70072 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
70073 + return -ENOMEM;
70074 +
70075 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
70076 + return -ENOMEM;
70077 + }
70078 +
70079 /*
70080 * If we make a private mapping writable we increase our commit;
70081 * but (without finer accounting) cannot reduce our commit if we
70082 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70083 }
70084 }
70085
70086 +#ifdef CONFIG_PAX_SEGMEXEC
70087 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
70088 + if (start != vma->vm_start) {
70089 + error = split_vma(mm, vma, start, 1);
70090 + if (error)
70091 + goto fail;
70092 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
70093 + *pprev = (*pprev)->vm_next;
70094 + }
70095 +
70096 + if (end != vma->vm_end) {
70097 + error = split_vma(mm, vma, end, 0);
70098 + if (error)
70099 + goto fail;
70100 + }
70101 +
70102 + if (pax_find_mirror_vma(vma)) {
70103 + error = __do_munmap(mm, start_m, end_m - start_m);
70104 + if (error)
70105 + goto fail;
70106 + } else {
70107 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70108 + if (!vma_m) {
70109 + error = -ENOMEM;
70110 + goto fail;
70111 + }
70112 + vma->vm_flags = newflags;
70113 + error = pax_mirror_vma(vma_m, vma);
70114 + if (error) {
70115 + vma->vm_flags = oldflags;
70116 + goto fail;
70117 + }
70118 + }
70119 + }
70120 +#endif
70121 +
70122 /*
70123 * First try to merge with previous and/or next vma.
70124 */
70125 @@ -204,9 +306,21 @@ success:
70126 * vm_flags and vm_page_prot are protected by the mmap_sem
70127 * held in write mode.
70128 */
70129 +
70130 +#ifdef CONFIG_PAX_SEGMEXEC
70131 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
70132 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
70133 +#endif
70134 +
70135 vma->vm_flags = newflags;
70136 +
70137 +#ifdef CONFIG_PAX_MPROTECT
70138 + if (mm->binfmt && mm->binfmt->handle_mprotect)
70139 + mm->binfmt->handle_mprotect(vma, newflags);
70140 +#endif
70141 +
70142 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
70143 - vm_get_page_prot(newflags));
70144 + vm_get_page_prot(vma->vm_flags));
70145
70146 if (vma_wants_writenotify(vma)) {
70147 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
70148 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70149 end = start + len;
70150 if (end <= start)
70151 return -ENOMEM;
70152 +
70153 +#ifdef CONFIG_PAX_SEGMEXEC
70154 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70155 + if (end > SEGMEXEC_TASK_SIZE)
70156 + return -EINVAL;
70157 + } else
70158 +#endif
70159 +
70160 + if (end > TASK_SIZE)
70161 + return -EINVAL;
70162 +
70163 if (!arch_validate_prot(prot))
70164 return -EINVAL;
70165
70166 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70167 /*
70168 * Does the application expect PROT_READ to imply PROT_EXEC:
70169 */
70170 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70171 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70172 prot |= PROT_EXEC;
70173
70174 vm_flags = calc_vm_prot_bits(prot);
70175 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70176 if (start > vma->vm_start)
70177 prev = vma;
70178
70179 +#ifdef CONFIG_PAX_MPROTECT
70180 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
70181 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
70182 +#endif
70183 +
70184 for (nstart = start ; ; ) {
70185 unsigned long newflags;
70186
70187 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70188
70189 /* newflags >> 4 shift VM_MAY% in place of VM_% */
70190 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
70191 + if (prot & (PROT_WRITE | PROT_EXEC))
70192 + gr_log_rwxmprotect(vma->vm_file);
70193 +
70194 + error = -EACCES;
70195 + goto out;
70196 + }
70197 +
70198 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
70199 error = -EACCES;
70200 goto out;
70201 }
70202 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70203 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
70204 if (error)
70205 goto out;
70206 +
70207 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
70208 +
70209 nstart = tmp;
70210
70211 if (nstart < prev->vm_end)
70212 diff --git a/mm/mremap.c b/mm/mremap.c
70213 index d6959cb..18a402a 100644
70214 --- a/mm/mremap.c
70215 +++ b/mm/mremap.c
70216 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
70217 continue;
70218 pte = ptep_get_and_clear(mm, old_addr, old_pte);
70219 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
70220 +
70221 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70222 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
70223 + pte = pte_exprotect(pte);
70224 +#endif
70225 +
70226 set_pte_at(mm, new_addr, new_pte, pte);
70227 }
70228
70229 @@ -290,6 +296,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
70230 if (is_vm_hugetlb_page(vma))
70231 goto Einval;
70232
70233 +#ifdef CONFIG_PAX_SEGMEXEC
70234 + if (pax_find_mirror_vma(vma))
70235 + goto Einval;
70236 +#endif
70237 +
70238 /* We can't remap across vm area boundaries */
70239 if (old_len > vma->vm_end - addr)
70240 goto Efault;
70241 @@ -346,20 +357,25 @@ static unsigned long mremap_to(unsigned long addr,
70242 unsigned long ret = -EINVAL;
70243 unsigned long charged = 0;
70244 unsigned long map_flags;
70245 + unsigned long pax_task_size = TASK_SIZE;
70246
70247 if (new_addr & ~PAGE_MASK)
70248 goto out;
70249
70250 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
70251 +#ifdef CONFIG_PAX_SEGMEXEC
70252 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
70253 + pax_task_size = SEGMEXEC_TASK_SIZE;
70254 +#endif
70255 +
70256 + pax_task_size -= PAGE_SIZE;
70257 +
70258 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
70259 goto out;
70260
70261 /* Check if the location we're moving into overlaps the
70262 * old location at all, and fail if it does.
70263 */
70264 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
70265 - goto out;
70266 -
70267 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
70268 + if (addr + old_len > new_addr && new_addr + new_len > addr)
70269 goto out;
70270
70271 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
70272 @@ -431,6 +447,7 @@ unsigned long do_mremap(unsigned long addr,
70273 struct vm_area_struct *vma;
70274 unsigned long ret = -EINVAL;
70275 unsigned long charged = 0;
70276 + unsigned long pax_task_size = TASK_SIZE;
70277
70278 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
70279 goto out;
70280 @@ -449,6 +466,17 @@ unsigned long do_mremap(unsigned long addr,
70281 if (!new_len)
70282 goto out;
70283
70284 +#ifdef CONFIG_PAX_SEGMEXEC
70285 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
70286 + pax_task_size = SEGMEXEC_TASK_SIZE;
70287 +#endif
70288 +
70289 + pax_task_size -= PAGE_SIZE;
70290 +
70291 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
70292 + old_len > pax_task_size || addr > pax_task_size-old_len)
70293 + goto out;
70294 +
70295 if (flags & MREMAP_FIXED) {
70296 if (flags & MREMAP_MAYMOVE)
70297 ret = mremap_to(addr, old_len, new_addr, new_len);
70298 @@ -498,6 +526,7 @@ unsigned long do_mremap(unsigned long addr,
70299 addr + new_len);
70300 }
70301 ret = addr;
70302 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
70303 goto out;
70304 }
70305 }
70306 @@ -524,7 +553,13 @@ unsigned long do_mremap(unsigned long addr,
70307 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
70308 if (ret)
70309 goto out;
70310 +
70311 + map_flags = vma->vm_flags;
70312 ret = move_vma(vma, addr, old_len, new_len, new_addr);
70313 + if (!(ret & ~PAGE_MASK)) {
70314 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
70315 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
70316 + }
70317 }
70318 out:
70319 if (ret & ~PAGE_MASK)
70320 diff --git a/mm/nobootmem.c b/mm/nobootmem.c
70321 index 7fa41b4..6087460 100644
70322 --- a/mm/nobootmem.c
70323 +++ b/mm/nobootmem.c
70324 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
70325 unsigned long __init free_all_memory_core_early(int nodeid)
70326 {
70327 int i;
70328 - u64 start, end;
70329 + u64 start, end, startrange, endrange;
70330 unsigned long count = 0;
70331 - struct range *range = NULL;
70332 + struct range *range = NULL, rangerange = { 0, 0 };
70333 int nr_range;
70334
70335 nr_range = get_free_all_memory_range(&range, nodeid);
70336 + startrange = __pa(range) >> PAGE_SHIFT;
70337 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
70338
70339 for (i = 0; i < nr_range; i++) {
70340 start = range[i].start;
70341 end = range[i].end;
70342 + if (start <= endrange && startrange < end) {
70343 + BUG_ON(rangerange.start | rangerange.end);
70344 + rangerange = range[i];
70345 + continue;
70346 + }
70347 count += end - start;
70348 __free_pages_memory(start, end);
70349 }
70350 + start = rangerange.start;
70351 + end = rangerange.end;
70352 + count += end - start;
70353 + __free_pages_memory(start, end);
70354
70355 return count;
70356 }
70357 diff --git a/mm/nommu.c b/mm/nommu.c
70358 index b982290..7d73f53 100644
70359 --- a/mm/nommu.c
70360 +++ b/mm/nommu.c
70361 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
70362 int sysctl_overcommit_ratio = 50; /* default is 50% */
70363 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
70364 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
70365 -int heap_stack_gap = 0;
70366
70367 atomic_long_t mmap_pages_allocated;
70368
70369 @@ -825,15 +824,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
70370 EXPORT_SYMBOL(find_vma);
70371
70372 /*
70373 - * find a VMA
70374 - * - we don't extend stack VMAs under NOMMU conditions
70375 - */
70376 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
70377 -{
70378 - return find_vma(mm, addr);
70379 -}
70380 -
70381 -/*
70382 * expand a stack to a given address
70383 * - not supported under NOMMU conditions
70384 */
70385 @@ -1553,6 +1543,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
70386
70387 /* most fields are the same, copy all, and then fixup */
70388 *new = *vma;
70389 + INIT_LIST_HEAD(&new->anon_vma_chain);
70390 *region = *vma->vm_region;
70391 new->vm_region = region;
70392
70393 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
70394 index 485be89..c059ad3 100644
70395 --- a/mm/page_alloc.c
70396 +++ b/mm/page_alloc.c
70397 @@ -341,7 +341,7 @@ out:
70398 * This usage means that zero-order pages may not be compound.
70399 */
70400
70401 -static void free_compound_page(struct page *page)
70402 +void free_compound_page(struct page *page)
70403 {
70404 __free_pages_ok(page, compound_order(page));
70405 }
70406 @@ -654,6 +654,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
70407 int i;
70408 int bad = 0;
70409
70410 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
70411 + unsigned long index = 1UL << order;
70412 +#endif
70413 +
70414 trace_mm_page_free_direct(page, order);
70415 kmemcheck_free_shadow(page, order);
70416
70417 @@ -669,6 +673,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
70418 debug_check_no_obj_freed(page_address(page),
70419 PAGE_SIZE << order);
70420 }
70421 +
70422 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
70423 + for (; index; --index)
70424 + sanitize_highpage(page + index - 1);
70425 +#endif
70426 +
70427 arch_free_page(page, order);
70428 kernel_map_pages(page, 1 << order, 0);
70429
70430 @@ -784,8 +794,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
70431 arch_alloc_page(page, order);
70432 kernel_map_pages(page, 1 << order, 1);
70433
70434 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
70435 if (gfp_flags & __GFP_ZERO)
70436 prep_zero_page(page, order, gfp_flags);
70437 +#endif
70438
70439 if (order && (gfp_flags & __GFP_COMP))
70440 prep_compound_page(page, order);
70441 @@ -3357,7 +3369,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
70442 unsigned long pfn;
70443
70444 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
70445 +#ifdef CONFIG_X86_32
70446 + /* boot failures in VMware 8 on 32bit vanilla since
70447 + this change */
70448 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
70449 +#else
70450 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
70451 +#endif
70452 return 1;
70453 }
70454 return 0;
70455 diff --git a/mm/percpu.c b/mm/percpu.c
70456 index 716eb4a..8d10419 100644
70457 --- a/mm/percpu.c
70458 +++ b/mm/percpu.c
70459 @@ -121,7 +121,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
70460 static unsigned int pcpu_high_unit_cpu __read_mostly;
70461
70462 /* the address of the first chunk which starts with the kernel static area */
70463 -void *pcpu_base_addr __read_mostly;
70464 +void *pcpu_base_addr __read_only;
70465 EXPORT_SYMBOL_GPL(pcpu_base_addr);
70466
70467 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
70468 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
70469 index e920aa3..137702a 100644
70470 --- a/mm/process_vm_access.c
70471 +++ b/mm/process_vm_access.c
70472 @@ -13,6 +13,7 @@
70473 #include <linux/uio.h>
70474 #include <linux/sched.h>
70475 #include <linux/highmem.h>
70476 +#include <linux/security.h>
70477 #include <linux/ptrace.h>
70478 #include <linux/slab.h>
70479 #include <linux/syscalls.h>
70480 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
70481 size_t iov_l_curr_offset = 0;
70482 ssize_t iov_len;
70483
70484 + return -ENOSYS; // PaX: until properly audited
70485 +
70486 /*
70487 * Work out how many pages of struct pages we're going to need
70488 * when eventually calling get_user_pages
70489 */
70490 for (i = 0; i < riovcnt; i++) {
70491 iov_len = rvec[i].iov_len;
70492 - if (iov_len > 0) {
70493 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
70494 - + iov_len)
70495 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
70496 - / PAGE_SIZE + 1;
70497 - nr_pages = max(nr_pages, nr_pages_iov);
70498 - }
70499 + if (iov_len <= 0)
70500 + continue;
70501 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
70502 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
70503 + nr_pages = max(nr_pages, nr_pages_iov);
70504 }
70505
70506 if (nr_pages == 0)
70507 @@ -298,23 +299,23 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
70508 goto free_proc_pages;
70509 }
70510
70511 - task_lock(task);
70512 - if (__ptrace_may_access(task, PTRACE_MODE_ATTACH)) {
70513 - task_unlock(task);
70514 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
70515 rc = -EPERM;
70516 goto put_task_struct;
70517 }
70518 - mm = task->mm;
70519
70520 - if (!mm || (task->flags & PF_KTHREAD)) {
70521 - task_unlock(task);
70522 - rc = -EINVAL;
70523 + mm = mm_access(task, PTRACE_MODE_ATTACH);
70524 + if (!mm || IS_ERR(mm)) {
70525 + rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
70526 + /*
70527 + * Explicitly map EACCES to EPERM as EPERM is a more a
70528 + * appropriate error code for process_vw_readv/writev
70529 + */
70530 + if (rc == -EACCES)
70531 + rc = -EPERM;
70532 goto put_task_struct;
70533 }
70534
70535 - atomic_inc(&mm->mm_users);
70536 - task_unlock(task);
70537 -
70538 for (i = 0; i < riovcnt && iov_l_curr_idx < liovcnt; i++) {
70539 rc = process_vm_rw_single_vec(
70540 (unsigned long)rvec[i].iov_base, rvec[i].iov_len,
70541 diff --git a/mm/rmap.c b/mm/rmap.c
70542 index a4fd368..e0ffec7 100644
70543 --- a/mm/rmap.c
70544 +++ b/mm/rmap.c
70545 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70546 struct anon_vma *anon_vma = vma->anon_vma;
70547 struct anon_vma_chain *avc;
70548
70549 +#ifdef CONFIG_PAX_SEGMEXEC
70550 + struct anon_vma_chain *avc_m = NULL;
70551 +#endif
70552 +
70553 might_sleep();
70554 if (unlikely(!anon_vma)) {
70555 struct mm_struct *mm = vma->vm_mm;
70556 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70557 if (!avc)
70558 goto out_enomem;
70559
70560 +#ifdef CONFIG_PAX_SEGMEXEC
70561 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
70562 + if (!avc_m)
70563 + goto out_enomem_free_avc;
70564 +#endif
70565 +
70566 anon_vma = find_mergeable_anon_vma(vma);
70567 allocated = NULL;
70568 if (!anon_vma) {
70569 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70570 /* page_table_lock to protect against threads */
70571 spin_lock(&mm->page_table_lock);
70572 if (likely(!vma->anon_vma)) {
70573 +
70574 +#ifdef CONFIG_PAX_SEGMEXEC
70575 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
70576 +
70577 + if (vma_m) {
70578 + BUG_ON(vma_m->anon_vma);
70579 + vma_m->anon_vma = anon_vma;
70580 + avc_m->anon_vma = anon_vma;
70581 + avc_m->vma = vma;
70582 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
70583 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
70584 + avc_m = NULL;
70585 + }
70586 +#endif
70587 +
70588 vma->anon_vma = anon_vma;
70589 avc->anon_vma = anon_vma;
70590 avc->vma = vma;
70591 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70592
70593 if (unlikely(allocated))
70594 put_anon_vma(allocated);
70595 +
70596 +#ifdef CONFIG_PAX_SEGMEXEC
70597 + if (unlikely(avc_m))
70598 + anon_vma_chain_free(avc_m);
70599 +#endif
70600 +
70601 if (unlikely(avc))
70602 anon_vma_chain_free(avc);
70603 }
70604 return 0;
70605
70606 out_enomem_free_avc:
70607 +
70608 +#ifdef CONFIG_PAX_SEGMEXEC
70609 + if (avc_m)
70610 + anon_vma_chain_free(avc_m);
70611 +#endif
70612 +
70613 anon_vma_chain_free(avc);
70614 out_enomem:
70615 return -ENOMEM;
70616 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
70617 * Attach the anon_vmas from src to dst.
70618 * Returns 0 on success, -ENOMEM on failure.
70619 */
70620 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
70621 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
70622 {
70623 struct anon_vma_chain *avc, *pavc;
70624 struct anon_vma *root = NULL;
70625 @@ -276,7 +313,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
70626 * the corresponding VMA in the parent process is attached to.
70627 * Returns 0 on success, non-zero on failure.
70628 */
70629 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
70630 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
70631 {
70632 struct anon_vma_chain *avc;
70633 struct anon_vma *anon_vma;
70634 diff --git a/mm/shmem.c b/mm/shmem.c
70635 index 6c253f7..367e20a 100644
70636 --- a/mm/shmem.c
70637 +++ b/mm/shmem.c
70638 @@ -31,7 +31,7 @@
70639 #include <linux/export.h>
70640 #include <linux/swap.h>
70641
70642 -static struct vfsmount *shm_mnt;
70643 +struct vfsmount *shm_mnt;
70644
70645 #ifdef CONFIG_SHMEM
70646 /*
70647 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
70648 #define BOGO_DIRENT_SIZE 20
70649
70650 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
70651 -#define SHORT_SYMLINK_LEN 128
70652 +#define SHORT_SYMLINK_LEN 64
70653
70654 struct shmem_xattr {
70655 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
70656 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
70657 int err = -ENOMEM;
70658
70659 /* Round up to L1_CACHE_BYTES to resist false sharing */
70660 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
70661 - L1_CACHE_BYTES), GFP_KERNEL);
70662 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
70663 if (!sbinfo)
70664 return -ENOMEM;
70665
70666 diff --git a/mm/slab.c b/mm/slab.c
70667 index 83311c9a..fcf8f86 100644
70668 --- a/mm/slab.c
70669 +++ b/mm/slab.c
70670 @@ -151,7 +151,7 @@
70671
70672 /* Legal flag mask for kmem_cache_create(). */
70673 #if DEBUG
70674 -# define CREATE_MASK (SLAB_RED_ZONE | \
70675 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
70676 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
70677 SLAB_CACHE_DMA | \
70678 SLAB_STORE_USER | \
70679 @@ -159,7 +159,7 @@
70680 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
70681 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
70682 #else
70683 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
70684 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
70685 SLAB_CACHE_DMA | \
70686 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
70687 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
70688 @@ -288,7 +288,7 @@ struct kmem_list3 {
70689 * Need this for bootstrapping a per node allocator.
70690 */
70691 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
70692 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
70693 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
70694 #define CACHE_CACHE 0
70695 #define SIZE_AC MAX_NUMNODES
70696 #define SIZE_L3 (2 * MAX_NUMNODES)
70697 @@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
70698 if ((x)->max_freeable < i) \
70699 (x)->max_freeable = i; \
70700 } while (0)
70701 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
70702 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
70703 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
70704 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
70705 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
70706 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
70707 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
70708 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
70709 #else
70710 #define STATS_INC_ACTIVE(x) do { } while (0)
70711 #define STATS_DEC_ACTIVE(x) do { } while (0)
70712 @@ -538,7 +538,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
70713 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
70714 */
70715 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
70716 - const struct slab *slab, void *obj)
70717 + const struct slab *slab, const void *obj)
70718 {
70719 u32 offset = (obj - slab->s_mem);
70720 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
70721 @@ -564,7 +564,7 @@ struct cache_names {
70722 static struct cache_names __initdata cache_names[] = {
70723 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
70724 #include <linux/kmalloc_sizes.h>
70725 - {NULL,}
70726 + {NULL}
70727 #undef CACHE
70728 };
70729
70730 @@ -1572,7 +1572,7 @@ void __init kmem_cache_init(void)
70731 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
70732 sizes[INDEX_AC].cs_size,
70733 ARCH_KMALLOC_MINALIGN,
70734 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70735 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70736 NULL);
70737
70738 if (INDEX_AC != INDEX_L3) {
70739 @@ -1580,7 +1580,7 @@ void __init kmem_cache_init(void)
70740 kmem_cache_create(names[INDEX_L3].name,
70741 sizes[INDEX_L3].cs_size,
70742 ARCH_KMALLOC_MINALIGN,
70743 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70744 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70745 NULL);
70746 }
70747
70748 @@ -1598,7 +1598,7 @@ void __init kmem_cache_init(void)
70749 sizes->cs_cachep = kmem_cache_create(names->name,
70750 sizes->cs_size,
70751 ARCH_KMALLOC_MINALIGN,
70752 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70753 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70754 NULL);
70755 }
70756 #ifdef CONFIG_ZONE_DMA
70757 @@ -4322,10 +4322,10 @@ static int s_show(struct seq_file *m, void *p)
70758 }
70759 /* cpu stats */
70760 {
70761 - unsigned long allochit = atomic_read(&cachep->allochit);
70762 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
70763 - unsigned long freehit = atomic_read(&cachep->freehit);
70764 - unsigned long freemiss = atomic_read(&cachep->freemiss);
70765 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
70766 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
70767 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
70768 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
70769
70770 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
70771 allochit, allocmiss, freehit, freemiss);
70772 @@ -4584,13 +4584,62 @@ static int __init slab_proc_init(void)
70773 {
70774 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
70775 #ifdef CONFIG_DEBUG_SLAB_LEAK
70776 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
70777 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
70778 #endif
70779 return 0;
70780 }
70781 module_init(slab_proc_init);
70782 #endif
70783
70784 +void check_object_size(const void *ptr, unsigned long n, bool to)
70785 +{
70786 +
70787 +#ifdef CONFIG_PAX_USERCOPY
70788 + struct page *page;
70789 + struct kmem_cache *cachep = NULL;
70790 + struct slab *slabp;
70791 + unsigned int objnr;
70792 + unsigned long offset;
70793 + const char *type;
70794 +
70795 + if (!n)
70796 + return;
70797 +
70798 + type = "<null>";
70799 + if (ZERO_OR_NULL_PTR(ptr))
70800 + goto report;
70801 +
70802 + if (!virt_addr_valid(ptr))
70803 + return;
70804 +
70805 + page = virt_to_head_page(ptr);
70806 +
70807 + type = "<process stack>";
70808 + if (!PageSlab(page)) {
70809 + if (object_is_on_stack(ptr, n) == -1)
70810 + goto report;
70811 + return;
70812 + }
70813 +
70814 + cachep = page_get_cache(page);
70815 + type = cachep->name;
70816 + if (!(cachep->flags & SLAB_USERCOPY))
70817 + goto report;
70818 +
70819 + slabp = page_get_slab(page);
70820 + objnr = obj_to_index(cachep, slabp, ptr);
70821 + BUG_ON(objnr >= cachep->num);
70822 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
70823 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
70824 + return;
70825 +
70826 +report:
70827 + pax_report_usercopy(ptr, n, to, type);
70828 +#endif
70829 +
70830 +}
70831 +EXPORT_SYMBOL(check_object_size);
70832 +
70833 /**
70834 * ksize - get the actual amount of memory allocated for a given object
70835 * @objp: Pointer to the object
70836 diff --git a/mm/slob.c b/mm/slob.c
70837 index 8105be4..e045f96 100644
70838 --- a/mm/slob.c
70839 +++ b/mm/slob.c
70840 @@ -29,7 +29,7 @@
70841 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
70842 * alloc_pages() directly, allocating compound pages so the page order
70843 * does not have to be separately tracked, and also stores the exact
70844 - * allocation size in page->private so that it can be used to accurately
70845 + * allocation size in slob_page->size so that it can be used to accurately
70846 * provide ksize(). These objects are detected in kfree() because slob_page()
70847 * is false for them.
70848 *
70849 @@ -58,6 +58,7 @@
70850 */
70851
70852 #include <linux/kernel.h>
70853 +#include <linux/sched.h>
70854 #include <linux/slab.h>
70855 #include <linux/mm.h>
70856 #include <linux/swap.h> /* struct reclaim_state */
70857 @@ -102,7 +103,8 @@ struct slob_page {
70858 unsigned long flags; /* mandatory */
70859 atomic_t _count; /* mandatory */
70860 slobidx_t units; /* free units left in page */
70861 - unsigned long pad[2];
70862 + unsigned long pad[1];
70863 + unsigned long size; /* size when >=PAGE_SIZE */
70864 slob_t *free; /* first free slob_t in page */
70865 struct list_head list; /* linked list of free pages */
70866 };
70867 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
70868 */
70869 static inline int is_slob_page(struct slob_page *sp)
70870 {
70871 - return PageSlab((struct page *)sp);
70872 + return PageSlab((struct page *)sp) && !sp->size;
70873 }
70874
70875 static inline void set_slob_page(struct slob_page *sp)
70876 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
70877
70878 static inline struct slob_page *slob_page(const void *addr)
70879 {
70880 - return (struct slob_page *)virt_to_page(addr);
70881 + return (struct slob_page *)virt_to_head_page(addr);
70882 }
70883
70884 /*
70885 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
70886 /*
70887 * Return the size of a slob block.
70888 */
70889 -static slobidx_t slob_units(slob_t *s)
70890 +static slobidx_t slob_units(const slob_t *s)
70891 {
70892 if (s->units > 0)
70893 return s->units;
70894 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
70895 /*
70896 * Return the next free slob block pointer after this one.
70897 */
70898 -static slob_t *slob_next(slob_t *s)
70899 +static slob_t *slob_next(const slob_t *s)
70900 {
70901 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
70902 slobidx_t next;
70903 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
70904 /*
70905 * Returns true if s is the last free block in its page.
70906 */
70907 -static int slob_last(slob_t *s)
70908 +static int slob_last(const slob_t *s)
70909 {
70910 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
70911 }
70912 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
70913 if (!page)
70914 return NULL;
70915
70916 + set_slob_page(page);
70917 return page_address(page);
70918 }
70919
70920 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
70921 if (!b)
70922 return NULL;
70923 sp = slob_page(b);
70924 - set_slob_page(sp);
70925
70926 spin_lock_irqsave(&slob_lock, flags);
70927 sp->units = SLOB_UNITS(PAGE_SIZE);
70928 sp->free = b;
70929 + sp->size = 0;
70930 INIT_LIST_HEAD(&sp->list);
70931 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
70932 set_slob_page_free(sp, slob_list);
70933 @@ -476,10 +479,9 @@ out:
70934 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
70935 */
70936
70937 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70938 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
70939 {
70940 - unsigned int *m;
70941 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70942 + slob_t *m;
70943 void *ret;
70944
70945 gfp &= gfp_allowed_mask;
70946 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70947
70948 if (!m)
70949 return NULL;
70950 - *m = size;
70951 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
70952 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
70953 + m[0].units = size;
70954 + m[1].units = align;
70955 ret = (void *)m + align;
70956
70957 trace_kmalloc_node(_RET_IP_, ret,
70958 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70959 gfp |= __GFP_COMP;
70960 ret = slob_new_pages(gfp, order, node);
70961 if (ret) {
70962 - struct page *page;
70963 - page = virt_to_page(ret);
70964 - page->private = size;
70965 + struct slob_page *sp;
70966 + sp = slob_page(ret);
70967 + sp->size = size;
70968 }
70969
70970 trace_kmalloc_node(_RET_IP_, ret,
70971 size, PAGE_SIZE << order, gfp, node);
70972 }
70973
70974 - kmemleak_alloc(ret, size, 1, gfp);
70975 + return ret;
70976 +}
70977 +
70978 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70979 +{
70980 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70981 + void *ret = __kmalloc_node_align(size, gfp, node, align);
70982 +
70983 + if (!ZERO_OR_NULL_PTR(ret))
70984 + kmemleak_alloc(ret, size, 1, gfp);
70985 return ret;
70986 }
70987 EXPORT_SYMBOL(__kmalloc_node);
70988 @@ -533,13 +547,92 @@ void kfree(const void *block)
70989 sp = slob_page(block);
70990 if (is_slob_page(sp)) {
70991 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70992 - unsigned int *m = (unsigned int *)(block - align);
70993 - slob_free(m, *m + align);
70994 - } else
70995 + slob_t *m = (slob_t *)(block - align);
70996 + slob_free(m, m[0].units + align);
70997 + } else {
70998 + clear_slob_page(sp);
70999 + free_slob_page(sp);
71000 + sp->size = 0;
71001 put_page(&sp->page);
71002 + }
71003 }
71004 EXPORT_SYMBOL(kfree);
71005
71006 +void check_object_size(const void *ptr, unsigned long n, bool to)
71007 +{
71008 +
71009 +#ifdef CONFIG_PAX_USERCOPY
71010 + struct slob_page *sp;
71011 + const slob_t *free;
71012 + const void *base;
71013 + unsigned long flags;
71014 + const char *type;
71015 +
71016 + if (!n)
71017 + return;
71018 +
71019 + type = "<null>";
71020 + if (ZERO_OR_NULL_PTR(ptr))
71021 + goto report;
71022 +
71023 + if (!virt_addr_valid(ptr))
71024 + return;
71025 +
71026 + type = "<process stack>";
71027 + sp = slob_page(ptr);
71028 + if (!PageSlab((struct page *)sp)) {
71029 + if (object_is_on_stack(ptr, n) == -1)
71030 + goto report;
71031 + return;
71032 + }
71033 +
71034 + type = "<slob>";
71035 + if (sp->size) {
71036 + base = page_address(&sp->page);
71037 + if (base <= ptr && n <= sp->size - (ptr - base))
71038 + return;
71039 + goto report;
71040 + }
71041 +
71042 + /* some tricky double walking to find the chunk */
71043 + spin_lock_irqsave(&slob_lock, flags);
71044 + base = (void *)((unsigned long)ptr & PAGE_MASK);
71045 + free = sp->free;
71046 +
71047 + while (!slob_last(free) && (void *)free <= ptr) {
71048 + base = free + slob_units(free);
71049 + free = slob_next(free);
71050 + }
71051 +
71052 + while (base < (void *)free) {
71053 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
71054 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
71055 + int offset;
71056 +
71057 + if (ptr < base + align)
71058 + break;
71059 +
71060 + offset = ptr - base - align;
71061 + if (offset >= m) {
71062 + base += size;
71063 + continue;
71064 + }
71065 +
71066 + if (n > m - offset)
71067 + break;
71068 +
71069 + spin_unlock_irqrestore(&slob_lock, flags);
71070 + return;
71071 + }
71072 +
71073 + spin_unlock_irqrestore(&slob_lock, flags);
71074 +report:
71075 + pax_report_usercopy(ptr, n, to, type);
71076 +#endif
71077 +
71078 +}
71079 +EXPORT_SYMBOL(check_object_size);
71080 +
71081 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
71082 size_t ksize(const void *block)
71083 {
71084 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
71085 sp = slob_page(block);
71086 if (is_slob_page(sp)) {
71087 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
71088 - unsigned int *m = (unsigned int *)(block - align);
71089 - return SLOB_UNITS(*m) * SLOB_UNIT;
71090 + slob_t *m = (slob_t *)(block - align);
71091 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
71092 } else
71093 - return sp->page.private;
71094 + return sp->size;
71095 }
71096 EXPORT_SYMBOL(ksize);
71097
71098 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71099 {
71100 struct kmem_cache *c;
71101
71102 +#ifdef CONFIG_PAX_USERCOPY
71103 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
71104 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
71105 +#else
71106 c = slob_alloc(sizeof(struct kmem_cache),
71107 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
71108 +#endif
71109
71110 if (c) {
71111 c->name = name;
71112 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
71113
71114 lockdep_trace_alloc(flags);
71115
71116 +#ifdef CONFIG_PAX_USERCOPY
71117 + b = __kmalloc_node_align(c->size, flags, node, c->align);
71118 +#else
71119 if (c->size < PAGE_SIZE) {
71120 b = slob_alloc(c->size, flags, c->align, node);
71121 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
71122 SLOB_UNITS(c->size) * SLOB_UNIT,
71123 flags, node);
71124 } else {
71125 + struct slob_page *sp;
71126 +
71127 b = slob_new_pages(flags, get_order(c->size), node);
71128 + sp = slob_page(b);
71129 + sp->size = c->size;
71130 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
71131 PAGE_SIZE << get_order(c->size),
71132 flags, node);
71133 }
71134 +#endif
71135
71136 if (c->ctor)
71137 c->ctor(b);
71138 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
71139
71140 static void __kmem_cache_free(void *b, int size)
71141 {
71142 - if (size < PAGE_SIZE)
71143 + struct slob_page *sp = slob_page(b);
71144 +
71145 + if (is_slob_page(sp))
71146 slob_free(b, size);
71147 - else
71148 + else {
71149 + clear_slob_page(sp);
71150 + free_slob_page(sp);
71151 + sp->size = 0;
71152 slob_free_pages(b, get_order(size));
71153 + }
71154 }
71155
71156 static void kmem_rcu_free(struct rcu_head *head)
71157 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
71158
71159 void kmem_cache_free(struct kmem_cache *c, void *b)
71160 {
71161 + int size = c->size;
71162 +
71163 +#ifdef CONFIG_PAX_USERCOPY
71164 + if (size + c->align < PAGE_SIZE) {
71165 + size += c->align;
71166 + b -= c->align;
71167 + }
71168 +#endif
71169 +
71170 kmemleak_free_recursive(b, c->flags);
71171 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
71172 struct slob_rcu *slob_rcu;
71173 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
71174 - slob_rcu->size = c->size;
71175 + slob_rcu = b + (size - sizeof(struct slob_rcu));
71176 + slob_rcu->size = size;
71177 call_rcu(&slob_rcu->head, kmem_rcu_free);
71178 } else {
71179 - __kmem_cache_free(b, c->size);
71180 + __kmem_cache_free(b, size);
71181 }
71182
71183 +#ifdef CONFIG_PAX_USERCOPY
71184 + trace_kfree(_RET_IP_, b);
71185 +#else
71186 trace_kmem_cache_free(_RET_IP_, b);
71187 +#endif
71188 +
71189 }
71190 EXPORT_SYMBOL(kmem_cache_free);
71191
71192 diff --git a/mm/slub.c b/mm/slub.c
71193 index 1a919f0..1739c9b 100644
71194 --- a/mm/slub.c
71195 +++ b/mm/slub.c
71196 @@ -208,7 +208,7 @@ struct track {
71197
71198 enum track_item { TRACK_ALLOC, TRACK_FREE };
71199
71200 -#ifdef CONFIG_SYSFS
71201 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71202 static int sysfs_slab_add(struct kmem_cache *);
71203 static int sysfs_slab_alias(struct kmem_cache *, const char *);
71204 static void sysfs_slab_remove(struct kmem_cache *);
71205 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
71206 if (!t->addr)
71207 return;
71208
71209 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
71210 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
71211 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
71212 #ifdef CONFIG_STACKTRACE
71213 {
71214 @@ -2559,6 +2559,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
71215
71216 page = virt_to_head_page(x);
71217
71218 + BUG_ON(!PageSlab(page));
71219 +
71220 slab_free(s, page, x, _RET_IP_);
71221
71222 trace_kmem_cache_free(_RET_IP_, x);
71223 @@ -2592,7 +2594,7 @@ static int slub_min_objects;
71224 * Merge control. If this is set then no merging of slab caches will occur.
71225 * (Could be removed. This was introduced to pacify the merge skeptics.)
71226 */
71227 -static int slub_nomerge;
71228 +static int slub_nomerge = 1;
71229
71230 /*
71231 * Calculate the order of allocation given an slab object size.
71232 @@ -3042,7 +3044,7 @@ static int kmem_cache_open(struct kmem_cache *s,
71233 else
71234 s->cpu_partial = 30;
71235
71236 - s->refcount = 1;
71237 + atomic_set(&s->refcount, 1);
71238 #ifdef CONFIG_NUMA
71239 s->remote_node_defrag_ratio = 1000;
71240 #endif
71241 @@ -3146,8 +3148,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
71242 void kmem_cache_destroy(struct kmem_cache *s)
71243 {
71244 down_write(&slub_lock);
71245 - s->refcount--;
71246 - if (!s->refcount) {
71247 + if (atomic_dec_and_test(&s->refcount)) {
71248 list_del(&s->list);
71249 up_write(&slub_lock);
71250 if (kmem_cache_close(s)) {
71251 @@ -3358,6 +3359,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
71252 EXPORT_SYMBOL(__kmalloc_node);
71253 #endif
71254
71255 +void check_object_size(const void *ptr, unsigned long n, bool to)
71256 +{
71257 +
71258 +#ifdef CONFIG_PAX_USERCOPY
71259 + struct page *page;
71260 + struct kmem_cache *s = NULL;
71261 + unsigned long offset;
71262 + const char *type;
71263 +
71264 + if (!n)
71265 + return;
71266 +
71267 + type = "<null>";
71268 + if (ZERO_OR_NULL_PTR(ptr))
71269 + goto report;
71270 +
71271 + if (!virt_addr_valid(ptr))
71272 + return;
71273 +
71274 + page = virt_to_head_page(ptr);
71275 +
71276 + type = "<process stack>";
71277 + if (!PageSlab(page)) {
71278 + if (object_is_on_stack(ptr, n) == -1)
71279 + goto report;
71280 + return;
71281 + }
71282 +
71283 + s = page->slab;
71284 + type = s->name;
71285 + if (!(s->flags & SLAB_USERCOPY))
71286 + goto report;
71287 +
71288 + offset = (ptr - page_address(page)) % s->size;
71289 + if (offset <= s->objsize && n <= s->objsize - offset)
71290 + return;
71291 +
71292 +report:
71293 + pax_report_usercopy(ptr, n, to, type);
71294 +#endif
71295 +
71296 +}
71297 +EXPORT_SYMBOL(check_object_size);
71298 +
71299 size_t ksize(const void *object)
71300 {
71301 struct page *page;
71302 @@ -3632,7 +3677,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
71303 int node;
71304
71305 list_add(&s->list, &slab_caches);
71306 - s->refcount = -1;
71307 + atomic_set(&s->refcount, -1);
71308
71309 for_each_node_state(node, N_NORMAL_MEMORY) {
71310 struct kmem_cache_node *n = get_node(s, node);
71311 @@ -3749,17 +3794,17 @@ void __init kmem_cache_init(void)
71312
71313 /* Caches that are not of the two-to-the-power-of size */
71314 if (KMALLOC_MIN_SIZE <= 32) {
71315 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
71316 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
71317 caches++;
71318 }
71319
71320 if (KMALLOC_MIN_SIZE <= 64) {
71321 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
71322 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
71323 caches++;
71324 }
71325
71326 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
71327 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
71328 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
71329 caches++;
71330 }
71331
71332 @@ -3827,7 +3872,7 @@ static int slab_unmergeable(struct kmem_cache *s)
71333 /*
71334 * We may have set a slab to be unmergeable during bootstrap.
71335 */
71336 - if (s->refcount < 0)
71337 + if (atomic_read(&s->refcount) < 0)
71338 return 1;
71339
71340 return 0;
71341 @@ -3886,7 +3931,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71342 down_write(&slub_lock);
71343 s = find_mergeable(size, align, flags, name, ctor);
71344 if (s) {
71345 - s->refcount++;
71346 + atomic_inc(&s->refcount);
71347 /*
71348 * Adjust the object sizes so that we clear
71349 * the complete object on kzalloc.
71350 @@ -3895,7 +3940,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71351 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
71352
71353 if (sysfs_slab_alias(s, name)) {
71354 - s->refcount--;
71355 + atomic_dec(&s->refcount);
71356 goto err;
71357 }
71358 up_write(&slub_lock);
71359 @@ -4023,7 +4068,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
71360 }
71361 #endif
71362
71363 -#ifdef CONFIG_SYSFS
71364 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71365 static int count_inuse(struct page *page)
71366 {
71367 return page->inuse;
71368 @@ -4410,12 +4455,12 @@ static void resiliency_test(void)
71369 validate_slab_cache(kmalloc_caches[9]);
71370 }
71371 #else
71372 -#ifdef CONFIG_SYSFS
71373 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71374 static void resiliency_test(void) {};
71375 #endif
71376 #endif
71377
71378 -#ifdef CONFIG_SYSFS
71379 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71380 enum slab_stat_type {
71381 SL_ALL, /* All slabs */
71382 SL_PARTIAL, /* Only partially allocated slabs */
71383 @@ -4656,7 +4701,7 @@ SLAB_ATTR_RO(ctor);
71384
71385 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
71386 {
71387 - return sprintf(buf, "%d\n", s->refcount - 1);
71388 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
71389 }
71390 SLAB_ATTR_RO(aliases);
71391
71392 @@ -5223,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
71393 return name;
71394 }
71395
71396 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71397 static int sysfs_slab_add(struct kmem_cache *s)
71398 {
71399 int err;
71400 @@ -5285,6 +5331,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
71401 kobject_del(&s->kobj);
71402 kobject_put(&s->kobj);
71403 }
71404 +#endif
71405
71406 /*
71407 * Need to buffer aliases during bootup until sysfs becomes
71408 @@ -5298,6 +5345,7 @@ struct saved_alias {
71409
71410 static struct saved_alias *alias_list;
71411
71412 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71413 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
71414 {
71415 struct saved_alias *al;
71416 @@ -5320,6 +5368,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
71417 alias_list = al;
71418 return 0;
71419 }
71420 +#endif
71421
71422 static int __init slab_sysfs_init(void)
71423 {
71424 diff --git a/mm/swap.c b/mm/swap.c
71425 index a91caf7..b887e735 100644
71426 --- a/mm/swap.c
71427 +++ b/mm/swap.c
71428 @@ -31,6 +31,7 @@
71429 #include <linux/backing-dev.h>
71430 #include <linux/memcontrol.h>
71431 #include <linux/gfp.h>
71432 +#include <linux/hugetlb.h>
71433
71434 #include "internal.h"
71435
71436 @@ -71,6 +72,8 @@ static void __put_compound_page(struct page *page)
71437
71438 __page_cache_release(page);
71439 dtor = get_compound_page_dtor(page);
71440 + if (!PageHuge(page))
71441 + BUG_ON(dtor != free_compound_page);
71442 (*dtor)(page);
71443 }
71444
71445 diff --git a/mm/swapfile.c b/mm/swapfile.c
71446 index b1cd120..aaae885 100644
71447 --- a/mm/swapfile.c
71448 +++ b/mm/swapfile.c
71449 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
71450
71451 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
71452 /* Activity counter to indicate that a swapon or swapoff has occurred */
71453 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
71454 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
71455
71456 static inline unsigned char swap_count(unsigned char ent)
71457 {
71458 @@ -1670,7 +1670,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
71459 }
71460 filp_close(swap_file, NULL);
71461 err = 0;
71462 - atomic_inc(&proc_poll_event);
71463 + atomic_inc_unchecked(&proc_poll_event);
71464 wake_up_interruptible(&proc_poll_wait);
71465
71466 out_dput:
71467 @@ -1686,8 +1686,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
71468
71469 poll_wait(file, &proc_poll_wait, wait);
71470
71471 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
71472 - seq->poll_event = atomic_read(&proc_poll_event);
71473 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
71474 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
71475 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
71476 }
71477
71478 @@ -1785,7 +1785,7 @@ static int swaps_open(struct inode *inode, struct file *file)
71479 return ret;
71480
71481 seq = file->private_data;
71482 - seq->poll_event = atomic_read(&proc_poll_event);
71483 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
71484 return 0;
71485 }
71486
71487 @@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
71488 (p->flags & SWP_DISCARDABLE) ? "D" : "");
71489
71490 mutex_unlock(&swapon_mutex);
71491 - atomic_inc(&proc_poll_event);
71492 + atomic_inc_unchecked(&proc_poll_event);
71493 wake_up_interruptible(&proc_poll_wait);
71494
71495 if (S_ISREG(inode->i_mode))
71496 diff --git a/mm/util.c b/mm/util.c
71497 index 136ac4f..5117eef 100644
71498 --- a/mm/util.c
71499 +++ b/mm/util.c
71500 @@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
71501 * allocated buffer. Use this if you don't want to free the buffer immediately
71502 * like, for example, with RCU.
71503 */
71504 +#undef __krealloc
71505 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
71506 {
71507 void *ret;
71508 @@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
71509 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
71510 * %NULL pointer, the object pointed to is freed.
71511 */
71512 +#undef krealloc
71513 void *krealloc(const void *p, size_t new_size, gfp_t flags)
71514 {
71515 void *ret;
71516 @@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
71517 void arch_pick_mmap_layout(struct mm_struct *mm)
71518 {
71519 mm->mmap_base = TASK_UNMAPPED_BASE;
71520 +
71521 +#ifdef CONFIG_PAX_RANDMMAP
71522 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71523 + mm->mmap_base += mm->delta_mmap;
71524 +#endif
71525 +
71526 mm->get_unmapped_area = arch_get_unmapped_area;
71527 mm->unmap_area = arch_unmap_area;
71528 }
71529 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
71530 index 27be2f0..0aef2c2 100644
71531 --- a/mm/vmalloc.c
71532 +++ b/mm/vmalloc.c
71533 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
71534
71535 pte = pte_offset_kernel(pmd, addr);
71536 do {
71537 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
71538 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
71539 +
71540 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71541 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
71542 + BUG_ON(!pte_exec(*pte));
71543 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
71544 + continue;
71545 + }
71546 +#endif
71547 +
71548 + {
71549 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
71550 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
71551 + }
71552 } while (pte++, addr += PAGE_SIZE, addr != end);
71553 }
71554
71555 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
71556 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
71557 {
71558 pte_t *pte;
71559 + int ret = -ENOMEM;
71560
71561 /*
71562 * nr is a running index into the array which helps higher level
71563 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
71564 pte = pte_alloc_kernel(pmd, addr);
71565 if (!pte)
71566 return -ENOMEM;
71567 +
71568 + pax_open_kernel();
71569 do {
71570 struct page *page = pages[*nr];
71571
71572 - if (WARN_ON(!pte_none(*pte)))
71573 - return -EBUSY;
71574 - if (WARN_ON(!page))
71575 - return -ENOMEM;
71576 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71577 + if (pgprot_val(prot) & _PAGE_NX)
71578 +#endif
71579 +
71580 + if (WARN_ON(!pte_none(*pte))) {
71581 + ret = -EBUSY;
71582 + goto out;
71583 + }
71584 + if (WARN_ON(!page)) {
71585 + ret = -ENOMEM;
71586 + goto out;
71587 + }
71588 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
71589 (*nr)++;
71590 } while (pte++, addr += PAGE_SIZE, addr != end);
71591 - return 0;
71592 + ret = 0;
71593 +out:
71594 + pax_close_kernel();
71595 + return ret;
71596 }
71597
71598 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
71599 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
71600 * and fall back on vmalloc() if that fails. Others
71601 * just put it in the vmalloc space.
71602 */
71603 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
71604 +#ifdef CONFIG_MODULES
71605 +#ifdef MODULES_VADDR
71606 unsigned long addr = (unsigned long)x;
71607 if (addr >= MODULES_VADDR && addr < MODULES_END)
71608 return 1;
71609 #endif
71610 +
71611 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71612 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
71613 + return 1;
71614 +#endif
71615 +
71616 +#endif
71617 +
71618 return is_vmalloc_addr(x);
71619 }
71620
71621 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
71622
71623 if (!pgd_none(*pgd)) {
71624 pud_t *pud = pud_offset(pgd, addr);
71625 +#ifdef CONFIG_X86
71626 + if (!pud_large(*pud))
71627 +#endif
71628 if (!pud_none(*pud)) {
71629 pmd_t *pmd = pmd_offset(pud, addr);
71630 +#ifdef CONFIG_X86
71631 + if (!pmd_large(*pmd))
71632 +#endif
71633 if (!pmd_none(*pmd)) {
71634 pte_t *ptep, pte;
71635
71636 @@ -1294,6 +1334,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
71637 struct vm_struct *area;
71638
71639 BUG_ON(in_interrupt());
71640 +
71641 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71642 + if (flags & VM_KERNEXEC) {
71643 + if (start != VMALLOC_START || end != VMALLOC_END)
71644 + return NULL;
71645 + start = (unsigned long)MODULES_EXEC_VADDR;
71646 + end = (unsigned long)MODULES_EXEC_END;
71647 + }
71648 +#endif
71649 +
71650 if (flags & VM_IOREMAP) {
71651 int bit = fls(size);
71652
71653 @@ -1526,6 +1576,11 @@ void *vmap(struct page **pages, unsigned int count,
71654 if (count > totalram_pages)
71655 return NULL;
71656
71657 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71658 + if (!(pgprot_val(prot) & _PAGE_NX))
71659 + flags |= VM_KERNEXEC;
71660 +#endif
71661 +
71662 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
71663 __builtin_return_address(0));
71664 if (!area)
71665 @@ -1627,6 +1682,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
71666 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
71667 goto fail;
71668
71669 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71670 + if (!(pgprot_val(prot) & _PAGE_NX))
71671 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
71672 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
71673 + else
71674 +#endif
71675 +
71676 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
71677 start, end, node, gfp_mask, caller);
71678 if (!area)
71679 @@ -1679,6 +1741,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
71680 gfp_mask, prot, node, caller);
71681 }
71682
71683 +#undef __vmalloc
71684 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
71685 {
71686 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
71687 @@ -1702,6 +1765,7 @@ static inline void *__vmalloc_node_flags(unsigned long size,
71688 * For tight control over page level allocator and protection flags
71689 * use __vmalloc() instead.
71690 */
71691 +#undef vmalloc
71692 void *vmalloc(unsigned long size)
71693 {
71694 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
71695 @@ -1718,6 +1782,7 @@ EXPORT_SYMBOL(vmalloc);
71696 * For tight control over page level allocator and protection flags
71697 * use __vmalloc() instead.
71698 */
71699 +#undef vzalloc
71700 void *vzalloc(unsigned long size)
71701 {
71702 return __vmalloc_node_flags(size, -1,
71703 @@ -1732,6 +1797,7 @@ EXPORT_SYMBOL(vzalloc);
71704 * The resulting memory area is zeroed so it can be mapped to userspace
71705 * without leaking data.
71706 */
71707 +#undef vmalloc_user
71708 void *vmalloc_user(unsigned long size)
71709 {
71710 struct vm_struct *area;
71711 @@ -1759,6 +1825,7 @@ EXPORT_SYMBOL(vmalloc_user);
71712 * For tight control over page level allocator and protection flags
71713 * use __vmalloc() instead.
71714 */
71715 +#undef vmalloc_node
71716 void *vmalloc_node(unsigned long size, int node)
71717 {
71718 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
71719 @@ -1778,6 +1845,7 @@ EXPORT_SYMBOL(vmalloc_node);
71720 * For tight control over page level allocator and protection flags
71721 * use __vmalloc_node() instead.
71722 */
71723 +#undef vzalloc_node
71724 void *vzalloc_node(unsigned long size, int node)
71725 {
71726 return __vmalloc_node_flags(size, node,
71727 @@ -1800,10 +1868,10 @@ EXPORT_SYMBOL(vzalloc_node);
71728 * For tight control over page level allocator and protection flags
71729 * use __vmalloc() instead.
71730 */
71731 -
71732 +#undef vmalloc_exec
71733 void *vmalloc_exec(unsigned long size)
71734 {
71735 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
71736 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
71737 -1, __builtin_return_address(0));
71738 }
71739
71740 @@ -1822,6 +1890,7 @@ void *vmalloc_exec(unsigned long size)
71741 * Allocate enough 32bit PA addressable pages to cover @size from the
71742 * page level allocator and map them into contiguous kernel virtual space.
71743 */
71744 +#undef vmalloc_32
71745 void *vmalloc_32(unsigned long size)
71746 {
71747 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
71748 @@ -1836,6 +1905,7 @@ EXPORT_SYMBOL(vmalloc_32);
71749 * The resulting memory area is 32bit addressable and zeroed so it can be
71750 * mapped to userspace without leaking data.
71751 */
71752 +#undef vmalloc_32_user
71753 void *vmalloc_32_user(unsigned long size)
71754 {
71755 struct vm_struct *area;
71756 @@ -2098,6 +2168,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
71757 unsigned long uaddr = vma->vm_start;
71758 unsigned long usize = vma->vm_end - vma->vm_start;
71759
71760 + BUG_ON(vma->vm_mirror);
71761 +
71762 if ((PAGE_SIZE-1) & (unsigned long)addr)
71763 return -EINVAL;
71764
71765 diff --git a/mm/vmstat.c b/mm/vmstat.c
71766 index 8fd603b..cf0d930 100644
71767 --- a/mm/vmstat.c
71768 +++ b/mm/vmstat.c
71769 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
71770 *
71771 * vm_stat contains the global counters
71772 */
71773 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
71774 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
71775 EXPORT_SYMBOL(vm_stat);
71776
71777 #ifdef CONFIG_SMP
71778 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
71779 v = p->vm_stat_diff[i];
71780 p->vm_stat_diff[i] = 0;
71781 local_irq_restore(flags);
71782 - atomic_long_add(v, &zone->vm_stat[i]);
71783 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
71784 global_diff[i] += v;
71785 #ifdef CONFIG_NUMA
71786 /* 3 seconds idle till flush */
71787 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
71788
71789 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
71790 if (global_diff[i])
71791 - atomic_long_add(global_diff[i], &vm_stat[i]);
71792 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
71793 }
71794
71795 #endif
71796 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
71797 start_cpu_timer(cpu);
71798 #endif
71799 #ifdef CONFIG_PROC_FS
71800 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
71801 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
71802 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
71803 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
71804 + {
71805 + mode_t gr_mode = S_IRUGO;
71806 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71807 + gr_mode = S_IRUSR;
71808 +#endif
71809 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
71810 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
71811 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
71812 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
71813 +#else
71814 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
71815 +#endif
71816 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
71817 + }
71818 #endif
71819 return 0;
71820 }
71821 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
71822 index 5471628..cef8398 100644
71823 --- a/net/8021q/vlan.c
71824 +++ b/net/8021q/vlan.c
71825 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
71826 err = -EPERM;
71827 if (!capable(CAP_NET_ADMIN))
71828 break;
71829 - if ((args.u.name_type >= 0) &&
71830 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
71831 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
71832 struct vlan_net *vn;
71833
71834 vn = net_generic(net, vlan_net_id);
71835 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
71836 index fdfdb57..38d368c 100644
71837 --- a/net/9p/trans_fd.c
71838 +++ b/net/9p/trans_fd.c
71839 @@ -423,7 +423,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
71840 oldfs = get_fs();
71841 set_fs(get_ds());
71842 /* The cast to a user pointer is valid due to the set_fs() */
71843 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
71844 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
71845 set_fs(oldfs);
71846
71847 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
71848 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
71849 index f41f026..fe76ea8 100644
71850 --- a/net/atm/atm_misc.c
71851 +++ b/net/atm/atm_misc.c
71852 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
71853 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
71854 return 1;
71855 atm_return(vcc, truesize);
71856 - atomic_inc(&vcc->stats->rx_drop);
71857 + atomic_inc_unchecked(&vcc->stats->rx_drop);
71858 return 0;
71859 }
71860 EXPORT_SYMBOL(atm_charge);
71861 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
71862 }
71863 }
71864 atm_return(vcc, guess);
71865 - atomic_inc(&vcc->stats->rx_drop);
71866 + atomic_inc_unchecked(&vcc->stats->rx_drop);
71867 return NULL;
71868 }
71869 EXPORT_SYMBOL(atm_alloc_charge);
71870 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
71871
71872 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
71873 {
71874 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
71875 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
71876 __SONET_ITEMS
71877 #undef __HANDLE_ITEM
71878 }
71879 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
71880
71881 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
71882 {
71883 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
71884 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
71885 __SONET_ITEMS
71886 #undef __HANDLE_ITEM
71887 }
71888 diff --git a/net/atm/lec.h b/net/atm/lec.h
71889 index dfc0719..47c5322 100644
71890 --- a/net/atm/lec.h
71891 +++ b/net/atm/lec.h
71892 @@ -48,7 +48,7 @@ struct lane2_ops {
71893 const u8 *tlvs, u32 sizeoftlvs);
71894 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
71895 const u8 *tlvs, u32 sizeoftlvs);
71896 -};
71897 +} __no_const;
71898
71899 /*
71900 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
71901 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
71902 index 0919a88..a23d54e 100644
71903 --- a/net/atm/mpc.h
71904 +++ b/net/atm/mpc.h
71905 @@ -33,7 +33,7 @@ struct mpoa_client {
71906 struct mpc_parameters parameters; /* parameters for this client */
71907
71908 const struct net_device_ops *old_ops;
71909 - struct net_device_ops new_ops;
71910 + net_device_ops_no_const new_ops;
71911 };
71912
71913
71914 diff --git a/net/atm/proc.c b/net/atm/proc.c
71915 index 0d020de..011c7bb 100644
71916 --- a/net/atm/proc.c
71917 +++ b/net/atm/proc.c
71918 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
71919 const struct k_atm_aal_stats *stats)
71920 {
71921 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
71922 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
71923 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
71924 - atomic_read(&stats->rx_drop));
71925 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
71926 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
71927 + atomic_read_unchecked(&stats->rx_drop));
71928 }
71929
71930 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
71931 diff --git a/net/atm/resources.c b/net/atm/resources.c
71932 index 23f45ce..c748f1a 100644
71933 --- a/net/atm/resources.c
71934 +++ b/net/atm/resources.c
71935 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
71936 static void copy_aal_stats(struct k_atm_aal_stats *from,
71937 struct atm_aal_stats *to)
71938 {
71939 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
71940 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
71941 __AAL_STAT_ITEMS
71942 #undef __HANDLE_ITEM
71943 }
71944 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
71945 static void subtract_aal_stats(struct k_atm_aal_stats *from,
71946 struct atm_aal_stats *to)
71947 {
71948 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
71949 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
71950 __AAL_STAT_ITEMS
71951 #undef __HANDLE_ITEM
71952 }
71953 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
71954 index 3512e25..2b33401 100644
71955 --- a/net/batman-adv/bat_iv_ogm.c
71956 +++ b/net/batman-adv/bat_iv_ogm.c
71957 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
71958
71959 /* change sequence number to network order */
71960 batman_ogm_packet->seqno =
71961 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
71962 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
71963
71964 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
71965 batman_ogm_packet->tt_crc = htons((uint16_t)
71966 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
71967 else
71968 batman_ogm_packet->gw_flags = NO_FLAGS;
71969
71970 - atomic_inc(&hard_iface->seqno);
71971 + atomic_inc_unchecked(&hard_iface->seqno);
71972
71973 slide_own_bcast_window(hard_iface);
71974 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
71975 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
71976 return;
71977
71978 /* could be changed by schedule_own_packet() */
71979 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
71980 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
71981
71982 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
71983
71984 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
71985 index 7704df4..beb4e16 100644
71986 --- a/net/batman-adv/hard-interface.c
71987 +++ b/net/batman-adv/hard-interface.c
71988 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
71989 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
71990 dev_add_pack(&hard_iface->batman_adv_ptype);
71991
71992 - atomic_set(&hard_iface->seqno, 1);
71993 - atomic_set(&hard_iface->frag_seqno, 1);
71994 + atomic_set_unchecked(&hard_iface->seqno, 1);
71995 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
71996 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
71997 hard_iface->net_dev->name);
71998
71999 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
72000 index f9cc957..efd9dae 100644
72001 --- a/net/batman-adv/soft-interface.c
72002 +++ b/net/batman-adv/soft-interface.c
72003 @@ -634,7 +634,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
72004
72005 /* set broadcast sequence number */
72006 bcast_packet->seqno =
72007 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
72008 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
72009
72010 add_bcast_packet_to_list(bat_priv, skb, 1);
72011
72012 @@ -828,7 +828,7 @@ struct net_device *softif_create(const char *name)
72013 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
72014
72015 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
72016 - atomic_set(&bat_priv->bcast_seqno, 1);
72017 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
72018 atomic_set(&bat_priv->ttvn, 0);
72019 atomic_set(&bat_priv->tt_local_changes, 0);
72020 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
72021 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
72022 index ab8d0fe..ceba3fd 100644
72023 --- a/net/batman-adv/types.h
72024 +++ b/net/batman-adv/types.h
72025 @@ -38,8 +38,8 @@ struct hard_iface {
72026 int16_t if_num;
72027 char if_status;
72028 struct net_device *net_dev;
72029 - atomic_t seqno;
72030 - atomic_t frag_seqno;
72031 + atomic_unchecked_t seqno;
72032 + atomic_unchecked_t frag_seqno;
72033 unsigned char *packet_buff;
72034 int packet_len;
72035 struct kobject *hardif_obj;
72036 @@ -154,7 +154,7 @@ struct bat_priv {
72037 atomic_t orig_interval; /* uint */
72038 atomic_t hop_penalty; /* uint */
72039 atomic_t log_level; /* uint */
72040 - atomic_t bcast_seqno;
72041 + atomic_unchecked_t bcast_seqno;
72042 atomic_t bcast_queue_left;
72043 atomic_t batman_queue_left;
72044 atomic_t ttvn; /* translation table version number */
72045 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
72046 index 07d1c1d..7e9bea9 100644
72047 --- a/net/batman-adv/unicast.c
72048 +++ b/net/batman-adv/unicast.c
72049 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
72050 frag1->flags = UNI_FRAG_HEAD | large_tail;
72051 frag2->flags = large_tail;
72052
72053 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
72054 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
72055 frag1->seqno = htons(seqno - 1);
72056 frag2->seqno = htons(seqno);
72057
72058 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
72059 index c1c597e..05ebb40 100644
72060 --- a/net/bluetooth/hci_conn.c
72061 +++ b/net/bluetooth/hci_conn.c
72062 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
72063 memset(&cp, 0, sizeof(cp));
72064
72065 cp.handle = cpu_to_le16(conn->handle);
72066 - memcpy(cp.ltk, ltk, sizeof(ltk));
72067 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
72068
72069 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
72070 }
72071 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
72072 index 17b5b1c..826d872 100644
72073 --- a/net/bluetooth/l2cap_core.c
72074 +++ b/net/bluetooth/l2cap_core.c
72075 @@ -2176,8 +2176,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
72076 break;
72077
72078 case L2CAP_CONF_RFC:
72079 - if (olen == sizeof(rfc))
72080 - memcpy(&rfc, (void *)val, olen);
72081 + if (olen != sizeof(rfc))
72082 + break;
72083 +
72084 + memcpy(&rfc, (void *)val, olen);
72085
72086 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
72087 rfc.mode != chan->mode)
72088 @@ -2265,8 +2267,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
72089
72090 switch (type) {
72091 case L2CAP_CONF_RFC:
72092 - if (olen == sizeof(rfc))
72093 - memcpy(&rfc, (void *)val, olen);
72094 + if (olen != sizeof(rfc))
72095 + break;
72096 +
72097 + memcpy(&rfc, (void *)val, olen);
72098 goto done;
72099 }
72100 }
72101 diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
72102 index a5f4e57..910ee6d 100644
72103 --- a/net/bridge/br_multicast.c
72104 +++ b/net/bridge/br_multicast.c
72105 @@ -1485,7 +1485,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
72106 nexthdr = ip6h->nexthdr;
72107 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
72108
72109 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
72110 + if (nexthdr != IPPROTO_ICMPV6)
72111 return 0;
72112
72113 /* Okay, we found ICMPv6 header */
72114 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
72115 index 5864cc4..121f3a3 100644
72116 --- a/net/bridge/netfilter/ebtables.c
72117 +++ b/net/bridge/netfilter/ebtables.c
72118 @@ -1513,7 +1513,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
72119 tmp.valid_hooks = t->table->valid_hooks;
72120 }
72121 mutex_unlock(&ebt_mutex);
72122 - if (copy_to_user(user, &tmp, *len) != 0){
72123 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
72124 BUGPRINT("c2u Didn't work\n");
72125 ret = -EFAULT;
72126 break;
72127 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
72128 index a986280..13444a1 100644
72129 --- a/net/caif/caif_socket.c
72130 +++ b/net/caif/caif_socket.c
72131 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
72132 #ifdef CONFIG_DEBUG_FS
72133 struct debug_fs_counter {
72134 atomic_t caif_nr_socks;
72135 - atomic_t caif_sock_create;
72136 - atomic_t num_connect_req;
72137 - atomic_t num_connect_resp;
72138 - atomic_t num_connect_fail_resp;
72139 - atomic_t num_disconnect;
72140 - atomic_t num_remote_shutdown_ind;
72141 - atomic_t num_tx_flow_off_ind;
72142 - atomic_t num_tx_flow_on_ind;
72143 - atomic_t num_rx_flow_off;
72144 - atomic_t num_rx_flow_on;
72145 + atomic_unchecked_t caif_sock_create;
72146 + atomic_unchecked_t num_connect_req;
72147 + atomic_unchecked_t num_connect_resp;
72148 + atomic_unchecked_t num_connect_fail_resp;
72149 + atomic_unchecked_t num_disconnect;
72150 + atomic_unchecked_t num_remote_shutdown_ind;
72151 + atomic_unchecked_t num_tx_flow_off_ind;
72152 + atomic_unchecked_t num_tx_flow_on_ind;
72153 + atomic_unchecked_t num_rx_flow_off;
72154 + atomic_unchecked_t num_rx_flow_on;
72155 };
72156 static struct debug_fs_counter cnt;
72157 #define dbfs_atomic_inc(v) atomic_inc_return(v)
72158 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
72159 #define dbfs_atomic_dec(v) atomic_dec_return(v)
72160 #else
72161 #define dbfs_atomic_inc(v) 0
72162 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72163 atomic_read(&cf_sk->sk.sk_rmem_alloc),
72164 sk_rcvbuf_lowwater(cf_sk));
72165 set_rx_flow_off(cf_sk);
72166 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
72167 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
72168 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
72169 }
72170
72171 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72172 set_rx_flow_off(cf_sk);
72173 if (net_ratelimit())
72174 pr_debug("sending flow OFF due to rmem_schedule\n");
72175 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
72176 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
72177 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
72178 }
72179 skb->dev = NULL;
72180 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
72181 switch (flow) {
72182 case CAIF_CTRLCMD_FLOW_ON_IND:
72183 /* OK from modem to start sending again */
72184 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
72185 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
72186 set_tx_flow_on(cf_sk);
72187 cf_sk->sk.sk_state_change(&cf_sk->sk);
72188 break;
72189
72190 case CAIF_CTRLCMD_FLOW_OFF_IND:
72191 /* Modem asks us to shut up */
72192 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
72193 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
72194 set_tx_flow_off(cf_sk);
72195 cf_sk->sk.sk_state_change(&cf_sk->sk);
72196 break;
72197 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72198 /* We're now connected */
72199 caif_client_register_refcnt(&cf_sk->layer,
72200 cfsk_hold, cfsk_put);
72201 - dbfs_atomic_inc(&cnt.num_connect_resp);
72202 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
72203 cf_sk->sk.sk_state = CAIF_CONNECTED;
72204 set_tx_flow_on(cf_sk);
72205 cf_sk->sk.sk_state_change(&cf_sk->sk);
72206 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72207
72208 case CAIF_CTRLCMD_INIT_FAIL_RSP:
72209 /* Connect request failed */
72210 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
72211 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
72212 cf_sk->sk.sk_err = ECONNREFUSED;
72213 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
72214 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
72215 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72216
72217 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
72218 /* Modem has closed this connection, or device is down. */
72219 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
72220 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
72221 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
72222 cf_sk->sk.sk_err = ECONNRESET;
72223 set_rx_flow_on(cf_sk);
72224 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
72225 return;
72226
72227 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
72228 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
72229 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
72230 set_rx_flow_on(cf_sk);
72231 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
72232 }
72233 @@ -854,7 +855,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
72234 /*ifindex = id of the interface.*/
72235 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
72236
72237 - dbfs_atomic_inc(&cnt.num_connect_req);
72238 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
72239 cf_sk->layer.receive = caif_sktrecv_cb;
72240
72241 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
72242 @@ -943,7 +944,7 @@ static int caif_release(struct socket *sock)
72243 spin_unlock_bh(&sk->sk_receive_queue.lock);
72244 sock->sk = NULL;
72245
72246 - dbfs_atomic_inc(&cnt.num_disconnect);
72247 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
72248
72249 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
72250 if (cf_sk->debugfs_socket_dir != NULL)
72251 @@ -1122,7 +1123,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
72252 cf_sk->conn_req.protocol = protocol;
72253 /* Increase the number of sockets created. */
72254 dbfs_atomic_inc(&cnt.caif_nr_socks);
72255 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
72256 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
72257 #ifdef CONFIG_DEBUG_FS
72258 if (!IS_ERR(debugfsdir)) {
72259
72260 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
72261 index 5cf5222..6f704ad 100644
72262 --- a/net/caif/cfctrl.c
72263 +++ b/net/caif/cfctrl.c
72264 @@ -9,6 +9,7 @@
72265 #include <linux/stddef.h>
72266 #include <linux/spinlock.h>
72267 #include <linux/slab.h>
72268 +#include <linux/sched.h>
72269 #include <net/caif/caif_layer.h>
72270 #include <net/caif/cfpkt.h>
72271 #include <net/caif/cfctrl.h>
72272 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
72273 memset(&dev_info, 0, sizeof(dev_info));
72274 dev_info.id = 0xff;
72275 cfsrvl_init(&this->serv, 0, &dev_info, false);
72276 - atomic_set(&this->req_seq_no, 1);
72277 - atomic_set(&this->rsp_seq_no, 1);
72278 + atomic_set_unchecked(&this->req_seq_no, 1);
72279 + atomic_set_unchecked(&this->rsp_seq_no, 1);
72280 this->serv.layer.receive = cfctrl_recv;
72281 sprintf(this->serv.layer.name, "ctrl");
72282 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
72283 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
72284 struct cfctrl_request_info *req)
72285 {
72286 spin_lock_bh(&ctrl->info_list_lock);
72287 - atomic_inc(&ctrl->req_seq_no);
72288 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
72289 + atomic_inc_unchecked(&ctrl->req_seq_no);
72290 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
72291 list_add_tail(&req->list, &ctrl->list);
72292 spin_unlock_bh(&ctrl->info_list_lock);
72293 }
72294 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
72295 if (p != first)
72296 pr_warn("Requests are not received in order\n");
72297
72298 - atomic_set(&ctrl->rsp_seq_no,
72299 + atomic_set_unchecked(&ctrl->rsp_seq_no,
72300 p->sequence_no);
72301 list_del(&p->list);
72302 goto out;
72303 diff --git a/net/can/gw.c b/net/can/gw.c
72304 index 3d79b12..8de85fa 100644
72305 --- a/net/can/gw.c
72306 +++ b/net/can/gw.c
72307 @@ -96,7 +96,7 @@ struct cf_mod {
72308 struct {
72309 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
72310 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
72311 - } csumfunc;
72312 + } __no_const csumfunc;
72313 };
72314
72315
72316 diff --git a/net/compat.c b/net/compat.c
72317 index 6def90e..c6992fa 100644
72318 --- a/net/compat.c
72319 +++ b/net/compat.c
72320 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
72321 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
72322 __get_user(kmsg->msg_flags, &umsg->msg_flags))
72323 return -EFAULT;
72324 - kmsg->msg_name = compat_ptr(tmp1);
72325 - kmsg->msg_iov = compat_ptr(tmp2);
72326 - kmsg->msg_control = compat_ptr(tmp3);
72327 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
72328 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
72329 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
72330 return 0;
72331 }
72332
72333 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72334
72335 if (kern_msg->msg_namelen) {
72336 if (mode == VERIFY_READ) {
72337 - int err = move_addr_to_kernel(kern_msg->msg_name,
72338 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
72339 kern_msg->msg_namelen,
72340 kern_address);
72341 if (err < 0)
72342 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72343 kern_msg->msg_name = NULL;
72344
72345 tot_len = iov_from_user_compat_to_kern(kern_iov,
72346 - (struct compat_iovec __user *)kern_msg->msg_iov,
72347 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
72348 kern_msg->msg_iovlen);
72349 if (tot_len >= 0)
72350 kern_msg->msg_iov = kern_iov;
72351 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72352
72353 #define CMSG_COMPAT_FIRSTHDR(msg) \
72354 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
72355 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
72356 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
72357 (struct compat_cmsghdr __user *)NULL)
72358
72359 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
72360 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
72361 (ucmlen) <= (unsigned long) \
72362 ((mhdr)->msg_controllen - \
72363 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
72364 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
72365
72366 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
72367 struct compat_cmsghdr __user *cmsg, int cmsg_len)
72368 {
72369 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
72370 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
72371 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
72372 msg->msg_controllen)
72373 return NULL;
72374 return (struct compat_cmsghdr __user *)ptr;
72375 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
72376 {
72377 struct compat_timeval ctv;
72378 struct compat_timespec cts[3];
72379 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
72380 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
72381 struct compat_cmsghdr cmhdr;
72382 int cmlen;
72383
72384 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
72385
72386 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
72387 {
72388 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
72389 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
72390 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
72391 int fdnum = scm->fp->count;
72392 struct file **fp = scm->fp->fp;
72393 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
72394 return -EFAULT;
72395 old_fs = get_fs();
72396 set_fs(KERNEL_DS);
72397 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
72398 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
72399 set_fs(old_fs);
72400
72401 return err;
72402 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
72403 len = sizeof(ktime);
72404 old_fs = get_fs();
72405 set_fs(KERNEL_DS);
72406 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
72407 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
72408 set_fs(old_fs);
72409
72410 if (!err) {
72411 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72412 case MCAST_JOIN_GROUP:
72413 case MCAST_LEAVE_GROUP:
72414 {
72415 - struct compat_group_req __user *gr32 = (void *)optval;
72416 + struct compat_group_req __user *gr32 = (void __user *)optval;
72417 struct group_req __user *kgr =
72418 compat_alloc_user_space(sizeof(struct group_req));
72419 u32 interface;
72420 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72421 case MCAST_BLOCK_SOURCE:
72422 case MCAST_UNBLOCK_SOURCE:
72423 {
72424 - struct compat_group_source_req __user *gsr32 = (void *)optval;
72425 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
72426 struct group_source_req __user *kgsr = compat_alloc_user_space(
72427 sizeof(struct group_source_req));
72428 u32 interface;
72429 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72430 }
72431 case MCAST_MSFILTER:
72432 {
72433 - struct compat_group_filter __user *gf32 = (void *)optval;
72434 + struct compat_group_filter __user *gf32 = (void __user *)optval;
72435 struct group_filter __user *kgf;
72436 u32 interface, fmode, numsrc;
72437
72438 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
72439 char __user *optval, int __user *optlen,
72440 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
72441 {
72442 - struct compat_group_filter __user *gf32 = (void *)optval;
72443 + struct compat_group_filter __user *gf32 = (void __user *)optval;
72444 struct group_filter __user *kgf;
72445 int __user *koptlen;
72446 u32 interface, fmode, numsrc;
72447 diff --git a/net/core/datagram.c b/net/core/datagram.c
72448 index 68bbf9f..5ef0d12 100644
72449 --- a/net/core/datagram.c
72450 +++ b/net/core/datagram.c
72451 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
72452 }
72453
72454 kfree_skb(skb);
72455 - atomic_inc(&sk->sk_drops);
72456 + atomic_inc_unchecked(&sk->sk_drops);
72457 sk_mem_reclaim_partial(sk);
72458
72459 return err;
72460 diff --git a/net/core/dev.c b/net/core/dev.c
72461 index 5a13edf..a6f2bd2 100644
72462 --- a/net/core/dev.c
72463 +++ b/net/core/dev.c
72464 @@ -1139,10 +1139,14 @@ void dev_load(struct net *net, const char *name)
72465 if (no_module && capable(CAP_NET_ADMIN))
72466 no_module = request_module("netdev-%s", name);
72467 if (no_module && capable(CAP_SYS_MODULE)) {
72468 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
72469 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
72470 +#else
72471 if (!request_module("%s", name))
72472 pr_err("Loading kernel module for a network device "
72473 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
72474 "instead\n", name);
72475 +#endif
72476 }
72477 }
72478 EXPORT_SYMBOL(dev_load);
72479 @@ -1573,7 +1577,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
72480 {
72481 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
72482 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
72483 - atomic_long_inc(&dev->rx_dropped);
72484 + atomic_long_inc_unchecked(&dev->rx_dropped);
72485 kfree_skb(skb);
72486 return NET_RX_DROP;
72487 }
72488 @@ -1583,7 +1587,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
72489 nf_reset(skb);
72490
72491 if (unlikely(!is_skb_forwardable(dev, skb))) {
72492 - atomic_long_inc(&dev->rx_dropped);
72493 + atomic_long_inc_unchecked(&dev->rx_dropped);
72494 kfree_skb(skb);
72495 return NET_RX_DROP;
72496 }
72497 @@ -2036,7 +2040,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
72498
72499 struct dev_gso_cb {
72500 void (*destructor)(struct sk_buff *skb);
72501 -};
72502 +} __no_const;
72503
72504 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
72505
72506 @@ -2970,7 +2974,7 @@ enqueue:
72507
72508 local_irq_restore(flags);
72509
72510 - atomic_long_inc(&skb->dev->rx_dropped);
72511 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
72512 kfree_skb(skb);
72513 return NET_RX_DROP;
72514 }
72515 @@ -3044,7 +3048,7 @@ int netif_rx_ni(struct sk_buff *skb)
72516 }
72517 EXPORT_SYMBOL(netif_rx_ni);
72518
72519 -static void net_tx_action(struct softirq_action *h)
72520 +static void net_tx_action(void)
72521 {
72522 struct softnet_data *sd = &__get_cpu_var(softnet_data);
72523
72524 @@ -3333,7 +3337,7 @@ ncls:
72525 if (pt_prev) {
72526 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
72527 } else {
72528 - atomic_long_inc(&skb->dev->rx_dropped);
72529 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
72530 kfree_skb(skb);
72531 /* Jamal, now you will not able to escape explaining
72532 * me how you were going to use this. :-)
72533 @@ -3891,7 +3895,7 @@ void netif_napi_del(struct napi_struct *napi)
72534 }
72535 EXPORT_SYMBOL(netif_napi_del);
72536
72537 -static void net_rx_action(struct softirq_action *h)
72538 +static void net_rx_action(void)
72539 {
72540 struct softnet_data *sd = &__get_cpu_var(softnet_data);
72541 unsigned long time_limit = jiffies + 2;
72542 @@ -5949,7 +5953,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
72543 } else {
72544 netdev_stats_to_stats64(storage, &dev->stats);
72545 }
72546 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
72547 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
72548 return storage;
72549 }
72550 EXPORT_SYMBOL(dev_get_stats);
72551 diff --git a/net/core/flow.c b/net/core/flow.c
72552 index e318c7e..168b1d0 100644
72553 --- a/net/core/flow.c
72554 +++ b/net/core/flow.c
72555 @@ -61,7 +61,7 @@ struct flow_cache {
72556 struct timer_list rnd_timer;
72557 };
72558
72559 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
72560 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
72561 EXPORT_SYMBOL(flow_cache_genid);
72562 static struct flow_cache flow_cache_global;
72563 static struct kmem_cache *flow_cachep __read_mostly;
72564 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
72565
72566 static int flow_entry_valid(struct flow_cache_entry *fle)
72567 {
72568 - if (atomic_read(&flow_cache_genid) != fle->genid)
72569 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
72570 return 0;
72571 if (fle->object && !fle->object->ops->check(fle->object))
72572 return 0;
72573 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
72574 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
72575 fcp->hash_count++;
72576 }
72577 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
72578 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
72579 flo = fle->object;
72580 if (!flo)
72581 goto ret_object;
72582 @@ -280,7 +280,7 @@ nocache:
72583 }
72584 flo = resolver(net, key, family, dir, flo, ctx);
72585 if (fle) {
72586 - fle->genid = atomic_read(&flow_cache_genid);
72587 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
72588 if (!IS_ERR(flo))
72589 fle->object = flo;
72590 else
72591 diff --git a/net/core/iovec.c b/net/core/iovec.c
72592 index c40f27e..7f49254 100644
72593 --- a/net/core/iovec.c
72594 +++ b/net/core/iovec.c
72595 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
72596 if (m->msg_namelen) {
72597 if (mode == VERIFY_READ) {
72598 void __user *namep;
72599 - namep = (void __user __force *) m->msg_name;
72600 + namep = (void __force_user *) m->msg_name;
72601 err = move_addr_to_kernel(namep, m->msg_namelen,
72602 address);
72603 if (err < 0)
72604 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
72605 }
72606
72607 size = m->msg_iovlen * sizeof(struct iovec);
72608 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
72609 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
72610 return -EFAULT;
72611
72612 m->msg_iov = iov;
72613 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
72614 index 9083e82..1673203 100644
72615 --- a/net/core/rtnetlink.c
72616 +++ b/net/core/rtnetlink.c
72617 @@ -57,7 +57,7 @@ struct rtnl_link {
72618 rtnl_doit_func doit;
72619 rtnl_dumpit_func dumpit;
72620 rtnl_calcit_func calcit;
72621 -};
72622 +} __no_const;
72623
72624 static DEFINE_MUTEX(rtnl_mutex);
72625 static u16 min_ifinfo_dump_size;
72626 diff --git a/net/core/scm.c b/net/core/scm.c
72627 index ff52ad0..aff1c0f 100644
72628 --- a/net/core/scm.c
72629 +++ b/net/core/scm.c
72630 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
72631 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
72632 {
72633 struct cmsghdr __user *cm
72634 - = (__force struct cmsghdr __user *)msg->msg_control;
72635 + = (struct cmsghdr __force_user *)msg->msg_control;
72636 struct cmsghdr cmhdr;
72637 int cmlen = CMSG_LEN(len);
72638 int err;
72639 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
72640 err = -EFAULT;
72641 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
72642 goto out;
72643 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
72644 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
72645 goto out;
72646 cmlen = CMSG_SPACE(len);
72647 if (msg->msg_controllen < cmlen)
72648 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
72649 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
72650 {
72651 struct cmsghdr __user *cm
72652 - = (__force struct cmsghdr __user*)msg->msg_control;
72653 + = (struct cmsghdr __force_user *)msg->msg_control;
72654
72655 int fdmax = 0;
72656 int fdnum = scm->fp->count;
72657 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
72658 if (fdnum < fdmax)
72659 fdmax = fdnum;
72660
72661 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
72662 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
72663 i++, cmfptr++)
72664 {
72665 int new_fd;
72666 diff --git a/net/core/sock.c b/net/core/sock.c
72667 index b23f174..b9a0d26 100644
72668 --- a/net/core/sock.c
72669 +++ b/net/core/sock.c
72670 @@ -289,7 +289,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72671 struct sk_buff_head *list = &sk->sk_receive_queue;
72672
72673 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
72674 - atomic_inc(&sk->sk_drops);
72675 + atomic_inc_unchecked(&sk->sk_drops);
72676 trace_sock_rcvqueue_full(sk, skb);
72677 return -ENOMEM;
72678 }
72679 @@ -299,7 +299,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72680 return err;
72681
72682 if (!sk_rmem_schedule(sk, skb->truesize)) {
72683 - atomic_inc(&sk->sk_drops);
72684 + atomic_inc_unchecked(&sk->sk_drops);
72685 return -ENOBUFS;
72686 }
72687
72688 @@ -319,7 +319,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72689 skb_dst_force(skb);
72690
72691 spin_lock_irqsave(&list->lock, flags);
72692 - skb->dropcount = atomic_read(&sk->sk_drops);
72693 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
72694 __skb_queue_tail(list, skb);
72695 spin_unlock_irqrestore(&list->lock, flags);
72696
72697 @@ -339,7 +339,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
72698 skb->dev = NULL;
72699
72700 if (sk_rcvqueues_full(sk, skb)) {
72701 - atomic_inc(&sk->sk_drops);
72702 + atomic_inc_unchecked(&sk->sk_drops);
72703 goto discard_and_relse;
72704 }
72705 if (nested)
72706 @@ -357,7 +357,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
72707 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
72708 } else if (sk_add_backlog(sk, skb)) {
72709 bh_unlock_sock(sk);
72710 - atomic_inc(&sk->sk_drops);
72711 + atomic_inc_unchecked(&sk->sk_drops);
72712 goto discard_and_relse;
72713 }
72714
72715 @@ -917,7 +917,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
72716 if (len > sizeof(peercred))
72717 len = sizeof(peercred);
72718 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
72719 - if (copy_to_user(optval, &peercred, len))
72720 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
72721 return -EFAULT;
72722 goto lenout;
72723 }
72724 @@ -930,7 +930,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
72725 return -ENOTCONN;
72726 if (lv < len)
72727 return -EINVAL;
72728 - if (copy_to_user(optval, address, len))
72729 + if (len > sizeof(address) || copy_to_user(optval, address, len))
72730 return -EFAULT;
72731 goto lenout;
72732 }
72733 @@ -963,7 +963,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
72734
72735 if (len > lv)
72736 len = lv;
72737 - if (copy_to_user(optval, &v, len))
72738 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
72739 return -EFAULT;
72740 lenout:
72741 if (put_user(len, optlen))
72742 @@ -2020,7 +2020,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
72743 */
72744 smp_wmb();
72745 atomic_set(&sk->sk_refcnt, 1);
72746 - atomic_set(&sk->sk_drops, 0);
72747 + atomic_set_unchecked(&sk->sk_drops, 0);
72748 }
72749 EXPORT_SYMBOL(sock_init_data);
72750
72751 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
72752 index 02e75d1..9a57a7c 100644
72753 --- a/net/decnet/sysctl_net_decnet.c
72754 +++ b/net/decnet/sysctl_net_decnet.c
72755 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
72756
72757 if (len > *lenp) len = *lenp;
72758
72759 - if (copy_to_user(buffer, addr, len))
72760 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
72761 return -EFAULT;
72762
72763 *lenp = len;
72764 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
72765
72766 if (len > *lenp) len = *lenp;
72767
72768 - if (copy_to_user(buffer, devname, len))
72769 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
72770 return -EFAULT;
72771
72772 *lenp = len;
72773 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
72774 index 39a2d29..f39c0fe 100644
72775 --- a/net/econet/Kconfig
72776 +++ b/net/econet/Kconfig
72777 @@ -4,7 +4,7 @@
72778
72779 config ECONET
72780 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
72781 - depends on EXPERIMENTAL && INET
72782 + depends on EXPERIMENTAL && INET && BROKEN
72783 ---help---
72784 Econet is a fairly old and slow networking protocol mainly used by
72785 Acorn computers to access file and print servers. It uses native
72786 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
72787 index 92fc5f6..b790d91 100644
72788 --- a/net/ipv4/fib_frontend.c
72789 +++ b/net/ipv4/fib_frontend.c
72790 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
72791 #ifdef CONFIG_IP_ROUTE_MULTIPATH
72792 fib_sync_up(dev);
72793 #endif
72794 - atomic_inc(&net->ipv4.dev_addr_genid);
72795 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
72796 rt_cache_flush(dev_net(dev), -1);
72797 break;
72798 case NETDEV_DOWN:
72799 fib_del_ifaddr(ifa, NULL);
72800 - atomic_inc(&net->ipv4.dev_addr_genid);
72801 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
72802 if (ifa->ifa_dev->ifa_list == NULL) {
72803 /* Last address was deleted from this interface.
72804 * Disable IP.
72805 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
72806 #ifdef CONFIG_IP_ROUTE_MULTIPATH
72807 fib_sync_up(dev);
72808 #endif
72809 - atomic_inc(&net->ipv4.dev_addr_genid);
72810 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
72811 rt_cache_flush(dev_net(dev), -1);
72812 break;
72813 case NETDEV_DOWN:
72814 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
72815 index 80106d8..232e898 100644
72816 --- a/net/ipv4/fib_semantics.c
72817 +++ b/net/ipv4/fib_semantics.c
72818 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
72819 nh->nh_saddr = inet_select_addr(nh->nh_dev,
72820 nh->nh_gw,
72821 nh->nh_parent->fib_scope);
72822 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
72823 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
72824
72825 return nh->nh_saddr;
72826 }
72827 diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
72828 index ccee270..db23c3c 100644
72829 --- a/net/ipv4/inet_diag.c
72830 +++ b/net/ipv4/inet_diag.c
72831 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct sock *sk,
72832 r->idiag_retrans = 0;
72833
72834 r->id.idiag_if = sk->sk_bound_dev_if;
72835 +
72836 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72837 + r->id.idiag_cookie[0] = 0;
72838 + r->id.idiag_cookie[1] = 0;
72839 +#else
72840 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
72841 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
72842 +#endif
72843
72844 r->id.idiag_sport = inet->inet_sport;
72845 r->id.idiag_dport = inet->inet_dport;
72846 @@ -210,8 +216,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
72847 r->idiag_family = tw->tw_family;
72848 r->idiag_retrans = 0;
72849 r->id.idiag_if = tw->tw_bound_dev_if;
72850 +
72851 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72852 + r->id.idiag_cookie[0] = 0;
72853 + r->id.idiag_cookie[1] = 0;
72854 +#else
72855 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
72856 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
72857 +#endif
72858 +
72859 r->id.idiag_sport = tw->tw_sport;
72860 r->id.idiag_dport = tw->tw_dport;
72861 r->id.idiag_src[0] = tw->tw_rcv_saddr;
72862 @@ -294,12 +307,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
72863 if (sk == NULL)
72864 goto unlock;
72865
72866 +#ifndef CONFIG_GRKERNSEC_HIDESYM
72867 err = -ESTALE;
72868 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
72869 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
72870 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
72871 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
72872 goto out;
72873 +#endif
72874
72875 err = -ENOMEM;
72876 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
72877 @@ -589,8 +604,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
72878 r->idiag_retrans = req->retrans;
72879
72880 r->id.idiag_if = sk->sk_bound_dev_if;
72881 +
72882 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72883 + r->id.idiag_cookie[0] = 0;
72884 + r->id.idiag_cookie[1] = 0;
72885 +#else
72886 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
72887 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
72888 +#endif
72889
72890 tmo = req->expires - jiffies;
72891 if (tmo < 0)
72892 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
72893 index 984ec65..97ac518 100644
72894 --- a/net/ipv4/inet_hashtables.c
72895 +++ b/net/ipv4/inet_hashtables.c
72896 @@ -18,12 +18,15 @@
72897 #include <linux/sched.h>
72898 #include <linux/slab.h>
72899 #include <linux/wait.h>
72900 +#include <linux/security.h>
72901
72902 #include <net/inet_connection_sock.h>
72903 #include <net/inet_hashtables.h>
72904 #include <net/secure_seq.h>
72905 #include <net/ip.h>
72906
72907 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
72908 +
72909 /*
72910 * Allocate and initialize a new local port bind bucket.
72911 * The bindhash mutex for snum's hash chain must be held here.
72912 @@ -530,6 +533,8 @@ ok:
72913 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
72914 spin_unlock(&head->lock);
72915
72916 + gr_update_task_in_ip_table(current, inet_sk(sk));
72917 +
72918 if (tw) {
72919 inet_twsk_deschedule(tw, death_row);
72920 while (twrefcnt) {
72921 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
72922 index 86f13c67..59a35b5 100644
72923 --- a/net/ipv4/inetpeer.c
72924 +++ b/net/ipv4/inetpeer.c
72925 @@ -436,8 +436,8 @@ relookup:
72926 if (p) {
72927 p->daddr = *daddr;
72928 atomic_set(&p->refcnt, 1);
72929 - atomic_set(&p->rid, 0);
72930 - atomic_set(&p->ip_id_count,
72931 + atomic_set_unchecked(&p->rid, 0);
72932 + atomic_set_unchecked(&p->ip_id_count,
72933 (daddr->family == AF_INET) ?
72934 secure_ip_id(daddr->addr.a4) :
72935 secure_ipv6_id(daddr->addr.a6));
72936 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
72937 index fdaabf2..0ec3205 100644
72938 --- a/net/ipv4/ip_fragment.c
72939 +++ b/net/ipv4/ip_fragment.c
72940 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
72941 return 0;
72942
72943 start = qp->rid;
72944 - end = atomic_inc_return(&peer->rid);
72945 + end = atomic_inc_return_unchecked(&peer->rid);
72946 qp->rid = end;
72947
72948 rc = qp->q.fragments && (end - start) > max;
72949 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
72950 index 09ff51b..d3968eb 100644
72951 --- a/net/ipv4/ip_sockglue.c
72952 +++ b/net/ipv4/ip_sockglue.c
72953 @@ -1111,7 +1111,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
72954 len = min_t(unsigned int, len, opt->optlen);
72955 if (put_user(len, optlen))
72956 return -EFAULT;
72957 - if (copy_to_user(optval, opt->__data, len))
72958 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
72959 + copy_to_user(optval, opt->__data, len))
72960 return -EFAULT;
72961 return 0;
72962 }
72963 @@ -1239,7 +1240,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
72964 if (sk->sk_type != SOCK_STREAM)
72965 return -ENOPROTOOPT;
72966
72967 - msg.msg_control = optval;
72968 + msg.msg_control = (void __force_kernel *)optval;
72969 msg.msg_controllen = len;
72970 msg.msg_flags = flags;
72971
72972 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
72973 index 99ec116..c5628fe 100644
72974 --- a/net/ipv4/ipconfig.c
72975 +++ b/net/ipv4/ipconfig.c
72976 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
72977
72978 mm_segment_t oldfs = get_fs();
72979 set_fs(get_ds());
72980 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
72981 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
72982 set_fs(oldfs);
72983 return res;
72984 }
72985 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
72986
72987 mm_segment_t oldfs = get_fs();
72988 set_fs(get_ds());
72989 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
72990 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
72991 set_fs(oldfs);
72992 return res;
72993 }
72994 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
72995
72996 mm_segment_t oldfs = get_fs();
72997 set_fs(get_ds());
72998 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
72999 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
73000 set_fs(oldfs);
73001 return res;
73002 }
73003 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
73004 index 2133c30..5c4b40b 100644
73005 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
73006 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
73007 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
73008
73009 *len = 0;
73010
73011 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
73012 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
73013 if (*octets == NULL)
73014 return 0;
73015
73016 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
73017 index 43d4c3b..1914409 100644
73018 --- a/net/ipv4/ping.c
73019 +++ b/net/ipv4/ping.c
73020 @@ -836,7 +836,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
73021 sk_rmem_alloc_get(sp),
73022 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
73023 atomic_read(&sp->sk_refcnt), sp,
73024 - atomic_read(&sp->sk_drops), len);
73025 + atomic_read_unchecked(&sp->sk_drops), len);
73026 }
73027
73028 static int ping_seq_show(struct seq_file *seq, void *v)
73029 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
73030 index 007e2eb..85a18a0 100644
73031 --- a/net/ipv4/raw.c
73032 +++ b/net/ipv4/raw.c
73033 @@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
73034 int raw_rcv(struct sock *sk, struct sk_buff *skb)
73035 {
73036 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
73037 - atomic_inc(&sk->sk_drops);
73038 + atomic_inc_unchecked(&sk->sk_drops);
73039 kfree_skb(skb);
73040 return NET_RX_DROP;
73041 }
73042 @@ -738,16 +738,20 @@ static int raw_init(struct sock *sk)
73043
73044 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
73045 {
73046 + struct icmp_filter filter;
73047 +
73048 if (optlen > sizeof(struct icmp_filter))
73049 optlen = sizeof(struct icmp_filter);
73050 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
73051 + if (copy_from_user(&filter, optval, optlen))
73052 return -EFAULT;
73053 + raw_sk(sk)->filter = filter;
73054 return 0;
73055 }
73056
73057 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
73058 {
73059 int len, ret = -EFAULT;
73060 + struct icmp_filter filter;
73061
73062 if (get_user(len, optlen))
73063 goto out;
73064 @@ -757,8 +761,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
73065 if (len > sizeof(struct icmp_filter))
73066 len = sizeof(struct icmp_filter);
73067 ret = -EFAULT;
73068 - if (put_user(len, optlen) ||
73069 - copy_to_user(optval, &raw_sk(sk)->filter, len))
73070 + filter = raw_sk(sk)->filter;
73071 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
73072 goto out;
73073 ret = 0;
73074 out: return ret;
73075 @@ -986,7 +990,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
73076 sk_wmem_alloc_get(sp),
73077 sk_rmem_alloc_get(sp),
73078 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
73079 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
73080 + atomic_read(&sp->sk_refcnt),
73081 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73082 + NULL,
73083 +#else
73084 + sp,
73085 +#endif
73086 + atomic_read_unchecked(&sp->sk_drops));
73087 }
73088
73089 static int raw_seq_show(struct seq_file *seq, void *v)
73090 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
73091 index 94cdbc5..0cb0063 100644
73092 --- a/net/ipv4/route.c
73093 +++ b/net/ipv4/route.c
73094 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
73095
73096 static inline int rt_genid(struct net *net)
73097 {
73098 - return atomic_read(&net->ipv4.rt_genid);
73099 + return atomic_read_unchecked(&net->ipv4.rt_genid);
73100 }
73101
73102 #ifdef CONFIG_PROC_FS
73103 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
73104 unsigned char shuffle;
73105
73106 get_random_bytes(&shuffle, sizeof(shuffle));
73107 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
73108 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
73109 redirect_genid++;
73110 }
73111
73112 @@ -3022,7 +3022,7 @@ static int rt_fill_info(struct net *net,
73113 error = rt->dst.error;
73114 if (peer) {
73115 inet_peer_refcheck(rt->peer);
73116 - id = atomic_read(&peer->ip_id_count) & 0xffff;
73117 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
73118 if (peer->tcp_ts_stamp) {
73119 ts = peer->tcp_ts;
73120 tsage = get_seconds() - peer->tcp_ts_stamp;
73121 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
73122 index c89e354..8bd55c8 100644
73123 --- a/net/ipv4/tcp_ipv4.c
73124 +++ b/net/ipv4/tcp_ipv4.c
73125 @@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
73126 int sysctl_tcp_low_latency __read_mostly;
73127 EXPORT_SYMBOL(sysctl_tcp_low_latency);
73128
73129 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73130 +extern int grsec_enable_blackhole;
73131 +#endif
73132
73133 #ifdef CONFIG_TCP_MD5SIG
73134 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
73135 @@ -1627,6 +1630,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
73136 return 0;
73137
73138 reset:
73139 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73140 + if (!grsec_enable_blackhole)
73141 +#endif
73142 tcp_v4_send_reset(rsk, skb);
73143 discard:
73144 kfree_skb(skb);
73145 @@ -1689,12 +1695,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
73146 TCP_SKB_CB(skb)->sacked = 0;
73147
73148 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
73149 - if (!sk)
73150 + if (!sk) {
73151 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73152 + ret = 1;
73153 +#endif
73154 goto no_tcp_socket;
73155 -
73156 + }
73157 process:
73158 - if (sk->sk_state == TCP_TIME_WAIT)
73159 + if (sk->sk_state == TCP_TIME_WAIT) {
73160 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73161 + ret = 2;
73162 +#endif
73163 goto do_time_wait;
73164 + }
73165
73166 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
73167 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
73168 @@ -1744,6 +1757,10 @@ no_tcp_socket:
73169 bad_packet:
73170 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
73171 } else {
73172 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73173 + if (!grsec_enable_blackhole || (ret == 1 &&
73174 + (skb->dev->flags & IFF_LOOPBACK)))
73175 +#endif
73176 tcp_v4_send_reset(NULL, skb);
73177 }
73178
73179 @@ -2404,7 +2421,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
73180 0, /* non standard timer */
73181 0, /* open_requests have no inode */
73182 atomic_read(&sk->sk_refcnt),
73183 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73184 + NULL,
73185 +#else
73186 req,
73187 +#endif
73188 len);
73189 }
73190
73191 @@ -2454,7 +2475,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
73192 sock_i_uid(sk),
73193 icsk->icsk_probes_out,
73194 sock_i_ino(sk),
73195 - atomic_read(&sk->sk_refcnt), sk,
73196 + atomic_read(&sk->sk_refcnt),
73197 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73198 + NULL,
73199 +#else
73200 + sk,
73201 +#endif
73202 jiffies_to_clock_t(icsk->icsk_rto),
73203 jiffies_to_clock_t(icsk->icsk_ack.ato),
73204 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
73205 @@ -2482,7 +2508,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
73206 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
73207 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
73208 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
73209 - atomic_read(&tw->tw_refcnt), tw, len);
73210 + atomic_read(&tw->tw_refcnt),
73211 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73212 + NULL,
73213 +#else
73214 + tw,
73215 +#endif
73216 + len);
73217 }
73218
73219 #define TMPSZ 150
73220 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
73221 index 66363b6..b0654a3 100644
73222 --- a/net/ipv4/tcp_minisocks.c
73223 +++ b/net/ipv4/tcp_minisocks.c
73224 @@ -27,6 +27,10 @@
73225 #include <net/inet_common.h>
73226 #include <net/xfrm.h>
73227
73228 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73229 +extern int grsec_enable_blackhole;
73230 +#endif
73231 +
73232 int sysctl_tcp_syncookies __read_mostly = 1;
73233 EXPORT_SYMBOL(sysctl_tcp_syncookies);
73234
73235 @@ -751,6 +755,10 @@ listen_overflow:
73236
73237 embryonic_reset:
73238 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
73239 +
73240 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73241 + if (!grsec_enable_blackhole)
73242 +#endif
73243 if (!(flg & TCP_FLAG_RST))
73244 req->rsk_ops->send_reset(sk, skb);
73245
73246 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
73247 index 85ee7eb..53277ab 100644
73248 --- a/net/ipv4/tcp_probe.c
73249 +++ b/net/ipv4/tcp_probe.c
73250 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
73251 if (cnt + width >= len)
73252 break;
73253
73254 - if (copy_to_user(buf + cnt, tbuf, width))
73255 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
73256 return -EFAULT;
73257 cnt += width;
73258 }
73259 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
73260 index 2e0f0af..e2948bf 100644
73261 --- a/net/ipv4/tcp_timer.c
73262 +++ b/net/ipv4/tcp_timer.c
73263 @@ -22,6 +22,10 @@
73264 #include <linux/gfp.h>
73265 #include <net/tcp.h>
73266
73267 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73268 +extern int grsec_lastack_retries;
73269 +#endif
73270 +
73271 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
73272 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
73273 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
73274 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock *sk)
73275 }
73276 }
73277
73278 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73279 + if ((sk->sk_state == TCP_LAST_ACK) &&
73280 + (grsec_lastack_retries > 0) &&
73281 + (grsec_lastack_retries < retry_until))
73282 + retry_until = grsec_lastack_retries;
73283 +#endif
73284 +
73285 if (retransmits_timed_out(sk, retry_until,
73286 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
73287 /* Has it gone just too far? */
73288 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
73289 index 5a65eea..bd913a1 100644
73290 --- a/net/ipv4/udp.c
73291 +++ b/net/ipv4/udp.c
73292 @@ -86,6 +86,7 @@
73293 #include <linux/types.h>
73294 #include <linux/fcntl.h>
73295 #include <linux/module.h>
73296 +#include <linux/security.h>
73297 #include <linux/socket.h>
73298 #include <linux/sockios.h>
73299 #include <linux/igmp.h>
73300 @@ -108,6 +109,10 @@
73301 #include <trace/events/udp.h>
73302 #include "udp_impl.h"
73303
73304 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73305 +extern int grsec_enable_blackhole;
73306 +#endif
73307 +
73308 struct udp_table udp_table __read_mostly;
73309 EXPORT_SYMBOL(udp_table);
73310
73311 @@ -565,6 +570,9 @@ found:
73312 return s;
73313 }
73314
73315 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
73316 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
73317 +
73318 /*
73319 * This routine is called by the ICMP module when it gets some
73320 * sort of error condition. If err < 0 then the socket should
73321 @@ -856,9 +864,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
73322 dport = usin->sin_port;
73323 if (dport == 0)
73324 return -EINVAL;
73325 +
73326 + err = gr_search_udp_sendmsg(sk, usin);
73327 + if (err)
73328 + return err;
73329 } else {
73330 if (sk->sk_state != TCP_ESTABLISHED)
73331 return -EDESTADDRREQ;
73332 +
73333 + err = gr_search_udp_sendmsg(sk, NULL);
73334 + if (err)
73335 + return err;
73336 +
73337 daddr = inet->inet_daddr;
73338 dport = inet->inet_dport;
73339 /* Open fast path for connected socket.
73340 @@ -1099,7 +1116,7 @@ static unsigned int first_packet_length(struct sock *sk)
73341 udp_lib_checksum_complete(skb)) {
73342 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
73343 IS_UDPLITE(sk));
73344 - atomic_inc(&sk->sk_drops);
73345 + atomic_inc_unchecked(&sk->sk_drops);
73346 __skb_unlink(skb, rcvq);
73347 __skb_queue_tail(&list_kill, skb);
73348 }
73349 @@ -1185,6 +1202,10 @@ try_again:
73350 if (!skb)
73351 goto out;
73352
73353 + err = gr_search_udp_recvmsg(sk, skb);
73354 + if (err)
73355 + goto out_free;
73356 +
73357 ulen = skb->len - sizeof(struct udphdr);
73358 copied = len;
73359 if (copied > ulen)
73360 @@ -1487,7 +1508,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73361
73362 drop:
73363 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
73364 - atomic_inc(&sk->sk_drops);
73365 + atomic_inc_unchecked(&sk->sk_drops);
73366 kfree_skb(skb);
73367 return -1;
73368 }
73369 @@ -1506,7 +1527,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
73370 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
73371
73372 if (!skb1) {
73373 - atomic_inc(&sk->sk_drops);
73374 + atomic_inc_unchecked(&sk->sk_drops);
73375 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
73376 IS_UDPLITE(sk));
73377 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
73378 @@ -1675,6 +1696,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
73379 goto csum_error;
73380
73381 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
73382 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73383 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
73384 +#endif
73385 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
73386
73387 /*
73388 @@ -2098,8 +2122,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
73389 sk_wmem_alloc_get(sp),
73390 sk_rmem_alloc_get(sp),
73391 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
73392 - atomic_read(&sp->sk_refcnt), sp,
73393 - atomic_read(&sp->sk_drops), len);
73394 + atomic_read(&sp->sk_refcnt),
73395 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73396 + NULL,
73397 +#else
73398 + sp,
73399 +#endif
73400 + atomic_read_unchecked(&sp->sk_drops), len);
73401 }
73402
73403 int udp4_seq_show(struct seq_file *seq, void *v)
73404 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
73405 index 836c4ea..cbb74dc 100644
73406 --- a/net/ipv6/addrconf.c
73407 +++ b/net/ipv6/addrconf.c
73408 @@ -2149,7 +2149,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
73409 p.iph.ihl = 5;
73410 p.iph.protocol = IPPROTO_IPV6;
73411 p.iph.ttl = 64;
73412 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
73413 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
73414
73415 if (ops->ndo_do_ioctl) {
73416 mm_segment_t oldfs = get_fs();
73417 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
73418 index 1567fb1..29af910 100644
73419 --- a/net/ipv6/inet6_connection_sock.c
73420 +++ b/net/ipv6/inet6_connection_sock.c
73421 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
73422 #ifdef CONFIG_XFRM
73423 {
73424 struct rt6_info *rt = (struct rt6_info *)dst;
73425 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
73426 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
73427 }
73428 #endif
73429 }
73430 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
73431 #ifdef CONFIG_XFRM
73432 if (dst) {
73433 struct rt6_info *rt = (struct rt6_info *)dst;
73434 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
73435 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
73436 __sk_dst_reset(sk);
73437 dst = NULL;
73438 }
73439 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
73440 index 26cb08c..8af9877 100644
73441 --- a/net/ipv6/ipv6_sockglue.c
73442 +++ b/net/ipv6/ipv6_sockglue.c
73443 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
73444 if (sk->sk_type != SOCK_STREAM)
73445 return -ENOPROTOOPT;
73446
73447 - msg.msg_control = optval;
73448 + msg.msg_control = (void __force_kernel *)optval;
73449 msg.msg_controllen = len;
73450 msg.msg_flags = flags;
73451
73452 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
73453 index 361ebf3..d5628fb 100644
73454 --- a/net/ipv6/raw.c
73455 +++ b/net/ipv6/raw.c
73456 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
73457 {
73458 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
73459 skb_checksum_complete(skb)) {
73460 - atomic_inc(&sk->sk_drops);
73461 + atomic_inc_unchecked(&sk->sk_drops);
73462 kfree_skb(skb);
73463 return NET_RX_DROP;
73464 }
73465 @@ -404,7 +404,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
73466 struct raw6_sock *rp = raw6_sk(sk);
73467
73468 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
73469 - atomic_inc(&sk->sk_drops);
73470 + atomic_inc_unchecked(&sk->sk_drops);
73471 kfree_skb(skb);
73472 return NET_RX_DROP;
73473 }
73474 @@ -428,7 +428,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
73475
73476 if (inet->hdrincl) {
73477 if (skb_checksum_complete(skb)) {
73478 - atomic_inc(&sk->sk_drops);
73479 + atomic_inc_unchecked(&sk->sk_drops);
73480 kfree_skb(skb);
73481 return NET_RX_DROP;
73482 }
73483 @@ -601,7 +601,7 @@ out:
73484 return err;
73485 }
73486
73487 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
73488 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
73489 struct flowi6 *fl6, struct dst_entry **dstp,
73490 unsigned int flags)
73491 {
73492 @@ -909,12 +909,15 @@ do_confirm:
73493 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
73494 char __user *optval, int optlen)
73495 {
73496 + struct icmp6_filter filter;
73497 +
73498 switch (optname) {
73499 case ICMPV6_FILTER:
73500 if (optlen > sizeof(struct icmp6_filter))
73501 optlen = sizeof(struct icmp6_filter);
73502 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
73503 + if (copy_from_user(&filter, optval, optlen))
73504 return -EFAULT;
73505 + raw6_sk(sk)->filter = filter;
73506 return 0;
73507 default:
73508 return -ENOPROTOOPT;
73509 @@ -927,6 +930,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
73510 char __user *optval, int __user *optlen)
73511 {
73512 int len;
73513 + struct icmp6_filter filter;
73514
73515 switch (optname) {
73516 case ICMPV6_FILTER:
73517 @@ -938,7 +942,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
73518 len = sizeof(struct icmp6_filter);
73519 if (put_user(len, optlen))
73520 return -EFAULT;
73521 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
73522 + filter = raw6_sk(sk)->filter;
73523 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
73524 return -EFAULT;
73525 return 0;
73526 default:
73527 @@ -1245,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
73528 0, 0L, 0,
73529 sock_i_uid(sp), 0,
73530 sock_i_ino(sp),
73531 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
73532 + atomic_read(&sp->sk_refcnt),
73533 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73534 + NULL,
73535 +#else
73536 + sp,
73537 +#endif
73538 + atomic_read_unchecked(&sp->sk_drops));
73539 }
73540
73541 static int raw6_seq_show(struct seq_file *seq, void *v)
73542 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
73543 index b859e4a..f9d1589 100644
73544 --- a/net/ipv6/tcp_ipv6.c
73545 +++ b/net/ipv6/tcp_ipv6.c
73546 @@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
73547 }
73548 #endif
73549
73550 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73551 +extern int grsec_enable_blackhole;
73552 +#endif
73553 +
73554 static void tcp_v6_hash(struct sock *sk)
73555 {
73556 if (sk->sk_state != TCP_CLOSE) {
73557 @@ -1651,6 +1655,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
73558 return 0;
73559
73560 reset:
73561 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73562 + if (!grsec_enable_blackhole)
73563 +#endif
73564 tcp_v6_send_reset(sk, skb);
73565 discard:
73566 if (opt_skb)
73567 @@ -1730,12 +1737,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
73568 TCP_SKB_CB(skb)->sacked = 0;
73569
73570 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
73571 - if (!sk)
73572 + if (!sk) {
73573 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73574 + ret = 1;
73575 +#endif
73576 goto no_tcp_socket;
73577 + }
73578
73579 process:
73580 - if (sk->sk_state == TCP_TIME_WAIT)
73581 + if (sk->sk_state == TCP_TIME_WAIT) {
73582 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73583 + ret = 2;
73584 +#endif
73585 goto do_time_wait;
73586 + }
73587
73588 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
73589 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
73590 @@ -1783,6 +1798,10 @@ no_tcp_socket:
73591 bad_packet:
73592 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
73593 } else {
73594 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73595 + if (!grsec_enable_blackhole || (ret == 1 &&
73596 + (skb->dev->flags & IFF_LOOPBACK)))
73597 +#endif
73598 tcp_v6_send_reset(NULL, skb);
73599 }
73600
73601 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
73602 uid,
73603 0, /* non standard timer */
73604 0, /* open_requests have no inode */
73605 - 0, req);
73606 + 0,
73607 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73608 + NULL
73609 +#else
73610 + req
73611 +#endif
73612 + );
73613 }
73614
73615 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
73616 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
73617 sock_i_uid(sp),
73618 icsk->icsk_probes_out,
73619 sock_i_ino(sp),
73620 - atomic_read(&sp->sk_refcnt), sp,
73621 + atomic_read(&sp->sk_refcnt),
73622 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73623 + NULL,
73624 +#else
73625 + sp,
73626 +#endif
73627 jiffies_to_clock_t(icsk->icsk_rto),
73628 jiffies_to_clock_t(icsk->icsk_ack.ato),
73629 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
73630 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
73631 dest->s6_addr32[2], dest->s6_addr32[3], destp,
73632 tw->tw_substate, 0, 0,
73633 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
73634 - atomic_read(&tw->tw_refcnt), tw);
73635 + atomic_read(&tw->tw_refcnt),
73636 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73637 + NULL
73638 +#else
73639 + tw
73640 +#endif
73641 + );
73642 }
73643
73644 static int tcp6_seq_show(struct seq_file *seq, void *v)
73645 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
73646 index 8c25419..47a51ae 100644
73647 --- a/net/ipv6/udp.c
73648 +++ b/net/ipv6/udp.c
73649 @@ -50,6 +50,10 @@
73650 #include <linux/seq_file.h>
73651 #include "udp_impl.h"
73652
73653 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73654 +extern int grsec_enable_blackhole;
73655 +#endif
73656 +
73657 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
73658 {
73659 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
73660 @@ -549,7 +553,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
73661
73662 return 0;
73663 drop:
73664 - atomic_inc(&sk->sk_drops);
73665 + atomic_inc_unchecked(&sk->sk_drops);
73666 drop_no_sk_drops_inc:
73667 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
73668 kfree_skb(skb);
73669 @@ -625,7 +629,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
73670 continue;
73671 }
73672 drop:
73673 - atomic_inc(&sk->sk_drops);
73674 + atomic_inc_unchecked(&sk->sk_drops);
73675 UDP6_INC_STATS_BH(sock_net(sk),
73676 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
73677 UDP6_INC_STATS_BH(sock_net(sk),
73678 @@ -780,6 +784,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
73679 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
73680 proto == IPPROTO_UDPLITE);
73681
73682 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73683 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
73684 +#endif
73685 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
73686
73687 kfree_skb(skb);
73688 @@ -796,7 +803,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
73689 if (!sock_owned_by_user(sk))
73690 udpv6_queue_rcv_skb(sk, skb);
73691 else if (sk_add_backlog(sk, skb)) {
73692 - atomic_inc(&sk->sk_drops);
73693 + atomic_inc_unchecked(&sk->sk_drops);
73694 bh_unlock_sock(sk);
73695 sock_put(sk);
73696 goto discard;
73697 @@ -1407,8 +1414,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
73698 0, 0L, 0,
73699 sock_i_uid(sp), 0,
73700 sock_i_ino(sp),
73701 - atomic_read(&sp->sk_refcnt), sp,
73702 - atomic_read(&sp->sk_drops));
73703 + atomic_read(&sp->sk_refcnt),
73704 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73705 + NULL,
73706 +#else
73707 + sp,
73708 +#endif
73709 + atomic_read_unchecked(&sp->sk_drops));
73710 }
73711
73712 int udp6_seq_show(struct seq_file *seq, void *v)
73713 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
73714 index 253695d..9481ce8 100644
73715 --- a/net/irda/ircomm/ircomm_tty.c
73716 +++ b/net/irda/ircomm/ircomm_tty.c
73717 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
73718 add_wait_queue(&self->open_wait, &wait);
73719
73720 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
73721 - __FILE__,__LINE__, tty->driver->name, self->open_count );
73722 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
73723
73724 /* As far as I can see, we protect open_count - Jean II */
73725 spin_lock_irqsave(&self->spinlock, flags);
73726 if (!tty_hung_up_p(filp)) {
73727 extra_count = 1;
73728 - self->open_count--;
73729 + local_dec(&self->open_count);
73730 }
73731 spin_unlock_irqrestore(&self->spinlock, flags);
73732 - self->blocked_open++;
73733 + local_inc(&self->blocked_open);
73734
73735 while (1) {
73736 if (tty->termios->c_cflag & CBAUD) {
73737 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
73738 }
73739
73740 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
73741 - __FILE__,__LINE__, tty->driver->name, self->open_count );
73742 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
73743
73744 schedule();
73745 }
73746 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
73747 if (extra_count) {
73748 /* ++ is not atomic, so this should be protected - Jean II */
73749 spin_lock_irqsave(&self->spinlock, flags);
73750 - self->open_count++;
73751 + local_inc(&self->open_count);
73752 spin_unlock_irqrestore(&self->spinlock, flags);
73753 }
73754 - self->blocked_open--;
73755 + local_dec(&self->blocked_open);
73756
73757 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
73758 - __FILE__,__LINE__, tty->driver->name, self->open_count);
73759 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
73760
73761 if (!retval)
73762 self->flags |= ASYNC_NORMAL_ACTIVE;
73763 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
73764 }
73765 /* ++ is not atomic, so this should be protected - Jean II */
73766 spin_lock_irqsave(&self->spinlock, flags);
73767 - self->open_count++;
73768 + local_inc(&self->open_count);
73769
73770 tty->driver_data = self;
73771 self->tty = tty;
73772 spin_unlock_irqrestore(&self->spinlock, flags);
73773
73774 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
73775 - self->line, self->open_count);
73776 + self->line, local_read(&self->open_count));
73777
73778 /* Not really used by us, but lets do it anyway */
73779 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
73780 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
73781 return;
73782 }
73783
73784 - if ((tty->count == 1) && (self->open_count != 1)) {
73785 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
73786 /*
73787 * Uh, oh. tty->count is 1, which means that the tty
73788 * structure will be freed. state->count should always
73789 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
73790 */
73791 IRDA_DEBUG(0, "%s(), bad serial port count; "
73792 "tty->count is 1, state->count is %d\n", __func__ ,
73793 - self->open_count);
73794 - self->open_count = 1;
73795 + local_read(&self->open_count));
73796 + local_set(&self->open_count, 1);
73797 }
73798
73799 - if (--self->open_count < 0) {
73800 + if (local_dec_return(&self->open_count) < 0) {
73801 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
73802 - __func__, self->line, self->open_count);
73803 - self->open_count = 0;
73804 + __func__, self->line, local_read(&self->open_count));
73805 + local_set(&self->open_count, 0);
73806 }
73807 - if (self->open_count) {
73808 + if (local_read(&self->open_count)) {
73809 spin_unlock_irqrestore(&self->spinlock, flags);
73810
73811 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
73812 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
73813 tty->closing = 0;
73814 self->tty = NULL;
73815
73816 - if (self->blocked_open) {
73817 + if (local_read(&self->blocked_open)) {
73818 if (self->close_delay)
73819 schedule_timeout_interruptible(self->close_delay);
73820 wake_up_interruptible(&self->open_wait);
73821 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
73822 spin_lock_irqsave(&self->spinlock, flags);
73823 self->flags &= ~ASYNC_NORMAL_ACTIVE;
73824 self->tty = NULL;
73825 - self->open_count = 0;
73826 + local_set(&self->open_count, 0);
73827 spin_unlock_irqrestore(&self->spinlock, flags);
73828
73829 wake_up_interruptible(&self->open_wait);
73830 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
73831 seq_putc(m, '\n');
73832
73833 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
73834 - seq_printf(m, "Open count: %d\n", self->open_count);
73835 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
73836 seq_printf(m, "Max data size: %d\n", self->max_data_size);
73837 seq_printf(m, "Max header size: %d\n", self->max_header_size);
73838
73839 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
73840 index 274d150..656a144 100644
73841 --- a/net/iucv/af_iucv.c
73842 +++ b/net/iucv/af_iucv.c
73843 @@ -787,10 +787,10 @@ static int iucv_sock_autobind(struct sock *sk)
73844
73845 write_lock_bh(&iucv_sk_list.lock);
73846
73847 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
73848 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
73849 while (__iucv_get_sock_by_name(name)) {
73850 sprintf(name, "%08x",
73851 - atomic_inc_return(&iucv_sk_list.autobind_name));
73852 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
73853 }
73854
73855 write_unlock_bh(&iucv_sk_list.lock);
73856 diff --git a/net/key/af_key.c b/net/key/af_key.c
73857 index 1e733e9..3d73c9f 100644
73858 --- a/net/key/af_key.c
73859 +++ b/net/key/af_key.c
73860 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
73861 static u32 get_acqseq(void)
73862 {
73863 u32 res;
73864 - static atomic_t acqseq;
73865 + static atomic_unchecked_t acqseq;
73866
73867 do {
73868 - res = atomic_inc_return(&acqseq);
73869 + res = atomic_inc_return_unchecked(&acqseq);
73870 } while (!res);
73871 return res;
73872 }
73873 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
73874 index 73495f1..ad51356 100644
73875 --- a/net/mac80211/ieee80211_i.h
73876 +++ b/net/mac80211/ieee80211_i.h
73877 @@ -27,6 +27,7 @@
73878 #include <net/ieee80211_radiotap.h>
73879 #include <net/cfg80211.h>
73880 #include <net/mac80211.h>
73881 +#include <asm/local.h>
73882 #include "key.h"
73883 #include "sta_info.h"
73884
73885 @@ -764,7 +765,7 @@ struct ieee80211_local {
73886 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
73887 spinlock_t queue_stop_reason_lock;
73888
73889 - int open_count;
73890 + local_t open_count;
73891 int monitors, cooked_mntrs;
73892 /* number of interfaces with corresponding FIF_ flags */
73893 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
73894 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
73895 index 30d7355..e260095 100644
73896 --- a/net/mac80211/iface.c
73897 +++ b/net/mac80211/iface.c
73898 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
73899 break;
73900 }
73901
73902 - if (local->open_count == 0) {
73903 + if (local_read(&local->open_count) == 0) {
73904 res = drv_start(local);
73905 if (res)
73906 goto err_del_bss;
73907 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
73908 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
73909
73910 if (!is_valid_ether_addr(dev->dev_addr)) {
73911 - if (!local->open_count)
73912 + if (!local_read(&local->open_count))
73913 drv_stop(local);
73914 return -EADDRNOTAVAIL;
73915 }
73916 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
73917 mutex_unlock(&local->mtx);
73918
73919 if (coming_up)
73920 - local->open_count++;
73921 + local_inc(&local->open_count);
73922
73923 if (hw_reconf_flags) {
73924 ieee80211_hw_config(local, hw_reconf_flags);
73925 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
73926 err_del_interface:
73927 drv_remove_interface(local, &sdata->vif);
73928 err_stop:
73929 - if (!local->open_count)
73930 + if (!local_read(&local->open_count))
73931 drv_stop(local);
73932 err_del_bss:
73933 sdata->bss = NULL;
73934 @@ -472,7 +472,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
73935 }
73936
73937 if (going_down)
73938 - local->open_count--;
73939 + local_dec(&local->open_count);
73940
73941 switch (sdata->vif.type) {
73942 case NL80211_IFTYPE_AP_VLAN:
73943 @@ -531,7 +531,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
73944
73945 ieee80211_recalc_ps(local, -1);
73946
73947 - if (local->open_count == 0) {
73948 + if (local_read(&local->open_count) == 0) {
73949 if (local->ops->napi_poll)
73950 napi_disable(&local->napi);
73951 ieee80211_clear_tx_pending(local);
73952 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
73953 index a7536fd..4039cc0 100644
73954 --- a/net/mac80211/main.c
73955 +++ b/net/mac80211/main.c
73956 @@ -163,7 +163,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
73957 local->hw.conf.power_level = power;
73958 }
73959
73960 - if (changed && local->open_count) {
73961 + if (changed && local_read(&local->open_count)) {
73962 ret = drv_config(local, changed);
73963 /*
73964 * Goal:
73965 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
73966 index 9ee7164..56c5061 100644
73967 --- a/net/mac80211/pm.c
73968 +++ b/net/mac80211/pm.c
73969 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
73970 struct ieee80211_sub_if_data *sdata;
73971 struct sta_info *sta;
73972
73973 - if (!local->open_count)
73974 + if (!local_read(&local->open_count))
73975 goto suspend;
73976
73977 ieee80211_scan_cancel(local);
73978 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
73979 cancel_work_sync(&local->dynamic_ps_enable_work);
73980 del_timer_sync(&local->dynamic_ps_timer);
73981
73982 - local->wowlan = wowlan && local->open_count;
73983 + local->wowlan = wowlan && local_read(&local->open_count);
73984 if (local->wowlan) {
73985 int err = drv_suspend(local, wowlan);
73986 if (err < 0) {
73987 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
73988 }
73989
73990 /* stop hardware - this must stop RX */
73991 - if (local->open_count)
73992 + if (local_read(&local->open_count))
73993 ieee80211_stop_device(local);
73994
73995 suspend:
73996 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
73997 index 5a5a776..9600b11 100644
73998 --- a/net/mac80211/rate.c
73999 +++ b/net/mac80211/rate.c
74000 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
74001
74002 ASSERT_RTNL();
74003
74004 - if (local->open_count)
74005 + if (local_read(&local->open_count))
74006 return -EBUSY;
74007
74008 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
74009 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
74010 index c97a065..ff61928 100644
74011 --- a/net/mac80211/rc80211_pid_debugfs.c
74012 +++ b/net/mac80211/rc80211_pid_debugfs.c
74013 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
74014
74015 spin_unlock_irqrestore(&events->lock, status);
74016
74017 - if (copy_to_user(buf, pb, p))
74018 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
74019 return -EFAULT;
74020
74021 return p;
74022 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
74023 index d5230ec..c604b21 100644
74024 --- a/net/mac80211/util.c
74025 +++ b/net/mac80211/util.c
74026 @@ -1000,7 +1000,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
74027 drv_set_coverage_class(local, hw->wiphy->coverage_class);
74028
74029 /* everything else happens only if HW was up & running */
74030 - if (!local->open_count)
74031 + if (!local_read(&local->open_count))
74032 goto wake_up;
74033
74034 /*
74035 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
74036 index d5597b7..ab6d39c 100644
74037 --- a/net/netfilter/Kconfig
74038 +++ b/net/netfilter/Kconfig
74039 @@ -779,6 +779,16 @@ config NETFILTER_XT_MATCH_ESP
74040
74041 To compile it as a module, choose M here. If unsure, say N.
74042
74043 +config NETFILTER_XT_MATCH_GRADM
74044 + tristate '"gradm" match support'
74045 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
74046 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
74047 + ---help---
74048 + The gradm match allows to match on grsecurity RBAC being enabled.
74049 + It is useful when iptables rules are applied early on bootup to
74050 + prevent connections to the machine (except from a trusted host)
74051 + while the RBAC system is disabled.
74052 +
74053 config NETFILTER_XT_MATCH_HASHLIMIT
74054 tristate '"hashlimit" match support'
74055 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
74056 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
74057 index 1a02853..5d8c22e 100644
74058 --- a/net/netfilter/Makefile
74059 +++ b/net/netfilter/Makefile
74060 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
74061 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
74062 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
74063 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
74064 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
74065 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
74066 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
74067 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
74068 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
74069 index 29fa5ba..8debc79 100644
74070 --- a/net/netfilter/ipvs/ip_vs_conn.c
74071 +++ b/net/netfilter/ipvs/ip_vs_conn.c
74072 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
74073 /* Increase the refcnt counter of the dest */
74074 atomic_inc(&dest->refcnt);
74075
74076 - conn_flags = atomic_read(&dest->conn_flags);
74077 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
74078 if (cp->protocol != IPPROTO_UDP)
74079 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
74080 /* Bind with the destination and its corresponding transmitter */
74081 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
74082 atomic_set(&cp->refcnt, 1);
74083
74084 atomic_set(&cp->n_control, 0);
74085 - atomic_set(&cp->in_pkts, 0);
74086 + atomic_set_unchecked(&cp->in_pkts, 0);
74087
74088 atomic_inc(&ipvs->conn_count);
74089 if (flags & IP_VS_CONN_F_NO_CPORT)
74090 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
74091
74092 /* Don't drop the entry if its number of incoming packets is not
74093 located in [0, 8] */
74094 - i = atomic_read(&cp->in_pkts);
74095 + i = atomic_read_unchecked(&cp->in_pkts);
74096 if (i > 8 || i < 0) return 0;
74097
74098 if (!todrop_rate[i]) return 0;
74099 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
74100 index 093cc32..9209ae1 100644
74101 --- a/net/netfilter/ipvs/ip_vs_core.c
74102 +++ b/net/netfilter/ipvs/ip_vs_core.c
74103 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
74104 ret = cp->packet_xmit(skb, cp, pd->pp);
74105 /* do not touch skb anymore */
74106
74107 - atomic_inc(&cp->in_pkts);
74108 + atomic_inc_unchecked(&cp->in_pkts);
74109 ip_vs_conn_put(cp);
74110 return ret;
74111 }
74112 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
74113 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
74114 pkts = sysctl_sync_threshold(ipvs);
74115 else
74116 - pkts = atomic_add_return(1, &cp->in_pkts);
74117 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
74118
74119 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
74120 cp->protocol == IPPROTO_SCTP) {
74121 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
74122 index e1a66cf..0910076 100644
74123 --- a/net/netfilter/ipvs/ip_vs_ctl.c
74124 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
74125 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
74126 ip_vs_rs_hash(ipvs, dest);
74127 write_unlock_bh(&ipvs->rs_lock);
74128 }
74129 - atomic_set(&dest->conn_flags, conn_flags);
74130 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
74131
74132 /* bind the service */
74133 if (!dest->svc) {
74134 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
74135 " %-7s %-6d %-10d %-10d\n",
74136 &dest->addr.in6,
74137 ntohs(dest->port),
74138 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
74139 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
74140 atomic_read(&dest->weight),
74141 atomic_read(&dest->activeconns),
74142 atomic_read(&dest->inactconns));
74143 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
74144 "%-7s %-6d %-10d %-10d\n",
74145 ntohl(dest->addr.ip),
74146 ntohs(dest->port),
74147 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
74148 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
74149 atomic_read(&dest->weight),
74150 atomic_read(&dest->activeconns),
74151 atomic_read(&dest->inactconns));
74152 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
74153
74154 entry.addr = dest->addr.ip;
74155 entry.port = dest->port;
74156 - entry.conn_flags = atomic_read(&dest->conn_flags);
74157 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
74158 entry.weight = atomic_read(&dest->weight);
74159 entry.u_threshold = dest->u_threshold;
74160 entry.l_threshold = dest->l_threshold;
74161 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
74162 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
74163
74164 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
74165 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
74166 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
74167 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
74168 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
74169 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
74170 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
74171 index 2b6678c0..aaa41fc 100644
74172 --- a/net/netfilter/ipvs/ip_vs_sync.c
74173 +++ b/net/netfilter/ipvs/ip_vs_sync.c
74174 @@ -649,7 +649,7 @@ control:
74175 * i.e only increment in_pkts for Templates.
74176 */
74177 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
74178 - int pkts = atomic_add_return(1, &cp->in_pkts);
74179 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
74180
74181 if (pkts % sysctl_sync_period(ipvs) != 1)
74182 return;
74183 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
74184
74185 if (opt)
74186 memcpy(&cp->in_seq, opt, sizeof(*opt));
74187 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
74188 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
74189 cp->state = state;
74190 cp->old_state = cp->state;
74191 /*
74192 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
74193 index aa2d720..d8aa111 100644
74194 --- a/net/netfilter/ipvs/ip_vs_xmit.c
74195 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
74196 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
74197 else
74198 rc = NF_ACCEPT;
74199 /* do not touch skb anymore */
74200 - atomic_inc(&cp->in_pkts);
74201 + atomic_inc_unchecked(&cp->in_pkts);
74202 goto out;
74203 }
74204
74205 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
74206 else
74207 rc = NF_ACCEPT;
74208 /* do not touch skb anymore */
74209 - atomic_inc(&cp->in_pkts);
74210 + atomic_inc_unchecked(&cp->in_pkts);
74211 goto out;
74212 }
74213
74214 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
74215 index 66b2c54..c7884e3 100644
74216 --- a/net/netfilter/nfnetlink_log.c
74217 +++ b/net/netfilter/nfnetlink_log.c
74218 @@ -70,7 +70,7 @@ struct nfulnl_instance {
74219 };
74220
74221 static DEFINE_SPINLOCK(instances_lock);
74222 -static atomic_t global_seq;
74223 +static atomic_unchecked_t global_seq;
74224
74225 #define INSTANCE_BUCKETS 16
74226 static struct hlist_head instance_table[INSTANCE_BUCKETS];
74227 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
74228 /* global sequence number */
74229 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
74230 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
74231 - htonl(atomic_inc_return(&global_seq)));
74232 + htonl(atomic_inc_return_unchecked(&global_seq)));
74233
74234 if (data_len) {
74235 struct nlattr *nla;
74236 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
74237 new file mode 100644
74238 index 0000000..6905327
74239 --- /dev/null
74240 +++ b/net/netfilter/xt_gradm.c
74241 @@ -0,0 +1,51 @@
74242 +/*
74243 + * gradm match for netfilter
74244 + * Copyright © Zbigniew Krzystolik, 2010
74245 + *
74246 + * This program is free software; you can redistribute it and/or modify
74247 + * it under the terms of the GNU General Public License; either version
74248 + * 2 or 3 as published by the Free Software Foundation.
74249 + */
74250 +#include <linux/module.h>
74251 +#include <linux/moduleparam.h>
74252 +#include <linux/skbuff.h>
74253 +#include <linux/netfilter/x_tables.h>
74254 +#include <linux/grsecurity.h>
74255 +#include <linux/netfilter/xt_gradm.h>
74256 +
74257 +static bool
74258 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
74259 +{
74260 + const struct xt_gradm_mtinfo *info = par->matchinfo;
74261 + bool retval = false;
74262 + if (gr_acl_is_enabled())
74263 + retval = true;
74264 + return retval ^ info->invflags;
74265 +}
74266 +
74267 +static struct xt_match gradm_mt_reg __read_mostly = {
74268 + .name = "gradm",
74269 + .revision = 0,
74270 + .family = NFPROTO_UNSPEC,
74271 + .match = gradm_mt,
74272 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
74273 + .me = THIS_MODULE,
74274 +};
74275 +
74276 +static int __init gradm_mt_init(void)
74277 +{
74278 + return xt_register_match(&gradm_mt_reg);
74279 +}
74280 +
74281 +static void __exit gradm_mt_exit(void)
74282 +{
74283 + xt_unregister_match(&gradm_mt_reg);
74284 +}
74285 +
74286 +module_init(gradm_mt_init);
74287 +module_exit(gradm_mt_exit);
74288 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
74289 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
74290 +MODULE_LICENSE("GPL");
74291 +MODULE_ALIAS("ipt_gradm");
74292 +MODULE_ALIAS("ip6t_gradm");
74293 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
74294 index 4fe4fb4..87a89e5 100644
74295 --- a/net/netfilter/xt_statistic.c
74296 +++ b/net/netfilter/xt_statistic.c
74297 @@ -19,7 +19,7 @@
74298 #include <linux/module.h>
74299
74300 struct xt_statistic_priv {
74301 - atomic_t count;
74302 + atomic_unchecked_t count;
74303 } ____cacheline_aligned_in_smp;
74304
74305 MODULE_LICENSE("GPL");
74306 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
74307 break;
74308 case XT_STATISTIC_MODE_NTH:
74309 do {
74310 - oval = atomic_read(&info->master->count);
74311 + oval = atomic_read_unchecked(&info->master->count);
74312 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
74313 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
74314 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
74315 if (nval == 0)
74316 ret = !ret;
74317 break;
74318 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
74319 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
74320 if (info->master == NULL)
74321 return -ENOMEM;
74322 - atomic_set(&info->master->count, info->u.nth.count);
74323 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
74324
74325 return 0;
74326 }
74327 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
74328 index 1201b6d..bcff8c6 100644
74329 --- a/net/netlink/af_netlink.c
74330 +++ b/net/netlink/af_netlink.c
74331 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock *sk)
74332 sk->sk_error_report(sk);
74333 }
74334 }
74335 - atomic_inc(&sk->sk_drops);
74336 + atomic_inc_unchecked(&sk->sk_drops);
74337 }
74338
74339 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
74340 @@ -1999,7 +1999,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
74341 sk_wmem_alloc_get(s),
74342 nlk->cb,
74343 atomic_read(&s->sk_refcnt),
74344 - atomic_read(&s->sk_drops),
74345 + atomic_read_unchecked(&s->sk_drops),
74346 sock_i_ino(s)
74347 );
74348
74349 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
74350 index 732152f..60bb09e 100644
74351 --- a/net/netrom/af_netrom.c
74352 +++ b/net/netrom/af_netrom.c
74353 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
74354 struct sock *sk = sock->sk;
74355 struct nr_sock *nr = nr_sk(sk);
74356
74357 + memset(sax, 0, sizeof(*sax));
74358 lock_sock(sk);
74359 if (peer != 0) {
74360 if (sk->sk_state != TCP_ESTABLISHED) {
74361 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
74362 *uaddr_len = sizeof(struct full_sockaddr_ax25);
74363 } else {
74364 sax->fsa_ax25.sax25_family = AF_NETROM;
74365 - sax->fsa_ax25.sax25_ndigis = 0;
74366 sax->fsa_ax25.sax25_call = nr->source_addr;
74367 *uaddr_len = sizeof(struct sockaddr_ax25);
74368 }
74369 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
74370 index d9d4970..d5a6a68 100644
74371 --- a/net/packet/af_packet.c
74372 +++ b/net/packet/af_packet.c
74373 @@ -1675,7 +1675,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
74374
74375 spin_lock(&sk->sk_receive_queue.lock);
74376 po->stats.tp_packets++;
74377 - skb->dropcount = atomic_read(&sk->sk_drops);
74378 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74379 __skb_queue_tail(&sk->sk_receive_queue, skb);
74380 spin_unlock(&sk->sk_receive_queue.lock);
74381 sk->sk_data_ready(sk, skb->len);
74382 @@ -1684,7 +1684,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
74383 drop_n_acct:
74384 spin_lock(&sk->sk_receive_queue.lock);
74385 po->stats.tp_drops++;
74386 - atomic_inc(&sk->sk_drops);
74387 + atomic_inc_unchecked(&sk->sk_drops);
74388 spin_unlock(&sk->sk_receive_queue.lock);
74389
74390 drop_n_restore:
74391 @@ -3266,7 +3266,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
74392 case PACKET_HDRLEN:
74393 if (len > sizeof(int))
74394 len = sizeof(int);
74395 - if (copy_from_user(&val, optval, len))
74396 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
74397 return -EFAULT;
74398 switch (val) {
74399 case TPACKET_V1:
74400 @@ -3316,7 +3316,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
74401
74402 if (put_user(len, optlen))
74403 return -EFAULT;
74404 - if (copy_to_user(optval, data, len))
74405 + if (len > sizeof(st) || copy_to_user(optval, data, len))
74406 return -EFAULT;
74407 return 0;
74408 }
74409 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
74410 index d65f699..05aa6ce 100644
74411 --- a/net/phonet/af_phonet.c
74412 +++ b/net/phonet/af_phonet.c
74413 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
74414 {
74415 struct phonet_protocol *pp;
74416
74417 - if (protocol >= PHONET_NPROTO)
74418 + if (protocol < 0 || protocol >= PHONET_NPROTO)
74419 return NULL;
74420
74421 rcu_read_lock();
74422 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
74423 {
74424 int err = 0;
74425
74426 - if (protocol >= PHONET_NPROTO)
74427 + if (protocol < 0 || protocol >= PHONET_NPROTO)
74428 return -EINVAL;
74429
74430 err = proto_register(pp->prot, 1);
74431 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
74432 index 2ba6e9f..409573f 100644
74433 --- a/net/phonet/pep.c
74434 +++ b/net/phonet/pep.c
74435 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
74436
74437 case PNS_PEP_CTRL_REQ:
74438 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
74439 - atomic_inc(&sk->sk_drops);
74440 + atomic_inc_unchecked(&sk->sk_drops);
74441 break;
74442 }
74443 __skb_pull(skb, 4);
74444 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
74445 }
74446
74447 if (pn->rx_credits == 0) {
74448 - atomic_inc(&sk->sk_drops);
74449 + atomic_inc_unchecked(&sk->sk_drops);
74450 err = -ENOBUFS;
74451 break;
74452 }
74453 @@ -557,7 +557,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
74454 }
74455
74456 if (pn->rx_credits == 0) {
74457 - atomic_inc(&sk->sk_drops);
74458 + atomic_inc_unchecked(&sk->sk_drops);
74459 err = NET_RX_DROP;
74460 break;
74461 }
74462 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
74463 index 4c7eff3..59c727f 100644
74464 --- a/net/phonet/socket.c
74465 +++ b/net/phonet/socket.c
74466 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
74467 pn->resource, sk->sk_state,
74468 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
74469 sock_i_uid(sk), sock_i_ino(sk),
74470 - atomic_read(&sk->sk_refcnt), sk,
74471 - atomic_read(&sk->sk_drops), &len);
74472 + atomic_read(&sk->sk_refcnt),
74473 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74474 + NULL,
74475 +#else
74476 + sk,
74477 +#endif
74478 + atomic_read_unchecked(&sk->sk_drops), &len);
74479 }
74480 seq_printf(seq, "%*s\n", 127 - len, "");
74481 return 0;
74482 diff --git a/net/rds/cong.c b/net/rds/cong.c
74483 index e5b65ac..f3b6fb7 100644
74484 --- a/net/rds/cong.c
74485 +++ b/net/rds/cong.c
74486 @@ -78,7 +78,7 @@
74487 * finds that the saved generation number is smaller than the global generation
74488 * number, it wakes up the process.
74489 */
74490 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
74491 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
74492
74493 /*
74494 * Congestion monitoring
74495 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
74496 rdsdebug("waking map %p for %pI4\n",
74497 map, &map->m_addr);
74498 rds_stats_inc(s_cong_update_received);
74499 - atomic_inc(&rds_cong_generation);
74500 + atomic_inc_unchecked(&rds_cong_generation);
74501 if (waitqueue_active(&map->m_waitq))
74502 wake_up(&map->m_waitq);
74503 if (waitqueue_active(&rds_poll_waitq))
74504 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
74505
74506 int rds_cong_updated_since(unsigned long *recent)
74507 {
74508 - unsigned long gen = atomic_read(&rds_cong_generation);
74509 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
74510
74511 if (likely(*recent == gen))
74512 return 0;
74513 diff --git a/net/rds/ib.h b/net/rds/ib.h
74514 index edfaaaf..8c89879 100644
74515 --- a/net/rds/ib.h
74516 +++ b/net/rds/ib.h
74517 @@ -128,7 +128,7 @@ struct rds_ib_connection {
74518 /* sending acks */
74519 unsigned long i_ack_flags;
74520 #ifdef KERNEL_HAS_ATOMIC64
74521 - atomic64_t i_ack_next; /* next ACK to send */
74522 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
74523 #else
74524 spinlock_t i_ack_lock; /* protect i_ack_next */
74525 u64 i_ack_next; /* next ACK to send */
74526 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
74527 index 51c8689..36c555f 100644
74528 --- a/net/rds/ib_cm.c
74529 +++ b/net/rds/ib_cm.c
74530 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
74531 /* Clear the ACK state */
74532 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
74533 #ifdef KERNEL_HAS_ATOMIC64
74534 - atomic64_set(&ic->i_ack_next, 0);
74535 + atomic64_set_unchecked(&ic->i_ack_next, 0);
74536 #else
74537 ic->i_ack_next = 0;
74538 #endif
74539 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
74540 index e29e0ca..fa3a6a3 100644
74541 --- a/net/rds/ib_recv.c
74542 +++ b/net/rds/ib_recv.c
74543 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
74544 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
74545 int ack_required)
74546 {
74547 - atomic64_set(&ic->i_ack_next, seq);
74548 + atomic64_set_unchecked(&ic->i_ack_next, seq);
74549 if (ack_required) {
74550 smp_mb__before_clear_bit();
74551 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74552 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
74553 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74554 smp_mb__after_clear_bit();
74555
74556 - return atomic64_read(&ic->i_ack_next);
74557 + return atomic64_read_unchecked(&ic->i_ack_next);
74558 }
74559 #endif
74560
74561 diff --git a/net/rds/iw.h b/net/rds/iw.h
74562 index 04ce3b1..48119a6 100644
74563 --- a/net/rds/iw.h
74564 +++ b/net/rds/iw.h
74565 @@ -134,7 +134,7 @@ struct rds_iw_connection {
74566 /* sending acks */
74567 unsigned long i_ack_flags;
74568 #ifdef KERNEL_HAS_ATOMIC64
74569 - atomic64_t i_ack_next; /* next ACK to send */
74570 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
74571 #else
74572 spinlock_t i_ack_lock; /* protect i_ack_next */
74573 u64 i_ack_next; /* next ACK to send */
74574 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
74575 index 9556d28..f046d0e 100644
74576 --- a/net/rds/iw_cm.c
74577 +++ b/net/rds/iw_cm.c
74578 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
74579 /* Clear the ACK state */
74580 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
74581 #ifdef KERNEL_HAS_ATOMIC64
74582 - atomic64_set(&ic->i_ack_next, 0);
74583 + atomic64_set_unchecked(&ic->i_ack_next, 0);
74584 #else
74585 ic->i_ack_next = 0;
74586 #endif
74587 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
74588 index 5e57347..3916042 100644
74589 --- a/net/rds/iw_recv.c
74590 +++ b/net/rds/iw_recv.c
74591 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
74592 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
74593 int ack_required)
74594 {
74595 - atomic64_set(&ic->i_ack_next, seq);
74596 + atomic64_set_unchecked(&ic->i_ack_next, seq);
74597 if (ack_required) {
74598 smp_mb__before_clear_bit();
74599 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74600 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
74601 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74602 smp_mb__after_clear_bit();
74603
74604 - return atomic64_read(&ic->i_ack_next);
74605 + return atomic64_read_unchecked(&ic->i_ack_next);
74606 }
74607 #endif
74608
74609 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
74610 index edac9ef..16bcb98 100644
74611 --- a/net/rds/tcp.c
74612 +++ b/net/rds/tcp.c
74613 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
74614 int val = 1;
74615
74616 set_fs(KERNEL_DS);
74617 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
74618 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
74619 sizeof(val));
74620 set_fs(oldfs);
74621 }
74622 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
74623 index 1b4fd68..2234175 100644
74624 --- a/net/rds/tcp_send.c
74625 +++ b/net/rds/tcp_send.c
74626 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
74627
74628 oldfs = get_fs();
74629 set_fs(KERNEL_DS);
74630 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
74631 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
74632 sizeof(val));
74633 set_fs(oldfs);
74634 }
74635 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
74636 index 74c064c..fdec26f 100644
74637 --- a/net/rxrpc/af_rxrpc.c
74638 +++ b/net/rxrpc/af_rxrpc.c
74639 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
74640 __be32 rxrpc_epoch;
74641
74642 /* current debugging ID */
74643 -atomic_t rxrpc_debug_id;
74644 +atomic_unchecked_t rxrpc_debug_id;
74645
74646 /* count of skbs currently in use */
74647 atomic_t rxrpc_n_skbs;
74648 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
74649 index f99cfce..cc529dd 100644
74650 --- a/net/rxrpc/ar-ack.c
74651 +++ b/net/rxrpc/ar-ack.c
74652 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
74653
74654 _enter("{%d,%d,%d,%d},",
74655 call->acks_hard, call->acks_unacked,
74656 - atomic_read(&call->sequence),
74657 + atomic_read_unchecked(&call->sequence),
74658 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
74659
74660 stop = 0;
74661 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
74662
74663 /* each Tx packet has a new serial number */
74664 sp->hdr.serial =
74665 - htonl(atomic_inc_return(&call->conn->serial));
74666 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
74667
74668 hdr = (struct rxrpc_header *) txb->head;
74669 hdr->serial = sp->hdr.serial;
74670 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
74671 */
74672 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
74673 {
74674 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
74675 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
74676 }
74677
74678 /*
74679 @@ -629,7 +629,7 @@ process_further:
74680
74681 latest = ntohl(sp->hdr.serial);
74682 hard = ntohl(ack.firstPacket);
74683 - tx = atomic_read(&call->sequence);
74684 + tx = atomic_read_unchecked(&call->sequence);
74685
74686 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
74687 latest,
74688 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
74689 goto maybe_reschedule;
74690
74691 send_ACK_with_skew:
74692 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
74693 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
74694 ntohl(ack.serial));
74695 send_ACK:
74696 mtu = call->conn->trans->peer->if_mtu;
74697 @@ -1173,7 +1173,7 @@ send_ACK:
74698 ackinfo.rxMTU = htonl(5692);
74699 ackinfo.jumbo_max = htonl(4);
74700
74701 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
74702 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
74703 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
74704 ntohl(hdr.serial),
74705 ntohs(ack.maxSkew),
74706 @@ -1191,7 +1191,7 @@ send_ACK:
74707 send_message:
74708 _debug("send message");
74709
74710 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
74711 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
74712 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
74713 send_message_2:
74714
74715 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
74716 index bf656c2..48f9d27 100644
74717 --- a/net/rxrpc/ar-call.c
74718 +++ b/net/rxrpc/ar-call.c
74719 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
74720 spin_lock_init(&call->lock);
74721 rwlock_init(&call->state_lock);
74722 atomic_set(&call->usage, 1);
74723 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
74724 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74725 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
74726
74727 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
74728 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
74729 index 4106ca9..a338d7a 100644
74730 --- a/net/rxrpc/ar-connection.c
74731 +++ b/net/rxrpc/ar-connection.c
74732 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
74733 rwlock_init(&conn->lock);
74734 spin_lock_init(&conn->state_lock);
74735 atomic_set(&conn->usage, 1);
74736 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
74737 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74738 conn->avail_calls = RXRPC_MAXCALLS;
74739 conn->size_align = 4;
74740 conn->header_size = sizeof(struct rxrpc_header);
74741 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
74742 index e7ed43a..6afa140 100644
74743 --- a/net/rxrpc/ar-connevent.c
74744 +++ b/net/rxrpc/ar-connevent.c
74745 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
74746
74747 len = iov[0].iov_len + iov[1].iov_len;
74748
74749 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
74750 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
74751 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
74752
74753 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
74754 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
74755 index 1a2b0633..e8d1382 100644
74756 --- a/net/rxrpc/ar-input.c
74757 +++ b/net/rxrpc/ar-input.c
74758 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
74759 /* track the latest serial number on this connection for ACK packet
74760 * information */
74761 serial = ntohl(sp->hdr.serial);
74762 - hi_serial = atomic_read(&call->conn->hi_serial);
74763 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
74764 while (serial > hi_serial)
74765 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
74766 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
74767 serial);
74768
74769 /* request ACK generation for any ACK or DATA packet that requests
74770 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
74771 index 8e22bd3..f66d1c0 100644
74772 --- a/net/rxrpc/ar-internal.h
74773 +++ b/net/rxrpc/ar-internal.h
74774 @@ -272,8 +272,8 @@ struct rxrpc_connection {
74775 int error; /* error code for local abort */
74776 int debug_id; /* debug ID for printks */
74777 unsigned call_counter; /* call ID counter */
74778 - atomic_t serial; /* packet serial number counter */
74779 - atomic_t hi_serial; /* highest serial number received */
74780 + atomic_unchecked_t serial; /* packet serial number counter */
74781 + atomic_unchecked_t hi_serial; /* highest serial number received */
74782 u8 avail_calls; /* number of calls available */
74783 u8 size_align; /* data size alignment (for security) */
74784 u8 header_size; /* rxrpc + security header size */
74785 @@ -346,7 +346,7 @@ struct rxrpc_call {
74786 spinlock_t lock;
74787 rwlock_t state_lock; /* lock for state transition */
74788 atomic_t usage;
74789 - atomic_t sequence; /* Tx data packet sequence counter */
74790 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
74791 u32 abort_code; /* local/remote abort code */
74792 enum { /* current state of call */
74793 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
74794 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
74795 */
74796 extern atomic_t rxrpc_n_skbs;
74797 extern __be32 rxrpc_epoch;
74798 -extern atomic_t rxrpc_debug_id;
74799 +extern atomic_unchecked_t rxrpc_debug_id;
74800 extern struct workqueue_struct *rxrpc_workqueue;
74801
74802 /*
74803 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
74804 index 87f7135..74d3703 100644
74805 --- a/net/rxrpc/ar-local.c
74806 +++ b/net/rxrpc/ar-local.c
74807 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
74808 spin_lock_init(&local->lock);
74809 rwlock_init(&local->services_lock);
74810 atomic_set(&local->usage, 1);
74811 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
74812 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74813 memcpy(&local->srx, srx, sizeof(*srx));
74814 }
74815
74816 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
74817 index 338d793..47391d0 100644
74818 --- a/net/rxrpc/ar-output.c
74819 +++ b/net/rxrpc/ar-output.c
74820 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
74821 sp->hdr.cid = call->cid;
74822 sp->hdr.callNumber = call->call_id;
74823 sp->hdr.seq =
74824 - htonl(atomic_inc_return(&call->sequence));
74825 + htonl(atomic_inc_return_unchecked(&call->sequence));
74826 sp->hdr.serial =
74827 - htonl(atomic_inc_return(&conn->serial));
74828 + htonl(atomic_inc_return_unchecked(&conn->serial));
74829 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
74830 sp->hdr.userStatus = 0;
74831 sp->hdr.securityIndex = conn->security_ix;
74832 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
74833 index 2754f09..b20e38f 100644
74834 --- a/net/rxrpc/ar-peer.c
74835 +++ b/net/rxrpc/ar-peer.c
74836 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
74837 INIT_LIST_HEAD(&peer->error_targets);
74838 spin_lock_init(&peer->lock);
74839 atomic_set(&peer->usage, 1);
74840 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
74841 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74842 memcpy(&peer->srx, srx, sizeof(*srx));
74843
74844 rxrpc_assess_MTU_size(peer);
74845 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
74846 index 38047f7..9f48511 100644
74847 --- a/net/rxrpc/ar-proc.c
74848 +++ b/net/rxrpc/ar-proc.c
74849 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
74850 atomic_read(&conn->usage),
74851 rxrpc_conn_states[conn->state],
74852 key_serial(conn->key),
74853 - atomic_read(&conn->serial),
74854 - atomic_read(&conn->hi_serial));
74855 + atomic_read_unchecked(&conn->serial),
74856 + atomic_read_unchecked(&conn->hi_serial));
74857
74858 return 0;
74859 }
74860 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
74861 index 92df566..87ec1bf 100644
74862 --- a/net/rxrpc/ar-transport.c
74863 +++ b/net/rxrpc/ar-transport.c
74864 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
74865 spin_lock_init(&trans->client_lock);
74866 rwlock_init(&trans->conn_lock);
74867 atomic_set(&trans->usage, 1);
74868 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
74869 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74870
74871 if (peer->srx.transport.family == AF_INET) {
74872 switch (peer->srx.transport_type) {
74873 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
74874 index 7635107..4670276 100644
74875 --- a/net/rxrpc/rxkad.c
74876 +++ b/net/rxrpc/rxkad.c
74877 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
74878
74879 len = iov[0].iov_len + iov[1].iov_len;
74880
74881 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
74882 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
74883 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
74884
74885 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
74886 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
74887
74888 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
74889
74890 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
74891 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
74892 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
74893
74894 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
74895 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
74896 index 1e2eee8..ce3967e 100644
74897 --- a/net/sctp/proc.c
74898 +++ b/net/sctp/proc.c
74899 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
74900 seq_printf(seq,
74901 "%8pK %8pK %-3d %-3d %-2d %-4d "
74902 "%4d %8d %8d %7d %5lu %-5d %5d ",
74903 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
74904 + assoc, sk,
74905 + sctp_sk(sk)->type, sk->sk_state,
74906 assoc->state, hash,
74907 assoc->assoc_id,
74908 assoc->sndbuf_used,
74909 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
74910 index 54a7cd2..944edae 100644
74911 --- a/net/sctp/socket.c
74912 +++ b/net/sctp/socket.c
74913 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
74914 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
74915 if (space_left < addrlen)
74916 return -ENOMEM;
74917 - if (copy_to_user(to, &temp, addrlen))
74918 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
74919 return -EFAULT;
74920 to += addrlen;
74921 cnt++;
74922 diff --git a/net/socket.c b/net/socket.c
74923 index 2dce67a..1e91168 100644
74924 --- a/net/socket.c
74925 +++ b/net/socket.c
74926 @@ -88,6 +88,7 @@
74927 #include <linux/nsproxy.h>
74928 #include <linux/magic.h>
74929 #include <linux/slab.h>
74930 +#include <linux/in.h>
74931
74932 #include <asm/uaccess.h>
74933 #include <asm/unistd.h>
74934 @@ -105,6 +106,8 @@
74935 #include <linux/sockios.h>
74936 #include <linux/atalk.h>
74937
74938 +#include <linux/grsock.h>
74939 +
74940 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
74941 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
74942 unsigned long nr_segs, loff_t pos);
74943 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
74944 &sockfs_dentry_operations, SOCKFS_MAGIC);
74945 }
74946
74947 -static struct vfsmount *sock_mnt __read_mostly;
74948 +struct vfsmount *sock_mnt __read_mostly;
74949
74950 static struct file_system_type sock_fs_type = {
74951 .name = "sockfs",
74952 @@ -1187,6 +1190,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
74953 return -EAFNOSUPPORT;
74954 if (type < 0 || type >= SOCK_MAX)
74955 return -EINVAL;
74956 + if (protocol < 0)
74957 + return -EINVAL;
74958
74959 /* Compatibility.
74960
74961 @@ -1319,6 +1324,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
74962 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
74963 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
74964
74965 + if(!gr_search_socket(family, type, protocol)) {
74966 + retval = -EACCES;
74967 + goto out;
74968 + }
74969 +
74970 + if (gr_handle_sock_all(family, type, protocol)) {
74971 + retval = -EACCES;
74972 + goto out;
74973 + }
74974 +
74975 retval = sock_create(family, type, protocol, &sock);
74976 if (retval < 0)
74977 goto out;
74978 @@ -1431,6 +1446,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
74979 if (sock) {
74980 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
74981 if (err >= 0) {
74982 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
74983 + err = -EACCES;
74984 + goto error;
74985 + }
74986 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
74987 + if (err)
74988 + goto error;
74989 +
74990 err = security_socket_bind(sock,
74991 (struct sockaddr *)&address,
74992 addrlen);
74993 @@ -1439,6 +1462,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
74994 (struct sockaddr *)
74995 &address, addrlen);
74996 }
74997 +error:
74998 fput_light(sock->file, fput_needed);
74999 }
75000 return err;
75001 @@ -1462,10 +1486,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
75002 if ((unsigned)backlog > somaxconn)
75003 backlog = somaxconn;
75004
75005 + if (gr_handle_sock_server_other(sock->sk)) {
75006 + err = -EPERM;
75007 + goto error;
75008 + }
75009 +
75010 + err = gr_search_listen(sock);
75011 + if (err)
75012 + goto error;
75013 +
75014 err = security_socket_listen(sock, backlog);
75015 if (!err)
75016 err = sock->ops->listen(sock, backlog);
75017
75018 +error:
75019 fput_light(sock->file, fput_needed);
75020 }
75021 return err;
75022 @@ -1509,6 +1543,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
75023 newsock->type = sock->type;
75024 newsock->ops = sock->ops;
75025
75026 + if (gr_handle_sock_server_other(sock->sk)) {
75027 + err = -EPERM;
75028 + sock_release(newsock);
75029 + goto out_put;
75030 + }
75031 +
75032 + err = gr_search_accept(sock);
75033 + if (err) {
75034 + sock_release(newsock);
75035 + goto out_put;
75036 + }
75037 +
75038 /*
75039 * We don't need try_module_get here, as the listening socket (sock)
75040 * has the protocol module (sock->ops->owner) held.
75041 @@ -1547,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
75042 fd_install(newfd, newfile);
75043 err = newfd;
75044
75045 + gr_attach_curr_ip(newsock->sk);
75046 +
75047 out_put:
75048 fput_light(sock->file, fput_needed);
75049 out:
75050 @@ -1579,6 +1627,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
75051 int, addrlen)
75052 {
75053 struct socket *sock;
75054 + struct sockaddr *sck;
75055 struct sockaddr_storage address;
75056 int err, fput_needed;
75057
75058 @@ -1589,6 +1638,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
75059 if (err < 0)
75060 goto out_put;
75061
75062 + sck = (struct sockaddr *)&address;
75063 +
75064 + if (gr_handle_sock_client(sck)) {
75065 + err = -EACCES;
75066 + goto out_put;
75067 + }
75068 +
75069 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
75070 + if (err)
75071 + goto out_put;
75072 +
75073 err =
75074 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
75075 if (err)
75076 @@ -1950,7 +2010,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
75077 * checking falls down on this.
75078 */
75079 if (copy_from_user(ctl_buf,
75080 - (void __user __force *)msg_sys->msg_control,
75081 + (void __force_user *)msg_sys->msg_control,
75082 ctl_len))
75083 goto out_freectl;
75084 msg_sys->msg_control = ctl_buf;
75085 @@ -2120,7 +2180,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
75086 * kernel msghdr to use the kernel address space)
75087 */
75088
75089 - uaddr = (__force void __user *)msg_sys->msg_name;
75090 + uaddr = (void __force_user *)msg_sys->msg_name;
75091 uaddr_len = COMPAT_NAMELEN(msg);
75092 if (MSG_CMSG_COMPAT & flags) {
75093 err = verify_compat_iovec(msg_sys, iov,
75094 @@ -2748,7 +2808,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
75095 }
75096
75097 ifr = compat_alloc_user_space(buf_size);
75098 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
75099 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
75100
75101 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
75102 return -EFAULT;
75103 @@ -2772,12 +2832,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
75104 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
75105
75106 if (copy_in_user(rxnfc, compat_rxnfc,
75107 - (void *)(&rxnfc->fs.m_ext + 1) -
75108 - (void *)rxnfc) ||
75109 + (void __user *)(&rxnfc->fs.m_ext + 1) -
75110 + (void __user *)rxnfc) ||
75111 copy_in_user(&rxnfc->fs.ring_cookie,
75112 &compat_rxnfc->fs.ring_cookie,
75113 - (void *)(&rxnfc->fs.location + 1) -
75114 - (void *)&rxnfc->fs.ring_cookie) ||
75115 + (void __user *)(&rxnfc->fs.location + 1) -
75116 + (void __user *)&rxnfc->fs.ring_cookie) ||
75117 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
75118 sizeof(rxnfc->rule_cnt)))
75119 return -EFAULT;
75120 @@ -2789,12 +2849,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
75121
75122 if (convert_out) {
75123 if (copy_in_user(compat_rxnfc, rxnfc,
75124 - (const void *)(&rxnfc->fs.m_ext + 1) -
75125 - (const void *)rxnfc) ||
75126 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
75127 + (const void __user *)rxnfc) ||
75128 copy_in_user(&compat_rxnfc->fs.ring_cookie,
75129 &rxnfc->fs.ring_cookie,
75130 - (const void *)(&rxnfc->fs.location + 1) -
75131 - (const void *)&rxnfc->fs.ring_cookie) ||
75132 + (const void __user *)(&rxnfc->fs.location + 1) -
75133 + (const void __user *)&rxnfc->fs.ring_cookie) ||
75134 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
75135 sizeof(rxnfc->rule_cnt)))
75136 return -EFAULT;
75137 @@ -2864,7 +2924,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
75138 old_fs = get_fs();
75139 set_fs(KERNEL_DS);
75140 err = dev_ioctl(net, cmd,
75141 - (struct ifreq __user __force *) &kifr);
75142 + (struct ifreq __force_user *) &kifr);
75143 set_fs(old_fs);
75144
75145 return err;
75146 @@ -2973,7 +3033,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
75147
75148 old_fs = get_fs();
75149 set_fs(KERNEL_DS);
75150 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
75151 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
75152 set_fs(old_fs);
75153
75154 if (cmd == SIOCGIFMAP && !err) {
75155 @@ -3078,7 +3138,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
75156 ret |= __get_user(rtdev, &(ur4->rt_dev));
75157 if (rtdev) {
75158 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
75159 - r4.rt_dev = (char __user __force *)devname;
75160 + r4.rt_dev = (char __force_user *)devname;
75161 devname[15] = 0;
75162 } else
75163 r4.rt_dev = NULL;
75164 @@ -3318,8 +3378,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
75165 int __user *uoptlen;
75166 int err;
75167
75168 - uoptval = (char __user __force *) optval;
75169 - uoptlen = (int __user __force *) optlen;
75170 + uoptval = (char __force_user *) optval;
75171 + uoptlen = (int __force_user *) optlen;
75172
75173 set_fs(KERNEL_DS);
75174 if (level == SOL_SOCKET)
75175 @@ -3339,7 +3399,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
75176 char __user *uoptval;
75177 int err;
75178
75179 - uoptval = (char __user __force *) optval;
75180 + uoptval = (char __force_user *) optval;
75181
75182 set_fs(KERNEL_DS);
75183 if (level == SOL_SOCKET)
75184 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
75185 index 00a1a2a..6a0138a 100644
75186 --- a/net/sunrpc/sched.c
75187 +++ b/net/sunrpc/sched.c
75188 @@ -238,9 +238,9 @@ static int rpc_wait_bit_killable(void *word)
75189 #ifdef RPC_DEBUG
75190 static void rpc_task_set_debuginfo(struct rpc_task *task)
75191 {
75192 - static atomic_t rpc_pid;
75193 + static atomic_unchecked_t rpc_pid;
75194
75195 - task->tk_pid = atomic_inc_return(&rpc_pid);
75196 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
75197 }
75198 #else
75199 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
75200 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
75201 index 71bed1c..5dff36d 100644
75202 --- a/net/sunrpc/svcsock.c
75203 +++ b/net/sunrpc/svcsock.c
75204 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
75205 int buflen, unsigned int base)
75206 {
75207 size_t save_iovlen;
75208 - void __user *save_iovbase;
75209 + void *save_iovbase;
75210 unsigned int i;
75211 int ret;
75212
75213 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
75214 index 09af4fa..77110a9 100644
75215 --- a/net/sunrpc/xprtrdma/svc_rdma.c
75216 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
75217 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
75218 static unsigned int min_max_inline = 4096;
75219 static unsigned int max_max_inline = 65536;
75220
75221 -atomic_t rdma_stat_recv;
75222 -atomic_t rdma_stat_read;
75223 -atomic_t rdma_stat_write;
75224 -atomic_t rdma_stat_sq_starve;
75225 -atomic_t rdma_stat_rq_starve;
75226 -atomic_t rdma_stat_rq_poll;
75227 -atomic_t rdma_stat_rq_prod;
75228 -atomic_t rdma_stat_sq_poll;
75229 -atomic_t rdma_stat_sq_prod;
75230 +atomic_unchecked_t rdma_stat_recv;
75231 +atomic_unchecked_t rdma_stat_read;
75232 +atomic_unchecked_t rdma_stat_write;
75233 +atomic_unchecked_t rdma_stat_sq_starve;
75234 +atomic_unchecked_t rdma_stat_rq_starve;
75235 +atomic_unchecked_t rdma_stat_rq_poll;
75236 +atomic_unchecked_t rdma_stat_rq_prod;
75237 +atomic_unchecked_t rdma_stat_sq_poll;
75238 +atomic_unchecked_t rdma_stat_sq_prod;
75239
75240 /* Temporary NFS request map and context caches */
75241 struct kmem_cache *svc_rdma_map_cachep;
75242 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
75243 len -= *ppos;
75244 if (len > *lenp)
75245 len = *lenp;
75246 - if (len && copy_to_user(buffer, str_buf, len))
75247 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
75248 return -EFAULT;
75249 *lenp = len;
75250 *ppos += len;
75251 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
75252 {
75253 .procname = "rdma_stat_read",
75254 .data = &rdma_stat_read,
75255 - .maxlen = sizeof(atomic_t),
75256 + .maxlen = sizeof(atomic_unchecked_t),
75257 .mode = 0644,
75258 .proc_handler = read_reset_stat,
75259 },
75260 {
75261 .procname = "rdma_stat_recv",
75262 .data = &rdma_stat_recv,
75263 - .maxlen = sizeof(atomic_t),
75264 + .maxlen = sizeof(atomic_unchecked_t),
75265 .mode = 0644,
75266 .proc_handler = read_reset_stat,
75267 },
75268 {
75269 .procname = "rdma_stat_write",
75270 .data = &rdma_stat_write,
75271 - .maxlen = sizeof(atomic_t),
75272 + .maxlen = sizeof(atomic_unchecked_t),
75273 .mode = 0644,
75274 .proc_handler = read_reset_stat,
75275 },
75276 {
75277 .procname = "rdma_stat_sq_starve",
75278 .data = &rdma_stat_sq_starve,
75279 - .maxlen = sizeof(atomic_t),
75280 + .maxlen = sizeof(atomic_unchecked_t),
75281 .mode = 0644,
75282 .proc_handler = read_reset_stat,
75283 },
75284 {
75285 .procname = "rdma_stat_rq_starve",
75286 .data = &rdma_stat_rq_starve,
75287 - .maxlen = sizeof(atomic_t),
75288 + .maxlen = sizeof(atomic_unchecked_t),
75289 .mode = 0644,
75290 .proc_handler = read_reset_stat,
75291 },
75292 {
75293 .procname = "rdma_stat_rq_poll",
75294 .data = &rdma_stat_rq_poll,
75295 - .maxlen = sizeof(atomic_t),
75296 + .maxlen = sizeof(atomic_unchecked_t),
75297 .mode = 0644,
75298 .proc_handler = read_reset_stat,
75299 },
75300 {
75301 .procname = "rdma_stat_rq_prod",
75302 .data = &rdma_stat_rq_prod,
75303 - .maxlen = sizeof(atomic_t),
75304 + .maxlen = sizeof(atomic_unchecked_t),
75305 .mode = 0644,
75306 .proc_handler = read_reset_stat,
75307 },
75308 {
75309 .procname = "rdma_stat_sq_poll",
75310 .data = &rdma_stat_sq_poll,
75311 - .maxlen = sizeof(atomic_t),
75312 + .maxlen = sizeof(atomic_unchecked_t),
75313 .mode = 0644,
75314 .proc_handler = read_reset_stat,
75315 },
75316 {
75317 .procname = "rdma_stat_sq_prod",
75318 .data = &rdma_stat_sq_prod,
75319 - .maxlen = sizeof(atomic_t),
75320 + .maxlen = sizeof(atomic_unchecked_t),
75321 .mode = 0644,
75322 .proc_handler = read_reset_stat,
75323 },
75324 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75325 index df67211..c354b13 100644
75326 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75327 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75328 @@ -499,7 +499,7 @@ next_sge:
75329 svc_rdma_put_context(ctxt, 0);
75330 goto out;
75331 }
75332 - atomic_inc(&rdma_stat_read);
75333 + atomic_inc_unchecked(&rdma_stat_read);
75334
75335 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
75336 chl_map->ch[ch_no].count -= read_wr.num_sge;
75337 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
75338 dto_q);
75339 list_del_init(&ctxt->dto_q);
75340 } else {
75341 - atomic_inc(&rdma_stat_rq_starve);
75342 + atomic_inc_unchecked(&rdma_stat_rq_starve);
75343 clear_bit(XPT_DATA, &xprt->xpt_flags);
75344 ctxt = NULL;
75345 }
75346 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
75347 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
75348 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
75349 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
75350 - atomic_inc(&rdma_stat_recv);
75351 + atomic_inc_unchecked(&rdma_stat_recv);
75352
75353 /* Build up the XDR from the receive buffers. */
75354 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
75355 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75356 index 249a835..fb2794b 100644
75357 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75358 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75359 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
75360 write_wr.wr.rdma.remote_addr = to;
75361
75362 /* Post It */
75363 - atomic_inc(&rdma_stat_write);
75364 + atomic_inc_unchecked(&rdma_stat_write);
75365 if (svc_rdma_send(xprt, &write_wr))
75366 goto err;
75367 return 0;
75368 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
75369 index ba1296d..0fec1a5 100644
75370 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
75371 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
75372 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
75373 return;
75374
75375 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
75376 - atomic_inc(&rdma_stat_rq_poll);
75377 + atomic_inc_unchecked(&rdma_stat_rq_poll);
75378
75379 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
75380 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
75381 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
75382 }
75383
75384 if (ctxt)
75385 - atomic_inc(&rdma_stat_rq_prod);
75386 + atomic_inc_unchecked(&rdma_stat_rq_prod);
75387
75388 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
75389 /*
75390 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
75391 return;
75392
75393 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
75394 - atomic_inc(&rdma_stat_sq_poll);
75395 + atomic_inc_unchecked(&rdma_stat_sq_poll);
75396 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
75397 if (wc.status != IB_WC_SUCCESS)
75398 /* Close the transport */
75399 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
75400 }
75401
75402 if (ctxt)
75403 - atomic_inc(&rdma_stat_sq_prod);
75404 + atomic_inc_unchecked(&rdma_stat_sq_prod);
75405 }
75406
75407 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
75408 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
75409 spin_lock_bh(&xprt->sc_lock);
75410 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
75411 spin_unlock_bh(&xprt->sc_lock);
75412 - atomic_inc(&rdma_stat_sq_starve);
75413 + atomic_inc_unchecked(&rdma_stat_sq_starve);
75414
75415 /* See if we can opportunistically reap SQ WR to make room */
75416 sq_cq_reap(xprt);
75417 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
75418 index e758139..d29ea47 100644
75419 --- a/net/sysctl_net.c
75420 +++ b/net/sysctl_net.c
75421 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
75422 struct ctl_table *table)
75423 {
75424 /* Allow network administrator to have same access as root. */
75425 - if (capable(CAP_NET_ADMIN)) {
75426 + if (capable_nolog(CAP_NET_ADMIN)) {
75427 int mode = (table->mode >> 6) & 7;
75428 return (mode << 6) | (mode << 3) | mode;
75429 }
75430 diff --git a/net/tipc/link.c b/net/tipc/link.c
75431 index ae98a72..7bb6056 100644
75432 --- a/net/tipc/link.c
75433 +++ b/net/tipc/link.c
75434 @@ -1203,7 +1203,7 @@ static int link_send_sections_long(struct tipc_port *sender,
75435 struct tipc_msg fragm_hdr;
75436 struct sk_buff *buf, *buf_chain, *prev;
75437 u32 fragm_crs, fragm_rest, hsz, sect_rest;
75438 - const unchar *sect_crs;
75439 + const unchar __user *sect_crs;
75440 int curr_sect;
75441 u32 fragm_no;
75442
75443 @@ -1247,7 +1247,7 @@ again:
75444
75445 if (!sect_rest) {
75446 sect_rest = msg_sect[++curr_sect].iov_len;
75447 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
75448 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
75449 }
75450
75451 if (sect_rest < fragm_rest)
75452 @@ -1266,7 +1266,7 @@ error:
75453 }
75454 } else
75455 skb_copy_to_linear_data_offset(buf, fragm_crs,
75456 - sect_crs, sz);
75457 + (const void __force_kernel *)sect_crs, sz);
75458 sect_crs += sz;
75459 sect_rest -= sz;
75460 fragm_crs += sz;
75461 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
75462 index 83d5096..dcba497 100644
75463 --- a/net/tipc/msg.c
75464 +++ b/net/tipc/msg.c
75465 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
75466 msg_sect[cnt].iov_len);
75467 else
75468 skb_copy_to_linear_data_offset(*buf, pos,
75469 - msg_sect[cnt].iov_base,
75470 + (const void __force_kernel *)msg_sect[cnt].iov_base,
75471 msg_sect[cnt].iov_len);
75472 pos += msg_sect[cnt].iov_len;
75473 }
75474 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
75475 index 1983717..4d6102c 100644
75476 --- a/net/tipc/subscr.c
75477 +++ b/net/tipc/subscr.c
75478 @@ -101,7 +101,7 @@ static void subscr_send_event(struct subscription *sub,
75479 {
75480 struct iovec msg_sect;
75481
75482 - msg_sect.iov_base = (void *)&sub->evt;
75483 + msg_sect.iov_base = (void __force_user *)&sub->evt;
75484 msg_sect.iov_len = sizeof(struct tipc_event);
75485
75486 sub->evt.event = htohl(event, sub->swap);
75487 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
75488 index d99678a..3514a21 100644
75489 --- a/net/unix/af_unix.c
75490 +++ b/net/unix/af_unix.c
75491 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(struct net *net,
75492 err = -ECONNREFUSED;
75493 if (!S_ISSOCK(inode->i_mode))
75494 goto put_fail;
75495 +
75496 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
75497 + err = -EACCES;
75498 + goto put_fail;
75499 + }
75500 +
75501 u = unix_find_socket_byinode(inode);
75502 if (!u)
75503 goto put_fail;
75504 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(struct net *net,
75505 if (u) {
75506 struct dentry *dentry;
75507 dentry = unix_sk(u)->dentry;
75508 +
75509 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
75510 + err = -EPERM;
75511 + sock_put(u);
75512 + goto fail;
75513 + }
75514 +
75515 if (dentry)
75516 touch_atime(unix_sk(u)->mnt, dentry);
75517 } else
75518 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
75519 err = security_path_mknod(&path, dentry, mode, 0);
75520 if (err)
75521 goto out_mknod_drop_write;
75522 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
75523 + err = -EACCES;
75524 + goto out_mknod_drop_write;
75525 + }
75526 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
75527 out_mknod_drop_write:
75528 mnt_drop_write(path.mnt);
75529 if (err)
75530 goto out_mknod_dput;
75531 +
75532 + gr_handle_create(dentry, path.mnt);
75533 +
75534 mutex_unlock(&path.dentry->d_inode->i_mutex);
75535 dput(path.dentry);
75536 path.dentry = dentry;
75537 diff --git a/net/wireless/core.h b/net/wireless/core.h
75538 index b9ec306..b4a563e 100644
75539 --- a/net/wireless/core.h
75540 +++ b/net/wireless/core.h
75541 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
75542 struct mutex mtx;
75543
75544 /* rfkill support */
75545 - struct rfkill_ops rfkill_ops;
75546 + rfkill_ops_no_const rfkill_ops;
75547 struct rfkill *rfkill;
75548 struct work_struct rfkill_sync;
75549
75550 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
75551 index 0af7f54..c916d2f 100644
75552 --- a/net/wireless/wext-core.c
75553 +++ b/net/wireless/wext-core.c
75554 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
75555 */
75556
75557 /* Support for very large requests */
75558 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
75559 - (user_length > descr->max_tokens)) {
75560 + if (user_length > descr->max_tokens) {
75561 /* Allow userspace to GET more than max so
75562 * we can support any size GET requests.
75563 * There is still a limit : -ENOMEM.
75564 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
75565 }
75566 }
75567
75568 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
75569 - /*
75570 - * If this is a GET, but not NOMAX, it means that the extra
75571 - * data is not bounded by userspace, but by max_tokens. Thus
75572 - * set the length to max_tokens. This matches the extra data
75573 - * allocation.
75574 - * The driver should fill it with the number of tokens it
75575 - * provided, and it may check iwp->length rather than having
75576 - * knowledge of max_tokens. If the driver doesn't change the
75577 - * iwp->length, this ioctl just copies back max_token tokens
75578 - * filled with zeroes. Hopefully the driver isn't claiming
75579 - * them to be valid data.
75580 - */
75581 - iwp->length = descr->max_tokens;
75582 - }
75583 -
75584 err = handler(dev, info, (union iwreq_data *) iwp, extra);
75585
75586 iwp->length += essid_compat;
75587 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
75588 index 9049a5c..cfa6f5c 100644
75589 --- a/net/xfrm/xfrm_policy.c
75590 +++ b/net/xfrm/xfrm_policy.c
75591 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
75592 {
75593 policy->walk.dead = 1;
75594
75595 - atomic_inc(&policy->genid);
75596 + atomic_inc_unchecked(&policy->genid);
75597
75598 if (del_timer(&policy->timer))
75599 xfrm_pol_put(policy);
75600 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
75601 hlist_add_head(&policy->bydst, chain);
75602 xfrm_pol_hold(policy);
75603 net->xfrm.policy_count[dir]++;
75604 - atomic_inc(&flow_cache_genid);
75605 + atomic_inc_unchecked(&flow_cache_genid);
75606 if (delpol)
75607 __xfrm_policy_unlink(delpol, dir);
75608 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
75609 @@ -1530,7 +1530,7 @@ free_dst:
75610 goto out;
75611 }
75612
75613 -static int inline
75614 +static inline int
75615 xfrm_dst_alloc_copy(void **target, const void *src, int size)
75616 {
75617 if (!*target) {
75618 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
75619 return 0;
75620 }
75621
75622 -static int inline
75623 +static inline int
75624 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
75625 {
75626 #ifdef CONFIG_XFRM_SUB_POLICY
75627 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
75628 #endif
75629 }
75630
75631 -static int inline
75632 +static inline int
75633 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
75634 {
75635 #ifdef CONFIG_XFRM_SUB_POLICY
75636 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
75637
75638 xdst->num_pols = num_pols;
75639 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
75640 - xdst->policy_genid = atomic_read(&pols[0]->genid);
75641 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
75642
75643 return xdst;
75644 }
75645 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
75646 if (xdst->xfrm_genid != dst->xfrm->genid)
75647 return 0;
75648 if (xdst->num_pols > 0 &&
75649 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
75650 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
75651 return 0;
75652
75653 mtu = dst_mtu(dst->child);
75654 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
75655 sizeof(pol->xfrm_vec[i].saddr));
75656 pol->xfrm_vec[i].encap_family = mp->new_family;
75657 /* flush bundles */
75658 - atomic_inc(&pol->genid);
75659 + atomic_inc_unchecked(&pol->genid);
75660 }
75661 }
75662
75663 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
75664 index d2b366c..51ff91e 100644
75665 --- a/scripts/Makefile.build
75666 +++ b/scripts/Makefile.build
75667 @@ -109,7 +109,7 @@ endif
75668 endif
75669
75670 # Do not include host rules unless needed
75671 -ifneq ($(hostprogs-y)$(hostprogs-m),)
75672 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
75673 include scripts/Makefile.host
75674 endif
75675
75676 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
75677 index 686cb0d..9d653bf 100644
75678 --- a/scripts/Makefile.clean
75679 +++ b/scripts/Makefile.clean
75680 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
75681 __clean-files := $(extra-y) $(always) \
75682 $(targets) $(clean-files) \
75683 $(host-progs) \
75684 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
75685 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
75686 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
75687
75688 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
75689
75690 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
75691 index 1ac414f..a1c1451 100644
75692 --- a/scripts/Makefile.host
75693 +++ b/scripts/Makefile.host
75694 @@ -31,6 +31,7 @@
75695 # Note: Shared libraries consisting of C++ files are not supported
75696
75697 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
75698 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
75699
75700 # C code
75701 # Executables compiled from a single .c file
75702 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
75703 # Shared libaries (only .c supported)
75704 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
75705 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
75706 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
75707 # Remove .so files from "xxx-objs"
75708 host-cobjs := $(filter-out %.so,$(host-cobjs))
75709
75710 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
75711 index cb1f50c..cef2a7c 100644
75712 --- a/scripts/basic/fixdep.c
75713 +++ b/scripts/basic/fixdep.c
75714 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
75715 /*
75716 * Lookup a value in the configuration string.
75717 */
75718 -static int is_defined_config(const char *name, int len, unsigned int hash)
75719 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
75720 {
75721 struct item *aux;
75722
75723 @@ -211,10 +211,10 @@ static void clear_config(void)
75724 /*
75725 * Record the use of a CONFIG_* word.
75726 */
75727 -static void use_config(const char *m, int slen)
75728 +static void use_config(const char *m, unsigned int slen)
75729 {
75730 unsigned int hash = strhash(m, slen);
75731 - int c, i;
75732 + unsigned int c, i;
75733
75734 if (is_defined_config(m, slen, hash))
75735 return;
75736 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
75737
75738 static void parse_config_file(const char *map, size_t len)
75739 {
75740 - const int *end = (const int *) (map + len);
75741 + const unsigned int *end = (const unsigned int *) (map + len);
75742 /* start at +1, so that p can never be < map */
75743 - const int *m = (const int *) map + 1;
75744 + const unsigned int *m = (const unsigned int *) map + 1;
75745 const char *p, *q;
75746
75747 for (; m < end; m++) {
75748 @@ -406,7 +406,7 @@ static void print_deps(void)
75749 static void traps(void)
75750 {
75751 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
75752 - int *p = (int *)test;
75753 + unsigned int *p = (unsigned int *)test;
75754
75755 if (*p != INT_CONF) {
75756 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
75757 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
75758 new file mode 100644
75759 index 0000000..8729101
75760 --- /dev/null
75761 +++ b/scripts/gcc-plugin.sh
75762 @@ -0,0 +1,2 @@
75763 +#!/bin/sh
75764 +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"
75765 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
75766 index f936d1f..a66d95f 100644
75767 --- a/scripts/mod/file2alias.c
75768 +++ b/scripts/mod/file2alias.c
75769 @@ -72,7 +72,7 @@ static void device_id_check(const char *modname, const char *device_id,
75770 unsigned long size, unsigned long id_size,
75771 void *symval)
75772 {
75773 - int i;
75774 + unsigned int i;
75775
75776 if (size % id_size || size < id_size) {
75777 if (cross_build != 0)
75778 @@ -102,7 +102,7 @@ static void device_id_check(const char *modname, const char *device_id,
75779 /* USB is special because the bcdDevice can be matched against a numeric range */
75780 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
75781 static void do_usb_entry(struct usb_device_id *id,
75782 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
75783 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
75784 unsigned char range_lo, unsigned char range_hi,
75785 unsigned char max, struct module *mod)
75786 {
75787 @@ -203,7 +203,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
75788 {
75789 unsigned int devlo, devhi;
75790 unsigned char chi, clo, max;
75791 - int ndigits;
75792 + unsigned int ndigits;
75793
75794 id->match_flags = TO_NATIVE(id->match_flags);
75795 id->idVendor = TO_NATIVE(id->idVendor);
75796 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
75797 for (i = 0; i < count; i++) {
75798 const char *id = (char *)devs[i].id;
75799 char acpi_id[sizeof(devs[0].id)];
75800 - int j;
75801 + unsigned int j;
75802
75803 buf_printf(&mod->dev_table_buf,
75804 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
75805 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
75806
75807 for (j = 0; j < PNP_MAX_DEVICES; j++) {
75808 const char *id = (char *)card->devs[j].id;
75809 - int i2, j2;
75810 + unsigned int i2, j2;
75811 int dup = 0;
75812
75813 if (!id[0])
75814 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
75815 /* add an individual alias for every device entry */
75816 if (!dup) {
75817 char acpi_id[sizeof(card->devs[0].id)];
75818 - int k;
75819 + unsigned int k;
75820
75821 buf_printf(&mod->dev_table_buf,
75822 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
75823 @@ -807,7 +807,7 @@ static void dmi_ascii_filter(char *d, const char *s)
75824 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
75825 char *alias)
75826 {
75827 - int i, j;
75828 + unsigned int i, j;
75829
75830 sprintf(alias, "dmi*");
75831
75832 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
75833 index 2bd594e..d43245e 100644
75834 --- a/scripts/mod/modpost.c
75835 +++ b/scripts/mod/modpost.c
75836 @@ -919,6 +919,7 @@ enum mismatch {
75837 ANY_INIT_TO_ANY_EXIT,
75838 ANY_EXIT_TO_ANY_INIT,
75839 EXPORT_TO_INIT_EXIT,
75840 + DATA_TO_TEXT
75841 };
75842
75843 struct sectioncheck {
75844 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
75845 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
75846 .mismatch = EXPORT_TO_INIT_EXIT,
75847 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
75848 +},
75849 +/* Do not reference code from writable data */
75850 +{
75851 + .fromsec = { DATA_SECTIONS, NULL },
75852 + .tosec = { TEXT_SECTIONS, NULL },
75853 + .mismatch = DATA_TO_TEXT
75854 }
75855 };
75856
75857 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
75858 continue;
75859 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
75860 continue;
75861 - if (sym->st_value == addr)
75862 - return sym;
75863 /* Find a symbol nearby - addr are maybe negative */
75864 d = sym->st_value - addr;
75865 + if (d == 0)
75866 + return sym;
75867 if (d < 0)
75868 d = addr - sym->st_value;
75869 if (d < distance) {
75870 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
75871 tosym, prl_to, prl_to, tosym);
75872 free(prl_to);
75873 break;
75874 + case DATA_TO_TEXT:
75875 +/*
75876 + fprintf(stderr,
75877 + "The variable %s references\n"
75878 + "the %s %s%s%s\n",
75879 + fromsym, to, sec2annotation(tosec), tosym, to_p);
75880 +*/
75881 + break;
75882 }
75883 fprintf(stderr, "\n");
75884 }
75885 @@ -1656,7 +1671,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
75886 static void check_sec_ref(struct module *mod, const char *modname,
75887 struct elf_info *elf)
75888 {
75889 - int i;
75890 + unsigned int i;
75891 Elf_Shdr *sechdrs = elf->sechdrs;
75892
75893 /* Walk through all sections */
75894 @@ -1754,7 +1769,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
75895 va_end(ap);
75896 }
75897
75898 -void buf_write(struct buffer *buf, const char *s, int len)
75899 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
75900 {
75901 if (buf->size - buf->pos < len) {
75902 buf->size += len + SZ;
75903 @@ -1972,7 +1987,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
75904 if (fstat(fileno(file), &st) < 0)
75905 goto close_write;
75906
75907 - if (st.st_size != b->pos)
75908 + if (st.st_size != (off_t)b->pos)
75909 goto close_write;
75910
75911 tmp = NOFAIL(malloc(b->pos));
75912 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
75913 index 2031119..b5433af 100644
75914 --- a/scripts/mod/modpost.h
75915 +++ b/scripts/mod/modpost.h
75916 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
75917
75918 struct buffer {
75919 char *p;
75920 - int pos;
75921 - int size;
75922 + unsigned int pos;
75923 + unsigned int size;
75924 };
75925
75926 void __attribute__((format(printf, 2, 3)))
75927 buf_printf(struct buffer *buf, const char *fmt, ...);
75928
75929 void
75930 -buf_write(struct buffer *buf, const char *s, int len);
75931 +buf_write(struct buffer *buf, const char *s, unsigned int len);
75932
75933 struct module {
75934 struct module *next;
75935 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
75936 index 9dfcd6d..099068e 100644
75937 --- a/scripts/mod/sumversion.c
75938 +++ b/scripts/mod/sumversion.c
75939 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
75940 goto out;
75941 }
75942
75943 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
75944 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
75945 warn("writing sum in %s failed: %s\n",
75946 filename, strerror(errno));
75947 goto out;
75948 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
75949 index 5c11312..72742b5 100644
75950 --- a/scripts/pnmtologo.c
75951 +++ b/scripts/pnmtologo.c
75952 @@ -237,14 +237,14 @@ static void write_header(void)
75953 fprintf(out, " * Linux logo %s\n", logoname);
75954 fputs(" */\n\n", out);
75955 fputs("#include <linux/linux_logo.h>\n\n", out);
75956 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
75957 + fprintf(out, "static unsigned char %s_data[] = {\n",
75958 logoname);
75959 }
75960
75961 static void write_footer(void)
75962 {
75963 fputs("\n};\n\n", out);
75964 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
75965 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
75966 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
75967 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
75968 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
75969 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
75970 fputs("\n};\n\n", out);
75971
75972 /* write logo clut */
75973 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
75974 + fprintf(out, "static unsigned char %s_clut[] = {\n",
75975 logoname);
75976 write_hex_cnt = 0;
75977 for (i = 0; i < logo_clutsize; i++) {
75978 diff --git a/security/Kconfig b/security/Kconfig
75979 index 51bd5a0..eeabc9f 100644
75980 --- a/security/Kconfig
75981 +++ b/security/Kconfig
75982 @@ -4,6 +4,627 @@
75983
75984 menu "Security options"
75985
75986 +source grsecurity/Kconfig
75987 +
75988 +menu "PaX"
75989 +
75990 + config ARCH_TRACK_EXEC_LIMIT
75991 + bool
75992 +
75993 + config PAX_KERNEXEC_PLUGIN
75994 + bool
75995 +
75996 + config PAX_PER_CPU_PGD
75997 + bool
75998 +
75999 + config TASK_SIZE_MAX_SHIFT
76000 + int
76001 + depends on X86_64
76002 + default 47 if !PAX_PER_CPU_PGD
76003 + default 42 if PAX_PER_CPU_PGD
76004 +
76005 + config PAX_ENABLE_PAE
76006 + bool
76007 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
76008 +
76009 +config PAX
76010 + bool "Enable various PaX features"
76011 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
76012 + help
76013 + This allows you to enable various PaX features. PaX adds
76014 + intrusion prevention mechanisms to the kernel that reduce
76015 + the risks posed by exploitable memory corruption bugs.
76016 +
76017 +menu "PaX Control"
76018 + depends on PAX
76019 +
76020 +config PAX_SOFTMODE
76021 + bool 'Support soft mode'
76022 + help
76023 + Enabling this option will allow you to run PaX in soft mode, that
76024 + is, PaX features will not be enforced by default, only on executables
76025 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
76026 + support as they are the only way to mark executables for soft mode use.
76027 +
76028 + Soft mode can be activated by using the "pax_softmode=1" kernel command
76029 + line option on boot. Furthermore you can control various PaX features
76030 + at runtime via the entries in /proc/sys/kernel/pax.
76031 +
76032 +config PAX_EI_PAX
76033 + bool 'Use legacy ELF header marking'
76034 + help
76035 + Enabling this option will allow you to control PaX features on
76036 + a per executable basis via the 'chpax' utility available at
76037 + http://pax.grsecurity.net/. The control flags will be read from
76038 + an otherwise reserved part of the ELF header. This marking has
76039 + numerous drawbacks (no support for soft-mode, toolchain does not
76040 + know about the non-standard use of the ELF header) therefore it
76041 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
76042 + support.
76043 +
76044 + If you have applications not marked by the PT_PAX_FLAGS ELF program
76045 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
76046 + option otherwise they will not get any protection.
76047 +
76048 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
76049 + support as well, they will override the legacy EI_PAX marks.
76050 +
76051 +config PAX_PT_PAX_FLAGS
76052 + bool 'Use ELF program header marking'
76053 + help
76054 + Enabling this option will allow you to control PaX features on
76055 + a per executable basis via the 'paxctl' utility available at
76056 + http://pax.grsecurity.net/. The control flags will be read from
76057 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
76058 + has the benefits of supporting both soft mode and being fully
76059 + integrated into the toolchain (the binutils patch is available
76060 + from http://pax.grsecurity.net).
76061 +
76062 + If you have applications not marked by the PT_PAX_FLAGS ELF program
76063 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
76064 + support otherwise they will not get any protection.
76065 +
76066 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
76067 + must make sure that the marks are the same if a binary has both marks.
76068 +
76069 + Note that if you enable the legacy EI_PAX marking support as well,
76070 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
76071 +
76072 +config PAX_XATTR_PAX_FLAGS
76073 + bool 'Use filesystem extended attributes marking'
76074 + depends on EXPERT
76075 + select CIFS_XATTR if CIFS
76076 + select EXT2_FS_XATTR if EXT2_FS
76077 + select EXT3_FS_XATTR if EXT3_FS
76078 + select EXT4_FS_XATTR if EXT4_FS
76079 + select JFFS2_FS_XATTR if JFFS2_FS
76080 + select REISERFS_FS_XATTR if REISERFS_FS
76081 + select SQUASHFS_XATTR if SQUASHFS
76082 + select TMPFS_XATTR if TMPFS
76083 + select UBIFS_FS_XATTR if UBIFS_FS
76084 + help
76085 + Enabling this option will allow you to control PaX features on
76086 + a per executable basis via the 'setfattr' utility. The control
76087 + flags will be read from the user.pax.flags extended attribute of
76088 + the file. This marking has the benefit of supporting binary-only
76089 + applications that self-check themselves (e.g., skype) and would
76090 + not tolerate chpax/paxctl changes. The main drawback is that
76091 + extended attributes are not supported by some filesystems (e.g.,
76092 + isofs, udf, vfat) so copying files through such filesystems will
76093 + lose the extended attributes and these PaX markings.
76094 +
76095 + If you have applications not marked by the PT_PAX_FLAGS ELF program
76096 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
76097 + support otherwise they will not get any protection.
76098 +
76099 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
76100 + must make sure that the marks are the same if a binary has both marks.
76101 +
76102 + Note that if you enable the legacy EI_PAX marking support as well,
76103 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
76104 +
76105 +choice
76106 + prompt 'MAC system integration'
76107 + default PAX_HAVE_ACL_FLAGS
76108 + help
76109 + Mandatory Access Control systems have the option of controlling
76110 + PaX flags on a per executable basis, choose the method supported
76111 + by your particular system.
76112 +
76113 + - "none": if your MAC system does not interact with PaX,
76114 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
76115 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
76116 +
76117 + NOTE: this option is for developers/integrators only.
76118 +
76119 + config PAX_NO_ACL_FLAGS
76120 + bool 'none'
76121 +
76122 + config PAX_HAVE_ACL_FLAGS
76123 + bool 'direct'
76124 +
76125 + config PAX_HOOK_ACL_FLAGS
76126 + bool 'hook'
76127 +endchoice
76128 +
76129 +endmenu
76130 +
76131 +menu "Non-executable pages"
76132 + depends on PAX
76133 +
76134 +config PAX_NOEXEC
76135 + bool "Enforce non-executable pages"
76136 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
76137 + help
76138 + By design some architectures do not allow for protecting memory
76139 + pages against execution or even if they do, Linux does not make
76140 + use of this feature. In practice this means that if a page is
76141 + readable (such as the stack or heap) it is also executable.
76142 +
76143 + There is a well known exploit technique that makes use of this
76144 + fact and a common programming mistake where an attacker can
76145 + introduce code of his choice somewhere in the attacked program's
76146 + memory (typically the stack or the heap) and then execute it.
76147 +
76148 + If the attacked program was running with different (typically
76149 + higher) privileges than that of the attacker, then he can elevate
76150 + his own privilege level (e.g. get a root shell, write to files for
76151 + which he does not have write access to, etc).
76152 +
76153 + Enabling this option will let you choose from various features
76154 + that prevent the injection and execution of 'foreign' code in
76155 + a program.
76156 +
76157 + This will also break programs that rely on the old behaviour and
76158 + expect that dynamically allocated memory via the malloc() family
76159 + of functions is executable (which it is not). Notable examples
76160 + are the XFree86 4.x server, the java runtime and wine.
76161 +
76162 +config PAX_PAGEEXEC
76163 + bool "Paging based non-executable pages"
76164 + 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)
76165 + select S390_SWITCH_AMODE if S390
76166 + select S390_EXEC_PROTECT if S390
76167 + select ARCH_TRACK_EXEC_LIMIT if X86_32
76168 + help
76169 + This implementation is based on the paging feature of the CPU.
76170 + On i386 without hardware non-executable bit support there is a
76171 + variable but usually low performance impact, however on Intel's
76172 + P4 core based CPUs it is very high so you should not enable this
76173 + for kernels meant to be used on such CPUs.
76174 +
76175 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
76176 + with hardware non-executable bit support there is no performance
76177 + impact, on ppc the impact is negligible.
76178 +
76179 + Note that several architectures require various emulations due to
76180 + badly designed userland ABIs, this will cause a performance impact
76181 + but will disappear as soon as userland is fixed. For example, ppc
76182 + userland MUST have been built with secure-plt by a recent toolchain.
76183 +
76184 +config PAX_SEGMEXEC
76185 + bool "Segmentation based non-executable pages"
76186 + depends on PAX_NOEXEC && X86_32
76187 + help
76188 + This implementation is based on the segmentation feature of the
76189 + CPU and has a very small performance impact, however applications
76190 + will be limited to a 1.5 GB address space instead of the normal
76191 + 3 GB.
76192 +
76193 +config PAX_EMUTRAMP
76194 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
76195 + default y if PARISC
76196 + help
76197 + There are some programs and libraries that for one reason or
76198 + another attempt to execute special small code snippets from
76199 + non-executable memory pages. Most notable examples are the
76200 + signal handler return code generated by the kernel itself and
76201 + the GCC trampolines.
76202 +
76203 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
76204 + such programs will no longer work under your kernel.
76205 +
76206 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
76207 + utilities to enable trampoline emulation for the affected programs
76208 + yet still have the protection provided by the non-executable pages.
76209 +
76210 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
76211 + your system will not even boot.
76212 +
76213 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
76214 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
76215 + for the affected files.
76216 +
76217 + NOTE: enabling this feature *may* open up a loophole in the
76218 + protection provided by non-executable pages that an attacker
76219 + could abuse. Therefore the best solution is to not have any
76220 + files on your system that would require this option. This can
76221 + be achieved by not using libc5 (which relies on the kernel
76222 + signal handler return code) and not using or rewriting programs
76223 + that make use of the nested function implementation of GCC.
76224 + Skilled users can just fix GCC itself so that it implements
76225 + nested function calls in a way that does not interfere with PaX.
76226 +
76227 +config PAX_EMUSIGRT
76228 + bool "Automatically emulate sigreturn trampolines"
76229 + depends on PAX_EMUTRAMP && PARISC
76230 + default y
76231 + help
76232 + Enabling this option will have the kernel automatically detect
76233 + and emulate signal return trampolines executing on the stack
76234 + that would otherwise lead to task termination.
76235 +
76236 + This solution is intended as a temporary one for users with
76237 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
76238 + Modula-3 runtime, etc) or executables linked to such, basically
76239 + everything that does not specify its own SA_RESTORER function in
76240 + normal executable memory like glibc 2.1+ does.
76241 +
76242 + On parisc you MUST enable this option, otherwise your system will
76243 + not even boot.
76244 +
76245 + NOTE: this feature cannot be disabled on a per executable basis
76246 + and since it *does* open up a loophole in the protection provided
76247 + by non-executable pages, the best solution is to not have any
76248 + files on your system that would require this option.
76249 +
76250 +config PAX_MPROTECT
76251 + bool "Restrict mprotect()"
76252 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
76253 + help
76254 + Enabling this option will prevent programs from
76255 + - changing the executable status of memory pages that were
76256 + not originally created as executable,
76257 + - making read-only executable pages writable again,
76258 + - creating executable pages from anonymous memory,
76259 + - making read-only-after-relocations (RELRO) data pages writable again.
76260 +
76261 + You should say Y here to complete the protection provided by
76262 + the enforcement of non-executable pages.
76263 +
76264 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
76265 + this feature on a per file basis.
76266 +
76267 +config PAX_MPROTECT_COMPAT
76268 + bool "Use legacy/compat protection demoting (read help)"
76269 + depends on PAX_MPROTECT
76270 + default n
76271 + help
76272 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
76273 + by sending the proper error code to the application. For some broken
76274 + userland, this can cause problems with Python or other applications. The
76275 + current implementation however allows for applications like clamav to
76276 + detect if JIT compilation/execution is allowed and to fall back gracefully
76277 + to an interpreter-based mode if it does not. While we encourage everyone
76278 + to use the current implementation as-is and push upstream to fix broken
76279 + userland (note that the RWX logging option can assist with this), in some
76280 + environments this may not be possible. Having to disable MPROTECT
76281 + completely on certain binaries reduces the security benefit of PaX,
76282 + so this option is provided for those environments to revert to the old
76283 + behavior.
76284 +
76285 +config PAX_ELFRELOCS
76286 + bool "Allow ELF text relocations (read help)"
76287 + depends on PAX_MPROTECT
76288 + default n
76289 + help
76290 + Non-executable pages and mprotect() restrictions are effective
76291 + in preventing the introduction of new executable code into an
76292 + attacked task's address space. There remain only two venues
76293 + for this kind of attack: if the attacker can execute already
76294 + existing code in the attacked task then he can either have it
76295 + create and mmap() a file containing his code or have it mmap()
76296 + an already existing ELF library that does not have position
76297 + independent code in it and use mprotect() on it to make it
76298 + writable and copy his code there. While protecting against
76299 + the former approach is beyond PaX, the latter can be prevented
76300 + by having only PIC ELF libraries on one's system (which do not
76301 + need to relocate their code). If you are sure this is your case,
76302 + as is the case with all modern Linux distributions, then leave
76303 + this option disabled. You should say 'n' here.
76304 +
76305 +config PAX_ETEXECRELOCS
76306 + bool "Allow ELF ET_EXEC text relocations"
76307 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
76308 + select PAX_ELFRELOCS
76309 + default y
76310 + help
76311 + On some architectures there are incorrectly created applications
76312 + that require text relocations and would not work without enabling
76313 + this option. If you are an alpha, ia64 or parisc user, you should
76314 + enable this option and disable it once you have made sure that
76315 + none of your applications need it.
76316 +
76317 +config PAX_EMUPLT
76318 + bool "Automatically emulate ELF PLT"
76319 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
76320 + default y
76321 + help
76322 + Enabling this option will have the kernel automatically detect
76323 + and emulate the Procedure Linkage Table entries in ELF files.
76324 + On some architectures such entries are in writable memory, and
76325 + become non-executable leading to task termination. Therefore
76326 + it is mandatory that you enable this option on alpha, parisc,
76327 + sparc and sparc64, otherwise your system would not even boot.
76328 +
76329 + NOTE: this feature *does* open up a loophole in the protection
76330 + provided by the non-executable pages, therefore the proper
76331 + solution is to modify the toolchain to produce a PLT that does
76332 + not need to be writable.
76333 +
76334 +config PAX_DLRESOLVE
76335 + bool 'Emulate old glibc resolver stub'
76336 + depends on PAX_EMUPLT && SPARC
76337 + default n
76338 + help
76339 + This option is needed if userland has an old glibc (before 2.4)
76340 + that puts a 'save' instruction into the runtime generated resolver
76341 + stub that needs special emulation.
76342 +
76343 +config PAX_KERNEXEC
76344 + bool "Enforce non-executable kernel pages"
76345 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
76346 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
76347 + select PAX_KERNEXEC_PLUGIN if X86_64
76348 + help
76349 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
76350 + that is, enabling this option will make it harder to inject
76351 + and execute 'foreign' code in kernel memory itself.
76352 +
76353 + Note that on x86_64 kernels there is a known regression when
76354 + this feature and KVM/VMX are both enabled in the host kernel.
76355 +
76356 +choice
76357 + prompt "Return Address Instrumentation Method"
76358 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
76359 + depends on PAX_KERNEXEC_PLUGIN
76360 + help
76361 + Select the method used to instrument function pointer dereferences.
76362 + Note that binary modules cannot be instrumented by this approach.
76363 +
76364 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
76365 + bool "bts"
76366 + help
76367 + This method is compatible with binary only modules but has
76368 + a higher runtime overhead.
76369 +
76370 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
76371 + bool "or"
76372 + depends on !PARAVIRT
76373 + help
76374 + This method is incompatible with binary only modules but has
76375 + a lower runtime overhead.
76376 +endchoice
76377 +
76378 +config PAX_KERNEXEC_PLUGIN_METHOD
76379 + string
76380 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
76381 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
76382 + default ""
76383 +
76384 +config PAX_KERNEXEC_MODULE_TEXT
76385 + int "Minimum amount of memory reserved for module code"
76386 + default "4"
76387 + depends on PAX_KERNEXEC && X86_32 && MODULES
76388 + help
76389 + Due to implementation details the kernel must reserve a fixed
76390 + amount of memory for module code at compile time that cannot be
76391 + changed at runtime. Here you can specify the minimum amount
76392 + in MB that will be reserved. Due to the same implementation
76393 + details this size will always be rounded up to the next 2/4 MB
76394 + boundary (depends on PAE) so the actually available memory for
76395 + module code will usually be more than this minimum.
76396 +
76397 + The default 4 MB should be enough for most users but if you have
76398 + an excessive number of modules (e.g., most distribution configs
76399 + compile many drivers as modules) or use huge modules such as
76400 + nvidia's kernel driver, you will need to adjust this amount.
76401 + A good rule of thumb is to look at your currently loaded kernel
76402 + modules and add up their sizes.
76403 +
76404 +endmenu
76405 +
76406 +menu "Address Space Layout Randomization"
76407 + depends on PAX
76408 +
76409 +config PAX_ASLR
76410 + bool "Address Space Layout Randomization"
76411 + help
76412 + Many if not most exploit techniques rely on the knowledge of
76413 + certain addresses in the attacked program. The following options
76414 + will allow the kernel to apply a certain amount of randomization
76415 + to specific parts of the program thereby forcing an attacker to
76416 + guess them in most cases. Any failed guess will most likely crash
76417 + the attacked program which allows the kernel to detect such attempts
76418 + and react on them. PaX itself provides no reaction mechanisms,
76419 + instead it is strongly encouraged that you make use of Nergal's
76420 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
76421 + (http://www.grsecurity.net/) built-in crash detection features or
76422 + develop one yourself.
76423 +
76424 + By saying Y here you can choose to randomize the following areas:
76425 + - top of the task's kernel stack
76426 + - top of the task's userland stack
76427 + - base address for mmap() requests that do not specify one
76428 + (this includes all libraries)
76429 + - base address of the main executable
76430 +
76431 + It is strongly recommended to say Y here as address space layout
76432 + randomization has negligible impact on performance yet it provides
76433 + a very effective protection.
76434 +
76435 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
76436 + this feature on a per file basis.
76437 +
76438 +config PAX_RANDKSTACK
76439 + bool "Randomize kernel stack base"
76440 + depends on X86_TSC && X86
76441 + help
76442 + By saying Y here the kernel will randomize every task's kernel
76443 + stack on every system call. This will not only force an attacker
76444 + to guess it but also prevent him from making use of possible
76445 + leaked information about it.
76446 +
76447 + Since the kernel stack is a rather scarce resource, randomization
76448 + may cause unexpected stack overflows, therefore you should very
76449 + carefully test your system. Note that once enabled in the kernel
76450 + configuration, this feature cannot be disabled on a per file basis.
76451 +
76452 +config PAX_RANDUSTACK
76453 + bool "Randomize user stack base"
76454 + depends on PAX_ASLR
76455 + help
76456 + By saying Y here the kernel will randomize every task's userland
76457 + stack. The randomization is done in two steps where the second
76458 + one may apply a big amount of shift to the top of the stack and
76459 + cause problems for programs that want to use lots of memory (more
76460 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
76461 + For this reason the second step can be controlled by 'chpax' or
76462 + 'paxctl' on a per file basis.
76463 +
76464 +config PAX_RANDMMAP
76465 + bool "Randomize mmap() base"
76466 + depends on PAX_ASLR
76467 + help
76468 + By saying Y here the kernel will use a randomized base address for
76469 + mmap() requests that do not specify one themselves. As a result
76470 + all dynamically loaded libraries will appear at random addresses
76471 + and therefore be harder to exploit by a technique where an attacker
76472 + attempts to execute library code for his purposes (e.g. spawn a
76473 + shell from an exploited program that is running at an elevated
76474 + privilege level).
76475 +
76476 + Furthermore, if a program is relinked as a dynamic ELF file, its
76477 + base address will be randomized as well, completing the full
76478 + randomization of the address space layout. Attacking such programs
76479 + becomes a guess game. You can find an example of doing this at
76480 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
76481 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
76482 +
76483 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
76484 + feature on a per file basis.
76485 +
76486 +endmenu
76487 +
76488 +menu "Miscellaneous hardening features"
76489 +
76490 +config PAX_MEMORY_SANITIZE
76491 + bool "Sanitize all freed memory"
76492 + depends on !HIBERNATION
76493 + help
76494 + By saying Y here the kernel will erase memory pages as soon as they
76495 + are freed. This in turn reduces the lifetime of data stored in the
76496 + pages, making it less likely that sensitive information such as
76497 + passwords, cryptographic secrets, etc stay in memory for too long.
76498 +
76499 + This is especially useful for programs whose runtime is short, long
76500 + lived processes and the kernel itself benefit from this as long as
76501 + they operate on whole memory pages and ensure timely freeing of pages
76502 + that may hold sensitive information.
76503 +
76504 + The tradeoff is performance impact, on a single CPU system kernel
76505 + compilation sees a 3% slowdown, other systems and workloads may vary
76506 + and you are advised to test this feature on your expected workload
76507 + before deploying it.
76508 +
76509 + Note that this feature does not protect data stored in live pages,
76510 + e.g., process memory swapped to disk may stay there for a long time.
76511 +
76512 +config PAX_MEMORY_STACKLEAK
76513 + bool "Sanitize kernel stack"
76514 + depends on X86
76515 + help
76516 + By saying Y here the kernel will erase the kernel stack before it
76517 + returns from a system call. This in turn reduces the information
76518 + that a kernel stack leak bug can reveal.
76519 +
76520 + Note that such a bug can still leak information that was put on
76521 + the stack by the current system call (the one eventually triggering
76522 + the bug) but traces of earlier system calls on the kernel stack
76523 + cannot leak anymore.
76524 +
76525 + The tradeoff is performance impact: on a single CPU system kernel
76526 + compilation sees a 1% slowdown, other systems and workloads may vary
76527 + and you are advised to test this feature on your expected workload
76528 + before deploying it.
76529 +
76530 + Note: full support for this feature requires gcc with plugin support
76531 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
76532 + versions means that functions with large enough stack frames may
76533 + leave uninitialized memory behind that may be exposed to a later
76534 + syscall leaking the stack.
76535 +
76536 +config PAX_MEMORY_UDEREF
76537 + bool "Prevent invalid userland pointer dereference"
76538 + depends on X86 && !UML_X86 && !XEN
76539 + select PAX_PER_CPU_PGD if X86_64
76540 + help
76541 + By saying Y here the kernel will be prevented from dereferencing
76542 + userland pointers in contexts where the kernel expects only kernel
76543 + pointers. This is both a useful runtime debugging feature and a
76544 + security measure that prevents exploiting a class of kernel bugs.
76545 +
76546 + The tradeoff is that some virtualization solutions may experience
76547 + a huge slowdown and therefore you should not enable this feature
76548 + for kernels meant to run in such environments. Whether a given VM
76549 + solution is affected or not is best determined by simply trying it
76550 + out, the performance impact will be obvious right on boot as this
76551 + mechanism engages from very early on. A good rule of thumb is that
76552 + VMs running on CPUs without hardware virtualization support (i.e.,
76553 + the majority of IA-32 CPUs) will likely experience the slowdown.
76554 +
76555 +config PAX_REFCOUNT
76556 + bool "Prevent various kernel object reference counter overflows"
76557 + depends on GRKERNSEC && (X86 || SPARC64)
76558 + help
76559 + By saying Y here the kernel will detect and prevent overflowing
76560 + various (but not all) kinds of object reference counters. Such
76561 + overflows can normally occur due to bugs only and are often, if
76562 + not always, exploitable.
76563 +
76564 + The tradeoff is that data structures protected by an overflowed
76565 + refcount will never be freed and therefore will leak memory. Note
76566 + that this leak also happens even without this protection but in
76567 + that case the overflow can eventually trigger the freeing of the
76568 + data structure while it is still being used elsewhere, resulting
76569 + in the exploitable situation that this feature prevents.
76570 +
76571 + Since this has a negligible performance impact, you should enable
76572 + this feature.
76573 +
76574 +config PAX_USERCOPY
76575 + bool "Harden heap object copies between kernel and userland"
76576 + depends on X86 || PPC || SPARC || ARM
76577 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
76578 + help
76579 + By saying Y here the kernel will enforce the size of heap objects
76580 + when they are copied in either direction between the kernel and
76581 + userland, even if only a part of the heap object is copied.
76582 +
76583 + Specifically, this checking prevents information leaking from the
76584 + kernel heap during kernel to userland copies (if the kernel heap
76585 + object is otherwise fully initialized) and prevents kernel heap
76586 + overflows during userland to kernel copies.
76587 +
76588 + Note that the current implementation provides the strictest bounds
76589 + checks for the SLUB allocator.
76590 +
76591 + Enabling this option also enables per-slab cache protection against
76592 + data in a given cache being copied into/out of via userland
76593 + accessors. Though the whitelist of regions will be reduced over
76594 + time, it notably protects important data structures like task structs.
76595 +
76596 + If frame pointers are enabled on x86, this option will also restrict
76597 + copies into and out of the kernel stack to local variables within a
76598 + single frame.
76599 +
76600 + Since this has a negligible performance impact, you should enable
76601 + this feature.
76602 +
76603 +endmenu
76604 +
76605 +endmenu
76606 +
76607 config KEYS
76608 bool "Enable access key retention support"
76609 help
76610 @@ -169,7 +790,7 @@ config INTEL_TXT
76611 config LSM_MMAP_MIN_ADDR
76612 int "Low address space for LSM to protect from user allocation"
76613 depends on SECURITY && SECURITY_SELINUX
76614 - default 32768 if ARM
76615 + default 32768 if ALPHA || ARM || PARISC || SPARC32
76616 default 65536
76617 help
76618 This is the portion of low virtual memory which should be protected
76619 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
76620 index 3783202..1852837 100644
76621 --- a/security/apparmor/lsm.c
76622 +++ b/security/apparmor/lsm.c
76623 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
76624 return error;
76625 }
76626
76627 -static struct security_operations apparmor_ops = {
76628 +static struct security_operations apparmor_ops __read_only = {
76629 .name = "apparmor",
76630
76631 .ptrace_access_check = apparmor_ptrace_access_check,
76632 diff --git a/security/commoncap.c b/security/commoncap.c
76633 index ee4f848..a320c64 100644
76634 --- a/security/commoncap.c
76635 +++ b/security/commoncap.c
76636 @@ -28,6 +28,7 @@
76637 #include <linux/prctl.h>
76638 #include <linux/securebits.h>
76639 #include <linux/user_namespace.h>
76640 +#include <net/sock.h>
76641
76642 /*
76643 * If a non-root user executes a setuid-root binary in
76644 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
76645
76646 int cap_netlink_recv(struct sk_buff *skb, int cap)
76647 {
76648 - if (!cap_raised(current_cap(), cap))
76649 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
76650 return -EPERM;
76651 return 0;
76652 }
76653 @@ -579,6 +580,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
76654 {
76655 const struct cred *cred = current_cred();
76656
76657 + if (gr_acl_enable_at_secure())
76658 + return 1;
76659 +
76660 if (cred->uid != 0) {
76661 if (bprm->cap_effective)
76662 return 1;
76663 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
76664 index 3ccf7ac..d73ad64 100644
76665 --- a/security/integrity/ima/ima.h
76666 +++ b/security/integrity/ima/ima.h
76667 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
76668 extern spinlock_t ima_queue_lock;
76669
76670 struct ima_h_table {
76671 - atomic_long_t len; /* number of stored measurements in the list */
76672 - atomic_long_t violations;
76673 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
76674 + atomic_long_unchecked_t violations;
76675 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
76676 };
76677 extern struct ima_h_table ima_htable;
76678 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
76679 index 88a2788..581ab92 100644
76680 --- a/security/integrity/ima/ima_api.c
76681 +++ b/security/integrity/ima/ima_api.c
76682 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
76683 int result;
76684
76685 /* can overflow, only indicator */
76686 - atomic_long_inc(&ima_htable.violations);
76687 + atomic_long_inc_unchecked(&ima_htable.violations);
76688
76689 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
76690 if (!entry) {
76691 diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c
76692 index c5c5a72..2ad942f 100644
76693 --- a/security/integrity/ima/ima_audit.c
76694 +++ b/security/integrity/ima/ima_audit.c
76695 @@ -56,9 +56,11 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
76696 audit_log_format(ab, " name=");
76697 audit_log_untrustedstring(ab, fname);
76698 }
76699 - if (inode)
76700 - audit_log_format(ab, " dev=%s ino=%lu",
76701 - inode->i_sb->s_id, inode->i_ino);
76702 + if (inode) {
76703 + audit_log_format(ab, " dev=");
76704 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
76705 + audit_log_format(ab, " ino=%lu", inode->i_ino);
76706 + }
76707 audit_log_format(ab, " res=%d", !result ? 0 : 1);
76708 audit_log_end(ab);
76709 }
76710 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
76711 index e1aa2b4..52027bf 100644
76712 --- a/security/integrity/ima/ima_fs.c
76713 +++ b/security/integrity/ima/ima_fs.c
76714 @@ -28,12 +28,12 @@
76715 static int valid_policy = 1;
76716 #define TMPBUFLEN 12
76717 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
76718 - loff_t *ppos, atomic_long_t *val)
76719 + loff_t *ppos, atomic_long_unchecked_t *val)
76720 {
76721 char tmpbuf[TMPBUFLEN];
76722 ssize_t len;
76723
76724 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
76725 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
76726 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
76727 }
76728
76729 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
76730 index 55a6271..ad829c3 100644
76731 --- a/security/integrity/ima/ima_queue.c
76732 +++ b/security/integrity/ima/ima_queue.c
76733 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
76734 INIT_LIST_HEAD(&qe->later);
76735 list_add_tail_rcu(&qe->later, &ima_measurements);
76736
76737 - atomic_long_inc(&ima_htable.len);
76738 + atomic_long_inc_unchecked(&ima_htable.len);
76739 key = ima_hash_key(entry->digest);
76740 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
76741 return 0;
76742 diff --git a/security/keys/compat.c b/security/keys/compat.c
76743 index 4c48e13..7abdac9 100644
76744 --- a/security/keys/compat.c
76745 +++ b/security/keys/compat.c
76746 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
76747 if (ret == 0)
76748 goto no_payload_free;
76749
76750 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
76751 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
76752
76753 if (iov != iovstack)
76754 kfree(iov);
76755 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
76756 index 0b3f5d7..892c8a6 100644
76757 --- a/security/keys/keyctl.c
76758 +++ b/security/keys/keyctl.c
76759 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
76760 /*
76761 * Copy the iovec data from userspace
76762 */
76763 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
76764 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
76765 unsigned ioc)
76766 {
76767 for (; ioc > 0; ioc--) {
76768 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
76769 * If successful, 0 will be returned.
76770 */
76771 long keyctl_instantiate_key_common(key_serial_t id,
76772 - const struct iovec *payload_iov,
76773 + const struct iovec __user *payload_iov,
76774 unsigned ioc,
76775 size_t plen,
76776 key_serial_t ringid)
76777 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
76778 [0].iov_len = plen
76779 };
76780
76781 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
76782 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
76783 }
76784
76785 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
76786 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
76787 if (ret == 0)
76788 goto no_payload_free;
76789
76790 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
76791 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
76792
76793 if (iov != iovstack)
76794 kfree(iov);
76795 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
76796 index 37a7f3b..86dc19f 100644
76797 --- a/security/keys/keyring.c
76798 +++ b/security/keys/keyring.c
76799 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
76800 ret = -EFAULT;
76801
76802 for (loop = 0; loop < klist->nkeys; loop++) {
76803 + key_serial_t serial;
76804 key = klist->keys[loop];
76805 + serial = key->serial;
76806
76807 tmp = sizeof(key_serial_t);
76808 if (tmp > buflen)
76809 tmp = buflen;
76810
76811 - if (copy_to_user(buffer,
76812 - &key->serial,
76813 - tmp) != 0)
76814 + if (copy_to_user(buffer, &serial, tmp))
76815 goto error;
76816
76817 buflen -= tmp;
76818 diff --git a/security/lsm_audit.c b/security/lsm_audit.c
76819 index 893af8a..ba9237c 100644
76820 --- a/security/lsm_audit.c
76821 +++ b/security/lsm_audit.c
76822 @@ -234,10 +234,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
76823 audit_log_d_path(ab, "path=", &a->u.path);
76824
76825 inode = a->u.path.dentry->d_inode;
76826 - if (inode)
76827 - audit_log_format(ab, " dev=%s ino=%lu",
76828 - inode->i_sb->s_id,
76829 - inode->i_ino);
76830 + if (inode) {
76831 + audit_log_format(ab, " dev=");
76832 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
76833 + audit_log_format(ab, " ino=%lu", inode->i_ino);
76834 + }
76835 break;
76836 }
76837 case LSM_AUDIT_DATA_DENTRY: {
76838 @@ -247,10 +248,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
76839 audit_log_untrustedstring(ab, a->u.dentry->d_name.name);
76840
76841 inode = a->u.dentry->d_inode;
76842 - if (inode)
76843 - audit_log_format(ab, " dev=%s ino=%lu",
76844 - inode->i_sb->s_id,
76845 - inode->i_ino);
76846 + if (inode) {
76847 + audit_log_format(ab, " dev=");
76848 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
76849 + audit_log_format(ab, " ino=%lu", inode->i_ino);
76850 + }
76851 break;
76852 }
76853 case LSM_AUDIT_DATA_INODE: {
76854 @@ -265,8 +267,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
76855 dentry->d_name.name);
76856 dput(dentry);
76857 }
76858 - audit_log_format(ab, " dev=%s ino=%lu", inode->i_sb->s_id,
76859 - inode->i_ino);
76860 + audit_log_format(ab, " dev=");
76861 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
76862 + audit_log_format(ab, " ino=%lu", inode->i_ino);
76863 break;
76864 }
76865 case LSM_AUDIT_DATA_TASK:
76866 diff --git a/security/min_addr.c b/security/min_addr.c
76867 index f728728..6457a0c 100644
76868 --- a/security/min_addr.c
76869 +++ b/security/min_addr.c
76870 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
76871 */
76872 static void update_mmap_min_addr(void)
76873 {
76874 +#ifndef SPARC
76875 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
76876 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
76877 mmap_min_addr = dac_mmap_min_addr;
76878 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
76879 #else
76880 mmap_min_addr = dac_mmap_min_addr;
76881 #endif
76882 +#endif
76883 }
76884
76885 /*
76886 diff --git a/security/security.c b/security/security.c
76887 index e2f684a..8d62ef5 100644
76888 --- a/security/security.c
76889 +++ b/security/security.c
76890 @@ -26,8 +26,8 @@
76891 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
76892 CONFIG_DEFAULT_SECURITY;
76893
76894 -static struct security_operations *security_ops;
76895 -static struct security_operations default_security_ops = {
76896 +static struct security_operations *security_ops __read_only;
76897 +static struct security_operations default_security_ops __read_only = {
76898 .name = "default",
76899 };
76900
76901 @@ -68,7 +68,9 @@ int __init security_init(void)
76902
76903 void reset_security_ops(void)
76904 {
76905 + pax_open_kernel();
76906 security_ops = &default_security_ops;
76907 + pax_close_kernel();
76908 }
76909
76910 /* Save user chosen LSM */
76911 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
76912 index 1126c10..effb32b 100644
76913 --- a/security/selinux/hooks.c
76914 +++ b/security/selinux/hooks.c
76915 @@ -94,8 +94,6 @@
76916
76917 #define NUM_SEL_MNT_OPTS 5
76918
76919 -extern struct security_operations *security_ops;
76920 -
76921 /* SECMARK reference count */
76922 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
76923
76924 @@ -5449,7 +5447,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
76925
76926 #endif
76927
76928 -static struct security_operations selinux_ops = {
76929 +static struct security_operations selinux_ops __read_only = {
76930 .name = "selinux",
76931
76932 .ptrace_access_check = selinux_ptrace_access_check,
76933 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
76934 index b43813c..74be837 100644
76935 --- a/security/selinux/include/xfrm.h
76936 +++ b/security/selinux/include/xfrm.h
76937 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
76938
76939 static inline void selinux_xfrm_notify_policyload(void)
76940 {
76941 - atomic_inc(&flow_cache_genid);
76942 + atomic_inc_unchecked(&flow_cache_genid);
76943 }
76944 #else
76945 static inline int selinux_xfrm_enabled(void)
76946 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
76947 index 7db62b4..ee4d949 100644
76948 --- a/security/smack/smack_lsm.c
76949 +++ b/security/smack/smack_lsm.c
76950 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
76951 return 0;
76952 }
76953
76954 -struct security_operations smack_ops = {
76955 +struct security_operations smack_ops __read_only = {
76956 .name = "smack",
76957
76958 .ptrace_access_check = smack_ptrace_access_check,
76959 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
76960 index 4b327b6..646c57a 100644
76961 --- a/security/tomoyo/tomoyo.c
76962 +++ b/security/tomoyo/tomoyo.c
76963 @@ -504,7 +504,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
76964 * tomoyo_security_ops is a "struct security_operations" which is used for
76965 * registering TOMOYO.
76966 */
76967 -static struct security_operations tomoyo_security_ops = {
76968 +static struct security_operations tomoyo_security_ops __read_only = {
76969 .name = "tomoyo",
76970 .cred_alloc_blank = tomoyo_cred_alloc_blank,
76971 .cred_prepare = tomoyo_cred_prepare,
76972 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
76973 index 762af68..7103453 100644
76974 --- a/sound/aoa/codecs/onyx.c
76975 +++ b/sound/aoa/codecs/onyx.c
76976 @@ -54,7 +54,7 @@ struct onyx {
76977 spdif_locked:1,
76978 analog_locked:1,
76979 original_mute:2;
76980 - int open_count;
76981 + local_t open_count;
76982 struct codec_info *codec_info;
76983
76984 /* mutex serializes concurrent access to the device
76985 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
76986 struct onyx *onyx = cii->codec_data;
76987
76988 mutex_lock(&onyx->mutex);
76989 - onyx->open_count++;
76990 + local_inc(&onyx->open_count);
76991 mutex_unlock(&onyx->mutex);
76992
76993 return 0;
76994 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
76995 struct onyx *onyx = cii->codec_data;
76996
76997 mutex_lock(&onyx->mutex);
76998 - onyx->open_count--;
76999 - if (!onyx->open_count)
77000 + if (local_dec_and_test(&onyx->open_count))
77001 onyx->spdif_locked = onyx->analog_locked = 0;
77002 mutex_unlock(&onyx->mutex);
77003
77004 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
77005 index ffd2025..df062c9 100644
77006 --- a/sound/aoa/codecs/onyx.h
77007 +++ b/sound/aoa/codecs/onyx.h
77008 @@ -11,6 +11,7 @@
77009 #include <linux/i2c.h>
77010 #include <asm/pmac_low_i2c.h>
77011 #include <asm/prom.h>
77012 +#include <asm/local.h>
77013
77014 /* PCM3052 register definitions */
77015
77016 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
77017 index 3cc4b86..af0a951 100644
77018 --- a/sound/core/oss/pcm_oss.c
77019 +++ b/sound/core/oss/pcm_oss.c
77020 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
77021 if (in_kernel) {
77022 mm_segment_t fs;
77023 fs = snd_enter_user();
77024 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
77025 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
77026 snd_leave_user(fs);
77027 } else {
77028 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
77029 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
77030 }
77031 if (ret != -EPIPE && ret != -ESTRPIPE)
77032 break;
77033 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
77034 if (in_kernel) {
77035 mm_segment_t fs;
77036 fs = snd_enter_user();
77037 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
77038 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
77039 snd_leave_user(fs);
77040 } else {
77041 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
77042 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
77043 }
77044 if (ret == -EPIPE) {
77045 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
77046 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
77047 struct snd_pcm_plugin_channel *channels;
77048 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
77049 if (!in_kernel) {
77050 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
77051 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
77052 return -EFAULT;
77053 buf = runtime->oss.buffer;
77054 }
77055 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
77056 }
77057 } else {
77058 tmp = snd_pcm_oss_write2(substream,
77059 - (const char __force *)buf,
77060 + (const char __force_kernel *)buf,
77061 runtime->oss.period_bytes, 0);
77062 if (tmp <= 0)
77063 goto err;
77064 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
77065 struct snd_pcm_runtime *runtime = substream->runtime;
77066 snd_pcm_sframes_t frames, frames1;
77067 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
77068 - char __user *final_dst = (char __force __user *)buf;
77069 + char __user *final_dst = (char __force_user *)buf;
77070 if (runtime->oss.plugin_first) {
77071 struct snd_pcm_plugin_channel *channels;
77072 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
77073 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
77074 xfer += tmp;
77075 runtime->oss.buffer_used -= tmp;
77076 } else {
77077 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
77078 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
77079 runtime->oss.period_bytes, 0);
77080 if (tmp <= 0)
77081 goto err;
77082 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
77083 size1);
77084 size1 /= runtime->channels; /* frames */
77085 fs = snd_enter_user();
77086 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
77087 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
77088 snd_leave_user(fs);
77089 }
77090 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
77091 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
77092 index 91cdf94..4085161 100644
77093 --- a/sound/core/pcm_compat.c
77094 +++ b/sound/core/pcm_compat.c
77095 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
77096 int err;
77097
77098 fs = snd_enter_user();
77099 - err = snd_pcm_delay(substream, &delay);
77100 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
77101 snd_leave_user(fs);
77102 if (err < 0)
77103 return err;
77104 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
77105 index 25ed9fe..24c46e9 100644
77106 --- a/sound/core/pcm_native.c
77107 +++ b/sound/core/pcm_native.c
77108 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
77109 switch (substream->stream) {
77110 case SNDRV_PCM_STREAM_PLAYBACK:
77111 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
77112 - (void __user *)arg);
77113 + (void __force_user *)arg);
77114 break;
77115 case SNDRV_PCM_STREAM_CAPTURE:
77116 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
77117 - (void __user *)arg);
77118 + (void __force_user *)arg);
77119 break;
77120 default:
77121 result = -EINVAL;
77122 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
77123 index 5cf8d65..912a79c 100644
77124 --- a/sound/core/seq/seq_device.c
77125 +++ b/sound/core/seq/seq_device.c
77126 @@ -64,7 +64,7 @@ struct ops_list {
77127 int argsize; /* argument size */
77128
77129 /* operators */
77130 - struct snd_seq_dev_ops ops;
77131 + struct snd_seq_dev_ops *ops;
77132
77133 /* registred devices */
77134 struct list_head dev_list; /* list of devices */
77135 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
77136
77137 mutex_lock(&ops->reg_mutex);
77138 /* copy driver operators */
77139 - ops->ops = *entry;
77140 + ops->ops = entry;
77141 ops->driver |= DRIVER_LOADED;
77142 ops->argsize = argsize;
77143
77144 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
77145 dev->name, ops->id, ops->argsize, dev->argsize);
77146 return -EINVAL;
77147 }
77148 - if (ops->ops.init_device(dev) >= 0) {
77149 + if (ops->ops->init_device(dev) >= 0) {
77150 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
77151 ops->num_init_devices++;
77152 } else {
77153 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
77154 dev->name, ops->id, ops->argsize, dev->argsize);
77155 return -EINVAL;
77156 }
77157 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
77158 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
77159 dev->status = SNDRV_SEQ_DEVICE_FREE;
77160 dev->driver_data = NULL;
77161 ops->num_init_devices--;
77162 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
77163 index f24bf9a..1f7b67c 100644
77164 --- a/sound/drivers/mts64.c
77165 +++ b/sound/drivers/mts64.c
77166 @@ -29,6 +29,7 @@
77167 #include <sound/initval.h>
77168 #include <sound/rawmidi.h>
77169 #include <sound/control.h>
77170 +#include <asm/local.h>
77171
77172 #define CARD_NAME "Miditerminal 4140"
77173 #define DRIVER_NAME "MTS64"
77174 @@ -67,7 +68,7 @@ struct mts64 {
77175 struct pardevice *pardev;
77176 int pardev_claimed;
77177
77178 - int open_count;
77179 + local_t open_count;
77180 int current_midi_output_port;
77181 int current_midi_input_port;
77182 u8 mode[MTS64_NUM_INPUT_PORTS];
77183 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
77184 {
77185 struct mts64 *mts = substream->rmidi->private_data;
77186
77187 - if (mts->open_count == 0) {
77188 + if (local_read(&mts->open_count) == 0) {
77189 /* We don't need a spinlock here, because this is just called
77190 if the device has not been opened before.
77191 So there aren't any IRQs from the device */
77192 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
77193
77194 msleep(50);
77195 }
77196 - ++(mts->open_count);
77197 + local_inc(&mts->open_count);
77198
77199 return 0;
77200 }
77201 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
77202 struct mts64 *mts = substream->rmidi->private_data;
77203 unsigned long flags;
77204
77205 - --(mts->open_count);
77206 - if (mts->open_count == 0) {
77207 + if (local_dec_return(&mts->open_count) == 0) {
77208 /* We need the spinlock_irqsave here because we can still
77209 have IRQs at this point */
77210 spin_lock_irqsave(&mts->lock, flags);
77211 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
77212
77213 msleep(500);
77214
77215 - } else if (mts->open_count < 0)
77216 - mts->open_count = 0;
77217 + } else if (local_read(&mts->open_count) < 0)
77218 + local_set(&mts->open_count, 0);
77219
77220 return 0;
77221 }
77222 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
77223 index b953fb4..1999c01 100644
77224 --- a/sound/drivers/opl4/opl4_lib.c
77225 +++ b/sound/drivers/opl4/opl4_lib.c
77226 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
77227 MODULE_DESCRIPTION("OPL4 driver");
77228 MODULE_LICENSE("GPL");
77229
77230 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
77231 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
77232 {
77233 int timeout = 10;
77234 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
77235 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
77236 index f664823..590c745 100644
77237 --- a/sound/drivers/portman2x4.c
77238 +++ b/sound/drivers/portman2x4.c
77239 @@ -48,6 +48,7 @@
77240 #include <sound/initval.h>
77241 #include <sound/rawmidi.h>
77242 #include <sound/control.h>
77243 +#include <asm/local.h>
77244
77245 #define CARD_NAME "Portman 2x4"
77246 #define DRIVER_NAME "portman"
77247 @@ -85,7 +86,7 @@ struct portman {
77248 struct pardevice *pardev;
77249 int pardev_claimed;
77250
77251 - int open_count;
77252 + local_t open_count;
77253 int mode[PORTMAN_NUM_INPUT_PORTS];
77254 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
77255 };
77256 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
77257 index 87657dd..a8268d4 100644
77258 --- a/sound/firewire/amdtp.c
77259 +++ b/sound/firewire/amdtp.c
77260 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
77261 ptr = s->pcm_buffer_pointer + data_blocks;
77262 if (ptr >= pcm->runtime->buffer_size)
77263 ptr -= pcm->runtime->buffer_size;
77264 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
77265 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
77266
77267 s->pcm_period_pointer += data_blocks;
77268 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
77269 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
77270 */
77271 void amdtp_out_stream_update(struct amdtp_out_stream *s)
77272 {
77273 - ACCESS_ONCE(s->source_node_id_field) =
77274 + ACCESS_ONCE_RW(s->source_node_id_field) =
77275 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
77276 }
77277 EXPORT_SYMBOL(amdtp_out_stream_update);
77278 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
77279 index 537a9cb..8e8c8e9 100644
77280 --- a/sound/firewire/amdtp.h
77281 +++ b/sound/firewire/amdtp.h
77282 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
77283 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
77284 struct snd_pcm_substream *pcm)
77285 {
77286 - ACCESS_ONCE(s->pcm) = pcm;
77287 + ACCESS_ONCE_RW(s->pcm) = pcm;
77288 }
77289
77290 /**
77291 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
77292 index cd094ec..eca1277 100644
77293 --- a/sound/firewire/isight.c
77294 +++ b/sound/firewire/isight.c
77295 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
77296 ptr += count;
77297 if (ptr >= runtime->buffer_size)
77298 ptr -= runtime->buffer_size;
77299 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
77300 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
77301
77302 isight->period_counter += count;
77303 if (isight->period_counter >= runtime->period_size) {
77304 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
77305 if (err < 0)
77306 return err;
77307
77308 - ACCESS_ONCE(isight->pcm_active) = true;
77309 + ACCESS_ONCE_RW(isight->pcm_active) = true;
77310
77311 return 0;
77312 }
77313 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
77314 {
77315 struct isight *isight = substream->private_data;
77316
77317 - ACCESS_ONCE(isight->pcm_active) = false;
77318 + ACCESS_ONCE_RW(isight->pcm_active) = false;
77319
77320 mutex_lock(&isight->mutex);
77321 isight_stop_streaming(isight);
77322 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
77323
77324 switch (cmd) {
77325 case SNDRV_PCM_TRIGGER_START:
77326 - ACCESS_ONCE(isight->pcm_running) = true;
77327 + ACCESS_ONCE_RW(isight->pcm_running) = true;
77328 break;
77329 case SNDRV_PCM_TRIGGER_STOP:
77330 - ACCESS_ONCE(isight->pcm_running) = false;
77331 + ACCESS_ONCE_RW(isight->pcm_running) = false;
77332 break;
77333 default:
77334 return -EINVAL;
77335 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
77336 index c94578d..0794ac1 100644
77337 --- a/sound/isa/cmi8330.c
77338 +++ b/sound/isa/cmi8330.c
77339 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
77340
77341 struct snd_pcm *pcm;
77342 struct snd_cmi8330_stream {
77343 - struct snd_pcm_ops ops;
77344 + snd_pcm_ops_no_const ops;
77345 snd_pcm_open_callback_t open;
77346 void *private_data; /* sb or wss */
77347 } streams[2];
77348 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
77349 index 733b014..56ce96f 100644
77350 --- a/sound/oss/sb_audio.c
77351 +++ b/sound/oss/sb_audio.c
77352 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
77353 buf16 = (signed short *)(localbuf + localoffs);
77354 while (c)
77355 {
77356 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
77357 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
77358 if (copy_from_user(lbuf8,
77359 userbuf+useroffs + p,
77360 locallen))
77361 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
77362 index 09d4648..cf234c7 100644
77363 --- a/sound/oss/swarm_cs4297a.c
77364 +++ b/sound/oss/swarm_cs4297a.c
77365 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
77366 {
77367 struct cs4297a_state *s;
77368 u32 pwr, id;
77369 - mm_segment_t fs;
77370 int rval;
77371 #ifndef CONFIG_BCM_CS4297A_CSWARM
77372 u64 cfg;
77373 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
77374 if (!rval) {
77375 char *sb1250_duart_present;
77376
77377 +#if 0
77378 + mm_segment_t fs;
77379 fs = get_fs();
77380 set_fs(KERNEL_DS);
77381 -#if 0
77382 val = SOUND_MASK_LINE;
77383 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
77384 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
77385 val = initvol[i].vol;
77386 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
77387 }
77388 + set_fs(fs);
77389 // cs4297a_write_ac97(s, 0x18, 0x0808);
77390 #else
77391 // cs4297a_write_ac97(s, 0x5e, 0x180);
77392 cs4297a_write_ac97(s, 0x02, 0x0808);
77393 cs4297a_write_ac97(s, 0x18, 0x0808);
77394 #endif
77395 - set_fs(fs);
77396
77397 list_add(&s->list, &cs4297a_devs);
77398
77399 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
77400 index 5644711..a2aebc1 100644
77401 --- a/sound/pci/hda/hda_codec.h
77402 +++ b/sound/pci/hda/hda_codec.h
77403 @@ -611,7 +611,7 @@ struct hda_bus_ops {
77404 /* notify power-up/down from codec to controller */
77405 void (*pm_notify)(struct hda_bus *bus);
77406 #endif
77407 -};
77408 +} __no_const;
77409
77410 /* template to pass to the bus constructor */
77411 struct hda_bus_template {
77412 @@ -713,6 +713,7 @@ struct hda_codec_ops {
77413 #endif
77414 void (*reboot_notify)(struct hda_codec *codec);
77415 };
77416 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
77417
77418 /* record for amp information cache */
77419 struct hda_cache_head {
77420 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
77421 struct snd_pcm_substream *substream);
77422 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
77423 struct snd_pcm_substream *substream);
77424 -};
77425 +} __no_const;
77426
77427 /* PCM information for each substream */
77428 struct hda_pcm_stream {
77429 @@ -801,7 +802,7 @@ struct hda_codec {
77430 const char *modelname; /* model name for preset */
77431
77432 /* set by patch */
77433 - struct hda_codec_ops patch_ops;
77434 + hda_codec_ops_no_const patch_ops;
77435
77436 /* PCM to create, set by patch_ops.build_pcms callback */
77437 unsigned int num_pcms;
77438 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
77439 index 0da778a..bc38b84 100644
77440 --- a/sound/pci/ice1712/ice1712.h
77441 +++ b/sound/pci/ice1712/ice1712.h
77442 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
77443 unsigned int mask_flags; /* total mask bits */
77444 struct snd_akm4xxx_ops {
77445 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
77446 - } ops;
77447 + } __no_const ops;
77448 };
77449
77450 struct snd_ice1712_spdif {
77451 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
77452 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77453 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77454 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77455 - } ops;
77456 + } __no_const ops;
77457 };
77458
77459
77460 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
77461 index 03ee4e3..be86b46 100644
77462 --- a/sound/pci/ymfpci/ymfpci_main.c
77463 +++ b/sound/pci/ymfpci/ymfpci_main.c
77464 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
77465 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
77466 break;
77467 }
77468 - if (atomic_read(&chip->interrupt_sleep_count)) {
77469 - atomic_set(&chip->interrupt_sleep_count, 0);
77470 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
77471 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77472 wake_up(&chip->interrupt_sleep);
77473 }
77474 __end:
77475 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
77476 continue;
77477 init_waitqueue_entry(&wait, current);
77478 add_wait_queue(&chip->interrupt_sleep, &wait);
77479 - atomic_inc(&chip->interrupt_sleep_count);
77480 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
77481 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
77482 remove_wait_queue(&chip->interrupt_sleep, &wait);
77483 }
77484 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
77485 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
77486 spin_unlock(&chip->reg_lock);
77487
77488 - if (atomic_read(&chip->interrupt_sleep_count)) {
77489 - atomic_set(&chip->interrupt_sleep_count, 0);
77490 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
77491 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77492 wake_up(&chip->interrupt_sleep);
77493 }
77494 }
77495 @@ -2382,7 +2382,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
77496 spin_lock_init(&chip->reg_lock);
77497 spin_lock_init(&chip->voice_lock);
77498 init_waitqueue_head(&chip->interrupt_sleep);
77499 - atomic_set(&chip->interrupt_sleep_count, 0);
77500 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77501 chip->card = card;
77502 chip->pci = pci;
77503 chip->irq = -1;
77504 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
77505 index ee15337..e2187a6 100644
77506 --- a/sound/soc/soc-pcm.c
77507 +++ b/sound/soc/soc-pcm.c
77508 @@ -583,7 +583,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
77509 }
77510
77511 /* ASoC PCM operations */
77512 -static struct snd_pcm_ops soc_pcm_ops = {
77513 +static snd_pcm_ops_no_const soc_pcm_ops = {
77514 .open = soc_pcm_open,
77515 .close = soc_pcm_close,
77516 .hw_params = soc_pcm_hw_params,
77517 diff --git a/sound/usb/card.h b/sound/usb/card.h
77518 index a39edcc..1014050 100644
77519 --- a/sound/usb/card.h
77520 +++ b/sound/usb/card.h
77521 @@ -44,6 +44,7 @@ struct snd_urb_ops {
77522 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
77523 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
77524 };
77525 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
77526
77527 struct snd_usb_substream {
77528 struct snd_usb_stream *stream;
77529 @@ -93,7 +94,7 @@ struct snd_usb_substream {
77530 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
77531 spinlock_t lock;
77532
77533 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
77534 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
77535 int last_frame_number; /* stored frame number */
77536 int last_delay; /* stored delay */
77537 };
77538 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
77539 new file mode 100644
77540 index 0000000..b044b80
77541 --- /dev/null
77542 +++ b/tools/gcc/Makefile
77543 @@ -0,0 +1,21 @@
77544 +#CC := gcc
77545 +#PLUGIN_SOURCE_FILES := pax_plugin.c
77546 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
77547 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
77548 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W
77549 +
77550 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include
77551 +
77552 +hostlibs-y := constify_plugin.so
77553 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
77554 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
77555 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
77556 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
77557 +
77558 +always := $(hostlibs-y)
77559 +
77560 +constify_plugin-objs := constify_plugin.o
77561 +stackleak_plugin-objs := stackleak_plugin.o
77562 +kallocstat_plugin-objs := kallocstat_plugin.o
77563 +kernexec_plugin-objs := kernexec_plugin.o
77564 +checker_plugin-objs := checker_plugin.o
77565 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
77566 new file mode 100644
77567 index 0000000..d41b5af
77568 --- /dev/null
77569 +++ b/tools/gcc/checker_plugin.c
77570 @@ -0,0 +1,171 @@
77571 +/*
77572 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
77573 + * Licensed under the GPL v2
77574 + *
77575 + * Note: the choice of the license means that the compilation process is
77576 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
77577 + * but for the kernel it doesn't matter since it doesn't link against
77578 + * any of the gcc libraries
77579 + *
77580 + * gcc plugin to implement various sparse (source code checker) features
77581 + *
77582 + * TODO:
77583 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
77584 + *
77585 + * BUGS:
77586 + * - none known
77587 + */
77588 +#include "gcc-plugin.h"
77589 +#include "config.h"
77590 +#include "system.h"
77591 +#include "coretypes.h"
77592 +#include "tree.h"
77593 +#include "tree-pass.h"
77594 +#include "flags.h"
77595 +#include "intl.h"
77596 +#include "toplev.h"
77597 +#include "plugin.h"
77598 +//#include "expr.h" where are you...
77599 +#include "diagnostic.h"
77600 +#include "plugin-version.h"
77601 +#include "tm.h"
77602 +#include "function.h"
77603 +#include "basic-block.h"
77604 +#include "gimple.h"
77605 +#include "rtl.h"
77606 +#include "emit-rtl.h"
77607 +#include "tree-flow.h"
77608 +#include "target.h"
77609 +
77610 +extern void c_register_addr_space (const char *str, addr_space_t as);
77611 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
77612 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
77613 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
77614 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
77615 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
77616 +
77617 +extern void print_gimple_stmt(FILE *, gimple, int, int);
77618 +extern rtx emit_move_insn(rtx x, rtx y);
77619 +
77620 +int plugin_is_GPL_compatible;
77621 +
77622 +static struct plugin_info checker_plugin_info = {
77623 + .version = "201111150100",
77624 +};
77625 +
77626 +#define ADDR_SPACE_KERNEL 0
77627 +#define ADDR_SPACE_FORCE_KERNEL 1
77628 +#define ADDR_SPACE_USER 2
77629 +#define ADDR_SPACE_FORCE_USER 3
77630 +#define ADDR_SPACE_IOMEM 0
77631 +#define ADDR_SPACE_FORCE_IOMEM 0
77632 +#define ADDR_SPACE_PERCPU 0
77633 +#define ADDR_SPACE_FORCE_PERCPU 0
77634 +#define ADDR_SPACE_RCU 0
77635 +#define ADDR_SPACE_FORCE_RCU 0
77636 +
77637 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
77638 +{
77639 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
77640 +}
77641 +
77642 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
77643 +{
77644 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
77645 +}
77646 +
77647 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
77648 +{
77649 + return default_addr_space_valid_pointer_mode(mode, as);
77650 +}
77651 +
77652 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
77653 +{
77654 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
77655 +}
77656 +
77657 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
77658 +{
77659 + return default_addr_space_legitimize_address(x, oldx, mode, as);
77660 +}
77661 +
77662 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
77663 +{
77664 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
77665 + return true;
77666 +
77667 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
77668 + return true;
77669 +
77670 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
77671 + return true;
77672 +
77673 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
77674 + return true;
77675 +
77676 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
77677 + return true;
77678 +
77679 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
77680 + return true;
77681 +
77682 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
77683 + return true;
77684 +
77685 + return subset == superset;
77686 +}
77687 +
77688 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
77689 +{
77690 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
77691 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
77692 +
77693 + return op;
77694 +}
77695 +
77696 +static void register_checker_address_spaces(void *event_data, void *data)
77697 +{
77698 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
77699 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
77700 + c_register_addr_space("__user", ADDR_SPACE_USER);
77701 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
77702 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
77703 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
77704 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
77705 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
77706 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
77707 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
77708 +
77709 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
77710 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
77711 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
77712 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
77713 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
77714 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
77715 + targetm.addr_space.convert = checker_addr_space_convert;
77716 +}
77717 +
77718 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
77719 +{
77720 + const char * const plugin_name = plugin_info->base_name;
77721 + const int argc = plugin_info->argc;
77722 + const struct plugin_argument * const argv = plugin_info->argv;
77723 + int i;
77724 +
77725 + if (!plugin_default_version_check(version, &gcc_version)) {
77726 + error(G_("incompatible gcc/plugin versions"));
77727 + return 1;
77728 + }
77729 +
77730 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
77731 +
77732 + for (i = 0; i < argc; ++i)
77733 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
77734 +
77735 + if (TARGET_64BIT == 0)
77736 + return 0;
77737 +
77738 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
77739 +
77740 + return 0;
77741 +}
77742 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
77743 new file mode 100644
77744 index 0000000..704a564
77745 --- /dev/null
77746 +++ b/tools/gcc/constify_plugin.c
77747 @@ -0,0 +1,303 @@
77748 +/*
77749 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
77750 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
77751 + * Licensed under the GPL v2, or (at your option) v3
77752 + *
77753 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
77754 + *
77755 + * Homepage:
77756 + * http://www.grsecurity.net/~ephox/const_plugin/
77757 + *
77758 + * Usage:
77759 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
77760 + * $ gcc -fplugin=constify_plugin.so test.c -O2
77761 + */
77762 +
77763 +#include "gcc-plugin.h"
77764 +#include "config.h"
77765 +#include "system.h"
77766 +#include "coretypes.h"
77767 +#include "tree.h"
77768 +#include "tree-pass.h"
77769 +#include "flags.h"
77770 +#include "intl.h"
77771 +#include "toplev.h"
77772 +#include "plugin.h"
77773 +#include "diagnostic.h"
77774 +#include "plugin-version.h"
77775 +#include "tm.h"
77776 +#include "function.h"
77777 +#include "basic-block.h"
77778 +#include "gimple.h"
77779 +#include "rtl.h"
77780 +#include "emit-rtl.h"
77781 +#include "tree-flow.h"
77782 +
77783 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
77784 +
77785 +int plugin_is_GPL_compatible;
77786 +
77787 +static struct plugin_info const_plugin_info = {
77788 + .version = "201111150100",
77789 + .help = "no-constify\tturn off constification\n",
77790 +};
77791 +
77792 +static void constify_type(tree type);
77793 +static bool walk_struct(tree node);
77794 +
77795 +static tree deconstify_type(tree old_type)
77796 +{
77797 + tree new_type, field;
77798 +
77799 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
77800 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
77801 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
77802 + DECL_FIELD_CONTEXT(field) = new_type;
77803 + TYPE_READONLY(new_type) = 0;
77804 + C_TYPE_FIELDS_READONLY(new_type) = 0;
77805 + return new_type;
77806 +}
77807 +
77808 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
77809 +{
77810 + tree type;
77811 +
77812 + *no_add_attrs = true;
77813 + if (TREE_CODE(*node) == FUNCTION_DECL) {
77814 + error("%qE attribute does not apply to functions", name);
77815 + return NULL_TREE;
77816 + }
77817 +
77818 + if (TREE_CODE(*node) == VAR_DECL) {
77819 + error("%qE attribute does not apply to variables", name);
77820 + return NULL_TREE;
77821 + }
77822 +
77823 + if (TYPE_P(*node)) {
77824 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
77825 + *no_add_attrs = false;
77826 + else
77827 + error("%qE attribute applies to struct and union types only", name);
77828 + return NULL_TREE;
77829 + }
77830 +
77831 + type = TREE_TYPE(*node);
77832 +
77833 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
77834 + error("%qE attribute applies to struct and union types only", name);
77835 + return NULL_TREE;
77836 + }
77837 +
77838 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
77839 + error("%qE attribute is already applied to the type", name);
77840 + return NULL_TREE;
77841 + }
77842 +
77843 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
77844 + error("%qE attribute used on type that is not constified", name);
77845 + return NULL_TREE;
77846 + }
77847 +
77848 + if (TREE_CODE(*node) == TYPE_DECL) {
77849 + TREE_TYPE(*node) = deconstify_type(type);
77850 + TREE_READONLY(*node) = 0;
77851 + return NULL_TREE;
77852 + }
77853 +
77854 + return NULL_TREE;
77855 +}
77856 +
77857 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
77858 +{
77859 + *no_add_attrs = true;
77860 + if (!TYPE_P(*node)) {
77861 + error("%qE attribute applies to types only", name);
77862 + return NULL_TREE;
77863 + }
77864 +
77865 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
77866 + error("%qE attribute applies to struct and union types only", name);
77867 + return NULL_TREE;
77868 + }
77869 +
77870 + *no_add_attrs = false;
77871 + constify_type(*node);
77872 + return NULL_TREE;
77873 +}
77874 +
77875 +static struct attribute_spec no_const_attr = {
77876 + .name = "no_const",
77877 + .min_length = 0,
77878 + .max_length = 0,
77879 + .decl_required = false,
77880 + .type_required = false,
77881 + .function_type_required = false,
77882 + .handler = handle_no_const_attribute,
77883 +#if BUILDING_GCC_VERSION >= 4007
77884 + .affects_type_identity = true
77885 +#endif
77886 +};
77887 +
77888 +static struct attribute_spec do_const_attr = {
77889 + .name = "do_const",
77890 + .min_length = 0,
77891 + .max_length = 0,
77892 + .decl_required = false,
77893 + .type_required = false,
77894 + .function_type_required = false,
77895 + .handler = handle_do_const_attribute,
77896 +#if BUILDING_GCC_VERSION >= 4007
77897 + .affects_type_identity = true
77898 +#endif
77899 +};
77900 +
77901 +static void register_attributes(void *event_data, void *data)
77902 +{
77903 + register_attribute(&no_const_attr);
77904 + register_attribute(&do_const_attr);
77905 +}
77906 +
77907 +static void constify_type(tree type)
77908 +{
77909 + TYPE_READONLY(type) = 1;
77910 + C_TYPE_FIELDS_READONLY(type) = 1;
77911 +}
77912 +
77913 +static bool is_fptr(tree field)
77914 +{
77915 + tree ptr = TREE_TYPE(field);
77916 +
77917 + if (TREE_CODE(ptr) != POINTER_TYPE)
77918 + return false;
77919 +
77920 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
77921 +}
77922 +
77923 +static bool walk_struct(tree node)
77924 +{
77925 + tree field;
77926 +
77927 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
77928 + return false;
77929 +
77930 + if (TYPE_FIELDS(node) == NULL_TREE)
77931 + return false;
77932 +
77933 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
77934 + tree type = TREE_TYPE(field);
77935 + enum tree_code code = TREE_CODE(type);
77936 + if (code == RECORD_TYPE || code == UNION_TYPE) {
77937 + if (!(walk_struct(type)))
77938 + return false;
77939 + } else if (!is_fptr(field) && !TREE_READONLY(field))
77940 + return false;
77941 + }
77942 + return true;
77943 +}
77944 +
77945 +static void finish_type(void *event_data, void *data)
77946 +{
77947 + tree type = (tree)event_data;
77948 +
77949 + if (type == NULL_TREE)
77950 + return;
77951 +
77952 + if (TYPE_READONLY(type))
77953 + return;
77954 +
77955 + if (walk_struct(type))
77956 + constify_type(type);
77957 +}
77958 +
77959 +static unsigned int check_local_variables(void);
77960 +
77961 +struct gimple_opt_pass pass_local_variable = {
77962 + {
77963 + .type = GIMPLE_PASS,
77964 + .name = "check_local_variables",
77965 + .gate = NULL,
77966 + .execute = check_local_variables,
77967 + .sub = NULL,
77968 + .next = NULL,
77969 + .static_pass_number = 0,
77970 + .tv_id = TV_NONE,
77971 + .properties_required = 0,
77972 + .properties_provided = 0,
77973 + .properties_destroyed = 0,
77974 + .todo_flags_start = 0,
77975 + .todo_flags_finish = 0
77976 + }
77977 +};
77978 +
77979 +static unsigned int check_local_variables(void)
77980 +{
77981 + tree var;
77982 + referenced_var_iterator rvi;
77983 +
77984 +#if BUILDING_GCC_VERSION == 4005
77985 + FOR_EACH_REFERENCED_VAR(var, rvi) {
77986 +#else
77987 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
77988 +#endif
77989 + tree type = TREE_TYPE(var);
77990 +
77991 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
77992 + continue;
77993 +
77994 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
77995 + continue;
77996 +
77997 + if (!TYPE_READONLY(type))
77998 + continue;
77999 +
78000 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
78001 +// continue;
78002 +
78003 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
78004 +// continue;
78005 +
78006 + if (walk_struct(type)) {
78007 + error("constified variable %qE cannot be local", var);
78008 + return 1;
78009 + }
78010 + }
78011 + return 0;
78012 +}
78013 +
78014 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78015 +{
78016 + const char * const plugin_name = plugin_info->base_name;
78017 + const int argc = plugin_info->argc;
78018 + const struct plugin_argument * const argv = plugin_info->argv;
78019 + int i;
78020 + bool constify = true;
78021 +
78022 + struct register_pass_info local_variable_pass_info = {
78023 + .pass = &pass_local_variable.pass,
78024 + .reference_pass_name = "*referenced_vars",
78025 + .ref_pass_instance_number = 0,
78026 + .pos_op = PASS_POS_INSERT_AFTER
78027 + };
78028 +
78029 + if (!plugin_default_version_check(version, &gcc_version)) {
78030 + error(G_("incompatible gcc/plugin versions"));
78031 + return 1;
78032 + }
78033 +
78034 + for (i = 0; i < argc; ++i) {
78035 + if (!(strcmp(argv[i].key, "no-constify"))) {
78036 + constify = false;
78037 + continue;
78038 + }
78039 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78040 + }
78041 +
78042 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
78043 + if (constify) {
78044 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
78045 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
78046 + }
78047 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
78048 +
78049 + return 0;
78050 +}
78051 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
78052 new file mode 100644
78053 index 0000000..a5eabce
78054 --- /dev/null
78055 +++ b/tools/gcc/kallocstat_plugin.c
78056 @@ -0,0 +1,167 @@
78057 +/*
78058 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78059 + * Licensed under the GPL v2
78060 + *
78061 + * Note: the choice of the license means that the compilation process is
78062 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78063 + * but for the kernel it doesn't matter since it doesn't link against
78064 + * any of the gcc libraries
78065 + *
78066 + * gcc plugin to find the distribution of k*alloc sizes
78067 + *
78068 + * TODO:
78069 + *
78070 + * BUGS:
78071 + * - none known
78072 + */
78073 +#include "gcc-plugin.h"
78074 +#include "config.h"
78075 +#include "system.h"
78076 +#include "coretypes.h"
78077 +#include "tree.h"
78078 +#include "tree-pass.h"
78079 +#include "flags.h"
78080 +#include "intl.h"
78081 +#include "toplev.h"
78082 +#include "plugin.h"
78083 +//#include "expr.h" where are you...
78084 +#include "diagnostic.h"
78085 +#include "plugin-version.h"
78086 +#include "tm.h"
78087 +#include "function.h"
78088 +#include "basic-block.h"
78089 +#include "gimple.h"
78090 +#include "rtl.h"
78091 +#include "emit-rtl.h"
78092 +
78093 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78094 +
78095 +int plugin_is_GPL_compatible;
78096 +
78097 +static const char * const kalloc_functions[] = {
78098 + "__kmalloc",
78099 + "kmalloc",
78100 + "kmalloc_large",
78101 + "kmalloc_node",
78102 + "kmalloc_order",
78103 + "kmalloc_order_trace",
78104 + "kmalloc_slab",
78105 + "kzalloc",
78106 + "kzalloc_node",
78107 +};
78108 +
78109 +static struct plugin_info kallocstat_plugin_info = {
78110 + .version = "201111150100",
78111 +};
78112 +
78113 +static unsigned int execute_kallocstat(void);
78114 +
78115 +static struct gimple_opt_pass kallocstat_pass = {
78116 + .pass = {
78117 + .type = GIMPLE_PASS,
78118 + .name = "kallocstat",
78119 + .gate = NULL,
78120 + .execute = execute_kallocstat,
78121 + .sub = NULL,
78122 + .next = NULL,
78123 + .static_pass_number = 0,
78124 + .tv_id = TV_NONE,
78125 + .properties_required = 0,
78126 + .properties_provided = 0,
78127 + .properties_destroyed = 0,
78128 + .todo_flags_start = 0,
78129 + .todo_flags_finish = 0
78130 + }
78131 +};
78132 +
78133 +static bool is_kalloc(const char *fnname)
78134 +{
78135 + size_t i;
78136 +
78137 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
78138 + if (!strcmp(fnname, kalloc_functions[i]))
78139 + return true;
78140 + return false;
78141 +}
78142 +
78143 +static unsigned int execute_kallocstat(void)
78144 +{
78145 + basic_block bb;
78146 +
78147 + // 1. loop through BBs and GIMPLE statements
78148 + FOR_EACH_BB(bb) {
78149 + gimple_stmt_iterator gsi;
78150 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78151 + // gimple match:
78152 + tree fndecl, size;
78153 + gimple call_stmt;
78154 + const char *fnname;
78155 +
78156 + // is it a call
78157 + call_stmt = gsi_stmt(gsi);
78158 + if (!is_gimple_call(call_stmt))
78159 + continue;
78160 + fndecl = gimple_call_fndecl(call_stmt);
78161 + if (fndecl == NULL_TREE)
78162 + continue;
78163 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
78164 + continue;
78165 +
78166 + // is it a call to k*alloc
78167 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
78168 + if (!is_kalloc(fnname))
78169 + continue;
78170 +
78171 + // is the size arg the result of a simple const assignment
78172 + size = gimple_call_arg(call_stmt, 0);
78173 + while (true) {
78174 + gimple def_stmt;
78175 + expanded_location xloc;
78176 + size_t size_val;
78177 +
78178 + if (TREE_CODE(size) != SSA_NAME)
78179 + break;
78180 + def_stmt = SSA_NAME_DEF_STMT(size);
78181 + if (!def_stmt || !is_gimple_assign(def_stmt))
78182 + break;
78183 + if (gimple_num_ops(def_stmt) != 2)
78184 + break;
78185 + size = gimple_assign_rhs1(def_stmt);
78186 + if (!TREE_CONSTANT(size))
78187 + continue;
78188 + xloc = expand_location(gimple_location(def_stmt));
78189 + if (!xloc.file)
78190 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
78191 + size_val = TREE_INT_CST_LOW(size);
78192 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
78193 + break;
78194 + }
78195 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
78196 +//debug_tree(gimple_call_fn(call_stmt));
78197 +//print_node(stderr, "pax", fndecl, 4);
78198 + }
78199 + }
78200 +
78201 + return 0;
78202 +}
78203 +
78204 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78205 +{
78206 + const char * const plugin_name = plugin_info->base_name;
78207 + struct register_pass_info kallocstat_pass_info = {
78208 + .pass = &kallocstat_pass.pass,
78209 + .reference_pass_name = "ssa",
78210 + .ref_pass_instance_number = 0,
78211 + .pos_op = PASS_POS_INSERT_AFTER
78212 + };
78213 +
78214 + if (!plugin_default_version_check(version, &gcc_version)) {
78215 + error(G_("incompatible gcc/plugin versions"));
78216 + return 1;
78217 + }
78218 +
78219 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
78220 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
78221 +
78222 + return 0;
78223 +}
78224 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
78225 new file mode 100644
78226 index 0000000..51f747e
78227 --- /dev/null
78228 +++ b/tools/gcc/kernexec_plugin.c
78229 @@ -0,0 +1,348 @@
78230 +/*
78231 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78232 + * Licensed under the GPL v2
78233 + *
78234 + * Note: the choice of the license means that the compilation process is
78235 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78236 + * but for the kernel it doesn't matter since it doesn't link against
78237 + * any of the gcc libraries
78238 + *
78239 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
78240 + *
78241 + * TODO:
78242 + *
78243 + * BUGS:
78244 + * - none known
78245 + */
78246 +#include "gcc-plugin.h"
78247 +#include "config.h"
78248 +#include "system.h"
78249 +#include "coretypes.h"
78250 +#include "tree.h"
78251 +#include "tree-pass.h"
78252 +#include "flags.h"
78253 +#include "intl.h"
78254 +#include "toplev.h"
78255 +#include "plugin.h"
78256 +//#include "expr.h" where are you...
78257 +#include "diagnostic.h"
78258 +#include "plugin-version.h"
78259 +#include "tm.h"
78260 +#include "function.h"
78261 +#include "basic-block.h"
78262 +#include "gimple.h"
78263 +#include "rtl.h"
78264 +#include "emit-rtl.h"
78265 +#include "tree-flow.h"
78266 +
78267 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78268 +extern rtx emit_move_insn(rtx x, rtx y);
78269 +
78270 +int plugin_is_GPL_compatible;
78271 +
78272 +static struct plugin_info kernexec_plugin_info = {
78273 + .version = "201111291120",
78274 + .help = "method=[bts|or]\tinstrumentation method\n"
78275 +};
78276 +
78277 +static unsigned int execute_kernexec_fptr(void);
78278 +static unsigned int execute_kernexec_retaddr(void);
78279 +static bool kernexec_cmodel_check(void);
78280 +
78281 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator);
78282 +static void (*kernexec_instrument_retaddr)(rtx);
78283 +
78284 +static struct gimple_opt_pass kernexec_fptr_pass = {
78285 + .pass = {
78286 + .type = GIMPLE_PASS,
78287 + .name = "kernexec_fptr",
78288 + .gate = kernexec_cmodel_check,
78289 + .execute = execute_kernexec_fptr,
78290 + .sub = NULL,
78291 + .next = NULL,
78292 + .static_pass_number = 0,
78293 + .tv_id = TV_NONE,
78294 + .properties_required = 0,
78295 + .properties_provided = 0,
78296 + .properties_destroyed = 0,
78297 + .todo_flags_start = 0,
78298 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
78299 + }
78300 +};
78301 +
78302 +static struct rtl_opt_pass kernexec_retaddr_pass = {
78303 + .pass = {
78304 + .type = RTL_PASS,
78305 + .name = "kernexec_retaddr",
78306 + .gate = kernexec_cmodel_check,
78307 + .execute = execute_kernexec_retaddr,
78308 + .sub = NULL,
78309 + .next = NULL,
78310 + .static_pass_number = 0,
78311 + .tv_id = TV_NONE,
78312 + .properties_required = 0,
78313 + .properties_provided = 0,
78314 + .properties_destroyed = 0,
78315 + .todo_flags_start = 0,
78316 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
78317 + }
78318 +};
78319 +
78320 +static bool kernexec_cmodel_check(void)
78321 +{
78322 + tree section;
78323 +
78324 + if (ix86_cmodel != CM_KERNEL)
78325 + return false;
78326 +
78327 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
78328 + if (!section || !TREE_VALUE(section))
78329 + return true;
78330 +
78331 + section = TREE_VALUE(TREE_VALUE(section));
78332 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
78333 + return true;
78334 +
78335 + return false;
78336 +}
78337 +
78338 +/*
78339 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
78340 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
78341 + */
78342 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator gsi)
78343 +{
78344 + gimple assign_intptr, assign_new_fptr, call_stmt;
78345 + tree intptr, old_fptr, new_fptr, kernexec_mask;
78346 +
78347 + call_stmt = gsi_stmt(gsi);
78348 + old_fptr = gimple_call_fn(call_stmt);
78349 +
78350 + // create temporary unsigned long variable used for bitops and cast fptr to it
78351 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
78352 + add_referenced_var(intptr);
78353 + mark_sym_for_renaming(intptr);
78354 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
78355 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
78356 + update_stmt(assign_intptr);
78357 +
78358 + // apply logical or to temporary unsigned long and bitmask
78359 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
78360 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
78361 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
78362 + gsi_insert_before(&gsi, assign_intptr, GSI_SAME_STMT);
78363 + update_stmt(assign_intptr);
78364 +
78365 + // cast temporary unsigned long back to a temporary fptr variable
78366 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
78367 + add_referenced_var(new_fptr);
78368 + mark_sym_for_renaming(new_fptr);
78369 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
78370 + gsi_insert_before(&gsi, assign_new_fptr, GSI_SAME_STMT);
78371 + update_stmt(assign_new_fptr);
78372 +
78373 + // replace call stmt fn with the new fptr
78374 + gimple_call_set_fn(call_stmt, new_fptr);
78375 + update_stmt(call_stmt);
78376 +}
78377 +
78378 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator gsi)
78379 +{
78380 + gimple asm_or_stmt, call_stmt;
78381 + tree old_fptr, new_fptr, input, output;
78382 + VEC(tree, gc) *inputs = NULL;
78383 + VEC(tree, gc) *outputs = NULL;
78384 +
78385 + call_stmt = gsi_stmt(gsi);
78386 + old_fptr = gimple_call_fn(call_stmt);
78387 +
78388 + // create temporary fptr variable
78389 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
78390 + add_referenced_var(new_fptr);
78391 + mark_sym_for_renaming(new_fptr);
78392 +
78393 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
78394 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
78395 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
78396 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
78397 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
78398 + VEC_safe_push(tree, gc, inputs, input);
78399 + VEC_safe_push(tree, gc, outputs, output);
78400 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
78401 + gimple_asm_set_volatile(asm_or_stmt, true);
78402 + gsi_insert_before(&gsi, asm_or_stmt, GSI_SAME_STMT);
78403 + update_stmt(asm_or_stmt);
78404 +
78405 + // replace call stmt fn with the new fptr
78406 + gimple_call_set_fn(call_stmt, new_fptr);
78407 + update_stmt(call_stmt);
78408 +}
78409 +
78410 +/*
78411 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
78412 + */
78413 +static unsigned int execute_kernexec_fptr(void)
78414 +{
78415 + basic_block bb;
78416 + gimple_stmt_iterator gsi;
78417 +
78418 + // 1. loop through BBs and GIMPLE statements
78419 + FOR_EACH_BB(bb) {
78420 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78421 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
78422 + tree fn;
78423 + gimple call_stmt;
78424 +
78425 + // is it a call ...
78426 + call_stmt = gsi_stmt(gsi);
78427 + if (!is_gimple_call(call_stmt))
78428 + continue;
78429 + fn = gimple_call_fn(call_stmt);
78430 + if (TREE_CODE(fn) == ADDR_EXPR)
78431 + continue;
78432 + if (TREE_CODE(fn) != SSA_NAME)
78433 + gcc_unreachable();
78434 +
78435 + // ... through a function pointer
78436 + fn = SSA_NAME_VAR(fn);
78437 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
78438 + continue;
78439 + fn = TREE_TYPE(fn);
78440 + if (TREE_CODE(fn) != POINTER_TYPE)
78441 + continue;
78442 + fn = TREE_TYPE(fn);
78443 + if (TREE_CODE(fn) != FUNCTION_TYPE)
78444 + continue;
78445 +
78446 + kernexec_instrument_fptr(gsi);
78447 +
78448 +//debug_tree(gimple_call_fn(call_stmt));
78449 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
78450 + }
78451 + }
78452 +
78453 + return 0;
78454 +}
78455 +
78456 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
78457 +static void kernexec_instrument_retaddr_bts(rtx insn)
78458 +{
78459 + rtx btsq;
78460 + rtvec argvec, constraintvec, labelvec;
78461 + int line;
78462 +
78463 + // create asm volatile("btsq $63,(%%rsp)":::)
78464 + argvec = rtvec_alloc(0);
78465 + constraintvec = rtvec_alloc(0);
78466 + labelvec = rtvec_alloc(0);
78467 + line = expand_location(RTL_LOCATION(insn)).line;
78468 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
78469 + MEM_VOLATILE_P(btsq) = 1;
78470 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
78471 + emit_insn_before(btsq, insn);
78472 +}
78473 +
78474 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
78475 +static void kernexec_instrument_retaddr_or(rtx insn)
78476 +{
78477 + rtx orq;
78478 + rtvec argvec, constraintvec, labelvec;
78479 + int line;
78480 +
78481 + // create asm volatile("orq %%r10,(%%rsp)":::)
78482 + argvec = rtvec_alloc(0);
78483 + constraintvec = rtvec_alloc(0);
78484 + labelvec = rtvec_alloc(0);
78485 + line = expand_location(RTL_LOCATION(insn)).line;
78486 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
78487 + MEM_VOLATILE_P(orq) = 1;
78488 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
78489 + emit_insn_before(orq, insn);
78490 +}
78491 +
78492 +/*
78493 + * find all asm level function returns and forcibly set the highest bit of the return address
78494 + */
78495 +static unsigned int execute_kernexec_retaddr(void)
78496 +{
78497 + rtx insn;
78498 +
78499 + // 1. find function returns
78500 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
78501 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
78502 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
78503 + rtx body;
78504 +
78505 + // is it a retn
78506 + if (!JUMP_P(insn))
78507 + continue;
78508 + body = PATTERN(insn);
78509 + if (GET_CODE(body) == PARALLEL)
78510 + body = XVECEXP(body, 0, 0);
78511 + if (GET_CODE(body) != RETURN)
78512 + continue;
78513 + kernexec_instrument_retaddr(insn);
78514 + }
78515 +
78516 +// print_simple_rtl(stderr, get_insns());
78517 +// print_rtl(stderr, get_insns());
78518 +
78519 + return 0;
78520 +}
78521 +
78522 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78523 +{
78524 + const char * const plugin_name = plugin_info->base_name;
78525 + const int argc = plugin_info->argc;
78526 + const struct plugin_argument * const argv = plugin_info->argv;
78527 + int i;
78528 + struct register_pass_info kernexec_fptr_pass_info = {
78529 + .pass = &kernexec_fptr_pass.pass,
78530 + .reference_pass_name = "ssa",
78531 + .ref_pass_instance_number = 0,
78532 + .pos_op = PASS_POS_INSERT_AFTER
78533 + };
78534 + struct register_pass_info kernexec_retaddr_pass_info = {
78535 + .pass = &kernexec_retaddr_pass.pass,
78536 + .reference_pass_name = "pro_and_epilogue",
78537 + .ref_pass_instance_number = 0,
78538 + .pos_op = PASS_POS_INSERT_AFTER
78539 + };
78540 +
78541 + if (!plugin_default_version_check(version, &gcc_version)) {
78542 + error(G_("incompatible gcc/plugin versions"));
78543 + return 1;
78544 + }
78545 +
78546 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
78547 +
78548 + if (TARGET_64BIT == 0)
78549 + return 0;
78550 +
78551 + for (i = 0; i < argc; ++i) {
78552 + if (!strcmp(argv[i].key, "method")) {
78553 + if (!argv[i].value) {
78554 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78555 + continue;
78556 + }
78557 + if (!strcmp(argv[i].value, "bts")) {
78558 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
78559 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
78560 + } else if (!strcmp(argv[i].value, "or")) {
78561 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
78562 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
78563 + fix_register("r10", 1, 1);
78564 + } else
78565 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
78566 + continue;
78567 + }
78568 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78569 + }
78570 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
78571 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
78572 +
78573 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
78574 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
78575 +
78576 + return 0;
78577 +}
78578 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
78579 new file mode 100644
78580 index 0000000..d44f37c
78581 --- /dev/null
78582 +++ b/tools/gcc/stackleak_plugin.c
78583 @@ -0,0 +1,291 @@
78584 +/*
78585 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78586 + * Licensed under the GPL v2
78587 + *
78588 + * Note: the choice of the license means that the compilation process is
78589 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78590 + * but for the kernel it doesn't matter since it doesn't link against
78591 + * any of the gcc libraries
78592 + *
78593 + * gcc plugin to help implement various PaX features
78594 + *
78595 + * - track lowest stack pointer
78596 + *
78597 + * TODO:
78598 + * - initialize all local variables
78599 + *
78600 + * BUGS:
78601 + * - none known
78602 + */
78603 +#include "gcc-plugin.h"
78604 +#include "config.h"
78605 +#include "system.h"
78606 +#include "coretypes.h"
78607 +#include "tree.h"
78608 +#include "tree-pass.h"
78609 +#include "flags.h"
78610 +#include "intl.h"
78611 +#include "toplev.h"
78612 +#include "plugin.h"
78613 +//#include "expr.h" where are you...
78614 +#include "diagnostic.h"
78615 +#include "plugin-version.h"
78616 +#include "tm.h"
78617 +#include "function.h"
78618 +#include "basic-block.h"
78619 +#include "gimple.h"
78620 +#include "rtl.h"
78621 +#include "emit-rtl.h"
78622 +
78623 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78624 +
78625 +int plugin_is_GPL_compatible;
78626 +
78627 +static int track_frame_size = -1;
78628 +static const char track_function[] = "pax_track_stack";
78629 +static const char check_function[] = "pax_check_alloca";
78630 +static bool init_locals;
78631 +
78632 +static struct plugin_info stackleak_plugin_info = {
78633 + .version = "201111150100",
78634 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
78635 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
78636 +};
78637 +
78638 +static bool gate_stackleak_track_stack(void);
78639 +static unsigned int execute_stackleak_tree_instrument(void);
78640 +static unsigned int execute_stackleak_final(void);
78641 +
78642 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
78643 + .pass = {
78644 + .type = GIMPLE_PASS,
78645 + .name = "stackleak_tree_instrument",
78646 + .gate = gate_stackleak_track_stack,
78647 + .execute = execute_stackleak_tree_instrument,
78648 + .sub = NULL,
78649 + .next = NULL,
78650 + .static_pass_number = 0,
78651 + .tv_id = TV_NONE,
78652 + .properties_required = PROP_gimple_leh | PROP_cfg,
78653 + .properties_provided = 0,
78654 + .properties_destroyed = 0,
78655 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
78656 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
78657 + }
78658 +};
78659 +
78660 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
78661 + .pass = {
78662 + .type = RTL_PASS,
78663 + .name = "stackleak_final",
78664 + .gate = gate_stackleak_track_stack,
78665 + .execute = execute_stackleak_final,
78666 + .sub = NULL,
78667 + .next = NULL,
78668 + .static_pass_number = 0,
78669 + .tv_id = TV_NONE,
78670 + .properties_required = 0,
78671 + .properties_provided = 0,
78672 + .properties_destroyed = 0,
78673 + .todo_flags_start = 0,
78674 + .todo_flags_finish = TODO_dump_func
78675 + }
78676 +};
78677 +
78678 +static bool gate_stackleak_track_stack(void)
78679 +{
78680 + return track_frame_size >= 0;
78681 +}
78682 +
78683 +static void stackleak_check_alloca(gimple_stmt_iterator gsi)
78684 +{
78685 + gimple check_alloca;
78686 + tree fndecl, fntype, alloca_size;
78687 +
78688 + // insert call to void pax_check_alloca(unsigned long size)
78689 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
78690 + fndecl = build_fn_decl(check_function, fntype);
78691 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
78692 + alloca_size = gimple_call_arg(gsi_stmt(gsi), 0);
78693 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
78694 + gsi_insert_before(&gsi, check_alloca, GSI_CONTINUE_LINKING);
78695 +}
78696 +
78697 +static void stackleak_add_instrumentation(gimple_stmt_iterator gsi)
78698 +{
78699 + gimple track_stack;
78700 + tree fndecl, fntype;
78701 +
78702 + // insert call to void pax_track_stack(void)
78703 + fntype = build_function_type_list(void_type_node, NULL_TREE);
78704 + fndecl = build_fn_decl(track_function, fntype);
78705 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
78706 + track_stack = gimple_build_call(fndecl, 0);
78707 + gsi_insert_after(&gsi, track_stack, GSI_CONTINUE_LINKING);
78708 +}
78709 +
78710 +#if BUILDING_GCC_VERSION == 4005
78711 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
78712 +{
78713 + tree fndecl;
78714 +
78715 + if (!is_gimple_call(stmt))
78716 + return false;
78717 + fndecl = gimple_call_fndecl(stmt);
78718 + if (!fndecl)
78719 + return false;
78720 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
78721 + return false;
78722 +// print_node(stderr, "pax", fndecl, 4);
78723 + return DECL_FUNCTION_CODE(fndecl) == code;
78724 +}
78725 +#endif
78726 +
78727 +static bool is_alloca(gimple stmt)
78728 +{
78729 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
78730 + return true;
78731 +
78732 +#if BUILDING_GCC_VERSION >= 4007
78733 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
78734 + return true;
78735 +#endif
78736 +
78737 + return false;
78738 +}
78739 +
78740 +static unsigned int execute_stackleak_tree_instrument(void)
78741 +{
78742 + basic_block bb, entry_bb;
78743 + bool prologue_instrumented = false;
78744 +
78745 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
78746 +
78747 + // 1. loop through BBs and GIMPLE statements
78748 + FOR_EACH_BB(bb) {
78749 + gimple_stmt_iterator gsi;
78750 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78751 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
78752 + if (!is_alloca(gsi_stmt(gsi)))
78753 + continue;
78754 +
78755 + // 2. insert stack overflow check before each __builtin_alloca call
78756 + stackleak_check_alloca(gsi);
78757 +
78758 + // 3. insert track call after each __builtin_alloca call
78759 + stackleak_add_instrumentation(gsi);
78760 + if (bb == entry_bb)
78761 + prologue_instrumented = true;
78762 + }
78763 + }
78764 +
78765 + // 4. insert track call at the beginning
78766 + if (!prologue_instrumented) {
78767 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
78768 + if (dom_info_available_p(CDI_DOMINATORS))
78769 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
78770 + stackleak_add_instrumentation(gsi_start_bb(bb));
78771 + }
78772 +
78773 + return 0;
78774 +}
78775 +
78776 +static unsigned int execute_stackleak_final(void)
78777 +{
78778 + rtx insn;
78779 +
78780 + if (cfun->calls_alloca)
78781 + return 0;
78782 +
78783 + // keep calls only if function frame is big enough
78784 + if (get_frame_size() >= track_frame_size)
78785 + return 0;
78786 +
78787 + // 1. find pax_track_stack calls
78788 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
78789 + // 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))
78790 + rtx body;
78791 +
78792 + if (!CALL_P(insn))
78793 + continue;
78794 + body = PATTERN(insn);
78795 + if (GET_CODE(body) != CALL)
78796 + continue;
78797 + body = XEXP(body, 0);
78798 + if (GET_CODE(body) != MEM)
78799 + continue;
78800 + body = XEXP(body, 0);
78801 + if (GET_CODE(body) != SYMBOL_REF)
78802 + continue;
78803 + if (strcmp(XSTR(body, 0), track_function))
78804 + continue;
78805 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
78806 + // 2. delete call
78807 + insn = delete_insn_and_edges(insn);
78808 +#if BUILDING_GCC_VERSION >= 4007
78809 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
78810 + insn = delete_insn_and_edges(insn);
78811 +#endif
78812 + }
78813 +
78814 +// print_simple_rtl(stderr, get_insns());
78815 +// print_rtl(stderr, get_insns());
78816 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
78817 +
78818 + return 0;
78819 +}
78820 +
78821 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78822 +{
78823 + const char * const plugin_name = plugin_info->base_name;
78824 + const int argc = plugin_info->argc;
78825 + const struct plugin_argument * const argv = plugin_info->argv;
78826 + int i;
78827 + struct register_pass_info stackleak_tree_instrument_pass_info = {
78828 + .pass = &stackleak_tree_instrument_pass.pass,
78829 +// .reference_pass_name = "tree_profile",
78830 + .reference_pass_name = "optimized",
78831 + .ref_pass_instance_number = 0,
78832 + .pos_op = PASS_POS_INSERT_AFTER
78833 + };
78834 + struct register_pass_info stackleak_final_pass_info = {
78835 + .pass = &stackleak_final_rtl_opt_pass.pass,
78836 + .reference_pass_name = "final",
78837 + .ref_pass_instance_number = 0,
78838 + .pos_op = PASS_POS_INSERT_BEFORE
78839 + };
78840 +
78841 + if (!plugin_default_version_check(version, &gcc_version)) {
78842 + error(G_("incompatible gcc/plugin versions"));
78843 + return 1;
78844 + }
78845 +
78846 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
78847 +
78848 + for (i = 0; i < argc; ++i) {
78849 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
78850 + if (!argv[i].value) {
78851 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78852 + continue;
78853 + }
78854 + track_frame_size = atoi(argv[i].value);
78855 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
78856 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
78857 + continue;
78858 + }
78859 + if (!strcmp(argv[i].key, "initialize-locals")) {
78860 + if (argv[i].value) {
78861 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
78862 + continue;
78863 + }
78864 + init_locals = true;
78865 + continue;
78866 + }
78867 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78868 + }
78869 +
78870 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
78871 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
78872 +
78873 + return 0;
78874 +}
78875 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
78876 index 6789d78..4afd019 100644
78877 --- a/tools/perf/util/include/asm/alternative-asm.h
78878 +++ b/tools/perf/util/include/asm/alternative-asm.h
78879 @@ -5,4 +5,7 @@
78880
78881 #define altinstruction_entry #
78882
78883 + .macro pax_force_retaddr rip=0, reload=0
78884 + .endm
78885 +
78886 #endif
78887 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
78888 index af0f22f..9a7d479 100644
78889 --- a/usr/gen_init_cpio.c
78890 +++ b/usr/gen_init_cpio.c
78891 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
78892 int retval;
78893 int rc = -1;
78894 int namesize;
78895 - int i;
78896 + unsigned int i;
78897
78898 mode |= S_IFREG;
78899
78900 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
78901 *env_var = *expanded = '\0';
78902 strncat(env_var, start + 2, end - start - 2);
78903 strncat(expanded, new_location, start - new_location);
78904 - strncat(expanded, getenv(env_var), PATH_MAX);
78905 - strncat(expanded, end + 1, PATH_MAX);
78906 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
78907 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
78908 strncpy(new_location, expanded, PATH_MAX);
78909 + new_location[PATH_MAX] = 0;
78910 } else
78911 break;
78912 }
78913 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
78914 index d9cfb78..4f27c10 100644
78915 --- a/virt/kvm/kvm_main.c
78916 +++ b/virt/kvm/kvm_main.c
78917 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
78918
78919 static cpumask_var_t cpus_hardware_enabled;
78920 static int kvm_usage_count = 0;
78921 -static atomic_t hardware_enable_failed;
78922 +static atomic_unchecked_t hardware_enable_failed;
78923
78924 struct kmem_cache *kvm_vcpu_cache;
78925 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
78926 @@ -2268,7 +2268,7 @@ static void hardware_enable_nolock(void *junk)
78927
78928 if (r) {
78929 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
78930 - atomic_inc(&hardware_enable_failed);
78931 + atomic_inc_unchecked(&hardware_enable_failed);
78932 printk(KERN_INFO "kvm: enabling virtualization on "
78933 "CPU%d failed\n", cpu);
78934 }
78935 @@ -2322,10 +2322,10 @@ static int hardware_enable_all(void)
78936
78937 kvm_usage_count++;
78938 if (kvm_usage_count == 1) {
78939 - atomic_set(&hardware_enable_failed, 0);
78940 + atomic_set_unchecked(&hardware_enable_failed, 0);
78941 on_each_cpu(hardware_enable_nolock, NULL, 1);
78942
78943 - if (atomic_read(&hardware_enable_failed)) {
78944 + if (atomic_read_unchecked(&hardware_enable_failed)) {
78945 hardware_disable_all_nolock();
78946 r = -EBUSY;
78947 }
78948 @@ -2676,7 +2676,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
78949 kvm_arch_vcpu_put(vcpu);
78950 }
78951
78952 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78953 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78954 struct module *module)
78955 {
78956 int r;
78957 @@ -2739,7 +2739,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78958 if (!vcpu_align)
78959 vcpu_align = __alignof__(struct kvm_vcpu);
78960 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
78961 - 0, NULL);
78962 + SLAB_USERCOPY, NULL);
78963 if (!kvm_vcpu_cache) {
78964 r = -ENOMEM;
78965 goto out_free_3;
78966 @@ -2749,9 +2749,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78967 if (r)
78968 goto out_free;
78969
78970 - kvm_chardev_ops.owner = module;
78971 - kvm_vm_fops.owner = module;
78972 - kvm_vcpu_fops.owner = module;
78973 + pax_open_kernel();
78974 + *(void **)&kvm_chardev_ops.owner = module;
78975 + *(void **)&kvm_vm_fops.owner = module;
78976 + *(void **)&kvm_vcpu_fops.owner = module;
78977 + pax_close_kernel();
78978
78979 r = misc_register(&kvm_dev);
78980 if (r) {